authhero 0.218.0 → 0.219.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 +13 -13
- package/dist/authhero.mjs +148 -144
- package/package.json +1 -1
package/dist/authhero.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var Lw=Object.defineProperty;var Fw=(t,e,n)=>e in t?Lw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var be=(t,e,n)=>Fw(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@hono/zod-openapi"),Se=t=>typeof t=="string",mo=()=>{let t,e;const n=new Promise((r,i)=>{t=r,e=i});return n.resolve=t,n.reject=e,n},ah=t=>t==null?"":""+t,Uw=(t,e,n)=>{t.forEach(r=>{e[r]&&(n[r]=e[r])})},Mw=/###/g,ch=t=>t&&t.indexOf("###")>-1?t.replace(Mw,"."):t,lh=t=>!t||Se(t),So=(t,e,n)=>{const r=Se(e)?e.split("."):e;let i=0;for(;i<r.length-1;){if(lh(t))return{};const s=ch(r[i]);!t[s]&&n&&(t[s]=new n),Object.prototype.hasOwnProperty.call(t,s)?t=t[s]:t={},++i}return lh(t)?{}:{obj:t,k:ch(r[i])}},uh=(t,e,n)=>{const{obj:r,k:i}=So(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),l=So(t,a,Object);for(;l.obj===void 0&&a.length;)s=`${a[a.length-1]}.${s}`,a=a.slice(0,a.length-1),l=So(t,a,Object),l!=null&&l.obj&&typeof l.obj[`${l.k}.${s}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${s}`]=n},qw=(t,e,n,r)=>{const{obj:i,k:s}=So(t,e,Object);i[s]=i[s]||[],i[s].push(n)},wa=(t,e)=>{const{obj:n,k:r}=So(t,e);if(n&&Object.prototype.hasOwnProperty.call(n,r))return n[r]},Vw=(t,e,n)=>{const r=wa(t,n);return r!==void 0?r:wa(e,n)},Tm=(t,e,n)=>{for(const r in e)r!=="__proto__"&&r!=="constructor"&&(r in t?Se(t[r])||t[r]instanceof String||Se(e[r])||e[r]instanceof String?n&&(t[r]=e[r]):Tm(t[r],e[r],n):t[r]=e[r]);return t},fi=t=>t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var Hw={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const Kw=t=>Se(t)?t.replace(/[&<>"'\/]/g,e=>Hw[e]):t;class Gw{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 Ww=[" ",",","?","!",";"],Xw=new Gw(20),Jw=(t,e,n)=>{e=e||"",n=n||"";const r=Ww.filter(a=>e.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const i=Xw.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},Su=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,l="";for(let u=s;u<r.length;++u)if(u!==s&&(l+=n),l+=r[u],a=i[l],a!==void 0){if(["string","number","boolean"].indexOf(typeof a)>-1&&u<r.length-1)continue;s+=u-s+1;break}i=a}return i},va=t=>t==null?void 0:t.replace("_","-"),Yw={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 ba{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||Yw,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:(Se(e[0])&&(e[0]=`${r}${this.prefix} ${e[0]}`),this.logger[n](e))}create(e){return new ba(this.logger,{prefix:`${this.prefix}:${e}:`,...this.options})}clone(e){return e=e||this.options,e.prefix=e.prefix||this.prefix,new ba(this.logger,e)}}var Nn=new ba;class kc{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[l,u]=a;for(let d=0;d<u;d++)l(...r)}),this.observers["*"]&&Array.from(this.observers["*"].entries()).forEach(a=>{let[l,u]=a;for(let d=0;d<u;d++)l.apply(l,[e,...r])})}}class dh extends kc{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,p;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 l;e.indexOf(".")>-1?l=e.split("."):(l=[e,n],r&&(Array.isArray(r)?l.push(...r):Se(r)&&s?l.push(...r.split(s)):l.push(r)));const u=wa(this.data,l);return!u&&!n&&!r&&e.indexOf(".")>-1&&(e=l[0],n=l[1],r=l.slice(2).join(".")),u||!a||!Se(r)?u:Su((p=(d=this.data)==null?void 0:d[e])==null?void 0:p[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 l=[e,n];r&&(l=l.concat(a?r.split(a):r)),e.indexOf(".")>-1&&(l=e.split("."),i=n,n=l[1]),this.addNamespaces(n),uh(this.data,l,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)(Se(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},l=[e,n];e.indexOf(".")>-1&&(l=e.split("."),i=r,r=n,n=l[1]),this.addNamespaces(n);let u=wa(this.data,l)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),i?Tm(u,r,s):u={...u,...r},uh(this.data,l,u),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 Om={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 ph={};class $a extends kc{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=Nn.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,l=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!Jw(e,r,i);if(a&&!l){const u=e.match(this.interpolator.nestingRegexp);if(u&&u.length>0)return{key:e,namespaces:Se(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:Se(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:l}=this.extractFromKey(e[e.length-1],n),u=l[l.length-1],d=n.lng||this.language,p=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if((d==null?void 0:d.toLowerCase())==="cimode"){if(p){const q=n.nsSeparator||this.options.nsSeparator;return i?{res:`${u}${q}${a}`,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:u,usedParams:this.getUsedParamsDetails(n)}:`${u}${q}${a}`}return i?{res:a,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:u,usedParams:this.getUsedParamsDetails(n)}:a}const h=this.resolve(e,n);let g=h==null?void 0:h.res;const $=(h==null?void 0:h.usedKey)||a,A=(h==null?void 0:h.exactUsedKey)||a,z=Object.prototype.toString.apply(g),T=["[object Number]","[object Function]","[object RegExp]"],O=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,x=!this.i18nFormat||this.i18nFormat.handleAsObject,U=!Se(g)&&typeof g!="boolean"&&typeof g!="number";if(x&&g&&U&&T.indexOf(z)<0&&!(Se(O)&&Array.isArray(g))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const q=this.options.returnedObjectHandler?this.options.returnedObjectHandler($,g,{...n,ns:l}):`key '${a} (${this.language})' returned an object instead of string.`;return i?(h.res=q,h.usedParams=this.getUsedParamsDetails(n),h):q}if(s){const q=Array.isArray(g),F=q?[]:{},K=q?A:$;for(const G in g)if(Object.prototype.hasOwnProperty.call(g,G)){const Y=`${K}${s}${G}`;F[G]=this.translate(Y,{...n,joinArrays:!1,ns:l}),F[G]===Y&&(F[G]=g[G])}g=F}}else if(x&&Se(O)&&Array.isArray(g))g=g.join(O),g&&(g=this.extendTranslation(g,e,n,r));else{let q=!1,F=!1;const K=n.count!==void 0&&!Se(n.count),G=$a.hasDefaultValue(n),Y=K?this.pluralResolver.getSuffix(d,n.count,n):"",J=n.ordinal&&K?this.pluralResolver.getSuffix(d,n.count,{ordinal:!1}):"",Ae=K&&!n.ordinal&&n.count===0,R=Ae&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${Y}`]||n[`defaultValue${J}`]||n.defaultValue;!this.isValidLookup(g)&&G&&(q=!0,g=R),this.isValidLookup(g)||(F=!0,g=a);const j=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&F?void 0:g,N=G&&R!==g&&this.options.updateMissing;if(F||q||N){if(this.logger.log(N?"updateKey":"missingKey",d,u,a,N?R:g),s){const de=this.resolve(a,{...n,keySeparator:!1});de&&de.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 k=[];const B=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&B&&B[0])for(let de=0;de<B.length;de++)k.push(B[de]);else this.options.saveMissingTo==="all"?k=this.languageUtils.toResolveHierarchy(n.lng||this.language):k.push(n.lng||this.language);const H=(de,ie,ve)=>{var Q;const ke=G&&ve!==g?ve:j;this.options.missingKeyHandler?this.options.missingKeyHandler(de,u,ie,ke,N,n):(Q=this.backendConnector)!=null&&Q.saveMissing&&this.backendConnector.saveMissing(de,u,ie,ke,N,n),this.emit("missingKey",de,u,ie,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&K?k.forEach(de=>{const ie=this.pluralResolver.getSuffixes(de,n);Ae&&n[`defaultValue${this.options.pluralSeparator}zero`]&&ie.indexOf(`${this.options.pluralSeparator}zero`)<0&&ie.push(`${this.options.pluralSeparator}zero`),ie.forEach(ve=>{H([de],a+ve,n[`defaultValue${ve}`]||R)})}):H(k,a,R))}g=this.extendTranslation(g,e,n,h,r),F&&g===a&&this.options.appendNamespaceToMissingKey&&(g=`${u}:${a}`),(F||q)&&this.options.parseMissingKeyHandler&&(g=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${u}:${a}`:a,q?g:void 0))}return i?(h.res=g,h.usedParams=this.getUsedParamsDetails(n),h):g}extendTranslation(e,n,r,i,s){var d,p;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 h=Se(e)&&(((p=r==null?void 0:r.interpolation)==null?void 0:p.skipOnVariables)!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let g;if(h){const A=e.match(this.interpolator.nestingRegexp);g=A&&A.length}let $=r.replace&&!Se(r.replace)?r.replace:r;if(this.options.interpolation.defaultVariables&&($={...this.options.interpolation.defaultVariables,...$}),e=this.interpolator.interpolate(e,$,r.lng||this.language||i.usedLng,r),h){const A=e.match(this.interpolator.nestingRegexp),z=A&&A.length;g<z&&(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 A=arguments.length,z=new Array(A),T=0;T<A;T++)z[T]=arguments[T];return(s==null?void 0:s[0])===z[0]&&!r.context?(a.logger.warn(`It seems you are nesting recursively key: ${z[0]} in key: ${n[0]}`),null):a.translate(...z,n)},r)),r.interpolation&&this.interpolator.reset()}const l=r.postProcess||this.options.postProcess,u=Se(l)?[l]:l;return e!=null&&(u!=null&&u.length)&&r.applyPostProcessor!==!1&&(e=Om.handle(u,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,l;return Se(e)&&(e=[e]),e.forEach(u=>{if(this.isValidLookup(r))return;const d=this.extractFromKey(u,n),p=d.key;i=p;let h=d.namespaces;this.options.fallbackNS&&(h=h.concat(this.options.fallbackNS));const g=n.count!==void 0&&!Se(n.count),$=g&&!n.ordinal&&n.count===0,A=n.context!==void 0&&(Se(n.context)||typeof n.context=="number")&&n.context!=="",z=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);h.forEach(T=>{var O,x;this.isValidLookup(r)||(l=T,!ph[`${z[0]}-${T}`]&&((O=this.utils)!=null&&O.hasLoadedNamespace)&&!((x=this.utils)!=null&&x.hasLoadedNamespace(l))&&(ph[`${z[0]}-${T}`]=!0,this.logger.warn(`key "${i}" for languages "${z.join(", ")}" won't get resolved as namespace "${l}" 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!!!")),z.forEach(U=>{var K;if(this.isValidLookup(r))return;a=U;const q=[p];if((K=this.i18nFormat)!=null&&K.addLookupKeys)this.i18nFormat.addLookupKeys(q,p,U,T,n);else{let G;g&&(G=this.pluralResolver.getSuffix(U,n.count,n));const Y=`${this.options.pluralSeparator}zero`,J=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(g&&(q.push(p+G),n.ordinal&&G.indexOf(J)===0&&q.push(p+G.replace(J,this.options.pluralSeparator)),$&&q.push(p+Y)),A){const Ae=`${p}${this.options.contextSeparator}${n.context}`;q.push(Ae),g&&(q.push(Ae+G),n.ordinal&&G.indexOf(J)===0&&q.push(Ae+G.replace(J,this.options.pluralSeparator)),$&&q.push(Ae+Y))}}let F;for(;F=q.pop();)this.isValidLookup(r)||(s=F,r=this.getResource(U,T,F,n))}))})}),{res:r,usedKey:i,exactUsedKey:s,usedLng:a,usedNS:l}}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&&!Se(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 fh{constructor(e){this.options=e,this.supportedLngs=this.options.supportedLngs||!1,this.logger=Nn.create("languageUtils")}getScriptPartFromCode(e){if(e=va(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=va(e),!e||e.indexOf("-")<0)return e;const n=e.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(e){if(Se(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)),Se(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 Se(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))):Se(e)&&s(this.formatLanguageCode(e)),r.forEach(a=>{i.indexOf(a)<0&&s(this.formatLanguageCode(a))}),i}}const hh={zero:0,one:1,two:2,few:3,many:4,other:5},gh={select:t=>t===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class Zw{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=e,this.options=n,this.logger=Nn.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=va(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!"),gh;if(!e.match(/-|_/))return gh;const u=this.languageUtils.getLanguagePartFromCode(e);a=this.getRule(u,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)=>hh[i]-hh[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 mh=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=Vw(t,e,n);return!s&&i&&Se(n)&&(s=Su(t,n,r),s===void 0&&(s=Su(e,n,r))),s},Gl=t=>t.replace(/\$/g,"$$$$");class Qw{constructor(){var n;let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=Nn.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:l,suffixEscaped:u,formatSeparator:d,unescapeSuffix:p,unescapePrefix:h,nestingPrefix:g,nestingPrefixEscaped:$,nestingSuffix:A,nestingSuffixEscaped:z,nestingOptionsSeparator:T,maxReplaces:O,alwaysFormat:x}=e.interpolation;this.escape=n!==void 0?n:Kw,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=i!==void 0?i:!1,this.prefix=s?fi(s):a||"{{",this.suffix=l?fi(l):u||"}}",this.formatSeparator=d||",",this.unescapePrefix=p?"":h||"-",this.unescapeSuffix=this.unescapePrefix?"":p||"",this.nestingPrefix=g?fi(g):$||fi("$t("),this.nestingSuffix=A?fi(A):z||fi(")"),this.nestingOptionsSeparator=T||",",this.maxReplaces=O||1e3,this.alwaysFormat=x!==void 0?x:!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 $;let s,a,l;const u=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},d=A=>{if(A.indexOf(this.formatSeparator)<0){const x=mh(n,u,A,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(x,void 0,r,{...i,...n,interpolationkey:A}):x}const z=A.split(this.formatSeparator),T=z.shift().trim(),O=z.join(this.formatSeparator).trim();return this.format(mh(n,u,T,this.options.keySeparator,this.options.ignoreJSONStructure),O,r,{...i,...n,interpolationkey:T})};this.resetRegExp();const p=(i==null?void 0:i.missingInterpolationHandler)||this.options.missingInterpolationHandler,h=(($=i==null?void 0:i.interpolation)==null?void 0:$.skipOnVariables)!==void 0?i.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:A=>Gl(A)},{regex:this.regexp,safeValue:A=>this.escapeValue?Gl(this.escape(A)):Gl(A)}].forEach(A=>{for(l=0;s=A.regex.exec(e);){const z=s[1].trim();if(a=d(z),a===void 0)if(typeof p=="function"){const O=p(e,s,i);a=Se(O)?O:""}else if(i&&Object.prototype.hasOwnProperty.call(i,z))a="";else if(h){a=s[0];continue}else this.logger.warn(`missed to pass in variable ${z} for interpolating ${e}`),a="";else!Se(a)&&!this.useRawValueToEscape&&(a=ah(a));const T=A.safeValue(a);if(e=e.replace(s[0],T),h?(A.regex.lastIndex+=a.length,A.regex.lastIndex-=s[0].length):A.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),e}nest(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,s,a;const l=(u,d)=>{const p=this.nestingOptionsSeparator;if(u.indexOf(p)<0)return u;const h=u.split(new RegExp(`${p}[ ]*{`));let g=`{${h[1]}`;u=h[0],g=this.interpolate(g,a);const $=g.match(/'/g),A=g.match(/"/g);((($==null?void 0:$.length)??0)%2===0&&!A||A.length%2!==0)&&(g=g.replace(/'/g,'"'));try{a=JSON.parse(g),d&&(a={...d,...a})}catch(z){return this.logger.warn(`failed parsing options string in nesting for key ${u}`,z),`${u}${p}${g}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,u};for(;i=this.nestingRegexp.exec(e);){let u=[];a={...r},a=a.replace&&!Se(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 p=i[1].split(this.formatSeparator).map(h=>h.trim());i[1]=p.shift(),u=p,d=!0}if(s=n(l.call(this,i[1].trim(),a),a),s&&i[0]===e&&!Se(s))return s;Se(s)||(s=ah(s)),s||(this.logger.warn(`missed to resolve ${i[1]} for nesting ${e}`),s=""),d&&(s=u.reduce((p,h)=>this.format(p,h,r.lng,{...r,interpolationkey:i[1].trim()}),s.trim())),e=e.replace(i[0],s),this.regexp.lastIndex=0}return e}}const ev=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[l,...u]=a.split(":"),d=u.join(":").trim().replace(/^'+|'+$/g,""),p=l.trim();n[p]||(n[p]=d),d==="false"&&(n[p]=!1),d==="true"&&(n[p]=!0),isNaN(d)||(n[p]=parseInt(d,10))}})}return{formatName:e,formatOptions:n}},hi=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 l=e[a];return l||(l=t(va(r),i),e[a]=l),l(n)}};class tv{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=Nn.create("formatter"),this.options=e,this.formats={number:hi((n,r)=>{const i=new Intl.NumberFormat(n,{...r});return s=>i.format(s)}),currency:hi((n,r)=>{const i=new Intl.NumberFormat(n,{...r,style:"currency"});return s=>i.format(s)}),datetime:hi((n,r)=>{const i=new Intl.DateTimeFormat(n,{...r});return s=>i.format(s)}),relativetime:hi((n,r)=>{const i=new Intl.RelativeTimeFormat(n,{...r});return s=>i.format(s,r.range||"day")}),list:hi((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()]=hi(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(l=>l.indexOf(")")>-1)){const l=s.findIndex(u=>u.indexOf(")")>-1);s[0]=[s[0],...s.splice(1,l)].join(this.formatSeparator)}return s.reduce((l,u)=>{var h;const{formatName:d,formatOptions:p}=ev(u);if(this.formats[d]){let g=l;try{const $=((h=i==null?void 0:i.formatParams)==null?void 0:h[i.interpolationkey])||{},A=$.locale||$.lng||i.locale||i.lng||r;g=this.formats[d](l,A,{...p,...i,...$})}catch($){this.logger.warn($)}return g}else this.logger.warn(`there was no format function for ${d}`);return l},e)}}const nv=(t,e)=>{t.pending[e]!==void 0&&(delete t.pending[e],t.pendingCount--)};class rv extends kc{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=Nn.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={},l={},u={};return e.forEach(d=>{let p=!0;n.forEach(h=>{const g=`${d}|${h}`;!r.reload&&this.store.hasResourceBundle(d,h)?this.state[g]=2:this.state[g]<0||(this.state[g]===1?a[g]===void 0&&(a[g]=!0):(this.state[g]=1,p=!1,a[g]===void 0&&(a[g]=!0),s[g]===void 0&&(s[g]=!0),u[h]===void 0&&(u[h]=!0)))}),p||(l[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(l),toLoadNamespaces:Object.keys(u)}}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 l={};this.queue.forEach(u=>{qw(u.loaded,[s],a),nv(u,e),n&&u.errors.push(n),u.pendingCount===0&&!u.done&&(Object.keys(u.loaded).forEach(d=>{l[d]||(l[d]={});const p=u.loaded[d];p.length&&p.forEach(h=>{l[d][h]===void 0&&(l[d][h]=!0)})}),u.done=!0,u.errors.length?u.callback(u.errors):u.callback())}),this.emit("loaded",l),this.queue=this.queue.filter(u=>!u.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 l=(d,p)=>{if(this.readingCalls--,this.waitingReads.length>0){const h=this.waitingReads.shift();this.read(h.lng,h.ns,h.fcName,h.tried,h.wait,h.callback)}if(d&&p&&i<this.maxRetries){setTimeout(()=>{this.read.call(this,e,n,r,i+1,s*2,a)},s);return}a(d,p)},u=this.backend[r].bind(this.backend);if(u.length===2){try{const d=u(e,n);d&&typeof d.then=="function"?d.then(p=>l(null,p)).catch(l):l(null,d)}catch(d){l(d)}return}return u(e,n,l)}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();Se(e)&&(e=this.languageUtils.toResolveHierarchy(e)),Se(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,l)=>{a&&this.logger.warn(`${n}loading namespace ${s} for language ${i} failed`,a),!a&&l&&this.logger.log(`${n}loaded namespace ${s} for language ${i}`,l),this.loaded(e,a,l)})}saveMissing(e,n,r,i,s){var u,d,p,h,g;let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},l=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if((d=(u=this.services)==null?void 0:u.utils)!=null&&d.hasLoadedNamespace&&!((h=(p=this.services)==null?void 0:p.utils)!=null&&h.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((g=this.backend)!=null&&g.create){const $={...a,isUpdate:s},A=this.backend.create.bind(this.backend);if(A.length<6)try{let z;A.length===5?z=A(e,n,r,i,$):z=A(e,n,r,i),z&&typeof z.then=="function"?z.then(T=>l(null,T)).catch(l):l(null,z)}catch(z){l(z)}else A(e,n,r,i,l,$)}!e||!e[0]||this.store.addResource(e[0],n,r,i)}}}const _h=()=>({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]),Se(t[1])&&(e.defaultValue=t[1]),Se(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}}),yh=t=>{var e,n;return Se(t.ns)&&(t.ns=[t.ns]),Se(t.fallbackLng)&&(t.fallbackLng=[t.fallbackLng]),Se(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},Us=()=>{},iv=t=>{Object.getOwnPropertyNames(Object.getPrototypeOf(t)).forEach(n=>{typeof t[n]=="function"&&(t[n]=t[n].bind(t))})};class Ro extends kc{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=yh(e),this.services={},this.logger=Nn,this.modules={external:[]},iv(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&&(Se(n.ns)?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const i=_h();this.options={...i,...this.options,...yh(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=p=>p?typeof p=="function"?new p:p:null;if(!this.options.isClone){this.modules.logger?Nn.init(s(this.modules.logger),this.options):Nn.init(null,this.options);let p;this.modules.formatter?p=this.modules.formatter:p=tv;const h=new fh(this.options);this.store=new dh(this.options.resources,this.options);const g=this.services;g.logger=Nn,g.resourceStore=this.store,g.languageUtils=h,g.pluralResolver=new Zw(h,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),p&&(!this.options.interpolation.format||this.options.interpolation.format===i.interpolation.format)&&(g.formatter=s(p),g.formatter.init(g,this.options),this.options.interpolation.format=g.formatter.format.bind(g.formatter)),g.interpolator=new Qw(this.options),g.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},g.backendConnector=new rv(s(this.modules.backend),g.resourceStore,g,this.options),g.backendConnector.on("*",function($){for(var A=arguments.length,z=new Array(A>1?A-1:0),T=1;T<A;T++)z[T-1]=arguments[T];e.emit($,...z)}),this.modules.languageDetector&&(g.languageDetector=s(this.modules.languageDetector),g.languageDetector.init&&g.languageDetector.init(g,this.options.detection,this.options)),this.modules.i18nFormat&&(g.i18nFormat=s(this.modules.i18nFormat),g.i18nFormat.init&&g.i18nFormat.init(this)),this.translator=new $a(this.services,this.options),this.translator.on("*",function($){for(var A=arguments.length,z=new Array(A>1?A-1:0),T=1;T<A;T++)z[T-1]=arguments[T];e.emit($,...z)}),this.modules.external.forEach($=>{$.init&&$.init(this)})}if(this.format=this.options.interpolation.format,r||(r=Us),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const p=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);p.length>0&&p[0]!=="dev"&&(this.options.lng=p[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(p=>{this[p]=function(){return e.store[p](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(p=>{this[p]=function(){return e.store[p](...arguments),e}});const u=mo(),d=()=>{const p=(h,g)=>{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),u.resolve(g),r(h,g)};if(this.languages&&!this.isInitialized)return p(null,this.t.bind(this));this.changeLanguage(this.options.lng,p)};return this.options.resources||!this.options.initAsync?d():setTimeout(d,0),u}loadResources(e){var s,a;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Us;const i=Se(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 l=[],u=d=>{if(!d||d==="cimode")return;this.services.languageUtils.toResolveHierarchy(d).forEach(h=>{h!=="cimode"&&l.indexOf(h)<0&&l.push(h)})};i?u(i):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(p=>u(p)),(a=(s=this.options.preload)==null?void 0:s.forEach)==null||a.call(s,d=>u(d)),this.services.backendConnector.load(l,this.options.ns,d=>{!d&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(d)})}else r(null)}reloadResources(e,n,r){const i=mo();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=Us),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"&&Om.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=mo();this.emit("languageChanging",e);const s=u=>{this.language=u,this.languages=this.services.languageUtils.toResolveHierarchy(u),this.resolvedLanguage=void 0,this.setResolvedLanguage(u)},a=(u,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(u,function(){return r.t(...arguments)})},l=u=>{var p,h;!e&&!u&&this.services.languageDetector&&(u=[]);const d=Se(u)?u:this.services.languageUtils.getBestMatchFromCodes(u);d&&(this.language||s(d),this.translator.language||this.translator.changeLanguage(d),(h=(p=this.services.languageDetector)==null?void 0:p.cacheUserLanguage)==null||h.call(p,d)),this.loadResources(d,g=>{a(g,d)})};return!e&&this.services.languageDetector&&!this.services.languageDetector.async?l(this.services.languageDetector.detect()):!e&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(l):this.services.languageDetector.detect(l):l(e),i}getFixedT(e,n,r){var i=this;const s=function(a,l){let u;if(typeof l!="object"){for(var d=arguments.length,p=new Array(d>2?d-2:0),h=2;h<d;h++)p[h-2]=arguments[h];u=i.options.overloadTranslationOptionHandler([a,l].concat(p))}else u={...l};u.lng=u.lng||s.lng,u.lngs=u.lngs||s.lngs,u.ns=u.ns||s.ns,u.keyPrefix!==""&&(u.keyPrefix=u.keyPrefix||r||s.keyPrefix);const g=i.options.keySeparator||".";let $;return u.keyPrefix&&Array.isArray(a)?$=a.map(A=>`${u.keyPrefix}${g}${A}`):$=u.keyPrefix?`${u.keyPrefix}${g}${a}`:a,i.t($,u)};return Se(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=(l,u)=>{const d=this.services.backendConnector.state[`${l}|${u}`];return d===-1||d===0||d===2};if(n.precheck){const l=n.precheck(this,a);if(l!==void 0)return l}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=mo();return this.options.ns?(Se(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=mo();Se(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 fh(_h());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 Ro(e,n)}cloneInstance(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Us;const r=e.forkResourceStore;r&&delete e.forkResourceStore;const i={...this.options,...e,isClone:!0},s=new Ro(i);if((e.debug!==void 0||e.prefix!==void 0)&&(s.logger=s.logger.clone(e)),["store","services","language"].forEach(l=>{s[l]=this[l]}),s.services={...this.services},s.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},r){const l=Object.keys(this.store.data).reduce((u,d)=>(u[d]={...this.store.data[d]},Object.keys(u[d]).reduce((p,h)=>(p[h]={...u[d][h]},p),{})),{});s.store=new dh(l,i),s.services.resourceStore=s.store}return s.translator=new $a(s.services,i),s.translator.on("*",function(l){for(var u=arguments.length,d=new Array(u>1?u-1:0),p=1;p<u;p++)d[p-1]=arguments[p];s.emit(l,...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 P=Ro.createInstance();P.createInstance=Ro.createInstance;P.createInstance;P.dir;P.init;P.loadResources;P.reloadResources;P.use;P.changeLanguage;P.getFixedT;const xe=P.t;P.exists;P.setDefaultNamespace;P.hasLoadedNamespace;P.loadNamespaces;P.loadLanguages;var Dm=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,l){var p;function u(h,g){a.res.headers.set(h,g)}const d=r(a.req.header("origin")||"",a);if(d&&u("Access-Control-Allow-Origin",d),n.origin!=="*"){const h=a.req.header("Vary");h?u("Vary",h):u("Vary","Origin")}if(n.credentials&&u("Access-Control-Allow-Credentials","true"),(p=n.exposeHeaders)!=null&&p.length&&u("Access-Control-Expose-Headers",n.exposeHeaders.join(",")),a.req.method==="OPTIONS"){n.maxAge!=null&&u("Access-Control-Max-Age",n.maxAge.toString());const h=i(a.req.header("origin")||"",a);h.length&&u("Access-Control-Allow-Methods",h.join(","));let g=n.allowHeaders;if(!(g!=null&&g.length)){const $=a.req.header("Access-Control-Request-Headers");$&&(g=$.split(/\s*,\s*/))}return g!=null&&g.length&&(u("Access-Control-Allow-Headers",g.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 l()}};const zt=o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()}),Zi=o.z.object({created_at:o.z.string(),updated_at:o.z.string()}),Rm=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()),jm=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:Rm.optional()}),Nc=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()}),xa=Nc.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()}),yp=o.z.object({...xa.shape,...Zi.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(jm).optional()}),kn=yp,ov=Nc.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()),sv="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let av=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=sv[n[t]&63];return e};const Aa=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(()=>av()).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()}),Rr=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),...Aa.shape}),Ea=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."})}),jr=o.z.object({id:o.z.string().openapi({description:"ID of the client grant."}),...Ea.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),cv=o.z.array(jr),Qi=o.z.object({x:o.z.number(),y:o.z.number()});var wp=(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))(wp||{}),vp=(t=>(t.BLOCK="BLOCK",t.FIELD="FIELD",t))(vp||{});const Cc=o.z.object({id:o.z.string(),category:o.z.nativeEnum(vp),type:o.z.nativeEnum(wp)}),Pm=Cc.extend({category:o.z.literal("BLOCK"),type:o.z.literal("RICH_TEXT"),config:o.z.object({content:o.z.string()}).passthrough()}),Bm=Cc.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()}),Lm=Cc.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()}),Fm=Cc.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()}),Um=o.z.object({id:o.z.string(),category:o.z.string(),type:o.z.string()}).passthrough(),Mm=o.z.union([Pm,Bm,Lm,Fm,Um]);var qm=(t=>(t.STEP="STEP",t.FLOW="FLOW",t.CONDITION="CONDITION",t.ACTION="ACTION",t))(qm||{});const Vm=o.z.object({id:o.z.string(),type:o.z.literal("STEP"),coordinates:Qi,alias:o.z.string().optional(),config:o.z.object({components:o.z.array(Mm),next_node:o.z.string()}).passthrough()}),Hm=o.z.object({id:o.z.string(),type:o.z.literal("FLOW"),coordinates:Qi,alias:o.z.string().optional(),config:o.z.object({flow_id:o.z.string(),next_node:o.z.string()})}),Km=o.z.object({id:o.z.string(),type:o.z.string(),coordinates:Qi}).passthrough(),Gm=o.z.union([Vm,Hm,Km]),Wm=o.z.object({next_node:o.z.string(),coordinates:Qi}).passthrough(),Xm=o.z.object({resume_flow:o.z.boolean().optional(),coordinates:Qi}).passthrough(),Jm=o.z.object({id:o.z.string(),name:o.z.string(),languages:o.z.object({primary:o.z.string()}).passthrough(),nodes:o.z.array(Gm),start:Wm,ending:Xm,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(),lv=Jm.omit({id:!0,created_at:!0,updated_at:!0});var Yt=(t=>(t.TOKEN="token",t.TOKEN_ID_TOKEN="token id_token",t.CODE="code",t))(Yt||{}),zn=(t=>(t.QUERY="query",t.FRAGMENT="fragment",t.FORM_POST="form_post",t.WEB_MESSAGE="web_message",t.SAML_POST="saml_post",t))(zn||{}),zc=(t=>(t.S256="S256",t.Plain="plain",t))(zc||{});const jo=o.z.object({client_id:o.z.string(),act_as:o.z.string().optional(),response_type:o.z.nativeEnum(Yt).optional(),response_mode:o.z.nativeEnum(zn).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(zc).optional(),code_challenge:o.z.string().optional(),username:o.z.string().optional(),ui_locales:o.z.string().optional(),vendor_id:o.z.string().optional()}),ku=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(),font:o.z.object({url:o.z.string()}).optional()}),Ni=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()}),Sa=o.z.object({id:o.z.string().optional(),name:o.z.string(),strategy:o.z.string(),options:Ni.default({}),enabled_clients:o.z.array(o.z.string()).default([]).optional(),response_type:o.z.custom().optional(),response_mode:o.z.custom().optional()}),cn=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(Sa.shape),ka=o.z.object({name:o.z.string(),audience:o.z.string(),sender_email:o.z.string().email(),sender_name:o.z.string(),support_url:o.z.string().url().optional(),logo:o.z.string().url().optional(),primary_color:o.z.string().optional(),secondary_color:o.z.string().optional(),language:o.z.string().optional(),id:o.z.string().optional()}),Ci=o.z.object({created_at:o.z.string().transform(t=>t===null?"":t),updated_at:o.z.string().transform(t=>t===null?"":t),...ka.shape,id:o.z.string()});o.z.object({...Rr.shape,tenant:Ci,connections:o.z.array(cn),disable_sign_ups:o.z.boolean(),email_validation:o.z.string()});const Ym=o.z.enum(["password_reset","email_verification","otp","authorization_code","oauth2_state","ticket"]),Zm=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:Ym,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()}),uv=o.z.object({...Zm.shape,created_at:o.z.string()}),bp=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()}),Qm=o.z.object({name:o.z.literal("txt"),record:o.z.string(),domain:o.z.string()}),pr=o.z.object({...bp.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(Qm)}).optional(),tls_policy:o.z.string().optional()}),dv=pr.extend({tenant_id:o.z.string()}),pv=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()}),e_=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)})]),Na=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(e_),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)"}),Ai=o.z.object({...Zi.shape,...Na.shape,id:o.z.string()}),t_=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),n_=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),Ic={enabled:o.z.boolean().default(!1),synchronous:o.z.boolean().default(!1),priority:o.z.number().optional(),hook_id:o.z.string().optional()},fv=o.z.object({...Ic,trigger_id:t_,url:o.z.string()}),hv=o.z.object({...Ic,trigger_id:n_,form_id:o.z.string()}),ea=o.z.union([fv,hv]),gv=o.z.object({...Ic,trigger_id:t_,...Zi.shape,hook_id:o.z.string(),url:o.z.string()}),mv=o.z.object({...Ic,trigger_id:n_,...Zi.shape,hook_id:o.z.string(),form_id:o.z.string()}),Ei=o.z.union([gv,mv]),$p=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()}),r_=o.z.object({keys:o.z.array($p)}),Nu=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())}),i_=o.z.object({csrf_token:o.z.string(),auth0Client:o.z.string().optional(),authParams:jo,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"}),_v=o.z.object({...i_.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()}),Le={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"},yv=o.z.string().refine(t=>Object.values(Le).includes(t),{message:"Invalid log type"}),o_=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()}),Ca=o.z.object({type:yv,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:o_.optional()}),s_=o.z.object({user_id:o.z.string(),password:o.z.string(),algorithm:o.z.enum(["bcrypt","argon2id"]).default("argon2id")}),wv=o.z.object({...s_.shape,created_at:o.z.string(),updated_at:o.z.string()}),a_=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")}),c_=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:a_.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")}),Tc=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),authenticated_at:o.z.string(),last_interaction_at:o.z.string(),...c_.shape}),Cu=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 an=(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))(an||{});const xp=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 l_=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()}),u_=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()}),Tr=o.z.object({bold:o.z.boolean(),size:o.z.number()}),d_=o.z.object({body_text:Tr,buttons_text:Tr,font_url:o.z.string(),input_labels:Tr,links:Tr,links_style:o.z.enum(["normal","underlined"]),reference_text_size:o.z.number(),subtitle:Tr,title:Tr}),p_=o.z.object({background_color:o.z.string(),background_image_url:o.z.string(),page_layout:o.z.enum(["center","left","right"])}),f_=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"])}),h_=o.z.object({borders:l_,colors:u_,displayName:o.z.string(),fonts:d_,page_background:p_,widget:f_}),ta=h_.extend({themeId:o.z.string()}),na=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()}),ra=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()}),Ap=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:a_,resource_servers:o.z.array(o.z.object({audience:o.z.string(),scopes:o.z.string()})),rotating:o.z.boolean()}),vv=o.z.object({created_at:o.z.string(),...Ap.shape}),bv=o.z.object({to:o.z.string(),message:o.z.string()}),$v=o.z.object({name:o.z.string(),options:o.z.object({})}),g_=o.z.object({value:o.z.string(),description:o.z.string().optional()}),m_=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()}),za=o.z.object({name:o.z.string(),identifier:o.z.string(),scopes:o.z.array(g_).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:m_.optional()}),Pr=o.z.object({id:o.z.string().optional(),...za.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),xv=o.z.array(Pr),__=o.z.object({role_id:o.z.string(),resource_server_identifier:o.z.string(),permission_name:o.z.string()}),y_=o.z.object({...__.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Av=o.z.array(y_),w_=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()}),v_=o.z.array(w_),b_=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()}),$_=o.z.object({...b_.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Ev=o.z.array($_),x_=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()}),A_=o.z.array(x_),E_=o.z.object({user_id:o.z.string(),role_id:o.z.string(),organization_id:o.z.string().optional()}),S_=o.z.object({...E_.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Sv=o.z.array(S_),Ia=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"})}),Br=o.z.object({id:o.z.string().openapi({description:"The unique identifier of the role"}),...Ia.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),Ta=o.z.array(Br),k_=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(),N_=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"})}),C_=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(),Oa=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:k_,metadata:o.z.record(o.z.any()).default({}).optional().openapi({description:"Custom metadata for the organization"}),enabled_connections:o.z.array(N_).default([]).optional().openapi({description:"List of enabled connections for the organization"}),token_quota:C_}),fr=o.z.object({...Oa.shape,...Zi.shape,id:o.z.string()}),z_=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"})}),kv=o.z.object({...z_.shape,...Zi.shape,id:o.z.string()});function Nv(t){const[e,n]=t.split("|");if(!e||!n)throw new Error(`Invalid user_id: ${t}`);return{connection:e,id:n}}const wh={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 vh(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 Cv=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:ta}},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(wh)}).openapi(o.createRoute({tags:["branding"],method:"patch",path:"/default",request:{body:{content:{"application/json":{schema:ta.deepPartial()}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:ta}},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=vh(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=vh(wh,e),i=await t.env.data.themes.create(t.var.tenant_id,r);return t.json(i)}}),zv={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"}},Iv=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:ku}},description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.branding.get(e);return n?t.json(n):t.json(zv)}).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(ku.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");return await t.env.data.branding.set(e,n),t.text("OK")}).route("/themes",Cv);var E=class extends Error{constructor(e=500,n){super(n==null?void 0:n.message,{cause:n==null?void 0:n.cause});be(this,"res");be(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})}},Lr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function I_(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Tv(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 Ov(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 T_={exports:{}};const Dv={},Rv=Object.freeze(Object.defineProperty({__proto__:null,default:Dv},Symbol.toStringTag,{value:"Module"})),Oc=Tv(Rv);(function(t){/**
|
|
1
|
+
"use strict";var Lw=Object.defineProperty;var Fw=(t,e,n)=>e in t?Lw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var be=(t,e,n)=>Fw(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@hono/zod-openapi"),Se=t=>typeof t=="string",mo=()=>{let t,e;const n=new Promise((r,i)=>{t=r,e=i});return n.resolve=t,n.reject=e,n},ah=t=>t==null?"":""+t,Uw=(t,e,n)=>{t.forEach(r=>{e[r]&&(n[r]=e[r])})},Mw=/###/g,ch=t=>t&&t.indexOf("###")>-1?t.replace(Mw,"."):t,lh=t=>!t||Se(t),So=(t,e,n)=>{const r=Se(e)?e.split("."):e;let i=0;for(;i<r.length-1;){if(lh(t))return{};const s=ch(r[i]);!t[s]&&n&&(t[s]=new n),Object.prototype.hasOwnProperty.call(t,s)?t=t[s]:t={},++i}return lh(t)?{}:{obj:t,k:ch(r[i])}},uh=(t,e,n)=>{const{obj:r,k:i}=So(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),l=So(t,a,Object);for(;l.obj===void 0&&a.length;)s=`${a[a.length-1]}.${s}`,a=a.slice(0,a.length-1),l=So(t,a,Object),l!=null&&l.obj&&typeof l.obj[`${l.k}.${s}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${s}`]=n},qw=(t,e,n,r)=>{const{obj:i,k:s}=So(t,e,Object);i[s]=i[s]||[],i[s].push(n)},wa=(t,e)=>{const{obj:n,k:r}=So(t,e);if(n&&Object.prototype.hasOwnProperty.call(n,r))return n[r]},Vw=(t,e,n)=>{const r=wa(t,n);return r!==void 0?r:wa(e,n)},Tm=(t,e,n)=>{for(const r in e)r!=="__proto__"&&r!=="constructor"&&(r in t?Se(t[r])||t[r]instanceof String||Se(e[r])||e[r]instanceof String?n&&(t[r]=e[r]):Tm(t[r],e[r],n):t[r]=e[r]);return t},fi=t=>t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var Hw={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const Kw=t=>Se(t)?t.replace(/[&<>"'\/]/g,e=>Hw[e]):t;class Gw{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 Ww=[" ",",","?","!",";"],Xw=new Gw(20),Jw=(t,e,n)=>{e=e||"",n=n||"";const r=Ww.filter(a=>e.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const i=Xw.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},Su=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,l="";for(let u=s;u<r.length;++u)if(u!==s&&(l+=n),l+=r[u],a=i[l],a!==void 0){if(["string","number","boolean"].indexOf(typeof a)>-1&&u<r.length-1)continue;s+=u-s+1;break}i=a}return i},va=t=>t==null?void 0:t.replace("_","-"),Yw={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 ba{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||Yw,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:(Se(e[0])&&(e[0]=`${r}${this.prefix} ${e[0]}`),this.logger[n](e))}create(e){return new ba(this.logger,{prefix:`${this.prefix}:${e}:`,...this.options})}clone(e){return e=e||this.options,e.prefix=e.prefix||this.prefix,new ba(this.logger,e)}}var Nn=new ba;class kc{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[l,u]=a;for(let d=0;d<u;d++)l(...r)}),this.observers["*"]&&Array.from(this.observers["*"].entries()).forEach(a=>{let[l,u]=a;for(let d=0;d<u;d++)l.apply(l,[e,...r])})}}class dh extends kc{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,p;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 l;e.indexOf(".")>-1?l=e.split("."):(l=[e,n],r&&(Array.isArray(r)?l.push(...r):Se(r)&&s?l.push(...r.split(s)):l.push(r)));const u=wa(this.data,l);return!u&&!n&&!r&&e.indexOf(".")>-1&&(e=l[0],n=l[1],r=l.slice(2).join(".")),u||!a||!Se(r)?u:Su((p=(d=this.data)==null?void 0:d[e])==null?void 0:p[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 l=[e,n];r&&(l=l.concat(a?r.split(a):r)),e.indexOf(".")>-1&&(l=e.split("."),i=n,n=l[1]),this.addNamespaces(n),uh(this.data,l,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)(Se(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},l=[e,n];e.indexOf(".")>-1&&(l=e.split("."),i=r,r=n,n=l[1]),this.addNamespaces(n);let u=wa(this.data,l)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),i?Tm(u,r,s):u={...u,...r},uh(this.data,l,u),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 Om={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 ph={};class $a extends kc{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=Nn.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,l=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!Jw(e,r,i);if(a&&!l){const u=e.match(this.interpolator.nestingRegexp);if(u&&u.length>0)return{key:e,namespaces:Se(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:Se(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:l}=this.extractFromKey(e[e.length-1],n),u=l[l.length-1],d=n.lng||this.language,p=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if((d==null?void 0:d.toLowerCase())==="cimode"){if(p){const q=n.nsSeparator||this.options.nsSeparator;return i?{res:`${u}${q}${a}`,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:u,usedParams:this.getUsedParamsDetails(n)}:`${u}${q}${a}`}return i?{res:a,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:u,usedParams:this.getUsedParamsDetails(n)}:a}const h=this.resolve(e,n);let g=h==null?void 0:h.res;const $=(h==null?void 0:h.usedKey)||a,A=(h==null?void 0:h.exactUsedKey)||a,z=Object.prototype.toString.apply(g),T=["[object Number]","[object Function]","[object RegExp]"],O=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,x=!this.i18nFormat||this.i18nFormat.handleAsObject,U=!Se(g)&&typeof g!="boolean"&&typeof g!="number";if(x&&g&&U&&T.indexOf(z)<0&&!(Se(O)&&Array.isArray(g))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const q=this.options.returnedObjectHandler?this.options.returnedObjectHandler($,g,{...n,ns:l}):`key '${a} (${this.language})' returned an object instead of string.`;return i?(h.res=q,h.usedParams=this.getUsedParamsDetails(n),h):q}if(s){const q=Array.isArray(g),F=q?[]:{},H=q?A:$;for(const G in g)if(Object.prototype.hasOwnProperty.call(g,G)){const Y=`${H}${s}${G}`;F[G]=this.translate(Y,{...n,joinArrays:!1,ns:l}),F[G]===Y&&(F[G]=g[G])}g=F}}else if(x&&Se(O)&&Array.isArray(g))g=g.join(O),g&&(g=this.extendTranslation(g,e,n,r));else{let q=!1,F=!1;const H=n.count!==void 0&&!Se(n.count),G=$a.hasDefaultValue(n),Y=H?this.pluralResolver.getSuffix(d,n.count,n):"",J=n.ordinal&&H?this.pluralResolver.getSuffix(d,n.count,{ordinal:!1}):"",Ae=H&&!n.ordinal&&n.count===0,R=Ae&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${Y}`]||n[`defaultValue${J}`]||n.defaultValue;!this.isValidLookup(g)&&G&&(q=!0,g=R),this.isValidLookup(g)||(F=!0,g=a);const j=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&F?void 0:g,N=G&&R!==g&&this.options.updateMissing;if(F||q||N){if(this.logger.log(N?"updateKey":"missingKey",d,u,a,N?R:g),s){const de=this.resolve(a,{...n,keySeparator:!1});de&&de.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 k=[];const B=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&B&&B[0])for(let de=0;de<B.length;de++)k.push(B[de]);else this.options.saveMissingTo==="all"?k=this.languageUtils.toResolveHierarchy(n.lng||this.language):k.push(n.lng||this.language);const K=(de,ie,ve)=>{var Q;const ke=G&&ve!==g?ve:j;this.options.missingKeyHandler?this.options.missingKeyHandler(de,u,ie,ke,N,n):(Q=this.backendConnector)!=null&&Q.saveMissing&&this.backendConnector.saveMissing(de,u,ie,ke,N,n),this.emit("missingKey",de,u,ie,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&H?k.forEach(de=>{const ie=this.pluralResolver.getSuffixes(de,n);Ae&&n[`defaultValue${this.options.pluralSeparator}zero`]&&ie.indexOf(`${this.options.pluralSeparator}zero`)<0&&ie.push(`${this.options.pluralSeparator}zero`),ie.forEach(ve=>{K([de],a+ve,n[`defaultValue${ve}`]||R)})}):K(k,a,R))}g=this.extendTranslation(g,e,n,h,r),F&&g===a&&this.options.appendNamespaceToMissingKey&&(g=`${u}:${a}`),(F||q)&&this.options.parseMissingKeyHandler&&(g=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${u}:${a}`:a,q?g:void 0))}return i?(h.res=g,h.usedParams=this.getUsedParamsDetails(n),h):g}extendTranslation(e,n,r,i,s){var d,p;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 h=Se(e)&&(((p=r==null?void 0:r.interpolation)==null?void 0:p.skipOnVariables)!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let g;if(h){const A=e.match(this.interpolator.nestingRegexp);g=A&&A.length}let $=r.replace&&!Se(r.replace)?r.replace:r;if(this.options.interpolation.defaultVariables&&($={...this.options.interpolation.defaultVariables,...$}),e=this.interpolator.interpolate(e,$,r.lng||this.language||i.usedLng,r),h){const A=e.match(this.interpolator.nestingRegexp),z=A&&A.length;g<z&&(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 A=arguments.length,z=new Array(A),T=0;T<A;T++)z[T]=arguments[T];return(s==null?void 0:s[0])===z[0]&&!r.context?(a.logger.warn(`It seems you are nesting recursively key: ${z[0]} in key: ${n[0]}`),null):a.translate(...z,n)},r)),r.interpolation&&this.interpolator.reset()}const l=r.postProcess||this.options.postProcess,u=Se(l)?[l]:l;return e!=null&&(u!=null&&u.length)&&r.applyPostProcessor!==!1&&(e=Om.handle(u,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,l;return Se(e)&&(e=[e]),e.forEach(u=>{if(this.isValidLookup(r))return;const d=this.extractFromKey(u,n),p=d.key;i=p;let h=d.namespaces;this.options.fallbackNS&&(h=h.concat(this.options.fallbackNS));const g=n.count!==void 0&&!Se(n.count),$=g&&!n.ordinal&&n.count===0,A=n.context!==void 0&&(Se(n.context)||typeof n.context=="number")&&n.context!=="",z=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);h.forEach(T=>{var O,x;this.isValidLookup(r)||(l=T,!ph[`${z[0]}-${T}`]&&((O=this.utils)!=null&&O.hasLoadedNamespace)&&!((x=this.utils)!=null&&x.hasLoadedNamespace(l))&&(ph[`${z[0]}-${T}`]=!0,this.logger.warn(`key "${i}" for languages "${z.join(", ")}" won't get resolved as namespace "${l}" 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!!!")),z.forEach(U=>{var H;if(this.isValidLookup(r))return;a=U;const q=[p];if((H=this.i18nFormat)!=null&&H.addLookupKeys)this.i18nFormat.addLookupKeys(q,p,U,T,n);else{let G;g&&(G=this.pluralResolver.getSuffix(U,n.count,n));const Y=`${this.options.pluralSeparator}zero`,J=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(g&&(q.push(p+G),n.ordinal&&G.indexOf(J)===0&&q.push(p+G.replace(J,this.options.pluralSeparator)),$&&q.push(p+Y)),A){const Ae=`${p}${this.options.contextSeparator}${n.context}`;q.push(Ae),g&&(q.push(Ae+G),n.ordinal&&G.indexOf(J)===0&&q.push(Ae+G.replace(J,this.options.pluralSeparator)),$&&q.push(Ae+Y))}}let F;for(;F=q.pop();)this.isValidLookup(r)||(s=F,r=this.getResource(U,T,F,n))}))})}),{res:r,usedKey:i,exactUsedKey:s,usedLng:a,usedNS:l}}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&&!Se(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 fh{constructor(e){this.options=e,this.supportedLngs=this.options.supportedLngs||!1,this.logger=Nn.create("languageUtils")}getScriptPartFromCode(e){if(e=va(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=va(e),!e||e.indexOf("-")<0)return e;const n=e.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(e){if(Se(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)),Se(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 Se(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))):Se(e)&&s(this.formatLanguageCode(e)),r.forEach(a=>{i.indexOf(a)<0&&s(this.formatLanguageCode(a))}),i}}const hh={zero:0,one:1,two:2,few:3,many:4,other:5},gh={select:t=>t===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class Zw{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=e,this.options=n,this.logger=Nn.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=va(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!"),gh;if(!e.match(/-|_/))return gh;const u=this.languageUtils.getLanguagePartFromCode(e);a=this.getRule(u,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)=>hh[i]-hh[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 mh=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=Vw(t,e,n);return!s&&i&&Se(n)&&(s=Su(t,n,r),s===void 0&&(s=Su(e,n,r))),s},Gl=t=>t.replace(/\$/g,"$$$$");class Qw{constructor(){var n;let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=Nn.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:l,suffixEscaped:u,formatSeparator:d,unescapeSuffix:p,unescapePrefix:h,nestingPrefix:g,nestingPrefixEscaped:$,nestingSuffix:A,nestingSuffixEscaped:z,nestingOptionsSeparator:T,maxReplaces:O,alwaysFormat:x}=e.interpolation;this.escape=n!==void 0?n:Kw,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=i!==void 0?i:!1,this.prefix=s?fi(s):a||"{{",this.suffix=l?fi(l):u||"}}",this.formatSeparator=d||",",this.unescapePrefix=p?"":h||"-",this.unescapeSuffix=this.unescapePrefix?"":p||"",this.nestingPrefix=g?fi(g):$||fi("$t("),this.nestingSuffix=A?fi(A):z||fi(")"),this.nestingOptionsSeparator=T||",",this.maxReplaces=O||1e3,this.alwaysFormat=x!==void 0?x:!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 $;let s,a,l;const u=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},d=A=>{if(A.indexOf(this.formatSeparator)<0){const x=mh(n,u,A,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(x,void 0,r,{...i,...n,interpolationkey:A}):x}const z=A.split(this.formatSeparator),T=z.shift().trim(),O=z.join(this.formatSeparator).trim();return this.format(mh(n,u,T,this.options.keySeparator,this.options.ignoreJSONStructure),O,r,{...i,...n,interpolationkey:T})};this.resetRegExp();const p=(i==null?void 0:i.missingInterpolationHandler)||this.options.missingInterpolationHandler,h=(($=i==null?void 0:i.interpolation)==null?void 0:$.skipOnVariables)!==void 0?i.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:A=>Gl(A)},{regex:this.regexp,safeValue:A=>this.escapeValue?Gl(this.escape(A)):Gl(A)}].forEach(A=>{for(l=0;s=A.regex.exec(e);){const z=s[1].trim();if(a=d(z),a===void 0)if(typeof p=="function"){const O=p(e,s,i);a=Se(O)?O:""}else if(i&&Object.prototype.hasOwnProperty.call(i,z))a="";else if(h){a=s[0];continue}else this.logger.warn(`missed to pass in variable ${z} for interpolating ${e}`),a="";else!Se(a)&&!this.useRawValueToEscape&&(a=ah(a));const T=A.safeValue(a);if(e=e.replace(s[0],T),h?(A.regex.lastIndex+=a.length,A.regex.lastIndex-=s[0].length):A.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),e}nest(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,s,a;const l=(u,d)=>{const p=this.nestingOptionsSeparator;if(u.indexOf(p)<0)return u;const h=u.split(new RegExp(`${p}[ ]*{`));let g=`{${h[1]}`;u=h[0],g=this.interpolate(g,a);const $=g.match(/'/g),A=g.match(/"/g);((($==null?void 0:$.length)??0)%2===0&&!A||A.length%2!==0)&&(g=g.replace(/'/g,'"'));try{a=JSON.parse(g),d&&(a={...d,...a})}catch(z){return this.logger.warn(`failed parsing options string in nesting for key ${u}`,z),`${u}${p}${g}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,u};for(;i=this.nestingRegexp.exec(e);){let u=[];a={...r},a=a.replace&&!Se(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 p=i[1].split(this.formatSeparator).map(h=>h.trim());i[1]=p.shift(),u=p,d=!0}if(s=n(l.call(this,i[1].trim(),a),a),s&&i[0]===e&&!Se(s))return s;Se(s)||(s=ah(s)),s||(this.logger.warn(`missed to resolve ${i[1]} for nesting ${e}`),s=""),d&&(s=u.reduce((p,h)=>this.format(p,h,r.lng,{...r,interpolationkey:i[1].trim()}),s.trim())),e=e.replace(i[0],s),this.regexp.lastIndex=0}return e}}const ev=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[l,...u]=a.split(":"),d=u.join(":").trim().replace(/^'+|'+$/g,""),p=l.trim();n[p]||(n[p]=d),d==="false"&&(n[p]=!1),d==="true"&&(n[p]=!0),isNaN(d)||(n[p]=parseInt(d,10))}})}return{formatName:e,formatOptions:n}},hi=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 l=e[a];return l||(l=t(va(r),i),e[a]=l),l(n)}};class tv{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=Nn.create("formatter"),this.options=e,this.formats={number:hi((n,r)=>{const i=new Intl.NumberFormat(n,{...r});return s=>i.format(s)}),currency:hi((n,r)=>{const i=new Intl.NumberFormat(n,{...r,style:"currency"});return s=>i.format(s)}),datetime:hi((n,r)=>{const i=new Intl.DateTimeFormat(n,{...r});return s=>i.format(s)}),relativetime:hi((n,r)=>{const i=new Intl.RelativeTimeFormat(n,{...r});return s=>i.format(s,r.range||"day")}),list:hi((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()]=hi(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(l=>l.indexOf(")")>-1)){const l=s.findIndex(u=>u.indexOf(")")>-1);s[0]=[s[0],...s.splice(1,l)].join(this.formatSeparator)}return s.reduce((l,u)=>{var h;const{formatName:d,formatOptions:p}=ev(u);if(this.formats[d]){let g=l;try{const $=((h=i==null?void 0:i.formatParams)==null?void 0:h[i.interpolationkey])||{},A=$.locale||$.lng||i.locale||i.lng||r;g=this.formats[d](l,A,{...p,...i,...$})}catch($){this.logger.warn($)}return g}else this.logger.warn(`there was no format function for ${d}`);return l},e)}}const nv=(t,e)=>{t.pending[e]!==void 0&&(delete t.pending[e],t.pendingCount--)};class rv extends kc{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=Nn.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={},l={},u={};return e.forEach(d=>{let p=!0;n.forEach(h=>{const g=`${d}|${h}`;!r.reload&&this.store.hasResourceBundle(d,h)?this.state[g]=2:this.state[g]<0||(this.state[g]===1?a[g]===void 0&&(a[g]=!0):(this.state[g]=1,p=!1,a[g]===void 0&&(a[g]=!0),s[g]===void 0&&(s[g]=!0),u[h]===void 0&&(u[h]=!0)))}),p||(l[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(l),toLoadNamespaces:Object.keys(u)}}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 l={};this.queue.forEach(u=>{qw(u.loaded,[s],a),nv(u,e),n&&u.errors.push(n),u.pendingCount===0&&!u.done&&(Object.keys(u.loaded).forEach(d=>{l[d]||(l[d]={});const p=u.loaded[d];p.length&&p.forEach(h=>{l[d][h]===void 0&&(l[d][h]=!0)})}),u.done=!0,u.errors.length?u.callback(u.errors):u.callback())}),this.emit("loaded",l),this.queue=this.queue.filter(u=>!u.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 l=(d,p)=>{if(this.readingCalls--,this.waitingReads.length>0){const h=this.waitingReads.shift();this.read(h.lng,h.ns,h.fcName,h.tried,h.wait,h.callback)}if(d&&p&&i<this.maxRetries){setTimeout(()=>{this.read.call(this,e,n,r,i+1,s*2,a)},s);return}a(d,p)},u=this.backend[r].bind(this.backend);if(u.length===2){try{const d=u(e,n);d&&typeof d.then=="function"?d.then(p=>l(null,p)).catch(l):l(null,d)}catch(d){l(d)}return}return u(e,n,l)}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();Se(e)&&(e=this.languageUtils.toResolveHierarchy(e)),Se(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,l)=>{a&&this.logger.warn(`${n}loading namespace ${s} for language ${i} failed`,a),!a&&l&&this.logger.log(`${n}loaded namespace ${s} for language ${i}`,l),this.loaded(e,a,l)})}saveMissing(e,n,r,i,s){var u,d,p,h,g;let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},l=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if((d=(u=this.services)==null?void 0:u.utils)!=null&&d.hasLoadedNamespace&&!((h=(p=this.services)==null?void 0:p.utils)!=null&&h.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((g=this.backend)!=null&&g.create){const $={...a,isUpdate:s},A=this.backend.create.bind(this.backend);if(A.length<6)try{let z;A.length===5?z=A(e,n,r,i,$):z=A(e,n,r,i),z&&typeof z.then=="function"?z.then(T=>l(null,T)).catch(l):l(null,z)}catch(z){l(z)}else A(e,n,r,i,l,$)}!e||!e[0]||this.store.addResource(e[0],n,r,i)}}}const _h=()=>({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]),Se(t[1])&&(e.defaultValue=t[1]),Se(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}}),yh=t=>{var e,n;return Se(t.ns)&&(t.ns=[t.ns]),Se(t.fallbackLng)&&(t.fallbackLng=[t.fallbackLng]),Se(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},Us=()=>{},iv=t=>{Object.getOwnPropertyNames(Object.getPrototypeOf(t)).forEach(n=>{typeof t[n]=="function"&&(t[n]=t[n].bind(t))})};class Ro extends kc{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=yh(e),this.services={},this.logger=Nn,this.modules={external:[]},iv(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&&(Se(n.ns)?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const i=_h();this.options={...i,...this.options,...yh(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=p=>p?typeof p=="function"?new p:p:null;if(!this.options.isClone){this.modules.logger?Nn.init(s(this.modules.logger),this.options):Nn.init(null,this.options);let p;this.modules.formatter?p=this.modules.formatter:p=tv;const h=new fh(this.options);this.store=new dh(this.options.resources,this.options);const g=this.services;g.logger=Nn,g.resourceStore=this.store,g.languageUtils=h,g.pluralResolver=new Zw(h,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),p&&(!this.options.interpolation.format||this.options.interpolation.format===i.interpolation.format)&&(g.formatter=s(p),g.formatter.init(g,this.options),this.options.interpolation.format=g.formatter.format.bind(g.formatter)),g.interpolator=new Qw(this.options),g.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},g.backendConnector=new rv(s(this.modules.backend),g.resourceStore,g,this.options),g.backendConnector.on("*",function($){for(var A=arguments.length,z=new Array(A>1?A-1:0),T=1;T<A;T++)z[T-1]=arguments[T];e.emit($,...z)}),this.modules.languageDetector&&(g.languageDetector=s(this.modules.languageDetector),g.languageDetector.init&&g.languageDetector.init(g,this.options.detection,this.options)),this.modules.i18nFormat&&(g.i18nFormat=s(this.modules.i18nFormat),g.i18nFormat.init&&g.i18nFormat.init(this)),this.translator=new $a(this.services,this.options),this.translator.on("*",function($){for(var A=arguments.length,z=new Array(A>1?A-1:0),T=1;T<A;T++)z[T-1]=arguments[T];e.emit($,...z)}),this.modules.external.forEach($=>{$.init&&$.init(this)})}if(this.format=this.options.interpolation.format,r||(r=Us),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const p=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);p.length>0&&p[0]!=="dev"&&(this.options.lng=p[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(p=>{this[p]=function(){return e.store[p](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(p=>{this[p]=function(){return e.store[p](...arguments),e}});const u=mo(),d=()=>{const p=(h,g)=>{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),u.resolve(g),r(h,g)};if(this.languages&&!this.isInitialized)return p(null,this.t.bind(this));this.changeLanguage(this.options.lng,p)};return this.options.resources||!this.options.initAsync?d():setTimeout(d,0),u}loadResources(e){var s,a;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Us;const i=Se(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 l=[],u=d=>{if(!d||d==="cimode")return;this.services.languageUtils.toResolveHierarchy(d).forEach(h=>{h!=="cimode"&&l.indexOf(h)<0&&l.push(h)})};i?u(i):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(p=>u(p)),(a=(s=this.options.preload)==null?void 0:s.forEach)==null||a.call(s,d=>u(d)),this.services.backendConnector.load(l,this.options.ns,d=>{!d&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(d)})}else r(null)}reloadResources(e,n,r){const i=mo();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=Us),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"&&Om.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=mo();this.emit("languageChanging",e);const s=u=>{this.language=u,this.languages=this.services.languageUtils.toResolveHierarchy(u),this.resolvedLanguage=void 0,this.setResolvedLanguage(u)},a=(u,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(u,function(){return r.t(...arguments)})},l=u=>{var p,h;!e&&!u&&this.services.languageDetector&&(u=[]);const d=Se(u)?u:this.services.languageUtils.getBestMatchFromCodes(u);d&&(this.language||s(d),this.translator.language||this.translator.changeLanguage(d),(h=(p=this.services.languageDetector)==null?void 0:p.cacheUserLanguage)==null||h.call(p,d)),this.loadResources(d,g=>{a(g,d)})};return!e&&this.services.languageDetector&&!this.services.languageDetector.async?l(this.services.languageDetector.detect()):!e&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(l):this.services.languageDetector.detect(l):l(e),i}getFixedT(e,n,r){var i=this;const s=function(a,l){let u;if(typeof l!="object"){for(var d=arguments.length,p=new Array(d>2?d-2:0),h=2;h<d;h++)p[h-2]=arguments[h];u=i.options.overloadTranslationOptionHandler([a,l].concat(p))}else u={...l};u.lng=u.lng||s.lng,u.lngs=u.lngs||s.lngs,u.ns=u.ns||s.ns,u.keyPrefix!==""&&(u.keyPrefix=u.keyPrefix||r||s.keyPrefix);const g=i.options.keySeparator||".";let $;return u.keyPrefix&&Array.isArray(a)?$=a.map(A=>`${u.keyPrefix}${g}${A}`):$=u.keyPrefix?`${u.keyPrefix}${g}${a}`:a,i.t($,u)};return Se(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=(l,u)=>{const d=this.services.backendConnector.state[`${l}|${u}`];return d===-1||d===0||d===2};if(n.precheck){const l=n.precheck(this,a);if(l!==void 0)return l}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=mo();return this.options.ns?(Se(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=mo();Se(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 fh(_h());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 Ro(e,n)}cloneInstance(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Us;const r=e.forkResourceStore;r&&delete e.forkResourceStore;const i={...this.options,...e,isClone:!0},s=new Ro(i);if((e.debug!==void 0||e.prefix!==void 0)&&(s.logger=s.logger.clone(e)),["store","services","language"].forEach(l=>{s[l]=this[l]}),s.services={...this.services},s.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},r){const l=Object.keys(this.store.data).reduce((u,d)=>(u[d]={...this.store.data[d]},Object.keys(u[d]).reduce((p,h)=>(p[h]={...u[d][h]},p),{})),{});s.store=new dh(l,i),s.services.resourceStore=s.store}return s.translator=new $a(s.services,i),s.translator.on("*",function(l){for(var u=arguments.length,d=new Array(u>1?u-1:0),p=1;p<u;p++)d[p-1]=arguments[p];s.emit(l,...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 P=Ro.createInstance();P.createInstance=Ro.createInstance;P.createInstance;P.dir;P.init;P.loadResources;P.reloadResources;P.use;P.changeLanguage;P.getFixedT;const xe=P.t;P.exists;P.setDefaultNamespace;P.hasLoadedNamespace;P.loadNamespaces;P.loadLanguages;var Dm=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,l){var p;function u(h,g){a.res.headers.set(h,g)}const d=r(a.req.header("origin")||"",a);if(d&&u("Access-Control-Allow-Origin",d),n.origin!=="*"){const h=a.req.header("Vary");h?u("Vary",h):u("Vary","Origin")}if(n.credentials&&u("Access-Control-Allow-Credentials","true"),(p=n.exposeHeaders)!=null&&p.length&&u("Access-Control-Expose-Headers",n.exposeHeaders.join(",")),a.req.method==="OPTIONS"){n.maxAge!=null&&u("Access-Control-Max-Age",n.maxAge.toString());const h=i(a.req.header("origin")||"",a);h.length&&u("Access-Control-Allow-Methods",h.join(","));let g=n.allowHeaders;if(!(g!=null&&g.length)){const $=a.req.header("Access-Control-Request-Headers");$&&(g=$.split(/\s*,\s*/))}return g!=null&&g.length&&(u("Access-Control-Allow-Headers",g.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 l()}};const zt=o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()}),Zi=o.z.object({created_at:o.z.string(),updated_at:o.z.string()}),Rm=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()),jm=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:Rm.optional()}),Nc=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()}),xa=Nc.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()}),yp=o.z.object({...xa.shape,...Zi.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(jm).optional()}),kn=yp,ov=Nc.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()),sv="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let av=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=sv[n[t]&63];return e};const Aa=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(()=>av()).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()}),Rr=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),...Aa.shape}),Ea=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."})}),jr=o.z.object({id:o.z.string().openapi({description:"ID of the client grant."}),...Ea.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),cv=o.z.array(jr),Qi=o.z.object({x:o.z.number(),y:o.z.number()});var wp=(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))(wp||{}),vp=(t=>(t.BLOCK="BLOCK",t.FIELD="FIELD",t))(vp||{});const Cc=o.z.object({id:o.z.string(),category:o.z.nativeEnum(vp),type:o.z.nativeEnum(wp)}),Pm=Cc.extend({category:o.z.literal("BLOCK"),type:o.z.literal("RICH_TEXT"),config:o.z.object({content:o.z.string()}).passthrough()}),Bm=Cc.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()}),Lm=Cc.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()}),Fm=Cc.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()}),Um=o.z.object({id:o.z.string(),category:o.z.string(),type:o.z.string()}).passthrough(),Mm=o.z.union([Pm,Bm,Lm,Fm,Um]);var qm=(t=>(t.STEP="STEP",t.FLOW="FLOW",t.CONDITION="CONDITION",t.ACTION="ACTION",t))(qm||{});const Vm=o.z.object({id:o.z.string(),type:o.z.literal("STEP"),coordinates:Qi,alias:o.z.string().optional(),config:o.z.object({components:o.z.array(Mm),next_node:o.z.string()}).passthrough()}),Hm=o.z.object({id:o.z.string(),type:o.z.literal("FLOW"),coordinates:Qi,alias:o.z.string().optional(),config:o.z.object({flow_id:o.z.string(),next_node:o.z.string()})}),Km=o.z.object({id:o.z.string(),type:o.z.string(),coordinates:Qi}).passthrough(),Gm=o.z.union([Vm,Hm,Km]),Wm=o.z.object({next_node:o.z.string(),coordinates:Qi}).passthrough(),Xm=o.z.object({resume_flow:o.z.boolean().optional(),coordinates:Qi}).passthrough(),Jm=o.z.object({id:o.z.string(),name:o.z.string(),languages:o.z.object({primary:o.z.string()}).passthrough(),nodes:o.z.array(Gm),start:Wm,ending:Xm,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(),lv=Jm.omit({id:!0,created_at:!0,updated_at:!0});var Yt=(t=>(t.TOKEN="token",t.TOKEN_ID_TOKEN="token id_token",t.CODE="code",t))(Yt||{}),zn=(t=>(t.QUERY="query",t.FRAGMENT="fragment",t.FORM_POST="form_post",t.WEB_MESSAGE="web_message",t.SAML_POST="saml_post",t))(zn||{}),zc=(t=>(t.S256="S256",t.Plain="plain",t))(zc||{});const jo=o.z.object({client_id:o.z.string(),act_as:o.z.string().optional(),response_type:o.z.nativeEnum(Yt).optional(),response_mode:o.z.nativeEnum(zn).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(zc).optional(),code_challenge:o.z.string().optional(),username:o.z.string().optional(),ui_locales:o.z.string().optional(),vendor_id:o.z.string().optional()}),ku=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(),font:o.z.object({url:o.z.string()}).optional()}),Ni=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()}),Sa=o.z.object({id:o.z.string().optional(),name:o.z.string(),strategy:o.z.string(),options:Ni.default({}),enabled_clients:o.z.array(o.z.string()).default([]).optional(),response_type:o.z.custom().optional(),response_mode:o.z.custom().optional()}),cn=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(Sa.shape),ka=o.z.object({name:o.z.string(),audience:o.z.string(),sender_email:o.z.string().email(),sender_name:o.z.string(),support_url:o.z.string().url().optional(),logo:o.z.string().url().optional(),primary_color:o.z.string().optional(),secondary_color:o.z.string().optional(),language:o.z.string().optional(),id:o.z.string().optional()}),Ci=o.z.object({created_at:o.z.string().transform(t=>t===null?"":t),updated_at:o.z.string().transform(t=>t===null?"":t),...ka.shape,id:o.z.string()});o.z.object({...Rr.shape,tenant:Ci,connections:o.z.array(cn),disable_sign_ups:o.z.boolean(),email_validation:o.z.string()});const Ym=o.z.enum(["password_reset","email_verification","otp","authorization_code","oauth2_state","ticket"]),Zm=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:Ym,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()}),uv=o.z.object({...Zm.shape,created_at:o.z.string()}),bp=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()}),Qm=o.z.object({name:o.z.literal("txt"),record:o.z.string(),domain:o.z.string()}),pr=o.z.object({...bp.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(Qm)}).optional(),tls_policy:o.z.string().optional()}),dv=pr.extend({tenant_id:o.z.string()}),pv=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()}),e_=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)})]),Na=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(e_),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)"}),Ai=o.z.object({...Zi.shape,...Na.shape,id:o.z.string()}),t_=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),n_=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),Ic={enabled:o.z.boolean().default(!1),synchronous:o.z.boolean().default(!1),priority:o.z.number().optional(),hook_id:o.z.string().optional()},fv=o.z.object({...Ic,trigger_id:t_,url:o.z.string()}),hv=o.z.object({...Ic,trigger_id:n_,form_id:o.z.string()}),ea=o.z.union([fv,hv]),gv=o.z.object({...Ic,trigger_id:t_,...Zi.shape,hook_id:o.z.string(),url:o.z.string()}),mv=o.z.object({...Ic,trigger_id:n_,...Zi.shape,hook_id:o.z.string(),form_id:o.z.string()}),Ei=o.z.union([gv,mv]),$p=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()}),r_=o.z.object({keys:o.z.array($p)}),Nu=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())}),i_=o.z.object({csrf_token:o.z.string(),auth0Client:o.z.string().optional(),authParams:jo,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"}),_v=o.z.object({...i_.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()}),Le={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"},yv=o.z.string().refine(t=>Object.values(Le).includes(t),{message:"Invalid log type"}),o_=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()}),Ca=o.z.object({type:yv,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:o_.optional()}),s_=o.z.object({user_id:o.z.string(),password:o.z.string(),algorithm:o.z.enum(["bcrypt","argon2id"]).default("argon2id")}),wv=o.z.object({...s_.shape,created_at:o.z.string(),updated_at:o.z.string()}),a_=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")}),c_=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:a_.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")}),Tc=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),authenticated_at:o.z.string(),last_interaction_at:o.z.string(),...c_.shape}),Cu=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 an=(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))(an||{});const xp=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 l_=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()}),u_=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()}),Tr=o.z.object({bold:o.z.boolean(),size:o.z.number()}),d_=o.z.object({body_text:Tr,buttons_text:Tr,font_url:o.z.string(),input_labels:Tr,links:Tr,links_style:o.z.enum(["normal","underlined"]),reference_text_size:o.z.number(),subtitle:Tr,title:Tr}),p_=o.z.object({background_color:o.z.string(),background_image_url:o.z.string(),page_layout:o.z.enum(["center","left","right"])}),f_=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"])}),h_=o.z.object({borders:l_,colors:u_,displayName:o.z.string(),fonts:d_,page_background:p_,widget:f_}),ta=h_.extend({themeId:o.z.string()}),na=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()}),ra=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()}),Ap=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:a_,resource_servers:o.z.array(o.z.object({audience:o.z.string(),scopes:o.z.string()})),rotating:o.z.boolean()}),vv=o.z.object({created_at:o.z.string(),...Ap.shape}),bv=o.z.object({to:o.z.string(),message:o.z.string()}),$v=o.z.object({name:o.z.string(),options:o.z.object({})}),g_=o.z.object({value:o.z.string(),description:o.z.string().optional()}),m_=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()}),za=o.z.object({name:o.z.string(),identifier:o.z.string(),scopes:o.z.array(g_).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:m_.optional()}),Pr=o.z.object({id:o.z.string().optional(),...za.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),xv=o.z.array(Pr),__=o.z.object({role_id:o.z.string(),resource_server_identifier:o.z.string(),permission_name:o.z.string()}),y_=o.z.object({...__.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Av=o.z.array(y_),w_=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()}),v_=o.z.array(w_),b_=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()}),$_=o.z.object({...b_.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Ev=o.z.array($_),x_=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()}),A_=o.z.array(x_),E_=o.z.object({user_id:o.z.string(),role_id:o.z.string(),organization_id:o.z.string().optional()}),S_=o.z.object({...E_.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Sv=o.z.array(S_),Ia=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"})}),Br=o.z.object({id:o.z.string().openapi({description:"The unique identifier of the role"}),...Ia.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),Ta=o.z.array(Br),k_=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(),N_=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"})}),C_=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(),Oa=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:k_,metadata:o.z.record(o.z.any()).default({}).optional().openapi({description:"Custom metadata for the organization"}),enabled_connections:o.z.array(N_).default([]).optional().openapi({description:"List of enabled connections for the organization"}),token_quota:C_}),fr=o.z.object({...Oa.shape,...Zi.shape,id:o.z.string()}),z_=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"})}),kv=o.z.object({...z_.shape,...Zi.shape,id:o.z.string()});function Nv(t){const[e,n]=t.split("|");if(!e||!n)throw new Error(`Invalid user_id: ${t}`);return{connection:e,id:n}}const wh={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 vh(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 Cv=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:ta}},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(wh)}).openapi(o.createRoute({tags:["branding"],method:"patch",path:"/default",request:{body:{content:{"application/json":{schema:ta.deepPartial()}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:ta}},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=vh(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=vh(wh,e),i=await t.env.data.themes.create(t.var.tenant_id,r);return t.json(i)}}),zv={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"}},Iv=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:ku}},description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.branding.get(e);return n?t.json(n):t.json(zv)}).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(ku.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");return await t.env.data.branding.set(e,n),t.text("OK")}).route("/themes",Cv);var E=class extends Error{constructor(e=500,n){super(n==null?void 0:n.message,{cause:n==null?void 0:n.cause});be(this,"res");be(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})}},Lr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function I_(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Tv(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 Ov(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 T_={exports:{}};const Dv={},Rv=Object.freeze(Object.defineProperty({__proto__:null,default:Dv},Symbol.toStringTag,{value:"Module"})),Oc=Tv(Rv);(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 Ov=="function"&&t&&t.exports?t.exports=n():(e.dcodeIO=e.dcodeIO||{}).bcrypt=n()})(Lr,function(){var e={},n=null;function r(R){if(t&&t.exports)try{return Oc.randomBytes(R)}catch{}try{var L;return(self.crypto||self.msCrypto).getRandomValues(L=new Uint32Array(R)),Array.prototype.slice.call(L)}catch{}if(!n)throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");return n(R)}var i=!1;try{r(1),i=!0}catch{}n=null,e.setRandomFallback=function(R){n=R},e.genSaltSync=function(R,L){if(R=R||z,typeof R!="number")throw Error("Illegal arguments: "+typeof R+", "+typeof L);R<4?R=4:R>31&&(R=31);var j=[];return j.push("$2a$"),R<10&&j.push("0"),j.push(R.toString()),j.push("$"),j.push(h(r(A),A)),j.join("")},e.genSalt=function(R,L,j){if(typeof L=="function"&&(j=L,L=void 0),typeof R=="function"&&(j=R,R=void 0),typeof R>"u")R=z;else if(typeof R!="number")throw Error("illegal arguments: "+typeof R);function N(k){a(function(){try{k(null,e.genSaltSync(R))}catch(B){k(B)}})}if(j){if(typeof j!="function")throw Error("Illegal callback: "+typeof j);N(j)}else return new Promise(function(k,B){N(function(H,de){if(H){B(H);return}k(de)})})},e.hashSync=function(R,L){if(typeof L>"u"&&(L=z),typeof L=="number"&&(L=e.genSaltSync(L)),typeof R!="string"||typeof L!="string")throw Error("Illegal arguments: "+typeof R+", "+typeof L);return Ae(R,L)},e.hash=function(R,L,j,N){function k(B){typeof R=="string"&&typeof L=="number"?e.genSalt(L,function(H,de){Ae(R,de,B,N)}):typeof R=="string"&&typeof L=="string"?Ae(R,L,B,N):a(B.bind(this,Error("Illegal arguments: "+typeof R+", "+typeof L)))}if(j){if(typeof j!="function")throw Error("Illegal callback: "+typeof j);k(j)}else return new Promise(function(B,H){k(function(de,ie){if(de){H(de);return}B(ie)})})};function s(R,L){for(var j=0,N=0,k=0,B=R.length;k<B;++k)R.charCodeAt(k)===L.charCodeAt(k)?++j:++N;return j<0?!1:N===0}e.compareSync=function(R,L){if(typeof R!="string"||typeof L!="string")throw Error("Illegal arguments: "+typeof R+", "+typeof L);return L.length!==60?!1:s(e.hashSync(R,L.substr(0,L.length-31)),L)},e.compare=function(R,L,j,N){function k(B){if(typeof R!="string"||typeof L!="string"){a(B.bind(this,Error("Illegal arguments: "+typeof R+", "+typeof L)));return}if(L.length!==60){a(B.bind(this,null,!1));return}e.hash(R,L.substr(0,29),function(H,de){H?B(H):B(null,s(de,L))},N)}if(j){if(typeof j!="function")throw Error("Illegal callback: "+typeof j);k(j)}else return new Promise(function(B,H){k(function(de,ie){if(de){H(de);return}B(ie)})})},e.getRounds=function(R){if(typeof R!="string")throw Error("Illegal arguments: "+typeof R);return parseInt(R.split("$")[2],10)},e.getSalt=function(R){if(typeof R!="string")throw Error("Illegal arguments: "+typeof R);if(R.length!==60)throw Error("Illegal hash length: "+R.length+" != 60");return R.substring(0,29)};var a=typeof process<"u"&&process&&typeof process.nextTick=="function"?typeof setImmediate=="function"?setImmediate:process.nextTick:setTimeout;function l(R){var L=[],j=0;return $.encodeUTF16toUTF8(function(){return j>=R.length?null:R.charCodeAt(j++)},function(N){L.push(N)}),L}var u="./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],p=String.fromCharCode;function h(R,L){var j=0,N=[],k,B;if(L<=0||L>R.length)throw Error("Illegal len: "+L);for(;j<L;){if(k=R[j++]&255,N.push(u[k>>2&63]),k=(k&3)<<4,j>=L){N.push(u[k&63]);break}if(B=R[j++]&255,k|=B>>4&15,N.push(u[k&63]),k=(B&15)<<2,j>=L){N.push(u[k&63]);break}B=R[j++]&255,k|=B>>6&3,N.push(u[k&63]),N.push(u[B&63])}return N.join("")}function g(R,L){var j=0,N=R.length,k=0,B=[],H,de,ie,ve,ke,Q;if(L<=0)throw Error("Illegal len: "+L);for(;j<N-1&&k<L&&(Q=R.charCodeAt(j++),H=Q<d.length?d[Q]:-1,Q=R.charCodeAt(j++),de=Q<d.length?d[Q]:-1,!(H==-1||de==-1||(ke=H<<2>>>0,ke|=(de&48)>>4,B.push(p(ke)),++k>=L||j>=N)||(Q=R.charCodeAt(j++),ie=Q<d.length?d[Q]:-1,ie==-1)||(ke=(de&15)<<4>>>0,ke|=(ie&60)>>2,B.push(p(ke)),++k>=L||j>=N)));)Q=R.charCodeAt(j++),ve=Q<d.length?d[Q]:-1,ke=(ie&3)<<6>>>0,ke|=ve,B.push(p(ke)),++k;var ye=[];for(j=0;j<k;j++)ye.push(B[j].charCodeAt(0));return ye}var $=function(){var R={};return R.MAX_CODEPOINT=1114111,R.encodeUTF8=function(L,j){var N=null;for(typeof L=="number"&&(N=L,L=function(){return null});N!==null||(N=L())!==null;)N<128?j(N&127):N<2048?(j(N>>6&31|192),j(N&63|128)):N<65536?(j(N>>12&15|224),j(N>>6&63|128),j(N&63|128)):(j(N>>18&7|240),j(N>>12&63|128),j(N>>6&63|128),j(N&63|128)),N=null},R.decodeUTF8=function(L,j){for(var N,k,B,H,de=function(ie){ie=ie.slice(0,ie.indexOf(null));var ve=Error(ie.toString());throw ve.name="TruncatedError",ve.bytes=ie,ve};(N=L())!==null;)if(!(N&128))j(N);else if((N&224)===192)(k=L())===null&&de([N,k]),j((N&31)<<6|k&63);else if((N&240)===224)((k=L())===null||(B=L())===null)&&de([N,k,B]),j((N&15)<<12|(k&63)<<6|B&63);else if((N&248)===240)((k=L())===null||(B=L())===null||(H=L())===null)&&de([N,k,B,H]),j((N&7)<<18|(k&63)<<12|(B&63)<<6|H&63);else throw RangeError("Illegal starting byte: "+N)},R.UTF16toUTF8=function(L,j){for(var N,k=null;(N=k!==null?k:L())!==null;){if(N>=55296&&N<=57343&&(k=L())!==null&&k>=56320&&k<=57343){j((N-55296)*1024+k-56320+65536),k=null;continue}j(N)}k!==null&&j(k)},R.UTF8toUTF16=function(L,j){var N=null;for(typeof L=="number"&&(N=L,L=function(){return null});N!==null||(N=L())!==null;)N<=65535?j(N):(N-=65536,j((N>>10)+55296),j(N%1024+56320)),N=null},R.encodeUTF16toUTF8=function(L,j){R.UTF16toUTF8(L,function(N){R.encodeUTF8(N,j)})},R.decodeUTF8toUTF16=function(L,j){R.decodeUTF8(L,function(N){R.UTF8toUTF16(N,j)})},R.calculateCodePoint=function(L){return L<128?1:L<2048?2:L<65536?3:4},R.calculateUTF8=function(L){for(var j,N=0;(j=L())!==null;)N+=R.calculateCodePoint(j);return N},R.calculateUTF16asUTF8=function(L){var j=0,N=0;return R.UTF16toUTF8(L,function(k){++j,N+=R.calculateCodePoint(k)}),[j,N]},R}();Date.now=Date.now||function(){return+new Date};var A=16,z=10,T=16,O=100,x=[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],q=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892];function F(R,L,j,N){var k,B=R[L],H=R[L+1];return B^=j[0],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[1],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[2],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[3],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[4],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[5],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[6],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[7],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[8],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[9],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[10],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[11],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[12],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[13],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[14],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],H^=k^j[15],k=N[H>>>24],k+=N[256|H>>16&255],k^=N[512|H>>8&255],k+=N[768|H&255],B^=k^j[16],R[L]=H^j[T+1],R[L+1]=B,R}function K(R,L){for(var j=0,N=0;j<4;++j)N=N<<8|R[L]&255,L=(L+1)%R.length;return{key:N,offp:L}}function G(R,L,j){for(var N=0,k=[0,0],B=L.length,H=j.length,de,ie=0;ie<B;ie++)de=K(R,N),N=de.offp,L[ie]=L[ie]^de.key;for(ie=0;ie<B;ie+=2)k=F(k,0,L,j),L[ie]=k[0],L[ie+1]=k[1];for(ie=0;ie<H;ie+=2)k=F(k,0,L,j),j[ie]=k[0],j[ie+1]=k[1]}function Y(R,L,j,N){for(var k=0,B=[0,0],H=j.length,de=N.length,ie,ve=0;ve<H;ve++)ie=K(L,k),k=ie.offp,j[ve]=j[ve]^ie.key;for(k=0,ve=0;ve<H;ve+=2)ie=K(R,k),k=ie.offp,B[0]^=ie.key,ie=K(R,k),k=ie.offp,B[1]^=ie.key,B=F(B,0,j,N),j[ve]=B[0],j[ve+1]=B[1];for(ve=0;ve<de;ve+=2)ie=K(R,k),k=ie.offp,B[0]^=ie.key,ie=K(R,k),k=ie.offp,B[1]^=ie.key,B=F(B,0,j,N),N[ve]=B[0],N[ve+1]=B[1]}function J(R,L,j,N,k){var B=q.slice(),H=B.length,de;if(j<4||j>31)if(de=Error("Illegal number of rounds (4-31): "+j),N){a(N.bind(this,de));return}else throw de;if(L.length!==A)if(de=Error("Illegal salt length: "+L.length+" != "+A),N){a(N.bind(this,de));return}else throw de;j=1<<j>>>0;var ie,ve,ke=0,Q;Int32Array?(ie=new Int32Array(x),ve=new Int32Array(U)):(ie=x.slice(),ve=U.slice()),Y(L,R,ie,ve);function ye(){if(k&&k(ke/j),ke<j)for(var Pe=Date.now();ke<j&&(ke=ke+1,G(R,ie,ve),G(L,ie,ve),!(Date.now()-Pe>O)););else{for(ke=0;ke<64;ke++)for(Q=0;Q<H>>1;Q++)F(B,Q<<1,ie,ve);var Ge=[];for(ke=0;ke<H;ke++)Ge.push((B[ke]>>24&255)>>>0),Ge.push((B[ke]>>16&255)>>>0),Ge.push((B[ke]>>8&255)>>>0),Ge.push((B[ke]&255)>>>0);if(N){N(null,Ge);return}else return Ge}N&&a(ye)}if(typeof N<"u")ye();else for(var Fn;;)if(typeof(Fn=ye())<"u")return Fn||[]}function Ae(R,L,j,N){var k;if(typeof R!="string"||typeof L!="string")if(k=Error("Invalid string / salt: Not a string"),j){a(j.bind(this,k));return}else throw k;var B,H;if(L.charAt(0)!=="$"||L.charAt(1)!=="2")if(k=Error("Invalid salt version: "+L.substring(0,2)),j){a(j.bind(this,k));return}else throw k;if(L.charAt(2)==="$")B="\0",H=3;else{if(B=L.charAt(2),B!=="a"&&B!=="b"&&B!=="y"||L.charAt(3)!=="$")if(k=Error("Invalid salt revision: "+L.substring(2,4)),j){a(j.bind(this,k));return}else throw k;H=4}if(L.charAt(H+2)>"$")if(k=Error("Missing salt rounds"),j){a(j.bind(this,k));return}else throw k;var de=parseInt(L.substring(H,H+1),10)*10,ie=parseInt(L.substring(H+1,H+2),10),ve=de+ie,ke=L.substring(H+3,H+25);R+=B>="a"?"\0":"";var Q=l(R),ye=g(ke,A);function Fn(Pe){var Ge=[];return Ge.push("$2"),B>="a"&&Ge.push(B),Ge.push("$"),ve<10&&Ge.push("0"),Ge.push(ve.toString()),Ge.push("$"),Ge.push(h(ye,ye.length)),Ge.push(h(Pe,q.length*4-1)),Ge.join("")}if(typeof j>"u")return Fn(J(Q,ye,ve));J(Q,ye,ve,function(Pe,Ge){Pe?j(Pe,null):j(null,Fn(Ge))},N)}return e.encodeBase64=h,e.decodeBase64=g,e})})(T_);var jv=T_.exports;const ss=I_(jv),Pv="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Bv=t=>crypto.getRandomValues(new Uint8Array(t)),Lv=(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 l=n(i),u=i;for(;u--;)if(a+=t[l[u]&r]||"",a.length===s)return a}}},Fv=(t,e=21)=>Lv(t,e,Bv),He=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Pv[n[t]&63];return e};const Uv=24;function Dc(){return Fv("0123456789abcdef",Uv)()}function bh(t){if(!t.includes("|"))return console.error("Invalid user_id format"),t;const[,e]=t.split("|");return e}function Mv(t){return async(e,n)=>{if(!n.email||!n.email_verified)return t.users.create(e,n);const r=await Op({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 Me(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:t.var.connection||"",strategy:e.strategy||"",strategy_type:e.strategy_type||"",audience:"",scope:[]}}class Ep{constructor(e,n){be(this,"value");be(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 Ep(Math.round(this.milliseconds()*e),"ms")}}class qv{constructor(e){be(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 O_(t){return await crypto.subtle.digest("SHA-256",t)}const $h="0123456789abcdef";function zu(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++){const i=e[r]>>4;n+=$h[i];const s=e[r]&15;n+=$h[s]}return n}class D_{constructor(e,n){be(this,"alphabet");be(this,"padding");be(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 l=0;l<e.length;l++)for(i=i<<8|e[l],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 l=(8-r.length%8)%8;for(let u=0;u<l;u++)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 l=0;const u=[];for(let p=0;p<8;p++){const h=e[a*8+p];if(h==="="){if(a+1!==i)throw new Error(`Invalid character: ${h}`);l+=1;continue}if(h===void 0){if(r)throw new Error("Invalid data");l+=1;continue}const g=this.decodeMap.get(h)??null;if(g===null)throw new Error(`Invalid character: ${h}`);u.push(g)}if(l===8||l===7||l===5||l===2)throw new Error("Invalid padding");const d=(u[0]<<3)+(u[1]>>2);if(s.push(d),l<6){const p=((u[1]&3)<<6)+(u[2]<<1)+(u[3]>>4);s.push(p)}if(l<4){const p=((u[3]&255)<<4)+(u[4]>>1);s.push(p)}if(l<3){const p=((u[4]&1)<<7)+(u[5]<<2)+(u[6]>>3);s.push(p)}if(l<1){const p=((u[6]&7)<<5)+u[7];s.push(p)}}return Uint8Array.from(s)}}new D_("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new D_("0123456789ABCDEFGHIJKLMNOPQRSTUV");class R_{constructor(e,n){be(this,"alphabet");be(this,"padding");be(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 l=0;l<e.length;l++)for(i=i<<8|e[l],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 l=(4-r.length%4)%4;for(let u=0;u<l;u++)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 l=0,u=0;for(let d=0;d<4;d++){const p=e[a*4+d];if(p==="="){if(a+1!==i)throw new Error(`Invalid character: ${p}`);l+=1;continue}if(p===void 0){if(r)throw new Error("Invalid data");l+=1;continue}const h=this.decodeMap.get(p)??null;if(h===null)throw new Error(`Invalid character: ${p}`);u+=h<<6*(3-d)}s.push(u>>16&255),l<2&&s.push(u>>8&255),l<1&&s.push(u&255)}return Uint8Array.from(s)}}const j_=new R_("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Mr=new R_("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");async function xh(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,l=Mr.encode(a.encode(JSON.stringify(i)),{includePadding:!1}),u=Mr.encode(a.encode(JSON.stringify(s)),{includePadding:!1}),d=a.encode([l,u].join(".")),p=await Hv(t).sign(e,d),h=Mr.encode(new Uint8Array(p),{includePadding:!1});return[l,u,h].join(".")}function Vv(t){const e=t.split(".");return e.length!==3?null:e}function Sp(t){const e=Vv(t);if(!e)return null;const n=new TextDecoder,r=Mr.decode(e[0],{strict:!1}),i=Mr.decode(e[1],{strict:!1}),s=JSON.parse(n.decode(r));if(typeof s!="object"||s===null||!("alg"in s)||!Kv(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 l={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;l.expiresAt=new Date(a.exp*1e3)}if("iss"in a){if(typeof a.iss!="string")return null;l.issuer=a.iss}if("sub"in a){if(typeof a.sub!="string")return null;l.subject=a.sub}if("aud"in a)if(Array.isArray(a.aud)){for(const u of a.aud)if(typeof u!="string")return null;l.audiences=a.aud}else{if(typeof a.aud!="string")return null;l.audiences=[a.aud]}if("nbf"in a){if(typeof a.nbf!="number")return null;l.notBefore=new Date(a.nbf*1e3)}if("iat"in a){if(typeof a.iat!="number")return null;l.issuedAt=new Date(a.iat*1e3)}if("jti"in a){if(typeof a.jti!="string")return null;l.jwtId=a.jti}return{value:t,header:{...s,typ:"JWT",alg:s.alg},payload:{...a},parts:e,...l}}function Hv(t){return new qv(Gv[t])}function Kv(t){return typeof t!="string"?!1:["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512","PS256","PS384","PS512"].includes(t)}const Gv={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512"};function Wv(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Mr.encode(t,{includePadding:!1})}function Xv(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 Jv(t,e){if(e==="plain")return t;const n=new TextEncoder().encode(t),r=await O_(n);return Mr.encode(new Uint8Array(r),{includePadding:!1})}const Ms=60*5,Rc=30*24*60*60,Hr=24*60*60,Yv="auth-token",ia=30*60*1e3,Iu=7*24*60*60*1e3,Zv=5*60,Qv=5*60,eb=30*60*1e3,tb=30*60*1e3,nb=24*60*60*1e3;function P_(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 rb(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 kp(t){return`${t}-${Yv}`}function B_(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 Di(t,e){return e?rb(e).get(kp(t)):void 0}function ib(t,e){return P_(kp(t),"",{path:"/",httpOnly:!0,secure:!0,maxAge:0,sameSite:"none",domain:e?B_(e):void 0})}function Da(t,e,n){return P_(kp(t),e,{path:"/",httpOnly:!0,secure:!0,maxAge:Rc,sameSite:"none",domain:n?B_(n):void 0})}var Np={},jc={};(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(l,u){const d=[];let p=u.exec(l);for(;p;){const h=[];h.startIndex=u.lastIndex-p[0].length;const g=p.length;for(let $=0;$<g;$++)h.push(p[$]);d.push(h),p=u.exec(l)}return d},a=function(l){const u=i.exec(l);return!(u===null||typeof u>"u")};t.isExist=function(l){return typeof l<"u"},t.isEmptyObject=function(l){return Object.keys(l).length===0},t.merge=function(l,u,d){if(u){const p=Object.keys(u),h=p.length;for(let g=0;g<h;g++)d==="strict"?l[p[g]]=[u[p[g]]]:l[p[g]]=u[p[g]]}},t.getValue=function(l){return t.isExist(l)?l:""},t.isName=a,t.getAllMatches=s,t.nameRegexp=r})(jc);const Cp=jc,ob={allowBooleanAttributes:!1,unpairedTags:[]};Np.validate=function(t,e){e=Object.assign({},ob,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=Eh(t,s),s.err)return s}else if(t[s]==="<"){let a=s;if(s++,t[s]==="!"){s=Sh(t,s);continue}else{let l=!1;t[s]==="/"&&(l=!0,s++);let u="";for(;s<t.length&&t[s]!==">"&&t[s]!==" "&&t[s]!==" "&&t[s]!==`
|
|
5
|
+
*/(function(e,n){typeof Ov=="function"&&t&&t.exports?t.exports=n():(e.dcodeIO=e.dcodeIO||{}).bcrypt=n()})(Lr,function(){var e={},n=null;function r(R){if(t&&t.exports)try{return Oc.randomBytes(R)}catch{}try{var L;return(self.crypto||self.msCrypto).getRandomValues(L=new Uint32Array(R)),Array.prototype.slice.call(L)}catch{}if(!n)throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");return n(R)}var i=!1;try{r(1),i=!0}catch{}n=null,e.setRandomFallback=function(R){n=R},e.genSaltSync=function(R,L){if(R=R||z,typeof R!="number")throw Error("Illegal arguments: "+typeof R+", "+typeof L);R<4?R=4:R>31&&(R=31);var j=[];return j.push("$2a$"),R<10&&j.push("0"),j.push(R.toString()),j.push("$"),j.push(h(r(A),A)),j.join("")},e.genSalt=function(R,L,j){if(typeof L=="function"&&(j=L,L=void 0),typeof R=="function"&&(j=R,R=void 0),typeof R>"u")R=z;else if(typeof R!="number")throw Error("illegal arguments: "+typeof R);function N(k){a(function(){try{k(null,e.genSaltSync(R))}catch(B){k(B)}})}if(j){if(typeof j!="function")throw Error("Illegal callback: "+typeof j);N(j)}else return new Promise(function(k,B){N(function(K,de){if(K){B(K);return}k(de)})})},e.hashSync=function(R,L){if(typeof L>"u"&&(L=z),typeof L=="number"&&(L=e.genSaltSync(L)),typeof R!="string"||typeof L!="string")throw Error("Illegal arguments: "+typeof R+", "+typeof L);return Ae(R,L)},e.hash=function(R,L,j,N){function k(B){typeof R=="string"&&typeof L=="number"?e.genSalt(L,function(K,de){Ae(R,de,B,N)}):typeof R=="string"&&typeof L=="string"?Ae(R,L,B,N):a(B.bind(this,Error("Illegal arguments: "+typeof R+", "+typeof L)))}if(j){if(typeof j!="function")throw Error("Illegal callback: "+typeof j);k(j)}else return new Promise(function(B,K){k(function(de,ie){if(de){K(de);return}B(ie)})})};function s(R,L){for(var j=0,N=0,k=0,B=R.length;k<B;++k)R.charCodeAt(k)===L.charCodeAt(k)?++j:++N;return j<0?!1:N===0}e.compareSync=function(R,L){if(typeof R!="string"||typeof L!="string")throw Error("Illegal arguments: "+typeof R+", "+typeof L);return L.length!==60?!1:s(e.hashSync(R,L.substr(0,L.length-31)),L)},e.compare=function(R,L,j,N){function k(B){if(typeof R!="string"||typeof L!="string"){a(B.bind(this,Error("Illegal arguments: "+typeof R+", "+typeof L)));return}if(L.length!==60){a(B.bind(this,null,!1));return}e.hash(R,L.substr(0,29),function(K,de){K?B(K):B(null,s(de,L))},N)}if(j){if(typeof j!="function")throw Error("Illegal callback: "+typeof j);k(j)}else return new Promise(function(B,K){k(function(de,ie){if(de){K(de);return}B(ie)})})},e.getRounds=function(R){if(typeof R!="string")throw Error("Illegal arguments: "+typeof R);return parseInt(R.split("$")[2],10)},e.getSalt=function(R){if(typeof R!="string")throw Error("Illegal arguments: "+typeof R);if(R.length!==60)throw Error("Illegal hash length: "+R.length+" != 60");return R.substring(0,29)};var a=typeof process<"u"&&process&&typeof process.nextTick=="function"?typeof setImmediate=="function"?setImmediate:process.nextTick:setTimeout;function l(R){var L=[],j=0;return $.encodeUTF16toUTF8(function(){return j>=R.length?null:R.charCodeAt(j++)},function(N){L.push(N)}),L}var u="./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],p=String.fromCharCode;function h(R,L){var j=0,N=[],k,B;if(L<=0||L>R.length)throw Error("Illegal len: "+L);for(;j<L;){if(k=R[j++]&255,N.push(u[k>>2&63]),k=(k&3)<<4,j>=L){N.push(u[k&63]);break}if(B=R[j++]&255,k|=B>>4&15,N.push(u[k&63]),k=(B&15)<<2,j>=L){N.push(u[k&63]);break}B=R[j++]&255,k|=B>>6&3,N.push(u[k&63]),N.push(u[B&63])}return N.join("")}function g(R,L){var j=0,N=R.length,k=0,B=[],K,de,ie,ve,ke,Q;if(L<=0)throw Error("Illegal len: "+L);for(;j<N-1&&k<L&&(Q=R.charCodeAt(j++),K=Q<d.length?d[Q]:-1,Q=R.charCodeAt(j++),de=Q<d.length?d[Q]:-1,!(K==-1||de==-1||(ke=K<<2>>>0,ke|=(de&48)>>4,B.push(p(ke)),++k>=L||j>=N)||(Q=R.charCodeAt(j++),ie=Q<d.length?d[Q]:-1,ie==-1)||(ke=(de&15)<<4>>>0,ke|=(ie&60)>>2,B.push(p(ke)),++k>=L||j>=N)));)Q=R.charCodeAt(j++),ve=Q<d.length?d[Q]:-1,ke=(ie&3)<<6>>>0,ke|=ve,B.push(p(ke)),++k;var ye=[];for(j=0;j<k;j++)ye.push(B[j].charCodeAt(0));return ye}var $=function(){var R={};return R.MAX_CODEPOINT=1114111,R.encodeUTF8=function(L,j){var N=null;for(typeof L=="number"&&(N=L,L=function(){return null});N!==null||(N=L())!==null;)N<128?j(N&127):N<2048?(j(N>>6&31|192),j(N&63|128)):N<65536?(j(N>>12&15|224),j(N>>6&63|128),j(N&63|128)):(j(N>>18&7|240),j(N>>12&63|128),j(N>>6&63|128),j(N&63|128)),N=null},R.decodeUTF8=function(L,j){for(var N,k,B,K,de=function(ie){ie=ie.slice(0,ie.indexOf(null));var ve=Error(ie.toString());throw ve.name="TruncatedError",ve.bytes=ie,ve};(N=L())!==null;)if(!(N&128))j(N);else if((N&224)===192)(k=L())===null&&de([N,k]),j((N&31)<<6|k&63);else if((N&240)===224)((k=L())===null||(B=L())===null)&&de([N,k,B]),j((N&15)<<12|(k&63)<<6|B&63);else if((N&248)===240)((k=L())===null||(B=L())===null||(K=L())===null)&&de([N,k,B,K]),j((N&7)<<18|(k&63)<<12|(B&63)<<6|K&63);else throw RangeError("Illegal starting byte: "+N)},R.UTF16toUTF8=function(L,j){for(var N,k=null;(N=k!==null?k:L())!==null;){if(N>=55296&&N<=57343&&(k=L())!==null&&k>=56320&&k<=57343){j((N-55296)*1024+k-56320+65536),k=null;continue}j(N)}k!==null&&j(k)},R.UTF8toUTF16=function(L,j){var N=null;for(typeof L=="number"&&(N=L,L=function(){return null});N!==null||(N=L())!==null;)N<=65535?j(N):(N-=65536,j((N>>10)+55296),j(N%1024+56320)),N=null},R.encodeUTF16toUTF8=function(L,j){R.UTF16toUTF8(L,function(N){R.encodeUTF8(N,j)})},R.decodeUTF8toUTF16=function(L,j){R.decodeUTF8(L,function(N){R.UTF8toUTF16(N,j)})},R.calculateCodePoint=function(L){return L<128?1:L<2048?2:L<65536?3:4},R.calculateUTF8=function(L){for(var j,N=0;(j=L())!==null;)N+=R.calculateCodePoint(j);return N},R.calculateUTF16asUTF8=function(L){var j=0,N=0;return R.UTF16toUTF8(L,function(k){++j,N+=R.calculateCodePoint(k)}),[j,N]},R}();Date.now=Date.now||function(){return+new Date};var A=16,z=10,T=16,O=100,x=[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],q=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892];function F(R,L,j,N){var k,B=R[L],K=R[L+1];return B^=j[0],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[1],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[2],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[3],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[4],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[5],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[6],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[7],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[8],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[9],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[10],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[11],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[12],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[13],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[14],k=N[B>>>24],k+=N[256|B>>16&255],k^=N[512|B>>8&255],k+=N[768|B&255],K^=k^j[15],k=N[K>>>24],k+=N[256|K>>16&255],k^=N[512|K>>8&255],k+=N[768|K&255],B^=k^j[16],R[L]=K^j[T+1],R[L+1]=B,R}function H(R,L){for(var j=0,N=0;j<4;++j)N=N<<8|R[L]&255,L=(L+1)%R.length;return{key:N,offp:L}}function G(R,L,j){for(var N=0,k=[0,0],B=L.length,K=j.length,de,ie=0;ie<B;ie++)de=H(R,N),N=de.offp,L[ie]=L[ie]^de.key;for(ie=0;ie<B;ie+=2)k=F(k,0,L,j),L[ie]=k[0],L[ie+1]=k[1];for(ie=0;ie<K;ie+=2)k=F(k,0,L,j),j[ie]=k[0],j[ie+1]=k[1]}function Y(R,L,j,N){for(var k=0,B=[0,0],K=j.length,de=N.length,ie,ve=0;ve<K;ve++)ie=H(L,k),k=ie.offp,j[ve]=j[ve]^ie.key;for(k=0,ve=0;ve<K;ve+=2)ie=H(R,k),k=ie.offp,B[0]^=ie.key,ie=H(R,k),k=ie.offp,B[1]^=ie.key,B=F(B,0,j,N),j[ve]=B[0],j[ve+1]=B[1];for(ve=0;ve<de;ve+=2)ie=H(R,k),k=ie.offp,B[0]^=ie.key,ie=H(R,k),k=ie.offp,B[1]^=ie.key,B=F(B,0,j,N),N[ve]=B[0],N[ve+1]=B[1]}function J(R,L,j,N,k){var B=q.slice(),K=B.length,de;if(j<4||j>31)if(de=Error("Illegal number of rounds (4-31): "+j),N){a(N.bind(this,de));return}else throw de;if(L.length!==A)if(de=Error("Illegal salt length: "+L.length+" != "+A),N){a(N.bind(this,de));return}else throw de;j=1<<j>>>0;var ie,ve,ke=0,Q;Int32Array?(ie=new Int32Array(x),ve=new Int32Array(U)):(ie=x.slice(),ve=U.slice()),Y(L,R,ie,ve);function ye(){if(k&&k(ke/j),ke<j)for(var Pe=Date.now();ke<j&&(ke=ke+1,G(R,ie,ve),G(L,ie,ve),!(Date.now()-Pe>O)););else{for(ke=0;ke<64;ke++)for(Q=0;Q<K>>1;Q++)F(B,Q<<1,ie,ve);var Ge=[];for(ke=0;ke<K;ke++)Ge.push((B[ke]>>24&255)>>>0),Ge.push((B[ke]>>16&255)>>>0),Ge.push((B[ke]>>8&255)>>>0),Ge.push((B[ke]&255)>>>0);if(N){N(null,Ge);return}else return Ge}N&&a(ye)}if(typeof N<"u")ye();else for(var Fn;;)if(typeof(Fn=ye())<"u")return Fn||[]}function Ae(R,L,j,N){var k;if(typeof R!="string"||typeof L!="string")if(k=Error("Invalid string / salt: Not a string"),j){a(j.bind(this,k));return}else throw k;var B,K;if(L.charAt(0)!=="$"||L.charAt(1)!=="2")if(k=Error("Invalid salt version: "+L.substring(0,2)),j){a(j.bind(this,k));return}else throw k;if(L.charAt(2)==="$")B="\0",K=3;else{if(B=L.charAt(2),B!=="a"&&B!=="b"&&B!=="y"||L.charAt(3)!=="$")if(k=Error("Invalid salt revision: "+L.substring(2,4)),j){a(j.bind(this,k));return}else throw k;K=4}if(L.charAt(K+2)>"$")if(k=Error("Missing salt rounds"),j){a(j.bind(this,k));return}else throw k;var de=parseInt(L.substring(K,K+1),10)*10,ie=parseInt(L.substring(K+1,K+2),10),ve=de+ie,ke=L.substring(K+3,K+25);R+=B>="a"?"\0":"";var Q=l(R),ye=g(ke,A);function Fn(Pe){var Ge=[];return Ge.push("$2"),B>="a"&&Ge.push(B),Ge.push("$"),ve<10&&Ge.push("0"),Ge.push(ve.toString()),Ge.push("$"),Ge.push(h(ye,ye.length)),Ge.push(h(Pe,q.length*4-1)),Ge.join("")}if(typeof j>"u")return Fn(J(Q,ye,ve));J(Q,ye,ve,function(Pe,Ge){Pe?j(Pe,null):j(null,Fn(Ge))},N)}return e.encodeBase64=h,e.decodeBase64=g,e})})(T_);var jv=T_.exports;const ss=I_(jv),Pv="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Bv=t=>crypto.getRandomValues(new Uint8Array(t)),Lv=(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 l=n(i),u=i;for(;u--;)if(a+=t[l[u]&r]||"",a.length===s)return a}}},Fv=(t,e=21)=>Lv(t,e,Bv),He=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Pv[n[t]&63];return e};const Uv=24;function Dc(){return Fv("0123456789abcdef",Uv)()}function bh(t){if(!t.includes("|"))return console.error("Invalid user_id format"),t;const[,e]=t.split("|");return e}function Mv(t){return async(e,n)=>{if(!n.email||!n.email_verified)return t.users.create(e,n);const r=await Op({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 Me(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:t.var.connection||"",strategy:e.strategy||"",strategy_type:e.strategy_type||"",audience:"",scope:[]}}class Ep{constructor(e,n){be(this,"value");be(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 Ep(Math.round(this.milliseconds()*e),"ms")}}class qv{constructor(e){be(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 O_(t){return await crypto.subtle.digest("SHA-256",t)}const $h="0123456789abcdef";function zu(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++){const i=e[r]>>4;n+=$h[i];const s=e[r]&15;n+=$h[s]}return n}class D_{constructor(e,n){be(this,"alphabet");be(this,"padding");be(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 l=0;l<e.length;l++)for(i=i<<8|e[l],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 l=(8-r.length%8)%8;for(let u=0;u<l;u++)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 l=0;const u=[];for(let p=0;p<8;p++){const h=e[a*8+p];if(h==="="){if(a+1!==i)throw new Error(`Invalid character: ${h}`);l+=1;continue}if(h===void 0){if(r)throw new Error("Invalid data");l+=1;continue}const g=this.decodeMap.get(h)??null;if(g===null)throw new Error(`Invalid character: ${h}`);u.push(g)}if(l===8||l===7||l===5||l===2)throw new Error("Invalid padding");const d=(u[0]<<3)+(u[1]>>2);if(s.push(d),l<6){const p=((u[1]&3)<<6)+(u[2]<<1)+(u[3]>>4);s.push(p)}if(l<4){const p=((u[3]&255)<<4)+(u[4]>>1);s.push(p)}if(l<3){const p=((u[4]&1)<<7)+(u[5]<<2)+(u[6]>>3);s.push(p)}if(l<1){const p=((u[6]&7)<<5)+u[7];s.push(p)}}return Uint8Array.from(s)}}new D_("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new D_("0123456789ABCDEFGHIJKLMNOPQRSTUV");class R_{constructor(e,n){be(this,"alphabet");be(this,"padding");be(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 l=0;l<e.length;l++)for(i=i<<8|e[l],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 l=(4-r.length%4)%4;for(let u=0;u<l;u++)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 l=0,u=0;for(let d=0;d<4;d++){const p=e[a*4+d];if(p==="="){if(a+1!==i)throw new Error(`Invalid character: ${p}`);l+=1;continue}if(p===void 0){if(r)throw new Error("Invalid data");l+=1;continue}const h=this.decodeMap.get(p)??null;if(h===null)throw new Error(`Invalid character: ${p}`);u+=h<<6*(3-d)}s.push(u>>16&255),l<2&&s.push(u>>8&255),l<1&&s.push(u&255)}return Uint8Array.from(s)}}const j_=new R_("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Mr=new R_("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");async function xh(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,l=Mr.encode(a.encode(JSON.stringify(i)),{includePadding:!1}),u=Mr.encode(a.encode(JSON.stringify(s)),{includePadding:!1}),d=a.encode([l,u].join(".")),p=await Hv(t).sign(e,d),h=Mr.encode(new Uint8Array(p),{includePadding:!1});return[l,u,h].join(".")}function Vv(t){const e=t.split(".");return e.length!==3?null:e}function Sp(t){const e=Vv(t);if(!e)return null;const n=new TextDecoder,r=Mr.decode(e[0],{strict:!1}),i=Mr.decode(e[1],{strict:!1}),s=JSON.parse(n.decode(r));if(typeof s!="object"||s===null||!("alg"in s)||!Kv(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 l={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;l.expiresAt=new Date(a.exp*1e3)}if("iss"in a){if(typeof a.iss!="string")return null;l.issuer=a.iss}if("sub"in a){if(typeof a.sub!="string")return null;l.subject=a.sub}if("aud"in a)if(Array.isArray(a.aud)){for(const u of a.aud)if(typeof u!="string")return null;l.audiences=a.aud}else{if(typeof a.aud!="string")return null;l.audiences=[a.aud]}if("nbf"in a){if(typeof a.nbf!="number")return null;l.notBefore=new Date(a.nbf*1e3)}if("iat"in a){if(typeof a.iat!="number")return null;l.issuedAt=new Date(a.iat*1e3)}if("jti"in a){if(typeof a.jti!="string")return null;l.jwtId=a.jti}return{value:t,header:{...s,typ:"JWT",alg:s.alg},payload:{...a},parts:e,...l}}function Hv(t){return new qv(Gv[t])}function Kv(t){return typeof t!="string"?!1:["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512","PS256","PS384","PS512"].includes(t)}const Gv={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512"};function Wv(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Mr.encode(t,{includePadding:!1})}function Xv(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 Jv(t,e){if(e==="plain")return t;const n=new TextEncoder().encode(t),r=await O_(n);return Mr.encode(new Uint8Array(r),{includePadding:!1})}const Ms=60*5,Rc=30*24*60*60,Hr=24*60*60,Yv="auth-token",ia=30*60*1e3,Iu=7*24*60*60*1e3,Zv=5*60,Qv=5*60,eb=30*60*1e3,tb=30*60*1e3,nb=24*60*60*1e3;function P_(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 rb(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 kp(t){return`${t}-${Yv}`}function B_(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 Di(t,e){return e?rb(e).get(kp(t)):void 0}function ib(t,e){return P_(kp(t),"",{path:"/",httpOnly:!0,secure:!0,maxAge:0,sameSite:"none",domain:e?B_(e):void 0})}function Da(t,e,n){return P_(kp(t),e,{path:"/",httpOnly:!0,secure:!0,maxAge:Rc,sameSite:"none",domain:n?B_(n):void 0})}var Np={},jc={};(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(l,u){const d=[];let p=u.exec(l);for(;p;){const h=[];h.startIndex=u.lastIndex-p[0].length;const g=p.length;for(let $=0;$<g;$++)h.push(p[$]);d.push(h),p=u.exec(l)}return d},a=function(l){const u=i.exec(l);return!(u===null||typeof u>"u")};t.isExist=function(l){return typeof l<"u"},t.isEmptyObject=function(l){return Object.keys(l).length===0},t.merge=function(l,u,d){if(u){const p=Object.keys(u),h=p.length;for(let g=0;g<h;g++)d==="strict"?l[p[g]]=[u[p[g]]]:l[p[g]]=u[p[g]]}},t.getValue=function(l){return t.isExist(l)?l:""},t.isName=a,t.getAllMatches=s,t.nameRegexp=r})(jc);const Cp=jc,ob={allowBooleanAttributes:!1,unpairedTags:[]};Np.validate=function(t,e){e=Object.assign({},ob,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=Eh(t,s),s.err)return s}else if(t[s]==="<"){let a=s;if(s++,t[s]==="!"){s=Sh(t,s);continue}else{let l=!1;t[s]==="/"&&(l=!0,s++);let u="";for(;s<t.length&&t[s]!==">"&&t[s]!==" "&&t[s]!==" "&&t[s]!==`
|
|
6
6
|
`&&t[s]!=="\r";s++)u+=t[s];if(u=u.trim(),u[u.length-1]==="/"&&(u=u.substring(0,u.length-1),s--),!fb(u)){let h;return u.trim().length===0?h="Invalid space after '<'.":h="Tag '"+u+"' is an invalid name.",Ze("InvalidTag",h,yt(t,s))}const d=cb(t,s);if(d===!1)return Ze("InvalidAttr","Attributes for '"+u+"' have open quote.",yt(t,s));let p=d.value;if(s=d.index,p[p.length-1]==="/"){const h=s-p.length;p=p.substring(0,p.length-1);const g=kh(p,e);if(g===!0)r=!0;else return Ze(g.err.code,g.err.msg,yt(t,h+g.err.line))}else if(l)if(d.tagClosed){if(p.trim().length>0)return Ze("InvalidTag","Closing tag '"+u+"' can't have attributes or invalid starting.",yt(t,a));if(n.length===0)return Ze("InvalidTag","Closing tag '"+u+"' has not been opened.",yt(t,a));{const h=n.pop();if(u!==h.tagName){let g=yt(t,h.tagStartPos);return Ze("InvalidTag","Expected closing tag '"+h.tagName+"' (opened in line "+g.line+", col "+g.col+") instead of closing tag '"+u+"'.",yt(t,a))}n.length==0&&(i=!0)}}else return Ze("InvalidTag","Closing tag '"+u+"' doesn't have proper closing.",yt(t,s));else{const h=kh(p,e);if(h!==!0)return Ze(h.err.code,h.err.msg,yt(t,s-p.length+h.err.line));if(i===!0)return Ze("InvalidXml","Multiple possible root nodes found.",yt(t,s));e.unpairedTags.indexOf(u)!==-1||n.push({tagName:u,tagStartPos:a}),r=!0}for(s++;s<t.length;s++)if(t[s]==="<")if(t[s+1]==="!"){s++,s=Sh(t,s);continue}else if(t[s+1]==="?"){if(s=Eh(t,++s),s.err)return s}else break;else if(t[s]==="&"){const h=db(t,s);if(h==-1)return Ze("InvalidChar","char '&' is not expected.",yt(t,s));s=h}else if(i===!0&&!Ah(t[s]))return Ze("InvalidXml","Extra text at the end",yt(t,s));t[s]==="<"&&s--}}else{if(Ah(t[s]))continue;return Ze("InvalidChar","char '"+t[s]+"' is not expected.",yt(t,s))}if(r){if(n.length==1)return Ze("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",yt(t,n[0].tagStartPos));if(n.length>0)return Ze("InvalidXml","Invalid '"+JSON.stringify(n.map(s=>s.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return Ze("InvalidXml","Start tag expected.",1);return!0};function Ah(t){return t===" "||t===" "||t===`
|
|
7
7
|
`||t==="\r"}function Eh(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 Ze("InvalidXml","XML declaration allowed only at the start of the document.",yt(t,e));if(t[e]=="?"&&t[e+1]==">"){e++;break}else continue}return e}function Sh(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 sb='"',ab="'";function cb(t,e){let n="",r="",i=!1;for(;e<t.length;e++){if(t[e]===sb||t[e]===ab)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 lb=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function kh(t,e){const n=Cp.getAllMatches(t,lb),r={};for(let i=0;i<n.length;i++){if(n[i][1].length===0)return Ze("InvalidAttr","Attribute '"+n[i][2]+"' has no space in starting.",_o(n[i]));if(n[i][3]!==void 0&&n[i][4]===void 0)return Ze("InvalidAttr","Attribute '"+n[i][2]+"' is without value.",_o(n[i]));if(n[i][3]===void 0&&!e.allowBooleanAttributes)return Ze("InvalidAttr","boolean attribute '"+n[i][2]+"' is not allowed.",_o(n[i]));const s=n[i][2];if(!pb(s))return Ze("InvalidAttr","Attribute '"+s+"' is an invalid name.",_o(n[i]));if(!r.hasOwnProperty(s))r[s]=1;else return Ze("InvalidAttr","Attribute '"+s+"' is repeated.",_o(n[i]))}return!0}function ub(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 db(t,e){if(e++,t[e]===";")return-1;if(t[e]==="#")return e++,ub(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 Ze(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function pb(t){return Cp.isName(t)}function fb(t){return Cp.isName(t)}function yt(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function _o(t){return t.startIndex+t[1].length}var zp={};const L_={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}},hb=function(t){return Object.assign({},L_,t)};zp.buildOptions=hb;zp.defaultOptions=L_;class gb{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 mb=gb;const _b=jc;function yb(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&&bb(t,e)){e+=7;let l,u;[l,u,e]=wb(t,e+1),u.indexOf("&")===-1&&(n[Eb(l)]={regx:RegExp(`&${l};`,"g"),val:u})}else if(i&&$b(t,e))e+=8;else if(i&&xb(t,e))e+=8;else if(i&&Ab(t,e))e+=9;else if(vb)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 wb(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 vb(t,e){return t[e+1]==="!"&&t[e+2]==="-"&&t[e+3]==="-"}function bb(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 $b(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 xb(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 Ab(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 Eb(t){if(_b.isName(t))return t;throw new Error(`Invalid entity name ${t}`)}var Sb=yb;const kb=/^[-+]?0x[a-fA-F0-9]+$/,Nb=/^([\-\+])?(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 Cb={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function zb(t,e={}){if(e=Object.assign({},Cb,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&&kb.test(n))return Number.parseInt(n,16);{const r=Nb.exec(n);if(r){const i=r[1],s=r[2];let a=Ib(r[3]);const l=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&i&&n[2]!==".")return t;if(!e.leadingZeros&&s.length>0&&!i&&n[1]!==".")return t;{const u=Number(n),d=""+u;return d.search(/[eE]/)!==-1||l?e.eNotation?u:t:n.indexOf(".")!==-1?d==="0"&&a===""||d===a||i&&d==="-"+a?u:t:s?a===d||i+a===d?u:t:n===d||n===i+d?u:t}}else return t}}function Ib(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 Tb=zb;function Ob(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 F_=Ob;const U_=jc,yo=mb,Db=Sb,Rb=Tb,jb=F_;let Pb=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=Bb,this.parseXml=qb,this.parseTextData=Lb,this.resolveNameSpace=Fb,this.buildAttributesMap=Mb,this.isItStopNode=Gb,this.replaceEntitiesValue=Hb,this.readStopNodeData=Xb,this.saveTextToParentTag=Kb,this.addChild=Vb,this.ignoreAttributesFn=jb(this.options.ignoreAttributes)}};function Bb(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 Lb(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 l=this.options.tagValueProcessor(e,t,n,i,s);return l==null?t:typeof l!=typeof t||l!==t?l:this.options.trimValues?Ou(t,this.options.parseTagValue,this.options.numberParseOptions):t.trim()===t?Ou(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function Fb(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 Ub=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function Mb(t,e,n){if(this.options.ignoreAttributes!==!0&&typeof t=="string"){const r=U_.getAllMatches(t,Ub),i=r.length,s={};for(let a=0;a<i;a++){const l=this.resolveNameSpace(r[a][1]);if(this.ignoreAttributesFn(l,e))continue;let u=r[a][4],d=this.options.attributeNamePrefix+l;if(l.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),d==="__proto__"&&(d="#__proto__"),u!==void 0){this.options.trimValues&&(u=u.trim()),u=this.replaceEntitiesValue(u);const p=this.options.attributeValueProcessor(l,u,e);p==null?s[d]=u:typeof p!=typeof u||p!==u?s[d]=p:s[d]=Ou(u,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 qb=function(t){t=t.replace(/\r\n?/g,`
|
|
8
8
|
`);const e=new yo("!xml");let n=e,r="",i="";for(let s=0;s<t.length;s++)if(t[s]==="<")if(t[s+1]==="/"){const l=Fr(t,">",s,"Closing Tag is not closed.");let u=t.substring(s+2,l).trim();if(this.options.removeNSPrefix){const h=u.indexOf(":");h!==-1&&(u=u.substr(h+1))}this.options.transformTagName&&(u=this.options.transformTagName(u)),n&&(r=this.saveTextToParentTag(r,n,i));const d=i.substring(i.lastIndexOf(".")+1);if(u&&this.options.unpairedTags.indexOf(u)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${u}>`);let p=0;d&&this.options.unpairedTags.indexOf(d)!==-1?(p=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):p=i.lastIndexOf("."),i=i.substring(0,p),n=this.tagsNodeStack.pop(),r="",s=l}else if(t[s+1]==="?"){let l=Tu(t,s,!1,"?>");if(!l)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&l.tagName==="?xml"||this.options.ignorePiTags)){const u=new yo(l.tagName);u.add(this.options.textNodeName,""),l.tagName!==l.tagExp&&l.attrExpPresent&&(u[":@"]=this.buildAttributesMap(l.tagExp,i,l.tagName)),this.addChild(n,u,i)}s=l.closeIndex+1}else if(t.substr(s+1,3)==="!--"){const l=Fr(t,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){const u=t.substring(s+4,l-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:u}])}s=l}else if(t.substr(s+1,2)==="!D"){const l=Db(t,s);this.docTypeEntities=l.entities,s=l.i}else if(t.substr(s+1,2)==="!["){const l=Fr(t,"]]>",s,"CDATA is not closed.")-2,u=t.substring(s+9,l);r=this.saveTextToParentTag(r,n,i);let d=this.parseTextData(u,n.tagname,i,!0,!1,!0,!0);d==null&&(d=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:u}]):n.add(this.options.textNodeName,d),s=l+2}else{let l=Tu(t,s,this.options.removeNSPrefix),u=l.tagName;const d=l.rawTagName;let p=l.tagExp,h=l.attrExpPresent,g=l.closeIndex;this.options.transformTagName&&(u=this.options.transformTagName(u)),n&&r&&n.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,n,i,!1));const $=n;if($&&this.options.unpairedTags.indexOf($.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),u!==e.tagname&&(i+=i?"."+u:u),this.isItStopNode(this.options.stopNodes,i,u)){let A="";if(p.length>0&&p.lastIndexOf("/")===p.length-1)u[u.length-1]==="/"?(u=u.substr(0,u.length-1),i=i.substr(0,i.length-1),p=u):p=p.substr(0,p.length-1),s=l.closeIndex;else if(this.options.unpairedTags.indexOf(u)!==-1)s=l.closeIndex;else{const T=this.readStopNodeData(t,d,g+1);if(!T)throw new Error(`Unexpected end of ${d}`);s=T.i,A=T.tagContent}const z=new yo(u);u!==p&&h&&(z[":@"]=this.buildAttributesMap(p,i,u)),A&&(A=this.parseTextData(A,u,i,!0,h,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),z.add(this.options.textNodeName,A),this.addChild(n,z,i)}else{if(p.length>0&&p.lastIndexOf("/")===p.length-1){u[u.length-1]==="/"?(u=u.substr(0,u.length-1),i=i.substr(0,i.length-1),p=u):p=p.substr(0,p.length-1),this.options.transformTagName&&(u=this.options.transformTagName(u));const A=new yo(u);u!==p&&h&&(A[":@"]=this.buildAttributesMap(p,i,u)),this.addChild(n,A,i),i=i.substr(0,i.lastIndexOf("."))}else{const A=new yo(u);this.tagsNodeStack.push(n),u!==p&&h&&(A[":@"]=this.buildAttributesMap(p,i,u)),this.addChild(n,A,i),n=A}r="",s=g}}else r+=t[s];return e.child};function Vb(t,e,n){const r=this.options.updateTag(e.tagname,n,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),t.addChild(e))}const Hb=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 Kb(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 Gb(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 Wb(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 Fr(t,e,n,r){const i=t.indexOf(e,n);if(i===-1)throw new Error(r);return i+e.length-1}function Tu(t,e,n,r=">"){const i=Wb(t,e+1,r);if(!i)return;let s=i.data;const a=i.index,l=s.search(/\s/);let u=s,d=!0;l!==-1&&(u=s.substring(0,l),s=s.substring(l+1).trimStart());const p=u;if(n){const h=u.indexOf(":");h!==-1&&(u=u.substr(h+1),d=u!==i.data.substr(h+1))}return{tagName:u,tagExp:s,closeIndex:a,attrExpPresent:d,rawTagName:p}}function Xb(t,e,n){const r=n;let i=1;for(;n<t.length;n++)if(t[n]==="<")if(t[n+1]==="/"){const s=Fr(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=Fr(t,"?>",n+1,"StopNode is not closed.");else if(t.substr(n+1,3)==="!--")n=Fr(t,"-->",n+3,"StopNode is not closed.");else if(t.substr(n+1,2)==="![")n=Fr(t,"]]>",n,"StopNode is not closed.")-2;else{const s=Tu(t,n,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&i++,n=s.closeIndex)}}function Ou(t,e,n){if(e&&typeof t=="string"){const r=t.trim();return r==="true"?!0:r==="false"?!1:Rb(t,n)}else return U_.isExist(t)?t:""}var Jb=Pb,M_={};function Yb(t,e){return q_(t,e)}function q_(t,e,n){let r;const i={};for(let s=0;s<t.length;s++){const a=t[s],l=Zb(a);let u="";if(n===void 0?u=l:u=n+"."+l,l===e.textNodeName)r===void 0?r=a[l]:r+=""+a[l];else{if(l===void 0)continue;if(a[l]){let d=q_(a[l],e,u);const p=e3(d,e);a[":@"]?Qb(d,a[":@"],u,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[l]!==void 0&&i.hasOwnProperty(l)?(Array.isArray(i[l])||(i[l]=[i[l]]),i[l].push(d)):e.isArray(l,u,p)?i[l]=[d]:i[l]=d}}}return typeof r=="string"?r.length>0&&(i[e.textNodeName]=r):r!==void 0&&(i[e.textNodeName]=r),i}function Zb(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];if(r!==":@")return r}}function Qb(t,e,n,r){if(e){const i=Object.keys(e),s=i.length;for(let a=0;a<s;a++){const l=i[a];r.isArray(l,n+"."+l,!0,!0)?t[l]=[e[l]]:t[l]=e[l]}}}function e3(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))}M_.prettify=Yb;const{buildOptions:t3}=zp,n3=Jb,{prettify:r3}=M_,i3=Np;let o3=class{constructor(e){this.externalEntities={},this.options=t3(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=i3.validate(e,n);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}const r=new n3(this.options);r.addExternalEntities(this.externalEntities);const i=r.parseXml(e);return this.options.preserveOrder||i===void 0?i:r3(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 '
'");if(n==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[e]=n}};var s3=o3;const a3=`
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
<\/script>
|
|
70
70
|
</body>
|
|
71
71
|
|
|
72
|
-
</html>`}class Ra extends E{constructor(e,n){super(e,{message:JSON.stringify(n),res:new Response(JSON.stringify(n),{status:e,headers:{"Content-Type":"application/json"}})})}}const G_=["openid","profile","email","address","phone"];async function k3(t,e){var x,U;const{tenantId:n,clientId:r,audience:i,requestedScopes:s}=e,a=s.filter(q=>G_.includes(q)),u=(await t.env.data.resourceServers.list(n)).resource_servers.filter(q=>q.identifier===i);if(u.length===0)return{scopes:a,permissions:[]};const d=u[0];if(!d)return{scopes:a,permissions:[]};const p=((x=d.options)==null?void 0:x.enforce_policies)===!0,h=((U=d.options)==null?void 0:U.token_dialect)||"access_token",$=(await t.env.data.clientGrants.list(n,{q:`client_id:"${r}"`})).client_grants.find(q=>q.audience===i);if(!$)return{scopes:a,permissions:[]};const A=$.scope||[],z=(d.scopes||[]).map(q=>q.value);if(!p){const q=s.filter(K=>z.includes(K)&&A.includes(K));return{scopes:[...new Set([...a,...q])],permissions:[]}}if(h==="access_token_authz"){const q=A.filter(F=>z.includes(F));return{scopes:a,permissions:q}}const T=s.filter(q=>z.includes(q)&&A.includes(q));return{scopes:[...new Set([...a,...T])],permissions:[]}}async function ja(t,e){var G,Y;if(e.grantType===an.ClientCredential)return await k3(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(R=>R.organization_id===a))throw new Ra(403,{error:"access_denied",error_description:"User is not a member of the specified organization"});const l=s.filter(J=>G_.includes(J)),d=(await t.env.data.resourceServers.list(n)).resource_servers.filter(J=>J.identifier===i);if(d.length===0)return{scopes:l,permissions:[]};const p=d[0];if(!p)return{scopes:l,permissions:[]};const h=(p.scopes||[]).map(J=>J.value),g=((G=p.options)==null?void 0:G.enforce_policies)===!0,$=((Y=p.options)==null?void 0:Y.token_dialect)||"access_token";if(!g){const J=s.filter(R=>h.includes(R));return{scopes:[...new Set([...l,...J])],permissions:[]}}const A=await t.env.data.userPermissions.list(n,r,void 0,a),z=await t.env.data.userRoles.list(n,r,void 0,""),T=a?await t.env.data.userRoles.list(n,r,void 0,a):[],O=[...z,...T],x=[];for(const J of O)(await t.env.data.rolePermissions.list(n,J.id)).forEach(R=>{R.resource_server_identifier===i&&x.push(R.permission_name)});const U=new Set;A.forEach(J=>{J.resource_server_identifier===i&&U.add(J.permission_name)}),x.forEach(J=>{U.add(J)});const q=Array.from(U);if($==="access_token_authz"){const J=q.filter(Ae=>h.includes(Ae));return{scopes:l,permissions:J}}const F=s.filter(J=>h.includes(J)&&q.includes(J));return{scopes:[...new Set([...l,...F])],permissions:[]}}const Ch=["sub","iss","aud","exp","nbf","iat","jti"];async function Pc(t,e){var T,O;const{authParams:n,user:r,client:i,session_id:s}=e,{signingKeys:a}=await t.env.data.keys.list({q:"type:jwt_signing"}),l=a.filter(x=>!x.revoked_at||new Date(x.revoked_at)>new Date),u=l[l.length-1];if(!(u!=null&&u.pkcs7))throw new E(500,{message:"No signing key available"});const d=Xv(u.pkcs7),p=t.var.custom_domain?`https://${t.var.custom_domain}/`:t.env.ISSUER,h={aud:n.audience||"default",scope:n.scope||"",sub:(r==null?void 0:r.user_id)||n.client_id,iss:p,tenant_id:t.var.tenant_id,sid:s,...e.organization&&{org_id:e.organization},...e.permissions&&e.permissions.length>0&&{permissions:e.permissions}},g=r&&((T=n.scope)!=null&&T.split(" ").includes("openid"))?{aud:n.client_id,sub:r.user_id,iss:p,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,...e.organization&&{org_id:e.organization}}:void 0;(O=t.env.hooks)!=null&&O.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:(x,U)=>{if(Ch.includes(x))throw new Error(`Cannot overwrite reserved claim '${x}'`);h[x]=U}},idToken:{setCustomClaim:(x,U)=>{if(Ch.includes(x))throw new Error(`Cannot overwrite reserved claim '${x}'`);g&&(g[x]=U)}},access:{deny:x=>{throw new E(400,{message:`Access denied: ${x}`})}}});const $={includeIssuedTimestamp:!0,expiresIn:new Ep(1,"d"),headers:{kid:u.kid}},A=await xh("RS256",d,h,$),z=g?await xh("RS256",d,g,$):void 0;return{access_token:A,refresh_token:e.refresh_token,id_token:z,token_type:"Bearer",expires_in:86400}}async function W_(t,e){return{code:(await t.env.data.codes.create(e.client.tenant.id,{code_id:He(),user_id:e.user.user_id,code_type:"authorization_code",login_id:e.login_id,expires_at:new Date(Date.now()+Zv*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 X_(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:He(),session_id:s,client_id:n.client_id,idle_expires_at:new Date(Date.now()+Rc*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 J_(t,{user:e,client:n,loginSession:r}){const i=await t.env.data.sessions.create(n.tenant.id,{id:He(),user_id:e.user_id,login_session_id:r.id,idle_expires_at:new Date(Date.now()+Rc*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 Dn(t,e){var A,z;const{authParams:n,client:r,ticketAuth:i}=e;let{user:s}=e;const a=n.response_type||Yt.CODE,l=n.response_mode||zn.QUERY,u=Me(t,{type:Le.SUCCESS_LOGIN,description:`Successful login for ${s.user_id}`,userId:s.user_id});if(ln(t,t.env.data.logs.create(r.tenant.id,u)),ln(t,t.env.data.users.update(r.tenant.id,s.user_id,{last_login:new Date().toISOString(),last_ip:t.var.ip||"",login_count:s.login_count+1})),i){if(!e.loginSession)throw new E(500,{message:"Login session not found for ticket auth."});const T=Wv(),O=He(12),x=await t.env.data.codes.create(r.tenant.id,{code_id:He(),code_type:"ticket",login_id:e.loginSession.id,expires_at:new Date(Date.now()+eb).toISOString(),code_verifier:[O,T].join("|"),redirect_uri:n.redirect_uri,state:n.state,nonce:n.nonce});return t.json({login_ticket:x.code_id,co_verifier:T,co_id:O})}let d=e.refreshToken,p=e.sessionId;if(!p&&((A=e.loginSession)!=null&&A.session_id)){p=e.loginSession.session_id;const T=await t.env.data.sessions.get(r.tenant.id,p);T&&!T.clients.includes(r.client_id)&&await t.env.data.sessions.update(r.tenant.id,p,{clients:[...T.clients,r.client_id]})}else if(!p){if(!e.loginSession)throw new E(500,{message:"Login session not found for creating a new session."});p=(await J_(t,{user:s,client:r,loginSession:e.loginSession})).id}if(!d&&((z=n.scope)!=null&&z.split(" ").includes("offline_access"))&&![Yt.TOKEN,Yt.CODE].includes(a)&&(d=(await X_(t,{user:s,client:r,session_id:p,scope:n.scope,audience:n.audience})).id),l===zn.SAML_POST){if(!p)throw new E(500,{message:"Session ID not available for SAML response"});return x3(t,e.client,e.authParams,s,p)}const h=await N3(t,{authParams:n,user:s,client:r,session_id:p,refresh_token:d,strategy:e.strategy,loginSession:e.loginSession,responseType:a,skipHooks:e.skipHooks,organization:e.organization});if(h instanceof Response)return h;if(l===zn.WEB_MESSAGE){if(!n.redirect_uri)throw new E(400,{message:"Redirect URI not allowed for WEB_MESSAGE response mode."});const T=new Headers;if(p){const U=Da(r.tenant.id,p,t.var.host||"");U&&T.set("set-cookie",U)}else console.warn("Session ID not available for WEB_MESSAGE, cookie will not be set.");const O=new URL(n.redirect_uri),x=`${O.protocol}//${O.host}`;return t.html(Du(x,JSON.stringify({...h,state:n.state})),{headers:T})}if(!n.redirect_uri)throw new E(400,{message:"Redirect uri not found for this response mode."});const g=new Headers;if(p){const T=Da(r.tenant.id,p,t.var.custom_domain||t.req.header("host")||"");T&&g.set("set-cookie",T)}const $=new URL(n.redirect_uri);if("code"in h)$.searchParams.set("code",h.code),h.state&&$.searchParams.set("state",h.state);else if("access_token"in h)$.hash=new URLSearchParams({access_token:h.access_token,...h.id_token&&{id_token:h.id_token},token_type:h.token_type,expires_in:h.expires_in.toString(),...n.state&&{state:n.state},...n.scope&&{scope:n.scope}}).toString();else throw new E(500,{message:"Invalid token response for implicit flow."});return g.set("location",$.toString()),new Response("Redirecting",{status:302,headers:g})}async function N3(t,e){var l,u,d,p;let{user:n}=e;const r=e.responseType||Yt.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($=>$.organization_id===e.organization))throw new Ra(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 h;if(e.grantType===an.ClientCredential||!n&&!e.user)h=await ja(t,{grantType:an.ClientCredential,tenantId:e.client.tenant.id,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((l=e.authParams.scope)==null?void 0:l.split(" "))||[],organizationId:e.organization});else{const g=(n==null?void 0:n.user_id)||((u=e.user)==null?void 0:u.user_id);if(!g)throw new Ra(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});h=await ja(t,{grantType:e.grantType,tenantId:e.client.tenant.id,userId:g,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((d=e.authParams.scope)==null?void 0:d.split(" "))||[],organizationId:e.organization})}i=h.scopes.join(" "),s=h.permissions}catch(h){if(h instanceof E)throw h;console.error("Error calculating scopes and permissions:",h)}const a={...e.authParams,scope:i};if(e.loginSession&&n&&!e.skipHooks){e.strategy&&((p=n.app_metadata)==null?void 0:p.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 h=await P3(t,t.env.data,e.client.tenant.id,n,e.loginSession,{client:e.client,authParams:a});if(h instanceof Response)return h;n=h}if(r===Yt.CODE){if(!n||!e.loginSession)throw new E(500,{message:"User and loginSession is required for code flow"});return await W_(t,{user:n,client:e.client,authParams:a,login_id:e.loginSession.id})}else return Pc(t,{...e,user:n,authParams:a,permissions:s})}async function C3(t,e,n){const r=await t.env.data.tenants.get(e);if(!r)throw new Error(`Tenant not found: ${e}`);const i={client_id:t.env.ISSUER,tenant:r,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),name:t.env.ISSUER,global:!1,is_first_party:!1,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:[]};return Pc(t,{client:i,authParams:{client_id:t.env.ISSUER,response_type:Yt.TOKEN,scope:n}})}async function Y_(t,e,n){const r=await C3(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=Me(t,{type:Le.FAILED_HOOK,description:`Failed to invoke hook ${i.hook_id}`});await t.env.data.logs.create(n.tenant_id,a)}}function z3(t){return async(e,n)=>{const{hooks:r}=await t.env.data.hooks.list(e);return await Y_(t,r,{tenant_id:e,user:n,trigger_id:"post-user-registration"}),n}}function I3(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 Y_(t,r,{tenant_id:e,email:n,trigger_id:"pre-user-signup"})}}function zh(t){return typeof t.form_id=="string"}async function T3(t,e,n){var u;const r=t.env.data,i=t.var.tenant_id||t.req.header("tenant-id");if(!i)throw new E(400,{message:"Missing tenant_id in context"});const s=await r.forms.get(i,e);if(!s)throw new E(404,{message:"Form not found for post-user-login hook"});let a=(u=s.start)==null?void 0:u.next_node;if(!a&&s.nodes&&s.nodes.length>0){const d=s.nodes.find(p=>p.type==="STEP");a=d==null?void 0:d.id}if(!a)throw new E(400,{message:"No start node found in form"});let l=`/u/forms/${s.id}/nodes/${a}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:l}})}function Ih(t){return typeof t.page_id=="string"&&typeof t.enabled=="boolean"}async function O3(t,e,n,r,i){const s=t.env.data,a=t.var.tenant_id||t.req.header("tenant-id");if(!a)throw new E(400,{message:"Missing tenant_id in context"});if(i&&!(await s.userPermissions.list(a,r.user_id)).some(p=>p.permission_name===i))return r;let l=`/u/${e}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:l}})}function Th(t){return typeof t.url=="string"}function D3(t,e){return async(n,r)=>{var a,l,u;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((l=t.env.hooks)!=null&&l.onExecutePreUserRegistration)try{await t.env.hooks.onExecutePreUserRegistration({ctx:t,user:r,request:i},{user:{setUserMetadata:async(d,p)=>{r[d]=p}}})}catch{const p=Me(t,{type:Le.FAILED_SIGNUP,description:"Pre user registration hook failed"});await e.logs.create(n,p)}let s=await Mv(e)(n,r);if((u=t.env.hooks)!=null&&u.onExecutePostUserRegistration)try{await t.env.hooks.onExecutePostUserRegistration({ctx:t,user:r,request:i},{user:{}})}catch{const p=Me(t,{type:Le.FAILED_SIGNUP,description:"Post user registration hook failed"});await t.env.data.logs.create(n,p)}return await z3(t)(n,s),s}}function R3(t,e){return async(n,r,i)=>{var a,l;const s={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((l=t.env.hooks)!=null&&l.onExecutePreUserUpdate)try{await t.env.hooks.onExecutePreUserUpdate({ctx:t,user_id:r,updates:i,request:s},{user:{setUserMetadata:async(u,d)=>{i[u]=d}},cancel:()=>{throw new E(400,{message:"User update cancelled by pre-update hook"})}})}catch(u){if(u instanceof E)throw u;const d=Me(t,{type:Le.FAILED_HOOK,description:"Pre user update hook failed"});throw await e.logs.create(n,d),new E(400,{message:"Pre user update hook failed"})}if(await e.users.update(n,r,i),i.email){const u=Me(t,{type:Le.SUCCESS_CHANGE_EMAIL,description:`Email updated to ${i.email}`,userId:r});await e.logs.create(n,u),console.log("log:",u)}return!0}}async function j3(t,e,n,r){var i;if(e.disable_sign_ups){const s=(i=t.var.loginSession)==null?void 0:i.authorization_url;if(!(s&&new URL(s).searchParams.get("screen_hint")==="signup")&&!await Op({userAdapter:n.users,tenant_id:e.tenant.id,email:r})){const u=Me(t,{type:Le.FAILED_SIGNUP,description:"Public signup is disabled"});throw await n.logs.create(e.tenant.id,u),new E(400,{message:"Signups are disabled for this client"})}}await I3(t)(t.var.tenant_id||"",r)}function as(t,e){return{...e,users:{...e.users,create:D3(t,e),update:R3(t,e)}}}async function P3(t,e,n,r,i,s){var u;(u=t.env.hooks)!=null&&u.onExecutePostLogin&&(s!=null&&s.client)&&(s!=null&&s.authParams)&&await t.env.hooks.onExecutePostLogin({ctx:t,client:s.client,user:r,request:{ip:t.var.ip,user_agent:t.var.useragent,method:t.req.method,url:t.req.url},scope:s.authParams.scope||"",grant_type:""},{prompt:{render:d=>{}}});const{hooks:a}=await e.hooks.list(n,{q:"trigger_id:post-user-login",page:0,per_page:100,include_totals:!1});if(i){const d=a.find(h=>h.enabled&&zh(h));if(d&&zh(d))return T3(t,d.form_id,i);const p=a.find(h=>h.enabled&&Ih(h));if(p&&Ih(p))return O3(t,p.page_id,i,r,p.permission_required)}const l=a.filter(d=>d.enabled&&Th(d));for(const d of l)if(Th(d))try{await fetch(d.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tenant_id:n,user:r,trigger_id:"post-user-login"})})}catch{const h=Me(t,{type:Le.FAILED_HOOK,description:`Failed to invoke post-user-login webhook: ${d.url}`});await e.logs.create(n,h)}return r}function B3(t){return as(t,t.env.data)}async function Tp(t,e,n){return(await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`})).users}async function eo({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 Op({userAdapter:t,tenant_id:e,email:n}){var l;const{users:r}=await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`}),i=r.filter(u=>!(u.provider==="auth2"&&!u.email_verified));if(i.length===0)return;const s=i.filter(u=>!u.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,(l=i[0])==null?void 0:l.linked_to);if(!a)throw new Error("Primary account not found");return a}async function Po({userAdapter:t,tenant_id:e,username:n,provider:r}){const i=await eo({userAdapter:t,tenant_id:e,username:n,provider:r});return i?i.linked_to?t.get(e,i.linked_to):i:null}async function Bc(t,e){const{username:n,provider:r,connection:i,client:s,userId:a,isSocial:l,profileData:u={},ip:d=""}=e;let p=await Po({userAdapter:t.env.data.users,tenant_id:e.client.tenant.id,username:n,provider:r});if(!p){const h={user_id:`${r}|${a||Dc()}`,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:l,last_login:new Date().toISOString(),profileData:JSON.stringify(u)};p=await B3(t).users.create(s.tenant.id,h),t.set("user_id",p.user_id)}return p}const ot=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 wt(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 Oh=zt.extend({users:o.z.array(kn)}),L3=zt.extend({sessions:o.z.array(Tc)}),F3=zt.extend({organizations:o.z.array(fr)}),U3=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:ot,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(kn),Oh])}},description:"List of users"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),{"tenant-id":a}=t.req.valid("header");if(s!=null&&s.includes("identities.profileData.email")){const p=s.split("=")[1],g=(await t.env.data.users.list(a,{page:e,per_page:n,include_totals:r,q:`email:${p}`})).users.filter(z=>z.linked_to),[$]=g;if(!$)return t.json([]);const A=await t.env.data.users.get(a,$.linked_to);if(!A)throw new E(500,{message:"Primary account not found"});return t.json([kn.parse(A)])}const l=["-_exists_:linked_to"];s&&l.push(s);const u=await t.env.data.users.list(a,{page:e,per_page:n,include_totals:r,sort:wt(i),q:l.join(" ")}),d=u.users.filter(p=>!p.linked_to);return r?t.json(Oh.parse({users:d,length:u.length,start:u.start,limit:u.limit})):t.json(o.z.array(kn).parse(d))}).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:kn}},description:"List of users"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),r=await t.env.data.users.get(n,e);if(!r)throw new E(404);if(r.linked_to)throw new E(404,{message:"User is linked to another user"});return t.json(r)}).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"),{"tenant-id":n}=t.req.valid("header");if(!await t.env.data.users.remove(n,e))throw new E(404);return 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({...xa.shape})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:kn}},description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");t.set("body",n);const{email:r,phone_number:i,name:s,linked_to:a,email_verified:l,provider:u,connection:d}=n,p=`${n.provider}|${n.user_id||Dc()}`;try{const h=await t.env.data.users.create(e,{email:r,user_id:p,name:s||r||i,phone_number:i,provider:u,connection:d,linked_to:a??void 0,email_verified:l||!1,last_ip:"",is_social:!1,last_login:new Date().toISOString()});t.set("user_id",h.user_id);const g=Me(t,{type:Le.SUCCESS_API_OPERATION,description:"User created"});ln(t,t.env.data.logs.create(e,g));const $={...h,identities:[{connection:h.connection,provider:h.provider,user_id:bh(h.user_id),isSocial:h.is_social}]};return t.json(kn.parse($),{status:201})}catch(h){throw h.message==="User already exists"?new E(409,{message:"User already exists"}):h}}).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({...xa.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 p;const{data:e}=t.env,{"tenant-id":n}=t.req.valid("header"),r=t.req.valid("json"),{user_id:i}=t.req.valid("param"),{verify_email:s,password:a,...l}=r,u=await e.users.get(n,i);if(!u)throw new E(404);if(l.email&&l.email!==u.email){const h=await Tp(t.env.data.users,n,l.email);if(h.length&&h.some(g=>g.user_id!==i))throw new E(409,{message:"Another user with the same email address already exists."})}if(u.linked_to)throw new E(404,{message:"User is linked to another user"});if(await t.env.data.users.update(n,i,l),a){const h=(p=u.identities)==null?void 0:p.find(A=>A.connection==="Username-Password-Authentication");if(!h)throw new E(400,{message:"User does not have a password identity"});const g={user_id:h.user_id,password:await ss.hash(a,10),algorithm:"bcrypt"};await e.passwords.get(n,h.user_id)?await e.passwords.update(n,g):await e.passwords.create(n,g)}const d=await t.env.data.users.get(n,i);if(!d)throw new E(500);return t.json(d)}).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{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),{user_id:r}=t.req.valid("param"),i="link_with"in n?n.link_with:n.user_id,s=await t.env.data.users.get(e,r);if(!s)throw new E(400,{message:"Linking an inexistent identity is not allowed."});await t.env.data.users.update(e,i,{linked_to:r});const a=await t.env.data.users.list(e,{page:0,per_page:10,include_totals:!1,q:`linked_to:${r}`}),l=[s,...a.users].map(u=>({connection:u.connection,provider:u.provider,user_id:bh(u.user_id),isSocial:u.is_social}));return t.json(l,{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(kn)}},description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{user_id:n,provider:r,linked_user_id:i}=t.req.valid("param");await t.env.data.users.unlink(e,n,r,i);const s=await t.env.data.users.get(e,n);if(!s)throw new E(404);return t.json([kn.parse(s)])}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/sessions",request:{query:ot,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(Tc),L3])}},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"),{"tenant-id":s}=t.req.valid("header"),a=await t.env.data.sessions.list(s,{page:r,per_page:i,include_totals:n,q:`user_id:${e}`});return n?t.json(a):t.json(a.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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:A_}},description:"User permissions"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});const u=await t.env.data.userPermissions.list(n,e,{page:r,per_page:i,include_totals:!1,sort:wt(s),q:a});return t.json(u)}).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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userPermissions.create(n,e,{user_id:e,resource_server_identifier:s.resource_server_identifier,permission_name:s.permission_name}))throw new E(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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userPermissions.remove(n,e,s))throw new E(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:Ta}},description:"User roles"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});const i=await t.env.data.userRoles.list(n,e,void 0,"");return t.json(i)}).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"),{"tenant-id":n}=t.req.valid("header"),{roles:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userRoles.create(n,e,s,""))throw new E(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"),{"tenant-id":n}=t.req.valid("header"),{roles:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userRoles.remove(n,e,s,""))throw new E(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:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([F3,o.z.array(fr)])}},description:"List of user organizations"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),{page:r,per_page:i,include_totals:s,sort:a}=t.req.valid("query");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});const u=await t.env.data.userOrganizations.listUserOrganizations(n,e,{page:r,per_page:i,sort:wt(a)});return s?t.json({organizations:u.organizations,start:u.start,limit:u.limit,length:u.length}):t.json(u.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"),{"tenant-id":r}=t.req.valid("header");if(!await t.env.data.users.get(r,e))throw new E(404,{message:"User not found"});const a=(await t.env.data.userOrganizations.list(r,{q:`user_id:${e}`,per_page:100})).userOrganizations.find(l=>l.organization_id===n);if(!a)throw new E(404,{message:"User is not a member of this organization"});return await t.env.data.userOrganizations.remove(r,a.id),t.json({message:"User removed from organization successfully"})});/*! *****************************************************************************
|
|
72
|
+
</html>`}class Ra extends E{constructor(e,n){super(e,{message:JSON.stringify(n),res:new Response(JSON.stringify(n),{status:e,headers:{"Content-Type":"application/json"}})})}}const G_=["openid","profile","email","address","phone"];async function k3(t,e){var x,U;const{tenantId:n,clientId:r,audience:i,requestedScopes:s}=e,a=s.filter(q=>G_.includes(q)),u=(await t.env.data.resourceServers.list(n)).resource_servers.filter(q=>q.identifier===i);if(u.length===0)return{scopes:a,permissions:[]};const d=u[0];if(!d)return{scopes:a,permissions:[]};const p=((x=d.options)==null?void 0:x.enforce_policies)===!0,h=((U=d.options)==null?void 0:U.token_dialect)||"access_token",$=(await t.env.data.clientGrants.list(n,{q:`client_id:"${r}"`})).client_grants.find(q=>q.audience===i);if(!$)return{scopes:a,permissions:[]};const A=$.scope||[],z=(d.scopes||[]).map(q=>q.value);if(!p){let q;return s.length===0?q=A.filter(H=>z.includes(H)):q=s.filter(H=>z.includes(H)&&A.includes(H)),{scopes:[...new Set([...a,...q])],permissions:[]}}if(h==="access_token_authz"){const q=A.filter(F=>z.includes(F));return{scopes:a,permissions:q}}let T;return s.length===0?T=A.filter(q=>z.includes(q)):T=s.filter(q=>z.includes(q)&&A.includes(q)),{scopes:[...new Set([...a,...T])],permissions:[]}}async function ja(t,e){var G,Y;if(e.grantType===an.ClientCredential)return await k3(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(R=>R.organization_id===a))throw new Ra(403,{error:"access_denied",error_description:"User is not a member of the specified organization"});const l=s.filter(J=>G_.includes(J)),d=(await t.env.data.resourceServers.list(n)).resource_servers.filter(J=>J.identifier===i);if(d.length===0)return{scopes:l,permissions:[]};const p=d[0];if(!p)return{scopes:l,permissions:[]};const h=(p.scopes||[]).map(J=>J.value),g=((G=p.options)==null?void 0:G.enforce_policies)===!0,$=((Y=p.options)==null?void 0:Y.token_dialect)||"access_token";if(!g){const J=s.filter(R=>h.includes(R));return{scopes:[...new Set([...l,...J])],permissions:[]}}const A=await t.env.data.userPermissions.list(n,r,void 0,a),z=await t.env.data.userRoles.list(n,r,void 0,""),T=a?await t.env.data.userRoles.list(n,r,void 0,a):[],O=[...z,...T],x=[];for(const J of O)(await t.env.data.rolePermissions.list(n,J.id)).forEach(R=>{R.resource_server_identifier===i&&x.push(R.permission_name)});const U=new Set;A.forEach(J=>{J.resource_server_identifier===i&&U.add(J.permission_name)}),x.forEach(J=>{U.add(J)});const q=Array.from(U);if($==="access_token_authz"){const J=q.filter(Ae=>h.includes(Ae));return{scopes:l,permissions:J}}const F=s.filter(J=>h.includes(J)&&q.includes(J));return{scopes:[...new Set([...l,...F])],permissions:[]}}const Ch=["sub","iss","aud","exp","nbf","iat","jti"];async function Pc(t,e){var T,O;const{authParams:n,user:r,client:i,session_id:s}=e,{signingKeys:a}=await t.env.data.keys.list({q:"type:jwt_signing"}),l=a.filter(x=>!x.revoked_at||new Date(x.revoked_at)>new Date),u=l[l.length-1];if(!(u!=null&&u.pkcs7))throw new E(500,{message:"No signing key available"});const d=Xv(u.pkcs7),p=t.var.custom_domain?`https://${t.var.custom_domain}/`:t.env.ISSUER,h={aud:n.audience||"default",scope:n.scope||"",sub:(r==null?void 0:r.user_id)||n.client_id,iss:p,tenant_id:t.var.tenant_id,sid:s,...e.organization&&{org_id:e.organization},...e.permissions&&e.permissions.length>0&&{permissions:e.permissions}},g=r&&((T=n.scope)!=null&&T.split(" ").includes("openid"))?{aud:n.client_id,sub:r.user_id,iss:p,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,...e.organization&&{org_id:e.organization}}:void 0;(O=t.env.hooks)!=null&&O.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:(x,U)=>{if(Ch.includes(x))throw new Error(`Cannot overwrite reserved claim '${x}'`);h[x]=U}},idToken:{setCustomClaim:(x,U)=>{if(Ch.includes(x))throw new Error(`Cannot overwrite reserved claim '${x}'`);g&&(g[x]=U)}},access:{deny:x=>{throw new E(400,{message:`Access denied: ${x}`})}}});const $={includeIssuedTimestamp:!0,expiresIn:new Ep(1,"d"),headers:{kid:u.kid}},A=await xh("RS256",d,h,$),z=g?await xh("RS256",d,g,$):void 0;return{access_token:A,refresh_token:e.refresh_token,id_token:z,token_type:"Bearer",expires_in:86400}}async function W_(t,e){return{code:(await t.env.data.codes.create(e.client.tenant.id,{code_id:He(),user_id:e.user.user_id,code_type:"authorization_code",login_id:e.login_id,expires_at:new Date(Date.now()+Zv*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 X_(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:He(),session_id:s,client_id:n.client_id,idle_expires_at:new Date(Date.now()+Rc*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 J_(t,{user:e,client:n,loginSession:r}){const i=await t.env.data.sessions.create(n.tenant.id,{id:He(),user_id:e.user_id,login_session_id:r.id,idle_expires_at:new Date(Date.now()+Rc*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 Dn(t,e){var A,z;const{authParams:n,client:r,ticketAuth:i}=e;let{user:s}=e;const a=n.response_type||Yt.CODE,l=n.response_mode||zn.QUERY,u=Me(t,{type:Le.SUCCESS_LOGIN,description:`Successful login for ${s.user_id}`,userId:s.user_id});if(ln(t,t.env.data.logs.create(r.tenant.id,u)),ln(t,t.env.data.users.update(r.tenant.id,s.user_id,{last_login:new Date().toISOString(),last_ip:t.var.ip||"",login_count:s.login_count+1})),i){if(!e.loginSession)throw new E(500,{message:"Login session not found for ticket auth."});const T=Wv(),O=He(12),x=await t.env.data.codes.create(r.tenant.id,{code_id:He(),code_type:"ticket",login_id:e.loginSession.id,expires_at:new Date(Date.now()+eb).toISOString(),code_verifier:[O,T].join("|"),redirect_uri:n.redirect_uri,state:n.state,nonce:n.nonce});return t.json({login_ticket:x.code_id,co_verifier:T,co_id:O})}let d=e.refreshToken,p=e.sessionId;if(!p&&((A=e.loginSession)!=null&&A.session_id)){p=e.loginSession.session_id;const T=await t.env.data.sessions.get(r.tenant.id,p);T&&!T.clients.includes(r.client_id)&&await t.env.data.sessions.update(r.tenant.id,p,{clients:[...T.clients,r.client_id]})}else if(!p){if(!e.loginSession)throw new E(500,{message:"Login session not found for creating a new session."});p=(await J_(t,{user:s,client:r,loginSession:e.loginSession})).id}if(!d&&((z=n.scope)!=null&&z.split(" ").includes("offline_access"))&&![Yt.TOKEN,Yt.CODE].includes(a)&&(d=(await X_(t,{user:s,client:r,session_id:p,scope:n.scope,audience:n.audience})).id),l===zn.SAML_POST){if(!p)throw new E(500,{message:"Session ID not available for SAML response"});return x3(t,e.client,e.authParams,s,p)}const h=await N3(t,{authParams:n,user:s,client:r,session_id:p,refresh_token:d,strategy:e.strategy,loginSession:e.loginSession,responseType:a,skipHooks:e.skipHooks,organization:e.organization});if(h instanceof Response)return h;if(l===zn.WEB_MESSAGE){if(!n.redirect_uri)throw new E(400,{message:"Redirect URI not allowed for WEB_MESSAGE response mode."});const T=new Headers;if(p){const U=Da(r.tenant.id,p,t.var.host||"");U&&T.set("set-cookie",U)}else console.warn("Session ID not available for WEB_MESSAGE, cookie will not be set.");const O=new URL(n.redirect_uri),x=`${O.protocol}//${O.host}`;return t.html(Du(x,JSON.stringify({...h,state:n.state})),{headers:T})}if(!n.redirect_uri)throw new E(400,{message:"Redirect uri not found for this response mode."});const g=new Headers;if(p){const T=Da(r.tenant.id,p,t.var.custom_domain||t.req.header("host")||"");T&&g.set("set-cookie",T)}const $=new URL(n.redirect_uri);if("code"in h)$.searchParams.set("code",h.code),h.state&&$.searchParams.set("state",h.state);else if("access_token"in h)$.hash=new URLSearchParams({access_token:h.access_token,...h.id_token&&{id_token:h.id_token},token_type:h.token_type,expires_in:h.expires_in.toString(),...n.state&&{state:n.state},...n.scope&&{scope:n.scope}}).toString();else throw new E(500,{message:"Invalid token response for implicit flow."});return g.set("location",$.toString()),new Response("Redirecting",{status:302,headers:g})}async function N3(t,e){var l,u,d,p;let{user:n}=e;const r=e.responseType||Yt.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($=>$.organization_id===e.organization))throw new Ra(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 h;if(e.grantType===an.ClientCredential||!n&&!e.user)h=await ja(t,{grantType:an.ClientCredential,tenantId:e.client.tenant.id,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((l=e.authParams.scope)==null?void 0:l.split(" "))||[],organizationId:e.organization});else{const g=(n==null?void 0:n.user_id)||((u=e.user)==null?void 0:u.user_id);if(!g)throw new Ra(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});h=await ja(t,{grantType:e.grantType,tenantId:e.client.tenant.id,userId:g,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((d=e.authParams.scope)==null?void 0:d.split(" "))||[],organizationId:e.organization})}i=h.scopes.join(" "),s=h.permissions}catch(h){if(h instanceof E)throw h;console.error("Error calculating scopes and permissions:",h)}const a={...e.authParams,scope:i};if(e.loginSession&&n&&!e.skipHooks){e.strategy&&((p=n.app_metadata)==null?void 0:p.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 h=await P3(t,t.env.data,e.client.tenant.id,n,e.loginSession,{client:e.client,authParams:a});if(h instanceof Response)return h;n=h}if(r===Yt.CODE){if(!n||!e.loginSession)throw new E(500,{message:"User and loginSession is required for code flow"});return await W_(t,{user:n,client:e.client,authParams:a,login_id:e.loginSession.id})}else return Pc(t,{...e,user:n,authParams:a,permissions:s})}async function C3(t,e,n){const r=await t.env.data.tenants.get(e);if(!r)throw new Error(`Tenant not found: ${e}`);const i={client_id:t.env.ISSUER,tenant:r,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),name:t.env.ISSUER,global:!1,is_first_party:!1,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:[]};return Pc(t,{client:i,authParams:{client_id:t.env.ISSUER,response_type:Yt.TOKEN,scope:n}})}async function Y_(t,e,n){const r=await C3(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=Me(t,{type:Le.FAILED_HOOK,description:`Failed to invoke hook ${i.hook_id}`});await t.env.data.logs.create(n.tenant_id,a)}}function z3(t){return async(e,n)=>{const{hooks:r}=await t.env.data.hooks.list(e);return await Y_(t,r,{tenant_id:e,user:n,trigger_id:"post-user-registration"}),n}}function I3(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 Y_(t,r,{tenant_id:e,email:n,trigger_id:"pre-user-signup"})}}function zh(t){return typeof t.form_id=="string"}async function T3(t,e,n){var u;const r=t.env.data,i=t.var.tenant_id||t.req.header("tenant-id");if(!i)throw new E(400,{message:"Missing tenant_id in context"});const s=await r.forms.get(i,e);if(!s)throw new E(404,{message:"Form not found for post-user-login hook"});let a=(u=s.start)==null?void 0:u.next_node;if(!a&&s.nodes&&s.nodes.length>0){const d=s.nodes.find(p=>p.type==="STEP");a=d==null?void 0:d.id}if(!a)throw new E(400,{message:"No start node found in form"});let l=`/u/forms/${s.id}/nodes/${a}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:l}})}function Ih(t){return typeof t.page_id=="string"&&typeof t.enabled=="boolean"}async function O3(t,e,n,r,i){const s=t.env.data,a=t.var.tenant_id||t.req.header("tenant-id");if(!a)throw new E(400,{message:"Missing tenant_id in context"});if(i&&!(await s.userPermissions.list(a,r.user_id)).some(p=>p.permission_name===i))return r;let l=`/u/${e}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:l}})}function Th(t){return typeof t.url=="string"}function D3(t,e){return async(n,r)=>{var a,l,u;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((l=t.env.hooks)!=null&&l.onExecutePreUserRegistration)try{await t.env.hooks.onExecutePreUserRegistration({ctx:t,user:r,request:i},{user:{setUserMetadata:async(d,p)=>{r[d]=p}}})}catch{const p=Me(t,{type:Le.FAILED_SIGNUP,description:"Pre user registration hook failed"});await e.logs.create(n,p)}let s=await Mv(e)(n,r);if((u=t.env.hooks)!=null&&u.onExecutePostUserRegistration)try{await t.env.hooks.onExecutePostUserRegistration({ctx:t,user:r,request:i},{user:{}})}catch{const p=Me(t,{type:Le.FAILED_SIGNUP,description:"Post user registration hook failed"});await t.env.data.logs.create(n,p)}return await z3(t)(n,s),s}}function R3(t,e){return async(n,r,i)=>{var a,l;const s={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((l=t.env.hooks)!=null&&l.onExecutePreUserUpdate)try{await t.env.hooks.onExecutePreUserUpdate({ctx:t,user_id:r,updates:i,request:s},{user:{setUserMetadata:async(u,d)=>{i[u]=d}},cancel:()=>{throw new E(400,{message:"User update cancelled by pre-update hook"})}})}catch(u){if(u instanceof E)throw u;const d=Me(t,{type:Le.FAILED_HOOK,description:"Pre user update hook failed"});throw await e.logs.create(n,d),new E(400,{message:"Pre user update hook failed"})}if(await e.users.update(n,r,i),i.email){const u=Me(t,{type:Le.SUCCESS_CHANGE_EMAIL,description:`Email updated to ${i.email}`,userId:r});await e.logs.create(n,u),console.log("log:",u)}return!0}}async function j3(t,e,n,r){var i;if(e.disable_sign_ups){const s=(i=t.var.loginSession)==null?void 0:i.authorization_url;if(!(s&&new URL(s).searchParams.get("screen_hint")==="signup")&&!await Op({userAdapter:n.users,tenant_id:e.tenant.id,email:r})){const u=Me(t,{type:Le.FAILED_SIGNUP,description:"Public signup is disabled"});throw await n.logs.create(e.tenant.id,u),new E(400,{message:"Signups are disabled for this client"})}}await I3(t)(t.var.tenant_id||"",r)}function as(t,e){return{...e,users:{...e.users,create:D3(t,e),update:R3(t,e)}}}async function P3(t,e,n,r,i,s){var u;(u=t.env.hooks)!=null&&u.onExecutePostLogin&&(s!=null&&s.client)&&(s!=null&&s.authParams)&&await t.env.hooks.onExecutePostLogin({ctx:t,client:s.client,user:r,request:{ip:t.var.ip,user_agent:t.var.useragent,method:t.req.method,url:t.req.url},scope:s.authParams.scope||"",grant_type:""},{prompt:{render:d=>{}}});const{hooks:a}=await e.hooks.list(n,{q:"trigger_id:post-user-login",page:0,per_page:100,include_totals:!1});if(i){const d=a.find(h=>h.enabled&&zh(h));if(d&&zh(d))return T3(t,d.form_id,i);const p=a.find(h=>h.enabled&&Ih(h));if(p&&Ih(p))return O3(t,p.page_id,i,r,p.permission_required)}const l=a.filter(d=>d.enabled&&Th(d));for(const d of l)if(Th(d))try{await fetch(d.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tenant_id:n,user:r,trigger_id:"post-user-login"})})}catch{const h=Me(t,{type:Le.FAILED_HOOK,description:`Failed to invoke post-user-login webhook: ${d.url}`});await e.logs.create(n,h)}return r}function B3(t){return as(t,t.env.data)}async function Tp(t,e,n){return(await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`})).users}async function eo({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 Op({userAdapter:t,tenant_id:e,email:n}){var l;const{users:r}=await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`}),i=r.filter(u=>!(u.provider==="auth2"&&!u.email_verified));if(i.length===0)return;const s=i.filter(u=>!u.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,(l=i[0])==null?void 0:l.linked_to);if(!a)throw new Error("Primary account not found");return a}async function Po({userAdapter:t,tenant_id:e,username:n,provider:r}){const i=await eo({userAdapter:t,tenant_id:e,username:n,provider:r});return i?i.linked_to?t.get(e,i.linked_to):i:null}async function Bc(t,e){const{username:n,provider:r,connection:i,client:s,userId:a,isSocial:l,profileData:u={},ip:d=""}=e;let p=await Po({userAdapter:t.env.data.users,tenant_id:e.client.tenant.id,username:n,provider:r});if(!p){const h={user_id:`${r}|${a||Dc()}`,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:l,last_login:new Date().toISOString(),profileData:JSON.stringify(u)};p=await B3(t).users.create(s.tenant.id,h),t.set("user_id",p.user_id)}return p}const ot=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 wt(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 Oh=zt.extend({users:o.z.array(kn)}),L3=zt.extend({sessions:o.z.array(Tc)}),F3=zt.extend({organizations:o.z.array(fr)}),U3=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:ot,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(kn),Oh])}},description:"List of users"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),{"tenant-id":a}=t.req.valid("header");if(s!=null&&s.includes("identities.profileData.email")){const p=s.split("=")[1],g=(await t.env.data.users.list(a,{page:e,per_page:n,include_totals:r,q:`email:${p}`})).users.filter(z=>z.linked_to),[$]=g;if(!$)return t.json([]);const A=await t.env.data.users.get(a,$.linked_to);if(!A)throw new E(500,{message:"Primary account not found"});return t.json([kn.parse(A)])}const l=["-_exists_:linked_to"];s&&l.push(s);const u=await t.env.data.users.list(a,{page:e,per_page:n,include_totals:r,sort:wt(i),q:l.join(" ")}),d=u.users.filter(p=>!p.linked_to);return r?t.json(Oh.parse({users:d,length:u.length,start:u.start,limit:u.limit})):t.json(o.z.array(kn).parse(d))}).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:kn}},description:"List of users"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),r=await t.env.data.users.get(n,e);if(!r)throw new E(404);if(r.linked_to)throw new E(404,{message:"User is linked to another user"});return t.json(r)}).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"),{"tenant-id":n}=t.req.valid("header");if(!await t.env.data.users.remove(n,e))throw new E(404);return 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({...xa.shape})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:kn}},description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");t.set("body",n);const{email:r,phone_number:i,name:s,linked_to:a,email_verified:l,provider:u,connection:d}=n,p=`${n.provider}|${n.user_id||Dc()}`;try{const h=await t.env.data.users.create(e,{email:r,user_id:p,name:s||r||i,phone_number:i,provider:u,connection:d,linked_to:a??void 0,email_verified:l||!1,last_ip:"",is_social:!1,last_login:new Date().toISOString()});t.set("user_id",h.user_id);const g=Me(t,{type:Le.SUCCESS_API_OPERATION,description:"User created"});ln(t,t.env.data.logs.create(e,g));const $={...h,identities:[{connection:h.connection,provider:h.provider,user_id:bh(h.user_id),isSocial:h.is_social}]};return t.json(kn.parse($),{status:201})}catch(h){throw h.message==="User already exists"?new E(409,{message:"User already exists"}):h}}).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({...xa.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 p;const{data:e}=t.env,{"tenant-id":n}=t.req.valid("header"),r=t.req.valid("json"),{user_id:i}=t.req.valid("param"),{verify_email:s,password:a,...l}=r,u=await e.users.get(n,i);if(!u)throw new E(404);if(l.email&&l.email!==u.email){const h=await Tp(t.env.data.users,n,l.email);if(h.length&&h.some(g=>g.user_id!==i))throw new E(409,{message:"Another user with the same email address already exists."})}if(u.linked_to)throw new E(404,{message:"User is linked to another user"});if(await t.env.data.users.update(n,i,l),a){const h=(p=u.identities)==null?void 0:p.find(A=>A.connection==="Username-Password-Authentication");if(!h)throw new E(400,{message:"User does not have a password identity"});const g={user_id:h.user_id,password:await ss.hash(a,10),algorithm:"bcrypt"};await e.passwords.get(n,h.user_id)?await e.passwords.update(n,g):await e.passwords.create(n,g)}const d=await t.env.data.users.get(n,i);if(!d)throw new E(500);return t.json(d)}).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{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),{user_id:r}=t.req.valid("param"),i="link_with"in n?n.link_with:n.user_id,s=await t.env.data.users.get(e,r);if(!s)throw new E(400,{message:"Linking an inexistent identity is not allowed."});await t.env.data.users.update(e,i,{linked_to:r});const a=await t.env.data.users.list(e,{page:0,per_page:10,include_totals:!1,q:`linked_to:${r}`}),l=[s,...a.users].map(u=>({connection:u.connection,provider:u.provider,user_id:bh(u.user_id),isSocial:u.is_social}));return t.json(l,{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(kn)}},description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{user_id:n,provider:r,linked_user_id:i}=t.req.valid("param");await t.env.data.users.unlink(e,n,r,i);const s=await t.env.data.users.get(e,n);if(!s)throw new E(404);return t.json([kn.parse(s)])}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/sessions",request:{query:ot,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(Tc),L3])}},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"),{"tenant-id":s}=t.req.valid("header"),a=await t.env.data.sessions.list(s,{page:r,per_page:i,include_totals:n,q:`user_id:${e}`});return n?t.json(a):t.json(a.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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:A_}},description:"User permissions"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});const u=await t.env.data.userPermissions.list(n,e,{page:r,per_page:i,include_totals:!1,sort:wt(s),q:a});return t.json(u)}).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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userPermissions.create(n,e,{user_id:e,resource_server_identifier:s.resource_server_identifier,permission_name:s.permission_name}))throw new E(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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userPermissions.remove(n,e,s))throw new E(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:Ta}},description:"User roles"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});const i=await t.env.data.userRoles.list(n,e,void 0,"");return t.json(i)}).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"),{"tenant-id":n}=t.req.valid("header"),{roles:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userRoles.create(n,e,s,""))throw new E(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"),{"tenant-id":n}=t.req.valid("header"),{roles:r}=t.req.valid("json");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});for(const s of r)if(!await t.env.data.userRoles.remove(n,e,s,""))throw new E(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:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([F3,o.z.array(fr)])}},description:"List of user organizations"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),{page:r,per_page:i,include_totals:s,sort:a}=t.req.valid("query");if(!await t.env.data.users.get(n,e))throw new E(404,{message:"User not found"});const u=await t.env.data.userOrganizations.listUserOrganizations(n,e,{page:r,per_page:i,sort:wt(a)});return s?t.json({organizations:u.organizations,start:u.start,limit:u.limit,length:u.length}):t.json(u.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"),{"tenant-id":r}=t.req.valid("header");if(!await t.env.data.users.get(r,e))throw new E(404,{message:"User not found"});const a=(await t.env.data.userOrganizations.list(r,{q:`user_id:${e}`,per_page:100})).userOrganizations.find(l=>l.organization_id===n);if(!a)throw new E(404,{message:"User is not a member of this organization"});return await t.env.data.userOrganizations.remove(r,a.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
|
|
@@ -82,7 +82,7 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
82
82
|
|
|
83
83
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
84
84
|
and limitations under the License.
|
|
85
|
-
***************************************************************************** */var Dh;(function(t){(function(e){var n=typeof globalThis=="object"?globalThis:typeof Lr=="object"?Lr:typeof self=="object"?self:typeof this=="object"?this:l(),r=i(t);typeof n.Reflect<"u"&&(r=i(n.Reflect,r)),e(r,n),typeof n.Reflect>"u"&&(n.Reflect=t);function i(u,d){return function(p,h){Object.defineProperty(u,p,{configurable:!0,writable:!0,value:h}),d&&d(p,h)}}function s(){try{return Function("return this;")()}catch{}}function a(){try{return(0,eval)("(function() { return this; })()")}catch{}}function l(){return s()||a()}})(function(e,n){var r=Object.prototype.hasOwnProperty,i=typeof Symbol=="function",s=i&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",a=i&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",l=typeof Object.create=="function",u={__proto__:[]}instanceof Array,d=!l&&!u,p={create:l?function(){return An(Object.create(null))}:u?function(){return An({__proto__:null})}:function(){return An({})},has:d?function(D,I){return r.call(D,I)}:function(D,I){return I in D},get:d?function(D,I){return r.call(D,I)?D[I]:void 0}:function(D,I){return D[I]}},h=Object.getPrototypeOf(Function),g=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:ce(),$=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Kt(),A=typeof WeakMap=="function"?WeakMap:Pt(),z=i?Symbol.for("@reflect-metadata:registry"):void 0,T=xn(),O=xt(T);function x(D,I,M,te){if(Q(M)){if(!Rt(D))throw new TypeError;if(!he(I))throw new TypeError;return L(D,I)}else{if(!Rt(D))throw new TypeError;if(!Pe(I))throw new TypeError;if(!Pe(te)&&!Q(te)&&!ye(te))throw new TypeError;return ye(te)&&(te=void 0),M=tt(M),j(D,I,M,te)}}e("decorate",x);function U(D,I){function M(te,we){if(!Pe(te))throw new TypeError;if(!Q(we)&&!ge(we))throw new TypeError;de(D,I,te,we)}return M}e("metadata",U);function q(D,I,M,te){if(!Pe(M))throw new TypeError;return Q(te)||(te=tt(te)),de(D,I,M,te)}e("defineMetadata",q);function F(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),N(D,I,M)}e("hasMetadata",F);function K(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),k(D,I,M)}e("hasOwnMetadata",K);function G(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),B(D,I,M)}e("getMetadata",G);function Y(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),H(D,I,M)}e("getOwnMetadata",Y);function J(D,I){if(!Pe(D))throw new TypeError;return Q(I)||(I=tt(I)),ie(D,I)}e("getMetadataKeys",J);function Ae(D,I){if(!Pe(D))throw new TypeError;return Q(I)||(I=tt(I)),ve(D,I)}e("getOwnMetadataKeys",Ae);function R(D,I,M){if(!Pe(I))throw new TypeError;if(Q(M)||(M=tt(M)),!Pe(I))throw new TypeError;Q(M)||(M=tt(M));var te=me(I,M,!1);return Q(te)?!1:te.OrdinaryDeleteMetadata(D,I,M)}e("deleteMetadata",R);function L(D,I){for(var M=D.length-1;M>=0;--M){var te=D[M],we=te(I);if(!Q(we)&&!ye(we)){if(!he(we))throw new TypeError;I=we}}return I}function j(D,I,M,te){for(var we=D.length-1;we>=0;--we){var nt=D[we],Re=nt(I,M,te);if(!Q(Re)&&!ye(Re)){if(!Pe(Re))throw new TypeError;te=Re}}return te}function N(D,I,M){var te=k(D,I,M);if(te)return!0;var we=jt(I);return ye(we)?!1:N(D,we,M)}function k(D,I,M){var te=me(I,M,!1);return Q(te)?!1:ee(te.OrdinaryHasOwnMetadata(D,I,M))}function B(D,I,M){var te=k(D,I,M);if(te)return H(D,I,M);var we=jt(I);if(!ye(we))return B(D,we,M)}function H(D,I,M){var te=me(I,M,!1);if(!Q(te))return te.OrdinaryGetOwnMetadata(D,I,M)}function de(D,I,M,te){var we=me(M,te,!0);we.OrdinaryDefineOwnMetadata(D,I,M,te)}function ie(D,I){var M=ve(D,I),te=jt(D);if(te===null)return M;var we=ie(te,I);if(we.length<=0)return M;if(M.length<=0)return we;for(var nt=new $,Re=[],c=0,f=M;c<f.length;c++){var y=f[c],b=nt.has(y);b||(nt.add(y),Re.push(y))}for(var v=0,S=we;v<S.length;v++){var y=S[v],b=nt.has(y);b||(nt.add(y),Re.push(y))}return Re}function ve(D,I){var M=me(D,I,!1);return M?M.OrdinaryOwnMetadataKeys(D,I):[]}function ke(D){if(D===null)return 1;switch(typeof D){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return D===null?1:6;default:return 6}}function Q(D){return D===void 0}function ye(D){return D===null}function Fn(D){return typeof D=="symbol"}function Pe(D){return typeof D=="object"?D!==null:typeof D=="function"}function Ge(D,I){switch(ke(D)){case 0:return D;case 1:return D;case 2:return D;case 3:return D;case 4:return D;case 5:return D}var M="string",te=Ls(D,s);if(te!==void 0){var we=te.call(D,M);if(Pe(we))throw new TypeError;return we}return nn(D)}function nn(D,I){var M,te;{var we=D.toString;if(Fe(we)){var te=we.call(D);if(!Pe(te))return te}var M=D.valueOf;if(Fe(M)){var te=M.call(D);if(!Pe(te))return te}}throw new TypeError}function ee(D){return!!D}function se(D){return""+D}function tt(D){var I=Ge(D);return Fn(I)?I:se(I)}function Rt(D){return Array.isArray?Array.isArray(D):D instanceof Object?D instanceof Array:Object.prototype.toString.call(D)==="[object Array]"}function Fe(D){return typeof D=="function"}function he(D){return typeof D=="function"}function ge(D){switch(ke(D)){case 3:return!0;case 4:return!0;default:return!1}}function go(D,I){return D===I||D!==D&&I!==I}function Ls(D,I){var M=D[I];if(M!=null){if(!Fe(M))throw new TypeError;return M}}function pe(D){var I=Ls(D,a);if(!Fe(I))throw new TypeError;var M=I.call(D);if(!Pe(M))throw new TypeError;return M}function at(D){return D.value}function Fs(D){var I=D.next();return I.done?!1:I}function ae(D){var I=D.return;I&&I.call(D)}function jt(D){var I=Object.getPrototypeOf(D);if(typeof D!="function"||D===h||I!==h)return I;var M=D.prototype,te=M&&Object.getPrototypeOf(M);if(te==null||te===Object.prototype)return I;var we=te.constructor;return typeof we!="function"||we===D?I:we}function Ht(){var D;!Q(z)&&typeof n.Reflect<"u"&&!(z in n.Reflect)&&typeof n.Reflect.defineMetadata=="function"&&(D=rn(n.Reflect));var I,M,te,we=new A,nt={registerProvider:Re,getProvider:f,setProvider:b};return nt;function Re(v){if(!Object.isExtensible(nt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case D===v:break;case Q(I):I=v;break;case I===v:break;case Q(M):M=v;break;case M===v:break;default:te===void 0&&(te=new $),te.add(v);break}}function c(v,S){if(!Q(I)){if(I.isProviderFor(v,S))return I;if(!Q(M)){if(M.isProviderFor(v,S))return I;if(!Q(te))for(var W=pe(te);;){var _e=Fs(W);if(!_e)return;var Ce=at(_e);if(Ce.isProviderFor(v,S))return ae(W),Ce}}}if(!Q(D)&&D.isProviderFor(v,S))return D}function f(v,S){var W=we.get(v),_e;return Q(W)||(_e=W.get(S)),Q(_e)&&(_e=c(v,S),Q(_e)||(Q(W)&&(W=new g,we.set(v,W)),W.set(S,_e))),_e}function y(v){if(Q(v))throw new TypeError;return I===v||M===v||!Q(te)&&te.has(v)}function b(v,S,W){if(!y(W))throw new Error("Metadata provider not registered.");var _e=f(v,S);if(_e!==W){if(!Q(_e))return!1;var Ce=we.get(v);Q(Ce)&&(Ce=new g,we.set(v,Ce)),Ce.set(S,W)}return!0}}function xn(){var D;return!Q(z)&&Pe(n.Reflect)&&Object.isExtensible(n.Reflect)&&(D=n.Reflect[z]),Q(D)&&(D=Ht()),!Q(z)&&Pe(n.Reflect)&&Object.isExtensible(n.Reflect)&&Object.defineProperty(n.Reflect,z,{enumerable:!1,configurable:!1,writable:!1,value:D}),D}function xt(D){var I=new A,M={isProviderFor:function(y,b){var v=I.get(y);return Q(v)?!1:v.has(b)},OrdinaryDefineOwnMetadata:Re,OrdinaryHasOwnMetadata:we,OrdinaryGetOwnMetadata:nt,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:f};return T.registerProvider(M),M;function te(y,b,v){var S=I.get(y),W=!1;if(Q(S)){if(!v)return;S=new g,I.set(y,S),W=!0}var _e=S.get(b);if(Q(_e)){if(!v)return;if(_e=new g,S.set(b,_e),!D.setProvider(y,b,M))throw S.delete(b),W&&I.delete(y),new Error("Wrong provider for target.")}return _e}function we(y,b,v){var S=te(b,v,!1);return Q(S)?!1:ee(S.has(y))}function nt(y,b,v){var S=te(b,v,!1);if(!Q(S))return S.get(y)}function Re(y,b,v,S){var W=te(v,S,!0);W.set(y,b)}function c(y,b){var v=[],S=te(y,b,!1);if(Q(S))return v;for(var W=S.keys(),_e=pe(W),Ce=0;;){var oe=Fs(_e);if(!oe)return v.length=Ce,v;var Ee=at(oe);try{v[Ce]=Ee}catch(At){try{ae(_e)}finally{throw At}}Ce++}}function f(y,b,v){var S=te(b,v,!1);if(Q(S)||!S.delete(y))return!1;if(S.size===0){var W=I.get(b);Q(W)||(W.delete(v),W.size===0&&I.delete(W))}return!0}}function rn(D){var I=D.defineMetadata,M=D.hasOwnMetadata,te=D.getOwnMetadata,we=D.getOwnMetadataKeys,nt=D.deleteMetadata,Re=new A,c={isProviderFor:function(f,y){var b=Re.get(f);return!Q(b)&&b.has(y)?!0:we(f,y).length?(Q(b)&&(b=new $,Re.set(f,b)),b.add(y),!0):!1},OrdinaryDefineOwnMetadata:I,OrdinaryHasOwnMetadata:M,OrdinaryGetOwnMetadata:te,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:nt};return c}function me(D,I,M){var te=T.getProvider(D,I);if(!Q(te))return te;if(M){if(T.setProvider(D,I,O))return O;throw new Error("Illegal state.")}}function ce(){var D={},I=[],M=function(){function c(f,y,b){this._index=0,this._keys=f,this._values=y,this._selector=b}return c.prototype["@@iterator"]=function(){return this},c.prototype[a]=function(){return this},c.prototype.next=function(){var f=this._index;if(f>=0&&f<this._keys.length){var y=this._selector(this._keys[f],this._values[f]);return f+1>=this._keys.length?(this._index=-1,this._keys=I,this._values=I):this._index++,{value:y,done:!1}}return{value:void 0,done:!0}},c.prototype.throw=function(f){throw this._index>=0&&(this._index=-1,this._keys=I,this._values=I),f},c.prototype.return=function(f){return this._index>=0&&(this._index=-1,this._keys=I,this._values=I),{value:f,done:!0}},c}(),te=function(){function c(){this._keys=[],this._values=[],this._cacheKey=D,this._cacheIndex=-2}return Object.defineProperty(c.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),c.prototype.has=function(f){return this._find(f,!1)>=0},c.prototype.get=function(f){var y=this._find(f,!1);return y>=0?this._values[y]:void 0},c.prototype.set=function(f,y){var b=this._find(f,!0);return this._values[b]=y,this},c.prototype.delete=function(f){var y=this._find(f,!1);if(y>=0){for(var b=this._keys.length,v=y+1;v<b;v++)this._keys[v-1]=this._keys[v],this._values[v-1]=this._values[v];return this._keys.length--,this._values.length--,go(f,this._cacheKey)&&(this._cacheKey=D,this._cacheIndex=-2),!0}return!1},c.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=D,this._cacheIndex=-2},c.prototype.keys=function(){return new M(this._keys,this._values,we)},c.prototype.values=function(){return new M(this._keys,this._values,nt)},c.prototype.entries=function(){return new M(this._keys,this._values,Re)},c.prototype["@@iterator"]=function(){return this.entries()},c.prototype[a]=function(){return this.entries()},c.prototype._find=function(f,y){if(!go(this._cacheKey,f)){this._cacheIndex=-1;for(var b=0;b<this._keys.length;b++)if(go(this._keys[b],f)){this._cacheIndex=b;break}}return this._cacheIndex<0&&y&&(this._cacheIndex=this._keys.length,this._keys.push(f),this._values.push(void 0)),this._cacheIndex},c}();return te;function we(c,f){return c}function nt(c,f){return f}function Re(c,f){return[c,f]}}function Kt(){var D=function(){function I(){this._map=new g}return Object.defineProperty(I.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),I.prototype.has=function(M){return this._map.has(M)},I.prototype.add=function(M){return this._map.set(M,M),this},I.prototype.delete=function(M){return this._map.delete(M)},I.prototype.clear=function(){this._map.clear()},I.prototype.keys=function(){return this._map.keys()},I.prototype.values=function(){return this._map.keys()},I.prototype.entries=function(){return this._map.entries()},I.prototype["@@iterator"]=function(){return this.keys()},I.prototype[a]=function(){return this.keys()},I}();return D}function Pt(){var D=16,I=p.create(),M=te();return function(){function f(){this._key=te()}return f.prototype.has=function(y){var b=we(y,!1);return b!==void 0?p.has(b,this._key):!1},f.prototype.get=function(y){var b=we(y,!1);return b!==void 0?p.get(b,this._key):void 0},f.prototype.set=function(y,b){var v=we(y,!0);return v[this._key]=b,this},f.prototype.delete=function(y){var b=we(y,!1);return b!==void 0?delete b[this._key]:!1},f.prototype.clear=function(){this._key=te()},f}();function te(){var f;do f="@@WeakMap@@"+c();while(p.has(I,f));return I[f]=!0,f}function we(f,y){if(!r.call(f,M)){if(!y)return;Object.defineProperty(f,M,{value:p.create()})}return f[M]}function nt(f,y){for(var b=0;b<y;++b)f[b]=Math.random()*255|0;return f}function Re(f){if(typeof Uint8Array=="function"){var y=new Uint8Array(f);return typeof crypto<"u"?crypto.getRandomValues(y):typeof msCrypto<"u"?msCrypto.getRandomValues(y):nt(y,f),y}return nt(new Array(f),f)}function c(){var f=Re(D);f[6]=f[6]&79|64,f[8]=f[8]&191|128;for(var y="",b=0;b<D;++b){var v=f[b];(b===4||b===6||b===8)&&(y+="-"),v<16&&(y+="0"),y+=v.toString(16).toLowerCase()}return y}}function An(D){return D.__=void 0,delete D.__,D}})})(Dh||(Dh={}));/*!
|
|
85
|
+
***************************************************************************** */var Dh;(function(t){(function(e){var n=typeof globalThis=="object"?globalThis:typeof Lr=="object"?Lr:typeof self=="object"?self:typeof this=="object"?this:l(),r=i(t);typeof n.Reflect<"u"&&(r=i(n.Reflect,r)),e(r,n),typeof n.Reflect>"u"&&(n.Reflect=t);function i(u,d){return function(p,h){Object.defineProperty(u,p,{configurable:!0,writable:!0,value:h}),d&&d(p,h)}}function s(){try{return Function("return this;")()}catch{}}function a(){try{return(0,eval)("(function() { return this; })()")}catch{}}function l(){return s()||a()}})(function(e,n){var r=Object.prototype.hasOwnProperty,i=typeof Symbol=="function",s=i&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",a=i&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",l=typeof Object.create=="function",u={__proto__:[]}instanceof Array,d=!l&&!u,p={create:l?function(){return An(Object.create(null))}:u?function(){return An({__proto__:null})}:function(){return An({})},has:d?function(D,I){return r.call(D,I)}:function(D,I){return I in D},get:d?function(D,I){return r.call(D,I)?D[I]:void 0}:function(D,I){return D[I]}},h=Object.getPrototypeOf(Function),g=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:ce(),$=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Kt(),A=typeof WeakMap=="function"?WeakMap:Pt(),z=i?Symbol.for("@reflect-metadata:registry"):void 0,T=xn(),O=xt(T);function x(D,I,M,te){if(Q(M)){if(!Rt(D))throw new TypeError;if(!he(I))throw new TypeError;return L(D,I)}else{if(!Rt(D))throw new TypeError;if(!Pe(I))throw new TypeError;if(!Pe(te)&&!Q(te)&&!ye(te))throw new TypeError;return ye(te)&&(te=void 0),M=tt(M),j(D,I,M,te)}}e("decorate",x);function U(D,I){function M(te,we){if(!Pe(te))throw new TypeError;if(!Q(we)&&!ge(we))throw new TypeError;de(D,I,te,we)}return M}e("metadata",U);function q(D,I,M,te){if(!Pe(M))throw new TypeError;return Q(te)||(te=tt(te)),de(D,I,M,te)}e("defineMetadata",q);function F(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),N(D,I,M)}e("hasMetadata",F);function H(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),k(D,I,M)}e("hasOwnMetadata",H);function G(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),B(D,I,M)}e("getMetadata",G);function Y(D,I,M){if(!Pe(I))throw new TypeError;return Q(M)||(M=tt(M)),K(D,I,M)}e("getOwnMetadata",Y);function J(D,I){if(!Pe(D))throw new TypeError;return Q(I)||(I=tt(I)),ie(D,I)}e("getMetadataKeys",J);function Ae(D,I){if(!Pe(D))throw new TypeError;return Q(I)||(I=tt(I)),ve(D,I)}e("getOwnMetadataKeys",Ae);function R(D,I,M){if(!Pe(I))throw new TypeError;if(Q(M)||(M=tt(M)),!Pe(I))throw new TypeError;Q(M)||(M=tt(M));var te=me(I,M,!1);return Q(te)?!1:te.OrdinaryDeleteMetadata(D,I,M)}e("deleteMetadata",R);function L(D,I){for(var M=D.length-1;M>=0;--M){var te=D[M],we=te(I);if(!Q(we)&&!ye(we)){if(!he(we))throw new TypeError;I=we}}return I}function j(D,I,M,te){for(var we=D.length-1;we>=0;--we){var nt=D[we],Re=nt(I,M,te);if(!Q(Re)&&!ye(Re)){if(!Pe(Re))throw new TypeError;te=Re}}return te}function N(D,I,M){var te=k(D,I,M);if(te)return!0;var we=jt(I);return ye(we)?!1:N(D,we,M)}function k(D,I,M){var te=me(I,M,!1);return Q(te)?!1:ee(te.OrdinaryHasOwnMetadata(D,I,M))}function B(D,I,M){var te=k(D,I,M);if(te)return K(D,I,M);var we=jt(I);if(!ye(we))return B(D,we,M)}function K(D,I,M){var te=me(I,M,!1);if(!Q(te))return te.OrdinaryGetOwnMetadata(D,I,M)}function de(D,I,M,te){var we=me(M,te,!0);we.OrdinaryDefineOwnMetadata(D,I,M,te)}function ie(D,I){var M=ve(D,I),te=jt(D);if(te===null)return M;var we=ie(te,I);if(we.length<=0)return M;if(M.length<=0)return we;for(var nt=new $,Re=[],c=0,f=M;c<f.length;c++){var y=f[c],b=nt.has(y);b||(nt.add(y),Re.push(y))}for(var v=0,S=we;v<S.length;v++){var y=S[v],b=nt.has(y);b||(nt.add(y),Re.push(y))}return Re}function ve(D,I){var M=me(D,I,!1);return M?M.OrdinaryOwnMetadataKeys(D,I):[]}function ke(D){if(D===null)return 1;switch(typeof D){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return D===null?1:6;default:return 6}}function Q(D){return D===void 0}function ye(D){return D===null}function Fn(D){return typeof D=="symbol"}function Pe(D){return typeof D=="object"?D!==null:typeof D=="function"}function Ge(D,I){switch(ke(D)){case 0:return D;case 1:return D;case 2:return D;case 3:return D;case 4:return D;case 5:return D}var M="string",te=Ls(D,s);if(te!==void 0){var we=te.call(D,M);if(Pe(we))throw new TypeError;return we}return nn(D)}function nn(D,I){var M,te;{var we=D.toString;if(Fe(we)){var te=we.call(D);if(!Pe(te))return te}var M=D.valueOf;if(Fe(M)){var te=M.call(D);if(!Pe(te))return te}}throw new TypeError}function ee(D){return!!D}function se(D){return""+D}function tt(D){var I=Ge(D);return Fn(I)?I:se(I)}function Rt(D){return Array.isArray?Array.isArray(D):D instanceof Object?D instanceof Array:Object.prototype.toString.call(D)==="[object Array]"}function Fe(D){return typeof D=="function"}function he(D){return typeof D=="function"}function ge(D){switch(ke(D)){case 3:return!0;case 4:return!0;default:return!1}}function go(D,I){return D===I||D!==D&&I!==I}function Ls(D,I){var M=D[I];if(M!=null){if(!Fe(M))throw new TypeError;return M}}function pe(D){var I=Ls(D,a);if(!Fe(I))throw new TypeError;var M=I.call(D);if(!Pe(M))throw new TypeError;return M}function at(D){return D.value}function Fs(D){var I=D.next();return I.done?!1:I}function ae(D){var I=D.return;I&&I.call(D)}function jt(D){var I=Object.getPrototypeOf(D);if(typeof D!="function"||D===h||I!==h)return I;var M=D.prototype,te=M&&Object.getPrototypeOf(M);if(te==null||te===Object.prototype)return I;var we=te.constructor;return typeof we!="function"||we===D?I:we}function Ht(){var D;!Q(z)&&typeof n.Reflect<"u"&&!(z in n.Reflect)&&typeof n.Reflect.defineMetadata=="function"&&(D=rn(n.Reflect));var I,M,te,we=new A,nt={registerProvider:Re,getProvider:f,setProvider:b};return nt;function Re(v){if(!Object.isExtensible(nt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case D===v:break;case Q(I):I=v;break;case I===v:break;case Q(M):M=v;break;case M===v:break;default:te===void 0&&(te=new $),te.add(v);break}}function c(v,S){if(!Q(I)){if(I.isProviderFor(v,S))return I;if(!Q(M)){if(M.isProviderFor(v,S))return I;if(!Q(te))for(var W=pe(te);;){var _e=Fs(W);if(!_e)return;var Ce=at(_e);if(Ce.isProviderFor(v,S))return ae(W),Ce}}}if(!Q(D)&&D.isProviderFor(v,S))return D}function f(v,S){var W=we.get(v),_e;return Q(W)||(_e=W.get(S)),Q(_e)&&(_e=c(v,S),Q(_e)||(Q(W)&&(W=new g,we.set(v,W)),W.set(S,_e))),_e}function y(v){if(Q(v))throw new TypeError;return I===v||M===v||!Q(te)&&te.has(v)}function b(v,S,W){if(!y(W))throw new Error("Metadata provider not registered.");var _e=f(v,S);if(_e!==W){if(!Q(_e))return!1;var Ce=we.get(v);Q(Ce)&&(Ce=new g,we.set(v,Ce)),Ce.set(S,W)}return!0}}function xn(){var D;return!Q(z)&&Pe(n.Reflect)&&Object.isExtensible(n.Reflect)&&(D=n.Reflect[z]),Q(D)&&(D=Ht()),!Q(z)&&Pe(n.Reflect)&&Object.isExtensible(n.Reflect)&&Object.defineProperty(n.Reflect,z,{enumerable:!1,configurable:!1,writable:!1,value:D}),D}function xt(D){var I=new A,M={isProviderFor:function(y,b){var v=I.get(y);return Q(v)?!1:v.has(b)},OrdinaryDefineOwnMetadata:Re,OrdinaryHasOwnMetadata:we,OrdinaryGetOwnMetadata:nt,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:f};return T.registerProvider(M),M;function te(y,b,v){var S=I.get(y),W=!1;if(Q(S)){if(!v)return;S=new g,I.set(y,S),W=!0}var _e=S.get(b);if(Q(_e)){if(!v)return;if(_e=new g,S.set(b,_e),!D.setProvider(y,b,M))throw S.delete(b),W&&I.delete(y),new Error("Wrong provider for target.")}return _e}function we(y,b,v){var S=te(b,v,!1);return Q(S)?!1:ee(S.has(y))}function nt(y,b,v){var S=te(b,v,!1);if(!Q(S))return S.get(y)}function Re(y,b,v,S){var W=te(v,S,!0);W.set(y,b)}function c(y,b){var v=[],S=te(y,b,!1);if(Q(S))return v;for(var W=S.keys(),_e=pe(W),Ce=0;;){var oe=Fs(_e);if(!oe)return v.length=Ce,v;var Ee=at(oe);try{v[Ce]=Ee}catch(At){try{ae(_e)}finally{throw At}}Ce++}}function f(y,b,v){var S=te(b,v,!1);if(Q(S)||!S.delete(y))return!1;if(S.size===0){var W=I.get(b);Q(W)||(W.delete(v),W.size===0&&I.delete(W))}return!0}}function rn(D){var I=D.defineMetadata,M=D.hasOwnMetadata,te=D.getOwnMetadata,we=D.getOwnMetadataKeys,nt=D.deleteMetadata,Re=new A,c={isProviderFor:function(f,y){var b=Re.get(f);return!Q(b)&&b.has(y)?!0:we(f,y).length?(Q(b)&&(b=new $,Re.set(f,b)),b.add(y),!0):!1},OrdinaryDefineOwnMetadata:I,OrdinaryHasOwnMetadata:M,OrdinaryGetOwnMetadata:te,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:nt};return c}function me(D,I,M){var te=T.getProvider(D,I);if(!Q(te))return te;if(M){if(T.setProvider(D,I,O))return O;throw new Error("Illegal state.")}}function ce(){var D={},I=[],M=function(){function c(f,y,b){this._index=0,this._keys=f,this._values=y,this._selector=b}return c.prototype["@@iterator"]=function(){return this},c.prototype[a]=function(){return this},c.prototype.next=function(){var f=this._index;if(f>=0&&f<this._keys.length){var y=this._selector(this._keys[f],this._values[f]);return f+1>=this._keys.length?(this._index=-1,this._keys=I,this._values=I):this._index++,{value:y,done:!1}}return{value:void 0,done:!0}},c.prototype.throw=function(f){throw this._index>=0&&(this._index=-1,this._keys=I,this._values=I),f},c.prototype.return=function(f){return this._index>=0&&(this._index=-1,this._keys=I,this._values=I),{value:f,done:!0}},c}(),te=function(){function c(){this._keys=[],this._values=[],this._cacheKey=D,this._cacheIndex=-2}return Object.defineProperty(c.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),c.prototype.has=function(f){return this._find(f,!1)>=0},c.prototype.get=function(f){var y=this._find(f,!1);return y>=0?this._values[y]:void 0},c.prototype.set=function(f,y){var b=this._find(f,!0);return this._values[b]=y,this},c.prototype.delete=function(f){var y=this._find(f,!1);if(y>=0){for(var b=this._keys.length,v=y+1;v<b;v++)this._keys[v-1]=this._keys[v],this._values[v-1]=this._values[v];return this._keys.length--,this._values.length--,go(f,this._cacheKey)&&(this._cacheKey=D,this._cacheIndex=-2),!0}return!1},c.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=D,this._cacheIndex=-2},c.prototype.keys=function(){return new M(this._keys,this._values,we)},c.prototype.values=function(){return new M(this._keys,this._values,nt)},c.prototype.entries=function(){return new M(this._keys,this._values,Re)},c.prototype["@@iterator"]=function(){return this.entries()},c.prototype[a]=function(){return this.entries()},c.prototype._find=function(f,y){if(!go(this._cacheKey,f)){this._cacheIndex=-1;for(var b=0;b<this._keys.length;b++)if(go(this._keys[b],f)){this._cacheIndex=b;break}}return this._cacheIndex<0&&y&&(this._cacheIndex=this._keys.length,this._keys.push(f),this._values.push(void 0)),this._cacheIndex},c}();return te;function we(c,f){return c}function nt(c,f){return f}function Re(c,f){return[c,f]}}function Kt(){var D=function(){function I(){this._map=new g}return Object.defineProperty(I.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),I.prototype.has=function(M){return this._map.has(M)},I.prototype.add=function(M){return this._map.set(M,M),this},I.prototype.delete=function(M){return this._map.delete(M)},I.prototype.clear=function(){this._map.clear()},I.prototype.keys=function(){return this._map.keys()},I.prototype.values=function(){return this._map.keys()},I.prototype.entries=function(){return this._map.entries()},I.prototype["@@iterator"]=function(){return this.keys()},I.prototype[a]=function(){return this.keys()},I}();return D}function Pt(){var D=16,I=p.create(),M=te();return function(){function f(){this._key=te()}return f.prototype.has=function(y){var b=we(y,!1);return b!==void 0?p.has(b,this._key):!1},f.prototype.get=function(y){var b=we(y,!1);return b!==void 0?p.get(b,this._key):void 0},f.prototype.set=function(y,b){var v=we(y,!0);return v[this._key]=b,this},f.prototype.delete=function(y){var b=we(y,!1);return b!==void 0?delete b[this._key]:!1},f.prototype.clear=function(){this._key=te()},f}();function te(){var f;do f="@@WeakMap@@"+c();while(p.has(I,f));return I[f]=!0,f}function we(f,y){if(!r.call(f,M)){if(!y)return;Object.defineProperty(f,M,{value:p.create()})}return f[M]}function nt(f,y){for(var b=0;b<y;++b)f[b]=Math.random()*255|0;return f}function Re(f){if(typeof Uint8Array=="function"){var y=new Uint8Array(f);return typeof crypto<"u"?crypto.getRandomValues(y):typeof msCrypto<"u"?msCrypto.getRandomValues(y):nt(y,f),y}return nt(new Array(f),f)}function c(){var f=Re(D);f[6]=f[6]&79|64,f[8]=f[8]&191|128;for(var y="",b=0;b<D;++b){var v=f[b];(b===4||b===6||b===8)&&(y+="-"),v<16&&(y+="0"),y+=v.toString(16).toLowerCase()}return y}}function An(D){return D.__=void 0,delete D.__,D}})})(Dh||(Dh={}));/*!
|
|
86
86
|
* MIT License
|
|
87
87
|
*
|
|
88
88
|
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
@@ -189,12 +189,12 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
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 P$(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 zu(await O_(s))}const B$=1e3*60*60*24,L$=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(Cu)}},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:Cu}},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 E(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()+B$).toISOString()});const n=await Zd({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 E(404,{message:"Key not found"});const r=await Zd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...r,type:"jwt_signing"}),t.text("OK")}),F$=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(yp)}},description:"List of users"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{email:n}=t.req.valid("query"),i=(await Tp(t.env.data.users,e,n)).filter(s=>!s.linked_to);return t.json(i)}),U$=zt.extend({clients:o.z.array(Rr)}),M$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([U$,o.z.array(Rr)])}},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"),u=(await t.env.data.clients.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a})).clients;return i?t.json({clients:u,start:0,limit:10,length:u.length}):t.json(u)}).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:Rr}},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 E(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 E(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(Aa.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:Rr}},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 E(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(Aa.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(Rr.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||He()},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()});Nc.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 q$=zt.extend({tenants:o.z.array(Ci)}),V$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants"],method:"get",path:"/",request:{query:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.union([o.z.array(Ci),q$])}},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:wt(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:Ci}},description:"A tenant"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.tenants.get(e);if(!n)throw new E(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(ka.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(ka.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"tenant/json":{schema:Ci}},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})}),H$=zt.extend({logs:o.z.array(Ca)}),K$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:ot,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(Ca),H$])}},description:"List of log rows"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),{"tenant-id":a}=t.req.valid("header"),l=await t.env.data.logs.list(a,{page:e,per_page:n,include_totals:r,sort:wt(i),q:s});return r?t.json(l):t.json(l.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:Ca}},description:"A log entry"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.logs.get(e,n);if(!r)throw new E(404);return t.json(r)}),G$=zt.extend({hooks:o.z.array(Ei)}),W$=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:ot,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(Ei),G$])}},description:"List of hooks"}}}),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.hooks.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:ea}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Ei}},description:"The created hook"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.hooks.create(e,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([ea.options[0].omit({hook_id:!0}).partial(),ea.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ei}},description:"The updated hook"},404:{description:"Hook not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{hook_id:n}=t.req.valid("param"),r=t.req.valid("json");await t.env.data.hooks.update(e,n,r);const i=await t.env.data.hooks.get(e,n);if(!i)throw new E(404,{message:"Hook not found"});return t.json(i)}).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:Ei}},description:"A hook"},404:{description:"Hook not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{hook_id:n}=t.req.valid("param"),r=await t.env.data.hooks.get(e,n);if(!r)throw new E(404,{message:"Hook not found"});return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{hook_id:n}=t.req.valid("param");if(!await t.env.data.hooks.remove(e,n))throw new E(404,{message:"Hook not found"});return t.text("OK")}),X$=zt.extend({connections:o.z.array(cn)}),J$=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:ot,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),X$])}},description:"List of connectionss"}}}),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"),l=await t.env.data.connections.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:cn}},description:"A connection"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.connections.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.connections.remove(e,n))throw new E(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(Sa.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:cn}},description:"The updated connection"}}}),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.connections.update(e,n,r))throw new E(404,{message:"Connection not found"});const s=await t.env.data.connections.get(e,n);if(!s)throw new E(404,{message:"Connection not found"});return t.json(s)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Sa.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cn}},description:"A connection"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.connections.create(e,n);return t.json(r,{status:201})}),Y$=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:na}},description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.promptSettings.get(e);return n?t.json(n):t.json(na.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(na.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.promptSettings.get(e);return Object.assign(r,n),await t.env.data.promptSettings.set(e,r),t.json(r)});let sg=!1;function xf(t){t.use(async(e,n)=>(sg||(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"}}}}),sg=!0),await n()))}var F1=t=>M1(t.replace(/_|-/g,e=>({_:"/","-":"+"})[e]??e)),U1=t=>Z$(t).replace(/\/|\+/g,e=>({"/":"_","+":"-"})[e]??e),Z$=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)},M1=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},q1=(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))(q1||{}),Q$=class extends Error{constructor(t){super(`${t} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Cl=class extends Error{constructor(t){super(`invalid JWT token: ${t}`),this.name="JwtTokenInvalid"}},ex=class extends Error{constructor(t){super(`token (${t}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},tx=class extends Error{constructor(t){super(`token (${t}) expired`),this.name="JwtTokenExpired"}},nx=class extends Error{constructor(t,e){super(`Invalid "iat" claim, must be a valid number lower than "${t}" (iat: "${e}")`),this.name="JwtTokenIssuedAt"}},su=class extends Error{constructor(t,e){super(`expected issuer "${t}", got ${e?`"${e}"`:"none"} `),this.name="JwtTokenIssuer"}},V1=class extends Error{constructor(t){super(`jwt header is invalid: ${JSON.stringify(t)}`),this.name="JwtHeaderInvalid"}},rx=class extends Error{constructor(t){super(`required "kid" in jwt header: ${JSON.stringify(t)}`),this.name="JwtHeaderRequiresKid"}},ix=class extends Error{constructor(t){super(`token(${t}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},Xo=(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))(Xo||{}),Ss=new TextEncoder,ox=new TextDecoder;async function sx(t,e,n){const r=H1(e),i=await cx(t,r);return await crypto.subtle.sign(r,i,n)}async function ax(t,e,n,r){const i=H1(e),s=await lx(t,i);return await crypto.subtle.verify(i,s,n,r)}function Qd(t){return M1(t.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function cx(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(K1(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=[Xo.Sign];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PRIVATE")?await crypto.subtle.importKey("pkcs8",Qd(t),e,!1,n):await crypto.subtle.importKey("raw",Ss.encode(t),e,!1,n)}async function lx(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(K1(t)){if(t.type==="public"||t.type==="secret")return t;t=await ag(t)}if(typeof t=="string"&&t.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Qd(t),e,!0,[Xo.Sign]);t=await ag(r)}const n=[Xo.Verify];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PUBLIC")?await crypto.subtle.importKey("spki",Qd(t),e,!1,n):await crypto.subtle.importKey("raw",Ss.encode(t),e,!1,n)}async function ag(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:l,y:u}=e;return{kty:n,alg:r,e:i,n:s,crv:a,x:l,y:u,key_ops:[Xo.Verify]}}function H1(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 Q$(t)}}function K1(t){return K_()==="node"&&crypto.webcrypto?t instanceof crypto.webcrypto.CryptoKey:t instanceof CryptoKey}var au=t=>U1(Ss.encode(JSON.stringify(t)).buffer).replace(/=/g,""),ux=t=>U1(t).replace(/=/g,""),ep=t=>JSON.parse(ox.decode(F1(t)));function G1(t){if(typeof t=="object"&&t!==null){const e=t;return"alg"in e&&Object.values(q1).includes(e.alg)&&(!("typ"in e)||e.typ==="JWT")}return!1}var dx=async(t,e,n="HS256")=>{const r=au(t);let i;typeof e=="object"&&"alg"in e?(n=e.alg,i=au({alg:n,typ:"JWT",kid:e.kid})):i=au({alg:n,typ:"JWT"});const s=`${i}.${r}`,a=await sx(e,n,Ss.encode(s)),l=ux(a);return`${s}.${l}`},W1=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 Cl(t);const{header:a,payload:l}=X1(t);if(!G1(a))throw new V1(a);const u=Date.now()/1e3|0;if(i.nbf&&l.nbf&&l.nbf>u)throw new ex(t);if(i.exp&&l.exp&&l.exp<=u)throw new tx(t);if(i.iat&&l.iat&&u<l.iat)throw new nx(u,l.iat);if(i.iss){if(!l.iss)throw new su(i.iss,null);if(typeof i.iss=="string"&&l.iss!==i.iss)throw new su(i.iss,l.iss);if(i.iss instanceof RegExp&&!i.iss.test(l.iss))throw new su(i.iss,l.iss)}const d=t.substring(0,t.lastIndexOf("."));if(!await ax(e,i.alg,F1(s[2]),Ss.encode(d)))throw new ix(t);return l},px=async(t,e,n)=>{const r=e.verification||{},i=fx(t);if(!G1(i))throw new V1(i);if(!i.kid)throw new rx(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 l=await a.json();if(!l.keys)throw new Error('invalid JWKS response. "keys" field is missing');if(!Array.isArray(l.keys))throw new Error('invalid JWKS response. "keys" field is not an array');e.keys?e.keys.push(...l.keys):e.keys=l.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 Cl(t);return await W1(t,s,{alg:s.alg||i.alg,...r})},X1=t=>{try{const[e,n]=t.split("."),r=ep(e),i=ep(n);return{header:r,payload:i}}catch{throw new Cl(t)}},fx=t=>{try{const[e]=t.split(".");return ep(e)}catch{throw new Cl(t)}},J1={sign:dx,verify:W1,decode:X1,verifyWithJwks:px},hx={Stringify:1,BeforeStream:2,Stream:3},hn=(t,e)=>{const n=new String(t);return n.isEscaped=!0,n.callbacks=e,n},gx=/[&<>'"]/,Y1=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 l=[n];wr(s,l),n=l[0]}}return hn(n,e)},wr=(t,e)=>{const n=t.search(gx);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=""";break;case 39:r="'";break;case 38:r="&";break;case 60:r="<";break;case 62:r=">";break;default:continue}e[0]+=t.substring(s,i)+r,s=i+1}e[0]+=t.substring(s,i)},Z1=t=>{const e=t.callbacks;if(!(e!=null&&e.length))return t;const n=[t],r={};return e.forEach(i=>i({phase:hx.Stringify,buffer:n,context:r})),n[0]},mx=J1.verify,_x=J1.decode;async function tp(t){const{signingKeys:e}=await t.keys.list({q:"type:jwt_signing"});return await Promise.all(e.map(async r=>{const s=await new Nl(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return $p.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 yx(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 tp(t.data))}return await tp(t.data)}async function wx(t,e){try{const{header:n}=_x(e),i=(await yx(t.env)).find(l=>l.kid===n.kid);if(!i)throw new E(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 mx(e,s,"RS256")}catch(n){throw n instanceof E?n:new E(403,{message:"Invalid JWT signature"})}}function vx(t){return t.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function bx(t,e){return e.startsWith(t)?e:t+e}function Af(t){return async(e,n)=>{var l,u,d;const r=e.req.matchedRoutes.find(p=>p.method.toUpperCase()===e.req.method&&p.path!=="/*");if(!r)return await n();const i=vx(r.path),s="basePath"in r&&typeof r.basePath=="string"?r.basePath:"",a=t.openAPIRegistry.definitions.find(p=>"route"in p&&bx(s,p.route.path)===i&&p.route.method.toUpperCase()===e.req.method.toUpperCase());if(a&&"route"in a){const p=(u=(l=a.route.security)==null?void 0:l[0])==null?void 0:u.Bearer;if(!(p!=null&&p.length))return await n();const h=e.req.header("authorization")||"",[g,$]=h.split(" ");if((g==null?void 0:g.toLowerCase())!=="bearer"||!$)throw new E(401,{message:"Missing bearer token"});try{const A=await wx(e,$);e.set("user_id",A.sub),e.set("user",A);const z=A.permissions||[],T=((d=A.scope)==null?void 0:d.split(" "))||[];if(p.length&&!(p.some(O=>z.includes(O))||p.some(O=>T.includes(O))))throw new E(403,{message:"Unauthorized"})}catch(A){throw A instanceof E?A:new E(403,{message:"Invalid token"})}}return await n()}}const $x=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:ra}},description:"Email provider"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.emailProviders.get(e);if(!n)throw new E(404,{message:"Email provider not found"});return t.json(n)}).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(ra.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");return await t.env.data.emailProviders.create(e,n),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(ra.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");return await t.env.data.emailProviders.update(e,n),t.text("OK")}),xx=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:Tc}},description:"A session"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.sessions.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.sessions.remove(e,n))throw new E(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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.sessions.update(e,n,{revoked_at:new Date().toDateString()}))throw new E(404,{message:"Session not found"});return t.text("Session deletion request accepted.",{status:202})}),Ax=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:Ap}},description:"A session"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.refreshTokens.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.refreshTokens.remove(e,n))throw new E(404,{message:"Session not found"});return t.text("OK")}),Ex=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(pr)}},description:"List of custom domains"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.customDomains.list(e);return t.json(n)}).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:pr}},description:"A connection"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.customDomains.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.customDomains.remove(e,n))throw new E(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(pr.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:pr}},description:"The updated custom domain"}}}),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.customDomains.update(e,n,r))throw new E(404);const s=await t.env.data.customDomains.get(e,n);if(!s)throw new E(404);return t.json(s)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(bp.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:pr}},description:"The created custom domain"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.customDomains.create(e,n);return t.json(r,{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:pr}},description:"The custom domain"}}}),async()=>{throw new E(501,{message:"Not implemented"})});function zl(t,e){const n={};for(const[r,i]of Object.entries(e)){const s={};for(const[a,l]of Object.entries(i))typeof l=="function"?s[a]=async(...u)=>{const d=performance.now();try{const p=await l(...u),g=performance.now()-d,$=t.res.headers.get("Server-Timing")||"",A=$?`${$}, ${r}-${a};dur=${g.toFixed(2)}`:`${r}-${a};dur=${g.toFixed(2)}`;return t.res.headers.set("Server-Timing",A),p}catch(p){const g=performance.now()-d,$=t.res.headers.get("Server-Timing")||"",A=$?`${$}, ${r}-${a}-error;dur=${g.toFixed(2)}`:`${r}-${a}-error;dur=${g.toFixed(2)}`;throw t.res.headers.set("Server-Timing",A),p}}:s[a]=l;n[r]=s}return n}function Il(t){return t.ISSUER}function dt(t){return t.UNIVERSAL_LOGIN_URL||`${t.ISSUER}u/`}function ct(t){return t.OAUTH_API_URL||t.ISSUER}async function Tl(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(Il(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 Sx=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function kx(t){if(t)try{let e=t;try{e=atob(t)}catch{}try{const n=JSON.parse(e);return Sx.parse(n)}catch{}}catch{return}}const Ol=async(t,e)=>{var u,d,p,h;const n=(u=t.req.query("auth0Client"))==null?void 0:u.slice(0,255),i=(d=(()=>{var g;if(t.req.header("x-forwarded-host")&&t.req.header("x-forwarded-for")){const $=t.req.header("x-forwarded-for");return(g=$==null?void 0:$.split(",")[0])==null?void 0:g.trim()}return t.req.header("cf-connecting-ip")||t.req.header("x-real-ip")})())==null?void 0:d.slice(0,45),s=(p=t.req.header("user-agent"))==null?void 0:p.slice(0,512),a=(h=t.req.header("cf-ipcountry"))==null?void 0:h.slice(0,2),l=n?kx(n):void 0;l&&t.set("auth0_client",l),i&&t.set("ip",i),s&&t.set("useragent",s),a&&t.set("countryCode",a),await e()};function Nx(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 Dl(t,e){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:l}=e,u=new Set(s),d=a.length===0,p=new Set(a),h={};for(const[g,$]of Object.entries(t)){const A=d||p.has(g),z={};for(const[T,O]of Object.entries($))if(typeof O=="function"){if(!A){z[T]=O;continue}const x=`${g}:${T}`;if(u.has(x)){z[T]=O;continue}const U=i[x]??r,q=["create","update","remove","delete","set","used"].includes(T);z[T]=async(...F)=>{if(q)return await O.apply($,F);const K=Nx(g,T,F,l),G=await n.get(K);if(G!==null)if(G&&typeof G=="object"&&"isCachedNull"in G){const J=G;return J.isCachedNull?null:J.value}else return G;const Y=await O.apply($,F);if(U>=0)if(Y!==null)await n.set(K,Y,U);else{const J={value:null,isCachedNull:!0};await n.set(K,J,U)}return Y}}else z[T]=O;h[g]=z}return h}class Cx{constructor(e={}){be(this,"cache",new Map);be(this,"accessOrder",new Map);be(this,"accessCounter",0);be(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,l=a?Math.max(0,s):0;a&&(i=new Date(Date.now()+(l>0?l*1e3:-1))),this.config.maxEntries&&this.cache.size>=this.config.maxEntries&&!this.cache.has(e)&&this.evictLeastRecentlyUsed();const u={value:n,expiresAt:i};this.cache.set(e,u),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 ks(t={}){return new Cx(t)}const zx=zt.extend({forms:o.z.array(Ai)}),Ix=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:ot,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(Ai),zx])}},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"),l=await t.env.data.forms.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:Ai}},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 E(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 E(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(Na.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:Ai}},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 E(404,{message:"Form not found"});const s=await t.env.data.forms.get(e,n);if(!s)throw new E(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(Na.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Ai}},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})}),Tx=zt.extend({roles:o.z.array(Br)}),Ox=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:ot,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(Br),Tx])}},description:"List of roles"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),{"tenant-id":a}=t.req.valid("header"),l=await t.env.data.roles.list(a,{page:e,per_page:n,include_totals:r,sort:wt(i),q:s});return r?t.json(l):t.json(l.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:Br}},description:"A role"}}}),async t=>{const{id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),r=await t.env.data.roles.get(n,e);if(!r)throw new E(404);return t.json(r)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ia}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Br}},description:"Role created"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.roles.create(e,n);return t.json(r,{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:Ia.partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Br}},description:"Updated role"}}}),async t=>{const{id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),r=t.req.valid("json");if(!await t.env.data.roles.update(n,e,r))throw new E(404);const s=await t.env.data.roles.get(n,e);return t.json(s)}).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"),{"tenant-id":n}=t.req.valid("header");if(!await t.env.data.roles.remove(n,e))throw new E(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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:v_}},description:"Role permissions"}}}),async t=>{const{id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.roles.get(n,e))throw new E(404,{message:"Role not found"});const u=await t.env.data.rolePermissions.list(n,e,{page:r,per_page:i,include_totals:!1,sort:wt(s),q:a});return t.json(u)}).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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.roles.get(n,e))throw new E(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.assign(n,e,r.map(a=>({role_id:e,resource_server_identifier:a.resource_server_identifier,permission_name:a.permission_name}))))throw new E(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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.roles.get(n,e))throw new E(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.remove(n,e,r))throw new E(500,{message:"Failed to remove permissions from role"});return t.json({message:"Permissions removed successfully"})}),Dx=zt.extend({resource_servers:o.z.array(Pr)}),Rx=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:ot,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(Pr),Dx])}},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"),l=await t.env.data.resourceServers.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:Pr}},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 E(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 E(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(za.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:Pr}},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 E(404,{message:"Resource server not found"});const s=await t.env.data.resourceServers.get(e,n);if(!s)throw new E(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(za.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Pr}},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})}),jx=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."})}),Px=zt.extend({client_grants:o.z.array(jr)}),Bx=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:jx,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(jr),Px])}},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:l,client_id:u,allow_any_organization:d,subject_type:p}=t.req.valid("query"),h=[];u&&h.push(`client_id:"${u}"`),l&&h.push(`audience:"${l}"`),d!==void 0&&h.push(`allow_any_organization:${d}`),p&&h.push(`subject_type:"${p}"`),s&&h.push(`id:>${s}`);const g=h.length>0?h.join(" AND "):void 0,$=a??r,A=await t.env.data.clientGrants.list(e,{page:n,per_page:$,include_totals:i,q:g});return i?t.json(A):t.json(A.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:jr}},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 E(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 E(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(Ea.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:jr}},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 E(404,{message:"Client grant not found"});if(!await t.env.data.clientGrants.update(e,n,r))throw new E(500,{message:"Failed to update client grant"});const a=await t.env.data.clientGrants.get(e,n);if(!a)throw new E(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(Ea.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:jr}},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})}),Lx=zt.extend({organizations:o.z.array(fr)}),Ef=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"})}),Fx=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(Ef).openapi({description:"Array of organization members"})}),Ux=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(Ef).openapi({description:"Array of organization members"})}),Mx=o.z.object({users:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),qx=o.z.object({users:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),Vx=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([Lx,o.z.array(fr)])}},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"),l=await t.env.data.organizations.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:fr}},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 E(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 E(404,{message:"Organization not found"});return t.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Oa.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:fr}},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 E(404,{message:"Organization not found"});const s=await t.env.data.organizations.get(e,n);if(!s)throw new E(404,{message:"Organization not found"});return t.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Oa}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:fr}},description:"The created organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,id:n.id||He()},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:ot,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(Ef),Fx,Ux])}},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 E(404,{message:"Organization not found"});const u=await t.env.data.userOrganizations.list(e,{page:r,per_page:i,include_totals:s,sort:wt(a),q:`organization_id:${n}`}),d=[];for(const p of u.userOrganizations){const h=await t.env.data.users.get(e,p.user_id);h&&d.push({user_id:h.user_id,email:h.email||void 0,roles:[]})}return s?t.json({start:u.start,limit:u.limit,total:u.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:Mx}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Members added successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{users:r}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new E(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(u=>u.organization_id===n)||await t.env.data.userOrganizations.create(e,{user_id:s,organization_id:n});return t.json({message:"Members added successfully"},{status:201})}).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:qx}}}},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"),{users: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(l=>l.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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ta}},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 E(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new E(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 E(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new E(404,{message:"User not found"});for(const l of i){if(!await t.env.data.roles.get(e,l))throw new E(400,{message:`Role ${l} not found`});if(!await t.env.data.userRoles.create(e,r,l,n))throw new E(500,{message:`Failed to assign role ${l} 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 E(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new E(404,{message:"User not found"});for(const l of i)if(!await t.env.data.userRoles.remove(e,r,l,n))throw new E(500,{message:`Failed to remove role ${l} 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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ta}},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 E(404,{message:"Organization not found"});const u=await t.env.data.roles.list(e,{page:r,per_page:i,sort:wt(s),q:a});return t.json(u.roles)});function Hx(t){const e=new o.OpenAPIHono;e.use(Dm({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})),xf(e),e.use(async(r,i)=>{const s=as(r,t.dataAdapter),a=ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),l=Dl(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=zl(r,l),i()}),e.use(Ol).use(Tl).use(Af(e));const n=e.route("/branding",Iv).route("/custom-domains",Ex).route("/email/providers",$x).route("/users",U3).route("/keys",L$).route("/users-by-email",F$).route("/clients",M$).route("/client-grants",Bx).route("/tenants",V$).route("/logs",K$).route("/hooks",W$).route("/connections",J$).route("/prompts",Y$).route("/sessions",xx).route("/refresh_tokens",Ax).route("/forms",Ix).route("/roles",Ox).route("/resource-servers",Rx).route("/organizations",Vx);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 Kx(t,e){Object.keys(e).forEach(n=>{const r=e[n];r!=null&&r.length&&t.searchParams.set(n,r)})}function Yn(t){var e;if(t)return`${t.name}/${t.version}${(e=t.env)!=null&&e.node?` (env: node/${t.env.node})`:""}`}var cg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(cg||(cg={}));var lg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(lg||(lg={}));function Gx(t){return ey(t,Wx,Jo.Include)}function Q1(t){return ey(t,Xx,Jo.None)}function ey(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let l=0;l<3&&i+l<t.byteLength;l++)s=s<<8|t[i+l],a+=8;for(let l=0;l<4;l++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===Jo.Include&&(r+="=")}return r}const Wx="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Xx="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var Jo;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(Jo||(Jo={}));var ug;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(ug||(ug={}));class Jx{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 dg=new Jx;function Sn(t,e){return(t<<32-e|t>>>e)>>>0}function Yx(t){const e=new Zx;return e.update(t),e.digest()}class Zx{constructor(){be(this,"blockSize",64);be(this,"size",32);be(this,"blocks",new Uint8Array(64));be(this,"currentBlockSize",0);be(this,"H",new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]));be(this,"l",0n);be(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),dg.putUint64(this.blocks,this.l,this.blockSize-8),this.process();const e=new Uint8Array(32);for(let n=0;n<8;n++)dg.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 p=(Sn(this.w[d-2],17)^Sn(this.w[d-2],19)^this.w[d-2]>>>10)>>>0,h=(Sn(this.w[d-15],7)^Sn(this.w[d-15],18)^this.w[d-15]>>>3)>>>0;this.w[d]=p+this.w[d-7]+h+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],l=this.H[6],u=this.H[7];for(let d=0;d<64;d++){const p=(Sn(s,6)^Sn(s,11)^Sn(s,25))>>>0,h=(s&a^~s&l)>>>0,g=u+p+h+Qx[d]+this.w[d]|0,$=(Sn(e,2)^Sn(e,13)^Sn(e,22))>>>0,A=(e&n^e&r^n&r)>>>0,z=$+A|0;u=l,l=a,a=s,s=i+g|0,i=r,r=n,n=e,e=g+z|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]=l+this.H[6]|0,this.H[7]=u+this.H[7]|0}}const Qx=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 e5{constructor(e){be(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 t5(t){const e=Yx(new TextEncoder().encode(t));return Q1(e)}function n5(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Q1(t)}function Oo(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 cu(t,e){const n=new TextEncoder().encode(`${t}:${e}`);return Gx(n)}async function _c(t){let e;try{e=await fetch(t)}catch(n){throw new ny(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new la(e.status)}if(typeof n!="object"||n===null)throw new Ti(e.status,n);let r;try{r=ty(n)}catch{throw new Ti(e.status,n)}throw r}if(e.status===200){let n;try{n=await e.json()}catch{throw new la(e.status)}if(typeof n!="object"||n===null)throw new Ti(e.status,n);return new e5(n)}throw e.body!==null&&await e.body.cancel(),new la(e.status)}async function r5(t){let e;try{e=await fetch(t)}catch(n){throw new ny(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Ti(e.status,null)}if(typeof n!="object"||n===null)throw new Ti(e.status,n);let r;try{r=ty(n)}catch{throw new Ti(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 la(e.status)}function ty(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 i5(e,n,r,i)}class ny extends Error{constructor(e){super("Failed to send request",{cause:e})}}class i5 extends Error{constructor(n,r,i,s){super(`OAuth request error: ${n}`);be(this,"code");be(this,"description");be(this,"uri");be(this,"state");this.code=n,this.description=r,this.uri=i,this.state=s}}class la extends Error{constructor(n){super("Unexpected error response");be(this,"status");this.status=n}}class Ti extends Error{constructor(n,r){super("Unexpected error response body");be(this,"status");be(this,"data");this.status=n,this.data=r}}class Sf{constructor(e,n,r){be(this,"clientId");be(this,"clientPassword");be(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===Yo.S256){const l=t5(i);a.searchParams.set("code_challenge_method","S256"),a.searchParams.set("code_challenge",l)}else r===Yo.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=Oo(e,i);if(this.clientPassword!==null){const l=cu(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${l}`)}return await _c(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=Oo(e,i);if(this.clientPassword!==null){const l=cu(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${l}`)}return await _c(s)}async revokeToken(e,n){const r=new URLSearchParams;r.set("token",n),this.clientPassword===null&&r.set("client_id",this.clientId);const i=Oo(e,r);if(this.clientPassword!==null){const s=cu(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${s}`)}await r5(i)}}var Yo;(function(t){t[t.S256=0]="S256",t[t.Plain=1]="Plain"})(Yo||(Yo={}));var pg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(pg||(pg={}));var fg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(fg||(fg={}));function Do(t){return o5(t,s5,yc.None)}function o5(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let l=0;l<3&&i+l<t.byteLength;l++)s=s<<8|t[i+l],a+=8;for(let l=0;l<4;l++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===yc.Include&&(r+="=")}return r}const s5="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var yc;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(yc||(yc={}));var hg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(hg||(hg={}));function a5(t,e,n){const r=Do(new TextEncoder().encode(t)),i=Do(new TextEncoder().encode(e)),s=Do(n);return r+"."+i+"."+s}function c5(t,e){const n=Do(new TextEncoder().encode(t)),r=Do(new TextEncoder().encode(e)),i=n+"."+r;return new TextEncoder().encode(i)}const l5="https://appleid.apple.com/auth/authorize",u5="https://appleid.apple.com/auth/token";class ry{constructor(e,n,r,i,s){be(this,"clientId");be(this,"teamId");be(this,"keyId");be(this,"pkcs8PrivateKey");be(this,"redirectURI");this.clientId=e,this.teamId=n,this.keyId=r,this.pkcs8PrivateKey=i,this.redirectURI=s}createAuthorizationURL(e,n){const r=new URL(l5);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=Oo(u5,n);return await _c(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,c5(r,i)));return a5(r,i,s)}}const d5="https://www.facebook.com/v16.0/dialog/oauth",p5="https://graph.facebook.com/v16.0/oauth/access_token";class iy{constructor(e,n,r){be(this,"clientId");be(this,"clientSecret");be(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(d5);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=Oo(p5,n);return await _c(r)}}const f5="https://accounts.google.com/o/oauth2/v2/auth",gg="https://oauth2.googleapis.com/token",h5="https://oauth2.googleapis.com/revoke";let oy=class{constructor(e,n,r){be(this,"client");this.client=new Sf(e,n,r)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(f5,e,Yo.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(gg,e,n)}async refreshAccessToken(e){return await this.client.refreshAccessToken(gg,e,[])}async revokeToken(e){await this.client.revokeToken(h5,e)}};const Rl=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();Rl.omit({iat:!0,auth_time:!0,nonce:!0,acr:!0,amr:!0,azp:!0,at_hash:!0,c_hash:!0});function sy(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 g5(t,e){var d,p;const{options:n,keyArray:r}=sy(e),i=`${ct(t.env)}callback`,s=new ry(n.client_id,n.team_id,n.kid,r,i),a=He(),l=await s.createAuthorizationURL(a,((d=n.scope)==null?void 0:d.split(" "))||["name","email"]);return(((p=n.scope)==null?void 0:p.split(" "))||["name","email"]).some(h=>["email","name"].includes(h))&&l.searchParams.set("response_mode","form_post"),{redirectUrl:l.href,code:a}}async function m5(t,e,n){const{options:r,keyArray:i}=sy(e),a=await new ry(r.client_id,r.team_id,r.kid,i,`${ct(t.env)}callback`).validateAuthorizationCode(n),l=Sp(a.idToken());if(!l)throw new Error("Invalid ID token");const u=Rl.parse(l.payload);return{sub:u.sub,email:u.email,given_name:u.given_name,family_name:u.family_name,name:u.name,picture:u.picture,locale:u.locale}}const _5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:g5,validateAuthorizationCodeAndGetUser:m5},Symbol.toStringTag,{value:"Module"}));async function y5(t,e){var l;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=`${ct(t.env)}callback`,i=new iy(n.client_id,n.client_secret,r),s=He();return{redirectUrl:i.createAuthorizationURL(s,((l=n.scope)==null?void 0:l.split(" "))||["email"]).href,code:s}}async function w5(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 iy(r.client_id,r.client_secret,`${ct(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 l=await a.json();return t.set("log",`Userinfo: ${JSON.stringify(l)}`),{sub:l.id,email:l.email,name:l.name}}const v5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:y5,validateAuthorizationCodeAndGetUser:w5},Symbol.toStringTag,{value:"Module"}));async function b5(t,e){var u;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Google authentication parameters");const r=`${ct(t.env)}callback`,i=new oy(n.client_id,n.client_secret,r),s=He(),a=n5();return{redirectUrl:i.createAuthorizationURL(s,a,((u=n.scope)==null?void 0:u.split(" "))??["email","profile"]).href,code:s,codeVerifier:a}}async function $5(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 oy(i.client_id,i.client_secret,`${ct(t.env)}callback`).validateAuthorizationCode(n,r),l=Sp(a.idToken());if(!l)throw new Error("Invalid ID token");const u=Rl.parse(l.payload);return{sub:u.sub,email:u.email,given_name:u.given_name,family_name:u.family_name,name:u.name,picture:u.picture,locale:u.locale}}const x5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:b5,validateAuthorizationCodeAndGetUser:$5},Symbol.toStringTag,{value:"Module"}));async function A5(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 Sf(n.client_id,n.client_secret,`${ct(t.env)}callback`),i=He(),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 E5(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 Sf(r.client_id,r.client_secret,`${ct(t.env)}callback`).validateAuthorizationCode("https://api.vipps.no/access-management-1.0/access/oauth2/token",n,null),a=Sp(s.idToken());if(!a)throw new Error("Invalid ID token");const l=Rl.parse(a.payload);if(typeof l.msn!="string")throw new Error("msn not available in id token");const u=await fetch("https://api.vipps.no/vipps-userinfo-api/userinfo",{headers:{Authorization:`Bearer ${s.accessToken()}`,"Merchant-Serial-Number":l.msn}});if(!u.ok)throw new E(400,{message:"Failed to get user from vipps"});return await u.json()}const S5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:A5,validateAuthorizationCodeAndGetUser:E5},Symbol.toStringTag,{value:"Module"}));function ay(t,e){const n=t.env.STRATEGIES||{},i={apple:_5,facebook:v5,"google-oauth2":x5,vipps:S5,...n}[e];if(!i)throw new Error(`Strategy ${e} not found`);return i}async function fo(t,e){const n=await t.data.legacyClients.get(e);if(!n)throw new E(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:[]},l=s.connections.map(u=>{var h;const d=(h=a.connections)==null?void 0:h.find(g=>g.name===u.name);if(!(d!=null&&d.options))return u;const p=cn.parse({...d||{},...u});return p.options=Ni.passthrough().parse({...d.options||{},...u.options}),p}).filter(u=>u);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:l,tenant:{...(i==null?void 0:i.tenant)||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${dt(t)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],t.ISSUER],callbacks:[...r.callbacks||[],`${dt(t)}info`]}}async function mg(t,e,n,r){if(!r.state)throw new E(400,{message:"State not found"});const i=e.connections.find(u=>u.name===n);if(!i){t.set("client_id",e.client_id);const u=Me(t,{type:Le.FAILED_LOGIN,description:"Connection not found"});throw await t.env.data.logs.create(e.tenant.id,u),new E(403,{message:"Connection Not Found"})}let s=await t.env.data.loginSessions.get(e.tenant.id,r.state);if(!s){const u=t.get("ip"),d=t.get("useragent"),p=t.get("auth0_client");s=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:r,csrf_token:He(),ip:u,useragent:d,auth0Client:Yn(p)})}const l=await ay(t,i.strategy).getRedirect(t,i);return await t.env.data.codes.create(e.tenant.id,{login_id:s.id,code_id:l.code,code_type:"oauth2_state",connection_id:i.id,code_verifier:l.codeVerifier,expires_at:new Date(Date.now()+Qv*1e3).toISOString()}),new Response(null,{status:302,headers:{location:l.redirectUrl}})}async function _g(t,{code:e,state:n}){var A;const{env:r}=t,i=await r.data.codes.get(t.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new E(403,{message:"State not found"});const s=await r.data.loginSessions.get(t.var.tenant_id||"",i.login_id);if(!s)throw new E(403,{message:"Session not found"});if(s.authorization_url){const z=new URL(s.authorization_url).hostname,T=t.var.host||"";if(z!==T&&z){const O=new URL(`https://${z}/callback`);return O.searchParams.set("state",n),O.searchParams.set("code",e),new Response("Redirecting",{status:307,headers:{location:O.toString()}})}}const a=await fo(r,s.authParams.client_id);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const l=a.connections.find(z=>z.id===i.connection_id);if(!l){const z=Me(t,{type:Le.FAILED_LOGIN,description:"Connection not found"});throw await r.data.logs.create(a.tenant.id,z),new E(403,{message:"Connection not found"})}if(t.set("connection",l.name),!s.authParams.redirect_uri){const z=Me(t,{type:Le.FAILED_LOGIN,description:"Redirect URI not defined"});throw await r.data.logs.create(a.tenant.id,z),new E(403,{message:"Redirect URI not defined"})}const d=await ay(t,l.strategy).validateAuthorizationCodeAndGetUser(t,l,e,i.code_verifier),{sub:p,...h}=d;t.set("user_id",p);const g=((A=d.email)==null?void 0:A.toLocaleLowerCase())||`${l.name}.${p}@${new URL(t.env.ISSUER).hostname}`;t.set("username",g);const $=await Bc(t,{client:a,username:g,provider:l.strategy,connection:l.name,userId:p,profileData:h,isSocial:!0,ip:t.var.ip});return Dn(t,{client:a,authParams:s.authParams,loginSession:s,user:$,strategy:l.strategy})}async function yg(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 E(400,{message:"State not found"});const l=await t.env.data.loginSessions.get(t.var.tenant_id,a.login_id);if(!l)throw new E(400,{message:"Login not found"});const{redirect_uri:u}=l.authParams;if(!u)throw new E(400,{message:"Redirect uri not found"});const d=Me(t,{type:Le.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});ln(t,t.env.data.logs.create(t.var.tenant_id,d));const p=new URL(u);return Kx(p,{error:n,error_description:r,error_reason:s,error_code:i,state:l.authParams.state}),t.redirect(`${dt(t.env)}login/identifier?state=${l.id}&error=${n}`)}const k5=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 yg(t,e,r,i,s,a);if(!n)throw new E(400,{message:"Code is required"});const l=await _g(t,{code:n,state:e});if(!(l instanceof Response))throw new E(500,{message:"Internal server error"});return l}).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 yg(t,e,r,i,s,a);if(!n)throw new E(400,{message:"Code is required"});const l=await _g(t,{code:n,state:e});if(!(l instanceof Response))throw new E(500,{message:"Internal server error"});return l});function kf(t,e=[],n={}){try{const r=new URL(t);return e.some(i=>{try{return N5(r,new URL(i),n.allowPathWildcards)}catch{return!1}})}catch{return!1}}function N5(t,e,n){if(t.protocol!==e.protocol)return!1;if(n&&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(e.hostname.startsWith("*.")&&e.hostname.split(".").length>2&&["http:","https:"].includes(e.protocol)){const r=e.hostname.split(".").slice(1).join(".");return t.hostname.endsWith(r)}return t.hostname===e.hostname}const C5=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(!kf(s,[...r.allowed_logout_urls||[],...(i==null?void 0:i.allowed_logout_urls)||[]],{allowPathWildcards:!0}))throw new E(400,{message:"Invalid redirect uri"});const a=t.req.header("cookie");if(a){const u=Di(r.tenant.id,a);if(u){const d=await t.env.data.sessions.get(r.tenant.id,u);if(d){const p=await t.env.data.users.get(r.tenant.id,d.user_id);p&&(t.set("user_id",p.user_id),t.set("connection",p.connection));const h=await t.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${u}`,page:0,per_page:100,include_totals:!1});await Promise.all(h.refresh_tokens.map(g=>t.env.data.refreshTokens.remove(r.tenant.id,g.id))),await t.env.data.sessions.update(r.tenant.id,u,{revoked_at:new Date().toISOString()})}}}const l=Me(t,{type:Le.SUCCESS_LOGOUT,description:"User successfully logged out"});return await t.env.data.logs.create(r.tenant.id,l),new Response("Redirecting",{status:302,headers:{"set-cookie":ib(r.tenant.id,t.req.header("host")),location:s}})}),wg=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()}),z5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:wg}},description:"Userinfo"}}}),async t=>{if(!t.var.user)throw new E(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 E(404,{message:"User not found"});return t.json(wg.parse({...e,sub:e.user_id}))}),I5=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:r_}},description:"List of tenants"}}}),async t=>{const e=await tp(t.env.data);return t.json({keys:e},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${Ms}, stale-while-revalidate=${Ms*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:Nu}},description:"List of tenants"}}}),async t=>{const e=Nu.parse({issuer:Il(t.env),authorization_endpoint:`${ct(t.env)}authorize`,token_endpoint:`${ct(t.env)}oauth/token`,device_authorization_endpoint:`${ct(t.env)}oauth/device/code`,userinfo_endpoint:`${ct(t.env)}userinfo`,mfa_challenge_endpoint:`${ct(t.env)}mfa/challenge`,jwks_uri:`${ct(t.env)}.well-known/jwks.json`,registration_endpoint:`${ct(t.env)}oidc/register`,revocation_endpoint:`${ct(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=${Ms}, stale-while-revalidate=${Ms*2}, stale-if-error=86400`}})});function ua(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 cy=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 T5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new E(403,{message:"Invalid client credentials"});if(n.client_secret&&!ua(n.client_secret,e.client_secret))throw new E(403,{message:"Invalid client credentials"});const r={client_id:n.client_id,scope:e.scope,audience:e.audience};return{client:n,authParams:r}}const O5=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()}).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 D5(t,e){var l;const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new E(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)throw new E(403,{message:"Invalid client credentials"});if(new Date(r.expires_at)<new Date)throw new E(403,{message:"Code expired"});if(r.used_at)throw new E(403,{message:"Code already used"});const i=await t.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new E(403,{message:"Invalid login"});if("client_secret"in e){const u=await t.env.data.legacyClients.get("DEFAULT_CLIENT");if(!ua(n.client_secret,e.client_secret)&&!ua(u==null?void 0:u.client_secret,e.client_secret))throw new E(403,{message:"Invalid client credentials"})}else if(r.code_challenge&&r.code_challenge_method&&e.code_verifier){const u=await Jv(e.code_verifier,r.code_challenge_method);if(!ua(u,r.code_challenge))throw new E(403,{message:"Invalid client credentials"})}if(r.redirect_uri&&r.redirect_uri!==e.redirect_uri)throw new E(403,{message:"Invalid redirect uri"});const s=await t.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new E(403,{message:"User not found"});await t.env.data.codes.used(n.tenant.id,e.code);let a;return i.session_id&&((l=i.authParams.scope)!=null&&l.split(" ").includes("offline_access"))&&(a=await X_(t,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience})),{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a==null?void 0:a.id,organization:i.authParams.organization,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:zn.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}const R5=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 j5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new E(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 E(403,{message:JSON.stringify({error:"invalid_grant",error_description:"Refresh token has expired"})})}else throw new E(403,{message:JSON.stringify({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 E(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:zn.WEB_MESSAGE}}}const P5={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 B5(t,e){var n=Array.prototype.slice.call(e);return n.push(P5),t.apply(this,n)}function vg(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 L5={}.constructor;function Oi(t){return t!=null&&t.constructor===L5}function np(t){"@babel/helpers - typeof";return np=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},np(t)}function jl(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function F5(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 Pl(t,e,n){return e&&F5(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var U5="1.2.0",M5="1.7.35",bg=" ext. ",q5=/^\d+$/,$t=function(){function t(e){jl(this,t),ly(e),this.metadata=e,uy.call(this,e)}return Pl(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&&q5.test(n)&&(r=n,n=null),n&&n!=="001"){if(!this.hasCountry(n))throw new Error("Unknown country: ".concat(n));this.numberingPlan=new $g(this.getCountryMetadata(n),this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new $g(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}(),$g=function(){function t(e,n){jl(this,t),this.globalMetadataObject=n,this.metadata=e,uy.call(this,n.metadata)}return Pl(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 V5(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()&&xg(this.types(),n))return new K5(xg(this.types(),n),this)}},{key:"ext",value:function(){return this.v1||this.v2?bg:this.metadata[13]||bg}}]),t}(),V5=function(){function t(e,n){jl(this,t),this._format=e,this.metadata=n}return Pl(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()&&!H5.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}]),t}(),H5=/^\(?\$1\)?$/,K5=function(){function t(e,n){jl(this,t),this.type=e,this.metadata=n}return Pl(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 xg(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 ly(t){if(!t)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!Oi(t)||!Oi(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(Oi(t)?"an object of shape: { "+Object.keys(t).join(", ")+" }":"a "+G5(t)+": "+t,"."))}var G5=function(e){return np(e)};function Nf(t,e){if(e=new $t(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 uy(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?vg(e,U5)===-1?this.v2=!0:vg(e,M5)===-1?this.v3=!0:this.v4=!0:this.v1=!0}function Cf(t,e){return X5(t,void 0,e)}function X5(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 J5(t,e,n){if(e===void 0&&(e={}),n=new $t(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 dy(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 dy(t,e){switch(Cf(t,e)){case"IS_POSSIBLE":return!0;default:return!1}}function Zn(t,e){return t=t||"",new RegExp("^(?:"+e+")$").test(t)}function Y5(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=Z5(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.
|
|
192
|
+
`,r}async function P$(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 zu(await O_(s))}const B$=1e3*60*60*24,L$=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(Cu)}},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:Cu}},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 E(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()+B$).toISOString()});const n=await Zd({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 E(404,{message:"Key not found"});const r=await Zd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...r,type:"jwt_signing"}),t.text("OK")}),F$=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(yp)}},description:"List of users"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{email:n}=t.req.valid("query"),i=(await Tp(t.env.data.users,e,n)).filter(s=>!s.linked_to);return t.json(i)}),U$=zt.extend({clients:o.z.array(Rr)}),M$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([U$,o.z.array(Rr)])}},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"),u=(await t.env.data.clients.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a})).clients;return i?t.json({clients:u,start:0,limit:10,length:u.length}):t.json(u)}).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:Rr}},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 E(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 E(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(Aa.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:Rr}},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 E(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(Aa.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(Rr.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||He()},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()});Nc.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 q$=zt.extend({tenants:o.z.array(Ci)}),V$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants"],method:"get",path:"/",request:{query:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.union([o.z.array(Ci),q$])}},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:wt(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:Ci}},description:"A tenant"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.tenants.get(e);if(!n)throw new E(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(ka.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(ka.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"tenant/json":{schema:Ci}},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})}),H$=zt.extend({logs:o.z.array(Ca)}),K$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:ot,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(Ca),H$])}},description:"List of log rows"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),{"tenant-id":a}=t.req.valid("header"),l=await t.env.data.logs.list(a,{page:e,per_page:n,include_totals:r,sort:wt(i),q:s});return r?t.json(l):t.json(l.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:Ca}},description:"A log entry"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.logs.get(e,n);if(!r)throw new E(404);return t.json(r)}),G$=zt.extend({hooks:o.z.array(Ei)}),W$=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:ot,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(Ei),G$])}},description:"List of hooks"}}}),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.hooks.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:ea}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Ei}},description:"The created hook"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.hooks.create(e,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([ea.options[0].omit({hook_id:!0}).partial(),ea.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ei}},description:"The updated hook"},404:{description:"Hook not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{hook_id:n}=t.req.valid("param"),r=t.req.valid("json");await t.env.data.hooks.update(e,n,r);const i=await t.env.data.hooks.get(e,n);if(!i)throw new E(404,{message:"Hook not found"});return t.json(i)}).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:Ei}},description:"A hook"},404:{description:"Hook not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{hook_id:n}=t.req.valid("param"),r=await t.env.data.hooks.get(e,n);if(!r)throw new E(404,{message:"Hook not found"});return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{hook_id:n}=t.req.valid("param");if(!await t.env.data.hooks.remove(e,n))throw new E(404,{message:"Hook not found"});return t.text("OK")}),X$=zt.extend({connections:o.z.array(cn)}),J$=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:ot,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),X$])}},description:"List of connectionss"}}}),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"),l=await t.env.data.connections.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:cn}},description:"A connection"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.connections.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.connections.remove(e,n))throw new E(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(Sa.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:cn}},description:"The updated connection"}}}),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.connections.update(e,n,r))throw new E(404,{message:"Connection not found"});const s=await t.env.data.connections.get(e,n);if(!s)throw new E(404,{message:"Connection not found"});return t.json(s)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Sa.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cn}},description:"A connection"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.connections.create(e,n);return t.json(r,{status:201})}),Y$=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:na}},description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.promptSettings.get(e);return n?t.json(n):t.json(na.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(na.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.promptSettings.get(e);return Object.assign(r,n),await t.env.data.promptSettings.set(e,r),t.json(r)});let sg=!1;function xf(t){t.use(async(e,n)=>(sg||(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"}}}}),sg=!0),await n()))}var F1=t=>M1(t.replace(/_|-/g,e=>({_:"/","-":"+"})[e]??e)),U1=t=>Z$(t).replace(/\/|\+/g,e=>({"/":"_","+":"-"})[e]??e),Z$=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)},M1=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},q1=(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))(q1||{}),Q$=class extends Error{constructor(t){super(`${t} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Cl=class extends Error{constructor(t){super(`invalid JWT token: ${t}`),this.name="JwtTokenInvalid"}},ex=class extends Error{constructor(t){super(`token (${t}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},tx=class extends Error{constructor(t){super(`token (${t}) expired`),this.name="JwtTokenExpired"}},nx=class extends Error{constructor(t,e){super(`Invalid "iat" claim, must be a valid number lower than "${t}" (iat: "${e}")`),this.name="JwtTokenIssuedAt"}},su=class extends Error{constructor(t,e){super(`expected issuer "${t}", got ${e?`"${e}"`:"none"} `),this.name="JwtTokenIssuer"}},V1=class extends Error{constructor(t){super(`jwt header is invalid: ${JSON.stringify(t)}`),this.name="JwtHeaderInvalid"}},rx=class extends Error{constructor(t){super(`required "kid" in jwt header: ${JSON.stringify(t)}`),this.name="JwtHeaderRequiresKid"}},ix=class extends Error{constructor(t){super(`token(${t}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},Xo=(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))(Xo||{}),Ss=new TextEncoder,ox=new TextDecoder;async function sx(t,e,n){const r=H1(e),i=await cx(t,r);return await crypto.subtle.sign(r,i,n)}async function ax(t,e,n,r){const i=H1(e),s=await lx(t,i);return await crypto.subtle.verify(i,s,n,r)}function Qd(t){return M1(t.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function cx(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(K1(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=[Xo.Sign];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PRIVATE")?await crypto.subtle.importKey("pkcs8",Qd(t),e,!1,n):await crypto.subtle.importKey("raw",Ss.encode(t),e,!1,n)}async function lx(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(K1(t)){if(t.type==="public"||t.type==="secret")return t;t=await ag(t)}if(typeof t=="string"&&t.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Qd(t),e,!0,[Xo.Sign]);t=await ag(r)}const n=[Xo.Verify];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PUBLIC")?await crypto.subtle.importKey("spki",Qd(t),e,!1,n):await crypto.subtle.importKey("raw",Ss.encode(t),e,!1,n)}async function ag(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:l,y:u}=e;return{kty:n,alg:r,e:i,n:s,crv:a,x:l,y:u,key_ops:[Xo.Verify]}}function H1(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 Q$(t)}}function K1(t){return K_()==="node"&&crypto.webcrypto?t instanceof crypto.webcrypto.CryptoKey:t instanceof CryptoKey}var au=t=>U1(Ss.encode(JSON.stringify(t)).buffer).replace(/=/g,""),ux=t=>U1(t).replace(/=/g,""),ep=t=>JSON.parse(ox.decode(F1(t)));function G1(t){if(typeof t=="object"&&t!==null){const e=t;return"alg"in e&&Object.values(q1).includes(e.alg)&&(!("typ"in e)||e.typ==="JWT")}return!1}var dx=async(t,e,n="HS256")=>{const r=au(t);let i;typeof e=="object"&&"alg"in e?(n=e.alg,i=au({alg:n,typ:"JWT",kid:e.kid})):i=au({alg:n,typ:"JWT"});const s=`${i}.${r}`,a=await sx(e,n,Ss.encode(s)),l=ux(a);return`${s}.${l}`},W1=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 Cl(t);const{header:a,payload:l}=X1(t);if(!G1(a))throw new V1(a);const u=Date.now()/1e3|0;if(i.nbf&&l.nbf&&l.nbf>u)throw new ex(t);if(i.exp&&l.exp&&l.exp<=u)throw new tx(t);if(i.iat&&l.iat&&u<l.iat)throw new nx(u,l.iat);if(i.iss){if(!l.iss)throw new su(i.iss,null);if(typeof i.iss=="string"&&l.iss!==i.iss)throw new su(i.iss,l.iss);if(i.iss instanceof RegExp&&!i.iss.test(l.iss))throw new su(i.iss,l.iss)}const d=t.substring(0,t.lastIndexOf("."));if(!await ax(e,i.alg,F1(s[2]),Ss.encode(d)))throw new ix(t);return l},px=async(t,e,n)=>{const r=e.verification||{},i=fx(t);if(!G1(i))throw new V1(i);if(!i.kid)throw new rx(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 l=await a.json();if(!l.keys)throw new Error('invalid JWKS response. "keys" field is missing');if(!Array.isArray(l.keys))throw new Error('invalid JWKS response. "keys" field is not an array');e.keys?e.keys.push(...l.keys):e.keys=l.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 Cl(t);return await W1(t,s,{alg:s.alg||i.alg,...r})},X1=t=>{try{const[e,n]=t.split("."),r=ep(e),i=ep(n);return{header:r,payload:i}}catch{throw new Cl(t)}},fx=t=>{try{const[e]=t.split(".");return ep(e)}catch{throw new Cl(t)}},J1={sign:dx,verify:W1,decode:X1,verifyWithJwks:px},hx={Stringify:1,BeforeStream:2,Stream:3},hn=(t,e)=>{const n=new String(t);return n.isEscaped=!0,n.callbacks=e,n},gx=/[&<>'"]/,Y1=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 l=[n];wr(s,l),n=l[0]}}return hn(n,e)},wr=(t,e)=>{const n=t.search(gx);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=""";break;case 39:r="'";break;case 38:r="&";break;case 60:r="<";break;case 62:r=">";break;default:continue}e[0]+=t.substring(s,i)+r,s=i+1}e[0]+=t.substring(s,i)},Z1=t=>{const e=t.callbacks;if(!(e!=null&&e.length))return t;const n=[t],r={};return e.forEach(i=>i({phase:hx.Stringify,buffer:n,context:r})),n[0]},mx=J1.verify,_x=J1.decode;async function tp(t){const{signingKeys:e}=await t.keys.list({q:"type:jwt_signing"});return await Promise.all(e.map(async r=>{const s=await new Nl(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return $p.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 yx(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 tp(t.data))}return await tp(t.data)}async function wx(t,e){try{const{header:n}=_x(e),i=(await yx(t.env)).find(l=>l.kid===n.kid);if(!i)throw new E(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 mx(e,s,"RS256")}catch(n){throw n instanceof E?n:new E(403,{message:"Invalid JWT signature"})}}function vx(t){return t.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function bx(t,e){return e.startsWith(t)?e:t+e}function Af(t){return async(e,n)=>{var l,u,d;const r=e.req.matchedRoutes.find(p=>p.method.toUpperCase()===e.req.method&&p.path!=="/*");if(!r)return await n();const i=vx(r.path),s="basePath"in r&&typeof r.basePath=="string"?r.basePath:"",a=t.openAPIRegistry.definitions.find(p=>"route"in p&&bx(s,p.route.path)===i&&p.route.method.toUpperCase()===e.req.method.toUpperCase());if(a&&"route"in a){const p=(u=(l=a.route.security)==null?void 0:l[0])==null?void 0:u.Bearer;if(!(p!=null&&p.length))return await n();const h=e.req.header("authorization")||"",[g,$]=h.split(" ");if((g==null?void 0:g.toLowerCase())!=="bearer"||!$)throw new E(401,{message:"Missing bearer token"});try{const A=await wx(e,$);e.set("user_id",A.sub),e.set("user",A);const z=A.permissions||[],T=((d=A.scope)==null?void 0:d.split(" "))||[];if(p.length&&!(p.some(O=>z.includes(O))||p.some(O=>T.includes(O))))throw new E(403,{message:"Unauthorized"})}catch(A){throw A instanceof E?A:new E(403,{message:"Invalid token"})}}return await n()}}const $x=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:ra}},description:"Email provider"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.emailProviders.get(e);if(!n)throw new E(404,{message:"Email provider not found"});return t.json(n)}).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(ra.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");return await t.env.data.emailProviders.create(e,n),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(ra.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json");return await t.env.data.emailProviders.update(e,n),t.text("OK")}),xx=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:Tc}},description:"A session"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.sessions.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.sessions.remove(e,n))throw new E(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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.sessions.update(e,n,{revoked_at:new Date().toDateString()}))throw new E(404,{message:"Session not found"});return t.text("Session deletion request accepted.",{status:202})}),Ax=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:Ap}},description:"A session"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.refreshTokens.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.refreshTokens.remove(e,n))throw new E(404,{message:"Session not found"});return t.text("OK")}),Ex=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(pr)}},description:"List of custom domains"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=await t.env.data.customDomains.list(e);return t.json(n)}).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:pr}},description:"A connection"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.customDomains.get(e,n);if(!r)throw new E(404);return t.json(r)}).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{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.customDomains.remove(e,n))throw new E(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(pr.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:pr}},description:"The updated custom domain"}}}),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.customDomains.update(e,n,r))throw new E(404);const s=await t.env.data.customDomains.get(e,n);if(!s)throw new E(404);return t.json(s)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(bp.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:pr}},description:"The created custom domain"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.customDomains.create(e,n);return t.json(r,{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:pr}},description:"The custom domain"}}}),async()=>{throw new E(501,{message:"Not implemented"})});function zl(t,e){const n={};for(const[r,i]of Object.entries(e)){const s={};for(const[a,l]of Object.entries(i))typeof l=="function"?s[a]=async(...u)=>{const d=performance.now();try{const p=await l(...u),g=performance.now()-d,$=t.res.headers.get("Server-Timing")||"",A=$?`${$}, ${r}-${a};dur=${g.toFixed(2)}`:`${r}-${a};dur=${g.toFixed(2)}`;return t.res.headers.set("Server-Timing",A),p}catch(p){const g=performance.now()-d,$=t.res.headers.get("Server-Timing")||"",A=$?`${$}, ${r}-${a}-error;dur=${g.toFixed(2)}`:`${r}-${a}-error;dur=${g.toFixed(2)}`;throw t.res.headers.set("Server-Timing",A),p}}:s[a]=l;n[r]=s}return n}function Il(t){return t.ISSUER}function dt(t){return t.UNIVERSAL_LOGIN_URL||`${t.ISSUER}u/`}function ct(t){return t.OAUTH_API_URL||t.ISSUER}async function Tl(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(Il(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 Sx=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function kx(t){if(t)try{let e=t;try{e=atob(t)}catch{}try{const n=JSON.parse(e);return Sx.parse(n)}catch{}}catch{return}}const Ol=async(t,e)=>{var u,d,p,h;const n=(u=t.req.query("auth0Client"))==null?void 0:u.slice(0,255),i=(d=(()=>{var g;if(t.req.header("x-forwarded-host")&&t.req.header("x-forwarded-for")){const $=t.req.header("x-forwarded-for");return(g=$==null?void 0:$.split(",")[0])==null?void 0:g.trim()}return t.req.header("cf-connecting-ip")||t.req.header("x-real-ip")})())==null?void 0:d.slice(0,45),s=(p=t.req.header("user-agent"))==null?void 0:p.slice(0,512),a=(h=t.req.header("cf-ipcountry"))==null?void 0:h.slice(0,2),l=n?kx(n):void 0;l&&t.set("auth0_client",l),i&&t.set("ip",i),s&&t.set("useragent",s),a&&t.set("countryCode",a),await e()};function Nx(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 Dl(t,e){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:l}=e,u=new Set(s),d=a.length===0,p=new Set(a),h={};for(const[g,$]of Object.entries(t)){const A=d||p.has(g),z={};for(const[T,O]of Object.entries($))if(typeof O=="function"){if(!A){z[T]=O;continue}const x=`${g}:${T}`;if(u.has(x)){z[T]=O;continue}const U=i[x]??r,q=["create","update","remove","delete","set","used"].includes(T);z[T]=async(...F)=>{if(q)return await O.apply($,F);const H=Nx(g,T,F,l),G=await n.get(H);if(G!==null)if(G&&typeof G=="object"&&"isCachedNull"in G){const J=G;return J.isCachedNull?null:J.value}else return G;const Y=await O.apply($,F);if(U>=0)if(Y!==null)await n.set(H,Y,U);else{const J={value:null,isCachedNull:!0};await n.set(H,J,U)}return Y}}else z[T]=O;h[g]=z}return h}class Cx{constructor(e={}){be(this,"cache",new Map);be(this,"accessOrder",new Map);be(this,"accessCounter",0);be(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,l=a?Math.max(0,s):0;a&&(i=new Date(Date.now()+(l>0?l*1e3:-1))),this.config.maxEntries&&this.cache.size>=this.config.maxEntries&&!this.cache.has(e)&&this.evictLeastRecentlyUsed();const u={value:n,expiresAt:i};this.cache.set(e,u),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 ks(t={}){return new Cx(t)}const zx=zt.extend({forms:o.z.array(Ai)}),Ix=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:ot,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(Ai),zx])}},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"),l=await t.env.data.forms.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:Ai}},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 E(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 E(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(Na.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:Ai}},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 E(404,{message:"Form not found"});const s=await t.env.data.forms.get(e,n);if(!s)throw new E(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(Na.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Ai}},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})}),Tx=zt.extend({roles:o.z.array(Br)}),Ox=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:ot,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(Br),Tx])}},description:"List of roles"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),{"tenant-id":a}=t.req.valid("header"),l=await t.env.data.roles.list(a,{page:e,per_page:n,include_totals:r,sort:wt(i),q:s});return r?t.json(l):t.json(l.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:Br}},description:"A role"}}}),async t=>{const{id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),r=await t.env.data.roles.get(n,e);if(!r)throw new E(404);return t.json(r)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ia}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Br}},description:"Role created"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.roles.create(e,n);return t.json(r,{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:Ia.partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Br}},description:"Updated role"}}}),async t=>{const{id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),r=t.req.valid("json");if(!await t.env.data.roles.update(n,e,r))throw new E(404);const s=await t.env.data.roles.get(n,e);return t.json(s)}).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"),{"tenant-id":n}=t.req.valid("header");if(!await t.env.data.roles.remove(n,e))throw new E(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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:v_}},description:"Role permissions"}}}),async t=>{const{id:e}=t.req.valid("param"),{"tenant-id":n}=t.req.valid("header"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.roles.get(n,e))throw new E(404,{message:"Role not found"});const u=await t.env.data.rolePermissions.list(n,e,{page:r,per_page:i,include_totals:!1,sort:wt(s),q:a});return t.json(u)}).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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.roles.get(n,e))throw new E(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.assign(n,e,r.map(a=>({role_id:e,resource_server_identifier:a.resource_server_identifier,permission_name:a.permission_name}))))throw new E(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"),{"tenant-id":n}=t.req.valid("header"),{permissions:r}=t.req.valid("json");if(!await t.env.data.roles.get(n,e))throw new E(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.remove(n,e,r))throw new E(500,{message:"Failed to remove permissions from role"});return t.json({message:"Permissions removed successfully"})}),Dx=zt.extend({resource_servers:o.z.array(Pr)}),Rx=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:ot,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(Pr),Dx])}},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"),l=await t.env.data.resourceServers.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:Pr}},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 E(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 E(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(za.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:Pr}},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 E(404,{message:"Resource server not found"});const s=await t.env.data.resourceServers.get(e,n);if(!s)throw new E(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(za.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Pr}},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})}),jx=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."})}),Px=zt.extend({client_grants:o.z.array(jr)}),Bx=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:jx,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(jr),Px])}},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:l,client_id:u,allow_any_organization:d,subject_type:p}=t.req.valid("query"),h=[];u&&h.push(`client_id:"${u}"`),l&&h.push(`audience:"${l}"`),d!==void 0&&h.push(`allow_any_organization:${d}`),p&&h.push(`subject_type:"${p}"`),s&&h.push(`id:>${s}`);const g=h.length>0?h.join(" AND "):void 0,$=a??r,A=await t.env.data.clientGrants.list(e,{page:n,per_page:$,include_totals:i,q:g});return i?t.json(A):t.json(A.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:jr}},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 E(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 E(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(Ea.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:jr}},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 E(404,{message:"Client grant not found"});if(!await t.env.data.clientGrants.update(e,n,r))throw new E(500,{message:"Failed to update client grant"});const a=await t.env.data.clientGrants.get(e,n);if(!a)throw new E(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(Ea.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:jr}},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})}),Lx=zt.extend({organizations:o.z.array(fr)}),Ef=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"})}),Fx=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(Ef).openapi({description:"Array of organization members"})}),Ux=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(Ef).openapi({description:"Array of organization members"})}),Mx=o.z.object({users:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),qx=o.z.object({users:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),Vx=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:ot,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([Lx,o.z.array(fr)])}},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"),l=await t.env.data.organizations.list(e,{page:n,per_page:r,include_totals:i,sort:wt(s),q:a});return i?t.json(l):t.json(l.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:fr}},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 E(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 E(404,{message:"Organization not found"});return t.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Oa.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:fr}},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 E(404,{message:"Organization not found"});const s=await t.env.data.organizations.get(e,n);if(!s)throw new E(404,{message:"Organization not found"});return t.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Oa}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:fr}},description:"The created organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,id:n.id||He()},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:ot,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(Ef),Fx,Ux])}},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 E(404,{message:"Organization not found"});const u=await t.env.data.userOrganizations.list(e,{page:r,per_page:i,include_totals:s,sort:wt(a),q:`organization_id:${n}`}),d=[];for(const p of u.userOrganizations){const h=await t.env.data.users.get(e,p.user_id);h&&d.push({user_id:h.user_id,email:h.email||void 0,roles:[]})}return s?t.json({start:u.start,limit:u.limit,total:u.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:Mx}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Members added successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{users:r}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new E(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(u=>u.organization_id===n)||await t.env.data.userOrganizations.create(e,{user_id:s,organization_id:n});return t.json({message:"Members added successfully"},{status:201})}).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:qx}}}},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"),{users: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(l=>l.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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ta}},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 E(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new E(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 E(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new E(404,{message:"User not found"});for(const l of i){if(!await t.env.data.roles.get(e,l))throw new E(400,{message:`Role ${l} not found`});if(!await t.env.data.userRoles.create(e,r,l,n))throw new E(500,{message:`Failed to assign role ${l} 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 E(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new E(404,{message:"User not found"});for(const l of i)if(!await t.env.data.userRoles.remove(e,r,l,n))throw new E(500,{message:`Failed to remove role ${l} 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:ot},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ta}},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 E(404,{message:"Organization not found"});const u=await t.env.data.roles.list(e,{page:r,per_page:i,sort:wt(s),q:a});return t.json(u.roles)});function Hx(t){const e=new o.OpenAPIHono;e.use(Dm({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})),xf(e),e.use(async(r,i)=>{const s=as(r,t.dataAdapter),a=ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),l=Dl(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=zl(r,l),i()}),e.use(Ol).use(Tl).use(Af(e));const n=e.route("/branding",Iv).route("/custom-domains",Ex).route("/email/providers",$x).route("/users",U3).route("/keys",L$).route("/users-by-email",F$).route("/clients",M$).route("/client-grants",Bx).route("/tenants",V$).route("/logs",K$).route("/hooks",W$).route("/connections",J$).route("/prompts",Y$).route("/sessions",xx).route("/refresh_tokens",Ax).route("/forms",Ix).route("/roles",Ox).route("/resource-servers",Rx).route("/organizations",Vx);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 Kx(t,e){Object.keys(e).forEach(n=>{const r=e[n];r!=null&&r.length&&t.searchParams.set(n,r)})}function Yn(t){var e;if(t)return`${t.name}/${t.version}${(e=t.env)!=null&&e.node?` (env: node/${t.env.node})`:""}`}var cg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(cg||(cg={}));var lg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(lg||(lg={}));function Gx(t){return ey(t,Wx,Jo.Include)}function Q1(t){return ey(t,Xx,Jo.None)}function ey(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let l=0;l<3&&i+l<t.byteLength;l++)s=s<<8|t[i+l],a+=8;for(let l=0;l<4;l++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===Jo.Include&&(r+="=")}return r}const Wx="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Xx="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var Jo;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(Jo||(Jo={}));var ug;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(ug||(ug={}));class Jx{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 dg=new Jx;function Sn(t,e){return(t<<32-e|t>>>e)>>>0}function Yx(t){const e=new Zx;return e.update(t),e.digest()}class Zx{constructor(){be(this,"blockSize",64);be(this,"size",32);be(this,"blocks",new Uint8Array(64));be(this,"currentBlockSize",0);be(this,"H",new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]));be(this,"l",0n);be(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),dg.putUint64(this.blocks,this.l,this.blockSize-8),this.process();const e=new Uint8Array(32);for(let n=0;n<8;n++)dg.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 p=(Sn(this.w[d-2],17)^Sn(this.w[d-2],19)^this.w[d-2]>>>10)>>>0,h=(Sn(this.w[d-15],7)^Sn(this.w[d-15],18)^this.w[d-15]>>>3)>>>0;this.w[d]=p+this.w[d-7]+h+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],l=this.H[6],u=this.H[7];for(let d=0;d<64;d++){const p=(Sn(s,6)^Sn(s,11)^Sn(s,25))>>>0,h=(s&a^~s&l)>>>0,g=u+p+h+Qx[d]+this.w[d]|0,$=(Sn(e,2)^Sn(e,13)^Sn(e,22))>>>0,A=(e&n^e&r^n&r)>>>0,z=$+A|0;u=l,l=a,a=s,s=i+g|0,i=r,r=n,n=e,e=g+z|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]=l+this.H[6]|0,this.H[7]=u+this.H[7]|0}}const Qx=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 e5{constructor(e){be(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 t5(t){const e=Yx(new TextEncoder().encode(t));return Q1(e)}function n5(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Q1(t)}function Oo(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 cu(t,e){const n=new TextEncoder().encode(`${t}:${e}`);return Gx(n)}async function _c(t){let e;try{e=await fetch(t)}catch(n){throw new ny(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new la(e.status)}if(typeof n!="object"||n===null)throw new Ti(e.status,n);let r;try{r=ty(n)}catch{throw new Ti(e.status,n)}throw r}if(e.status===200){let n;try{n=await e.json()}catch{throw new la(e.status)}if(typeof n!="object"||n===null)throw new Ti(e.status,n);return new e5(n)}throw e.body!==null&&await e.body.cancel(),new la(e.status)}async function r5(t){let e;try{e=await fetch(t)}catch(n){throw new ny(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Ti(e.status,null)}if(typeof n!="object"||n===null)throw new Ti(e.status,n);let r;try{r=ty(n)}catch{throw new Ti(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 la(e.status)}function ty(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 i5(e,n,r,i)}class ny extends Error{constructor(e){super("Failed to send request",{cause:e})}}class i5 extends Error{constructor(n,r,i,s){super(`OAuth request error: ${n}`);be(this,"code");be(this,"description");be(this,"uri");be(this,"state");this.code=n,this.description=r,this.uri=i,this.state=s}}class la extends Error{constructor(n){super("Unexpected error response");be(this,"status");this.status=n}}class Ti extends Error{constructor(n,r){super("Unexpected error response body");be(this,"status");be(this,"data");this.status=n,this.data=r}}class Sf{constructor(e,n,r){be(this,"clientId");be(this,"clientPassword");be(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===Yo.S256){const l=t5(i);a.searchParams.set("code_challenge_method","S256"),a.searchParams.set("code_challenge",l)}else r===Yo.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=Oo(e,i);if(this.clientPassword!==null){const l=cu(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${l}`)}return await _c(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=Oo(e,i);if(this.clientPassword!==null){const l=cu(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${l}`)}return await _c(s)}async revokeToken(e,n){const r=new URLSearchParams;r.set("token",n),this.clientPassword===null&&r.set("client_id",this.clientId);const i=Oo(e,r);if(this.clientPassword!==null){const s=cu(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${s}`)}await r5(i)}}var Yo;(function(t){t[t.S256=0]="S256",t[t.Plain=1]="Plain"})(Yo||(Yo={}));var pg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(pg||(pg={}));var fg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(fg||(fg={}));function Do(t){return o5(t,s5,yc.None)}function o5(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let l=0;l<3&&i+l<t.byteLength;l++)s=s<<8|t[i+l],a+=8;for(let l=0;l<4;l++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===yc.Include&&(r+="=")}return r}const s5="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var yc;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(yc||(yc={}));var hg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(hg||(hg={}));function a5(t,e,n){const r=Do(new TextEncoder().encode(t)),i=Do(new TextEncoder().encode(e)),s=Do(n);return r+"."+i+"."+s}function c5(t,e){const n=Do(new TextEncoder().encode(t)),r=Do(new TextEncoder().encode(e)),i=n+"."+r;return new TextEncoder().encode(i)}const l5="https://appleid.apple.com/auth/authorize",u5="https://appleid.apple.com/auth/token";class ry{constructor(e,n,r,i,s){be(this,"clientId");be(this,"teamId");be(this,"keyId");be(this,"pkcs8PrivateKey");be(this,"redirectURI");this.clientId=e,this.teamId=n,this.keyId=r,this.pkcs8PrivateKey=i,this.redirectURI=s}createAuthorizationURL(e,n){const r=new URL(l5);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=Oo(u5,n);return await _c(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,c5(r,i)));return a5(r,i,s)}}const d5="https://www.facebook.com/v16.0/dialog/oauth",p5="https://graph.facebook.com/v16.0/oauth/access_token";class iy{constructor(e,n,r){be(this,"clientId");be(this,"clientSecret");be(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(d5);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=Oo(p5,n);return await _c(r)}}const f5="https://accounts.google.com/o/oauth2/v2/auth",gg="https://oauth2.googleapis.com/token",h5="https://oauth2.googleapis.com/revoke";let oy=class{constructor(e,n,r){be(this,"client");this.client=new Sf(e,n,r)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(f5,e,Yo.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(gg,e,n)}async refreshAccessToken(e){return await this.client.refreshAccessToken(gg,e,[])}async revokeToken(e){await this.client.revokeToken(h5,e)}};const Rl=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();Rl.omit({iat:!0,auth_time:!0,nonce:!0,acr:!0,amr:!0,azp:!0,at_hash:!0,c_hash:!0});function sy(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 g5(t,e){var d,p;const{options:n,keyArray:r}=sy(e),i=`${ct(t.env)}callback`,s=new ry(n.client_id,n.team_id,n.kid,r,i),a=He(),l=await s.createAuthorizationURL(a,((d=n.scope)==null?void 0:d.split(" "))||["name","email"]);return(((p=n.scope)==null?void 0:p.split(" "))||["name","email"]).some(h=>["email","name"].includes(h))&&l.searchParams.set("response_mode","form_post"),{redirectUrl:l.href,code:a}}async function m5(t,e,n){const{options:r,keyArray:i}=sy(e),a=await new ry(r.client_id,r.team_id,r.kid,i,`${ct(t.env)}callback`).validateAuthorizationCode(n),l=Sp(a.idToken());if(!l)throw new Error("Invalid ID token");const u=Rl.parse(l.payload);return{sub:u.sub,email:u.email,given_name:u.given_name,family_name:u.family_name,name:u.name,picture:u.picture,locale:u.locale}}const _5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:g5,validateAuthorizationCodeAndGetUser:m5},Symbol.toStringTag,{value:"Module"}));async function y5(t,e){var l;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=`${ct(t.env)}callback`,i=new iy(n.client_id,n.client_secret,r),s=He();return{redirectUrl:i.createAuthorizationURL(s,((l=n.scope)==null?void 0:l.split(" "))||["email"]).href,code:s}}async function w5(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 iy(r.client_id,r.client_secret,`${ct(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 l=await a.json();return t.set("log",`Userinfo: ${JSON.stringify(l)}`),{sub:l.id,email:l.email,name:l.name}}const v5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:y5,validateAuthorizationCodeAndGetUser:w5},Symbol.toStringTag,{value:"Module"}));async function b5(t,e){var u;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Google authentication parameters");const r=`${ct(t.env)}callback`,i=new oy(n.client_id,n.client_secret,r),s=He(),a=n5();return{redirectUrl:i.createAuthorizationURL(s,a,((u=n.scope)==null?void 0:u.split(" "))??["email","profile"]).href,code:s,codeVerifier:a}}async function $5(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 oy(i.client_id,i.client_secret,`${ct(t.env)}callback`).validateAuthorizationCode(n,r),l=Sp(a.idToken());if(!l)throw new Error("Invalid ID token");const u=Rl.parse(l.payload);return{sub:u.sub,email:u.email,given_name:u.given_name,family_name:u.family_name,name:u.name,picture:u.picture,locale:u.locale}}const x5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:b5,validateAuthorizationCodeAndGetUser:$5},Symbol.toStringTag,{value:"Module"}));async function A5(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 Sf(n.client_id,n.client_secret,`${ct(t.env)}callback`),i=He(),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 E5(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 Sf(r.client_id,r.client_secret,`${ct(t.env)}callback`).validateAuthorizationCode("https://api.vipps.no/access-management-1.0/access/oauth2/token",n,null),a=Sp(s.idToken());if(!a)throw new Error("Invalid ID token");const l=Rl.parse(a.payload);if(typeof l.msn!="string")throw new Error("msn not available in id token");const u=await fetch("https://api.vipps.no/vipps-userinfo-api/userinfo",{headers:{Authorization:`Bearer ${s.accessToken()}`,"Merchant-Serial-Number":l.msn}});if(!u.ok)throw new E(400,{message:"Failed to get user from vipps"});return await u.json()}const S5=Object.freeze(Object.defineProperty({__proto__:null,getRedirect:A5,validateAuthorizationCodeAndGetUser:E5},Symbol.toStringTag,{value:"Module"}));function ay(t,e){const n=t.env.STRATEGIES||{},i={apple:_5,facebook:v5,"google-oauth2":x5,vipps:S5,...n}[e];if(!i)throw new Error(`Strategy ${e} not found`);return i}async function fo(t,e){const n=await t.data.legacyClients.get(e);if(!n)throw new E(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:[]},l=s.connections.map(u=>{var h;const d=(h=a.connections)==null?void 0:h.find(g=>g.name===u.name);if(!(d!=null&&d.options))return u;const p=cn.parse({...d||{},...u});return p.options=Ni.passthrough().parse({...d.options||{},...u.options}),p}).filter(u=>u);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:l,tenant:{...(i==null?void 0:i.tenant)||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${dt(t)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],t.ISSUER],callbacks:[...r.callbacks||[],`${dt(t)}info`]}}async function mg(t,e,n,r){if(!r.state)throw new E(400,{message:"State not found"});const i=e.connections.find(u=>u.name===n);if(!i){t.set("client_id",e.client_id);const u=Me(t,{type:Le.FAILED_LOGIN,description:"Connection not found"});throw await t.env.data.logs.create(e.tenant.id,u),new E(403,{message:"Connection Not Found"})}let s=await t.env.data.loginSessions.get(e.tenant.id,r.state);if(!s){const u=t.get("ip"),d=t.get("useragent"),p=t.get("auth0_client");s=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:r,csrf_token:He(),ip:u,useragent:d,auth0Client:Yn(p)})}const l=await ay(t,i.strategy).getRedirect(t,i);return await t.env.data.codes.create(e.tenant.id,{login_id:s.id,code_id:l.code,code_type:"oauth2_state",connection_id:i.id,code_verifier:l.codeVerifier,expires_at:new Date(Date.now()+Qv*1e3).toISOString()}),new Response(null,{status:302,headers:{location:l.redirectUrl}})}async function _g(t,{code:e,state:n}){var A;const{env:r}=t,i=await r.data.codes.get(t.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new E(403,{message:"State not found"});const s=await r.data.loginSessions.get(t.var.tenant_id||"",i.login_id);if(!s)throw new E(403,{message:"Session not found"});if(s.authorization_url){const z=new URL(s.authorization_url).hostname,T=t.var.host||"";if(z!==T&&z){const O=new URL(`https://${z}/callback`);return O.searchParams.set("state",n),O.searchParams.set("code",e),new Response("Redirecting",{status:307,headers:{location:O.toString()}})}}const a=await fo(r,s.authParams.client_id);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const l=a.connections.find(z=>z.id===i.connection_id);if(!l){const z=Me(t,{type:Le.FAILED_LOGIN,description:"Connection not found"});throw await r.data.logs.create(a.tenant.id,z),new E(403,{message:"Connection not found"})}if(t.set("connection",l.name),!s.authParams.redirect_uri){const z=Me(t,{type:Le.FAILED_LOGIN,description:"Redirect URI not defined"});throw await r.data.logs.create(a.tenant.id,z),new E(403,{message:"Redirect URI not defined"})}const d=await ay(t,l.strategy).validateAuthorizationCodeAndGetUser(t,l,e,i.code_verifier),{sub:p,...h}=d;t.set("user_id",p);const g=((A=d.email)==null?void 0:A.toLocaleLowerCase())||`${l.name}.${p}@${new URL(t.env.ISSUER).hostname}`;t.set("username",g);const $=await Bc(t,{client:a,username:g,provider:l.strategy,connection:l.name,userId:p,profileData:h,isSocial:!0,ip:t.var.ip});return Dn(t,{client:a,authParams:s.authParams,loginSession:s,user:$,strategy:l.strategy})}async function yg(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 E(400,{message:"State not found"});const l=await t.env.data.loginSessions.get(t.var.tenant_id,a.login_id);if(!l)throw new E(400,{message:"Login not found"});const{redirect_uri:u}=l.authParams;if(!u)throw new E(400,{message:"Redirect uri not found"});const d=Me(t,{type:Le.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});ln(t,t.env.data.logs.create(t.var.tenant_id,d));const p=new URL(u);return Kx(p,{error:n,error_description:r,error_reason:s,error_code:i,state:l.authParams.state}),t.redirect(`${dt(t.env)}login/identifier?state=${l.id}&error=${n}`)}const k5=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 yg(t,e,r,i,s,a);if(!n)throw new E(400,{message:"Code is required"});const l=await _g(t,{code:n,state:e});if(!(l instanceof Response))throw new E(500,{message:"Internal server error"});return l}).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 yg(t,e,r,i,s,a);if(!n)throw new E(400,{message:"Code is required"});const l=await _g(t,{code:n,state:e});if(!(l instanceof Response))throw new E(500,{message:"Internal server error"});return l});function kf(t,e=[],n={}){try{const r=new URL(t);return e.some(i=>{try{return N5(r,new URL(i),n.allowPathWildcards)}catch{return!1}})}catch{return!1}}function N5(t,e,n){if(t.protocol!==e.protocol)return!1;if(n&&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(e.hostname.startsWith("*.")&&e.hostname.split(".").length>2&&["http:","https:"].includes(e.protocol)){const r=e.hostname.split(".").slice(1).join(".");return t.hostname.endsWith(r)}return t.hostname===e.hostname}const C5=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(!kf(s,[...r.allowed_logout_urls||[],...(i==null?void 0:i.allowed_logout_urls)||[]],{allowPathWildcards:!0}))throw new E(400,{message:"Invalid redirect uri"});const a=t.req.header("cookie");if(a){const u=Di(r.tenant.id,a);if(u){const d=await t.env.data.sessions.get(r.tenant.id,u);if(d){const p=await t.env.data.users.get(r.tenant.id,d.user_id);p&&(t.set("user_id",p.user_id),t.set("connection",p.connection));const h=await t.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${u}`,page:0,per_page:100,include_totals:!1});await Promise.all(h.refresh_tokens.map(g=>t.env.data.refreshTokens.remove(r.tenant.id,g.id))),await t.env.data.sessions.update(r.tenant.id,u,{revoked_at:new Date().toISOString()})}}}const l=Me(t,{type:Le.SUCCESS_LOGOUT,description:"User successfully logged out"});return await t.env.data.logs.create(r.tenant.id,l),new Response("Redirecting",{status:302,headers:{"set-cookie":ib(r.tenant.id,t.req.header("host")),location:s}})}),wg=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()}),z5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:wg}},description:"Userinfo"}}}),async t=>{if(!t.var.user)throw new E(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 E(404,{message:"User not found"});return t.json(wg.parse({...e,sub:e.user_id}))}),I5=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:r_}},description:"List of tenants"}}}),async t=>{const e=await tp(t.env.data);return t.json({keys:e},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${Ms}, stale-while-revalidate=${Ms*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:Nu}},description:"List of tenants"}}}),async t=>{const e=Nu.parse({issuer:Il(t.env),authorization_endpoint:`${ct(t.env)}authorize`,token_endpoint:`${ct(t.env)}oauth/token`,device_authorization_endpoint:`${ct(t.env)}oauth/device/code`,userinfo_endpoint:`${ct(t.env)}userinfo`,mfa_challenge_endpoint:`${ct(t.env)}mfa/challenge`,jwks_uri:`${ct(t.env)}.well-known/jwks.json`,registration_endpoint:`${ct(t.env)}oidc/register`,revocation_endpoint:`${ct(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=${Ms}, stale-while-revalidate=${Ms*2}, stale-if-error=86400`}})});function ua(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 cy=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 T5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new E(403,{message:"Invalid client credentials"});if(n.client_secret&&!ua(n.client_secret,e.client_secret))throw new E(403,{message:"Invalid client credentials"});const r={client_id:n.client_id,scope:e.scope,audience:e.audience};return{client:n,authParams:r}}const O5=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()}).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 D5(t,e){var l;const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new E(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)throw new E(403,{message:"Invalid client credentials"});if(new Date(r.expires_at)<new Date)throw new E(403,{message:"Code expired"});if(r.used_at)throw new E(403,{message:"Code already used"});const i=await t.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new E(403,{message:"Invalid login"});if("client_secret"in e){const u=await t.env.data.legacyClients.get("DEFAULT_CLIENT");if(!ua(n.client_secret,e.client_secret)&&!ua(u==null?void 0:u.client_secret,e.client_secret))throw new E(403,{message:"Invalid client credentials"})}else if(r.code_challenge&&r.code_challenge_method&&e.code_verifier){const u=await Jv(e.code_verifier,r.code_challenge_method);if(!ua(u,r.code_challenge))throw new E(403,{message:"Invalid client credentials"})}if(r.redirect_uri&&r.redirect_uri!==e.redirect_uri)throw new E(403,{message:"Invalid redirect uri"});const s=await t.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new E(403,{message:"User not found"});await t.env.data.codes.used(n.tenant.id,e.code);let a;return i.session_id&&((l=i.authParams.scope)!=null&&l.split(" ").includes("offline_access"))&&(a=await X_(t,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience})),{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a==null?void 0:a.id,organization:i.authParams.organization,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:zn.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}const R5=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 j5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new E(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 E(403,{message:JSON.stringify({error:"invalid_grant",error_description:"Refresh token has expired"})})}else throw new E(403,{message:JSON.stringify({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 E(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:zn.WEB_MESSAGE}}}const P5={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 B5(t,e){var n=Array.prototype.slice.call(e);return n.push(P5),t.apply(this,n)}function vg(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 L5={}.constructor;function Oi(t){return t!=null&&t.constructor===L5}function np(t){"@babel/helpers - typeof";return np=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},np(t)}function jl(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function F5(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 Pl(t,e,n){return e&&F5(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var U5="1.2.0",M5="1.7.35",bg=" ext. ",q5=/^\d+$/,$t=function(){function t(e){jl(this,t),ly(e),this.metadata=e,uy.call(this,e)}return Pl(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&&q5.test(n)&&(r=n,n=null),n&&n!=="001"){if(!this.hasCountry(n))throw new Error("Unknown country: ".concat(n));this.numberingPlan=new $g(this.getCountryMetadata(n),this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new $g(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}(),$g=function(){function t(e,n){jl(this,t),this.globalMetadataObject=n,this.metadata=e,uy.call(this,n.metadata)}return Pl(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 V5(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()&&xg(this.types(),n))return new K5(xg(this.types(),n),this)}},{key:"ext",value:function(){return this.v1||this.v2?bg:this.metadata[13]||bg}}]),t}(),V5=function(){function t(e,n){jl(this,t),this._format=e,this.metadata=n}return Pl(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()&&!H5.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}]),t}(),H5=/^\(?\$1\)?$/,K5=function(){function t(e,n){jl(this,t),this.type=e,this.metadata=n}return Pl(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 xg(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 ly(t){if(!t)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!Oi(t)||!Oi(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(Oi(t)?"an object of shape: { "+Object.keys(t).join(", ")+" }":"a "+G5(t)+": "+t,"."))}var G5=function(e){return np(e)};function Nf(t,e){if(e=new $t(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 uy(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?vg(e,U5)===-1?this.v2=!0:vg(e,M5)===-1?this.v3=!0:this.v4=!0:this.v1=!0}function Cf(t,e){return X5(t,void 0,e)}function X5(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 J5(t,e,n){if(e===void 0&&(e={}),n=new $t(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 dy(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 dy(t,e){switch(Cf(t,e)){case"IS_POSSIBLE":return!0;default:return!1}}function Zn(t,e){return t=t||"",new RegExp("^(?:"+e+")$").test(t)}function Y5(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=Z5(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.
|
|
193
193
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Z5(t,e){if(t){if(typeof t=="string")return Ag(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 Ag(t,e)}}function Ag(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 Q5=["MOBILE","PREMIUM_RATE","TOLL_FREE","SHARED_COST","VOIP","PERSONAL_NUMBER","PAGER","UAN","VOICEMAIL"];function zf(t,e,n){if(e=e||{},!(!t.country&&!t.countryCallingCode)){n=new $t(n),n.selectNumberingPlan(t.country,t.countryCallingCode);var r=e.v2?t.nationalNumber:t.phone;if(Zn(r,n.nationalNumberPattern())){if(lu(r,"FIXED_LINE",n))return n.type("MOBILE")&&n.type("MOBILE").pattern()===""||!n.type("MOBILE")||lu(r,"MOBILE",n)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE";for(var i=Y5(Q5),s;!(s=i()).done;){var a=s.value;if(lu(r,a,n))return a}}}}function lu(t,e,n){return e=n.type(e),!e||!e.pattern()||e.possibleLengths()&&e.possibleLengths().indexOf(t.length)<0?!1:Zn(t,e.pattern())}function eA(t,e,n){if(e=e||{},n=new $t(n),n.selectNumberingPlan(t.country,t.countryCallingCode),n.hasTypes())return zf(t,e,n.metadata)!==void 0;var r=e.v2?t.nationalNumber:t.phone;return Zn(r,n.nationalNumberPattern())}function tA(t,e,n){var r=new $t(n),i=r.getCountryCodesForCallingCode(t);return i?i.filter(function(s){return nA(e,s,n)}):[]}function nA(t,e,n){var r=new $t(n);return r.selectNumberingPlan(e),r.numberingPlan.possibleLengths().indexOf(t.length)>=0}var If=2,rA=17,iA=3,_n="0-90-9٠-٩۰-۹",oA="-‐-―−ー-",sA="//",aA="..",cA=" ",lA="()()[]\\[\\]",uA="~⁓∼~",wc="".concat(oA).concat(sA).concat(aA).concat(cA).concat(lA).concat(uA),Tf="++",dA=new RegExp("(["+_n+"])");function pA(t,e,n,r){if(e){var i=new $t(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(dA);if(!(a&&a[1]!=null&&a[1].length>0&&a[1]==="0"))return t}}}function fA(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,l=a>0&&r[a];if(e.nationalPrefixTransformRule()&&l)i=t.replace(n,e.nationalPrefixTransformRule()),a>1&&(s=r[1]);else{var u=r[0];i=t.slice(u.length),l&&(s=r[1])}var d;if(l){var p=t.indexOf(r[1]),h=t.slice(0,p);h===e.numberingPlan.nationalPrefix()&&(d=e.numberingPlan.nationalPrefix())}else d=r[0];return{nationalNumber:i,nationalPrefix:d,carrierCode:s}}}return{nationalNumber:t}}function rp(t,e){var n=fA(t,e),r=n.carrierCode,i=n.nationalNumber;if(i!==t){if(!hA(t,i,e))return{nationalNumber:t};if(e.possibleLengths()&&!gA(i,e))return{nationalNumber:t}}return{nationalNumber:i,carrierCode:r}}function hA(t,e,n){return!(Zn(t,n.nationalNumberPattern())&&!Zn(e,n.nationalNumberPattern()))}function gA(t,e){switch(Cf(t,e)){case"TOO_SHORT":case"INVALID_LENGTH":return!1;default:return!0}}function mA(t,e,n,r){var i=e?Nf(e,r):n;if(t.indexOf(i)===0){r=new $t(r),r.selectNumberingPlan(e,n);var s=t.slice(i.length),a=rp(s,r),l=a.nationalNumber,u=rp(t,r),d=u.nationalNumber;if(!Zn(d,r.nationalNumberPattern())&&Zn(l,r.nationalNumberPattern())||Cf(d,r)==="TOO_LONG")return{countryCallingCode:i,number:s}}return{number:t}}function py(t,e,n,r){if(!t)return{};var i;if(t[0]!=="+"){var s=pA(t,e,n,r);if(s&&s!==t)i=!0,t="+"+s;else{if(e||n){var a=mA(t,e,n,r),l=a.countryCallingCode,u=a.number;if(l)return{countryCallingCodeSource:"FROM_NUMBER_WITHOUT_PLUS_SIGN",countryCallingCode:l,number:u}}return{number:t}}}if(t[1]==="0")return{};r=new $t(r);for(var d=2;d-1<=iA&&d<=t.length;){var p=t.slice(1,d);if(r.hasCallingCode(p))return r.selectNumberingPlan(p),{countryCallingCodeSource:i?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:p,number:t.slice(d)};d++}return{}}function _A(t){return t.replace(new RegExp("[".concat(wc,"]+"),"g")," ").trim()}var yA=/(\$\d)/;function wA(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(yA,e.nationalPrefixFormattingRule()):e.format());return r?_A(s):s}var vA=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;function bA(t,e,n){var r=new $t(n);if(r.selectNumberingPlan(t,e),r.defaultIDDPrefix())return r.defaultIDDPrefix();if(vA.test(r.IDDPrefix()))return r.IDDPrefix()}var $A=";ext=",mi=function(e){return"([".concat(_n,"]{1,").concat(e,"})")};function fy(t){var e="20",n="15",r="9",i="6",s="[ \\t,]*",a="[:\\..]?[ \\t,-]*",l="#?",u="(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)",d="(?:[xx##~~]|int|int)",p="[- ]+",h="[ \\t]*",g="(?:,{2}|;)",$=$A+mi(e),A=s+u+a+mi(e)+l,z=s+d+a+mi(r)+l,T=p+mi(i)+"#",O=h+g+a+mi(n)+l,x=h+"(?:,)+"+a+mi(r)+l;return $+"|"+A+"|"+z+"|"+T+"|"+O+"|"+x}var xA="["+_n+"]{"+If+"}",AA="["+Tf+"]{0,1}(?:["+wc+"]*["+_n+"]){3,}["+wc+_n+"]*",EA=new RegExp("^["+Tf+"]{0,1}(?:["+wc+"]*["+_n+"]){1,2}$","i"),SA=AA+"(?:"+fy()+")?",kA=new RegExp("^"+xA+"$|^"+SA+"$","i");function NA(t){return t.length>=If&&kA.test(t)}function CA(t){return EA.test(t)}function zA(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 IA(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=TA(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
194
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function TA(t,e){if(t){if(typeof t=="string")return Eg(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 Eg(t,e)}}function Eg(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 Sg(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 kg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Sg(Object(n),!0).forEach(function(r){OA(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Sg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function OA(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var Ng={formatExtension:function(e,n,r){return"".concat(e).concat(r.ext()).concat(n)}};function DA(t,e,n,r){if(n?n=kg(kg({},Ng),n):n=Ng,r=new $t(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=vc(s,t.carrierCode,"NATIONAL",r,n),uu(a,t.ext,r,n.formatExtension)):"";case"INTERNATIONAL":return s?(a=vc(s,null,"INTERNATIONAL",r,n),a="+".concat(i," ").concat(a),uu(a,t.ext,r,n.formatExtension)):"+".concat(i);case"E.164":return"+".concat(i).concat(s);case"RFC3966":return zA({number:"+".concat(i).concat(s),ext:t.ext});case"IDD":if(!n.fromCountry)return;var l=jA(s,t.carrierCode,i,n.fromCountry,r);return uu(l,t.ext,r,n.formatExtension);default:throw new Error('Unknown "format" argument passed to "formatNumber()": "'.concat(e,'"'))}}function vc(t,e,n,r,i){var s=RA(r.formats(),t);return s?wA(t,s,{useInternationalFormat:n==="INTERNATIONAL",withNationalPrefix:!(s.nationalPrefixIsOptionalWhenFormattingInNationalFormat()&&i&&i.nationalPrefix===!1),carrierCode:e,metadata:r}):t}function RA(t,e){for(var n=IA(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(Zn(e,i.pattern()))return i}}function uu(t,e,n,r){return e?r(t,e,n):t}function jA(t,e,n,r,i){var s=Nf(r,i.metadata);if(s===n){var a=vc(t,e,"NATIONAL",i);return n==="1"?n+" "+a:a}var l=bA(r,void 0,i.metadata);if(l)return"".concat(l," ").concat(n," ").concat(vc(t,null,"INTERNATIONAL",i))}function Cg(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 zg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Cg(Object(n),!0).forEach(function(r){PA(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Cg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function PA(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function BA(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function LA(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 FA(t,e,n){return e&&LA(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var UA=function(){function t(e,n,r){if(BA(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(Oi(n)&&Oi(n.countries)){r=n;var i=e;if(!VA.test(i))throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits');var s=py(i,void 0,void 0,r),a=s.countryCallingCode,l=s.number;if(n=l,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");ly(r);var u=qA(e,r),d=u.country,p=u.countryCallingCode;this.country=d,this.countryCallingCode=p,this.nationalNumber=n,this.number="+"+this.countryCallingCode+this.nationalNumber,this.getMetadata=function(){return r}}return FA(t,[{key:"setExt",value:function(n){this.ext=n}},{key:"getPossibleCountries",value:function(){return this.country?[this.country]:tA(this.countryCallingCode,this.nationalNumber,this.getMetadata())}},{key:"isPossible",value:function(){return J5(this,{v2:!0},this.getMetadata())}},{key:"isValid",value:function(){return eA(this,{v2:!0},this.getMetadata())}},{key:"isNonGeographic",value:function(){var n=new $t(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 zf(this,{v2:!0},this.getMetadata())}},{key:"format",value:function(n,r){return DA(this,n,r?zg(zg({},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}(),MA=function(e){return/^[A-Z]{2}$/.test(e)};function qA(t,e){var n,r,i=new $t(e);return MA(t)?(n=t,i.selectNumberingPlan(n),r=i.countryCallingCode()):r=t,{country:n,countryCallingCode:r}}var VA=/^\+\d+$/;function ip(t){"@babel/helpers - typeof";return ip=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},ip(t)}function HA(t,e,n){return Object.defineProperty(t,"prototype",{writable:!1}),t}function KA(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function GA(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&&Zo(t,e)}function WA(t){var e=gy();return function(){var r=Qo(t),i;if(e){var s=Qo(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return XA(this,i)}}function XA(t,e){if(e&&(ip(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return hy(t)}function hy(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function op(t){var e=typeof Map=="function"?new Map:void 0;return op=function(r){if(r===null||!JA(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 da(r,arguments,Qo(this).constructor)}return i.prototype=Object.create(r.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),Zo(i,r)},op(t)}function da(t,e,n){return gy()?da=Reflect.construct:da=function(i,s,a){var l=[null];l.push.apply(l,s);var u=Function.bind.apply(i,l),d=new u;return a&&Zo(d,a.prototype),d},da.apply(null,arguments)}function gy(){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 JA(t){return Function.toString.call(t).indexOf("[native code]")!==-1}function Zo(t,e){return Zo=Object.setPrototypeOf||function(r,i){return r.__proto__=i,r},Zo(t,e)}function Qo(t){return Qo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Qo(t)}var Un=function(t){GA(n,t);var e=WA(n);function n(r){var i;return KA(this,n),i=e.call(this,r),Object.setPrototypeOf(hy(i),n.prototype),i.name=i.constructor.name,i}return HA(n)}(op(Error)),Ig=new RegExp("(?:"+fy()+")$","i");function YA(t){var e=t.search(Ig);if(e<0)return{};for(var n=t.slice(0,e),r=t.match(Ig),i=1;i<r.length;){if(r[i])return{number:n,ext:r[i]};i++}}var ZA={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 QA(t){return ZA[t]}function eE(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=tE(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
195
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function tE(t,e){if(t){if(typeof t=="string")return Tg(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 Tg(t,e)}}function Tg(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 Og(t){for(var e="",n=eE(t.split("")),r;!(r=n()).done;){var i=r.value;e+=nE(i,e)||""}return e}function nE(t,e,n){return t==="+"?e?void 0:"+":QA(t)}function rE(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=iE(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 iE(t,e){if(t){if(typeof t=="string")return Dg(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 Dg(t,e)}}function Dg(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 oE(t,e){var n=e.countries,r=e.metadata;r=new $t(r);for(var i=rE(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(zf({phone:t,country:a},void 0,r.metadata))return a}}function sE(t,e){var n=e.nationalNumber,r=e.defaultCountry,i=e.metadata,s=i.getCountryCodesForCallingCode(t);if(s)return s.length===1?s[0]:oE(n,{countries:s,defaultCountry:r,metadata:i.metadata})}var my="+",aE="[\\-\\.\\(\\)]?",Rg="(["+_n+"]|"+aE+")",cE="^\\"+my+Rg+"*["+_n+"]"+Rg+"*$",lE=new RegExp(cE,"g"),sp=_n,uE="["+sp+"]+((\\-)*["+sp+"])*",dE="a-zA-Z",pE="["+dE+"]+((\\-)*["+sp+"])*",fE="^("+uE+"\\.)*"+pE+"\\.?$",hE=new RegExp(fE,"g"),jg="tel:",ap=";phone-context=",gE=";isub=";function mE(t){var e=t.indexOf(ap);if(e<0)return null;var n=e+ap.length;if(n>=t.length)return"";var r=t.indexOf(";",n);return r>=0?t.substring(n,r):t.substring(n)}function _E(t){return t===null?!0:t.length===0?!1:lE.test(t)||hE.test(t)}function yE(t,e){var n=e.extractFormattedPhoneNumber,r=mE(t);if(!_E(r))throw new Un("NOT_A_NUMBER");var i;if(r===null)i=n(t)||"";else{i="",r.charAt(0)===my&&(i+=r);var s=t.indexOf(jg),a;s>=0?a=s+jg.length:a=0;var l=t.indexOf(ap);i+=t.substring(a,l)}var u=i.indexOf(gE);if(u>0&&(i=i.substring(0,u)),i!=="")return i}var wE=250,vE=new RegExp("["+Tf+_n+"]"),bE=new RegExp("[^"+_n+"#]+$");function $E(t,e,n){if(e=e||{},n=new $t(n),e.defaultCountry&&!n.hasCountry(e.defaultCountry))throw e.v2?new Un("INVALID_COUNTRY"):new Error("Unknown country: ".concat(e.defaultCountry));var r=AE(t,e.v2,e.extract),i=r.number,s=r.ext,a=r.error;if(!i){if(e.v2)throw a==="TOO_SHORT"?new Un("TOO_SHORT"):new Un("NOT_A_NUMBER");return{}}var l=SE(i,e.defaultCountry,e.defaultCallingCode,n),u=l.country,d=l.nationalNumber,p=l.countryCallingCode,h=l.countryCallingCodeSource,g=l.carrierCode;if(!n.hasSelectedNumberingPlan()){if(e.v2)throw new Un("INVALID_COUNTRY");return{}}if(!d||d.length<If){if(e.v2)throw new Un("TOO_SHORT");return{}}if(d.length>rA){if(e.v2)throw new Un("TOO_LONG");return{}}if(e.v2){var $=new UA(p,d,n.metadata);return u&&($.country=u),g&&($.carrierCode=g),s&&($.ext=s),$.__countryCallingCodeSource=h,$}var A=(e.extended?n.hasSelectedNumberingPlan():u)?Zn(d,n.nationalNumberPattern()):!1;return e.extended?{country:u,countryCallingCode:p,carrierCode:g,valid:A,possible:A?!0:!!(e.extended===!0&&n.possibleLengths()&&dy(d,n)),phone:d,ext:s}:A?EE(u,d,s):{}}function xE(t,e,n){if(t){if(t.length>wE){if(n)throw new Un("TOO_LONG");return}if(e===!1)return t;var r=t.search(vE);if(!(r<0))return t.slice(r).replace(bE,"")}}function AE(t,e,n){var r=yE(t,{extractFormattedPhoneNumber:function(a){return xE(a,n,e)}});if(!r)return{};if(!NA(r))return CA(r)?{error:"TOO_SHORT"}:{};var i=YA(r);return i.ext?i:{number:r}}function EE(t,e,n){var r={country:t,phone:e};return n&&(r.ext=n),r}function SE(t,e,n,r){var i=py(Og(t),e,n,r.metadata),s=i.countryCallingCodeSource,a=i.countryCallingCode,l=i.number,u;if(a)r.selectNumberingPlan(a);else if(l&&(e||n))r.selectNumberingPlan(e,n),e&&(u=e),a=n||Nf(e,r.metadata);else return{};if(!l)return{countryCallingCodeSource:s,countryCallingCode:a};var d=rp(Og(l),r),p=d.nationalNumber,h=d.carrierCode,g=sE(a,{nationalNumber:p,defaultCountry:e,metadata:r});return g&&(u=g,g==="001"||r.country(u)),{country:u,countryCallingCode:a,countryCallingCodeSource:s,nationalNumber:p,carrierCode:h}}function Pg(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 Bg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Pg(Object(n),!0).forEach(function(r){kE(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Pg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function kE(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function NE(t,e,n){return $E(t,Bg(Bg({},e),{},{v2:!0}),n)}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 CE(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){zE(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 zE(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function IE(t,e){return RE(t)||DE(t,e)||OE(t,e)||TE()}function TE(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
197
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function OE(t,e){if(t){if(typeof t=="string")return Fg(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 Fg(t,e)}}function Fg(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 DE(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,l;try{for(n=n.call(t);!(i=(a=n.next()).done)&&(r.push(a.value),!(e&&r.length===e));i=!0);}catch(u){s=!0,l=u}finally{try{!i&&n.return!=null&&n.return()}finally{if(s)throw l}}return r}}function RE(t){if(Array.isArray(t))return t}function jE(t){var e=Array.prototype.slice.call(t),n=IE(e,4),r=n[0],i=n[1],s=n[2],a=n[3],l,u,d;if(typeof r=="string")l=r;else throw new TypeError("A text for parsing must be a string.");if(!i||typeof i=="string")a?(u=s,d=a):(u=void 0,d=s),i&&(u=CE({defaultCountry:i},u));else if(Oi(i))s?(u=i,d=s):d=i;else throw new Error("Invalid second argument: ".concat(i));return{text:l,options:u,metadata:d}}function Ug(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 Mg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ug(Object(n),!0).forEach(function(r){PE(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ug(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function PE(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function BE(t,e,n){e&&e.defaultCountry&&!W5(e.defaultCountry,n)&&(e=Mg(Mg({},e),{},{defaultCountry:void 0}));try{return NE(t,e,n)}catch(r){if(!(r instanceof Un))throw r}}function LE(){var t=jE(arguments),e=t.text,n=t.options,r=t.metadata;return BE(e,n,r)}function FE(){return B5(LE,arguments)}function Bl(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=FE(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 Of(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 UE(t){const n=Of(t).split(".");return n.length!==4?!1:n.every(r=>/^\d+$/.test(r)&&Number(r)>=0&&Number(r)<=255)}function ME(t){const e=Of(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 qE(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 qg(t){if(!t)return null;const e=Of(qE(t));return UE(e)?{family:4,normalized:e}:ME(e)?{family:6,normalized:e.toLowerCase()}:null}function Vg(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 VE(t,e,n=!0){const r=qg(t),i=qg(e);if(!r||!i||r.family!==i.family)return!1;if(r.family===4)return r.normalized===i.normalized;const s=Vg(r.normalized),a=Vg(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 oi extends Error{constructor(n,r=302){super(`Redirect to ${n}`);be(this,"location");be(this,"status");this.name=oi.name,this.location=n,this.status=r}}const HE=o.z.object({client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),otp:o.z.string(),authParams:jo.optional(),enforceIpCheck:o.z.boolean().optional().default(!1)});async function _y(t,{client_id:e,username:n,otp:r,authParams:i,enforceIpCheck:s=!1}){const a=t.get("ip"),l=t.get("countryCode"),{connectionType:u,normalized:d}=Bl(n,l);if(!d)throw new E(400,{message:"Invalid username format"});const p=await t.env.data.legacyClients.get(e);if(!p)throw new E(403,{message:"Client not found"});const{env:h}=t,g=await h.data.codes.get(p.tenant.id,r,"otp");if(!g)throw new E(400,{message:xe("code_invalid")});if(g.expires_at<new Date().toISOString())throw new E(400,{message:xe("code_expired")});if(g.used_at)throw new E(400,{message:xe("code_used")});const $=await h.data.loginSessions.get(p.tenant.id,g.login_id);if(!$||$.authParams.username!==n)throw new E(400,{message:"Code not found or expired"});if(s&&$.ip&&a&&!VE($.ip,a))throw new oi(`${dt(t.env)}invalid-session?state=${$.id}`);const A=await Bc(t,{client:p,username:d,provider:u,connection:u,isSocial:!1,ip:t.var.ip});return await h.data.codes.used(p.tenant.id,r),{user:A,client:p,loginSession:$,session_id:$.session_id,authParams:{...$.authParams,...i||{}}}}async function Df(t,e){const n=await _y(t,e);return Dn(t,{authParams:n.authParams,client:n.client,user:n.user,loginSession:n.loginSession,strategy:"email"})}const Hg=o.z.object({client_id:o.z.string().optional(),client_secret:o.z.string().optional()}),KE=o.z.union([cy.extend(Hg.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)}),o.z.object({grant_type:o.z.literal("authorization_code"),code:o.z.string(),redirect_uri:o.z.string().optional(),...Hg.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 GE(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 WE=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:KE}}}},responses:{200:{content:{"application/json":{schema:xp}},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 l,u,d;const e=t.req.valid("form"),n=GE(t.req.header("Authorization")),r={...e,...n};if(!r.client_id)throw new E(400,{message:"client_id is required"});t.set("client_id",r.client_id);let i;switch(e.grant_type){case an.AuthorizationCode:i=await D5(t,O5.parse(r));break;case an.ClientCredential:i=await T5(t,cy.parse(r));break;case an.RefreshToken:i=await j5(t,R5.parse(r));break;case an.OTP:i=await _y(t,HE.parse(r));break;default:return t.json({error:"unsupported_grant_type",error_description:"Grant type not implemented"},400)}const s=new Headers;if(i.session_id){const p=Da(i.client.tenant.id,i.session_id,t.var.host||"");s.set("Set-Cookie",p)}if(i.authParams.audience)try{let p;if(e.grant_type===an.ClientCredential)p=await ja(t,{grantType:an.ClientCredential,tenantId:i.client.tenant.id,clientId:i.client.client_id,audience:i.authParams.audience,requestedScopes:((l=i.authParams.scope)==null?void 0:l.split(" "))||[],organizationId:i.organization});else{if(!((u=i.user)!=null&&u.user_id))throw new Ra(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});p=await ja(t,{grantType:e.grant_type,tenantId:i.client.tenant.id,userId:i.user.user_id,clientId:i.client.client_id,audience:i.authParams.audience,requestedScopes:((d=i.authParams.scope)==null?void 0:d.split(" "))||[],organizationId:i.organization})}i.authParams.scope=p.scopes.join(" ")}catch(p){if(p instanceof E)throw p;console.error("Error calculating scopes and permissions:",p)}const a=await Pc(t,{...i,grantType:e.grant_type});return t.json(a,{headers:s})});var Rf={exports:{}};const jf=[{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}],yy=(t,e=jf,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(l=>new RegExp(`${l.regex}`).test(r)).map(l=>l.message),s.length=r.length;let a=e.filter(l=>s.contains.length>=l.minDiversity).filter(l=>s.length>=l.minLength).sort((l,u)=>u.id-l.id).map(l=>({id:l.id,value:l.value}));return Object.assign(s,a[0]),s};Rf.exports={passwordStrength:yy,defaultOptions:jf};var XE=Rf.exports.passwordStrength=yy;Rf.exports.defaultOptions=jf;function Pf(t){return XE(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 Ns(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 E(500,{message:"Email provider not found"});const r=(i=t.env.emailProviders)==null?void 0:i[n.name];if(!r)throw new E(500,{message:"Email provider not found"});await r({emailProvider:n,...e,from:n.default_from_address||`login@${t.env.ISSUER}`})}async function wy(t,e){var a,l;if(!t.var.client_id)throw new E(500,{message:"Client not found"});const n=await fo(t.env,t.var.client_id),r=n.connections.find(u=>u.strategy==="sms");if(!r)throw new E(500,{message:"SMS provider not found"});const i=((a=r.options)==null?void 0:a.provider)||"twilio",s=(l=t.env.smsProviders)==null?void 0:l[i];if(!s)throw new E(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.name,tenantId:n.tenant.id}})}async function vy(t,e,n,r){const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new E(500,{message:"Tenant not found"});const s=`${dt(t.env)}reset-password?state=${r}&code=${n}`,a={vendorName:i.name,lng:i.language||"en"};await Ns(t,{to:e,subject:xe("reset_password_title",a),html:`Click here to reset your password: ${dt(t.env)}reset-password?state=${r}&code=${n}`,template:"auth-password-reset",data:{vendorName:i.name,logo:i.logo||"",passwordResetUrl:s,supportUrl:i.support_url||"https://support.sesamy.com",buttonColor:i.primary_color||"#7d68f4",passwordResetTitle:xe("password_reset_title",a),resetPasswordEmailClickToReset:xe("reset_password_email_click_to_reset",a),resetPasswordEmailReset:xe("reset_password_email_reset",a),supportInfo:xe("support_info",a),contactUs:xe("contact_us",a),copyright:xe("copyright",a),tenantName:i.name,tenantId:i.id}})}async function Bf(t,{to:e,code:n}){const r=await t.env.data.tenants.get(t.var.tenant_id);if(!r)throw new E(500,{message:"Tenant not found"});const{connectionType:i}=Bl(e),s=new URL(dt(t.env)),a={vendorName:r.name,vendorId:r.id,loginDomain:s.hostname,code:n,lng:r.language||"en"};i==="email"?await Ns(t,{to:e,subject:xe("code_email_subject",a),html:`Click here to validate your email: ${dt(t.env)}validate-email`,template:"auth-code",data:{code:n,vendorName:r.name,logo:r.logo||"",supportUrl:r.support_url||"",buttonColor:r.primary_color||"",welcomeToYourAccount:xe("welcome_to_your_account",a),linkEmailClickToLogin:xe("link_email_click_to_login",a),linkEmailLogin:xe("link_email_login",a),linkEmailOrEnterCode:xe("link_email_or_enter_code",a),codeValid30Mins:xe("code_valid_30_minutes",a),supportInfo:xe("support_info",a),contactUs:xe("contact_us",a),copyright:xe("copyright",a)}}):i==="sms"&&await wy(t,{to:e,text:xe("sms_code_text",a),code:n,from:r.name});const l=Me(t,{type:Le.CODE_LINK_SENT,description:e});ln(t,t.env.data.logs.create(r.id,l))}async function Lf(t,{to:e,code:n,authParams:r}){const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new E(500,{message:"Tenant not found"});if(!r.redirect_uri)throw new E(400,{message:"redirect_uri is required"});const{connectionType:s}=Bl(e),a=new URL(ct(t.env));a.pathname="passwordless/verify_redirect",a.searchParams.set("verification_code",n),a.searchParams.set("connection",s),a.searchParams.set("client_id",r.client_id),a.searchParams.set("redirect_uri",r.redirect_uri),a.searchParams.set("email",e),r.response_type&&a.searchParams.set("response_type",r.response_type),r.scope&&a.searchParams.set("scope",r.scope),r.state&&a.searchParams.set("state",r.state),r.nonce&&a.searchParams.set("nonce",r.nonce),r.code_challenge&&a.searchParams.set("code_challenge",r.code_challenge),r.code_challenge_method&&a.searchParams.set("code_challenge_method",r.code_challenge_method),r.audience&&a.searchParams.set("audience",r.audience);const l={vendorName:i.name,code:n,lng:i.language||"en"};if(s==="email")await Ns(t,{to:e,subject:xe("code_email_subject",l),html:`Click here to validate your email: ${dt(t.env)}validate-email`,template:"auth-link",data:{code:n,vendorName:i.name,logo:i.logo||"",supportUrl:i.support_url||"",magicLink:a.toString(),buttonColor:i.primary_color||"",welcomeToYourAccount:xe("welcome_to_your_account",l),linkEmailClickToLogin:xe("link_email_click_to_login",l),linkEmailLogin:xe("link_email_login",l),linkEmailOrEnterCode:xe("link_email_or_enter_code",l),codeValid30Mins:xe("code_valid_30_minutes",l),supportInfo:xe("support_info",l),contactUs:xe("contact_us",l),copyright:xe("copyright",l)}});else if(s==="sms")await wy(t,{to:e,text:`${xe("link_sms_login",l)}: ${a.toString()}`,code:n,from:i.name});else throw new E(400,{message:"Only email and SMS connections are supported for magic links"});const u=Me(t,{type:Le.CODE_LINK_SENT,description:e});ln(t,t.env.data.logs.create(i.id,u))}async function Ff(t,e){const n=await t.env.data.tenants.get(t.var.tenant_id);if(!n)throw new E(500,{message:"Tenant not found"});if(!e.email)throw new E(400,{message:"User has no email"});const r={vendorName:n.name,lng:n.language||"en"};await Ns(t,{to:e.email,subject:xe("welcome_to_your_account",r),html:`Click here to validate your email: ${dt(t.env)}validate-email`,template:"auth-verify-email",data:{vendorName:n.name,logo:n.logo||"",emailValidationUrl:`${dt(t.env)}validate-email`,supportUrl:n.support_url||"https://support.sesamy.com",buttonColor:n.primary_color||"#7d68f4",welcomeToYourAccount:xe("welcome_to_your_account",r),verifyEmailVerify:xe("verify_email_verify",r),supportInfo:xe("support_info",r),contactUs:xe("contact_us",r),copyright:xe("copyright",r)}})}async function JE(t,e,n,r){const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new E(500,{message:"Tenant not found"});const s={vendorName:i.name,lng:i.language||"en"},a=`${dt(t.env)}signup?state=${r}&code=${n}`;await Ns(t,{to:e,subject:xe("register_password_account",s),html:`Click here to register: ${a}`,template:"auth-pre-signup-verification",data:{vendorName:i.name,logo:i.logo||"",signupUrl:a,setPassword:xe("set_password",s),registerPasswordAccount:xe("register_password_account",s),clickToSignUpDescription:xe("click_to_sign_up_description",s),supportUrl:i.support_url||"https://support.sesamy.com",buttonColor:i.primary_color||"#7d68f4",welcomeToYourAccount:xe("welcome_to_your_account",s),verifyEmailVerify:xe("verify_email_verify",s),supportInfo:xe("support_info",s),contactUs:xe("contact_us",s),copyright:xe("copyright",s)}})}const YE=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 E(400,{message:"Client not found"});if(t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id),!Pf(n))throw new E(400,{message:"Password does not meet the requirements"});if(await Po({userAdapter:t.env.data.users,tenant_id:i.tenant.id,username:e,provider:"auth2"}))throw new E(400,{message:"Invalid sign up"});const a=await t.env.data.users.create(i.tenant.id,{user_id:`auth2|${Dc()}`,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 l=await ss.hash(n,10);await t.env.data.passwords.create(i.tenant.id,{user_id:a.user_id,password:l,algorithm:"bcrypt"}),await Ff(t,a);const u=Me(t,{type:Le.SUCCESS_SIGNUP,description:"Successful signup"});return await t.env.data.logs.create(i.tenant.id,u),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 E(400,{message:"Client not found"});if(t.set("client_id",r.client_id),t.set("tenant_id",r.tenant.id),!await eo({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()+Hr*1e3).toISOString(),authParams:s,csrf_token:He(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Yn(t.get("auth0_client"))});return await vy(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 Ar(){const t="1234567890";let e="";for(let n=0;n<6;n+=1)e+=t[Math.floor(Math.random()*10)];return e.toString()}const ZE=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:jo.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:jo.omit({client_id:!0})})])}}}},responses:{200:{description:"Status"}}}),async t=>{const e=t.req.valid("json"),{env:n}=t,{client_id:r,send:i,authParams:s,connection:a}=e,l=await t.env.data.legacyClients.get(r);if(!l)throw new E(400,{message:"Client not found"});t.set("client_id",l.client_id),t.set("tenant_id",l.tenant.id);const u=a==="email"?e.email:e.phone_number,d=t.get("ip"),p=t.get("useragent"),h=t.get("auth0_client"),g=Yn(h),$=await n.data.loginSessions.create(l.tenant.id,{authParams:{...s,client_id:r,username:u},expires_at:new Date(Date.now()+ia).toISOString(),csrf_token:He(),ip:d,useragent:p,auth0Client:g}),A=await n.data.codes.create(l.tenant.id,{code_id:Ar(),code_type:"otp",login_id:$.id,expires_at:new Date(Date.now()+ia).toISOString(),redirect_uri:s.redirect_uri});return i==="link"?await Lf(t,{to:u,code:A.code_id,authParams:{...s,client_id:r}}):await Bf(t,{to:u,code:A.code_id}),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(Yt),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:l,audience:u,response_type:d,nonce:p}=t.req.valid("query"),h=await fo(e,n);t.set("client_id",h.client_id),t.set("tenant_id",h.tenant.id),t.set("connection","email");const g={client_id:n,redirect_uri:s,state:a,nonce:p,scope:l,audience:u,response_type:d};let $="Something went wrong. Please try again later.";try{const U=await Df(t,{client_id:n,username:r,otp:i,authParams:g,enforceIpCheck:!0});if(U instanceof Response)return U;if(U&&typeof U=="object"&&"access_token"in U)return t.json(U)}catch(U){const q=U;"message"in q&&typeof q.message=="string"&&($=q.message)}const A=t.get("ip"),z=t.get("useragent"),T=t.get("auth0_client"),O=Yn(T),x=await e.data.loginSessions.create(h.tenant.id,{authParams:{...g,username:r},expires_at:new Date(Date.now()+ia).toISOString(),csrf_token:He(),ip:A,useragent:z,auth0Client:O});return t.redirect(`${dt(t.env)}invalid-session?state=${x.id}&error=${encodeURIComponent($)}`,302)});class $i extends E{constructor(n,r){super(n,r);be(this,"_code");this._code=r==null?void 0:r.code}get code(){return this._code}}async function by(t,e,n,r){const{data:i}=t.env,{username:s}=n;if(t.set("username",s),!s)throw new E(400,{message:"Username is required"});const a=await eo({userAdapter:t.env.data.users,tenant_id:e.tenant.id,username:s,provider:"auth2"});if(!a){const $=Me(t,{type:Le.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid user"});throw ln(t,i.logs.create(e.tenant.id,$)),new $i(403,{message:"User not found",code:"USER_NOT_FOUND"})}const l=a.linked_to?await i.users.get(e.tenant.id,a.linked_to):a;if(!l)throw new $i(403,{message:"User not found",code:"USER_NOT_FOUND"});t.set("connection",a.connection),t.set("user_id",l.user_id);const u=await i.passwords.get(e.tenant.id,a.user_id);if(!(u&&await ss.compare(n.password,u.password))){const $=Me(t,{type:Le.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid password"});throw ln(t,i.logs.create(e.tenant.id,$)),new $i(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:${l.user_id}`})).logs.filter($=>$.type===Le.FAILED_LOGIN_INCORRECT_PASSWORD&&new Date($.date)>new Date(Date.now()-1e3*60*5)).length>=3){const $=Me(t,{type:Le.FAILED_LOGIN,description:"Too many failed login attempts"});throw ln(t,i.logs.create(e.tenant.id,$)),new $i(403,{message:"Too many failed login attempts",code:"TOO_MANY_FAILED_LOGINS"})}if(!a.email_verified&&e.email_validation==="enforced"){await Ff(t,a);const $=Me(t,{type:Le.FAILED_LOGIN,description:"Email not verified"});throw await i.logs.create(e.tenant.id,$),new $i(403,{message:"Email not verified",code:"EMAIL_NOT_VERIFIED"})}const g=Me(t,{type:Le.SUCCESS_LOGIN,description:"Successful login",strategy_type:"Username-Password-Authentication",strategy:"Username-Password-Authentication"});return ln(t,i.logs.create(e.tenant.id,g)),{client:e,authParams:n,user:l,loginSession:r}}async function $y(t,e,n,r,i){const s=await by(t,e,n,r);return Dn(t,{...s,ticketAuth:i,strategy:"Username-Password-Authentication"})}async function QE(t,e,n,r){await Bc(t,{client:e,username:n,provider:"auth2",connection:"Username-Password-Authentication",isSocial:!1,ip:t.var.ip});let i=Ar(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");for(;s;)i=Ar(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");const a=t.get("ip"),l=t.get("useragent"),u=t.get("auth0_client"),d=Yn(u),p=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+nb).toISOString(),authParams:{client_id:e.client_id,username:n},csrf_token:He(),ip:a,useragent:l,auth0Client:d}),h=await t.env.data.codes.create(e.tenant.id,{code_id:i,code_type:"password_reset",login_id:p.id,expires_at:new Date(Date.now()+tb).toISOString()});await vy(t,n,h.code_id,r)}const e8=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 E(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"),l=t.get("useragent"),u=t.get("auth0_client");let d;if("otp"in e)d=await Df(t,{client_id:n,username:s,otp:e.otp});else if("password"in e){const p=await t.env.data.loginSessions.create(i.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:{client_id:n,username:s},csrf_token:He(),ip:a,useragent:l,auth0Client:Yn(u)});d=await $y(t,i,{username:s,password:e.password,client_id:n},p,!0)}else throw new E(400,{message:"Code or password required"});if(!(d instanceof Response))throw new E(500,{message:"Unexpected response from loginWithPassword"});return d});function xy(t,e){var r,i,s;if(!t||e.length===0)return!1;const n=((r=du(t))==null?void 0:r.host)??null;if(!n)return!1;for(const a of e){let l;if(a.startsWith("http://")||a.startsWith("https://")?l=((i=du(a))==null?void 0:i.host)??null:l=((s=du("https://"+a))==null?void 0:s.host)??null,n===l)return!0}return!1}function du(t){try{return new URL(t)}catch{return null}}async function t8({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:l,auth0_client:u,useragent:d}=t.var,p=Yn(u),h=await t.env.data.loginSessions.create(n.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:r,csrf_token:He(),authorization_url:a.toString(),ip:l,useragent:d,auth0Client:p});if(e&&s){const g=await t.env.data.users.get(n.tenant.id,e.user_id);if((g==null?void 0:g.email)===s)return await t.env.data.loginSessions.update(n.tenant.id,h.id,{session_id:e.id}),Dn(t,{client:n,loginSession:{...h,session_id:e.id},authParams:r,user:g,sessionId:e.id})}if(i==="email"&&s){const g=Ar();return await t.env.data.codes.create(n.tenant.id,{code_id:g,code_type:"otp",login_id:h.id,expires_at:new Date(Date.now()+Hr*1e3).toISOString(),redirect_uri:r.redirect_uri}),await Lf(t,{code:g,to:s,authParams:r}),t.redirect(`/u/enter-code?state=${h.id}`)}return e?t.redirect(`/u/check-account?state=${h.id}`):t.redirect(`/u/login/identifier?state=${h.id}`)}function n8(t){if(t==="Username-Password-Authentication")return"auth2";if(t==="email")return"email";throw new E(403,{message:"Invalid realm"})}async function r8(t,e,n,r,i){var g;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 E(403,{message:"Ticket not found"});const l=await s.data.loginSessions.get(e,a.login_id);if(!l||!l.authParams.username)throw new E(403,{message:"Session not found"});const u=await s.data.legacyClients.get(l.authParams.client_id);if(!u)throw new E(403,{message:"Client not found"});t.set("client_id",l.authParams.client_id),await s.data.codes.used(e,n);const d=n8(i);let p=await Bc(t,{username:l.authParams.username,provider:d,client:u,connection:d==="auth2"?"Username-Password-Authentication":"email",isSocial:!1,ip:t.var.ip});t.set("username",p.email||p.phone_number),t.set("user_id",p.user_id);const h=await J_(t,{user:p,client:u,loginSession:l});return Dn(t,{authParams:{scope:(g=l.authParams)==null?void 0:g.scope,...r},loginSession:l,sessionId:h.id,user:p,client:u})}async function i8({ctx:t,client:e,session:n,redirect_uri:r,state:i,nonce:s,code_challenge_method:a,code_challenge:l,audience:u,scope:d,response_type:p}){const{env:h}=t,g=new URL(r),$=`${g.protocol}//${g.host}`;async function A(K="Login required"){const G=Me(t,{type:Le.FAILED_SILENT_AUTH,description:K});return await t.env.data.logs.create(e.tenant.id,G),t.html(Du($,JSON.stringify({error:"login_required",error_description:K,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 A();t.set("user_id",n.user_id);const T=await h.data.users.get(e.tenant.id,n.user_id);if(!T)return console.error("User not found",n.user_id),A("User not found");t.set("username",T.email),t.set("connection",T.connection);const O={client:e,authParams:{client_id:e.client_id,audience:u,code_challenge_method:a,code_challenge:l,scope:d,state:i,nonce:s,response_type:p,redirect_uri:r},user:T,session_id:n.id},x=p===Yt.CODE?await W_(t,{user:T,client:e,authParams:O.authParams,login_id:n.login_session_id}):await Pc(t,O);await h.data.sessions.update(e.tenant.id,n.id,{used_at:new Date().toISOString(),last_interaction_at:new Date().toISOString(),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()+Rc*1e3).toISOString():void 0});const U=Me(t,{type:Le.SUCCESS_SILENT_AUTH,description:"Successful silent authentication"});await t.env.data.logs.create(e.tenant.id,U);const q=new Headers;q.set("Server-Timing","cf-nel=0; no-cloudflare-insights=1");const F=Da(e.tenant.id,n.id,t.req.header("host"));return q.set("set-cookie",F),t.html(Du($,JSON.stringify({...x,state:i})),{headers:q})}const o8=["email","sms","Username-Password-Authentication"],s8=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(zn).optional(),response_type:o.z.nativeEnum(Yt).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(zc).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:xp}}},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:l,nonce:u,connection:d,response_type:p,response_mode:h,code_challenge:g,code_challenge_method:$,prompt:A,login_ticket:z,realm:T,auth0Client:O,login_hint:x,ui_locales:U,organization:q}=t.req.valid("query");t.set("log","authorize");const F=await fo(e,n);t.set("client_id",F.client_id),t.set("tenant_id",F.tenant.id);const K={redirect_uri:i.split("#")[0],scope:s,state:a,client_id:n,vendor_id:r,audience:l,nonce:u,prompt:A,response_type:p,response_mode:h,code_challenge:g,code_challenge_method:$,username:x,ui_locales:U,organization:q},G=t.req.header("origin");if(G&&!xy(G,F.web_origins||[]))throw new E(403,{message:`Origin ${G} not allowed`});if(K.redirect_uri){const L=F.callbacks||[];if(t.var.host&&(L.push(`${Il(t.env)}/*`),L.push(`${dt(t.env)}/*`)),!kf(K.redirect_uri,L,{allowPathWildcards:!0}))throw new E(400,{message:`Invalid redirect URI - ${K.redirect_uri}`})}const Y=Di(F.tenant.id,t.req.header("cookie")),J=Y?await e.data.sessions.get(F.tenant.id,Y):void 0,Ae=J&&!J.revoked_at?J:void 0;if(A=="none"){if(!p)throw new E(400,{message:"Missing response_type"});return i8({ctx:t,session:Ae||void 0,redirect_uri:i,state:a,response_type:p,client:F,nonce:u,code_challenge_method:$,code_challenge:g,audience:l,scope:s})}if(F.connections.length===1&&F.connections[0]&&!o8.includes(F.connections[0].strategy||""))return mg(t,F,F.connections[0].name,K);if(d&&d!=="email")return mg(t,F,d,K);if(z){const L=await r8(t,F.tenant.id,z,K,T);return L instanceof Response?L:t.json(L)}const R=await t8({ctx:t,client:F,auth0Client:O,authParams:K,session:Ae||void 0,connection:d,login_hint:x});return R instanceof Response?R:t.json(R)}),a8=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 fo(e,n);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const l={redirect_uri:r||t.req.url,client_id:n,username:i},u=t.req.header("origin");if(u&&!xy(u,a.web_origins||[]))throw new E(403,{message:`Origin ${u} not allowed`});if(l.redirect_uri){const x=a.callbacks||[];if(t.var.host&&(x.push(`${Il(t.env)}/*`),x.push(`${dt(t.env)}/*`)),!kf(l.redirect_uri,x,{allowPathWildcards:!0}))throw new E(400,{message:`Invalid redirect URI - ${l.redirect_uri}`})}const d=Di(a.tenant.id,t.req.header("cookie")),p=d?await e.data.sessions.get(a.tenant.id,d):void 0,h=p&&!p.revoked_at?p:void 0,g=new URL(t.req.url);t.var.custom_domain&&(g.hostname=t.var.custom_domain);const{ip:$,auth0_client:A,useragent:z}=t.var,T=Yn(A),O=await e.data.loginSessions.create(a.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:l,csrf_token:He(),authorization_url:g.toString(),ip:$,useragent:z,auth0Client:T});if(h){if(i){const U=await e.data.users.get(a.tenant.id,h.user_id);if((U==null?void 0:U.email)!==i)return t.redirect(`${dt(t.env)}login/identifier?state=${encodeURIComponent(O.id)}`)}if(await e.data.loginSessions.update(a.tenant.id,O.id,{session_id:h.id}),s==="change-email"){const U=new URL("/u/account/change-email",t.req.url);return U.searchParams.set("state",O.id),t.redirect(U.toString())}const x=new URL("/u/account",t.req.url);return x.searchParams.set("state",O.id),t.redirect(x.toString())}return t.redirect(`${dt(t.env)}login/identifier?state=${encodeURIComponent(O.id)}`)});function c8(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=as(r,t.dataAdapter),a=t.dataAdapter.cache||ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),l=t.dataAdapter.cache?300:0,u=Dl(s,{defaultTtl:l,cacheEntities:["tenants","connections","customDomains","clients","legacyClients","branding","themes","promptSettings","forms","resourceServers","roles","organizations","userRoles","userPermissions"],cache:a});return r.env.data=zl(r,u),i()}),e.use("/oauth/token",Dm({origin:r=>r||"",allowHeaders:["Tenant-Id","Content-Type","Auth0-Client","Upgrade-Insecure-Requests"],allowMethods:["POST"],maxAge:600})),e.use(Ol).use(Tl).use(Af(e));const n=e.route("/v2/logout",C5).route("/userinfo",z5).route("/.well-known",I5).route("/oauth/token",WE).route("/dbconnections",YE).route("/passwordless",ZE).route("/co/authenticate",e8).route("/authorize",s8).route("/account",a8).route("/callback",k5);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth API"},security:[{oauth2:["openid","email","profile"]}]}),xf(n),n}var Uf=(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,l=s.length;a<l;a++){const u=s[a];if(typeof u=="string")wr(u,n);else if(typeof u=="number")n[0]+=u;else{if(typeof u=="boolean"||u===null||u===void 0)continue;if(typeof u=="object"&&u.isEscaped)if(u.callbacks)n.unshift("",u);else{const d=u.toString();d instanceof Promise?n.unshift("",d):n[0]+=d}else u instanceof Promise?n.unshift("",u):wr(u.toString(),n)}}}return n[0]+=t.at(-1),n.length===1?"callbacks"in n?hn(Z1(hn(n[0],n.callbacks))):hn(n[0]):Y1(n,n.callbacks)},Mf=Symbol("RENDERER"),cp=Symbol("ERROR_HANDLER"),We=Symbol("STASH"),Ay=Symbol("INTERNAL"),l8=Symbol("MEMO"),bc=Symbol("PERMALINK"),Kg=t=>(t[Ay]=!0,t),Ey=t=>({value:e,children:n})=>{if(!n)return;const r={children:[{tag:Kg(()=>{t.push(e)}),props:{}}]};Array.isArray(n)?r.children.push(...n.flat()):r.children.push(n),r.children.push({tag:Kg(()=>{t.pop()}),props:{}});const i={tag:"",props:r,type:""};return i[cp]=s=>{throw t.pop(),s},i},Sy=t=>{const e=[t],n=Ey(e);return n.values=e,n.Provider=n,Ki.push(n),n},Ki=[],ky=t=>{const e=[t],n=r=>{e.push(r.value);let i;try{i=r.children?(Array.isArray(r.children)?new Iy("",{},r.children):r.children).toString():""}finally{e.pop()}return i instanceof Promise?i.then(s=>hn(s,s.callbacks)):hn(i)};return n.values=e,n.Provider=n,n[Mf]=Ey(e),Ki.push(n),n},ho=t=>t.values.at(-1),pa={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},lp={},fa="data-precedence",Cs=t=>Array.isArray(t)?t:[t],Gg=new WeakMap,Wg=(t,e,n,r)=>({buffer:i,context:s})=>{if(!i)return;const a=Gg.get(s)||{};Gg.set(s,a);const l=a[t]||(a[t]=[]);let u=!1;const d=pa[t];if(d.length>0){e:for(const[,p]of l)for(const h of d)if(((p==null?void 0:p[h])??null)===(n==null?void 0:n[h])){u=!0;break e}}if(u?i[0]=i[0].replaceAll(e,""):d.length>0?l.push([e,n,r]):l.unshift([e,n,r]),i[0].indexOf("</head>")!==-1){let p;if(r===void 0)p=l.map(([h])=>h);else{const h=[];p=l.map(([g,,$])=>{let A=h.indexOf($);return A===-1&&(h.push($),A=h.length-1),[g,A]}).sort((g,$)=>g[1]-$[1]).map(([g])=>g)}p.forEach(h=>{i[0]=i[0].replaceAll(h,"")}),i[0]=i[0].replace(/(?=<\/head>)/,p.join(""))}},zs=(t,e,n)=>hn(new gn(t,n,Cs(e??[])).toString()),Is=(t,e,n,r)=>{if("itemProp"in n)return zs(t,e,n);let{precedence:i,blocking:s,...a}=n;i=r?i??"":void 0,r&&(a[fa]=i);const l=new gn(t,a,Cs(e||[])).toString();return l instanceof Promise?l.then(u=>hn(l,[...u.callbacks||[],Wg(t,u,a,i)])):hn(l,[Wg(t,l,a,i)])},u8=({children:t,...e})=>{const n=qf();if(n){const r=ho(n);if(r==="svg"||r==="head")return new gn("title",e,Cs(t??[]))}return Is("title",t,e,!1)},d8=({children:t,...e})=>{const n=qf();return["src","async"].some(r=>!e[r])||n&&ho(n)==="head"?zs("script",t,e):Is("script",t,e,!1)},p8=({children:t,...e})=>["href","precedence"].every(n=>n in e)?(e["data-href"]=e.href,delete e.href,Is("style",t,e,!0)):zs("style",t,e),f8=({children:t,...e})=>["onLoad","onError"].some(n=>n in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?zs("link",t,e):Is("link",t,e,"precedence"in e),h8=({children:t,...e})=>{const n=qf();return n&&ho(n)==="head"?zs("meta",t,e):Is("meta",t,e,!1)},Ny=(t,{children:e,...n})=>new gn(t,n,Cs(e??[])),g8=t=>(typeof t.action=="function"&&(t.action=bc in t.action?t.action[bc]:void 0),Ny("form",t)),Cy=(t,e)=>(typeof e.formAction=="function"&&(e.formAction=bc in e.formAction?e.formAction[bc]:void 0),Ny(t,e)),m8=t=>Cy("input",t),_8=t=>Cy("button",t);const pu=Object.freeze(Object.defineProperty({__proto__:null,button:_8,form:g8,input:m8,link:f8,meta:h8,script:d8,style:p8,title:u8},Symbol.toStringTag,{value:"Module"}));var y8=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),$c=t=>y8.get(t)||t,zy=(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)}},es=void 0,qf=()=>es,w8=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,v8=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],b8=["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"],Vf=(t,e)=>{for(let n=0,r=t.length;n<r;n++){const i=t[n];if(typeof i=="string")wr(i,e);else{if(typeof i=="boolean"||i===null||i===void 0)continue;i instanceof gn?i.toStringToBuffer(e):typeof i=="number"||i.isEscaped?e[0]+=i:i instanceof Promise?e.unshift("",i):Vf(i,e)}}},gn=class{constructor(t,e,n){be(this,"tag");be(this,"props");be(this,"key");be(this,"children");be(this,"isEscaped",!0);be(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?Z1(hn(t[0],t.callbacks)).toString():t[0]:Y1(t,t.callbacks)}toStringToBuffer(t){const e=this.tag,n=this.props;let{children:r}=this;t[0]+=`<${e}`;const i=es&&ho(es)==="svg"?s=>w8($c(s)):s=>$c(s);for(let[s,a]of Object.entries(n))if(s=i(s),s!=="children"){if(s==="style"&&typeof a=="object"){let l="";zy(a,(u,d)=>{d!=null&&(l+=`${l?";":""}${u}:${d}`)}),t[0]+=' style="',wr(l,t),t[0]+='"'}else if(typeof a=="string")t[0]+=` ${s}="`,wr(a,t),t[0]+='"';else if(a!=null)if(typeof a=="number"||a.isEscaped)t[0]+=` ${s}="${a}"`;else if(typeof a=="boolean"&&b8.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=[hn(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}="`,wr(a.toString(),t),t[0]+='"'}if(v8.includes(e)&&r.length===0){t[0]+="/>";return}t[0]+=">",Vf(r,t),t[0]+=`</${e}>`}},fu=class extends gn{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(Ki.length===0)t.unshift("",n);else{const r=Ki.map(i=>[i,i.values.at(-1)]);t.unshift("",n.then(i=>(i instanceof gn&&(i.localContexts=r),i)))}else n instanceof gn?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?(t[0]+=n,n.callbacks&&(t.callbacks||(t.callbacks=[]),t.callbacks.push(...n.callbacks))):wr(n,t)}},Iy=class extends gn{toStringToBuffer(t){Vf(this.children,t)}},$8=(t,e,...n)=>{e??(e={}),n.length&&(e.children=n.length===1?n[0]:n);const r=e.key;delete e.key;const i=ha(t,e,n);return i.key=r,i},Xg=!1,ha=(t,e,n)=>{if(!Xg){for(const r in lp)pu[r][Mf]=lp[r];Xg=!0}return typeof t=="function"?new fu(t,e,n):pu[t]?new fu(pu[t],e,n):t==="svg"||t==="head"?(es||(es=ky("")),new gn(t,e,[new fu(es,{value:t},n)])):new gn(t,e,n)},Hf=({children:t})=>new Iy("",{children:t},Array.isArray(t)?t:t?[t]:[]),x8=(t,e,...n)=>{let r;if(n.length>0)r=n;else{const i=t.props.children;r=Array.isArray(i)?i:[i]}return $8(t.tag,{...t.props,...e},...r)};function _(t,e,n){let r;if(!e||!("children"in e))r=ha(t,e,[]);else{const i=e.children;r=Array.isArray(i)?ha(t,e,i):ha(t,e,[i])}return r.key=n,r}async function Ue(t,e,n=!1){var p;const{env:r}=t,i=await r.data.loginSessions.get(t.var.tenant_id||"",e);if(!i)throw new E(400,{message:"Login session not found"});t.set("loginSession",i);const s=await fo(r,i.authParams.client_id);t.set("client_id",s.client_id),t.set("tenant_id",s.tenant.id);const a=await r.data.tenants.get(s.tenant.id);if(a){if(i.session_id&&!n){if(!i.authParams.redirect_uri)throw new E(400,{message:"Login session closed and no redirect URI available"});const h=new URL(i.authParams.redirect_uri);throw h.searchParams.set("error","access_denied"),h.searchParams.set("error_description","Login session closed"),i.authParams.state&&h.searchParams.set("state",i.authParams.state),new oi(h.toString(),302)}}else throw new E(400,{message:"Tenant not found"});const l=await r.data.themes.get(a.id,"default"),u=await r.data.branding.get(a.id),d=(p=i.authParams.ui_locales)==null?void 0:p.split(" ").map(h=>h.split("-")[0]).find(h=>{if(Array.isArray(P.options.supportedLngs))return P.options.supportedLngs.includes(h)});return await P.changeLanguage(d||a.language||"sv"),{theme:l,branding:u,client:s,tenant:a,loginSession:i}}async function si(t,e){const{theme:n,branding:r,client:i,tenant:s,loginSession:a}=await Ue(t,e,!0),l=Di(i.tenant.id,t.req.header("cookie")),u=l?await t.env.data.sessions.get(i.tenant.id,l):null;if(!u||!a.session_id)throw new oi(`/u/login/identifier?state=${encodeURIComponent(e)}`);const d=await t.env.data.sessions.get(i.tenant.id,a.session_id),p=await t.env.data.users.get(i.tenant.id,u.user_id);if(!p||(d==null?void 0:d.user_id)!==u.user_id)throw new oi(`/u/login/identifier?state=${encodeURIComponent(e)}`);return{theme:n,branding:r,client:i,user:p,tenant:s,loginSession:a,session:d}}async function A8(t,e,n,r){if(r!==void 0)return r==="password";const i=await Op({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}const Ty=({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?_("div",{className:"flex h-9 items-center",children:_("img",{src:n,className:"max-h-full",alt:"Logo"})}):_(Hf,{})},Oy=t=>{var e,n;return _("div",{className:"mt-8",children:((n=(e=t.client)==null?void 0:e.client_metadata)==null?void 0:n.termsAndConditionsUrl)&&_("div",{className:"text-xs text-gray-300",children:[P.t("agree_to")," ",_("a",{href:t.client.client_metadata.termsAndConditionsUrl,className:"text-primary hover:underline",target:"_blank",rel:"noreferrer",children:P.t("terms")})]})})};var Dy={exports:{}};/*!
|
|
197
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function OE(t,e){if(t){if(typeof t=="string")return Fg(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 Fg(t,e)}}function Fg(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 DE(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,l;try{for(n=n.call(t);!(i=(a=n.next()).done)&&(r.push(a.value),!(e&&r.length===e));i=!0);}catch(u){s=!0,l=u}finally{try{!i&&n.return!=null&&n.return()}finally{if(s)throw l}}return r}}function RE(t){if(Array.isArray(t))return t}function jE(t){var e=Array.prototype.slice.call(t),n=IE(e,4),r=n[0],i=n[1],s=n[2],a=n[3],l,u,d;if(typeof r=="string")l=r;else throw new TypeError("A text for parsing must be a string.");if(!i||typeof i=="string")a?(u=s,d=a):(u=void 0,d=s),i&&(u=CE({defaultCountry:i},u));else if(Oi(i))s?(u=i,d=s):d=i;else throw new Error("Invalid second argument: ".concat(i));return{text:l,options:u,metadata:d}}function Ug(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 Mg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ug(Object(n),!0).forEach(function(r){PE(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ug(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function PE(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function BE(t,e,n){e&&e.defaultCountry&&!W5(e.defaultCountry,n)&&(e=Mg(Mg({},e),{},{defaultCountry:void 0}));try{return NE(t,e,n)}catch(r){if(!(r instanceof Un))throw r}}function LE(){var t=jE(arguments),e=t.text,n=t.options,r=t.metadata;return BE(e,n,r)}function FE(){return B5(LE,arguments)}function Bl(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=FE(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 Of(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 UE(t){const n=Of(t).split(".");return n.length!==4?!1:n.every(r=>/^\d+$/.test(r)&&Number(r)>=0&&Number(r)<=255)}function ME(t){const e=Of(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 qE(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 qg(t){if(!t)return null;const e=Of(qE(t));return UE(e)?{family:4,normalized:e}:ME(e)?{family:6,normalized:e.toLowerCase()}:null}function Vg(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 VE(t,e,n=!0){const r=qg(t),i=qg(e);if(!r||!i||r.family!==i.family)return!1;if(r.family===4)return r.normalized===i.normalized;const s=Vg(r.normalized),a=Vg(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 oi extends Error{constructor(n,r=302){super(`Redirect to ${n}`);be(this,"location");be(this,"status");this.name=oi.name,this.location=n,this.status=r}}const HE=o.z.object({client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),otp:o.z.string(),authParams:jo.optional(),enforceIpCheck:o.z.boolean().optional().default(!1)});async function _y(t,{client_id:e,username:n,otp:r,authParams:i,enforceIpCheck:s=!1}){const a=t.get("ip"),l=t.get("countryCode"),{connectionType:u,normalized:d}=Bl(n,l);if(!d)throw new E(400,{message:"Invalid username format"});const p=await t.env.data.legacyClients.get(e);if(!p)throw new E(403,{message:"Client not found"});const{env:h}=t,g=await h.data.codes.get(p.tenant.id,r,"otp");if(!g)throw new E(400,{message:xe("code_invalid")});if(g.expires_at<new Date().toISOString())throw new E(400,{message:xe("code_expired")});if(g.used_at)throw new E(400,{message:xe("code_used")});const $=await h.data.loginSessions.get(p.tenant.id,g.login_id);if(!$||$.authParams.username!==n)throw new E(400,{message:"Code not found or expired"});if(s&&$.ip&&a&&!VE($.ip,a))throw new oi(`${dt(t.env)}invalid-session?state=${$.id}`);const A=await Bc(t,{client:p,username:d,provider:u,connection:u,isSocial:!1,ip:t.var.ip});return await h.data.codes.used(p.tenant.id,r),{user:A,client:p,loginSession:$,session_id:$.session_id,authParams:{...$.authParams,...i||{}}}}async function Df(t,e){const n=await _y(t,e);return Dn(t,{authParams:n.authParams,client:n.client,user:n.user,loginSession:n.loginSession,strategy:"email"})}const Hg=o.z.object({client_id:o.z.string().optional(),client_secret:o.z.string().optional()}),KE=o.z.union([cy.extend(Hg.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)}),o.z.object({grant_type:o.z.literal("authorization_code"),code:o.z.string(),redirect_uri:o.z.string().optional(),...Hg.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 GE(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 WE=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:KE}}}},responses:{200:{content:{"application/json":{schema:xp}},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 l,u,d;const e=t.req.valid("form"),n=GE(t.req.header("Authorization")),r={...e,...n};if(!r.client_id)throw new E(400,{message:"client_id is required"});t.set("client_id",r.client_id);let i;switch(e.grant_type){case an.AuthorizationCode:i=await D5(t,O5.parse(r));break;case an.ClientCredential:i=await T5(t,cy.parse(r));break;case an.RefreshToken:i=await j5(t,R5.parse(r));break;case an.OTP:i=await _y(t,HE.parse(r));break;default:return t.json({error:"unsupported_grant_type",error_description:"Grant type not implemented"},400)}const s=new Headers;if(i.session_id){const p=Da(i.client.tenant.id,i.session_id,t.var.host||"");s.set("Set-Cookie",p)}if(i.authParams.audience)try{let p;if(e.grant_type===an.ClientCredential)p=await ja(t,{grantType:an.ClientCredential,tenantId:i.client.tenant.id,clientId:i.client.client_id,audience:i.authParams.audience,requestedScopes:((l=i.authParams.scope)==null?void 0:l.split(" "))||[],organizationId:i.organization});else{if(!((u=i.user)!=null&&u.user_id))throw new Ra(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});p=await ja(t,{grantType:e.grant_type,tenantId:i.client.tenant.id,userId:i.user.user_id,clientId:i.client.client_id,audience:i.authParams.audience,requestedScopes:((d=i.authParams.scope)==null?void 0:d.split(" "))||[],organizationId:i.organization})}i.authParams.scope=p.scopes.join(" ")}catch(p){if(p instanceof E)throw p;console.error("Error calculating scopes and permissions:",p)}const a=await Pc(t,{...i,grantType:e.grant_type});return t.json(a,{headers:s})});var Rf={exports:{}};const jf=[{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}],yy=(t,e=jf,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(l=>new RegExp(`${l.regex}`).test(r)).map(l=>l.message),s.length=r.length;let a=e.filter(l=>s.contains.length>=l.minDiversity).filter(l=>s.length>=l.minLength).sort((l,u)=>u.id-l.id).map(l=>({id:l.id,value:l.value}));return Object.assign(s,a[0]),s};Rf.exports={passwordStrength:yy,defaultOptions:jf};var XE=Rf.exports.passwordStrength=yy;Rf.exports.defaultOptions=jf;function Pf(t){return XE(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 Ns(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 E(500,{message:"Email provider not found"});const r=(i=t.env.emailProviders)==null?void 0:i[n.name];if(!r)throw new E(500,{message:"Email provider not found"});await r({emailProvider:n,...e,from:n.default_from_address||`login@${t.env.ISSUER}`})}async function wy(t,e){var a,l;if(!t.var.client_id)throw new E(500,{message:"Client not found"});const n=await fo(t.env,t.var.client_id),r=n.connections.find(u=>u.strategy==="sms");if(!r)throw new E(500,{message:"SMS provider not found"});const i=((a=r.options)==null?void 0:a.provider)||"twilio",s=(l=t.env.smsProviders)==null?void 0:l[i];if(!s)throw new E(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.name,tenantId:n.tenant.id}})}async function vy(t,e,n,r){const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new E(500,{message:"Tenant not found"});const s=`${dt(t.env)}reset-password?state=${r}&code=${n}`,a={vendorName:i.name,lng:i.language||"en"};await Ns(t,{to:e,subject:xe("reset_password_title",a),html:`Click here to reset your password: ${dt(t.env)}reset-password?state=${r}&code=${n}`,template:"auth-password-reset",data:{vendorName:i.name,logo:i.logo||"",passwordResetUrl:s,supportUrl:i.support_url||"https://support.sesamy.com",buttonColor:i.primary_color||"#7d68f4",passwordResetTitle:xe("password_reset_title",a),resetPasswordEmailClickToReset:xe("reset_password_email_click_to_reset",a),resetPasswordEmailReset:xe("reset_password_email_reset",a),supportInfo:xe("support_info",a),contactUs:xe("contact_us",a),copyright:xe("copyright",a),tenantName:i.name,tenantId:i.id}})}async function Bf(t,{to:e,code:n}){const r=await t.env.data.tenants.get(t.var.tenant_id);if(!r)throw new E(500,{message:"Tenant not found"});const{connectionType:i}=Bl(e),s=new URL(dt(t.env)),a={vendorName:r.name,vendorId:r.id,loginDomain:s.hostname,code:n,lng:r.language||"en"};i==="email"?await Ns(t,{to:e,subject:xe("code_email_subject",a),html:`Click here to validate your email: ${dt(t.env)}validate-email`,template:"auth-code",data:{code:n,vendorName:r.name,logo:r.logo||"",supportUrl:r.support_url||"",buttonColor:r.primary_color||"",welcomeToYourAccount:xe("welcome_to_your_account",a),linkEmailClickToLogin:xe("link_email_click_to_login",a),linkEmailLogin:xe("link_email_login",a),linkEmailOrEnterCode:xe("link_email_or_enter_code",a),codeValid30Mins:xe("code_valid_30_minutes",a),supportInfo:xe("support_info",a),contactUs:xe("contact_us",a),copyright:xe("copyright",a)}}):i==="sms"&&await wy(t,{to:e,text:xe("sms_code_text",a),code:n,from:r.name});const l=Me(t,{type:Le.CODE_LINK_SENT,description:e});ln(t,t.env.data.logs.create(r.id,l))}async function Lf(t,{to:e,code:n,authParams:r}){const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new E(500,{message:"Tenant not found"});if(!r.redirect_uri)throw new E(400,{message:"redirect_uri is required"});const{connectionType:s}=Bl(e),a=new URL(ct(t.env));a.pathname="passwordless/verify_redirect",a.searchParams.set("verification_code",n),a.searchParams.set("connection",s),a.searchParams.set("client_id",r.client_id),a.searchParams.set("redirect_uri",r.redirect_uri),a.searchParams.set("email",e),r.response_type&&a.searchParams.set("response_type",r.response_type),r.scope&&a.searchParams.set("scope",r.scope),r.state&&a.searchParams.set("state",r.state),r.nonce&&a.searchParams.set("nonce",r.nonce),r.code_challenge&&a.searchParams.set("code_challenge",r.code_challenge),r.code_challenge_method&&a.searchParams.set("code_challenge_method",r.code_challenge_method),r.audience&&a.searchParams.set("audience",r.audience);const l={vendorName:i.name,code:n,lng:i.language||"en"};if(s==="email")await Ns(t,{to:e,subject:xe("code_email_subject",l),html:`Click here to validate your email: ${dt(t.env)}validate-email`,template:"auth-link",data:{code:n,vendorName:i.name,logo:i.logo||"",supportUrl:i.support_url||"",magicLink:a.toString(),buttonColor:i.primary_color||"",welcomeToYourAccount:xe("welcome_to_your_account",l),linkEmailClickToLogin:xe("link_email_click_to_login",l),linkEmailLogin:xe("link_email_login",l),linkEmailOrEnterCode:xe("link_email_or_enter_code",l),codeValid30Mins:xe("code_valid_30_minutes",l),supportInfo:xe("support_info",l),contactUs:xe("contact_us",l),copyright:xe("copyright",l)}});else if(s==="sms")await wy(t,{to:e,text:`${xe("link_sms_login",l)}: ${a.toString()}`,code:n,from:i.name});else throw new E(400,{message:"Only email and SMS connections are supported for magic links"});const u=Me(t,{type:Le.CODE_LINK_SENT,description:e});ln(t,t.env.data.logs.create(i.id,u))}async function Ff(t,e){const n=await t.env.data.tenants.get(t.var.tenant_id);if(!n)throw new E(500,{message:"Tenant not found"});if(!e.email)throw new E(400,{message:"User has no email"});const r={vendorName:n.name,lng:n.language||"en"};await Ns(t,{to:e.email,subject:xe("welcome_to_your_account",r),html:`Click here to validate your email: ${dt(t.env)}validate-email`,template:"auth-verify-email",data:{vendorName:n.name,logo:n.logo||"",emailValidationUrl:`${dt(t.env)}validate-email`,supportUrl:n.support_url||"https://support.sesamy.com",buttonColor:n.primary_color||"#7d68f4",welcomeToYourAccount:xe("welcome_to_your_account",r),verifyEmailVerify:xe("verify_email_verify",r),supportInfo:xe("support_info",r),contactUs:xe("contact_us",r),copyright:xe("copyright",r)}})}async function JE(t,e,n,r){const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new E(500,{message:"Tenant not found"});const s={vendorName:i.name,lng:i.language||"en"},a=`${dt(t.env)}signup?state=${r}&code=${n}`;await Ns(t,{to:e,subject:xe("register_password_account",s),html:`Click here to register: ${a}`,template:"auth-pre-signup-verification",data:{vendorName:i.name,logo:i.logo||"",signupUrl:a,setPassword:xe("set_password",s),registerPasswordAccount:xe("register_password_account",s),clickToSignUpDescription:xe("click_to_sign_up_description",s),supportUrl:i.support_url||"https://support.sesamy.com",buttonColor:i.primary_color||"#7d68f4",welcomeToYourAccount:xe("welcome_to_your_account",s),verifyEmailVerify:xe("verify_email_verify",s),supportInfo:xe("support_info",s),contactUs:xe("contact_us",s),copyright:xe("copyright",s)}})}const YE=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 E(400,{message:"Client not found"});if(t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id),!Pf(n))throw new E(400,{message:"Password does not meet the requirements"});if(await Po({userAdapter:t.env.data.users,tenant_id:i.tenant.id,username:e,provider:"auth2"}))throw new E(400,{message:"Invalid sign up"});const a=await t.env.data.users.create(i.tenant.id,{user_id:`auth2|${Dc()}`,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 l=await ss.hash(n,10);await t.env.data.passwords.create(i.tenant.id,{user_id:a.user_id,password:l,algorithm:"bcrypt"}),await Ff(t,a);const u=Me(t,{type:Le.SUCCESS_SIGNUP,description:"Successful signup"});return await t.env.data.logs.create(i.tenant.id,u),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 E(400,{message:"Client not found"});if(t.set("client_id",r.client_id),t.set("tenant_id",r.tenant.id),!await eo({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()+Hr*1e3).toISOString(),authParams:s,csrf_token:He(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Yn(t.get("auth0_client"))});return await vy(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 Ar(){const t="1234567890";let e="";for(let n=0;n<6;n+=1)e+=t[Math.floor(Math.random()*10)];return e.toString()}const ZE=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:jo.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:jo.omit({client_id:!0})})])}}}},responses:{200:{description:"Status"}}}),async t=>{const e=t.req.valid("json"),{env:n}=t,{client_id:r,send:i,authParams:s,connection:a}=e,l=await t.env.data.legacyClients.get(r);if(!l)throw new E(400,{message:"Client not found"});t.set("client_id",l.client_id),t.set("tenant_id",l.tenant.id);const u=a==="email"?e.email:e.phone_number,d=t.get("ip"),p=t.get("useragent"),h=t.get("auth0_client"),g=Yn(h),$=await n.data.loginSessions.create(l.tenant.id,{authParams:{...s,client_id:r,username:u},expires_at:new Date(Date.now()+ia).toISOString(),csrf_token:He(),ip:d,useragent:p,auth0Client:g}),A=await n.data.codes.create(l.tenant.id,{code_id:Ar(),code_type:"otp",login_id:$.id,expires_at:new Date(Date.now()+ia).toISOString(),redirect_uri:s.redirect_uri});return i==="link"?await Lf(t,{to:u,code:A.code_id,authParams:{...s,client_id:r}}):await Bf(t,{to:u,code:A.code_id}),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(Yt),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:l,audience:u,response_type:d,nonce:p}=t.req.valid("query"),h=await fo(e,n);t.set("client_id",h.client_id),t.set("tenant_id",h.tenant.id),t.set("connection","email");const g={client_id:n,redirect_uri:s,state:a,nonce:p,scope:l,audience:u,response_type:d};let $="Something went wrong. Please try again later.";try{const U=await Df(t,{client_id:n,username:r,otp:i,authParams:g,enforceIpCheck:!0});if(U instanceof Response)return U;if(U&&typeof U=="object"&&"access_token"in U)return t.json(U)}catch(U){const q=U;"message"in q&&typeof q.message=="string"&&($=q.message)}const A=t.get("ip"),z=t.get("useragent"),T=t.get("auth0_client"),O=Yn(T),x=await e.data.loginSessions.create(h.tenant.id,{authParams:{...g,username:r},expires_at:new Date(Date.now()+ia).toISOString(),csrf_token:He(),ip:A,useragent:z,auth0Client:O});return t.redirect(`${dt(t.env)}invalid-session?state=${x.id}&error=${encodeURIComponent($)}`,302)});class $i extends E{constructor(n,r){super(n,r);be(this,"_code");this._code=r==null?void 0:r.code}get code(){return this._code}}async function by(t,e,n,r){const{data:i}=t.env,{username:s}=n;if(t.set("username",s),!s)throw new E(400,{message:"Username is required"});const a=await eo({userAdapter:t.env.data.users,tenant_id:e.tenant.id,username:s,provider:"auth2"});if(!a){const $=Me(t,{type:Le.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid user"});throw ln(t,i.logs.create(e.tenant.id,$)),new $i(403,{message:"User not found",code:"USER_NOT_FOUND"})}const l=a.linked_to?await i.users.get(e.tenant.id,a.linked_to):a;if(!l)throw new $i(403,{message:"User not found",code:"USER_NOT_FOUND"});t.set("connection",a.connection),t.set("user_id",l.user_id);const u=await i.passwords.get(e.tenant.id,a.user_id);if(!(u&&await ss.compare(n.password,u.password))){const $=Me(t,{type:Le.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid password"});throw ln(t,i.logs.create(e.tenant.id,$)),new $i(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:${l.user_id}`})).logs.filter($=>$.type===Le.FAILED_LOGIN_INCORRECT_PASSWORD&&new Date($.date)>new Date(Date.now()-1e3*60*5)).length>=3){const $=Me(t,{type:Le.FAILED_LOGIN,description:"Too many failed login attempts"});throw ln(t,i.logs.create(e.tenant.id,$)),new $i(403,{message:"Too many failed login attempts",code:"TOO_MANY_FAILED_LOGINS"})}if(!a.email_verified&&e.email_validation==="enforced"){await Ff(t,a);const $=Me(t,{type:Le.FAILED_LOGIN,description:"Email not verified"});throw await i.logs.create(e.tenant.id,$),new $i(403,{message:"Email not verified",code:"EMAIL_NOT_VERIFIED"})}const g=Me(t,{type:Le.SUCCESS_LOGIN,description:"Successful login",strategy_type:"Username-Password-Authentication",strategy:"Username-Password-Authentication"});return ln(t,i.logs.create(e.tenant.id,g)),{client:e,authParams:n,user:l,loginSession:r}}async function $y(t,e,n,r,i){const s=await by(t,e,n,r);return Dn(t,{...s,ticketAuth:i,strategy:"Username-Password-Authentication"})}async function QE(t,e,n,r){await Bc(t,{client:e,username:n,provider:"auth2",connection:"Username-Password-Authentication",isSocial:!1,ip:t.var.ip});let i=Ar(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");for(;s;)i=Ar(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");const a=t.get("ip"),l=t.get("useragent"),u=t.get("auth0_client"),d=Yn(u),p=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+nb).toISOString(),authParams:{client_id:e.client_id,username:n},csrf_token:He(),ip:a,useragent:l,auth0Client:d}),h=await t.env.data.codes.create(e.tenant.id,{code_id:i,code_type:"password_reset",login_id:p.id,expires_at:new Date(Date.now()+tb).toISOString()});await vy(t,n,h.code_id,r)}const e8=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 E(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"),l=t.get("useragent"),u=t.get("auth0_client");let d;if("otp"in e)d=await Df(t,{client_id:n,username:s,otp:e.otp});else if("password"in e){const p=await t.env.data.loginSessions.create(i.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:{client_id:n,username:s},csrf_token:He(),ip:a,useragent:l,auth0Client:Yn(u)});d=await $y(t,i,{username:s,password:e.password,client_id:n},p,!0)}else throw new E(400,{message:"Code or password required"});if(!(d instanceof Response))throw new E(500,{message:"Unexpected response from loginWithPassword"});return d});function xy(t,e){var r,i,s;if(!t||e.length===0)return!1;const n=((r=du(t))==null?void 0:r.host)??null;if(!n)return!1;for(const a of e){let l;if(a.startsWith("http://")||a.startsWith("https://")?l=((i=du(a))==null?void 0:i.host)??null:l=((s=du("https://"+a))==null?void 0:s.host)??null,n===l)return!0}return!1}function du(t){try{return new URL(t)}catch{return null}}async function t8({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:l,auth0_client:u,useragent:d}=t.var,p=Yn(u),h=await t.env.data.loginSessions.create(n.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:r,csrf_token:He(),authorization_url:a.toString(),ip:l,useragent:d,auth0Client:p});if(e&&s){const g=await t.env.data.users.get(n.tenant.id,e.user_id);if((g==null?void 0:g.email)===s)return await t.env.data.loginSessions.update(n.tenant.id,h.id,{session_id:e.id}),Dn(t,{client:n,loginSession:{...h,session_id:e.id},authParams:r,user:g,sessionId:e.id})}if(i==="email"&&s){const g=Ar();return await t.env.data.codes.create(n.tenant.id,{code_id:g,code_type:"otp",login_id:h.id,expires_at:new Date(Date.now()+Hr*1e3).toISOString(),redirect_uri:r.redirect_uri}),await Lf(t,{code:g,to:s,authParams:r}),t.redirect(`/u/enter-code?state=${h.id}`)}return e?t.redirect(`/u/check-account?state=${h.id}`):t.redirect(`/u/login/identifier?state=${h.id}`)}function n8(t){if(t==="Username-Password-Authentication")return"auth2";if(t==="email")return"email";throw new E(403,{message:"Invalid realm"})}async function r8(t,e,n,r,i){var g;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 E(403,{message:"Ticket not found"});const l=await s.data.loginSessions.get(e,a.login_id);if(!l||!l.authParams.username)throw new E(403,{message:"Session not found"});const u=await s.data.legacyClients.get(l.authParams.client_id);if(!u)throw new E(403,{message:"Client not found"});t.set("client_id",l.authParams.client_id),await s.data.codes.used(e,n);const d=n8(i);let p=await Bc(t,{username:l.authParams.username,provider:d,client:u,connection:d==="auth2"?"Username-Password-Authentication":"email",isSocial:!1,ip:t.var.ip});t.set("username",p.email||p.phone_number),t.set("user_id",p.user_id);const h=await J_(t,{user:p,client:u,loginSession:l});return Dn(t,{authParams:{scope:(g=l.authParams)==null?void 0:g.scope,...r},loginSession:l,sessionId:h.id,user:p,client:u})}async function i8({ctx:t,client:e,session:n,redirect_uri:r,state:i,nonce:s,code_challenge_method:a,code_challenge:l,audience:u,scope:d,response_type:p}){const{env:h}=t,g=new URL(r),$=`${g.protocol}//${g.host}`;async function A(H="Login required"){const G=Me(t,{type:Le.FAILED_SILENT_AUTH,description:H});return await t.env.data.logs.create(e.tenant.id,G),t.html(Du($,JSON.stringify({error:"login_required",error_description:H,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 A();t.set("user_id",n.user_id);const T=await h.data.users.get(e.tenant.id,n.user_id);if(!T)return console.error("User not found",n.user_id),A("User not found");t.set("username",T.email),t.set("connection",T.connection);const O={client:e,authParams:{client_id:e.client_id,audience:u,code_challenge_method:a,code_challenge:l,scope:d,state:i,nonce:s,response_type:p,redirect_uri:r},user:T,session_id:n.id},x=p===Yt.CODE?await W_(t,{user:T,client:e,authParams:O.authParams,login_id:n.login_session_id}):await Pc(t,O);await h.data.sessions.update(e.tenant.id,n.id,{used_at:new Date().toISOString(),last_interaction_at:new Date().toISOString(),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()+Rc*1e3).toISOString():void 0});const U=Me(t,{type:Le.SUCCESS_SILENT_AUTH,description:"Successful silent authentication"});await t.env.data.logs.create(e.tenant.id,U);const q=new Headers;q.set("Server-Timing","cf-nel=0; no-cloudflare-insights=1");const F=Da(e.tenant.id,n.id,t.req.header("host"));return q.set("set-cookie",F),t.html(Du($,JSON.stringify({...x,state:i})),{headers:q})}const o8=["email","sms","Username-Password-Authentication"],s8=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(zn).optional(),response_type:o.z.nativeEnum(Yt).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(zc).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:xp}}},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:l,nonce:u,connection:d,response_type:p,response_mode:h,code_challenge:g,code_challenge_method:$,prompt:A,login_ticket:z,realm:T,auth0Client:O,login_hint:x,ui_locales:U,organization:q}=t.req.valid("query");t.set("log","authorize");const F=await fo(e,n);t.set("client_id",F.client_id),t.set("tenant_id",F.tenant.id);const H={redirect_uri:i.split("#")[0],scope:s,state:a,client_id:n,vendor_id:r,audience:l,nonce:u,prompt:A,response_type:p,response_mode:h,code_challenge:g,code_challenge_method:$,username:x,ui_locales:U,organization:q},G=t.req.header("origin");if(G&&!xy(G,F.web_origins||[]))throw new E(403,{message:`Origin ${G} not allowed`});if(H.redirect_uri){const L=F.callbacks||[];if(t.var.host&&(L.push(`${Il(t.env)}/*`),L.push(`${dt(t.env)}/*`)),!kf(H.redirect_uri,L,{allowPathWildcards:!0}))throw new E(400,{message:`Invalid redirect URI - ${H.redirect_uri}`})}const Y=Di(F.tenant.id,t.req.header("cookie")),J=Y?await e.data.sessions.get(F.tenant.id,Y):void 0,Ae=J&&!J.revoked_at?J:void 0;if(A=="none"){if(!p)throw new E(400,{message:"Missing response_type"});return i8({ctx:t,session:Ae||void 0,redirect_uri:i,state:a,response_type:p,client:F,nonce:u,code_challenge_method:$,code_challenge:g,audience:l,scope:s})}if(F.connections.length===1&&F.connections[0]&&!o8.includes(F.connections[0].strategy||""))return mg(t,F,F.connections[0].name,H);if(d&&d!=="email")return mg(t,F,d,H);if(z){const L=await r8(t,F.tenant.id,z,H,T);return L instanceof Response?L:t.json(L)}const R=await t8({ctx:t,client:F,auth0Client:O,authParams:H,session:Ae||void 0,connection:d,login_hint:x});return R instanceof Response?R:t.json(R)}),a8=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 fo(e,n);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const l={redirect_uri:r||t.req.url,client_id:n,username:i},u=t.req.header("origin");if(u&&!xy(u,a.web_origins||[]))throw new E(403,{message:`Origin ${u} not allowed`});if(l.redirect_uri){const x=a.callbacks||[];if(t.var.host&&(x.push(`${Il(t.env)}/*`),x.push(`${dt(t.env)}/*`)),!kf(l.redirect_uri,x,{allowPathWildcards:!0}))throw new E(400,{message:`Invalid redirect URI - ${l.redirect_uri}`})}const d=Di(a.tenant.id,t.req.header("cookie")),p=d?await e.data.sessions.get(a.tenant.id,d):void 0,h=p&&!p.revoked_at?p:void 0,g=new URL(t.req.url);t.var.custom_domain&&(g.hostname=t.var.custom_domain);const{ip:$,auth0_client:A,useragent:z}=t.var,T=Yn(A),O=await e.data.loginSessions.create(a.tenant.id,{expires_at:new Date(Date.now()+Hr*1e3).toISOString(),authParams:l,csrf_token:He(),authorization_url:g.toString(),ip:$,useragent:z,auth0Client:T});if(h){if(i){const U=await e.data.users.get(a.tenant.id,h.user_id);if((U==null?void 0:U.email)!==i)return t.redirect(`${dt(t.env)}login/identifier?state=${encodeURIComponent(O.id)}`)}if(await e.data.loginSessions.update(a.tenant.id,O.id,{session_id:h.id}),s==="change-email"){const U=new URL("/u/account/change-email",t.req.url);return U.searchParams.set("state",O.id),t.redirect(U.toString())}const x=new URL("/u/account",t.req.url);return x.searchParams.set("state",O.id),t.redirect(x.toString())}return t.redirect(`${dt(t.env)}login/identifier?state=${encodeURIComponent(O.id)}`)});function c8(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=as(r,t.dataAdapter),a=t.dataAdapter.cache||ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),l=t.dataAdapter.cache?300:0,u=Dl(s,{defaultTtl:l,cacheEntities:["tenants","connections","customDomains","clients","legacyClients","branding","themes","promptSettings","forms","resourceServers","roles","organizations","userRoles","userPermissions"],cache:a});return r.env.data=zl(r,u),i()}),e.use("/oauth/token",Dm({origin:r=>r||"",allowHeaders:["Tenant-Id","Content-Type","Auth0-Client","Upgrade-Insecure-Requests"],allowMethods:["POST"],maxAge:600})),e.use(Ol).use(Tl).use(Af(e));const n=e.route("/v2/logout",C5).route("/userinfo",z5).route("/.well-known",I5).route("/oauth/token",WE).route("/dbconnections",YE).route("/passwordless",ZE).route("/co/authenticate",e8).route("/authorize",s8).route("/account",a8).route("/callback",k5);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth API"},security:[{oauth2:["openid","email","profile"]}]}),xf(n),n}var Uf=(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,l=s.length;a<l;a++){const u=s[a];if(typeof u=="string")wr(u,n);else if(typeof u=="number")n[0]+=u;else{if(typeof u=="boolean"||u===null||u===void 0)continue;if(typeof u=="object"&&u.isEscaped)if(u.callbacks)n.unshift("",u);else{const d=u.toString();d instanceof Promise?n.unshift("",d):n[0]+=d}else u instanceof Promise?n.unshift("",u):wr(u.toString(),n)}}}return n[0]+=t.at(-1),n.length===1?"callbacks"in n?hn(Z1(hn(n[0],n.callbacks))):hn(n[0]):Y1(n,n.callbacks)},Mf=Symbol("RENDERER"),cp=Symbol("ERROR_HANDLER"),We=Symbol("STASH"),Ay=Symbol("INTERNAL"),l8=Symbol("MEMO"),bc=Symbol("PERMALINK"),Kg=t=>(t[Ay]=!0,t),Ey=t=>({value:e,children:n})=>{if(!n)return;const r={children:[{tag:Kg(()=>{t.push(e)}),props:{}}]};Array.isArray(n)?r.children.push(...n.flat()):r.children.push(n),r.children.push({tag:Kg(()=>{t.pop()}),props:{}});const i={tag:"",props:r,type:""};return i[cp]=s=>{throw t.pop(),s},i},Sy=t=>{const e=[t],n=Ey(e);return n.values=e,n.Provider=n,Ki.push(n),n},Ki=[],ky=t=>{const e=[t],n=r=>{e.push(r.value);let i;try{i=r.children?(Array.isArray(r.children)?new Iy("",{},r.children):r.children).toString():""}finally{e.pop()}return i instanceof Promise?i.then(s=>hn(s,s.callbacks)):hn(i)};return n.values=e,n.Provider=n,n[Mf]=Ey(e),Ki.push(n),n},ho=t=>t.values.at(-1),pa={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},lp={},fa="data-precedence",Cs=t=>Array.isArray(t)?t:[t],Gg=new WeakMap,Wg=(t,e,n,r)=>({buffer:i,context:s})=>{if(!i)return;const a=Gg.get(s)||{};Gg.set(s,a);const l=a[t]||(a[t]=[]);let u=!1;const d=pa[t];if(d.length>0){e:for(const[,p]of l)for(const h of d)if(((p==null?void 0:p[h])??null)===(n==null?void 0:n[h])){u=!0;break e}}if(u?i[0]=i[0].replaceAll(e,""):d.length>0?l.push([e,n,r]):l.unshift([e,n,r]),i[0].indexOf("</head>")!==-1){let p;if(r===void 0)p=l.map(([h])=>h);else{const h=[];p=l.map(([g,,$])=>{let A=h.indexOf($);return A===-1&&(h.push($),A=h.length-1),[g,A]}).sort((g,$)=>g[1]-$[1]).map(([g])=>g)}p.forEach(h=>{i[0]=i[0].replaceAll(h,"")}),i[0]=i[0].replace(/(?=<\/head>)/,p.join(""))}},zs=(t,e,n)=>hn(new gn(t,n,Cs(e??[])).toString()),Is=(t,e,n,r)=>{if("itemProp"in n)return zs(t,e,n);let{precedence:i,blocking:s,...a}=n;i=r?i??"":void 0,r&&(a[fa]=i);const l=new gn(t,a,Cs(e||[])).toString();return l instanceof Promise?l.then(u=>hn(l,[...u.callbacks||[],Wg(t,u,a,i)])):hn(l,[Wg(t,l,a,i)])},u8=({children:t,...e})=>{const n=qf();if(n){const r=ho(n);if(r==="svg"||r==="head")return new gn("title",e,Cs(t??[]))}return Is("title",t,e,!1)},d8=({children:t,...e})=>{const n=qf();return["src","async"].some(r=>!e[r])||n&&ho(n)==="head"?zs("script",t,e):Is("script",t,e,!1)},p8=({children:t,...e})=>["href","precedence"].every(n=>n in e)?(e["data-href"]=e.href,delete e.href,Is("style",t,e,!0)):zs("style",t,e),f8=({children:t,...e})=>["onLoad","onError"].some(n=>n in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?zs("link",t,e):Is("link",t,e,"precedence"in e),h8=({children:t,...e})=>{const n=qf();return n&&ho(n)==="head"?zs("meta",t,e):Is("meta",t,e,!1)},Ny=(t,{children:e,...n})=>new gn(t,n,Cs(e??[])),g8=t=>(typeof t.action=="function"&&(t.action=bc in t.action?t.action[bc]:void 0),Ny("form",t)),Cy=(t,e)=>(typeof e.formAction=="function"&&(e.formAction=bc in e.formAction?e.formAction[bc]:void 0),Ny(t,e)),m8=t=>Cy("input",t),_8=t=>Cy("button",t);const pu=Object.freeze(Object.defineProperty({__proto__:null,button:_8,form:g8,input:m8,link:f8,meta:h8,script:d8,style:p8,title:u8},Symbol.toStringTag,{value:"Module"}));var y8=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),$c=t=>y8.get(t)||t,zy=(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)}},es=void 0,qf=()=>es,w8=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,v8=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],b8=["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"],Vf=(t,e)=>{for(let n=0,r=t.length;n<r;n++){const i=t[n];if(typeof i=="string")wr(i,e);else{if(typeof i=="boolean"||i===null||i===void 0)continue;i instanceof gn?i.toStringToBuffer(e):typeof i=="number"||i.isEscaped?e[0]+=i:i instanceof Promise?e.unshift("",i):Vf(i,e)}}},gn=class{constructor(t,e,n){be(this,"tag");be(this,"props");be(this,"key");be(this,"children");be(this,"isEscaped",!0);be(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?Z1(hn(t[0],t.callbacks)).toString():t[0]:Y1(t,t.callbacks)}toStringToBuffer(t){const e=this.tag,n=this.props;let{children:r}=this;t[0]+=`<${e}`;const i=es&&ho(es)==="svg"?s=>w8($c(s)):s=>$c(s);for(let[s,a]of Object.entries(n))if(s=i(s),s!=="children"){if(s==="style"&&typeof a=="object"){let l="";zy(a,(u,d)=>{d!=null&&(l+=`${l?";":""}${u}:${d}`)}),t[0]+=' style="',wr(l,t),t[0]+='"'}else if(typeof a=="string")t[0]+=` ${s}="`,wr(a,t),t[0]+='"';else if(a!=null)if(typeof a=="number"||a.isEscaped)t[0]+=` ${s}="${a}"`;else if(typeof a=="boolean"&&b8.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=[hn(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}="`,wr(a.toString(),t),t[0]+='"'}if(v8.includes(e)&&r.length===0){t[0]+="/>";return}t[0]+=">",Vf(r,t),t[0]+=`</${e}>`}},fu=class extends gn{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(Ki.length===0)t.unshift("",n);else{const r=Ki.map(i=>[i,i.values.at(-1)]);t.unshift("",n.then(i=>(i instanceof gn&&(i.localContexts=r),i)))}else n instanceof gn?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?(t[0]+=n,n.callbacks&&(t.callbacks||(t.callbacks=[]),t.callbacks.push(...n.callbacks))):wr(n,t)}},Iy=class extends gn{toStringToBuffer(t){Vf(this.children,t)}},$8=(t,e,...n)=>{e??(e={}),n.length&&(e.children=n.length===1?n[0]:n);const r=e.key;delete e.key;const i=ha(t,e,n);return i.key=r,i},Xg=!1,ha=(t,e,n)=>{if(!Xg){for(const r in lp)pu[r][Mf]=lp[r];Xg=!0}return typeof t=="function"?new fu(t,e,n):pu[t]?new fu(pu[t],e,n):t==="svg"||t==="head"?(es||(es=ky("")),new gn(t,e,[new fu(es,{value:t},n)])):new gn(t,e,n)},Hf=({children:t})=>new Iy("",{children:t},Array.isArray(t)?t:t?[t]:[]),x8=(t,e,...n)=>{let r;if(n.length>0)r=n;else{const i=t.props.children;r=Array.isArray(i)?i:[i]}return $8(t.tag,{...t.props,...e},...r)};function _(t,e,n){let r;if(!e||!("children"in e))r=ha(t,e,[]);else{const i=e.children;r=Array.isArray(i)?ha(t,e,i):ha(t,e,[i])}return r.key=n,r}async function Ue(t,e,n=!1){var p;const{env:r}=t,i=await r.data.loginSessions.get(t.var.tenant_id||"",e);if(!i)throw new E(400,{message:"Login session not found"});t.set("loginSession",i);const s=await fo(r,i.authParams.client_id);t.set("client_id",s.client_id),t.set("tenant_id",s.tenant.id);const a=await r.data.tenants.get(s.tenant.id);if(a){if(i.session_id&&!n){if(!i.authParams.redirect_uri)throw new E(400,{message:"Login session closed and no redirect URI available"});const h=new URL(i.authParams.redirect_uri);throw h.searchParams.set("error","access_denied"),h.searchParams.set("error_description","Login session closed"),i.authParams.state&&h.searchParams.set("state",i.authParams.state),new oi(h.toString(),302)}}else throw new E(400,{message:"Tenant not found"});const l=await r.data.themes.get(a.id,"default"),u=await r.data.branding.get(a.id),d=(p=i.authParams.ui_locales)==null?void 0:p.split(" ").map(h=>h.split("-")[0]).find(h=>{if(Array.isArray(P.options.supportedLngs))return P.options.supportedLngs.includes(h)});return await P.changeLanguage(d||a.language||"sv"),{theme:l,branding:u,client:s,tenant:a,loginSession:i}}async function si(t,e){const{theme:n,branding:r,client:i,tenant:s,loginSession:a}=await Ue(t,e,!0),l=Di(i.tenant.id,t.req.header("cookie")),u=l?await t.env.data.sessions.get(i.tenant.id,l):null;if(!u||!a.session_id)throw new oi(`/u/login/identifier?state=${encodeURIComponent(e)}`);const d=await t.env.data.sessions.get(i.tenant.id,a.session_id),p=await t.env.data.users.get(i.tenant.id,u.user_id);if(!p||(d==null?void 0:d.user_id)!==u.user_id)throw new oi(`/u/login/identifier?state=${encodeURIComponent(e)}`);return{theme:n,branding:r,client:i,user:p,tenant:s,loginSession:a,session:d}}async function A8(t,e,n,r){if(r!==void 0)return r==="password";const i=await Op({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}const Ty=({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?_("div",{className:"flex h-9 items-center",children:_("img",{src:n,className:"max-h-full",alt:"Logo"})}):_(Hf,{})},Oy=t=>{var e,n;return _("div",{className:"mt-8",children:((n=(e=t.client)==null?void 0:e.client_metadata)==null?void 0:n.termsAndConditionsUrl)&&_("div",{className:"text-xs text-gray-300",children:[P.t("agree_to")," ",_("a",{href:t.client.client_metadata.termsAndConditionsUrl,className:"text-primary hover:underline",target:"_blank",rel:"noreferrer",children:P.t("terms")})]})})};var Dy={exports:{}};/*!
|
|
198
198
|
Copyright (c) 2018 Jed Watson.
|
|
199
199
|
Licensed under the MIT License (MIT), see
|
|
200
200
|
http://jedwatson.github.io/classnames
|
|
@@ -227,7 +227,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
227
227
|
<\/script>
|
|
228
228
|
`])))]})},bn=({children:t,className:e})=>_("div",{className:yn("mb-2 text-sm text-red",e),children:t}),T8=t=>t==="small"?"text-base":t==="medium"?"text-2xl":t==="large"?"text-3xl":"",Ry=({size:t})=>{const e=T8(t);return _("div",{className:"relative inline-block leading-[0]",children:[_(Ve,{className:yn("text-gray-200 dark:text-[#201a41]",{[e]:e}),name:"spinner-circle"}),_(Ve,{className:yn("absolute inset-0 animate-spin text-primary",{[e]:e}),name:"spinner-inner"})]})},Xe=({children:t,className:e,Component:n="button",variant:r="primary",href:i,disabled:s,isLoading:a,id:l})=>{const u=n==="a"?{href:i}:{};return _(n,{class:yn("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:l,...u,children:[_("span",{className:"btn-label flex items-center justify-center space-x-2",children:t}),_("div",{className:"btn-spinner absolute left-0 top-0 flex h-full w-full items-center justify-center",children:_(Ry,{size:"medium"})})]})},Ao=({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 _(Xe,{className:yn("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||"",_("div",{className:yn("text-left text-black dark:text-white sm:text-base",{"hidden sm:inline short:hidden":r}),children:e})]})},jy=({...t})=>_("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",...t,children:[_("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"}),_("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"}),_("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"}),_("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"})]}),$n=({children:t,className:e})=>_("form",{id:"form",method:"post",className:e,children:t}),Py=({...t})=>_("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:[_("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"}),_("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
|
|
229
229
|
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
|
|
230
|
-
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`})]}),ga=({error:t,theme:e,branding:n,loginSession:r,email:i,client:s})=>{const a=s.connections.map(({strategy:q})=>q),l=a.includes("email")||a.includes("Username-Password-Authentication"),u=a.includes("sms"),d=a.includes("facebook"),p=a.includes("google-oauth2"),h=a.includes("apple"),g=a.includes("vipps"),$=d||p||h||g,A=l||u;let z="text",T="username";const O=l&&u?"email_or_phone_placeholder":l?"email_placeholder":"phone_placeholder";let x=P.t(O,l&&u?"Email or Phone Number":l?"Email Address":"Phone Number");return _(Je,{title:P.t("welcome"),theme:e,branding:n,client:s,children:[_("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:P.t("welcome")}),_("div",{className:"mb-8 text-gray-300",children:P.t("login_description_template",{authMethod:P.t(O,{defaultValue:l&&u?"email or phone number":l?"email address":"phone number"}).toLocaleLowerCase(),defaultValue:"Sign in with your {{authMethod}}"})}),_("div",{className:"flex flex-1 flex-col justify-center",children:[A&&_($n,{className:"mb-7",children:[_("input",{type:z,name:T,placeholder:x,className:yn("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&&_(bn,{children:t}),_(Xe,{className:"sm:mt-4 !text-base",children:[_("span",{children:P.t("continue")}),_(Ve,{className:"text-xs",name:"arrow-right"})]})]}),A&&$&&_("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[_("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),_("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:P.t("continue_social_login")})]}),_("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&&_(Ao,{connection:"facebook",text:P.t("continue_with",{provider:"Facebook"}),canResize:!0,icon:_(Ve,{className:"text-xl text-[#1196F5] sm:absolute sm:left-4 sm:top-1/2 sm:-translate-y-1/2 sm:text-2xl short:static short:left-auto short:top-auto short:translate-y-0 short:text-xl",name:"facebook"}),loginSession:r}),p&&_(Ao,{connection:"google-oauth2",text:P.t("continue_with",{provider:"Google"}),canResize:!0,icon:_(jy,{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}),h&&_(Ao,{connection:"apple",text:P.t("continue_with",{provider:"Apple"}),canResize:!0,icon:_(Ve,{className:"text-xl text-black dark:text-white sm:absolute sm:left-4 sm:top-1/2 sm:-translate-y-1/2 sm:text-2xl short:static short:left-auto short:top-auto short:translate-y-0 short:text-xl",name:"apple"}),loginSession:r}),g&&_(Ao,{connection:"vipps",text:P.t("continue_with",{provider:"Vipps"}),canResize:!0,icon:_(Py,{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})]})]})]})},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"}),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}=await Ue(t,e);return t.html(_(ga,{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"})}),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=>{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:l}=await Ue(t,n);t.set("client_id",i.client_id);const u=t.get("countryCode"),{normalized:d,connectionType:p}=Bl(r.username,u);if(!i.connections.find(T=>T.strategy===p)||!d)return t.html(_(ga,{theme:a,branding:l,loginSession:s,error:P.t("invalid_identifier"),email:r.username,client:i}),400);const h=await Po({userAdapter:e.data.users,tenant_id:i.tenant.id,username:d,provider:p});if(h&&t.set("user_id",h.user_id),!h)try{await j3(t,i,t.env.data,d)}catch{const T=Me(t,{type:Le.FAILED_SIGNUP,description:"Public signup is disabled"});return ln(t,t.env.data.logs.create(i.tenant.id,T)),t.html(_(ga,{theme:a,branding:l,loginSession:s,error:P.t("user_account_does_not_exist"),email:r.username,client:i}),400)}if(s.authParams.username=d,await e.data.loginSessions.update(i.tenant.id,s.id,s),await A8(t,i,r.username,r.login_selection))return t.redirect(`/u/enter-password?state=${n}`);let g=Ar(),$=await e.data.codes.get(i.tenant.id,g,"otp");for(;$;)g=Ar(),$=await e.data.codes.get(i.tenant.id,g,"otp");const A=await t.env.data.codes.create(i.tenant.id,{code_id:g,code_type:"otp",login_id:s.id,expires_at:new Date(Date.now()+ia).toISOString(),redirect_uri:s.authParams.redirect_uri}),z=i.connections.find(T=>T.strategy===p);if(!z)throw new E(400,{message:P.t("connection_not_found",{connection:p})});return p==="email"&&z.options.authentication_method==="magic_link"?await Lf(t,{to:d,code:A.code_id,authParams:s.authParams}):await Bf(t,{to:d,code:A.code_id}),t.redirect(`/u/enter-code?state=${n}`)}),Qt=t=>_("a",{className:"block text-primary hover:text-primaryHover text-center",href:`/u/login/identifier?state=${t.state}`,children:P.t("go_back")});var ts="_hp",D8={Change:"Input",DoubleClick:"DblClick"},R8={svg:"2000/svg",math:"1998/Math/MathML"},ns=[],up=new WeakMap,Gi=void 0,j8=()=>Gi,Mn=t=>"t"in t,hu={onClick:["click",!1]},Zg=t=>{if(!t.startsWith("on"))return;if(hu[t])return hu[t];const e=t.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);if(e){const[,n,r]=e;return hu[t]=[(D8[n]||n).toLowerCase(),!!r]}},Qg=(t,e)=>Gi&&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,P8=(t,e,n)=>{var r;e||(e={});for(let i in e){const s=e[i];if(i!=="children"&&(!n||n[i]!==s)){i=$c(i);const a=Zg(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 l;typeof s=="function"?l=s(t)||(()=>s(null)):s&&"current"in s&&(s.current=t,l=()=>s.current=null),up.set(t,l)}else if(i==="style"){const l=t.style;typeof s=="string"?l.cssText=s:(l.cssText="",s!=null&&zy(s,l.setProperty.bind(l)))}else{if(i==="value"){const u=t.nodeName;if(u==="INPUT"||u==="TEXTAREA"||u==="SELECT"){if(t.value=s==null||s===!1?null:s,u==="TEXTAREA"){t.textContent=s;continue}else if(u==="SELECT"){t.selectedIndex===-1&&(t.selectedIndex=0);continue}}}else(i==="checked"&&t.nodeName==="INPUT"||i==="selected"&&t.nodeName==="OPTION")&&(t[i]=s);const l=Qg(t,i);s==null||s===!1?t.removeAttribute(l):s===!0?t.setAttribute(l,""):typeof s=="string"||typeof s=="number"?t.setAttribute(l,s):t.setAttribute(l,s.toString())}}}if(n)for(let i in n){const s=n[i];if(i!=="children"&&!(i in e)){i=$c(i);const a=Zg(i);a?t.removeEventListener(a[0],s,a[1]):i==="ref"?(r=up.get(t))==null||r():t.removeAttribute(Qg(t,i))}}},B8=(t,e)=>{e[We][0]=0,ns.push([t,e]);const n=e.tag[Mf]||e.tag,r=n.defaultProps?{...n.defaultProps,...e.props}:e.props;try{return[n.call(null,r)]}finally{ns.pop()}},By=(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[We][1][My])==null||a.forEach(l=>i.push(l))),t.vC.forEach(l=>{var u;if(Mn(l))n.push(l);else if(typeof l.tag=="function"||l.tag===""){l.c=e;const d=n.length;if(By(l,e,n,r,i),l.s){for(let p=d;p<n.length;p++)n[p].s=!0;l.s=!1}}else n.push(l),(u=l.vR)!=null&&u.length&&(r.push(...l.vR),delete l.vR)})},L8=t=>{for(;;t=t.tag===ts||!t.vC||!t.pP?t.nN:t.vC[0]){if(!t)return null;if(t.tag!==ts&&t.e)return t.e}},Ly=t=>{var e,n,r,i,s,a;Mn(t)||((n=(e=t[We])==null?void 0:e[1][My])==null||n.forEach(l=>{var u;return(u=l[2])==null?void 0:u.call(l)}),(r=up.get(t.e))==null||r(),t.p===2&&((i=t.vC)==null||i.forEach(l=>l.p=2)),(s=t.vC)==null||s.forEach(Ly)),t.p||((a=t.e)==null||a.remove(),delete t.e),typeof t.tag=="function"&&(Eo.delete(t),ma.delete(t),delete t[We][3],t.a=!0)},Fy=(t,e,n)=>{t.c=e,Uy(t,e,n)},em=(t,e)=>{if(e){for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return n}},tm=Symbol(),Uy=(t,e,n)=>{var d;const r=[],i=[],s=[];By(t,e,r,i,s),i.forEach(Ly);const a=n?void 0:e.childNodes;let l,u=null;if(n)l=-1;else if(!a.length)l=0;else{const p=em(a,L8(t.nN));p!==void 0?(u=a[p],l=p):l=em(a,(d=r.find(h=>h.tag!==ts&&h.e))==null?void 0:d.e)??-1,l===-1&&(n=!0)}for(let p=0,h=r.length;p<h;p++,l++){const g=r[p];let $;if(g.s&&g.e)$=g.e,g.s=!1;else{const A=n||!g.e;Mn(g)?(g.e&&g.d&&(g.e.textContent=g.t),g.d=!1,$=g.e||(g.e=document.createTextNode(g.t))):($=g.e||(g.e=g.n?document.createElementNS(g.n,g.tag):document.createElement(g.tag)),P8($,g.props,g.pP),Uy(g,$,A))}g.tag===ts?l--:n?$.parentNode||e.appendChild($):a[l]!==$&&a[l-1]!==$&&(a[l+1]===$?e.appendChild(a[l]):e.insertBefore($,u||a[l]||null))}if(t.pP&&delete t.pP,s.length){const p=[],h=[];s.forEach(([,g,,$,A])=>{g&&p.push(g),$&&h.push($),A==null||A()}),p.forEach(g=>g()),h.length&&requestAnimationFrame(()=>{h.forEach(g=>g())})}},F8=(t,e)=>!!(t&&t.length===e.length&&t.every((n,r)=>n[1]===e[r][1])),ma=new WeakMap,dp=(t,e,n)=>{var s,a,l,u,d,p;const r=!n&&e.pC;n&&(e.pC||(e.pC=e.vC));let i;try{n||(n=typeof e.tag=="function"?B8(t,e):Cs(e.props.children)),((s=n[0])==null?void 0:s.tag)===""&&n[0][cp]&&(i=n[0][cp],t[5].push([t,i,e]));const h=r?[...e.pC]:e.vC?[...e.vC]:void 0,g=[];let $;for(let A=0;A<n.length;A++){Array.isArray(n[A])&&n.splice(A,1,...n[A].flat());let z=U8(n[A]);if(z){typeof z.tag=="function"&&!z.tag[Ay]&&(Ki.length>0&&(z[We][2]=Ki.map(O=>[O,O.values.at(-1)])),(a=t[5])!=null&&a.length&&(z[We][3]=t[5].at(-1)));let T;if(h&&h.length){const O=h.findIndex(Mn(z)?x=>Mn(x):z.key!==void 0?x=>x.key===z.key&&x.tag===z.tag:x=>x.tag===z.tag);O!==-1&&(T=h[O],h.splice(O,1))}if(T)if(Mn(z))T.t!==z.t&&(T.t=z.t,T.d=!0),z=T;else{const O=T.pP=T.props;if(T.props=z.props,T.f||(T.f=z.f||e.f),typeof z.tag=="function"){const x=T[We][2];T[We][2]=z[We][2]||[],T[We][3]=z[We][3],!T.f&&((T.o||T)===z.o||(u=(l=T.tag)[l8])!=null&&u.call(l,O,T.props))&&F8(x,T[We][2])&&(T.s=!0)}z=T}else if(!Mn(z)&&Gi){const O=ho(Gi);O&&(z.n=O)}if(!Mn(z)&&!z.s&&(dp(t,z),delete z.f),g.push(z),$&&!$.s&&!z.s)for(let O=$;O&&!Mn(O);O=(d=O.vC)==null?void 0:d.at(-1))O.nN=z;$=z}}e.vR=r?[...e.vC,...h||[]]:h||[],e.vC=g,r&&delete e.pC}catch(h){if(e.f=!0,h===tm){if(i)return;throw h}const[g,$,A]=((p=e[We])==null?void 0:p[3])||[];if($){const z=()=>_a([0,!1,t[2]],A),T=ma.get(A)||[];T.push(z),ma.set(A,T);const O=$(h,()=>{const x=ma.get(A);if(x){const U=x.indexOf(z);if(U!==-1)return x.splice(U,1),z()}});if(O){if(t[0]===1)t[1]=!0;else if(dp(t,A,[O]),($.length===1||t!==g)&&A.c){Fy(A,A.c,!1);return}throw tm}}throw h}finally{i&&t[5].pop()}},U8=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[We]=[0,[]];else{const e=R8[t.tag];e&&(Gi||(Gi=Sy("")),t.props.children=[{tag:Gi,props:{value:t.n=`http://www.w3.org/${e}`,children:t.props.children}}])}return t}},nm=(t,e)=>{var n,r;(n=e[We][2])==null||n.forEach(([i,s])=>{i.values.push(s)});try{dp(t,e,void 0)}catch{return}if(e.a){delete e.a;return}(r=e[We][2])==null||r.forEach(([i])=>{i.values.pop()}),(t[0]!==1||!t[1])&&Fy(e,e.c,!1)},Eo=new WeakMap,rm=[],_a=async(t,e)=>{t[5]||(t[5]=[]);const n=Eo.get(e);n&&n[0](void 0);let r;const i=new Promise(s=>r=s);if(Eo.set(e,[r,()=>{t[2]?t[2](t,e,s=>{nm(s,e)}).then(()=>r(e)):(nm(t,e),r(e))}]),rm.length)rm.at(-1).add(e);else{await Promise.resolve();const s=Eo.get(e);s&&(Eo.delete(e),s[1]())}return i},M8=(t,e,n)=>({tag:ts,props:{children:t},key:n,e,p:1}),gu=0,My=1,mu=2,_u=3,yu=new WeakMap,qy=(t,e)=>!t||!e||t.length!==e.length||e.some((n,r)=>n!==t[r]),q8=void 0,im=[],V8=t=>{var a;const e=()=>typeof t=="function"?t():t,n=ns.at(-1);if(!n)return[e(),()=>{}];const[,r]=n,i=(a=r[We][1])[gu]||(a[gu]=[]),s=r[We][0]++;return i[s]||(i[s]=[e(),l=>{const u=q8,d=i[s];if(typeof l=="function"&&(l=l(d[0])),!Object.is(l,d[0]))if(d[0]=l,im.length){const[p,h]=im.at(-1);Promise.all([p===3?r:_a([p,!1,u],r),h]).then(([g])=>{if(!g||!(p===2||p===3))return;const $=g.vC;requestAnimationFrame(()=>{setTimeout(()=>{$===g.vC&&_a([p===3?1:0,!1,u],g)})})})}else _a([0,!1,u],r)}])},Kf=(t,e)=>{var l;const n=ns.at(-1);if(!n)return t;const[,r]=n,i=(l=r[We][1])[mu]||(l[mu]=[]),s=r[We][0]++,a=i[s];return qy(a==null?void 0:a[1],e)?i[s]=[t,e]:t=i[s][0],t},H8=t=>{const e=yu.get(t);if(e){if(e.length===2)throw e[1];return e[0]}throw t.then(n=>yu.set(t,[n]),n=>yu.set(t,[void 0,n])),t},K8=(t,e)=>{var l;const n=ns.at(-1);if(!n)return t();const[,r]=n,i=(l=r[We][1])[_u]||(l[_u]=[]),s=r[We][0]++,a=i[s];return qy(a==null?void 0:a[1],e)&&(i[s]=[t(),e]),i[s][0]},G8=Sy({pending:!1,data:null,method:null,action:null}),om=new Set,W8=t=>{om.add(t),t.finally(()=>om.delete(t))},Gf=(t,e)=>K8(()=>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]),_i=Object.create(null),Ws=Object.create(null),Ts=(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:l,precedence:u,blocking:d,...p}=e,h=null,g=!1;const $=pa[t];let A;if($.length>0){const x=s.querySelectorAll(t);e:for(const U of x)for(const q of pa[t])if(U.getAttribute(q)===e[q]){h=U;break e}if(!h){const U=$.reduce((q,F)=>e[F]===void 0?q:`${q}-${F}-${e[F]}`,t);g=!Ws[U],h=Ws[U]||(Ws[U]=(()=>{const q=document.createElement(t);for(const F of $)e[F]!==void 0&&q.setAttribute(F,e[F]),e.rel&&q.setAttribute("rel",e.rel);return q})())}}else A=s.querySelectorAll(t);u=r?u??"":void 0,r&&(p[fa]=u);const z=Kf(x=>{if($.length>0){let U=!1;for(const q of s.querySelectorAll(t)){if(U&&q.getAttribute(fa)!==u){s.insertBefore(x,q);return}q.getAttribute(fa)===u&&(U=!0)}s.appendChild(x)}else if(A){let U=!1;for(const q of A)if(q===x){U=!0;break}U||s.insertBefore(x,s.contains(A[0])?A[0]:s.querySelector(t)),A=void 0}},[u]),T=Gf(e.ref,x=>{var F;const U=$[0];if(n===2&&(x.innerHTML=""),(g||A)&&z(x),!l&&!a)return;let q=_i[F=x.getAttribute(U)]||(_i[F]=new Promise((K,G)=>{x.addEventListener("load",K),x.addEventListener("error",G)}));a&&(q=q.then(a)),l&&(q=q.catch(l)),q.catch(()=>{})});if(i&&d==="render"){const x=pa[t][0];if(e[x]){const U=e[x],q=_i[U]||(_i[U]=new Promise((F,K)=>{z(h),h.addEventListener("load",F),h.addEventListener("error",K)}));H8(q)}}const O={tag:t,type:t,props:{...p,ref:T},ref:T};return O.p=n,h&&(O.e=h),M8(O,s)},X8=t=>{const e=j8(),n=e&&ho(e);return n!=null&&n.endsWith("svg")?{tag:"title",props:t,type:"title",ref:t.ref}:Ts("title",t,void 0,!1,!1)},J8=t=>!t||["src","async"].some(e=>!t[e])?{tag:"script",props:t,type:"script",ref:t.ref}:Ts("script",t,1,!1,!0),Y8=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,Ts("style",t,2,!0,!0)),Z8=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}:Ts("link",t,1,"precedence"in t,!0),Q8=t=>Ts("meta",t,void 0,!1,!1),Vy=Symbol(),e6=t=>{const{action:e,...n}=t;typeof e!="function"&&(n.action=e);const[r,i]=V8([null,!1]),s=Kf(async d=>{const p=d.isTrusted?e:d.detail[Vy];if(typeof p!="function")return;d.preventDefault();const h=new FormData(d.target);i([h,!0]);const g=p(h);g instanceof Promise&&(W8(g),await g),i([null,!0])},[]),a=Gf(t.ref,d=>(d.addEventListener("submit",s),()=>{d.removeEventListener("submit",s)})),[l,u]=r;return r[1]=!1,{tag:G8,props:{value:{pending:l!==null,data:l,method:l?"post":null,action:l?e:null},children:{tag:"form",props:{...n,ref:a},type:"form",ref:a}},f:u}},Hy=(t,{formAction:e,...n})=>{if(typeof e=="function"){const r=Kf(i=>{i.preventDefault(),i.currentTarget.form.dispatchEvent(new CustomEvent("submit",{detail:{[Vy]:e}}))},[]);n.ref=Gf(n.ref,i=>(i.addEventListener("click",r),()=>{i.removeEventListener("click",r)}))}return{tag:t,props:n,type:t,ref:n.ref}},t6=t=>Hy("input",t),n6=t=>Hy("button",t);Object.assign(lp,{title:X8,script:J8,style:Y8,link:Z8,meta:Q8,form:e6,input:t6,button:n6});ky(null);new TextEncoder;const Wi=t=>{const{i18nKey:e,values:n,components:r}=t,i=P.t(e,n),s=/<(\d+)>(.*?)<\/\d+>/g,a=[];let l=0,u;for(;(u=s.exec(i))!==null;){const[,d,p]=u,h=i.substring(l,u.index);h&&a.push(h);const g=parseInt(d,10);a.push(x8(r[g],{},p)),l=s.lastIndex}return l<i.length&&a.push(i.substring(l)),_(Hf,{children:a})},sm=6,pp=({error:t,theme:e,branding:n,email:r,state:i,client:s,hasPasswordLogin:a})=>{const l=new URLSearchParams({state:i}),d=s.connections.map(({name:p})=>p).includes("auth2");return _(Je,{title:P.t("verify_your_email"),theme:e,branding:n,client:s,children:[_("div",{className:"mb-4 text-2xl font-medium",children:P.t("verify_your_email")}),_("div",{className:"mb-8 text-gray-300",children:_(Wi,{i18nKey:"code_sent_template",components:[_("span",{className:"text-black dark:text-white"},"span")],values:{username:r}})}),_("div",{className:"flex flex-1 flex-col justify-center",children:[_($n,{className:"pt-2",children:[_("input",{autoFocus:!0,type:"text",pattern:"[0-9]*",maxLength:sm,inputMode:"numeric",name:"code",placeholder:"******",className:yn("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:sm,required:!0,id:"code-input"}),t&&_(bn,{children:t}),_(Xe,{className:"sm:mt-4 !text-base",children:[_("span",{children:P.t("login")}),_(Ve,{className:"text-xs",name:"arrow-right"})]}),_("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[_(Ve,{className:"text-base",name:"info-bubble"}),_("div",{className:"text-sm text-gray-300 md:text-sm",children:P.t("sent_code_spam")})]}),d&&_("div",{className:"text-center mb-12",children:[_("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[_("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),_("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:P.t("or")})]}),_(Xe,{Component:"a",href:`/u/${a?"enter-password":"pre-signup"}?${l.toString()}`,variant:"secondary",className:"block",children:P.t("enter_your_password_btn")})]})]}),_(Qt,{state:i})]})]})},en=t=>{const{message:e,theme:n,branding:r,client:i,pageTitle:s,state:a}=t;return _(Je,{title:"Login",theme:n,branding:r,client:i,children:[s?_("div",{className:"mb-4 text-2xl font-medium",children:s}):"",_("div",{className:"text-gray-300 mb-12",children:e}),a?_(Qt,{state:a}):""]})},r6=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state"})})},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}=t.req.valid("query");let n,r,i,s;try{if({theme:n,branding:r,loginSession:i,client:s}=await Ue(t,e),!i.authParams.username)return t.html(_(en,{theme:n,branding:r,client:s,state:e,pageTitle:P.t("error_page_title")||"Error",message:P.t("username_not_found_error")||"Username not found in session."}),400);const a=await Po({userAdapter:t.env.data.users,tenant_id:s.tenant.id,username:i.authParams.username,provider:"auth2"});return t.html(_(pp,{theme:n,branding:r,email:i.authParams.username,state:e,client:s,hasPasswordLogin:!!a}))}catch(a){return console.error("Error in GET /u/enter-code:",a),r||(r=null),n||(n=null),s||(s=null),t.html(_(en,{theme:n,branding:r,client:s,state:e,pageTitle:P.t("error_page_title")||"Error",message:P.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"})}),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 l;const{state:e}=t.req.valid("query"),{code:n}=t.req.valid("form"),{theme:r,branding:i,client:s,loginSession:a}=await Ue(t,e);if(!a.authParams.username)throw new E(400,{message:P.t("username_not_found_error")||"Username not found in session."});try{t.set("client_id",s.client_id);const u=await Df(t,{client_id:s.client_id,authParams:a.authParams,username:a.authParams.username,otp:n});if(u instanceof Response)return u;throw new E(500,{message:P.t("unexpected_error_try_again")||"An unexpected error occurred. Please try again."})}catch(u){let d;try{d=await Po({userAdapter:t.env.data.users,tenant_id:s.tenant.id,username:a.authParams.username,provider:"auth2"})}catch{d=null}return t.html(_(pp,{theme:r,branding:i,email:(l=a.authParams)==null?void 0:l.username,state:e,client:s,error:u.message,hasPasswordLogin:!!d}),400)}}),Ky=t=>{const{theme:e,branding:n,client:r,state:i}=t;return _(Je,{title:P.t("unverified_email"),theme:e,branding:n,client:r,children:[_("div",{className:"flex flex-1 flex-col justify-center",children:[_("p",{className:"mb-8 text-gray-300 text-lg",children:P.t("unverified_email")}),_("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[_(Ve,{className:"text-base",name:"info-bubble"}),_("div",{className:"text-sm text-gray-300 md:text-sm",children:P.t("sent_code_spam")})]}),_(Qt,{state:i})]}),_(Qt,{state:i})]})},i6=({width:t=22,height:e=17})=>_("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 576 512",children:_("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"})}),o6=({width:t=23,height:e=18})=>_("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512",children:_("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"})}),fp=({name:t,placeholder:e=P.t("password")})=>_("div",{className:"password-input relative mb-2",children:[_("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}),_("button",{type:"button","aria-label":P.t("show_password"),title:P.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:_(i6,{})}),_("button",{type:"button","aria-label":P.t("hide_password"),title:P.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:_(o6,{})})]});var am=Object.freeze,s6=Object.defineProperty,a6=(t,e)=>am(s6(t,"raw",{value:am(t.slice())})),cm;const ya=t=>{const{error:e,theme:n,branding:r,email:i,state:s,client:a}=t,l=new URLSearchParams({state:s});return _(Je,{title:P.t("enter_password"),theme:n,branding:r,client:a,children:[_("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:P.t("enter_password")}),_("div",{className:"mb-6 text-gray-300",children:P.t("enter_password_description")}),_("div",{className:"flex flex-1 flex-col justify-center",children:[_($n,{className:"mb-7",children:[_("input",{type:"text",name:"username",placeholder:P.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}),_(fp,{name:"password"}),e&&_(bn,{children:e}),_(Xe,{className:"sm:mt-4 !text-base",children:[_("span",{children:P.t("login")}),_(Ve,{className:"text-xs",name:"arrow-right"})]})]}),_("a",{href:`/u/forgot-password?${l.toString()}`,className:"text-primary hover:underline mb-4",children:P.t("forgot_password_link")}),_("div",{className:"text-center mb-12",children:[_("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[_("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),_("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:P.t("or")})]}),_("form",{method:"post",action:`/u/login/identifier?${l.toString()}`,children:[_("input",{type:"hidden",name:"login_selection",value:"code"}),_("input",{type:"hidden",name:"username",value:i}),_(Xe,{variant:"secondary",className:"block",children:P.t("enter_a_code_btn")})]})]}),_(Qt,{state:s})]}),Uf(cm||(cm=a6([`
|
|
230
|
+
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`})]}),ga=({error:t,theme:e,branding:n,loginSession:r,email:i,client:s})=>{const a=s.connections.map(({strategy:q})=>q),l=a.includes("email")||a.includes("Username-Password-Authentication"),u=a.includes("sms"),d=a.includes("facebook"),p=a.includes("google-oauth2"),h=a.includes("apple"),g=a.includes("vipps"),$=d||p||h||g,A=l||u;let z="text",T="username";const O=l&&u?"email_or_phone_placeholder":l?"email_placeholder":"phone_placeholder";let x=P.t(O,l&&u?"Email or Phone Number":l?"Email Address":"Phone Number");return _(Je,{title:P.t("welcome"),theme:e,branding:n,client:s,children:[_("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:P.t("welcome")}),_("div",{className:"mb-8 text-gray-300",children:P.t("login_description_template",{authMethod:P.t(O,{defaultValue:l&&u?"email or phone number":l?"email address":"phone number"}).toLocaleLowerCase(),defaultValue:"Sign in with your {{authMethod}}"})}),_("div",{className:"flex flex-1 flex-col justify-center",children:[A&&_($n,{className:"mb-7",children:[_("input",{type:z,name:T,placeholder:x,className:yn("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&&_(bn,{children:t}),_(Xe,{className:"sm:mt-4 !text-base",children:[_("span",{children:P.t("continue")}),_(Ve,{className:"text-xs",name:"arrow-right"})]})]}),A&&$&&_("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[_("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),_("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:P.t("continue_social_login")})]}),_("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&&_(Ao,{connection:"facebook",text:P.t("continue_with",{provider:"Facebook"}),canResize:!0,icon:_(Ve,{className:"text-xl text-[#1196F5] sm:absolute sm:left-4 sm:top-1/2 sm:-translate-y-1/2 sm:text-2xl short:static short:left-auto short:top-auto short:translate-y-0 short:text-xl",name:"facebook"}),loginSession:r}),p&&_(Ao,{connection:"google-oauth2",text:P.t("continue_with",{provider:"Google"}),canResize:!0,icon:_(jy,{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}),h&&_(Ao,{connection:"apple",text:P.t("continue_with",{provider:"Apple"}),canResize:!0,icon:_(Ve,{className:"text-xl text-black dark:text-white sm:absolute sm:left-4 sm:top-1/2 sm:-translate-y-1/2 sm:text-2xl short:static short:left-auto short:top-auto short:translate-y-0 short:text-xl",name:"apple"}),loginSession:r}),g&&_(Ao,{connection:"vipps",text:P.t("continue_with",{provider:"Vipps"}),canResize:!0,icon:_(Py,{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})]})]})]})},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"}),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}=await Ue(t,e);return t.html(_(ga,{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"})}),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=>{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:l}=await Ue(t,n);t.set("client_id",i.client_id);const u=t.get("countryCode"),{normalized:d,connectionType:p}=Bl(r.username,u);if(!i.connections.find(T=>T.strategy===p)||!d)return t.html(_(ga,{theme:a,branding:l,loginSession:s,error:P.t("invalid_identifier"),email:r.username,client:i}),400);const h=await Po({userAdapter:e.data.users,tenant_id:i.tenant.id,username:d,provider:p});if(h&&t.set("user_id",h.user_id),!h)try{await j3(t,i,t.env.data,d)}catch{const T=Me(t,{type:Le.FAILED_SIGNUP,description:"Public signup is disabled"});return ln(t,t.env.data.logs.create(i.tenant.id,T)),t.html(_(ga,{theme:a,branding:l,loginSession:s,error:P.t("user_account_does_not_exist"),email:r.username,client:i}),400)}if(s.authParams.username=d,await e.data.loginSessions.update(i.tenant.id,s.id,s),await A8(t,i,r.username,r.login_selection))return t.redirect(`/u/enter-password?state=${n}`);let g=Ar(),$=await e.data.codes.get(i.tenant.id,g,"otp");for(;$;)g=Ar(),$=await e.data.codes.get(i.tenant.id,g,"otp");const A=await t.env.data.codes.create(i.tenant.id,{code_id:g,code_type:"otp",login_id:s.id,expires_at:new Date(Date.now()+ia).toISOString(),redirect_uri:s.authParams.redirect_uri}),z=i.connections.find(T=>T.strategy===p);if(!z)throw new E(400,{message:P.t("connection_not_found",{connection:p})});return p==="email"&&z.options.authentication_method==="magic_link"?await Lf(t,{to:d,code:A.code_id,authParams:s.authParams}):await Bf(t,{to:d,code:A.code_id}),t.redirect(`/u/enter-code?state=${n}`)}),Qt=t=>_("a",{className:"block text-primary hover:text-primaryHover text-center",href:`/u/login/identifier?state=${t.state}`,children:P.t("go_back")});var ts="_hp",D8={Change:"Input",DoubleClick:"DblClick"},R8={svg:"2000/svg",math:"1998/Math/MathML"},ns=[],up=new WeakMap,Gi=void 0,j8=()=>Gi,Mn=t=>"t"in t,hu={onClick:["click",!1]},Zg=t=>{if(!t.startsWith("on"))return;if(hu[t])return hu[t];const e=t.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);if(e){const[,n,r]=e;return hu[t]=[(D8[n]||n).toLowerCase(),!!r]}},Qg=(t,e)=>Gi&&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,P8=(t,e,n)=>{var r;e||(e={});for(let i in e){const s=e[i];if(i!=="children"&&(!n||n[i]!==s)){i=$c(i);const a=Zg(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 l;typeof s=="function"?l=s(t)||(()=>s(null)):s&&"current"in s&&(s.current=t,l=()=>s.current=null),up.set(t,l)}else if(i==="style"){const l=t.style;typeof s=="string"?l.cssText=s:(l.cssText="",s!=null&&zy(s,l.setProperty.bind(l)))}else{if(i==="value"){const u=t.nodeName;if(u==="INPUT"||u==="TEXTAREA"||u==="SELECT"){if(t.value=s==null||s===!1?null:s,u==="TEXTAREA"){t.textContent=s;continue}else if(u==="SELECT"){t.selectedIndex===-1&&(t.selectedIndex=0);continue}}}else(i==="checked"&&t.nodeName==="INPUT"||i==="selected"&&t.nodeName==="OPTION")&&(t[i]=s);const l=Qg(t,i);s==null||s===!1?t.removeAttribute(l):s===!0?t.setAttribute(l,""):typeof s=="string"||typeof s=="number"?t.setAttribute(l,s):t.setAttribute(l,s.toString())}}}if(n)for(let i in n){const s=n[i];if(i!=="children"&&!(i in e)){i=$c(i);const a=Zg(i);a?t.removeEventListener(a[0],s,a[1]):i==="ref"?(r=up.get(t))==null||r():t.removeAttribute(Qg(t,i))}}},B8=(t,e)=>{e[We][0]=0,ns.push([t,e]);const n=e.tag[Mf]||e.tag,r=n.defaultProps?{...n.defaultProps,...e.props}:e.props;try{return[n.call(null,r)]}finally{ns.pop()}},By=(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[We][1][My])==null||a.forEach(l=>i.push(l))),t.vC.forEach(l=>{var u;if(Mn(l))n.push(l);else if(typeof l.tag=="function"||l.tag===""){l.c=e;const d=n.length;if(By(l,e,n,r,i),l.s){for(let p=d;p<n.length;p++)n[p].s=!0;l.s=!1}}else n.push(l),(u=l.vR)!=null&&u.length&&(r.push(...l.vR),delete l.vR)})},L8=t=>{for(;;t=t.tag===ts||!t.vC||!t.pP?t.nN:t.vC[0]){if(!t)return null;if(t.tag!==ts&&t.e)return t.e}},Ly=t=>{var e,n,r,i,s,a;Mn(t)||((n=(e=t[We])==null?void 0:e[1][My])==null||n.forEach(l=>{var u;return(u=l[2])==null?void 0:u.call(l)}),(r=up.get(t.e))==null||r(),t.p===2&&((i=t.vC)==null||i.forEach(l=>l.p=2)),(s=t.vC)==null||s.forEach(Ly)),t.p||((a=t.e)==null||a.remove(),delete t.e),typeof t.tag=="function"&&(Eo.delete(t),ma.delete(t),delete t[We][3],t.a=!0)},Fy=(t,e,n)=>{t.c=e,Uy(t,e,n)},em=(t,e)=>{if(e){for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return n}},tm=Symbol(),Uy=(t,e,n)=>{var d;const r=[],i=[],s=[];By(t,e,r,i,s),i.forEach(Ly);const a=n?void 0:e.childNodes;let l,u=null;if(n)l=-1;else if(!a.length)l=0;else{const p=em(a,L8(t.nN));p!==void 0?(u=a[p],l=p):l=em(a,(d=r.find(h=>h.tag!==ts&&h.e))==null?void 0:d.e)??-1,l===-1&&(n=!0)}for(let p=0,h=r.length;p<h;p++,l++){const g=r[p];let $;if(g.s&&g.e)$=g.e,g.s=!1;else{const A=n||!g.e;Mn(g)?(g.e&&g.d&&(g.e.textContent=g.t),g.d=!1,$=g.e||(g.e=document.createTextNode(g.t))):($=g.e||(g.e=g.n?document.createElementNS(g.n,g.tag):document.createElement(g.tag)),P8($,g.props,g.pP),Uy(g,$,A))}g.tag===ts?l--:n?$.parentNode||e.appendChild($):a[l]!==$&&a[l-1]!==$&&(a[l+1]===$?e.appendChild(a[l]):e.insertBefore($,u||a[l]||null))}if(t.pP&&delete t.pP,s.length){const p=[],h=[];s.forEach(([,g,,$,A])=>{g&&p.push(g),$&&h.push($),A==null||A()}),p.forEach(g=>g()),h.length&&requestAnimationFrame(()=>{h.forEach(g=>g())})}},F8=(t,e)=>!!(t&&t.length===e.length&&t.every((n,r)=>n[1]===e[r][1])),ma=new WeakMap,dp=(t,e,n)=>{var s,a,l,u,d,p;const r=!n&&e.pC;n&&(e.pC||(e.pC=e.vC));let i;try{n||(n=typeof e.tag=="function"?B8(t,e):Cs(e.props.children)),((s=n[0])==null?void 0:s.tag)===""&&n[0][cp]&&(i=n[0][cp],t[5].push([t,i,e]));const h=r?[...e.pC]:e.vC?[...e.vC]:void 0,g=[];let $;for(let A=0;A<n.length;A++){Array.isArray(n[A])&&n.splice(A,1,...n[A].flat());let z=U8(n[A]);if(z){typeof z.tag=="function"&&!z.tag[Ay]&&(Ki.length>0&&(z[We][2]=Ki.map(O=>[O,O.values.at(-1)])),(a=t[5])!=null&&a.length&&(z[We][3]=t[5].at(-1)));let T;if(h&&h.length){const O=h.findIndex(Mn(z)?x=>Mn(x):z.key!==void 0?x=>x.key===z.key&&x.tag===z.tag:x=>x.tag===z.tag);O!==-1&&(T=h[O],h.splice(O,1))}if(T)if(Mn(z))T.t!==z.t&&(T.t=z.t,T.d=!0),z=T;else{const O=T.pP=T.props;if(T.props=z.props,T.f||(T.f=z.f||e.f),typeof z.tag=="function"){const x=T[We][2];T[We][2]=z[We][2]||[],T[We][3]=z[We][3],!T.f&&((T.o||T)===z.o||(u=(l=T.tag)[l8])!=null&&u.call(l,O,T.props))&&F8(x,T[We][2])&&(T.s=!0)}z=T}else if(!Mn(z)&&Gi){const O=ho(Gi);O&&(z.n=O)}if(!Mn(z)&&!z.s&&(dp(t,z),delete z.f),g.push(z),$&&!$.s&&!z.s)for(let O=$;O&&!Mn(O);O=(d=O.vC)==null?void 0:d.at(-1))O.nN=z;$=z}}e.vR=r?[...e.vC,...h||[]]:h||[],e.vC=g,r&&delete e.pC}catch(h){if(e.f=!0,h===tm){if(i)return;throw h}const[g,$,A]=((p=e[We])==null?void 0:p[3])||[];if($){const z=()=>_a([0,!1,t[2]],A),T=ma.get(A)||[];T.push(z),ma.set(A,T);const O=$(h,()=>{const x=ma.get(A);if(x){const U=x.indexOf(z);if(U!==-1)return x.splice(U,1),z()}});if(O){if(t[0]===1)t[1]=!0;else if(dp(t,A,[O]),($.length===1||t!==g)&&A.c){Fy(A,A.c,!1);return}throw tm}}throw h}finally{i&&t[5].pop()}},U8=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[We]=[0,[]];else{const e=R8[t.tag];e&&(Gi||(Gi=Sy("")),t.props.children=[{tag:Gi,props:{value:t.n=`http://www.w3.org/${e}`,children:t.props.children}}])}return t}},nm=(t,e)=>{var n,r;(n=e[We][2])==null||n.forEach(([i,s])=>{i.values.push(s)});try{dp(t,e,void 0)}catch{return}if(e.a){delete e.a;return}(r=e[We][2])==null||r.forEach(([i])=>{i.values.pop()}),(t[0]!==1||!t[1])&&Fy(e,e.c,!1)},Eo=new WeakMap,rm=[],_a=async(t,e)=>{t[5]||(t[5]=[]);const n=Eo.get(e);n&&n[0](void 0);let r;const i=new Promise(s=>r=s);if(Eo.set(e,[r,()=>{t[2]?t[2](t,e,s=>{nm(s,e)}).then(()=>r(e)):(nm(t,e),r(e))}]),rm.length)rm.at(-1).add(e);else{await Promise.resolve();const s=Eo.get(e);s&&(Eo.delete(e),s[1]())}return i},M8=(t,e,n)=>({tag:ts,props:{children:t},key:n,e,p:1}),gu=0,My=1,mu=2,_u=3,yu=new WeakMap,qy=(t,e)=>!t||!e||t.length!==e.length||e.some((n,r)=>n!==t[r]),q8=void 0,im=[],V8=t=>{var a;const e=()=>typeof t=="function"?t():t,n=ns.at(-1);if(!n)return[e(),()=>{}];const[,r]=n,i=(a=r[We][1])[gu]||(a[gu]=[]),s=r[We][0]++;return i[s]||(i[s]=[e(),l=>{const u=q8,d=i[s];if(typeof l=="function"&&(l=l(d[0])),!Object.is(l,d[0]))if(d[0]=l,im.length){const[p,h]=im.at(-1);Promise.all([p===3?r:_a([p,!1,u],r),h]).then(([g])=>{if(!g||!(p===2||p===3))return;const $=g.vC;requestAnimationFrame(()=>{setTimeout(()=>{$===g.vC&&_a([p===3?1:0,!1,u],g)})})})}else _a([0,!1,u],r)}])},Kf=(t,e)=>{var l;const n=ns.at(-1);if(!n)return t;const[,r]=n,i=(l=r[We][1])[mu]||(l[mu]=[]),s=r[We][0]++,a=i[s];return qy(a==null?void 0:a[1],e)?i[s]=[t,e]:t=i[s][0],t},H8=t=>{const e=yu.get(t);if(e){if(e.length===2)throw e[1];return e[0]}throw t.then(n=>yu.set(t,[n]),n=>yu.set(t,[void 0,n])),t},K8=(t,e)=>{var l;const n=ns.at(-1);if(!n)return t();const[,r]=n,i=(l=r[We][1])[_u]||(l[_u]=[]),s=r[We][0]++,a=i[s];return qy(a==null?void 0:a[1],e)&&(i[s]=[t(),e]),i[s][0]},G8=Sy({pending:!1,data:null,method:null,action:null}),om=new Set,W8=t=>{om.add(t),t.finally(()=>om.delete(t))},Gf=(t,e)=>K8(()=>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]),_i=Object.create(null),Ws=Object.create(null),Ts=(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:l,precedence:u,blocking:d,...p}=e,h=null,g=!1;const $=pa[t];let A;if($.length>0){const x=s.querySelectorAll(t);e:for(const U of x)for(const q of pa[t])if(U.getAttribute(q)===e[q]){h=U;break e}if(!h){const U=$.reduce((q,F)=>e[F]===void 0?q:`${q}-${F}-${e[F]}`,t);g=!Ws[U],h=Ws[U]||(Ws[U]=(()=>{const q=document.createElement(t);for(const F of $)e[F]!==void 0&&q.setAttribute(F,e[F]),e.rel&&q.setAttribute("rel",e.rel);return q})())}}else A=s.querySelectorAll(t);u=r?u??"":void 0,r&&(p[fa]=u);const z=Kf(x=>{if($.length>0){let U=!1;for(const q of s.querySelectorAll(t)){if(U&&q.getAttribute(fa)!==u){s.insertBefore(x,q);return}q.getAttribute(fa)===u&&(U=!0)}s.appendChild(x)}else if(A){let U=!1;for(const q of A)if(q===x){U=!0;break}U||s.insertBefore(x,s.contains(A[0])?A[0]:s.querySelector(t)),A=void 0}},[u]),T=Gf(e.ref,x=>{var F;const U=$[0];if(n===2&&(x.innerHTML=""),(g||A)&&z(x),!l&&!a)return;let q=_i[F=x.getAttribute(U)]||(_i[F]=new Promise((H,G)=>{x.addEventListener("load",H),x.addEventListener("error",G)}));a&&(q=q.then(a)),l&&(q=q.catch(l)),q.catch(()=>{})});if(i&&d==="render"){const x=pa[t][0];if(e[x]){const U=e[x],q=_i[U]||(_i[U]=new Promise((F,H)=>{z(h),h.addEventListener("load",F),h.addEventListener("error",H)}));H8(q)}}const O={tag:t,type:t,props:{...p,ref:T},ref:T};return O.p=n,h&&(O.e=h),M8(O,s)},X8=t=>{const e=j8(),n=e&&ho(e);return n!=null&&n.endsWith("svg")?{tag:"title",props:t,type:"title",ref:t.ref}:Ts("title",t,void 0,!1,!1)},J8=t=>!t||["src","async"].some(e=>!t[e])?{tag:"script",props:t,type:"script",ref:t.ref}:Ts("script",t,1,!1,!0),Y8=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,Ts("style",t,2,!0,!0)),Z8=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}:Ts("link",t,1,"precedence"in t,!0),Q8=t=>Ts("meta",t,void 0,!1,!1),Vy=Symbol(),e6=t=>{const{action:e,...n}=t;typeof e!="function"&&(n.action=e);const[r,i]=V8([null,!1]),s=Kf(async d=>{const p=d.isTrusted?e:d.detail[Vy];if(typeof p!="function")return;d.preventDefault();const h=new FormData(d.target);i([h,!0]);const g=p(h);g instanceof Promise&&(W8(g),await g),i([null,!0])},[]),a=Gf(t.ref,d=>(d.addEventListener("submit",s),()=>{d.removeEventListener("submit",s)})),[l,u]=r;return r[1]=!1,{tag:G8,props:{value:{pending:l!==null,data:l,method:l?"post":null,action:l?e:null},children:{tag:"form",props:{...n,ref:a},type:"form",ref:a}},f:u}},Hy=(t,{formAction:e,...n})=>{if(typeof e=="function"){const r=Kf(i=>{i.preventDefault(),i.currentTarget.form.dispatchEvent(new CustomEvent("submit",{detail:{[Vy]:e}}))},[]);n.ref=Gf(n.ref,i=>(i.addEventListener("click",r),()=>{i.removeEventListener("click",r)}))}return{tag:t,props:n,type:t,ref:n.ref}},t6=t=>Hy("input",t),n6=t=>Hy("button",t);Object.assign(lp,{title:X8,script:J8,style:Y8,link:Z8,meta:Q8,form:e6,input:t6,button:n6});ky(null);new TextEncoder;const Wi=t=>{const{i18nKey:e,values:n,components:r}=t,i=P.t(e,n),s=/<(\d+)>(.*?)<\/\d+>/g,a=[];let l=0,u;for(;(u=s.exec(i))!==null;){const[,d,p]=u,h=i.substring(l,u.index);h&&a.push(h);const g=parseInt(d,10);a.push(x8(r[g],{},p)),l=s.lastIndex}return l<i.length&&a.push(i.substring(l)),_(Hf,{children:a})},sm=6,pp=({error:t,theme:e,branding:n,email:r,state:i,client:s,hasPasswordLogin:a})=>{const l=new URLSearchParams({state:i}),d=s.connections.map(({name:p})=>p).includes("auth2");return _(Je,{title:P.t("verify_your_email"),theme:e,branding:n,client:s,children:[_("div",{className:"mb-4 text-2xl font-medium",children:P.t("verify_your_email")}),_("div",{className:"mb-8 text-gray-300",children:_(Wi,{i18nKey:"code_sent_template",components:[_("span",{className:"text-black dark:text-white"},"span")],values:{username:r}})}),_("div",{className:"flex flex-1 flex-col justify-center",children:[_($n,{className:"pt-2",children:[_("input",{autoFocus:!0,type:"text",pattern:"[0-9]*",maxLength:sm,inputMode:"numeric",name:"code",placeholder:"******",className:yn("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:sm,required:!0,id:"code-input"}),t&&_(bn,{children:t}),_(Xe,{className:"sm:mt-4 !text-base",children:[_("span",{children:P.t("login")}),_(Ve,{className:"text-xs",name:"arrow-right"})]}),_("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[_(Ve,{className:"text-base",name:"info-bubble"}),_("div",{className:"text-sm text-gray-300 md:text-sm",children:P.t("sent_code_spam")})]}),d&&_("div",{className:"text-center mb-12",children:[_("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[_("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),_("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:P.t("or")})]}),_(Xe,{Component:"a",href:`/u/${a?"enter-password":"pre-signup"}?${l.toString()}`,variant:"secondary",className:"block",children:P.t("enter_your_password_btn")})]})]}),_(Qt,{state:i})]})]})},en=t=>{const{message:e,theme:n,branding:r,client:i,pageTitle:s,state:a}=t;return _(Je,{title:"Login",theme:n,branding:r,client:i,children:[s?_("div",{className:"mb-4 text-2xl font-medium",children:s}):"",_("div",{className:"text-gray-300 mb-12",children:e}),a?_(Qt,{state:a}):""]})},r6=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state"})})},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}=t.req.valid("query");let n,r,i,s;try{if({theme:n,branding:r,loginSession:i,client:s}=await Ue(t,e),!i.authParams.username)return t.html(_(en,{theme:n,branding:r,client:s,state:e,pageTitle:P.t("error_page_title")||"Error",message:P.t("username_not_found_error")||"Username not found in session."}),400);const a=await Po({userAdapter:t.env.data.users,tenant_id:s.tenant.id,username:i.authParams.username,provider:"auth2"});return t.html(_(pp,{theme:n,branding:r,email:i.authParams.username,state:e,client:s,hasPasswordLogin:!!a}))}catch(a){return console.error("Error in GET /u/enter-code:",a),r||(r=null),n||(n=null),s||(s=null),t.html(_(en,{theme:n,branding:r,client:s,state:e,pageTitle:P.t("error_page_title")||"Error",message:P.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"})}),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 l;const{state:e}=t.req.valid("query"),{code:n}=t.req.valid("form"),{theme:r,branding:i,client:s,loginSession:a}=await Ue(t,e);if(!a.authParams.username)throw new E(400,{message:P.t("username_not_found_error")||"Username not found in session."});try{t.set("client_id",s.client_id);const u=await Df(t,{client_id:s.client_id,authParams:a.authParams,username:a.authParams.username,otp:n});if(u instanceof Response)return u;throw new E(500,{message:P.t("unexpected_error_try_again")||"An unexpected error occurred. Please try again."})}catch(u){let d;try{d=await Po({userAdapter:t.env.data.users,tenant_id:s.tenant.id,username:a.authParams.username,provider:"auth2"})}catch{d=null}return t.html(_(pp,{theme:r,branding:i,email:(l=a.authParams)==null?void 0:l.username,state:e,client:s,error:u.message,hasPasswordLogin:!!d}),400)}}),Ky=t=>{const{theme:e,branding:n,client:r,state:i}=t;return _(Je,{title:P.t("unverified_email"),theme:e,branding:n,client:r,children:[_("div",{className:"flex flex-1 flex-col justify-center",children:[_("p",{className:"mb-8 text-gray-300 text-lg",children:P.t("unverified_email")}),_("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[_(Ve,{className:"text-base",name:"info-bubble"}),_("div",{className:"text-sm text-gray-300 md:text-sm",children:P.t("sent_code_spam")})]}),_(Qt,{state:i})]}),_(Qt,{state:i})]})},i6=({width:t=22,height:e=17})=>_("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 576 512",children:_("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"})}),o6=({width:t=23,height:e=18})=>_("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512",children:_("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"})}),fp=({name:t,placeholder:e=P.t("password")})=>_("div",{className:"password-input relative mb-2",children:[_("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}),_("button",{type:"button","aria-label":P.t("show_password"),title:P.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:_(i6,{})}),_("button",{type:"button","aria-label":P.t("hide_password"),title:P.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:_(o6,{})})]});var am=Object.freeze,s6=Object.defineProperty,a6=(t,e)=>am(s6(t,"raw",{value:am(t.slice())})),cm;const ya=t=>{const{error:e,theme:n,branding:r,email:i,state:s,client:a}=t,l=new URLSearchParams({state:s});return _(Je,{title:P.t("enter_password"),theme:n,branding:r,client:a,children:[_("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:P.t("enter_password")}),_("div",{className:"mb-6 text-gray-300",children:P.t("enter_password_description")}),_("div",{className:"flex flex-1 flex-col justify-center",children:[_($n,{className:"mb-7",children:[_("input",{type:"text",name:"username",placeholder:P.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}),_(fp,{name:"password"}),e&&_(bn,{children:e}),_(Xe,{className:"sm:mt-4 !text-base",children:[_("span",{children:P.t("login")}),_(Ve,{className:"text-xs",name:"arrow-right"})]})]}),_("a",{href:`/u/forgot-password?${l.toString()}`,className:"text-primary hover:underline mb-4",children:P.t("forgot_password_link")}),_("div",{className:"text-center mb-12",children:[_("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[_("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),_("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:P.t("or")})]}),_("form",{method:"post",action:`/u/login/identifier?${l.toString()}`,children:[_("input",{type:"hidden",name:"login_selection",value:"code"}),_("input",{type:"hidden",name:"username",value:i}),_(Xe,{variant:"secondary",className:"block",children:P.t("enter_a_code_btn")})]})]}),_(Qt,{state:s})]}),Uf(cm||(cm=a6([`
|
|
231
231
|
<script>
|
|
232
232
|
// Show password toggle
|
|
233
233
|
var passwordInputs = document.querySelectorAll(".password-input");
|
|
@@ -281,21 +281,21 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
281
281
|
}
|
|
282
282
|
});
|
|
283
283
|
<\/script>
|
|
284
|
-
`])))]})},T6=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}=await Ue(t,e,!0);if(!s.session_id)throw new E(400,{message:"No session linked to login session"});const a=await t.env.data.sessions.get(i.tenant.id,s.session_id);if(!a)throw new E(400,{message:"Session not found"});const l=await t.env.data.users.get(i.tenant.id,a.user_id);if(!l)throw new E(400,{message:"User not found"});return(await t.env.data.userPermissions.list(i.tenant.id,l.user_id)).some(p=>p.permission_name==="users:impersonate")?t.html(_(hm,{theme:n,branding:r,client:i,user:l,state:e})):t.html(_(en,{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 Ue(t,e,!0);if(!r.session_id)throw new E(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 E(400,{message:"Session not found"});const s=await t.env.data.users.get(n.tenant.id,i.user_id);if(!s)throw new E(400,{message:"User not found"});if(!(await t.env.data.userPermissions.list(n.tenant.id,s.user_id)).some(u=>u.permission_name==="users:impersonate"))throw new E(403,{message:"Access denied: insufficient permissions"});return Dn(t,{client:n,authParams:r.authParams,loginSession:r,user:s,sessionId:i.id})}).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}=await Ue(t,e,!0);if(!a.session_id)throw new E(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 E(400,{message:"Current session not found"});const u=await t.env.data.users.get(s.tenant.id,l.user_id);if(!u)throw new E(400,{message:"Current user not found"});if(!(await t.env.data.userPermissions.list(s.tenant.id,u.user_id)).some(g=>g.permission_name==="users:impersonate"))return t.html(_(en,{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);return h?(await t.env.data.sessions.update(s.tenant.id,l.id,{user_id:h.user_id}),Dn(t,{client:s,authParams:a.authParams,loginSession:a,user:h,sessionId:l.id})):t.html(_(hm,{theme:r,branding:i,client:s,user:u,state:e,error:`User with ID "${n}" not found.`}),400)});function O6(t){const e=new o.OpenAPIHono,n=t.dataAdapter.cache||ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),r=t.dataAdapter.cache?300:0;e.onError((s,a)=>s instanceof oi?a.redirect(s.location,s.status):s instanceof E?a.text(s.message||"Error",s.status):a.text("Unexpected error",500)),e.get("/css/tailwind.css",async s=>{const a=Wf;return s.text(a,200,{"content-type":"text/css; charset=utf-8"})}),e.use(async(s,a)=>{const l=as(s,t.dataAdapter),u=Dl(l,{defaultTtl:r,cacheEntities:["tenants","connections","clients","legacyClients","customDomains","resourceServers","roles","organizations","userRoles","userPermissions","branding","themes","promptSettings","forms"],cache:n});return s.env.data=zl(s,u),a()}).use(Ol).use(Tl);const i=e.route("/info",b6).route("/check-account",p6).route("/account",g6).route("/account/change-email",m6).route("/account/change-email-verify",_6).route("/account/change-email-confirmation",y6).route("/login/identifier",O8).route("/enter-code",r6).route("/enter-password",c6).route("/invalid-session",v6).route("/pre-signup",w6).route("/pre-signup-sent",x6).route("/reset-password",u6).route("/forgot-password",d6).route("/validate-email",$6).route("/signup",l6).route("/impersonate",T6).route("/forms",C6);return i.doc("/u/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Universal login"}}),i}const Wt=o.z.object({"#text":o.z.string()}),D6=o.z.object({"#text":o.z.string(),"@_xmlns:saml":o.z.string().optional()}),R6=o.z.object({"samlp:AuthnRequest":o.z.object({"saml:Issuer":D6,"@_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(Wt)}))})),":@":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(Wt)}),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 j6=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(),"@_Name":o.z.string().optional(),"@_NameFormat":o.z.string().optional()})}),P6=o.z.object({"ds:Transform":o.z.array(o.z.any()),":@":o.z.object({"@_Algorithm":o.z.string()})}),gm=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.string()),":@":o.z.object({"@_Algorithm":o.z.string()})}),o.z.object({"ds:SignatureMethod":o.z.array(o.z.string()),":@":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(P6)}),o.z.object({"ds:DigestMethod":o.z.array(o.z.string()),":@":o.z.object({"@_Algorithm":o.z.string()})}),o.z.object({"ds:DigestValue":o.z.array(Wt)})]))})]))}),o.z.object({"ds:SignatureValue":o.z.array(Wt)}),o.z.object({"ds:KeyInfo":o.z.array(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(Wt)}),o.z.object({"ds:Exponent":o.z.array(Wt)})]))}))}))})])),":@":o.z.object({"@_xmlns:ds":o.z.string()})});o.z.array(o.z.object({"samlp:Response":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(Wt)}),gm,o.z.object({"samlp:Status":o.z.array(o.z.object({"samlp:StatusCode":o.z.array(Wt),":@":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(Wt)}),gm,o.z.object({"saml:Subject":o.z.array(o.z.union([o.z.object({"saml:NameID":o.z.array(Wt),":@":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(Wt)}))})),":@":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(Wt)}))})),":@":o.z.object({"@_AuthnInstant":o.z.string(),"@_SessionIndex":o.z.string(),"@_SessionNotOnOrAfter":o.z.string()})}),o.z.object({"saml:AttributeStatement":o.z.array(o.z.object({"saml:Attribute":o.z.array(j6),":@":o.z.object({"@_FriendlyName":o.z.string().optional(),"@_Name":o.z.string(),"@_NameFormat":o.z.string()})}))})])),":@":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 B6={},ai={},Os={},Ll={};(function(t){var e=t;(function(n){function r(c){var f=Array.prototype.slice,y=c.length,b=function(S,W){return function(){return W.apply(this,S.concat(f.call(arguments)))}},v=function(){var S=f.call(arguments);return S.length<y?b(S,v):c.apply(this,f.apply(arguments,[0,y]))};return v}var i=function(c,f){for(var y=0;y<f.length;y+=1)c(f[y],y,f)},s=function(c,f,y){var b=f;return i(function(v,S){b=c(b,v,S)},y),b},a=function(c,f){var y=new Array(f.length);return i(function(b,v){y[v]=c(b)},f),y},l=function(c,f){var y=[];return i(function(b,v){c(b,v)&&y.push(b)},f),y},u=function(c,f){for(var y=0;y<c.length;y+=1)if(c[y]===f)return!0;return!1};function d(c){return function(){return c}}function p(c){return c.toString()}var h=function(c,f){return f.join(c)},g=function(c,f,y){return c+y+f},$=Array.prototype.concat,A=32767;function z(c){for(var f=[],y=0;y<c.length;y+=A){var b=c.slice(y,y+A);f=$.apply(f,b)}return f}function T(c,f){for(var y=Object(c),b=1;b<arguments.length;b++){var v=arguments[b];if(v!=null)for(var S in v)Object.prototype.hasOwnProperty.call(v,S)&&(y[S]=v[S])}return y}var O={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11};x.prototype=new Object,x.prototype.constructor=x,x.superclass=Object.prototype;function x(){this.init()}x.prototype.init=function(){this.reduceActions=[],this.reduceActions[3]=function(c){return new J(c[0],c[2])},this.reduceActions[5]=function(c){return new Ae(c[0],c[2])},this.reduceActions[7]=function(c){return new R(c[0],c[2])},this.reduceActions[8]=function(c){return new L(c[0],c[2])},this.reduceActions[10]=function(c){return new j(c[0],c[2])},this.reduceActions[11]=function(c){return new N(c[0],c[2])},this.reduceActions[12]=function(c){return new k(c[0],c[2])},this.reduceActions[13]=function(c){return new B(c[0],c[2])},this.reduceActions[15]=function(c){return new H(c[0],c[2])},this.reduceActions[16]=function(c){return new de(c[0],c[2])},this.reduceActions[18]=function(c){return new ie(c[0],c[2])},this.reduceActions[19]=function(c){return new ve(c[0],c[2])},this.reduceActions[20]=function(c){return new ke(c[0],c[2])},this.reduceActions[22]=function(c){return new G(c[1])},this.reduceActions[24]=function(c){return new Q(c[0],c[2])},this.reduceActions[25]=function(c){return new ye(void 0,void 0,c[0])},this.reduceActions[27]=function(c){return c[0].locationPath=c[2],c[0]},this.reduceActions[28]=function(c){return c[0].locationPath=c[2],c[0].locationPath.steps.unshift(new ee(ee.DESCENDANTORSELF,se.nodeTest,[])),c[0]},this.reduceActions[29]=function(c){return new ye(c[0],[],void 0)},this.reduceActions[30]=function(c){return ce.instance_of(c[0],ye)?(c[0].filterPredicates==null&&(c[0].filterPredicates=[]),c[0].filterPredicates.push(c[1]),c[0]):new ye(c[0],[c[1]],void 0)},this.reduceActions[32]=function(c){return c[1]},this.reduceActions[33]=function(c){return new he(c[0])},this.reduceActions[34]=function(c){return new ge(c[0])},this.reduceActions[36]=function(c){return new Rt(c[0],[])},this.reduceActions[37]=function(c){return new Rt(c[0],c[2])},this.reduceActions[38]=function(c){return[c[0]]},this.reduceActions[39]=function(c){return c[2].unshift(c[0]),c[2]},this.reduceActions[43]=function(c){return new nn(!0,[])},this.reduceActions[44]=function(c){return c[1].absolute=!0,c[1]},this.reduceActions[46]=function(c){return new nn(!1,[c[0]])},this.reduceActions[47]=function(c){return c[0].steps.push(c[2]),c[0]},this.reduceActions[49]=function(c){return new ee(c[0],c[1],[])},this.reduceActions[50]=function(c){return new ee(ee.CHILD,c[0],[])},this.reduceActions[51]=function(c){return new ee(c[0],c[1],c[2])},this.reduceActions[52]=function(c){return new ee(ee.CHILD,c[0],c[1])},this.reduceActions[54]=function(c){return[c[0]]},this.reduceActions[55]=function(c){return c[1].unshift(c[0]),c[1]},this.reduceActions[56]=function(c){return c[0]=="ancestor"?ee.ANCESTOR:c[0]=="ancestor-or-self"?ee.ANCESTORORSELF:c[0]=="attribute"?ee.ATTRIBUTE:c[0]=="child"?ee.CHILD:c[0]=="descendant"?ee.DESCENDANT:c[0]=="descendant-or-self"?ee.DESCENDANTORSELF:c[0]=="following"?ee.FOLLOWING:c[0]=="following-sibling"?ee.FOLLOWINGSIBLING:c[0]=="namespace"?ee.NAMESPACE:c[0]=="parent"?ee.PARENT:c[0]=="preceding"?ee.PRECEDING:c[0]=="preceding-sibling"?ee.PRECEDINGSIBLING:c[0]=="self"?ee.SELF:-1},this.reduceActions[57]=function(c){return ee.ATTRIBUTE},this.reduceActions[59]=function(c){return c[0]=="comment"?se.commentTest:c[0]=="text"?se.textTest:c[0]=="processing-instruction"?se.anyPiTest:c[0]=="node"?se.nodeTest:new se(-1,void 0)},this.reduceActions[60]=function(c){return new se.PITest(c[2])},this.reduceActions[61]=function(c){return c[1]},this.reduceActions[63]=function(c){return c[1].absolute=!0,c[1].steps.unshift(new ee(ee.DESCENDANTORSELF,se.nodeTest,[])),c[1]},this.reduceActions[64]=function(c){return c[0].steps.push(new ee(ee.DESCENDANTORSELF,se.nodeTest,[])),c[0].steps.push(c[2]),c[0]},this.reduceActions[65]=function(c){return new ee(ee.SELF,se.nodeTest,[])},this.reduceActions[66]=function(c){return new ee(ee.PARENT,se.nodeTest,[])},this.reduceActions[67]=function(c){return new tt(c[1])},this.reduceActions[68]=function(c){return se.nameTestAny},this.reduceActions[69]=function(c){return new se.NameTestPrefixAny(c[0].split(":")[0])},this.reduceActions[70]=function(c){return new se.NameTestQName(c[0])}},x.actionTable=[" s s sssssssss s ss s ss"," s ","r rrrrrrrrr rrrrrrr rr r "," rrrrr "," s s sssssssss s ss s ss","rs rrrrrrrr s sssssrrrrrr rrs rs "," s s sssssssss s ss s ss"," s "," s ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," s "," s "," s s sssss s s ","r rrrrrrrrr rrrrrrr rr r ","a ","r s rr r ","r sr rr r ","r s rr s rr r ","r rssrr rss rr r ","r rrrrr rrrss rr r ","r rrrrrsss rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrrs rr r ","r rrrrrrrr rrrrrr rr r ","r rrrrrrrr rrrrrr rr r ","r srrrrrrrr rrrrrrs rr sr ","r srrrrrrrr rrrrrrs rr r ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrr rrrrrr rr r ","r rrrrrrrr rrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r "," sssss ","r rrrrrrrrr rrrrrrr rr sr ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," s ","r srrrrrrrr rrrrrrs rr r ","r rrrrrrrr rrrrr rr r "," s "," s "," rrrrr "," s s sssssssss s sss s ss","r srrrrrrrr rrrrrrs rr r "," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss ss s ss"," s s sssssssss s ss s ss"," s s sssss s s "," s s sssss s s ","r rrrrrrrrr rrrrrrr rr rr "," s s sssss s s "," s s sssss s s ","r rrrrrrrrr rrrrrrr rr sr ","r rrrrrrrrr rrrrrrr rr sr ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr rr "," s ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," rr "," s "," rs ","r sr rr r ","r s rr s rr r ","r rssrr rss rr r ","r rssrr rss rr r ","r rrrrr rrrss rr r ","r rrrrr rrrss rr r ","r rrrrr rrrss rr r ","r rrrrr rrrss rr r ","r rrrrrsss rrrrr rr r ","r rrrrrsss rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrrr rr r "," r "," s ","r srrrrrrrr rrrrrrs rr r ","r srrrrrrrr rrrrrrs rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," s s sssssssss s ss s ss","r rrrrrrrrr rrrrrrr rr rr "," r "],x.actionTableNumber=[` 1 0 /.-,+*)(' & %$ # "!`," J ","a aaaaaaaaa aaaaaaa aa a "," YYYYY ",` 1 0 /.-,+*)(' & %$ # "!`,`K1 KKKKKKKK . +*)('KKKKKK KK# K" `,` 1 0 /.-,+*)(' & %$ # "!`," N "," O ","e eeeeeeeee eeeeeee ee ee ","f fffffffff fffffff ff ff ","d ddddddddd ddddddd dd dd ","B BBBBBBBBB BBBBBBB BB BB ","A AAAAAAAAA AAAAAAA AA AA "," P "," Q ",` 1 . +*)(' # " `,"b bbbbbbbbb bbbbbbb bb b "," ","! S !! ! ",'" T" "" " ',"$ V $$ U $$ $ ","& &ZY&& &XW && & ",") ))))) )))\\[ )) ) ",". ....._^] ..... .. . ","1 11111111 11111 11 1 ","5 55555555 55555` 55 5 ","7 77777777 777777 77 7 ","9 99999999 999999 99 9 ",": c:::::::: ::::::b :: a: ","I fIIIIIIII IIIIIIe II I ","= ========= ======= == == ","? ????????? ??????? ?? ?? ","C CCCCCCCCC CCCCCCC CC CC ","J JJJJJJJJ JJJJJJ JJ J ","M MMMMMMMM MMMMMM MM M ","N NNNNNNNNN NNNNNNN NN N ","P PPPPPPPPP PPPPPPP PP P "," +*)(' ","R RRRRRRRRR RRRRRRR RR aR ","U UUUUUUUUU UUUUUUU UU U ","Z ZZZZZZZZZ ZZZZZZZ ZZ ZZ ","c ccccccccc ccccccc cc cc "," j ","L fLLLLLLLL LLLLLLe LL L ","6 66666666 66666 66 6 "," k "," l "," XXXXX ",` 1 0 /.-,+*)(' & %$m # "!`,"_ f________ ______e __ _ ",` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 . +*)(' # " `,` 1 . +*)(' # " `,"> >>>>>>>>> >>>>>>> >> >> ",` 1 . +*)(' # " `,` 1 . +*)(' # " `,"Q QQQQQQQQQ QQQQQQQ QQ aQ ","V VVVVVVVVV VVVVVVV VV aV ","T TTTTTTTTT TTTTTTT TT T ","@ @@@@@@@@@ @@@@@@@ @@ @@ "," ","[ [[[[[[[[[ [[[[[[[ [[ [[ ","D DDDDDDDDD DDDDDDD DD DD "," HH "," "," F ","# T# ## # ","% V %% U %% % ","' 'ZY'' 'XW '' ' ","( (ZY(( (XW (( ( ","+ +++++ +++\\[ ++ + ","* ***** ***\\[ ** * ","- ----- ---\\[ -- - ",", ,,,,, ,,,\\[ ,, , ","0 00000_^] 00000 00 0 ","/ /////_^] ///// // / ","2 22222222 22222 22 2 ","3 33333333 33333 33 3 ","4 44444444 44444 44 4 ","8 88888888 888888 88 8 "," ^ "," ","; f;;;;;;;; ;;;;;;e ;; ; ","< f<<<<<<<< <<<<<<e << < ","O OOOOOOOOO OOOOOOO OO O ","` ````````` ``````` `` ` ","S SSSSSSSSS SSSSSSS SS S ","W WWWWWWWWW WWWWWWW WW W ","\\ \\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\ \\\\ \\\\ ","E EEEEEEEEE EEEEEEE EE EE ",` 1 0 /.-,+*)(' & %$ # "!`,"] ]]]]]]]]] ]]]]]]] ]] ]] "," G "],x.gotoTable=["3456789:;<=>?@ AB CDEFGH IJ "," "," "," ","L456789:;<=>?@ AB CDEFGH IJ "," M EFGH IJ "," N;<=>?@ AB CDEFGH IJ "," "," "," "," "," "," "," "," "," "," S EFGH IJ "," "," "," "," "," "," "," "," "," "," "," "," "," e "," "," "," "," "," "," "," "," "," h J "," i j "," "," "," "," "," "," "," "," "," ","o456789:;<=>?@ ABpqCDEFGH IJ "," "," r6789:;<=>?@ AB CDEFGH IJ "," s789:;<=>?@ AB CDEFGH IJ "," t89:;<=>?@ AB CDEFGH IJ "," u89:;<=>?@ AB CDEFGH IJ "," v9:;<=>?@ AB CDEFGH IJ "," w9:;<=>?@ AB CDEFGH IJ "," x9:;<=>?@ AB CDEFGH IJ "," y9:;<=>?@ AB CDEFGH IJ "," z:;<=>?@ AB CDEFGH IJ "," {:;<=>?@ AB CDEFGH IJ "," |;<=>?@ AB CDEFGH IJ "," };<=>?@ AB CDEFGH IJ "," ~;<=>?@ AB CDEFGH IJ "," =>?@ AB CDEFGH IJ ","456789:;<=>?@ AB CDEFGH IJ"," EFGH IJ "," EFGH IJ "," "," GH IJ ","
GH IJ "," i "," i "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","o456789:;<=>?@ ABqCDEFGH IJ "," "," "],x.productions=[[1,1,2],[2,1,3],[3,1,4],[3,3,3,-9,4],[4,1,5],[4,3,4,-8,5],[5,1,6],[5,3,5,-22,6],[5,3,5,-5,6],[6,1,7],[6,3,6,-23,7],[6,3,6,-24,7],[6,3,6,-6,7],[6,3,6,-7,7],[7,1,8],[7,3,7,-25,8],[7,3,7,-26,8],[8,1,9],[8,3,8,-12,9],[8,3,8,-11,9],[8,3,8,-10,9],[9,1,10],[9,2,-26,9],[10,1,11],[10,3,10,-27,11],[11,1,12],[11,1,13],[11,3,13,-28,14],[11,3,13,-4,14],[13,1,15],[13,2,13,16],[15,1,17],[15,3,-29,2,-30],[15,1,-15],[15,1,-16],[15,1,18],[18,3,-13,-29,-30],[18,4,-13,-29,19,-30],[19,1,20],[19,3,20,-31,19],[20,1,2],[12,1,14],[12,1,21],[21,1,-28],[21,2,-28,14],[21,1,22],[14,1,23],[14,3,14,-28,23],[14,1,24],[23,2,25,26],[23,1,26],[23,3,25,26,27],[23,2,26,27],[23,1,28],[27,1,16],[27,2,16,27],[25,2,-14,-3],[25,1,-32],[26,1,29],[26,3,-20,-29,-30],[26,4,-21,-29,-15,-30],[16,3,-33,30,-34],[30,1,2],[22,2,-4,14],[24,3,14,-4,23],[28,1,-35],[28,1,-2],[17,2,-36,-18],[29,1,-17],[29,1,-19],[29,1,-18]],x.DOUBLEDOT=2,x.DOUBLECOLON=3,x.DOUBLESLASH=4,x.NOTEQUAL=5,x.LESSTHANOREQUAL=6,x.GREATERTHANOREQUAL=7,x.AND=8,x.OR=9,x.MOD=10,x.DIV=11,x.MULTIPLYOPERATOR=12,x.FUNCTIONNAME=13,x.AXISNAME=14,x.LITERAL=15,x.NUMBER=16,x.ASTERISKNAMETEST=17,x.QNAME=18,x.NCNAMECOLONASTERISK=19,x.NODETYPE=20,x.PROCESSINGINSTRUCTIONWITHLITERAL=21,x.EQUALS=22,x.LESSTHAN=23,x.GREATERTHAN=24,x.PLUS=25,x.MINUS=26,x.BAR=27,x.SLASH=28,x.LEFTPARENTHESIS=29,x.RIGHTPARENTHESIS=30,x.COMMA=31,x.AT=32,x.LEFTBRACKET=33,x.RIGHTBRACKET=34,x.DOT=35,x.DOLLAR=36,x.prototype.tokenize=function(c){for(var f=[],y=[],b=c+"\0",v=0,S=b.charAt(v++);;){for(;S==" "||S==" "||S=="\r"||S==`
|
|
285
|
-
`;)S=b.charAt(v++);if(S=="\0"||v>=b.length)break;if(S=="("){f.push(x.LEFTPARENTHESIS),y.push(S),S=b.charAt(v++);continue}if(S==")"){f.push(x.RIGHTPARENTHESIS),y.push(S),S=b.charAt(v++);continue}if(S=="["){f.push(x.LEFTBRACKET),y.push(S),S=b.charAt(v++);continue}if(S=="]"){f.push(x.RIGHTBRACKET),y.push(S),S=b.charAt(v++);continue}if(S=="@"){f.push(x.AT),y.push(S),S=b.charAt(v++);continue}if(S==","){f.push(x.COMMA),y.push(S),S=b.charAt(v++);continue}if(S=="|"){f.push(x.BAR),y.push(S),S=b.charAt(v++);continue}if(S=="+"){f.push(x.PLUS),y.push(S),S=b.charAt(v++);continue}if(S=="-"){f.push(x.MINUS),y.push(S),S=b.charAt(v++);continue}if(S=="="){f.push(x.EQUALS),y.push(S),S=b.charAt(v++);continue}if(S=="$"){f.push(x.DOLLAR),y.push(S),S=b.charAt(v++);continue}if(S=="."){if(S=b.charAt(v++),S=="."){f.push(x.DOUBLEDOT),y.push(".."),S=b.charAt(v++);continue}if(S>="0"&&S<="9"){var W="."+S;for(S=b.charAt(v++);S>="0"&&S<="9";)W+=S,S=b.charAt(v++);f.push(x.NUMBER),y.push(W);continue}f.push(x.DOT),y.push(".");continue}if(S=="'"||S=='"'){for(var _e=S,Ce="";v<b.length&&(S=b.charAt(v))!==_e;)Ce+=S,v+=1;if(S!==_e)throw Kt.fromMessage("Unterminated string literal: "+_e+Ce);v+=1,f.push(x.LITERAL),y.push(Ce),S=b.charAt(v++);continue}if(S>="0"&&S<="9"){var W=S;for(S=b.charAt(v++);S>="0"&&S<="9";)W+=S,S=b.charAt(v++);if(S=="."&&b.charAt(v)>="0"&&b.charAt(v)<="9")for(W+=S,W+=b.charAt(v++),S=b.charAt(v++);S>="0"&&S<="9";)W+=S,S=b.charAt(v++);f.push(x.NUMBER),y.push(W);continue}if(S=="*"){if(f.length>0){var oe=f[f.length-1];if(oe!=x.AT&&oe!=x.DOUBLECOLON&&oe!=x.LEFTPARENTHESIS&&oe!=x.LEFTBRACKET&&oe!=x.AND&&oe!=x.OR&&oe!=x.MOD&&oe!=x.DIV&&oe!=x.MULTIPLYOPERATOR&&oe!=x.SLASH&&oe!=x.DOUBLESLASH&&oe!=x.BAR&&oe!=x.PLUS&&oe!=x.MINUS&&oe!=x.EQUALS&&oe!=x.NOTEQUAL&&oe!=x.LESSTHAN&&oe!=x.LESSTHANOREQUAL&&oe!=x.GREATERTHAN&&oe!=x.GREATERTHANOREQUAL){f.push(x.MULTIPLYOPERATOR),y.push(S),S=b.charAt(v++);continue}}f.push(x.ASTERISKNAMETEST),y.push(S),S=b.charAt(v++);continue}if(S==":"&&b.charAt(v)==":"){f.push(x.DOUBLECOLON),y.push("::"),v++,S=b.charAt(v++);continue}if(S=="/"){if(S=b.charAt(v++),S=="/"){f.push(x.DOUBLESLASH),y.push("//"),S=b.charAt(v++);continue}f.push(x.SLASH),y.push("/");continue}if(S=="!"&&b.charAt(v)=="="){f.push(x.NOTEQUAL),y.push("!="),v++,S=b.charAt(v++);continue}if(S=="<"){if(b.charAt(v)=="="){f.push(x.LESSTHANOREQUAL),y.push("<="),v++,S=b.charAt(v++);continue}f.push(x.LESSTHAN),y.push("<"),S=b.charAt(v++);continue}if(S==">"){if(b.charAt(v)=="="){f.push(x.GREATERTHANOREQUAL),y.push(">="),v++,S=b.charAt(v++);continue}f.push(x.GREATERTHAN),y.push(">"),S=b.charAt(v++);continue}if(S=="_"||ce.isLetter(S.charCodeAt(0))){var Ee=S;for(S=b.charAt(v++);ce.isNCNameChar(S.charCodeAt(0));)Ee+=S,S=b.charAt(v++);if(f.length>0){var oe=f[f.length-1];if(oe!=x.AT&&oe!=x.DOUBLECOLON&&oe!=x.LEFTPARENTHESIS&&oe!=x.LEFTBRACKET&&oe!=x.AND&&oe!=x.OR&&oe!=x.MOD&&oe!=x.DIV&&oe!=x.MULTIPLYOPERATOR&&oe!=x.SLASH&&oe!=x.DOUBLESLASH&&oe!=x.BAR&&oe!=x.PLUS&&oe!=x.MINUS&&oe!=x.EQUALS&&oe!=x.NOTEQUAL&&oe!=x.LESSTHAN&&oe!=x.LESSTHANOREQUAL&&oe!=x.GREATERTHAN&&oe!=x.GREATERTHANOREQUAL){if(Ee=="and"){f.push(x.AND),y.push(Ee);continue}if(Ee=="or"){f.push(x.OR),y.push(Ee);continue}if(Ee=="mod"){f.push(x.MOD),y.push(Ee);continue}if(Ee=="div"){f.push(x.DIV),y.push(Ee);continue}}}if(S==":"){if(b.charAt(v)=="*"){f.push(x.NCNAMECOLONASTERISK),y.push(Ee+":*"),v++,S=b.charAt(v++);continue}if(b.charAt(v)=="_"||ce.isLetter(b.charCodeAt(v))){for(Ee+=":",S=b.charAt(v++);ce.isNCNameChar(S.charCodeAt(0));)Ee+=S,S=b.charAt(v++);if(S=="("){f.push(x.FUNCTIONNAME),y.push(Ee);continue}f.push(x.QNAME),y.push(Ee);continue}if(b.charAt(v)==":"){f.push(x.AXISNAME),y.push(Ee);continue}}if(S=="("){if(Ee=="comment"||Ee=="text"||Ee=="node"){f.push(x.NODETYPE),y.push(Ee);continue}if(Ee=="processing-instruction"){b.charAt(v)==")"?f.push(x.NODETYPE):f.push(x.PROCESSINGINSTRUCTIONWITHLITERAL),y.push(Ee);continue}f.push(x.FUNCTIONNAME),y.push(Ee);continue}f.push(x.QNAME),y.push(Ee);continue}throw new Error("Unexpected character "+S)}return f.push(1),y.push("[EOF]"),[f,y]},x.SHIFT="s",x.REDUCE="r",x.ACCEPT="a",x.prototype.parse=function(Ce){var f,y,b=this.tokenize(Ce);if(b!=null){f=b[0],y=b[1];var v=0,S=[],W=[],_e=[],Ce,oe,Ee;for(S.push(0),W.push(1),_e.push("_S"),oe=f[v],Ee=y[v++];;)switch(Ce=S[S.length-1],x.actionTable[Ce].charAt(oe-1)){case x.SHIFT:W.push(-oe),_e.push(Ee),S.push(x.actionTableNumber[Ce].charCodeAt(oe-1)-32),oe=f[v],Ee=y[v++];break;case x.REDUCE:for(var At=x.productions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32][1],Be=[],cr=0;cr<At;cr++)W.pop(),Be.unshift(_e.pop()),S.pop();var lr=S[S.length-1];W.push(x.productions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32][0]),this.reduceActions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32]==null?_e.push(Be[0]):_e.push(this.reduceActions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32](Be)),S.push(x.gotoTable[lr].charCodeAt(x.productions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32][0]-2)-33);break;case x.ACCEPT:return new U(_e.pop());default:throw new Error("XPath parse error")}}},U.prototype=new Object,U.prototype.constructor=U,U.superclass=Object.prototype;function U(c){this.expression=c}U.prototype.toString=function(){return this.expression.toString()};function q(c,f,y){f in c||(c[f]=y)}U.prototype.evaluate=function(c){return c.contextNode=c.expressionContextNode,c.contextSize=1,c.contextPosition=1,c.isHtml&&(q(c,"caseInsensitive",!0),q(c,"allowAnyNamespaceForNoPrefix",!0)),q(c,"caseInsensitive",!1),this.expression.evaluate(c)},U.XML_NAMESPACE_URI="http://www.w3.org/XML/1998/namespace",U.XMLNS_NAMESPACE_URI="http://www.w3.org/2000/xmlns/",F.prototype=new Object,F.prototype.constructor=F,F.superclass=Object.prototype;function F(){}F.prototype.init=function(){},F.prototype.toString=function(){return"<Expression>"},F.prototype.evaluate=function(c){throw new Error("Could not evaluate expression.")},K.prototype=new F,K.prototype.constructor=K,K.superclass=F.prototype;function K(c){arguments.length>0&&this.init(c)}K.prototype.init=function(c){this.rhs=c},G.prototype=new K,G.prototype.constructor=G,G.superclass=K.prototype;function G(c){arguments.length>0&&this.init(c)}G.prototype.init=function(c){G.superclass.init.call(this,c)},G.prototype.evaluate=function(c){return this.rhs.evaluate(c).number().negate()},G.prototype.toString=function(){return"-"+this.rhs.toString()},Y.prototype=new F,Y.prototype.constructor=Y,Y.superclass=F.prototype;function Y(c,f){arguments.length>0&&this.init(c,f)}Y.prototype.init=function(c,f){this.lhs=c,this.rhs=f},J.prototype=new Y,J.prototype.constructor=J,J.superclass=Y.prototype;function J(c,f){arguments.length>0&&this.init(c,f)}J.prototype.init=function(c,f){J.superclass.init.call(this,c,f)},J.prototype.toString=function(){return"("+this.lhs.toString()+" or "+this.rhs.toString()+")"},J.prototype.evaluate=function(c){var f=this.lhs.evaluate(c).bool();return f.booleanValue()?f:this.rhs.evaluate(c).bool()},Ae.prototype=new Y,Ae.prototype.constructor=Ae,Ae.superclass=Y.prototype;function Ae(c,f){arguments.length>0&&this.init(c,f)}Ae.prototype.init=function(c,f){Ae.superclass.init.call(this,c,f)},Ae.prototype.toString=function(){return"("+this.lhs.toString()+" and "+this.rhs.toString()+")"},Ae.prototype.evaluate=function(c){var f=this.lhs.evaluate(c).bool();return f.booleanValue()?this.rhs.evaluate(c).bool():f},R.prototype=new Y,R.prototype.constructor=R,R.superclass=Y.prototype;function R(c,f){arguments.length>0&&this.init(c,f)}R.prototype.init=function(c,f){R.superclass.init.call(this,c,f)},R.prototype.toString=function(){return"("+this.lhs.toString()+" = "+this.rhs.toString()+")"},R.prototype.evaluate=function(c){return this.lhs.evaluate(c).equals(this.rhs.evaluate(c))},L.prototype=new Y,L.prototype.constructor=L,L.superclass=Y.prototype;function L(c,f){arguments.length>0&&this.init(c,f)}L.prototype.init=function(c,f){L.superclass.init.call(this,c,f)},L.prototype.toString=function(){return"("+this.lhs.toString()+" != "+this.rhs.toString()+")"},L.prototype.evaluate=function(c){return this.lhs.evaluate(c).notequal(this.rhs.evaluate(c))},j.prototype=new Y,j.prototype.constructor=j,j.superclass=Y.prototype;function j(c,f){arguments.length>0&&this.init(c,f)}j.prototype.init=function(c,f){j.superclass.init.call(this,c,f)},j.prototype.evaluate=function(c){return this.lhs.evaluate(c).lessthan(this.rhs.evaluate(c))},j.prototype.toString=function(){return"("+this.lhs.toString()+" < "+this.rhs.toString()+")"},N.prototype=new Y,N.prototype.constructor=N,N.superclass=Y.prototype;function N(c,f){arguments.length>0&&this.init(c,f)}N.prototype.init=function(c,f){N.superclass.init.call(this,c,f)},N.prototype.evaluate=function(c){return this.lhs.evaluate(c).greaterthan(this.rhs.evaluate(c))},N.prototype.toString=function(){return"("+this.lhs.toString()+" > "+this.rhs.toString()+")"},k.prototype=new Y,k.prototype.constructor=k,k.superclass=Y.prototype;function k(c,f){arguments.length>0&&this.init(c,f)}k.prototype.init=function(c,f){k.superclass.init.call(this,c,f)},k.prototype.evaluate=function(c){return this.lhs.evaluate(c).lessthanorequal(this.rhs.evaluate(c))},k.prototype.toString=function(){return"("+this.lhs.toString()+" <= "+this.rhs.toString()+")"},B.prototype=new Y,B.prototype.constructor=B,B.superclass=Y.prototype;function B(c,f){arguments.length>0&&this.init(c,f)}B.prototype.init=function(c,f){B.superclass.init.call(this,c,f)},B.prototype.evaluate=function(c){return this.lhs.evaluate(c).greaterthanorequal(this.rhs.evaluate(c))},B.prototype.toString=function(){return"("+this.lhs.toString()+" >= "+this.rhs.toString()+")"},H.prototype=new Y,H.prototype.constructor=H,H.superclass=Y.prototype;function H(c,f){arguments.length>0&&this.init(c,f)}H.prototype.init=function(c,f){H.superclass.init.call(this,c,f)},H.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().plus(this.rhs.evaluate(c).number())},H.prototype.toString=function(){return"("+this.lhs.toString()+" + "+this.rhs.toString()+")"},de.prototype=new Y,de.prototype.constructor=de,de.superclass=Y.prototype;function de(c,f){arguments.length>0&&this.init(c,f)}de.prototype.init=function(c,f){de.superclass.init.call(this,c,f)},de.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().minus(this.rhs.evaluate(c).number())},de.prototype.toString=function(){return"("+this.lhs.toString()+" - "+this.rhs.toString()+")"},ie.prototype=new Y,ie.prototype.constructor=ie,ie.superclass=Y.prototype;function ie(c,f){arguments.length>0&&this.init(c,f)}ie.prototype.init=function(c,f){ie.superclass.init.call(this,c,f)},ie.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().multiply(this.rhs.evaluate(c).number())},ie.prototype.toString=function(){return"("+this.lhs.toString()+" * "+this.rhs.toString()+")"},ve.prototype=new Y,ve.prototype.constructor=ve,ve.superclass=Y.prototype;function ve(c,f){arguments.length>0&&this.init(c,f)}ve.prototype.init=function(c,f){ve.superclass.init.call(this,c,f)},ve.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().div(this.rhs.evaluate(c).number())},ve.prototype.toString=function(){return"("+this.lhs.toString()+" div "+this.rhs.toString()+")"},ke.prototype=new Y,ke.prototype.constructor=ke,ke.superclass=Y.prototype;function ke(c,f){arguments.length>0&&this.init(c,f)}ke.prototype.init=function(c,f){ke.superclass.init.call(this,c,f)},ke.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().mod(this.rhs.evaluate(c).number())},ke.prototype.toString=function(){return"("+this.lhs.toString()+" mod "+this.rhs.toString()+")"},Q.prototype=new Y,Q.prototype.constructor=Q,Q.superclass=Y.prototype;function Q(c,f){arguments.length>0&&this.init(c,f)}Q.prototype.init=function(c,f){Q.superclass.init.call(this,c,f)},Q.prototype.evaluate=function(c){return this.lhs.evaluate(c).nodeset().union(this.rhs.evaluate(c).nodeset())},Q.prototype.toString=function(){return a(p,[this.lhs,this.rhs]).join(" | ")},ye.prototype=new F,ye.prototype.constructor=ye,ye.superclass=F.prototype;function ye(c,f,y){arguments.length>0&&this.init(c,f,y)}ye.prototype.init=function(c,f,y){ye.superclass.init.call(this),this.filter=c,this.filterPredicates=f,this.locationPath=y};function Fn(c){for(;c&&c.parentNode;)c=c.parentNode;return c}ye.applyPredicates=function(c,f,y){if(c.length===0)return y;var b=f.extend({});return s(function(v,S){return b.contextSize=v.length,l(function(W,_e){return b.contextNode=W,b.contextPosition=_e+1,ye.predicateMatches(S,b)},v)},y,c)},ye.getRoot=function(c,f){var y=f[0];if(y.nodeType===O.DOCUMENT_NODE)return y;if(c.virtualRoot)return c.virtualRoot;var b=y.ownerDocument;if(b)return b;for(var v=y;v.parentNode!=null;)v=v.parentNode;return v},ye.applyStep=function(c,f,y){var b=[];switch(f.contextNode=y,c.axis){case ee.ANCESTOR:if(f.contextNode===f.virtualRoot)break;var v;for(f.contextNode.nodeType==O.ATTRIBUTE_NODE?v=ye.getOwnerElement(f.contextNode):v=f.contextNode.parentNode;v!=null&&(c.nodeTest.matches(v,f)&&b.push(v),v!==f.virtualRoot);)v=v.parentNode;break;case ee.ANCESTORORSELF:for(var v=f.contextNode;v!=null&&(c.nodeTest.matches(v,f)&&b.push(v),v!==f.virtualRoot);v=v.nodeType==O.ATTRIBUTE_NODE?ye.getOwnerElement(v):v.parentNode);break;case ee.ATTRIBUTE:var S=f.contextNode.attributes;if(S!=null)for(var W=0;W<S.length;W++){var v=S.item(W);c.nodeTest.matches(v,f)&&b.push(v)}break;case ee.CHILD:for(var v=f.contextNode.firstChild;v!=null;v=v.nextSibling)c.nodeTest.matches(v,f)&&b.push(v);break;case ee.DESCENDANT:for(var Be=[f.contextNode.firstChild];Be.length>0;)for(var v=Be.pop();v!=null;)c.nodeTest.matches(v,f)&&b.push(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling;break;case ee.DESCENDANTORSELF:c.nodeTest.matches(f.contextNode,f)&&b.push(f.contextNode);for(var Be=[f.contextNode.firstChild];Be.length>0;)for(var v=Be.pop();v!=null;)c.nodeTest.matches(v,f)&&b.push(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling;break;case ee.FOLLOWING:if(f.contextNode===f.virtualRoot)break;var Be=[];f.contextNode.firstChild!=null?Be.unshift(f.contextNode.firstChild):Be.unshift(f.contextNode.nextSibling);for(var v=f.contextNode.parentNode;v!=null&&v.nodeType!=O.DOCUMENT_NODE&&v!==f.virtualRoot;v=v.parentNode)Be.unshift(v.nextSibling);do for(var v=Be.pop();v!=null;)c.nodeTest.matches(v,f)&&b.push(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling;while(Be.length>0);break;case ee.FOLLOWINGSIBLING:if(f.contextNode===f.virtualRoot)break;for(var v=f.contextNode.nextSibling;v!=null;v=v.nextSibling)c.nodeTest.matches(v,f)&&b.push(v);break;case ee.NAMESPACE:var _e={};if(f.contextNode.nodeType==O.ELEMENT_NODE){_e.xml=U.XML_NAMESPACE_URI,_e.xmlns=U.XMLNS_NAMESPACE_URI;for(var v=f.contextNode;v!=null&&v.nodeType==O.ELEMENT_NODE;v=v.parentNode)for(var W=0;W<v.attributes.length;W++){var Ce=v.attributes.item(W),oe=String(Ce.name);if(oe=="xmlns")_e[""]==null&&(_e[""]=Ce.value);else if(oe.length>6&&oe.substring(0,6)=="xmlns:"){var Ee=oe.substring(6,oe.length);_e[Ee]==null&&(_e[Ee]=Ce.value)}}for(var Ee in _e){var At=new jt(Ee,_e[Ee],f.contextNode);c.nodeTest.matches(At,f)&&b.push(At)}}break;case ee.PARENT:v=null,f.contextNode!==f.virtualRoot&&(f.contextNode.nodeType==O.ATTRIBUTE_NODE?v=ye.getOwnerElement(f.contextNode):v=f.contextNode.parentNode),v!=null&&c.nodeTest.matches(v,f)&&b.push(v);break;case ee.PRECEDING:var Be;f.virtualRoot!=null?Be=[f.virtualRoot]:Be=[Fn(f.contextNode)];e:for(;Be.length>0;)for(var v=Be.pop();v!=null;){if(v==f.contextNode)break e;c.nodeTest.matches(v,f)&&b.unshift(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling}break;case ee.PRECEDINGSIBLING:if(f.contextNode===f.virtualRoot)break;for(var v=f.contextNode.previousSibling;v!=null;v=v.previousSibling)c.nodeTest.matches(v,f)&&b.push(v);break;case ee.SELF:c.nodeTest.matches(f.contextNode,f)&&b.push(f.contextNode);break}return b};function Pe(c,f,y){return ye.applyPredicates(c.predicates,f,ye.applyStep(c,f,y))}function Ge(c,f,y){return z(a(Pe.bind(null,y,c),f))}ye.applySteps=function(c,f,y){return s(Ge.bind(null,f),y,c)},ye.prototype.applyFilter=function(c,f){if(!this.filter)return{nodes:[c.contextNode]};var y=this.filter.evaluate(c);if(!ce.instance_of(y,ae)){if(this.filterPredicates!=null&&this.filterPredicates.length>0||this.locationPath!=null)throw new Error("Path expression filter must evaluate to a nodeset if predicates or location path are used");return{nonNodes:y}}return{nodes:ye.applyPredicates(this.filterPredicates||[],f,y.toUnsortedArray())}},ye.applyLocationPath=function(c,f,y){if(!c)return y;var b=c.absolute?[ye.getRoot(f,y)]:y;return ye.applySteps(c.steps,f,b)},ye.prototype.evaluate=function(c){var f=T(new Ht,c),y=this.applyFilter(c,f);if("nonNodes"in y)return y.nonNodes;var b=new ae;return b.addArray(ye.applyLocationPath(this.locationPath,f,y.nodes)),b},ye.predicateMatches=function(c,f){var y=c.evaluate(f);return ce.instance_of(y,ge)?f.contextPosition===y.numberValue():y.booleanValue()},ye.predicateString=function(c){return g("[","]",c.toString())},ye.predicatesString=function(c){return h("",a(ye.predicateString,c))},ye.prototype.toString=function(){if(this.filter!=null){var c=p(this.filter);return ce.instance_of(this.filter,he)?g("'","'",c):this.filterPredicates!=null&&this.filterPredicates.length?g("(",")",c)+ye.predicatesString(this.filterPredicates):this.locationPath!=null?c+(this.locationPath.absolute?"":"/")+p(this.locationPath):c}return p(this.locationPath)},ye.getOwnerElement=function(c){if(c.ownerElement)return c.ownerElement;try{if(c.selectSingleNode)return c.selectSingleNode("..")}catch{}for(var f=c.nodeType==O.DOCUMENT_NODE?c:c.ownerDocument,y=f.getElementsByTagName("*"),b=0;b<y.length;b++)for(var v=y.item(b),S=v.attributes,W=0;W<S.length;W++){var _e=S.item(W);if(_e===c)return v}return null},nn.prototype=new Object,nn.prototype.constructor=nn,nn.superclass=Object.prototype;function nn(c,f){arguments.length>0&&this.init(c,f)}nn.prototype.init=function(c,f){this.absolute=c,this.steps=f},nn.prototype.toString=function(){return(this.absolute?"/":"")+a(p,this.steps).join("/")},ee.prototype=new Object,ee.prototype.constructor=ee,ee.superclass=Object.prototype;function ee(c,f,y){arguments.length>0&&this.init(c,f,y)}ee.prototype.init=function(c,f,y){this.axis=c,this.nodeTest=f,this.predicates=y},ee.prototype.toString=function(){return ee.STEPNAMES[this.axis]+"::"+this.nodeTest.toString()+ye.predicatesString(this.predicates)},ee.ANCESTOR=0,ee.ANCESTORORSELF=1,ee.ATTRIBUTE=2,ee.CHILD=3,ee.DESCENDANT=4,ee.DESCENDANTORSELF=5,ee.FOLLOWING=6,ee.FOLLOWINGSIBLING=7,ee.NAMESPACE=8,ee.PARENT=9,ee.PRECEDING=10,ee.PRECEDINGSIBLING=11,ee.SELF=12,ee.STEPNAMES=s(function(c,f){return c[f[0]]=f[1],c},{},[[ee.ANCESTOR,"ancestor"],[ee.ANCESTORORSELF,"ancestor-or-self"],[ee.ATTRIBUTE,"attribute"],[ee.CHILD,"child"],[ee.DESCENDANT,"descendant"],[ee.DESCENDANTORSELF,"descendant-or-self"],[ee.FOLLOWING,"following"],[ee.FOLLOWINGSIBLING,"following-sibling"],[ee.NAMESPACE,"namespace"],[ee.PARENT,"parent"],[ee.PRECEDING,"preceding"],[ee.PRECEDINGSIBLING,"preceding-sibling"],[ee.SELF,"self"]]),se.prototype=new Object,se.prototype.constructor=se,se.superclass=Object.prototype;function se(c,f){arguments.length>0&&this.init(c,f)}se.prototype.init=function(c,f){this.type=c,this.value=f},se.prototype.toString=function(){return"<unknown nodetest type>"},se.prototype.matches=function(c,f){console.warn("unknown node test type")},se.NAMETESTANY=0,se.NAMETESTPREFIXANY=1,se.NAMETESTQNAME=2,se.COMMENT=3,se.TEXT=4,se.PI=5,se.NODE=6,se.isNodeType=function(c){return function(f){return u(c,f.nodeType)}},se.makeNodeTestType=function(c,f,y){var b=y||function(){};return b.prototype=new se(c),b.prototype.constructor=b,T(b.prototype,f),b},se.makeNodeTypeTest=function(c,f,y){return new(se.makeNodeTestType(c,{matches:se.isNodeType(f),toString:d(y)}))},se.hasPrefix=function(c){return c.prefix||(c.nodeName||c.tagName).indexOf(":")!==-1},se.isElementOrAttribute=se.isNodeType([1,2]),se.nameSpaceMatches=function(c,f,y){var b=y.namespaceURI||"";if(!c)return!b||f.allowAnyNamespaceForNoPrefix&&!se.hasPrefix(y);var v=f.namespaceResolver.getNamespace(c,f.expressionContextNode);if(v==null)throw new Error("Cannot resolve QName "+c);return v===b},se.localNameMatches=function(c,f,y){var b=y.localName||y.nodeName;return f.caseInsensitive?c.toLowerCase()===b.toLowerCase():c===b},se.NameTestPrefixAny=se.makeNodeTestType(se.NAMETESTPREFIXANY,{matches:function(c,f){return se.isElementOrAttribute(c)&&se.nameSpaceMatches(this.prefix,f,c)},toString:function(){return this.prefix+":*"}},function(f){this.prefix=f}),se.NameTestQName=se.makeNodeTestType(se.NAMETESTQNAME,{matches:function(c,f){return se.isNodeType([O.ELEMENT_NODE,O.ATTRIBUTE_NODE,jt.XPATH_NAMESPACE_NODE])(c)&&se.nameSpaceMatches(this.prefix,f,c)&&se.localNameMatches(this.localName,f,c)},toString:function(){return this.name}},function(f){var y=f.split(":");this.name=f,this.prefix=y.length>1?y[0]:null,this.localName=y[y.length>1?1:0]}),se.PITest=se.makeNodeTestType(se.PI,{matches:function(c,f){return se.isNodeType([O.PROCESSING_INSTRUCTION_NODE])(c)&&(c.target||c.nodeName)===this.name},toString:function(){return g('processing-instruction("','")',this.name)}},function(c){this.name=c}),se.nameTestAny=se.makeNodeTypeTest(se.NAMETESTANY,[O.ELEMENT_NODE,O.ATTRIBUTE_NODE,jt.XPATH_NAMESPACE_NODE],"*"),se.textTest=se.makeNodeTypeTest(se.TEXT,[O.TEXT_NODE,O.CDATA_SECTION_NODE],"text()"),se.commentTest=se.makeNodeTypeTest(se.COMMENT,[O.COMMENT_NODE],"comment()"),se.nodeTest=se.makeNodeTypeTest(se.NODE,[O.ELEMENT_NODE,O.ATTRIBUTE_NODE,O.TEXT_NODE,O.CDATA_SECTION_NODE,O.PROCESSING_INSTRUCTION_NODE,O.COMMENT_NODE,O.DOCUMENT_NODE],"node()"),se.anyPiTest=se.makeNodeTypeTest(se.PI,[O.PROCESSING_INSTRUCTION_NODE],"processing-instruction()"),tt.prototype=new F,tt.prototype.constructor=tt,tt.superclass=F.prototype;function tt(c){arguments.length>0&&this.init(c)}tt.prototype.init=function(c){this.variable=c},tt.prototype.toString=function(){return"$"+this.variable},tt.prototype.evaluate=function(c){var f=ce.resolveQName(this.variable,c.namespaceResolver,c.contextNode,!1);if(f[0]==null)throw new Error("Cannot resolve QName "+fn);var y=c.variableResolver.getVariable(f[1],f[0]);if(!y)throw Kt.fromMessage("Undeclared variable: "+this.toString());return y},Rt.prototype=new F,Rt.prototype.constructor=Rt,Rt.superclass=F.prototype;function Rt(c,f){arguments.length>0&&this.init(c,f)}Rt.prototype.init=function(c,f){this.functionName=c,this.arguments=f},Rt.prototype.toString=function(){for(var c=this.functionName+"(",f=0;f<this.arguments.length;f++)f>0&&(c+=", "),c+=this.arguments[f].toString();return c+")"},Rt.prototype.evaluate=function(c){var f=xt.getFunctionFromContext(this.functionName,c);if(!f)throw new Error("Unknown function "+this.functionName);var y=[c].concat(this.arguments);return f.apply(c.functionResolver.thisArg,y)};var Fe=new Object;Fe.equals=function(c,f){return c.equals(f)},Fe.notequal=function(c,f){return c.notequal(f)},Fe.lessthan=function(c,f){return c.lessthan(f)},Fe.greaterthan=function(c,f){return c.greaterthan(f)},Fe.lessthanorequal=function(c,f){return c.lessthanorequal(f)},Fe.greaterthanorequal=function(c,f){return c.greaterthanorequal(f)},he.prototype=new F,he.prototype.constructor=he,he.superclass=F.prototype;function he(c){arguments.length>0&&this.init(c)}he.prototype.init=function(c){this.str=String(c)},he.prototype.toString=function(){return this.str},he.prototype.evaluate=function(c){return this},he.prototype.string=function(){return this},he.prototype.number=function(){return new ge(this.str)},he.prototype.bool=function(){return new pe(this.str)},he.prototype.nodeset=function(){throw new Error("Cannot convert string to nodeset")},he.prototype.stringValue=function(){return this.str},he.prototype.numberValue=function(){return this.number().numberValue()},he.prototype.booleanValue=function(){return this.bool().booleanValue()},he.prototype.equals=function(c){return ce.instance_of(c,pe)?this.bool().equals(c):ce.instance_of(c,ge)?this.number().equals(c):ce.instance_of(c,ae)?c.compareWithString(this,Fe.equals):new pe(this.str==c.str)},he.prototype.notequal=function(c){return ce.instance_of(c,pe)?this.bool().notequal(c):ce.instance_of(c,ge)?this.number().notequal(c):ce.instance_of(c,ae)?c.compareWithString(this,Fe.notequal):new pe(this.str!=c.str)},he.prototype.lessthan=function(c){return this.number().lessthan(c)},he.prototype.greaterthan=function(c){return this.number().greaterthan(c)},he.prototype.lessthanorequal=function(c){return this.number().lessthanorequal(c)},he.prototype.greaterthanorequal=function(c){return this.number().greaterthanorequal(c)},ge.prototype=new F,ge.prototype.constructor=ge,ge.superclass=F.prototype;function ge(c){arguments.length>0&&this.init(c)}ge.prototype.init=function(c){this.num=typeof c=="string"?this.parse(c):Number(c)},ge.prototype.numberFormat=/^\s*-?[0-9]*\.?[0-9]+\s*$/,ge.prototype.parse=function(c){return this.numberFormat.test(c)?parseFloat(c):Number.NaN};function go(c){for(var f=c.split("e-"),y=f[0].replace(".",""),b=Number(f[1]),v=0;v<b-1;v+=1)y="0"+y;return"0."+y}function Ls(c){for(var f=c.split("e"),y=f[0].replace(".",""),b=Number(f[1]),v=b+1-y.length,S=0;S<v;S+=1)y+="0";return y}ge.prototype.toString=function(){var c=this.num.toString();return c.indexOf("e-")!==-1?go(c):c.indexOf("e")!==-1?Ls(c):c},ge.prototype.evaluate=function(c){return this},ge.prototype.string=function(){return new he(this.toString())},ge.prototype.number=function(){return this},ge.prototype.bool=function(){return new pe(this.num)},ge.prototype.nodeset=function(){throw new Error("Cannot convert number to nodeset")},ge.prototype.stringValue=function(){return this.string().stringValue()},ge.prototype.numberValue=function(){return this.num},ge.prototype.booleanValue=function(){return this.bool().booleanValue()},ge.prototype.negate=function(){return new ge(-this.num)},ge.prototype.equals=function(c){return ce.instance_of(c,pe)?this.bool().equals(c):ce.instance_of(c,he)?this.equals(c.number()):ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.equals):new pe(this.num==c.num)},ge.prototype.notequal=function(c){return ce.instance_of(c,pe)?this.bool().notequal(c):ce.instance_of(c,he)?this.notequal(c.number()):ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.notequal):new pe(this.num!=c.num)},ge.prototype.lessthan=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.greaterthan):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.lessthan(c.number()):new pe(this.num<c.num)},ge.prototype.greaterthan=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.lessthan):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.greaterthan(c.number()):new pe(this.num>c.num)},ge.prototype.lessthanorequal=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.greaterthanorequal):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.lessthanorequal(c.number()):new pe(this.num<=c.num)},ge.prototype.greaterthanorequal=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.lessthanorequal):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.greaterthanorequal(c.number()):new pe(this.num>=c.num)},ge.prototype.plus=function(c){return new ge(this.num+c.num)},ge.prototype.minus=function(c){return new ge(this.num-c.num)},ge.prototype.multiply=function(c){return new ge(this.num*c.num)},ge.prototype.div=function(c){return new ge(this.num/c.num)},ge.prototype.mod=function(c){return new ge(this.num%c.num)},pe.prototype=new F,pe.prototype.constructor=pe,pe.superclass=F.prototype;function pe(c){arguments.length>0&&this.init(c)}pe.prototype.init=function(c){this.b=!!c},pe.prototype.toString=function(){return this.b.toString()},pe.prototype.evaluate=function(c){return this},pe.prototype.string=function(){return new he(this.b)},pe.prototype.number=function(){return new ge(this.b)},pe.prototype.bool=function(){return this},pe.prototype.nodeset=function(){throw new Error("Cannot convert boolean to nodeset")},pe.prototype.stringValue=function(){return this.string().stringValue()},pe.prototype.numberValue=function(){return this.number().numberValue()},pe.prototype.booleanValue=function(){return this.b},pe.prototype.not=function(){return new pe(!this.b)},pe.prototype.equals=function(c){return ce.instance_of(c,he)||ce.instance_of(c,ge)?this.equals(c.bool()):ce.instance_of(c,ae)?c.compareWithBoolean(this,Fe.equals):new pe(this.b==c.b)},pe.prototype.notequal=function(c){return ce.instance_of(c,he)||ce.instance_of(c,ge)?this.notequal(c.bool()):ce.instance_of(c,ae)?c.compareWithBoolean(this,Fe.notequal):new pe(this.b!=c.b)},pe.prototype.lessthan=function(c){return this.number().lessthan(c)},pe.prototype.greaterthan=function(c){return this.number().greaterthan(c)},pe.prototype.lessthanorequal=function(c){return this.number().lessthanorequal(c)},pe.prototype.greaterthanorequal=function(c){return this.number().greaterthanorequal(c)},pe.true_=new pe(!0),pe.false_=new pe(!1),at.prototype=new Object,at.prototype.constructor=at,at.superclass=Object.prototype;function at(c){this.init(c)}at.prototype.init=function(c){this.left=null,this.right=null,this.node=c,this.depth=1},at.prototype.balance=function(){var c=this.left==null?0:this.left.depth,f=this.right==null?0:this.right.depth;if(c>f+1){var y=this.left.left==null?0:this.left.left.depth,b=this.left.right==null?0:this.left.right.depth;y<b&&this.left.rotateRR(),this.rotateLL()}else if(c+1<f){var v=this.right.right==null?0:this.right.right.depth,S=this.right.left==null?0:this.right.left.depth;S>v&&this.right.rotateLL(),this.rotateRR()}},at.prototype.rotateLL=function(){var c=this.node,f=this.right;this.node=this.left.node,this.right=this.left,this.left=this.left.left,this.right.left=this.right.right,this.right.right=f,this.right.node=c,this.right.updateInNewLocation(),this.updateInNewLocation()},at.prototype.rotateRR=function(){var c=this.node,f=this.left;this.node=this.right.node,this.left=this.right,this.right=this.right.right,this.left.right=this.left.left,this.left.left=f,this.left.node=c,this.left.updateInNewLocation(),this.updateInNewLocation()},at.prototype.updateInNewLocation=function(){this.getDepthFromChildren()},at.prototype.getDepthFromChildren=function(){this.depth=this.node==null?0:1,this.left!=null&&(this.depth=this.left.depth+1),this.right!=null&&this.depth<=this.right.depth&&(this.depth=this.right.depth+1)};function Fs(c,f){if(c===f)return 0;if(c.compareDocumentPosition){var y=c.compareDocumentPosition(f);return y&1||y&10?1:y&20?-1:0}for(var b=0,v=0,S=c;S!=null;S=S.parentNode||S.ownerElement)b++;for(var W=f;W!=null;W=W.parentNode||W.ownerElement)v++;if(b>v){for(;b>v;)c=c.parentNode||c.ownerElement,b--;if(c===f)return 1}else if(v>b){for(;v>b;)f=f.parentNode||f.ownerElement,v--;if(c===f)return-1}for(var _e=c.parentNode||c.ownerElement,Ce=f.parentNode||f.ownerElement;_e!==Ce;)c=_e,f=Ce,_e=c.parentNode||c.ownerElement,Ce=f.parentNode||f.ownerElement;var oe=ce.isAttribute(c),Ee=ce.isAttribute(f);if(oe&&!Ee)return-1;if(!oe&&Ee)return 1;if(_e)for(var At=oe?_e.attributes:_e.childNodes,Be=At.length,cr=0;cr<Be;cr+=1){var lr=At[cr];if(lr===c)return-1;if(lr===f)return 1}throw new Error("Unexpected: could not determine node order")}at.prototype.add=function(c){if(c===this.node)return!1;var f=Fs(c,this.node),y=!1;return f==-1?this.left==null?(this.left=new at(c),y=!0):(y=this.left.add(c),y&&this.balance()):f==1&&(this.right==null?(this.right=new at(c),y=!0):(y=this.right.add(c),y&&this.balance())),y&&this.getDepthFromChildren(),y},ae.prototype=new F,ae.prototype.constructor=ae,ae.superclass=F.prototype;function ae(){this.init()}ae.prototype.init=function(){this.tree=null,this.nodes=[],this.size=0},ae.prototype.toString=function(){var c=this.first();return c==null?"":this.stringForNode(c)},ae.prototype.evaluate=function(c){return this},ae.prototype.string=function(){return new he(this.toString())},ae.prototype.stringValue=function(){return this.toString()},ae.prototype.number=function(){return new ge(this.string())},ae.prototype.numberValue=function(){return Number(this.string())},ae.prototype.bool=function(){return new pe(this.booleanValue())},ae.prototype.booleanValue=function(){return!!this.size},ae.prototype.nodeset=function(){return this},ae.prototype.stringForNode=function(c){return c.nodeType==O.DOCUMENT_NODE||c.nodeType==O.ELEMENT_NODE||c.nodeType===O.DOCUMENT_FRAGMENT_NODE?this.stringForContainerNode(c):c.nodeType===O.ATTRIBUTE_NODE?c.value||c.nodeValue:c.isNamespaceNode?c.namespace:c.nodeValue},ae.prototype.stringForContainerNode=function(c){for(var f="",y=c.firstChild;y!=null;y=y.nextSibling){var b=y.nodeType;(b===1||b===3||b===4||b===9||b===11)&&(f+=this.stringForNode(y))}return f},ae.prototype.buildTree=function(){if(!this.tree&&this.nodes.length){this.tree=new at(this.nodes[0]);for(var c=1;c<this.nodes.length;c+=1)this.tree.add(this.nodes[c])}return this.tree},ae.prototype.first=function(){var c=this.buildTree();if(c==null)return null;for(;c.left!=null;)c=c.left;return c.node},ae.prototype.add=function(c){for(var f=0;f<this.nodes.length;f+=1)if(c===this.nodes[f])return;this.tree=null,this.nodes.push(c),this.size+=1},ae.prototype.addArray=function(c){var f=this;i(function(y){f.add(y)},c)},ae.prototype.toArray=function(){var c=[];return this.toArrayRec(this.buildTree(),c),c},ae.prototype.toArrayRec=function(c,f){c!=null&&(this.toArrayRec(c.left,f),f.push(c.node),this.toArrayRec(c.right,f))},ae.prototype.toUnsortedArray=function(){return this.nodes.slice()},ae.prototype.compareWithString=function(c,f){for(var y=this.toUnsortedArray(),b=0;b<y.length;b++){var v=y[b],S=new he(this.stringForNode(v)),W=f(S,c);if(W.booleanValue())return W}return new pe(!1)},ae.prototype.compareWithNumber=function(c,f){for(var y=this.toUnsortedArray(),b=0;b<y.length;b++){var v=y[b],S=new ge(this.stringForNode(v)),W=f(S,c);if(W.booleanValue())return W}return new pe(!1)},ae.prototype.compareWithBoolean=function(c,f){return f(this.bool(),c)},ae.prototype.compareWithNodeSet=function(c,f){for(var y=this.toUnsortedArray(),b=function(_e,Ce){return f(Ce,_e)},v=0;v<y.length;v++){var S=new he(this.stringForNode(y[v])),W=c.compareWithString(S,b);if(W.booleanValue())return W}return new pe(!1)},ae.compareWith=r(function(c,f){return ce.instance_of(f,he)?this.compareWithString(f,c):ce.instance_of(f,ge)?this.compareWithNumber(f,c):ce.instance_of(f,pe)?this.compareWithBoolean(f,c):this.compareWithNodeSet(f,c)}),ae.prototype.equals=ae.compareWith(Fe.equals),ae.prototype.notequal=ae.compareWith(Fe.notequal),ae.prototype.lessthan=ae.compareWith(Fe.lessthan),ae.prototype.greaterthan=ae.compareWith(Fe.greaterthan),ae.prototype.lessthanorequal=ae.compareWith(Fe.lessthanorequal),ae.prototype.greaterthanorequal=ae.compareWith(Fe.greaterthanorequal),ae.prototype.union=function(c){var f=new ae;return f.addArray(this.toUnsortedArray()),f.addArray(c.toUnsortedArray()),f},jt.prototype=new Object,jt.prototype.constructor=jt,jt.superclass=Object.prototype;function jt(c,f,y){this.isXPathNamespace=!0,this.ownerDocument=y.ownerDocument,this.nodeName="#namespace",this.prefix=c,this.localName=c,this.namespaceURI=f,this.nodeValue=f,this.ownerElement=y,this.nodeType=jt.XPATH_NAMESPACE_NODE}jt.prototype.toString=function(){return'{ "'+this.prefix+'", "'+this.namespaceURI+'" }'},Ht.prototype=new Object,Ht.prototype.constructor=Ht,Ht.superclass=Object.prototype;function Ht(c,f,y){this.variableResolver=c??new xn,this.namespaceResolver=f??new rn,this.functionResolver=y??new xt}Ht.prototype.extend=function(c){return T(new Ht,this,c)},xn.prototype=new Object,xn.prototype.constructor=xn,xn.superclass=Object.prototype;function xn(){}xn.prototype.getVariable=function(c,f){return null},xt.prototype=new Object,xt.prototype.constructor=xt,xt.superclass=Object.prototype;function xt(c){this.thisArg=c??me,this.functions=new Object,this.addStandardFunctions()}xt.prototype.addStandardFunctions=function(){this.functions["{}last"]=me.last,this.functions["{}position"]=me.position,this.functions["{}count"]=me.count,this.functions["{}id"]=me.id,this.functions["{}local-name"]=me.localName,this.functions["{}namespace-uri"]=me.namespaceURI,this.functions["{}name"]=me.name,this.functions["{}string"]=me.string,this.functions["{}concat"]=me.concat,this.functions["{}starts-with"]=me.startsWith,this.functions["{}contains"]=me.contains,this.functions["{}substring-before"]=me.substringBefore,this.functions["{}substring-after"]=me.substringAfter,this.functions["{}substring"]=me.substring,this.functions["{}string-length"]=me.stringLength,this.functions["{}normalize-space"]=me.normalizeSpace,this.functions["{}translate"]=me.translate,this.functions["{}boolean"]=me.boolean_,this.functions["{}not"]=me.not,this.functions["{}true"]=me.true_,this.functions["{}false"]=me.false_,this.functions["{}lang"]=me.lang,this.functions["{}number"]=me.number,this.functions["{}sum"]=me.sum,this.functions["{}floor"]=me.floor,this.functions["{}ceiling"]=me.ceiling,this.functions["{}round"]=me.round},xt.prototype.addFunction=function(c,f,y){this.functions["{"+c+"}"+f]=y},xt.getFunctionFromContext=function(c,f){var y=ce.resolveQName(c,f.namespaceResolver,f.contextNode,!1);if(y[0]===null)throw new Error("Cannot resolve QName "+name);return f.functionResolver.getFunction(y[1],y[0])},xt.prototype.getFunction=function(c,f){return this.functions["{"+f+"}"+c]},rn.prototype=new Object,rn.prototype.constructor=rn,rn.superclass=Object.prototype;function rn(){}rn.prototype.getNamespace=function(c,f){if(c=="xml")return U.XML_NAMESPACE_URI;if(c=="xmlns")return U.XMLNS_NAMESPACE_URI;for(f.nodeType==O.DOCUMENT_NODE?f=f.documentElement:f.nodeType==O.ATTRIBUTE_NODE?f=ye.getOwnerElement(f):f.nodeType!=O.ELEMENT_NODE&&(f=f.parentNode);f!=null&&f.nodeType==O.ELEMENT_NODE;){for(var y=f.attributes,b=0;b<y.length;b++){var v=y.item(b),S=v.name||v.nodeName;if(S==="xmlns"&&c===""||S==="xmlns:"+c)return String(v.value||v.nodeValue)}f=f.parentNode}return null};var me=new Object;me.last=function(c){if(arguments.length!=1)throw new Error("Function last expects ()");return new ge(c.contextSize)},me.position=function(c){if(arguments.length!=1)throw new Error("Function position expects ()");return new ge(c.contextPosition)},me.count=function(){var c=arguments[0],f;if(arguments.length!=2||!ce.instance_of(f=arguments[1].evaluate(c),ae))throw new Error("Function count expects (node-set)");return new ge(f.size)},me.id=function(){var c=arguments[0],f;if(arguments.length!=2)throw new Error("Function id expects (object)");f=arguments[1].evaluate(c),ce.instance_of(f,ae)?f=f.toArray().join(" "):f=f.stringValue();for(var y=f.split(/[\x0d\x0a\x09\x20]+/),b=new ae,v=c.contextNode.nodeType==O.DOCUMENT_NODE?c.contextNode:c.contextNode.ownerDocument,S=0;S<y.length;S++){var W;v.getElementById?W=v.getElementById(y[S]):W=ce.getElementById(v,y[S]),W!=null&&b.add(W)}return b},me.localName=function(c,f){var y;if(arguments.length==1)y=c.contextNode;else if(arguments.length==2)y=f.evaluate(c).first();else throw new Error("Function local-name expects (node-set?)");return y==null?new he(""):new he(y.localName||y.baseName||y.target||y.nodeName||"")},me.namespaceURI=function(){var c=arguments[0],f;if(arguments.length==1)f=c.contextNode;else if(arguments.length==2)f=arguments[1].evaluate(c).first();else throw new Error("Function namespace-uri expects (node-set?)");return f==null?new he(""):new he(f.namespaceURI)},me.name=function(){var c=arguments[0],f;if(arguments.length==1)f=c.contextNode;else if(arguments.length==2)f=arguments[1].evaluate(c).first();else throw new Error("Function name expects (node-set?)");return f==null?new he(""):f.nodeType==O.ELEMENT_NODE?new he(f.nodeName):f.nodeType==O.ATTRIBUTE_NODE?new he(f.name||f.nodeName):f.nodeType===O.PROCESSING_INSTRUCTION_NODE?new he(f.target||f.nodeName):f.localName==null?new he(""):new he(f.localName)},me.string=function(){var c=arguments[0];if(arguments.length==1)return new he(ae.prototype.stringForNode(c.contextNode));if(arguments.length==2)return arguments[1].evaluate(c).string();throw new Error("Function string expects (object?)")},me.concat=function(c){if(arguments.length<3)throw new Error("Function concat expects (string, string[, string]*)");for(var f="",y=1;y<arguments.length;y++)f+=arguments[y].evaluate(c).stringValue();return new he(f)},me.startsWith=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function startsWith expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();return new pe(f.substring(0,y.length)==y)},me.contains=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function contains expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();return new pe(f.indexOf(y)!==-1)},me.substringBefore=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function substring-before expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();return new he(f.substring(0,f.indexOf(y)))},me.substringAfter=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function substring-after expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();if(y.length==0)return new he(f);var b=f.indexOf(y);return b==-1?new he(""):new he(f.substring(b+y.length))},me.substring=function(){var c=arguments[0];if(!(arguments.length==3||arguments.length==4))throw new Error("Function substring expects (string, number, number?)");var f=arguments[1].evaluate(c).stringValue(),y=Math.round(arguments[2].evaluate(c).numberValue())-1,b=arguments.length==4?y+Math.round(arguments[3].evaluate(c).numberValue()):void 0;return new he(f.substring(y,b))},me.stringLength=function(){var c=arguments[0],f;if(arguments.length==1)f=ae.prototype.stringForNode(c.contextNode);else if(arguments.length==2)f=arguments[1].evaluate(c).stringValue();else throw new Error("Function string-length expects (string?)");return new ge(f.length)},me.normalizeSpace=function(){var c=arguments[0],f;if(arguments.length==1)f=ae.prototype.stringForNode(c.contextNode);else if(arguments.length==2)f=arguments[1].evaluate(c).stringValue();else throw new Error("Function normalize-space expects (string?)");for(var y=0,b=f.length-1;ce.isSpace(f.charCodeAt(b));)b--;for(var v="";y<=b&&ce.isSpace(f.charCodeAt(y));)y++;for(;y<=b;)if(ce.isSpace(f.charCodeAt(y)))for(v+=" ";y<=b&&ce.isSpace(f.charCodeAt(y));)y++;else v+=f.charAt(y),y++;return new he(v)},me.translate=function(c,f,y,b){if(arguments.length!=4)throw new Error("Function translate expects (string, string, string)");var v=f.evaluate(c).stringValue(),S=y.evaluate(c).stringValue(),W=b.evaluate(c).stringValue(),_e=s(function(oe,Ee,At){return Ee in oe||(oe[Ee]=At>W.length?"":W[At]),oe},{},S),Ce=h("",a(function(oe){return oe in _e?_e[oe]:oe},v));return new he(Ce)},me.boolean_=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function boolean expects (object)");return arguments[1].evaluate(c).bool()},me.not=function(c,f){if(arguments.length!=2)throw new Error("Function not expects (object)");return f.evaluate(c).bool().not()},me.true_=function(){if(arguments.length!=1)throw new Error("Function true expects ()");return pe.true_},me.false_=function(){if(arguments.length!=1)throw new Error("Function false expects ()");return pe.false_},me.lang=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function lang expects (string)");for(var f,y=c.contextNode;y!=null&&y.nodeType!=O.DOCUMENT_NODE;y=y.parentNode){var b=y.getAttributeNS(U.XML_NAMESPACE_URI,"lang");if(b!=null){f=String(b);break}}if(f==null)return pe.false_;var v=arguments[1].evaluate(c).stringValue();return new pe(f.substring(0,v.length)==v&&(f.length==v.length||f.charAt(v.length)=="-"))},me.number=function(){var c=arguments[0];if(!(arguments.length==1||arguments.length==2))throw new Error("Function number expects (object?)");return arguments.length==1?new ge(ae.prototype.stringForNode(c.contextNode)):arguments[1].evaluate(c).number()},me.sum=function(){var c=arguments[0],f;if(arguments.length!=2||!ce.instance_of(f=arguments[1].evaluate(c),ae))throw new Error("Function sum expects (node-set)");f=f.toUnsortedArray();for(var y=0,b=0;b<f.length;b++)y+=new ge(ae.prototype.stringForNode(f[b])).numberValue();return new ge(y)},me.floor=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function floor expects (number)");return new ge(Math.floor(arguments[1].evaluate(c).numberValue()))},me.ceiling=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function ceiling expects (number)");return new ge(Math.ceil(arguments[1].evaluate(c).numberValue()))},me.round=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function round expects (number)");return new ge(Math.round(arguments[1].evaluate(c).numberValue()))};var ce=new Object;ce.isAttribute=function(c){return c&&(c.nodeType===O.ATTRIBUTE_NODE||c.ownerElement)},ce.splitQName=function(c){var f=c.indexOf(":");return f==-1?[null,c]:[c.substring(0,f),c.substring(f+1)]},ce.resolveQName=function(c,f,y,b){var v=ce.splitQName(c);return v[0]!=null?v[0]=f.getNamespace(v[0],y):b?(v[0]=f.getNamespace("",y),v[0]==null&&(v[0]="")):v[0]="",v},ce.isSpace=function(c){return c==9||c==13||c==10||c==32},ce.isLetter=function(c){return c>=65&&c<=90||c>=97&&c<=122||c>=192&&c<=214||c>=216&&c<=246||c>=248&&c<=255||c>=256&&c<=305||c>=308&&c<=318||c>=321&&c<=328||c>=330&&c<=382||c>=384&&c<=451||c>=461&&c<=496||c>=500&&c<=501||c>=506&&c<=535||c>=592&&c<=680||c>=699&&c<=705||c==902||c>=904&&c<=906||c==908||c>=910&&c<=929||c>=931&&c<=974||c>=976&&c<=982||c==986||c==988||c==990||c==992||c>=994&&c<=1011||c>=1025&&c<=1036||c>=1038&&c<=1103||c>=1105&&c<=1116||c>=1118&&c<=1153||c>=1168&&c<=1220||c>=1223&&c<=1224||c>=1227&&c<=1228||c>=1232&&c<=1259||c>=1262&&c<=1269||c>=1272&&c<=1273||c>=1329&&c<=1366||c==1369||c>=1377&&c<=1414||c>=1488&&c<=1514||c>=1520&&c<=1522||c>=1569&&c<=1594||c>=1601&&c<=1610||c>=1649&&c<=1719||c>=1722&&c<=1726||c>=1728&&c<=1742||c>=1744&&c<=1747||c==1749||c>=1765&&c<=1766||c>=2309&&c<=2361||c==2365||c>=2392&&c<=2401||c>=2437&&c<=2444||c>=2447&&c<=2448||c>=2451&&c<=2472||c>=2474&&c<=2480||c==2482||c>=2486&&c<=2489||c>=2524&&c<=2525||c>=2527&&c<=2529||c>=2544&&c<=2545||c>=2565&&c<=2570||c>=2575&&c<=2576||c>=2579&&c<=2600||c>=2602&&c<=2608||c>=2610&&c<=2611||c>=2613&&c<=2614||c>=2616&&c<=2617||c>=2649&&c<=2652||c==2654||c>=2674&&c<=2676||c>=2693&&c<=2699||c==2701||c>=2703&&c<=2705||c>=2707&&c<=2728||c>=2730&&c<=2736||c>=2738&&c<=2739||c>=2741&&c<=2745||c==2749||c==2784||c>=2821&&c<=2828||c>=2831&&c<=2832||c>=2835&&c<=2856||c>=2858&&c<=2864||c>=2866&&c<=2867||c>=2870&&c<=2873||c==2877||c>=2908&&c<=2909||c>=2911&&c<=2913||c>=2949&&c<=2954||c>=2958&&c<=2960||c>=2962&&c<=2965||c>=2969&&c<=2970||c==2972||c>=2974&&c<=2975||c>=2979&&c<=2980||c>=2984&&c<=2986||c>=2990&&c<=2997||c>=2999&&c<=3001||c>=3077&&c<=3084||c>=3086&&c<=3088||c>=3090&&c<=3112||c>=3114&&c<=3123||c>=3125&&c<=3129||c>=3168&&c<=3169||c>=3205&&c<=3212||c>=3214&&c<=3216||c>=3218&&c<=3240||c>=3242&&c<=3251||c>=3253&&c<=3257||c==3294||c>=3296&&c<=3297||c>=3333&&c<=3340||c>=3342&&c<=3344||c>=3346&&c<=3368||c>=3370&&c<=3385||c>=3424&&c<=3425||c>=3585&&c<=3630||c==3632||c>=3634&&c<=3635||c>=3648&&c<=3653||c>=3713&&c<=3714||c==3716||c>=3719&&c<=3720||c==3722||c==3725||c>=3732&&c<=3735||c>=3737&&c<=3743||c>=3745&&c<=3747||c==3749||c==3751||c>=3754&&c<=3755||c>=3757&&c<=3758||c==3760||c>=3762&&c<=3763||c==3773||c>=3776&&c<=3780||c>=3904&&c<=3911||c>=3913&&c<=3945||c>=4256&&c<=4293||c>=4304&&c<=4342||c==4352||c>=4354&&c<=4355||c>=4357&&c<=4359||c==4361||c>=4363&&c<=4364||c>=4366&&c<=4370||c==4412||c==4414||c==4416||c==4428||c==4430||c==4432||c>=4436&&c<=4437||c==4441||c>=4447&&c<=4449||c==4451||c==4453||c==4455||c==4457||c>=4461&&c<=4462||c>=4466&&c<=4467||c==4469||c==4510||c==4520||c==4523||c>=4526&&c<=4527||c>=4535&&c<=4536||c==4538||c>=4540&&c<=4546||c==4587||c==4592||c==4601||c>=7680&&c<=7835||c>=7840&&c<=7929||c>=7936&&c<=7957||c>=7960&&c<=7965||c>=7968&&c<=8005||c>=8008&&c<=8013||c>=8016&&c<=8023||c==8025||c==8027||c==8029||c>=8031&&c<=8061||c>=8064&&c<=8116||c>=8118&&c<=8124||c==8126||c>=8130&&c<=8132||c>=8134&&c<=8140||c>=8144&&c<=8147||c>=8150&&c<=8155||c>=8160&&c<=8172||c>=8178&&c<=8180||c>=8182&&c<=8188||c==8486||c>=8490&&c<=8491||c==8494||c>=8576&&c<=8578||c>=12353&&c<=12436||c>=12449&&c<=12538||c>=12549&&c<=12588||c>=44032&&c<=55203||c>=19968&&c<=40869||c==12295||c>=12321&&c<=12329},ce.isNCNameChar=function(c){return c>=48&&c<=57||c>=1632&&c<=1641||c>=1776&&c<=1785||c>=2406&&c<=2415||c>=2534&&c<=2543||c>=2662&&c<=2671||c>=2790&&c<=2799||c>=2918&&c<=2927||c>=3047&&c<=3055||c>=3174&&c<=3183||c>=3302&&c<=3311||c>=3430&&c<=3439||c>=3664&&c<=3673||c>=3792&&c<=3801||c>=3872&&c<=3881||c==46||c==45||c==95||ce.isLetter(c)||c>=768&&c<=837||c>=864&&c<=865||c>=1155&&c<=1158||c>=1425&&c<=1441||c>=1443&&c<=1465||c>=1467&&c<=1469||c==1471||c>=1473&&c<=1474||c==1476||c>=1611&&c<=1618||c==1648||c>=1750&&c<=1756||c>=1757&&c<=1759||c>=1760&&c<=1764||c>=1767&&c<=1768||c>=1770&&c<=1773||c>=2305&&c<=2307||c==2364||c>=2366&&c<=2380||c==2381||c>=2385&&c<=2388||c>=2402&&c<=2403||c>=2433&&c<=2435||c==2492||c==2494||c==2495||c>=2496&&c<=2500||c>=2503&&c<=2504||c>=2507&&c<=2509||c==2519||c>=2530&&c<=2531||c==2562||c==2620||c==2622||c==2623||c>=2624&&c<=2626||c>=2631&&c<=2632||c>=2635&&c<=2637||c>=2672&&c<=2673||c>=2689&&c<=2691||c==2748||c>=2750&&c<=2757||c>=2759&&c<=2761||c>=2763&&c<=2765||c>=2817&&c<=2819||c==2876||c>=2878&&c<=2883||c>=2887&&c<=2888||c>=2891&&c<=2893||c>=2902&&c<=2903||c>=2946&&c<=2947||c>=3006&&c<=3010||c>=3014&&c<=3016||c>=3018&&c<=3021||c==3031||c>=3073&&c<=3075||c>=3134&&c<=3140||c>=3142&&c<=3144||c>=3146&&c<=3149||c>=3157&&c<=3158||c>=3202&&c<=3203||c>=3262&&c<=3268||c>=3270&&c<=3272||c>=3274&&c<=3277||c>=3285&&c<=3286||c>=3330&&c<=3331||c>=3390&&c<=3395||c>=3398&&c<=3400||c>=3402&&c<=3405||c==3415||c==3633||c>=3636&&c<=3642||c>=3655&&c<=3662||c==3761||c>=3764&&c<=3769||c>=3771&&c<=3772||c>=3784&&c<=3789||c>=3864&&c<=3865||c==3893||c==3895||c==3897||c==3902||c==3903||c>=3953&&c<=3972||c>=3974&&c<=3979||c>=3984&&c<=3989||c==3991||c>=3993&&c<=4013||c>=4017&&c<=4023||c==4025||c>=8400&&c<=8412||c==8417||c>=12330&&c<=12335||c==12441||c==12442||c==183||c==720||c==721||c==903||c==1600||c==3654||c==3782||c==12293||c>=12337&&c<=12341||c>=12445&&c<=12446||c>=12540&&c<=12542},ce.coalesceText=function(c){for(var f=c.firstChild;f!=null;f=f.nextSibling)if(f.nodeType==O.TEXT_NODE||f.nodeType==O.CDATA_SECTION_NODE){var y=f.nodeValue,b=f;for(f=f.nextSibling;f!=null&&(f.nodeType==O.TEXT_NODE||f.nodeType==O.CDATA_SECTION_NODE);){y+=f.nodeValue;var v=f;f=f.nextSibling,v.parentNode.removeChild(v)}if(b.nodeType==O.CDATA_SECTION_NODE){var S=b.parentNode;if(b.nextSibling==null)S.removeChild(b),S.appendChild(S.ownerDocument.createTextNode(y));else{var W=b.nextSibling;S.removeChild(b),S.insertBefore(S.ownerDocument.createTextNode(y),W)}}else b.nodeValue=y;if(f==null)break}else f.nodeType==O.ELEMENT_NODE&&ce.coalesceText(f)},ce.instance_of=function(c,f){for(;c!=null;){if(c.constructor===f)return!0;if(c===Object)return!1;c=c.constructor.superclass}return!1},ce.getElementById=function(c,f){if(c.nodeType==O.ELEMENT_NODE&&(c.getAttribute("id")==f||c.getAttributeNS(null,"id")==f))return c;for(var y=c.firstChild;y!=null;y=y.nextSibling){var b=ce.getElementById(y,f);if(b!=null)return b}return null};var Kt=function(){function c(y,b){var v=b?": "+b.toString():"";switch(y){case f.INVALID_EXPRESSION_ERR:return"Invalid expression"+v;case f.TYPE_ERR:return"Type error"+v}return null}function f(y,b,v){var S=Error.call(this,c(y,b)||v);return S.code=y,S.exception=b,S}return f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,f.superclass=Error,f.prototype.toString=function(){return this.message},f.fromMessage=function(y,b){return new f(null,b,y)},f.INVALID_EXPRESSION_ERR=51,f.TYPE_ERR=52,f}();Pt.prototype={},Pt.prototype.constructor=Pt,Pt.superclass=Object.prototype;function Pt(c,f,y){this.xpath=y.parse(c),this.context=new Ht,this.context.namespaceResolver=new An(f)}Pt.getOwnerDocument=function(c){return c.nodeType===O.DOCUMENT_NODE?c:c.ownerDocument},Pt.detectHtmlDom=function(c){if(!c)return!1;var f=Pt.getOwnerDocument(c);try{return f.implementation.hasFeature("HTML","2.0")}catch{return!0}},Pt.prototype.evaluate=function(c,f,y){this.context.expressionContextNode=c,this.context.caseInsensitive=Pt.detectHtmlDom(c);var b=this.xpath.evaluate(this.context);return new I(b,f)},An.prototype={},An.prototype.constructor=An,An.superclass=Object.prototype;function An(c){this.xpathNSResolver=c}An.prototype.getNamespace=function(c,f){return this.xpathNSResolver==null?null:this.xpathNSResolver.lookupNamespaceURI(c)},D.prototype={},D.prototype.constructor=D,D.superclass=Object.prototype;function D(c){this.node=c,this.namespaceResolver=new rn}D.prototype.lookupNamespaceURI=function(c){return this.namespaceResolver.getNamespace(c,this.node)},I.prototype={},I.prototype.constructor=I,I.superclass=Object.prototype;function I(c,f){switch(f==I.ANY_TYPE&&(c.constructor===he?f=I.STRING_TYPE:c.constructor===ge?f=I.NUMBER_TYPE:c.constructor===pe?f=I.BOOLEAN_TYPE:c.constructor===ae&&(f=I.UNORDERED_NODE_ITERATOR_TYPE)),this.resultType=f,f){case I.NUMBER_TYPE:this.numberValue=c.numberValue();return;case I.STRING_TYPE:this.stringValue=c.stringValue();return;case I.BOOLEAN_TYPE:this.booleanValue=c.booleanValue();return;case I.ANY_UNORDERED_NODE_TYPE:case I.FIRST_ORDERED_NODE_TYPE:if(c.constructor===ae){this.singleNodeValue=c.first();return}break;case I.UNORDERED_NODE_ITERATOR_TYPE:case I.ORDERED_NODE_ITERATOR_TYPE:if(c.constructor===ae){this.invalidIteratorState=!1,this.nodes=c.toArray(),this.iteratorIndex=0;return}break;case I.UNORDERED_NODE_SNAPSHOT_TYPE:case I.ORDERED_NODE_SNAPSHOT_TYPE:if(c.constructor===ae){this.nodes=c.toArray(),this.snapshotLength=this.nodes.length;return}break}throw new Kt(Kt.TYPE_ERR)}I.prototype.iterateNext=function(){if(this.resultType!=I.UNORDERED_NODE_ITERATOR_TYPE&&this.resultType!=I.ORDERED_NODE_ITERATOR_TYPE)throw new Kt(Kt.TYPE_ERR);return this.nodes[this.iteratorIndex++]},I.prototype.snapshotItem=function(c){if(this.resultType!=I.UNORDERED_NODE_SNAPSHOT_TYPE&&this.resultType!=I.ORDERED_NODE_SNAPSHOT_TYPE)throw new Kt(Kt.TYPE_ERR);return this.nodes[c]},I.ANY_TYPE=0,I.NUMBER_TYPE=1,I.STRING_TYPE=2,I.BOOLEAN_TYPE=3,I.UNORDERED_NODE_ITERATOR_TYPE=4,I.ORDERED_NODE_ITERATOR_TYPE=5,I.UNORDERED_NODE_SNAPSHOT_TYPE=6,I.ORDERED_NODE_SNAPSHOT_TYPE=7,I.ANY_UNORDERED_NODE_TYPE=8,I.FIRST_ORDERED_NODE_TYPE=9;function M(c,f){c.createExpression=function(y,b){try{return new Pt(y,b,f)}catch(v){throw new Kt(Kt.INVALID_EXPRESSION_ERR,v)}},c.createNSResolver=function(y){return new D(y)},c.evaluate=function(y,b,v,S,W){if(S<0||S>9)throw{code:0,toString:function(){return"Request type not supported"}};return c.createExpression(y,v,f).evaluate(b,S,W)}}try{var te=!0;try{document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("XPath",null)&&(te=!1)}catch{}te&&M(document,new x)}catch{}M(n,new x),function(){var c=new x,f=new rn,y=new xt,b=new xn;function v(Z){return{getNamespace:function(ze,Et){var ur=Z(ze,Et);return ur||f.getNamespace(ze,Et)}}}function S(Z){return v(Z.getNamespace.bind(Z))}function W(Z){return v(function(ze){return Z[ze]})}function _e(Z){return Z&&typeof Z.getNamespace=="function"?S(Z):typeof Z=="function"?v(Z):typeof Z=="object"?W(Z):f}function Ce(Z){if(Z===null||typeof Z>"u"||Z instanceof he||Z instanceof pe||Z instanceof ge||Z instanceof ae)return Z;switch(typeof Z){case"string":return new he(Z);case"boolean":return new pe(Z);case"number":return new ge(Z)}var ze=new ae;return ze.addArray([].concat(Z)),ze}function oe(Z){return function(ze){var Et=Array.prototype.slice.call(arguments,1).map(function(Bw){return Bw.evaluate(ze)}),ur=Z.apply(this,[].concat(ze,Et));return Ce(ur)}}function Ee(Z){return{getFunction:function(ze,Et){var ur=Z(ze,Et);return ur?oe(ur):y.getFunction(ze,Et)}}}function At(Z){return Ee(Z.getFunction.bind(Z))}function Be(Z){return Ee(function(ze){return Z[ze]})}function cr(Z){return Z&&typeof Z.getFunction=="function"?At(Z):typeof Z=="function"?Ee(Z):typeof Z=="object"?Be(Z):y}function lr(Z){return{getVariable:function(ze,Et){var ur=Z(ze,Et);return Ce(ur)}}}function Ow(Z){if(Z){if(typeof Z.getVariable=="function")return lr(Z.getVariable.bind(Z));if(typeof Z=="function")return lr(Z);if(typeof Z=="object")return lr(function(ze){return Z[ze]})}return b}function sh(Z,ze,Et){Z in Et&&(ze[Z]=Et[Z])}function Dw(Z){var ze=new Ht;return Z?(ze.namespaceResolver=_e(Z.namespaces),ze.functionResolver=cr(Z.functions),ze.variableResolver=Ow(Z.variables),ze.expressionContextNode=Z.node,sh("allowAnyNamespaceForNoPrefix",ze,Z),sh("isHtml",ze,Z)):ze.namespaceResolver=f,ze}function Rw(Z,ze){var Et=Dw(ze);return Z.evaluate(Et)}var jw={evaluate:function(Z){return Rw(this.expression,Z)},evaluateNumber:function(Z){return this.evaluate(Z).numberValue()},evaluateString:function(Z){return this.evaluate(Z).stringValue()},evaluateBoolean:function(Z){return this.evaluate(Z).booleanValue()},evaluateNodeSet:function(Z){return this.evaluate(Z).nodeset()},select:function(Z){return this.evaluateNodeSet(Z).toArray()},select1:function(Z){return this.select(Z)[0]}};function Pw(Z){var ze=c.parse(Z);return Object.create(jw,{expression:{value:ze}})}n.parse=Pw}(),T(n,{XPath:U,XPathParser:x,XPathResult:I,Step:ee,PathExpr:ye,NodeTest:se,LocationPath:nn,OrOperation:J,AndOperation:Ae,BarOperation:Q,EqualsOperation:R,NotEqualOperation:L,LessThanOperation:j,GreaterThanOperation:N,LessThanOrEqualOperation:k,GreaterThanOrEqualOperation:B,PlusOperation:H,MinusOperation:de,MultiplyOperation:ie,DivOperation:ve,ModOperation:ke,UnaryMinusOperation:G,FunctionCall:Rt,VariableReference:tt,XPathContext:Ht,XNodeSet:ae,XBoolean:pe,XString:he,XNumber:ge,NamespaceResolver:rn,FunctionResolver:xt,VariableResolver:xn,Utilities:ce}),n.select=function(c,f,y){return n.selectWithResolver(c,f,null,y)},n.useNamespaces=function(c){var f={mappings:c||{},lookupNamespaceURI:function(y){return this.mappings[y]}};return function(y,b,v){return n.selectWithResolver(y,b,f,v)}},n.selectWithResolver=function(c,f,y,b){var v=new Pt(c,y,new x),S=I.ANY_TYPE,W=v.evaluate(f,S,null);return W.resultType==I.STRING_TYPE?W=W.stringValue:W.resultType==I.NUMBER_TYPE?W=W.numberValue:W.resultType==I.BOOLEAN_TYPE?W=W.booleanValue:(W=W.nodes,b&&(W=W[0])),W},n.select1=function(c,f){return n.select(c,f,!0)};var we=function(c){return c&&typeof c.nodeType=="number"&&Number.isInteger(c.nodeType)&&c.nodeType>=1&&c.nodeType<=11&&typeof c.nodeName=="string"},nt=function(c){return Array.isArray(c)&&c.every(we)},Re=function(c){return function(f){return we(f)&&f.nodeType===c}};T(n,{isNodeLike:we,isArrayOfNodes:nt,isElement:Re(O.ELEMENT_NODE),isAttribute:Re(O.ATTRIBUTE_NODE),isTextNode:Re(O.TEXT_NODE),isCDATASection:Re(O.CDATA_SECTION_NODE),isProcessingInstruction:Re(O.PROCESSING_INSTRUCTION_NODE),isComment:Re(O.COMMENT_NODE),isDocumentNode:Re(O.DOCUMENT_NODE),isDocumentTypeNode:Re(O.DOCUMENT_TYPE_NODE),isDocumentFragment:Re(O.DOCUMENT_FRAGMENT_NODE)})})(e)})(Ll);var $e={};Object.defineProperty($e,"__esModule",{value:!0});$e.assertIsDocumentFragmentNode=$e.assertIsDocumentTypeNode=$e.assertIsDocumentNode=$e.assertIsCommentNode=$e.assertIsProcessingInstructionNode=$e.assertIsCDATASectionNode=$e.assertIsTextNode=$e.assertIsAttributeNode=$e.assertIsElementNode=$e.isDocumentFragmentNode=$e.isDocumentTypeNode=$e.isDocumentNode=$e.isCommentNode=$e.isProcessingInstructionNode=$e.isCDATASectionNode=$e.isTextNode=$e.isAttributeNode=$e.isElementNode=$e.assertIsArrayOfNodes=$e.isArrayOfNodes=$e.assertIsNodeLike=$e.isNodeLike=$e.NodeTypes=void 0;var Ye;(function(t){t[t.ELEMENT_NODE=1]="ELEMENT_NODE",t[t.ATTRIBUTE_NODE=2]="ATTRIBUTE_NODE",t[t.TEXT_NODE=3]="TEXT_NODE",t[t.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",t[t.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",t[t.COMMENT_NODE=8]="COMMENT_NODE",t[t.DOCUMENT_NODE=9]="DOCUMENT_NODE",t[t.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",t[t.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"})(Ye||($e.NodeTypes=Ye={}));function Fl(t){return t&&typeof t=="object"&&Number.isInteger(t.nodeType)&&t.nodeType>=1&&t.nodeType<=11&&typeof t.nodeName=="string"&&typeof t.appendChild=="function"&&typeof t.removeChild=="function"}$e.isNodeLike=Fl;function L6(t){if(!Fl(t))throw new Error(`Value is not a Node-like object. Received: ${t}`)}$e.assertIsNodeLike=L6;function ew(t){return Array.isArray(t)&&t.every(Fl)}$e.isArrayOfNodes=ew;function F6(t){if(!ew(t))throw new Error("Value is not an array of Nodes")}$e.assertIsArrayOfNodes=F6;function Ln(t,e){return Fl(e)&&e.nodeType===t}function or(t,e){const n=Object.keys(Ye).find(r=>Ye[r]===t);if(!Ln(t,e))throw new Error(`Value is not of type ${n}`)}const U6=t=>Ln(Ye.ELEMENT_NODE,t);$e.isElementNode=U6;const M6=t=>Ln(Ye.ATTRIBUTE_NODE,t);$e.isAttributeNode=M6;const q6=t=>Ln(Ye.TEXT_NODE,t);$e.isTextNode=q6;const V6=t=>Ln(Ye.CDATA_SECTION_NODE,t);$e.isCDATASectionNode=V6;const H6=t=>Ln(Ye.PROCESSING_INSTRUCTION_NODE,t);$e.isProcessingInstructionNode=H6;const K6=t=>Ln(Ye.COMMENT_NODE,t);$e.isCommentNode=K6;const G6=t=>Ln(Ye.DOCUMENT_NODE,t);$e.isDocumentNode=G6;const W6=t=>Ln(Ye.DOCUMENT_TYPE_NODE,t);$e.isDocumentTypeNode=W6;const X6=t=>Ln(Ye.DOCUMENT_FRAGMENT_NODE,t);$e.isDocumentFragmentNode=X6;const J6=t=>{or(Ye.ELEMENT_NODE,t)};$e.assertIsElementNode=J6;const Y6=t=>or(Ye.ATTRIBUTE_NODE,t);$e.assertIsAttributeNode=Y6;const Z6=t=>or(Ye.TEXT_NODE,t);$e.assertIsTextNode=Z6;const Q6=t=>or(Ye.CDATA_SECTION_NODE,t);$e.assertIsCDATASectionNode=Q6;const eS=t=>or(Ye.PROCESSING_INSTRUCTION_NODE,t);$e.assertIsProcessingInstructionNode=eS;const tS=t=>or(Ye.COMMENT_NODE,t);$e.assertIsCommentNode=tS;const nS=t=>or(Ye.DOCUMENT_NODE,t);$e.assertIsDocumentNode=nS;const rS=t=>or(Ye.DOCUMENT_TYPE_NODE,t);$e.assertIsDocumentTypeNode=rS;const iS=t=>or(Ye.DOCUMENT_FRAGMENT_NODE,t);$e.assertIsDocumentFragmentNode=iS;(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.validateDigestValue=t.findAncestorNs=t.derToPem=t.pemToDer=t.normalizePem=t.BASE64_REGEX=t.EXTRACT_X509_CERTS=t.PEM_FORMAT_REGEX=t.encodeSpecialCharactersInText=t.encodeSpecialCharactersInAttribute=t.findChilds=t.findChildren=t.findAttr=t.isArrayHasLength=void 0;const e=Ll,n=$e;function r(F){return Array.isArray(F)&&F.length>0}t.isArrayHasLength=r;function i(F,K,G){return F.localName===K&&(F.namespaceURI===G||G==null)}function s(F,K,G,Y){return F.localName===K&&(!F.namespaceURI&&(Y==null?void 0:Y.namespaceURI)===G||G==null)}function a(F,K,G){for(let Y=0;Y<F.attributes.length;Y++){const J=F.attributes[Y];if(i(J,K,G)||s(J,K,G,F))return J}return null}t.findAttr=a;function l(F,K,G){const Y=F.documentElement??F,J=[];for(let Ae=0;Ae<Y.childNodes.length;Ae++){const R=Y.childNodes[Ae];n.isElementNode(R)&&R.localName===K&&(R.namespaceURI===G||G==null)&&J.push(R)}return J}t.findChildren=l;function u(F,K,G){return l(F,K,G)}t.findChilds=u;const d={"&":"&","<":"<",'"':""","\r":"
","\n":"
"," ":"	"},p={"&":"&","<":"<",">":">","\r":"
"};function h(F){return F.replace(/([&<"\r\n\t])/g,function(K,G){return d[G]})}t.encodeSpecialCharactersInAttribute=h;function g(F){return F.replace(/([&<>\r])/g,function(K,G){return p[G]})}t.encodeSpecialCharactersInText=g,t.PEM_FORMAT_REGEX=new RegExp("^-----BEGIN [A-Z ]{1,48}-----([^-]*)-----END [A-Z ]{1,48}-----$","s"),t.EXTRACT_X509_CERTS=new RegExp("-----BEGIN CERTIFICATE-----[^-]*-----END CERTIFICATE-----","g"),t.BASE64_REGEX=new RegExp("^(?:[A-Za-z0-9\\+\\/]{4}\\n{0,1})*(?:[A-Za-z0-9\\+\\/]{2}==|[A-Za-z0-9\\+\\/]{3}=)?$","s");function $(F){return`${(F.trim().replace(/(\r\n|\r)/g,`
|
|
284
|
+
`])))]})},T6=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}=await Ue(t,e,!0);if(!s.session_id)throw new E(400,{message:"No session linked to login session"});const a=await t.env.data.sessions.get(i.tenant.id,s.session_id);if(!a)throw new E(400,{message:"Session not found"});const l=await t.env.data.users.get(i.tenant.id,a.user_id);if(!l)throw new E(400,{message:"User not found"});return(await t.env.data.userPermissions.list(i.tenant.id,l.user_id)).some(p=>p.permission_name==="users:impersonate")?t.html(_(hm,{theme:n,branding:r,client:i,user:l,state:e})):t.html(_(en,{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 Ue(t,e,!0);if(!r.session_id)throw new E(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 E(400,{message:"Session not found"});const s=await t.env.data.users.get(n.tenant.id,i.user_id);if(!s)throw new E(400,{message:"User not found"});if(!(await t.env.data.userPermissions.list(n.tenant.id,s.user_id)).some(u=>u.permission_name==="users:impersonate"))throw new E(403,{message:"Access denied: insufficient permissions"});return Dn(t,{client:n,authParams:r.authParams,loginSession:r,user:s,sessionId:i.id})}).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}=await Ue(t,e,!0);if(!a.session_id)throw new E(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 E(400,{message:"Current session not found"});const u=await t.env.data.users.get(s.tenant.id,l.user_id);if(!u)throw new E(400,{message:"Current user not found"});if(!(await t.env.data.userPermissions.list(s.tenant.id,u.user_id)).some(g=>g.permission_name==="users:impersonate"))return t.html(_(en,{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);return h?(await t.env.data.sessions.update(s.tenant.id,l.id,{user_id:h.user_id}),Dn(t,{client:s,authParams:a.authParams,loginSession:a,user:h,sessionId:l.id})):t.html(_(hm,{theme:r,branding:i,client:s,user:u,state:e,error:`User with ID "${n}" not found.`}),400)});function O6(t){const e=new o.OpenAPIHono,n=t.dataAdapter.cache||ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),r=t.dataAdapter.cache?300:0;e.onError((s,a)=>s instanceof oi?a.redirect(s.location,s.status):s instanceof E?a.text(s.message||"Error",s.status):a.text("Unexpected error",500)),e.get("/css/tailwind.css",async s=>{const a=Wf;return s.text(a,200,{"content-type":"text/css; charset=utf-8"})}),e.use(async(s,a)=>{const l=as(s,t.dataAdapter),u=Dl(l,{defaultTtl:r,cacheEntities:["tenants","connections","clients","legacyClients","customDomains","resourceServers","roles","organizations","userRoles","userPermissions","branding","themes","promptSettings","forms"],cache:n});return s.env.data=zl(s,u),a()}).use(Ol).use(Tl);const i=e.route("/info",b6).route("/check-account",p6).route("/account",g6).route("/account/change-email",m6).route("/account/change-email-verify",_6).route("/account/change-email-confirmation",y6).route("/login/identifier",O8).route("/enter-code",r6).route("/enter-password",c6).route("/invalid-session",v6).route("/pre-signup",w6).route("/pre-signup-sent",x6).route("/reset-password",u6).route("/forgot-password",d6).route("/validate-email",$6).route("/signup",l6).route("/impersonate",T6).route("/forms",C6);return i.doc("/u/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Universal login"}}),i}const Wt=o.z.object({"#text":o.z.string()}),D6=o.z.object({"#text":o.z.string(),"@_xmlns:saml":o.z.string().optional()}),R6=o.z.object({"samlp:AuthnRequest":o.z.object({"saml:Issuer":D6,"@_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(Wt)}))})),":@":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(Wt)}),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 j6=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(),"@_Name":o.z.string().optional(),"@_NameFormat":o.z.string().optional()})}),P6=o.z.object({"ds:Transform":o.z.array(o.z.any()),":@":o.z.object({"@_Algorithm":o.z.string()})}),gm=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.string()),":@":o.z.object({"@_Algorithm":o.z.string()})}),o.z.object({"ds:SignatureMethod":o.z.array(o.z.string()),":@":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(P6)}),o.z.object({"ds:DigestMethod":o.z.array(o.z.string()),":@":o.z.object({"@_Algorithm":o.z.string()})}),o.z.object({"ds:DigestValue":o.z.array(Wt)})]))})]))}),o.z.object({"ds:SignatureValue":o.z.array(Wt)}),o.z.object({"ds:KeyInfo":o.z.array(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(Wt)}),o.z.object({"ds:Exponent":o.z.array(Wt)})]))}))}))})])),":@":o.z.object({"@_xmlns:ds":o.z.string()})});o.z.array(o.z.object({"samlp:Response":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(Wt)}),gm,o.z.object({"samlp:Status":o.z.array(o.z.object({"samlp:StatusCode":o.z.array(Wt),":@":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(Wt)}),gm,o.z.object({"saml:Subject":o.z.array(o.z.union([o.z.object({"saml:NameID":o.z.array(Wt),":@":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(Wt)}))})),":@":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(Wt)}))})),":@":o.z.object({"@_AuthnInstant":o.z.string(),"@_SessionIndex":o.z.string(),"@_SessionNotOnOrAfter":o.z.string()})}),o.z.object({"saml:AttributeStatement":o.z.array(o.z.object({"saml:Attribute":o.z.array(j6),":@":o.z.object({"@_FriendlyName":o.z.string().optional(),"@_Name":o.z.string(),"@_NameFormat":o.z.string()})}))})])),":@":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 B6={},ai={},Os={},Ll={};(function(t){var e=t;(function(n){function r(c){var f=Array.prototype.slice,y=c.length,b=function(S,W){return function(){return W.apply(this,S.concat(f.call(arguments)))}},v=function(){var S=f.call(arguments);return S.length<y?b(S,v):c.apply(this,f.apply(arguments,[0,y]))};return v}var i=function(c,f){for(var y=0;y<f.length;y+=1)c(f[y],y,f)},s=function(c,f,y){var b=f;return i(function(v,S){b=c(b,v,S)},y),b},a=function(c,f){var y=new Array(f.length);return i(function(b,v){y[v]=c(b)},f),y},l=function(c,f){var y=[];return i(function(b,v){c(b,v)&&y.push(b)},f),y},u=function(c,f){for(var y=0;y<c.length;y+=1)if(c[y]===f)return!0;return!1};function d(c){return function(){return c}}function p(c){return c.toString()}var h=function(c,f){return f.join(c)},g=function(c,f,y){return c+y+f},$=Array.prototype.concat,A=32767;function z(c){for(var f=[],y=0;y<c.length;y+=A){var b=c.slice(y,y+A);f=$.apply(f,b)}return f}function T(c,f){for(var y=Object(c),b=1;b<arguments.length;b++){var v=arguments[b];if(v!=null)for(var S in v)Object.prototype.hasOwnProperty.call(v,S)&&(y[S]=v[S])}return y}var O={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11};x.prototype=new Object,x.prototype.constructor=x,x.superclass=Object.prototype;function x(){this.init()}x.prototype.init=function(){this.reduceActions=[],this.reduceActions[3]=function(c){return new J(c[0],c[2])},this.reduceActions[5]=function(c){return new Ae(c[0],c[2])},this.reduceActions[7]=function(c){return new R(c[0],c[2])},this.reduceActions[8]=function(c){return new L(c[0],c[2])},this.reduceActions[10]=function(c){return new j(c[0],c[2])},this.reduceActions[11]=function(c){return new N(c[0],c[2])},this.reduceActions[12]=function(c){return new k(c[0],c[2])},this.reduceActions[13]=function(c){return new B(c[0],c[2])},this.reduceActions[15]=function(c){return new K(c[0],c[2])},this.reduceActions[16]=function(c){return new de(c[0],c[2])},this.reduceActions[18]=function(c){return new ie(c[0],c[2])},this.reduceActions[19]=function(c){return new ve(c[0],c[2])},this.reduceActions[20]=function(c){return new ke(c[0],c[2])},this.reduceActions[22]=function(c){return new G(c[1])},this.reduceActions[24]=function(c){return new Q(c[0],c[2])},this.reduceActions[25]=function(c){return new ye(void 0,void 0,c[0])},this.reduceActions[27]=function(c){return c[0].locationPath=c[2],c[0]},this.reduceActions[28]=function(c){return c[0].locationPath=c[2],c[0].locationPath.steps.unshift(new ee(ee.DESCENDANTORSELF,se.nodeTest,[])),c[0]},this.reduceActions[29]=function(c){return new ye(c[0],[],void 0)},this.reduceActions[30]=function(c){return ce.instance_of(c[0],ye)?(c[0].filterPredicates==null&&(c[0].filterPredicates=[]),c[0].filterPredicates.push(c[1]),c[0]):new ye(c[0],[c[1]],void 0)},this.reduceActions[32]=function(c){return c[1]},this.reduceActions[33]=function(c){return new he(c[0])},this.reduceActions[34]=function(c){return new ge(c[0])},this.reduceActions[36]=function(c){return new Rt(c[0],[])},this.reduceActions[37]=function(c){return new Rt(c[0],c[2])},this.reduceActions[38]=function(c){return[c[0]]},this.reduceActions[39]=function(c){return c[2].unshift(c[0]),c[2]},this.reduceActions[43]=function(c){return new nn(!0,[])},this.reduceActions[44]=function(c){return c[1].absolute=!0,c[1]},this.reduceActions[46]=function(c){return new nn(!1,[c[0]])},this.reduceActions[47]=function(c){return c[0].steps.push(c[2]),c[0]},this.reduceActions[49]=function(c){return new ee(c[0],c[1],[])},this.reduceActions[50]=function(c){return new ee(ee.CHILD,c[0],[])},this.reduceActions[51]=function(c){return new ee(c[0],c[1],c[2])},this.reduceActions[52]=function(c){return new ee(ee.CHILD,c[0],c[1])},this.reduceActions[54]=function(c){return[c[0]]},this.reduceActions[55]=function(c){return c[1].unshift(c[0]),c[1]},this.reduceActions[56]=function(c){return c[0]=="ancestor"?ee.ANCESTOR:c[0]=="ancestor-or-self"?ee.ANCESTORORSELF:c[0]=="attribute"?ee.ATTRIBUTE:c[0]=="child"?ee.CHILD:c[0]=="descendant"?ee.DESCENDANT:c[0]=="descendant-or-self"?ee.DESCENDANTORSELF:c[0]=="following"?ee.FOLLOWING:c[0]=="following-sibling"?ee.FOLLOWINGSIBLING:c[0]=="namespace"?ee.NAMESPACE:c[0]=="parent"?ee.PARENT:c[0]=="preceding"?ee.PRECEDING:c[0]=="preceding-sibling"?ee.PRECEDINGSIBLING:c[0]=="self"?ee.SELF:-1},this.reduceActions[57]=function(c){return ee.ATTRIBUTE},this.reduceActions[59]=function(c){return c[0]=="comment"?se.commentTest:c[0]=="text"?se.textTest:c[0]=="processing-instruction"?se.anyPiTest:c[0]=="node"?se.nodeTest:new se(-1,void 0)},this.reduceActions[60]=function(c){return new se.PITest(c[2])},this.reduceActions[61]=function(c){return c[1]},this.reduceActions[63]=function(c){return c[1].absolute=!0,c[1].steps.unshift(new ee(ee.DESCENDANTORSELF,se.nodeTest,[])),c[1]},this.reduceActions[64]=function(c){return c[0].steps.push(new ee(ee.DESCENDANTORSELF,se.nodeTest,[])),c[0].steps.push(c[2]),c[0]},this.reduceActions[65]=function(c){return new ee(ee.SELF,se.nodeTest,[])},this.reduceActions[66]=function(c){return new ee(ee.PARENT,se.nodeTest,[])},this.reduceActions[67]=function(c){return new tt(c[1])},this.reduceActions[68]=function(c){return se.nameTestAny},this.reduceActions[69]=function(c){return new se.NameTestPrefixAny(c[0].split(":")[0])},this.reduceActions[70]=function(c){return new se.NameTestQName(c[0])}},x.actionTable=[" s s sssssssss s ss s ss"," s ","r rrrrrrrrr rrrrrrr rr r "," rrrrr "," s s sssssssss s ss s ss","rs rrrrrrrr s sssssrrrrrr rrs rs "," s s sssssssss s ss s ss"," s "," s ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," s "," s "," s s sssss s s ","r rrrrrrrrr rrrrrrr rr r ","a ","r s rr r ","r sr rr r ","r s rr s rr r ","r rssrr rss rr r ","r rrrrr rrrss rr r ","r rrrrrsss rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrrs rr r ","r rrrrrrrr rrrrrr rr r ","r rrrrrrrr rrrrrr rr r ","r srrrrrrrr rrrrrrs rr sr ","r srrrrrrrr rrrrrrs rr r ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrr rrrrrr rr r ","r rrrrrrrr rrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r "," sssss ","r rrrrrrrrr rrrrrrr rr sr ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," s ","r srrrrrrrr rrrrrrs rr r ","r rrrrrrrr rrrrr rr r "," s "," s "," rrrrr "," s s sssssssss s sss s ss","r srrrrrrrr rrrrrrs rr r "," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss s ss s ss"," s s sssssssss ss s ss"," s s sssssssss s ss s ss"," s s sssss s s "," s s sssss s s ","r rrrrrrrrr rrrrrrr rr rr "," s s sssss s s "," s s sssss s s ","r rrrrrrrrr rrrrrrr rr sr ","r rrrrrrrrr rrrrrrr rr sr ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr rr "," s ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," rr "," s "," rs ","r sr rr r ","r s rr s rr r ","r rssrr rss rr r ","r rssrr rss rr r ","r rrrrr rrrss rr r ","r rrrrr rrrss rr r ","r rrrrr rrrss rr r ","r rrrrr rrrss rr r ","r rrrrrsss rrrrr rr r ","r rrrrrsss rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrr rr r ","r rrrrrrrr rrrrrr rr r "," r "," s ","r srrrrrrrr rrrrrrs rr r ","r srrrrrrrr rrrrrrs rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr r ","r rrrrrrrrr rrrrrrr rr rr ","r rrrrrrrrr rrrrrrr rr rr "," s s sssssssss s ss s ss","r rrrrrrrrr rrrrrrr rr rr "," r "],x.actionTableNumber=[` 1 0 /.-,+*)(' & %$ # "!`," J ","a aaaaaaaaa aaaaaaa aa a "," YYYYY ",` 1 0 /.-,+*)(' & %$ # "!`,`K1 KKKKKKKK . +*)('KKKKKK KK# K" `,` 1 0 /.-,+*)(' & %$ # "!`," N "," O ","e eeeeeeeee eeeeeee ee ee ","f fffffffff fffffff ff ff ","d ddddddddd ddddddd dd dd ","B BBBBBBBBB BBBBBBB BB BB ","A AAAAAAAAA AAAAAAA AA AA "," P "," Q ",` 1 . +*)(' # " `,"b bbbbbbbbb bbbbbbb bb b "," ","! S !! ! ",'" T" "" " ',"$ V $$ U $$ $ ","& &ZY&& &XW && & ",") ))))) )))\\[ )) ) ",". ....._^] ..... .. . ","1 11111111 11111 11 1 ","5 55555555 55555` 55 5 ","7 77777777 777777 77 7 ","9 99999999 999999 99 9 ",": c:::::::: ::::::b :: a: ","I fIIIIIIII IIIIIIe II I ","= ========= ======= == == ","? ????????? ??????? ?? ?? ","C CCCCCCCCC CCCCCCC CC CC ","J JJJJJJJJ JJJJJJ JJ J ","M MMMMMMMM MMMMMM MM M ","N NNNNNNNNN NNNNNNN NN N ","P PPPPPPPPP PPPPPPP PP P "," +*)(' ","R RRRRRRRRR RRRRRRR RR aR ","U UUUUUUUUU UUUUUUU UU U ","Z ZZZZZZZZZ ZZZZZZZ ZZ ZZ ","c ccccccccc ccccccc cc cc "," j ","L fLLLLLLLL LLLLLLe LL L ","6 66666666 66666 66 6 "," k "," l "," XXXXX ",` 1 0 /.-,+*)(' & %$m # "!`,"_ f________ ______e __ _ ",` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 0 /.-,+*)(' %$ # "!`,` 1 0 /.-,+*)(' & %$ # "!`,` 1 . +*)(' # " `,` 1 . +*)(' # " `,"> >>>>>>>>> >>>>>>> >> >> ",` 1 . +*)(' # " `,` 1 . +*)(' # " `,"Q QQQQQQQQQ QQQQQQQ QQ aQ ","V VVVVVVVVV VVVVVVV VV aV ","T TTTTTTTTT TTTTTTT TT T ","@ @@@@@@@@@ @@@@@@@ @@ @@ "," ","[ [[[[[[[[[ [[[[[[[ [[ [[ ","D DDDDDDDDD DDDDDDD DD DD "," HH "," "," F ","# T# ## # ","% V %% U %% % ","' 'ZY'' 'XW '' ' ","( (ZY(( (XW (( ( ","+ +++++ +++\\[ ++ + ","* ***** ***\\[ ** * ","- ----- ---\\[ -- - ",", ,,,,, ,,,\\[ ,, , ","0 00000_^] 00000 00 0 ","/ /////_^] ///// // / ","2 22222222 22222 22 2 ","3 33333333 33333 33 3 ","4 44444444 44444 44 4 ","8 88888888 888888 88 8 "," ^ "," ","; f;;;;;;;; ;;;;;;e ;; ; ","< f<<<<<<<< <<<<<<e << < ","O OOOOOOOOO OOOOOOO OO O ","` ````````` ``````` `` ` ","S SSSSSSSSS SSSSSSS SS S ","W WWWWWWWWW WWWWWWW WW W ","\\ \\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\ \\\\ \\\\ ","E EEEEEEEEE EEEEEEE EE EE ",` 1 0 /.-,+*)(' & %$ # "!`,"] ]]]]]]]]] ]]]]]]] ]] ]] "," G "],x.gotoTable=["3456789:;<=>?@ AB CDEFGH IJ "," "," "," ","L456789:;<=>?@ AB CDEFGH IJ "," M EFGH IJ "," N;<=>?@ AB CDEFGH IJ "," "," "," "," "," "," "," "," "," "," S EFGH IJ "," "," "," "," "," "," "," "," "," "," "," "," "," e "," "," "," "," "," "," "," "," "," h J "," i j "," "," "," "," "," "," "," "," "," ","o456789:;<=>?@ ABpqCDEFGH IJ "," "," r6789:;<=>?@ AB CDEFGH IJ "," s789:;<=>?@ AB CDEFGH IJ "," t89:;<=>?@ AB CDEFGH IJ "," u89:;<=>?@ AB CDEFGH IJ "," v9:;<=>?@ AB CDEFGH IJ "," w9:;<=>?@ AB CDEFGH IJ "," x9:;<=>?@ AB CDEFGH IJ "," y9:;<=>?@ AB CDEFGH IJ "," z:;<=>?@ AB CDEFGH IJ "," {:;<=>?@ AB CDEFGH IJ "," |;<=>?@ AB CDEFGH IJ "," };<=>?@ AB CDEFGH IJ "," ~;<=>?@ AB CDEFGH IJ "," =>?@ AB CDEFGH IJ ","456789:;<=>?@ AB CDEFGH IJ"," EFGH IJ "," EFGH IJ "," "," GH IJ ","
GH IJ "," i "," i "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","o456789:;<=>?@ ABqCDEFGH IJ "," "," "],x.productions=[[1,1,2],[2,1,3],[3,1,4],[3,3,3,-9,4],[4,1,5],[4,3,4,-8,5],[5,1,6],[5,3,5,-22,6],[5,3,5,-5,6],[6,1,7],[6,3,6,-23,7],[6,3,6,-24,7],[6,3,6,-6,7],[6,3,6,-7,7],[7,1,8],[7,3,7,-25,8],[7,3,7,-26,8],[8,1,9],[8,3,8,-12,9],[8,3,8,-11,9],[8,3,8,-10,9],[9,1,10],[9,2,-26,9],[10,1,11],[10,3,10,-27,11],[11,1,12],[11,1,13],[11,3,13,-28,14],[11,3,13,-4,14],[13,1,15],[13,2,13,16],[15,1,17],[15,3,-29,2,-30],[15,1,-15],[15,1,-16],[15,1,18],[18,3,-13,-29,-30],[18,4,-13,-29,19,-30],[19,1,20],[19,3,20,-31,19],[20,1,2],[12,1,14],[12,1,21],[21,1,-28],[21,2,-28,14],[21,1,22],[14,1,23],[14,3,14,-28,23],[14,1,24],[23,2,25,26],[23,1,26],[23,3,25,26,27],[23,2,26,27],[23,1,28],[27,1,16],[27,2,16,27],[25,2,-14,-3],[25,1,-32],[26,1,29],[26,3,-20,-29,-30],[26,4,-21,-29,-15,-30],[16,3,-33,30,-34],[30,1,2],[22,2,-4,14],[24,3,14,-4,23],[28,1,-35],[28,1,-2],[17,2,-36,-18],[29,1,-17],[29,1,-19],[29,1,-18]],x.DOUBLEDOT=2,x.DOUBLECOLON=3,x.DOUBLESLASH=4,x.NOTEQUAL=5,x.LESSTHANOREQUAL=6,x.GREATERTHANOREQUAL=7,x.AND=8,x.OR=9,x.MOD=10,x.DIV=11,x.MULTIPLYOPERATOR=12,x.FUNCTIONNAME=13,x.AXISNAME=14,x.LITERAL=15,x.NUMBER=16,x.ASTERISKNAMETEST=17,x.QNAME=18,x.NCNAMECOLONASTERISK=19,x.NODETYPE=20,x.PROCESSINGINSTRUCTIONWITHLITERAL=21,x.EQUALS=22,x.LESSTHAN=23,x.GREATERTHAN=24,x.PLUS=25,x.MINUS=26,x.BAR=27,x.SLASH=28,x.LEFTPARENTHESIS=29,x.RIGHTPARENTHESIS=30,x.COMMA=31,x.AT=32,x.LEFTBRACKET=33,x.RIGHTBRACKET=34,x.DOT=35,x.DOLLAR=36,x.prototype.tokenize=function(c){for(var f=[],y=[],b=c+"\0",v=0,S=b.charAt(v++);;){for(;S==" "||S==" "||S=="\r"||S==`
|
|
285
|
+
`;)S=b.charAt(v++);if(S=="\0"||v>=b.length)break;if(S=="("){f.push(x.LEFTPARENTHESIS),y.push(S),S=b.charAt(v++);continue}if(S==")"){f.push(x.RIGHTPARENTHESIS),y.push(S),S=b.charAt(v++);continue}if(S=="["){f.push(x.LEFTBRACKET),y.push(S),S=b.charAt(v++);continue}if(S=="]"){f.push(x.RIGHTBRACKET),y.push(S),S=b.charAt(v++);continue}if(S=="@"){f.push(x.AT),y.push(S),S=b.charAt(v++);continue}if(S==","){f.push(x.COMMA),y.push(S),S=b.charAt(v++);continue}if(S=="|"){f.push(x.BAR),y.push(S),S=b.charAt(v++);continue}if(S=="+"){f.push(x.PLUS),y.push(S),S=b.charAt(v++);continue}if(S=="-"){f.push(x.MINUS),y.push(S),S=b.charAt(v++);continue}if(S=="="){f.push(x.EQUALS),y.push(S),S=b.charAt(v++);continue}if(S=="$"){f.push(x.DOLLAR),y.push(S),S=b.charAt(v++);continue}if(S=="."){if(S=b.charAt(v++),S=="."){f.push(x.DOUBLEDOT),y.push(".."),S=b.charAt(v++);continue}if(S>="0"&&S<="9"){var W="."+S;for(S=b.charAt(v++);S>="0"&&S<="9";)W+=S,S=b.charAt(v++);f.push(x.NUMBER),y.push(W);continue}f.push(x.DOT),y.push(".");continue}if(S=="'"||S=='"'){for(var _e=S,Ce="";v<b.length&&(S=b.charAt(v))!==_e;)Ce+=S,v+=1;if(S!==_e)throw Kt.fromMessage("Unterminated string literal: "+_e+Ce);v+=1,f.push(x.LITERAL),y.push(Ce),S=b.charAt(v++);continue}if(S>="0"&&S<="9"){var W=S;for(S=b.charAt(v++);S>="0"&&S<="9";)W+=S,S=b.charAt(v++);if(S=="."&&b.charAt(v)>="0"&&b.charAt(v)<="9")for(W+=S,W+=b.charAt(v++),S=b.charAt(v++);S>="0"&&S<="9";)W+=S,S=b.charAt(v++);f.push(x.NUMBER),y.push(W);continue}if(S=="*"){if(f.length>0){var oe=f[f.length-1];if(oe!=x.AT&&oe!=x.DOUBLECOLON&&oe!=x.LEFTPARENTHESIS&&oe!=x.LEFTBRACKET&&oe!=x.AND&&oe!=x.OR&&oe!=x.MOD&&oe!=x.DIV&&oe!=x.MULTIPLYOPERATOR&&oe!=x.SLASH&&oe!=x.DOUBLESLASH&&oe!=x.BAR&&oe!=x.PLUS&&oe!=x.MINUS&&oe!=x.EQUALS&&oe!=x.NOTEQUAL&&oe!=x.LESSTHAN&&oe!=x.LESSTHANOREQUAL&&oe!=x.GREATERTHAN&&oe!=x.GREATERTHANOREQUAL){f.push(x.MULTIPLYOPERATOR),y.push(S),S=b.charAt(v++);continue}}f.push(x.ASTERISKNAMETEST),y.push(S),S=b.charAt(v++);continue}if(S==":"&&b.charAt(v)==":"){f.push(x.DOUBLECOLON),y.push("::"),v++,S=b.charAt(v++);continue}if(S=="/"){if(S=b.charAt(v++),S=="/"){f.push(x.DOUBLESLASH),y.push("//"),S=b.charAt(v++);continue}f.push(x.SLASH),y.push("/");continue}if(S=="!"&&b.charAt(v)=="="){f.push(x.NOTEQUAL),y.push("!="),v++,S=b.charAt(v++);continue}if(S=="<"){if(b.charAt(v)=="="){f.push(x.LESSTHANOREQUAL),y.push("<="),v++,S=b.charAt(v++);continue}f.push(x.LESSTHAN),y.push("<"),S=b.charAt(v++);continue}if(S==">"){if(b.charAt(v)=="="){f.push(x.GREATERTHANOREQUAL),y.push(">="),v++,S=b.charAt(v++);continue}f.push(x.GREATERTHAN),y.push(">"),S=b.charAt(v++);continue}if(S=="_"||ce.isLetter(S.charCodeAt(0))){var Ee=S;for(S=b.charAt(v++);ce.isNCNameChar(S.charCodeAt(0));)Ee+=S,S=b.charAt(v++);if(f.length>0){var oe=f[f.length-1];if(oe!=x.AT&&oe!=x.DOUBLECOLON&&oe!=x.LEFTPARENTHESIS&&oe!=x.LEFTBRACKET&&oe!=x.AND&&oe!=x.OR&&oe!=x.MOD&&oe!=x.DIV&&oe!=x.MULTIPLYOPERATOR&&oe!=x.SLASH&&oe!=x.DOUBLESLASH&&oe!=x.BAR&&oe!=x.PLUS&&oe!=x.MINUS&&oe!=x.EQUALS&&oe!=x.NOTEQUAL&&oe!=x.LESSTHAN&&oe!=x.LESSTHANOREQUAL&&oe!=x.GREATERTHAN&&oe!=x.GREATERTHANOREQUAL){if(Ee=="and"){f.push(x.AND),y.push(Ee);continue}if(Ee=="or"){f.push(x.OR),y.push(Ee);continue}if(Ee=="mod"){f.push(x.MOD),y.push(Ee);continue}if(Ee=="div"){f.push(x.DIV),y.push(Ee);continue}}}if(S==":"){if(b.charAt(v)=="*"){f.push(x.NCNAMECOLONASTERISK),y.push(Ee+":*"),v++,S=b.charAt(v++);continue}if(b.charAt(v)=="_"||ce.isLetter(b.charCodeAt(v))){for(Ee+=":",S=b.charAt(v++);ce.isNCNameChar(S.charCodeAt(0));)Ee+=S,S=b.charAt(v++);if(S=="("){f.push(x.FUNCTIONNAME),y.push(Ee);continue}f.push(x.QNAME),y.push(Ee);continue}if(b.charAt(v)==":"){f.push(x.AXISNAME),y.push(Ee);continue}}if(S=="("){if(Ee=="comment"||Ee=="text"||Ee=="node"){f.push(x.NODETYPE),y.push(Ee);continue}if(Ee=="processing-instruction"){b.charAt(v)==")"?f.push(x.NODETYPE):f.push(x.PROCESSINGINSTRUCTIONWITHLITERAL),y.push(Ee);continue}f.push(x.FUNCTIONNAME),y.push(Ee);continue}f.push(x.QNAME),y.push(Ee);continue}throw new Error("Unexpected character "+S)}return f.push(1),y.push("[EOF]"),[f,y]},x.SHIFT="s",x.REDUCE="r",x.ACCEPT="a",x.prototype.parse=function(Ce){var f,y,b=this.tokenize(Ce);if(b!=null){f=b[0],y=b[1];var v=0,S=[],W=[],_e=[],Ce,oe,Ee;for(S.push(0),W.push(1),_e.push("_S"),oe=f[v],Ee=y[v++];;)switch(Ce=S[S.length-1],x.actionTable[Ce].charAt(oe-1)){case x.SHIFT:W.push(-oe),_e.push(Ee),S.push(x.actionTableNumber[Ce].charCodeAt(oe-1)-32),oe=f[v],Ee=y[v++];break;case x.REDUCE:for(var At=x.productions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32][1],Be=[],cr=0;cr<At;cr++)W.pop(),Be.unshift(_e.pop()),S.pop();var lr=S[S.length-1];W.push(x.productions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32][0]),this.reduceActions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32]==null?_e.push(Be[0]):_e.push(this.reduceActions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32](Be)),S.push(x.gotoTable[lr].charCodeAt(x.productions[x.actionTableNumber[Ce].charCodeAt(oe-1)-32][0]-2)-33);break;case x.ACCEPT:return new U(_e.pop());default:throw new Error("XPath parse error")}}},U.prototype=new Object,U.prototype.constructor=U,U.superclass=Object.prototype;function U(c){this.expression=c}U.prototype.toString=function(){return this.expression.toString()};function q(c,f,y){f in c||(c[f]=y)}U.prototype.evaluate=function(c){return c.contextNode=c.expressionContextNode,c.contextSize=1,c.contextPosition=1,c.isHtml&&(q(c,"caseInsensitive",!0),q(c,"allowAnyNamespaceForNoPrefix",!0)),q(c,"caseInsensitive",!1),this.expression.evaluate(c)},U.XML_NAMESPACE_URI="http://www.w3.org/XML/1998/namespace",U.XMLNS_NAMESPACE_URI="http://www.w3.org/2000/xmlns/",F.prototype=new Object,F.prototype.constructor=F,F.superclass=Object.prototype;function F(){}F.prototype.init=function(){},F.prototype.toString=function(){return"<Expression>"},F.prototype.evaluate=function(c){throw new Error("Could not evaluate expression.")},H.prototype=new F,H.prototype.constructor=H,H.superclass=F.prototype;function H(c){arguments.length>0&&this.init(c)}H.prototype.init=function(c){this.rhs=c},G.prototype=new H,G.prototype.constructor=G,G.superclass=H.prototype;function G(c){arguments.length>0&&this.init(c)}G.prototype.init=function(c){G.superclass.init.call(this,c)},G.prototype.evaluate=function(c){return this.rhs.evaluate(c).number().negate()},G.prototype.toString=function(){return"-"+this.rhs.toString()},Y.prototype=new F,Y.prototype.constructor=Y,Y.superclass=F.prototype;function Y(c,f){arguments.length>0&&this.init(c,f)}Y.prototype.init=function(c,f){this.lhs=c,this.rhs=f},J.prototype=new Y,J.prototype.constructor=J,J.superclass=Y.prototype;function J(c,f){arguments.length>0&&this.init(c,f)}J.prototype.init=function(c,f){J.superclass.init.call(this,c,f)},J.prototype.toString=function(){return"("+this.lhs.toString()+" or "+this.rhs.toString()+")"},J.prototype.evaluate=function(c){var f=this.lhs.evaluate(c).bool();return f.booleanValue()?f:this.rhs.evaluate(c).bool()},Ae.prototype=new Y,Ae.prototype.constructor=Ae,Ae.superclass=Y.prototype;function Ae(c,f){arguments.length>0&&this.init(c,f)}Ae.prototype.init=function(c,f){Ae.superclass.init.call(this,c,f)},Ae.prototype.toString=function(){return"("+this.lhs.toString()+" and "+this.rhs.toString()+")"},Ae.prototype.evaluate=function(c){var f=this.lhs.evaluate(c).bool();return f.booleanValue()?this.rhs.evaluate(c).bool():f},R.prototype=new Y,R.prototype.constructor=R,R.superclass=Y.prototype;function R(c,f){arguments.length>0&&this.init(c,f)}R.prototype.init=function(c,f){R.superclass.init.call(this,c,f)},R.prototype.toString=function(){return"("+this.lhs.toString()+" = "+this.rhs.toString()+")"},R.prototype.evaluate=function(c){return this.lhs.evaluate(c).equals(this.rhs.evaluate(c))},L.prototype=new Y,L.prototype.constructor=L,L.superclass=Y.prototype;function L(c,f){arguments.length>0&&this.init(c,f)}L.prototype.init=function(c,f){L.superclass.init.call(this,c,f)},L.prototype.toString=function(){return"("+this.lhs.toString()+" != "+this.rhs.toString()+")"},L.prototype.evaluate=function(c){return this.lhs.evaluate(c).notequal(this.rhs.evaluate(c))},j.prototype=new Y,j.prototype.constructor=j,j.superclass=Y.prototype;function j(c,f){arguments.length>0&&this.init(c,f)}j.prototype.init=function(c,f){j.superclass.init.call(this,c,f)},j.prototype.evaluate=function(c){return this.lhs.evaluate(c).lessthan(this.rhs.evaluate(c))},j.prototype.toString=function(){return"("+this.lhs.toString()+" < "+this.rhs.toString()+")"},N.prototype=new Y,N.prototype.constructor=N,N.superclass=Y.prototype;function N(c,f){arguments.length>0&&this.init(c,f)}N.prototype.init=function(c,f){N.superclass.init.call(this,c,f)},N.prototype.evaluate=function(c){return this.lhs.evaluate(c).greaterthan(this.rhs.evaluate(c))},N.prototype.toString=function(){return"("+this.lhs.toString()+" > "+this.rhs.toString()+")"},k.prototype=new Y,k.prototype.constructor=k,k.superclass=Y.prototype;function k(c,f){arguments.length>0&&this.init(c,f)}k.prototype.init=function(c,f){k.superclass.init.call(this,c,f)},k.prototype.evaluate=function(c){return this.lhs.evaluate(c).lessthanorequal(this.rhs.evaluate(c))},k.prototype.toString=function(){return"("+this.lhs.toString()+" <= "+this.rhs.toString()+")"},B.prototype=new Y,B.prototype.constructor=B,B.superclass=Y.prototype;function B(c,f){arguments.length>0&&this.init(c,f)}B.prototype.init=function(c,f){B.superclass.init.call(this,c,f)},B.prototype.evaluate=function(c){return this.lhs.evaluate(c).greaterthanorequal(this.rhs.evaluate(c))},B.prototype.toString=function(){return"("+this.lhs.toString()+" >= "+this.rhs.toString()+")"},K.prototype=new Y,K.prototype.constructor=K,K.superclass=Y.prototype;function K(c,f){arguments.length>0&&this.init(c,f)}K.prototype.init=function(c,f){K.superclass.init.call(this,c,f)},K.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().plus(this.rhs.evaluate(c).number())},K.prototype.toString=function(){return"("+this.lhs.toString()+" + "+this.rhs.toString()+")"},de.prototype=new Y,de.prototype.constructor=de,de.superclass=Y.prototype;function de(c,f){arguments.length>0&&this.init(c,f)}de.prototype.init=function(c,f){de.superclass.init.call(this,c,f)},de.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().minus(this.rhs.evaluate(c).number())},de.prototype.toString=function(){return"("+this.lhs.toString()+" - "+this.rhs.toString()+")"},ie.prototype=new Y,ie.prototype.constructor=ie,ie.superclass=Y.prototype;function ie(c,f){arguments.length>0&&this.init(c,f)}ie.prototype.init=function(c,f){ie.superclass.init.call(this,c,f)},ie.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().multiply(this.rhs.evaluate(c).number())},ie.prototype.toString=function(){return"("+this.lhs.toString()+" * "+this.rhs.toString()+")"},ve.prototype=new Y,ve.prototype.constructor=ve,ve.superclass=Y.prototype;function ve(c,f){arguments.length>0&&this.init(c,f)}ve.prototype.init=function(c,f){ve.superclass.init.call(this,c,f)},ve.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().div(this.rhs.evaluate(c).number())},ve.prototype.toString=function(){return"("+this.lhs.toString()+" div "+this.rhs.toString()+")"},ke.prototype=new Y,ke.prototype.constructor=ke,ke.superclass=Y.prototype;function ke(c,f){arguments.length>0&&this.init(c,f)}ke.prototype.init=function(c,f){ke.superclass.init.call(this,c,f)},ke.prototype.evaluate=function(c){return this.lhs.evaluate(c).number().mod(this.rhs.evaluate(c).number())},ke.prototype.toString=function(){return"("+this.lhs.toString()+" mod "+this.rhs.toString()+")"},Q.prototype=new Y,Q.prototype.constructor=Q,Q.superclass=Y.prototype;function Q(c,f){arguments.length>0&&this.init(c,f)}Q.prototype.init=function(c,f){Q.superclass.init.call(this,c,f)},Q.prototype.evaluate=function(c){return this.lhs.evaluate(c).nodeset().union(this.rhs.evaluate(c).nodeset())},Q.prototype.toString=function(){return a(p,[this.lhs,this.rhs]).join(" | ")},ye.prototype=new F,ye.prototype.constructor=ye,ye.superclass=F.prototype;function ye(c,f,y){arguments.length>0&&this.init(c,f,y)}ye.prototype.init=function(c,f,y){ye.superclass.init.call(this),this.filter=c,this.filterPredicates=f,this.locationPath=y};function Fn(c){for(;c&&c.parentNode;)c=c.parentNode;return c}ye.applyPredicates=function(c,f,y){if(c.length===0)return y;var b=f.extend({});return s(function(v,S){return b.contextSize=v.length,l(function(W,_e){return b.contextNode=W,b.contextPosition=_e+1,ye.predicateMatches(S,b)},v)},y,c)},ye.getRoot=function(c,f){var y=f[0];if(y.nodeType===O.DOCUMENT_NODE)return y;if(c.virtualRoot)return c.virtualRoot;var b=y.ownerDocument;if(b)return b;for(var v=y;v.parentNode!=null;)v=v.parentNode;return v},ye.applyStep=function(c,f,y){var b=[];switch(f.contextNode=y,c.axis){case ee.ANCESTOR:if(f.contextNode===f.virtualRoot)break;var v;for(f.contextNode.nodeType==O.ATTRIBUTE_NODE?v=ye.getOwnerElement(f.contextNode):v=f.contextNode.parentNode;v!=null&&(c.nodeTest.matches(v,f)&&b.push(v),v!==f.virtualRoot);)v=v.parentNode;break;case ee.ANCESTORORSELF:for(var v=f.contextNode;v!=null&&(c.nodeTest.matches(v,f)&&b.push(v),v!==f.virtualRoot);v=v.nodeType==O.ATTRIBUTE_NODE?ye.getOwnerElement(v):v.parentNode);break;case ee.ATTRIBUTE:var S=f.contextNode.attributes;if(S!=null)for(var W=0;W<S.length;W++){var v=S.item(W);c.nodeTest.matches(v,f)&&b.push(v)}break;case ee.CHILD:for(var v=f.contextNode.firstChild;v!=null;v=v.nextSibling)c.nodeTest.matches(v,f)&&b.push(v);break;case ee.DESCENDANT:for(var Be=[f.contextNode.firstChild];Be.length>0;)for(var v=Be.pop();v!=null;)c.nodeTest.matches(v,f)&&b.push(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling;break;case ee.DESCENDANTORSELF:c.nodeTest.matches(f.contextNode,f)&&b.push(f.contextNode);for(var Be=[f.contextNode.firstChild];Be.length>0;)for(var v=Be.pop();v!=null;)c.nodeTest.matches(v,f)&&b.push(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling;break;case ee.FOLLOWING:if(f.contextNode===f.virtualRoot)break;var Be=[];f.contextNode.firstChild!=null?Be.unshift(f.contextNode.firstChild):Be.unshift(f.contextNode.nextSibling);for(var v=f.contextNode.parentNode;v!=null&&v.nodeType!=O.DOCUMENT_NODE&&v!==f.virtualRoot;v=v.parentNode)Be.unshift(v.nextSibling);do for(var v=Be.pop();v!=null;)c.nodeTest.matches(v,f)&&b.push(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling;while(Be.length>0);break;case ee.FOLLOWINGSIBLING:if(f.contextNode===f.virtualRoot)break;for(var v=f.contextNode.nextSibling;v!=null;v=v.nextSibling)c.nodeTest.matches(v,f)&&b.push(v);break;case ee.NAMESPACE:var _e={};if(f.contextNode.nodeType==O.ELEMENT_NODE){_e.xml=U.XML_NAMESPACE_URI,_e.xmlns=U.XMLNS_NAMESPACE_URI;for(var v=f.contextNode;v!=null&&v.nodeType==O.ELEMENT_NODE;v=v.parentNode)for(var W=0;W<v.attributes.length;W++){var Ce=v.attributes.item(W),oe=String(Ce.name);if(oe=="xmlns")_e[""]==null&&(_e[""]=Ce.value);else if(oe.length>6&&oe.substring(0,6)=="xmlns:"){var Ee=oe.substring(6,oe.length);_e[Ee]==null&&(_e[Ee]=Ce.value)}}for(var Ee in _e){var At=new jt(Ee,_e[Ee],f.contextNode);c.nodeTest.matches(At,f)&&b.push(At)}}break;case ee.PARENT:v=null,f.contextNode!==f.virtualRoot&&(f.contextNode.nodeType==O.ATTRIBUTE_NODE?v=ye.getOwnerElement(f.contextNode):v=f.contextNode.parentNode),v!=null&&c.nodeTest.matches(v,f)&&b.push(v);break;case ee.PRECEDING:var Be;f.virtualRoot!=null?Be=[f.virtualRoot]:Be=[Fn(f.contextNode)];e:for(;Be.length>0;)for(var v=Be.pop();v!=null;){if(v==f.contextNode)break e;c.nodeTest.matches(v,f)&&b.unshift(v),v.firstChild!=null?(Be.push(v.nextSibling),v=v.firstChild):v=v.nextSibling}break;case ee.PRECEDINGSIBLING:if(f.contextNode===f.virtualRoot)break;for(var v=f.contextNode.previousSibling;v!=null;v=v.previousSibling)c.nodeTest.matches(v,f)&&b.push(v);break;case ee.SELF:c.nodeTest.matches(f.contextNode,f)&&b.push(f.contextNode);break}return b};function Pe(c,f,y){return ye.applyPredicates(c.predicates,f,ye.applyStep(c,f,y))}function Ge(c,f,y){return z(a(Pe.bind(null,y,c),f))}ye.applySteps=function(c,f,y){return s(Ge.bind(null,f),y,c)},ye.prototype.applyFilter=function(c,f){if(!this.filter)return{nodes:[c.contextNode]};var y=this.filter.evaluate(c);if(!ce.instance_of(y,ae)){if(this.filterPredicates!=null&&this.filterPredicates.length>0||this.locationPath!=null)throw new Error("Path expression filter must evaluate to a nodeset if predicates or location path are used");return{nonNodes:y}}return{nodes:ye.applyPredicates(this.filterPredicates||[],f,y.toUnsortedArray())}},ye.applyLocationPath=function(c,f,y){if(!c)return y;var b=c.absolute?[ye.getRoot(f,y)]:y;return ye.applySteps(c.steps,f,b)},ye.prototype.evaluate=function(c){var f=T(new Ht,c),y=this.applyFilter(c,f);if("nonNodes"in y)return y.nonNodes;var b=new ae;return b.addArray(ye.applyLocationPath(this.locationPath,f,y.nodes)),b},ye.predicateMatches=function(c,f){var y=c.evaluate(f);return ce.instance_of(y,ge)?f.contextPosition===y.numberValue():y.booleanValue()},ye.predicateString=function(c){return g("[","]",c.toString())},ye.predicatesString=function(c){return h("",a(ye.predicateString,c))},ye.prototype.toString=function(){if(this.filter!=null){var c=p(this.filter);return ce.instance_of(this.filter,he)?g("'","'",c):this.filterPredicates!=null&&this.filterPredicates.length?g("(",")",c)+ye.predicatesString(this.filterPredicates):this.locationPath!=null?c+(this.locationPath.absolute?"":"/")+p(this.locationPath):c}return p(this.locationPath)},ye.getOwnerElement=function(c){if(c.ownerElement)return c.ownerElement;try{if(c.selectSingleNode)return c.selectSingleNode("..")}catch{}for(var f=c.nodeType==O.DOCUMENT_NODE?c:c.ownerDocument,y=f.getElementsByTagName("*"),b=0;b<y.length;b++)for(var v=y.item(b),S=v.attributes,W=0;W<S.length;W++){var _e=S.item(W);if(_e===c)return v}return null},nn.prototype=new Object,nn.prototype.constructor=nn,nn.superclass=Object.prototype;function nn(c,f){arguments.length>0&&this.init(c,f)}nn.prototype.init=function(c,f){this.absolute=c,this.steps=f},nn.prototype.toString=function(){return(this.absolute?"/":"")+a(p,this.steps).join("/")},ee.prototype=new Object,ee.prototype.constructor=ee,ee.superclass=Object.prototype;function ee(c,f,y){arguments.length>0&&this.init(c,f,y)}ee.prototype.init=function(c,f,y){this.axis=c,this.nodeTest=f,this.predicates=y},ee.prototype.toString=function(){return ee.STEPNAMES[this.axis]+"::"+this.nodeTest.toString()+ye.predicatesString(this.predicates)},ee.ANCESTOR=0,ee.ANCESTORORSELF=1,ee.ATTRIBUTE=2,ee.CHILD=3,ee.DESCENDANT=4,ee.DESCENDANTORSELF=5,ee.FOLLOWING=6,ee.FOLLOWINGSIBLING=7,ee.NAMESPACE=8,ee.PARENT=9,ee.PRECEDING=10,ee.PRECEDINGSIBLING=11,ee.SELF=12,ee.STEPNAMES=s(function(c,f){return c[f[0]]=f[1],c},{},[[ee.ANCESTOR,"ancestor"],[ee.ANCESTORORSELF,"ancestor-or-self"],[ee.ATTRIBUTE,"attribute"],[ee.CHILD,"child"],[ee.DESCENDANT,"descendant"],[ee.DESCENDANTORSELF,"descendant-or-self"],[ee.FOLLOWING,"following"],[ee.FOLLOWINGSIBLING,"following-sibling"],[ee.NAMESPACE,"namespace"],[ee.PARENT,"parent"],[ee.PRECEDING,"preceding"],[ee.PRECEDINGSIBLING,"preceding-sibling"],[ee.SELF,"self"]]),se.prototype=new Object,se.prototype.constructor=se,se.superclass=Object.prototype;function se(c,f){arguments.length>0&&this.init(c,f)}se.prototype.init=function(c,f){this.type=c,this.value=f},se.prototype.toString=function(){return"<unknown nodetest type>"},se.prototype.matches=function(c,f){console.warn("unknown node test type")},se.NAMETESTANY=0,se.NAMETESTPREFIXANY=1,se.NAMETESTQNAME=2,se.COMMENT=3,se.TEXT=4,se.PI=5,se.NODE=6,se.isNodeType=function(c){return function(f){return u(c,f.nodeType)}},se.makeNodeTestType=function(c,f,y){var b=y||function(){};return b.prototype=new se(c),b.prototype.constructor=b,T(b.prototype,f),b},se.makeNodeTypeTest=function(c,f,y){return new(se.makeNodeTestType(c,{matches:se.isNodeType(f),toString:d(y)}))},se.hasPrefix=function(c){return c.prefix||(c.nodeName||c.tagName).indexOf(":")!==-1},se.isElementOrAttribute=se.isNodeType([1,2]),se.nameSpaceMatches=function(c,f,y){var b=y.namespaceURI||"";if(!c)return!b||f.allowAnyNamespaceForNoPrefix&&!se.hasPrefix(y);var v=f.namespaceResolver.getNamespace(c,f.expressionContextNode);if(v==null)throw new Error("Cannot resolve QName "+c);return v===b},se.localNameMatches=function(c,f,y){var b=y.localName||y.nodeName;return f.caseInsensitive?c.toLowerCase()===b.toLowerCase():c===b},se.NameTestPrefixAny=se.makeNodeTestType(se.NAMETESTPREFIXANY,{matches:function(c,f){return se.isElementOrAttribute(c)&&se.nameSpaceMatches(this.prefix,f,c)},toString:function(){return this.prefix+":*"}},function(f){this.prefix=f}),se.NameTestQName=se.makeNodeTestType(se.NAMETESTQNAME,{matches:function(c,f){return se.isNodeType([O.ELEMENT_NODE,O.ATTRIBUTE_NODE,jt.XPATH_NAMESPACE_NODE])(c)&&se.nameSpaceMatches(this.prefix,f,c)&&se.localNameMatches(this.localName,f,c)},toString:function(){return this.name}},function(f){var y=f.split(":");this.name=f,this.prefix=y.length>1?y[0]:null,this.localName=y[y.length>1?1:0]}),se.PITest=se.makeNodeTestType(se.PI,{matches:function(c,f){return se.isNodeType([O.PROCESSING_INSTRUCTION_NODE])(c)&&(c.target||c.nodeName)===this.name},toString:function(){return g('processing-instruction("','")',this.name)}},function(c){this.name=c}),se.nameTestAny=se.makeNodeTypeTest(se.NAMETESTANY,[O.ELEMENT_NODE,O.ATTRIBUTE_NODE,jt.XPATH_NAMESPACE_NODE],"*"),se.textTest=se.makeNodeTypeTest(se.TEXT,[O.TEXT_NODE,O.CDATA_SECTION_NODE],"text()"),se.commentTest=se.makeNodeTypeTest(se.COMMENT,[O.COMMENT_NODE],"comment()"),se.nodeTest=se.makeNodeTypeTest(se.NODE,[O.ELEMENT_NODE,O.ATTRIBUTE_NODE,O.TEXT_NODE,O.CDATA_SECTION_NODE,O.PROCESSING_INSTRUCTION_NODE,O.COMMENT_NODE,O.DOCUMENT_NODE],"node()"),se.anyPiTest=se.makeNodeTypeTest(se.PI,[O.PROCESSING_INSTRUCTION_NODE],"processing-instruction()"),tt.prototype=new F,tt.prototype.constructor=tt,tt.superclass=F.prototype;function tt(c){arguments.length>0&&this.init(c)}tt.prototype.init=function(c){this.variable=c},tt.prototype.toString=function(){return"$"+this.variable},tt.prototype.evaluate=function(c){var f=ce.resolveQName(this.variable,c.namespaceResolver,c.contextNode,!1);if(f[0]==null)throw new Error("Cannot resolve QName "+fn);var y=c.variableResolver.getVariable(f[1],f[0]);if(!y)throw Kt.fromMessage("Undeclared variable: "+this.toString());return y},Rt.prototype=new F,Rt.prototype.constructor=Rt,Rt.superclass=F.prototype;function Rt(c,f){arguments.length>0&&this.init(c,f)}Rt.prototype.init=function(c,f){this.functionName=c,this.arguments=f},Rt.prototype.toString=function(){for(var c=this.functionName+"(",f=0;f<this.arguments.length;f++)f>0&&(c+=", "),c+=this.arguments[f].toString();return c+")"},Rt.prototype.evaluate=function(c){var f=xt.getFunctionFromContext(this.functionName,c);if(!f)throw new Error("Unknown function "+this.functionName);var y=[c].concat(this.arguments);return f.apply(c.functionResolver.thisArg,y)};var Fe=new Object;Fe.equals=function(c,f){return c.equals(f)},Fe.notequal=function(c,f){return c.notequal(f)},Fe.lessthan=function(c,f){return c.lessthan(f)},Fe.greaterthan=function(c,f){return c.greaterthan(f)},Fe.lessthanorequal=function(c,f){return c.lessthanorequal(f)},Fe.greaterthanorequal=function(c,f){return c.greaterthanorequal(f)},he.prototype=new F,he.prototype.constructor=he,he.superclass=F.prototype;function he(c){arguments.length>0&&this.init(c)}he.prototype.init=function(c){this.str=String(c)},he.prototype.toString=function(){return this.str},he.prototype.evaluate=function(c){return this},he.prototype.string=function(){return this},he.prototype.number=function(){return new ge(this.str)},he.prototype.bool=function(){return new pe(this.str)},he.prototype.nodeset=function(){throw new Error("Cannot convert string to nodeset")},he.prototype.stringValue=function(){return this.str},he.prototype.numberValue=function(){return this.number().numberValue()},he.prototype.booleanValue=function(){return this.bool().booleanValue()},he.prototype.equals=function(c){return ce.instance_of(c,pe)?this.bool().equals(c):ce.instance_of(c,ge)?this.number().equals(c):ce.instance_of(c,ae)?c.compareWithString(this,Fe.equals):new pe(this.str==c.str)},he.prototype.notequal=function(c){return ce.instance_of(c,pe)?this.bool().notequal(c):ce.instance_of(c,ge)?this.number().notequal(c):ce.instance_of(c,ae)?c.compareWithString(this,Fe.notequal):new pe(this.str!=c.str)},he.prototype.lessthan=function(c){return this.number().lessthan(c)},he.prototype.greaterthan=function(c){return this.number().greaterthan(c)},he.prototype.lessthanorequal=function(c){return this.number().lessthanorequal(c)},he.prototype.greaterthanorequal=function(c){return this.number().greaterthanorequal(c)},ge.prototype=new F,ge.prototype.constructor=ge,ge.superclass=F.prototype;function ge(c){arguments.length>0&&this.init(c)}ge.prototype.init=function(c){this.num=typeof c=="string"?this.parse(c):Number(c)},ge.prototype.numberFormat=/^\s*-?[0-9]*\.?[0-9]+\s*$/,ge.prototype.parse=function(c){return this.numberFormat.test(c)?parseFloat(c):Number.NaN};function go(c){for(var f=c.split("e-"),y=f[0].replace(".",""),b=Number(f[1]),v=0;v<b-1;v+=1)y="0"+y;return"0."+y}function Ls(c){for(var f=c.split("e"),y=f[0].replace(".",""),b=Number(f[1]),v=b+1-y.length,S=0;S<v;S+=1)y+="0";return y}ge.prototype.toString=function(){var c=this.num.toString();return c.indexOf("e-")!==-1?go(c):c.indexOf("e")!==-1?Ls(c):c},ge.prototype.evaluate=function(c){return this},ge.prototype.string=function(){return new he(this.toString())},ge.prototype.number=function(){return this},ge.prototype.bool=function(){return new pe(this.num)},ge.prototype.nodeset=function(){throw new Error("Cannot convert number to nodeset")},ge.prototype.stringValue=function(){return this.string().stringValue()},ge.prototype.numberValue=function(){return this.num},ge.prototype.booleanValue=function(){return this.bool().booleanValue()},ge.prototype.negate=function(){return new ge(-this.num)},ge.prototype.equals=function(c){return ce.instance_of(c,pe)?this.bool().equals(c):ce.instance_of(c,he)?this.equals(c.number()):ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.equals):new pe(this.num==c.num)},ge.prototype.notequal=function(c){return ce.instance_of(c,pe)?this.bool().notequal(c):ce.instance_of(c,he)?this.notequal(c.number()):ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.notequal):new pe(this.num!=c.num)},ge.prototype.lessthan=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.greaterthan):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.lessthan(c.number()):new pe(this.num<c.num)},ge.prototype.greaterthan=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.lessthan):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.greaterthan(c.number()):new pe(this.num>c.num)},ge.prototype.lessthanorequal=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.greaterthanorequal):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.lessthanorequal(c.number()):new pe(this.num<=c.num)},ge.prototype.greaterthanorequal=function(c){return ce.instance_of(c,ae)?c.compareWithNumber(this,Fe.lessthanorequal):ce.instance_of(c,pe)||ce.instance_of(c,he)?this.greaterthanorequal(c.number()):new pe(this.num>=c.num)},ge.prototype.plus=function(c){return new ge(this.num+c.num)},ge.prototype.minus=function(c){return new ge(this.num-c.num)},ge.prototype.multiply=function(c){return new ge(this.num*c.num)},ge.prototype.div=function(c){return new ge(this.num/c.num)},ge.prototype.mod=function(c){return new ge(this.num%c.num)},pe.prototype=new F,pe.prototype.constructor=pe,pe.superclass=F.prototype;function pe(c){arguments.length>0&&this.init(c)}pe.prototype.init=function(c){this.b=!!c},pe.prototype.toString=function(){return this.b.toString()},pe.prototype.evaluate=function(c){return this},pe.prototype.string=function(){return new he(this.b)},pe.prototype.number=function(){return new ge(this.b)},pe.prototype.bool=function(){return this},pe.prototype.nodeset=function(){throw new Error("Cannot convert boolean to nodeset")},pe.prototype.stringValue=function(){return this.string().stringValue()},pe.prototype.numberValue=function(){return this.number().numberValue()},pe.prototype.booleanValue=function(){return this.b},pe.prototype.not=function(){return new pe(!this.b)},pe.prototype.equals=function(c){return ce.instance_of(c,he)||ce.instance_of(c,ge)?this.equals(c.bool()):ce.instance_of(c,ae)?c.compareWithBoolean(this,Fe.equals):new pe(this.b==c.b)},pe.prototype.notequal=function(c){return ce.instance_of(c,he)||ce.instance_of(c,ge)?this.notequal(c.bool()):ce.instance_of(c,ae)?c.compareWithBoolean(this,Fe.notequal):new pe(this.b!=c.b)},pe.prototype.lessthan=function(c){return this.number().lessthan(c)},pe.prototype.greaterthan=function(c){return this.number().greaterthan(c)},pe.prototype.lessthanorequal=function(c){return this.number().lessthanorequal(c)},pe.prototype.greaterthanorequal=function(c){return this.number().greaterthanorequal(c)},pe.true_=new pe(!0),pe.false_=new pe(!1),at.prototype=new Object,at.prototype.constructor=at,at.superclass=Object.prototype;function at(c){this.init(c)}at.prototype.init=function(c){this.left=null,this.right=null,this.node=c,this.depth=1},at.prototype.balance=function(){var c=this.left==null?0:this.left.depth,f=this.right==null?0:this.right.depth;if(c>f+1){var y=this.left.left==null?0:this.left.left.depth,b=this.left.right==null?0:this.left.right.depth;y<b&&this.left.rotateRR(),this.rotateLL()}else if(c+1<f){var v=this.right.right==null?0:this.right.right.depth,S=this.right.left==null?0:this.right.left.depth;S>v&&this.right.rotateLL(),this.rotateRR()}},at.prototype.rotateLL=function(){var c=this.node,f=this.right;this.node=this.left.node,this.right=this.left,this.left=this.left.left,this.right.left=this.right.right,this.right.right=f,this.right.node=c,this.right.updateInNewLocation(),this.updateInNewLocation()},at.prototype.rotateRR=function(){var c=this.node,f=this.left;this.node=this.right.node,this.left=this.right,this.right=this.right.right,this.left.right=this.left.left,this.left.left=f,this.left.node=c,this.left.updateInNewLocation(),this.updateInNewLocation()},at.prototype.updateInNewLocation=function(){this.getDepthFromChildren()},at.prototype.getDepthFromChildren=function(){this.depth=this.node==null?0:1,this.left!=null&&(this.depth=this.left.depth+1),this.right!=null&&this.depth<=this.right.depth&&(this.depth=this.right.depth+1)};function Fs(c,f){if(c===f)return 0;if(c.compareDocumentPosition){var y=c.compareDocumentPosition(f);return y&1||y&10?1:y&20?-1:0}for(var b=0,v=0,S=c;S!=null;S=S.parentNode||S.ownerElement)b++;for(var W=f;W!=null;W=W.parentNode||W.ownerElement)v++;if(b>v){for(;b>v;)c=c.parentNode||c.ownerElement,b--;if(c===f)return 1}else if(v>b){for(;v>b;)f=f.parentNode||f.ownerElement,v--;if(c===f)return-1}for(var _e=c.parentNode||c.ownerElement,Ce=f.parentNode||f.ownerElement;_e!==Ce;)c=_e,f=Ce,_e=c.parentNode||c.ownerElement,Ce=f.parentNode||f.ownerElement;var oe=ce.isAttribute(c),Ee=ce.isAttribute(f);if(oe&&!Ee)return-1;if(!oe&&Ee)return 1;if(_e)for(var At=oe?_e.attributes:_e.childNodes,Be=At.length,cr=0;cr<Be;cr+=1){var lr=At[cr];if(lr===c)return-1;if(lr===f)return 1}throw new Error("Unexpected: could not determine node order")}at.prototype.add=function(c){if(c===this.node)return!1;var f=Fs(c,this.node),y=!1;return f==-1?this.left==null?(this.left=new at(c),y=!0):(y=this.left.add(c),y&&this.balance()):f==1&&(this.right==null?(this.right=new at(c),y=!0):(y=this.right.add(c),y&&this.balance())),y&&this.getDepthFromChildren(),y},ae.prototype=new F,ae.prototype.constructor=ae,ae.superclass=F.prototype;function ae(){this.init()}ae.prototype.init=function(){this.tree=null,this.nodes=[],this.size=0},ae.prototype.toString=function(){var c=this.first();return c==null?"":this.stringForNode(c)},ae.prototype.evaluate=function(c){return this},ae.prototype.string=function(){return new he(this.toString())},ae.prototype.stringValue=function(){return this.toString()},ae.prototype.number=function(){return new ge(this.string())},ae.prototype.numberValue=function(){return Number(this.string())},ae.prototype.bool=function(){return new pe(this.booleanValue())},ae.prototype.booleanValue=function(){return!!this.size},ae.prototype.nodeset=function(){return this},ae.prototype.stringForNode=function(c){return c.nodeType==O.DOCUMENT_NODE||c.nodeType==O.ELEMENT_NODE||c.nodeType===O.DOCUMENT_FRAGMENT_NODE?this.stringForContainerNode(c):c.nodeType===O.ATTRIBUTE_NODE?c.value||c.nodeValue:c.isNamespaceNode?c.namespace:c.nodeValue},ae.prototype.stringForContainerNode=function(c){for(var f="",y=c.firstChild;y!=null;y=y.nextSibling){var b=y.nodeType;(b===1||b===3||b===4||b===9||b===11)&&(f+=this.stringForNode(y))}return f},ae.prototype.buildTree=function(){if(!this.tree&&this.nodes.length){this.tree=new at(this.nodes[0]);for(var c=1;c<this.nodes.length;c+=1)this.tree.add(this.nodes[c])}return this.tree},ae.prototype.first=function(){var c=this.buildTree();if(c==null)return null;for(;c.left!=null;)c=c.left;return c.node},ae.prototype.add=function(c){for(var f=0;f<this.nodes.length;f+=1)if(c===this.nodes[f])return;this.tree=null,this.nodes.push(c),this.size+=1},ae.prototype.addArray=function(c){var f=this;i(function(y){f.add(y)},c)},ae.prototype.toArray=function(){var c=[];return this.toArrayRec(this.buildTree(),c),c},ae.prototype.toArrayRec=function(c,f){c!=null&&(this.toArrayRec(c.left,f),f.push(c.node),this.toArrayRec(c.right,f))},ae.prototype.toUnsortedArray=function(){return this.nodes.slice()},ae.prototype.compareWithString=function(c,f){for(var y=this.toUnsortedArray(),b=0;b<y.length;b++){var v=y[b],S=new he(this.stringForNode(v)),W=f(S,c);if(W.booleanValue())return W}return new pe(!1)},ae.prototype.compareWithNumber=function(c,f){for(var y=this.toUnsortedArray(),b=0;b<y.length;b++){var v=y[b],S=new ge(this.stringForNode(v)),W=f(S,c);if(W.booleanValue())return W}return new pe(!1)},ae.prototype.compareWithBoolean=function(c,f){return f(this.bool(),c)},ae.prototype.compareWithNodeSet=function(c,f){for(var y=this.toUnsortedArray(),b=function(_e,Ce){return f(Ce,_e)},v=0;v<y.length;v++){var S=new he(this.stringForNode(y[v])),W=c.compareWithString(S,b);if(W.booleanValue())return W}return new pe(!1)},ae.compareWith=r(function(c,f){return ce.instance_of(f,he)?this.compareWithString(f,c):ce.instance_of(f,ge)?this.compareWithNumber(f,c):ce.instance_of(f,pe)?this.compareWithBoolean(f,c):this.compareWithNodeSet(f,c)}),ae.prototype.equals=ae.compareWith(Fe.equals),ae.prototype.notequal=ae.compareWith(Fe.notequal),ae.prototype.lessthan=ae.compareWith(Fe.lessthan),ae.prototype.greaterthan=ae.compareWith(Fe.greaterthan),ae.prototype.lessthanorequal=ae.compareWith(Fe.lessthanorequal),ae.prototype.greaterthanorequal=ae.compareWith(Fe.greaterthanorequal),ae.prototype.union=function(c){var f=new ae;return f.addArray(this.toUnsortedArray()),f.addArray(c.toUnsortedArray()),f},jt.prototype=new Object,jt.prototype.constructor=jt,jt.superclass=Object.prototype;function jt(c,f,y){this.isXPathNamespace=!0,this.ownerDocument=y.ownerDocument,this.nodeName="#namespace",this.prefix=c,this.localName=c,this.namespaceURI=f,this.nodeValue=f,this.ownerElement=y,this.nodeType=jt.XPATH_NAMESPACE_NODE}jt.prototype.toString=function(){return'{ "'+this.prefix+'", "'+this.namespaceURI+'" }'},Ht.prototype=new Object,Ht.prototype.constructor=Ht,Ht.superclass=Object.prototype;function Ht(c,f,y){this.variableResolver=c??new xn,this.namespaceResolver=f??new rn,this.functionResolver=y??new xt}Ht.prototype.extend=function(c){return T(new Ht,this,c)},xn.prototype=new Object,xn.prototype.constructor=xn,xn.superclass=Object.prototype;function xn(){}xn.prototype.getVariable=function(c,f){return null},xt.prototype=new Object,xt.prototype.constructor=xt,xt.superclass=Object.prototype;function xt(c){this.thisArg=c??me,this.functions=new Object,this.addStandardFunctions()}xt.prototype.addStandardFunctions=function(){this.functions["{}last"]=me.last,this.functions["{}position"]=me.position,this.functions["{}count"]=me.count,this.functions["{}id"]=me.id,this.functions["{}local-name"]=me.localName,this.functions["{}namespace-uri"]=me.namespaceURI,this.functions["{}name"]=me.name,this.functions["{}string"]=me.string,this.functions["{}concat"]=me.concat,this.functions["{}starts-with"]=me.startsWith,this.functions["{}contains"]=me.contains,this.functions["{}substring-before"]=me.substringBefore,this.functions["{}substring-after"]=me.substringAfter,this.functions["{}substring"]=me.substring,this.functions["{}string-length"]=me.stringLength,this.functions["{}normalize-space"]=me.normalizeSpace,this.functions["{}translate"]=me.translate,this.functions["{}boolean"]=me.boolean_,this.functions["{}not"]=me.not,this.functions["{}true"]=me.true_,this.functions["{}false"]=me.false_,this.functions["{}lang"]=me.lang,this.functions["{}number"]=me.number,this.functions["{}sum"]=me.sum,this.functions["{}floor"]=me.floor,this.functions["{}ceiling"]=me.ceiling,this.functions["{}round"]=me.round},xt.prototype.addFunction=function(c,f,y){this.functions["{"+c+"}"+f]=y},xt.getFunctionFromContext=function(c,f){var y=ce.resolveQName(c,f.namespaceResolver,f.contextNode,!1);if(y[0]===null)throw new Error("Cannot resolve QName "+name);return f.functionResolver.getFunction(y[1],y[0])},xt.prototype.getFunction=function(c,f){return this.functions["{"+f+"}"+c]},rn.prototype=new Object,rn.prototype.constructor=rn,rn.superclass=Object.prototype;function rn(){}rn.prototype.getNamespace=function(c,f){if(c=="xml")return U.XML_NAMESPACE_URI;if(c=="xmlns")return U.XMLNS_NAMESPACE_URI;for(f.nodeType==O.DOCUMENT_NODE?f=f.documentElement:f.nodeType==O.ATTRIBUTE_NODE?f=ye.getOwnerElement(f):f.nodeType!=O.ELEMENT_NODE&&(f=f.parentNode);f!=null&&f.nodeType==O.ELEMENT_NODE;){for(var y=f.attributes,b=0;b<y.length;b++){var v=y.item(b),S=v.name||v.nodeName;if(S==="xmlns"&&c===""||S==="xmlns:"+c)return String(v.value||v.nodeValue)}f=f.parentNode}return null};var me=new Object;me.last=function(c){if(arguments.length!=1)throw new Error("Function last expects ()");return new ge(c.contextSize)},me.position=function(c){if(arguments.length!=1)throw new Error("Function position expects ()");return new ge(c.contextPosition)},me.count=function(){var c=arguments[0],f;if(arguments.length!=2||!ce.instance_of(f=arguments[1].evaluate(c),ae))throw new Error("Function count expects (node-set)");return new ge(f.size)},me.id=function(){var c=arguments[0],f;if(arguments.length!=2)throw new Error("Function id expects (object)");f=arguments[1].evaluate(c),ce.instance_of(f,ae)?f=f.toArray().join(" "):f=f.stringValue();for(var y=f.split(/[\x0d\x0a\x09\x20]+/),b=new ae,v=c.contextNode.nodeType==O.DOCUMENT_NODE?c.contextNode:c.contextNode.ownerDocument,S=0;S<y.length;S++){var W;v.getElementById?W=v.getElementById(y[S]):W=ce.getElementById(v,y[S]),W!=null&&b.add(W)}return b},me.localName=function(c,f){var y;if(arguments.length==1)y=c.contextNode;else if(arguments.length==2)y=f.evaluate(c).first();else throw new Error("Function local-name expects (node-set?)");return y==null?new he(""):new he(y.localName||y.baseName||y.target||y.nodeName||"")},me.namespaceURI=function(){var c=arguments[0],f;if(arguments.length==1)f=c.contextNode;else if(arguments.length==2)f=arguments[1].evaluate(c).first();else throw new Error("Function namespace-uri expects (node-set?)");return f==null?new he(""):new he(f.namespaceURI)},me.name=function(){var c=arguments[0],f;if(arguments.length==1)f=c.contextNode;else if(arguments.length==2)f=arguments[1].evaluate(c).first();else throw new Error("Function name expects (node-set?)");return f==null?new he(""):f.nodeType==O.ELEMENT_NODE?new he(f.nodeName):f.nodeType==O.ATTRIBUTE_NODE?new he(f.name||f.nodeName):f.nodeType===O.PROCESSING_INSTRUCTION_NODE?new he(f.target||f.nodeName):f.localName==null?new he(""):new he(f.localName)},me.string=function(){var c=arguments[0];if(arguments.length==1)return new he(ae.prototype.stringForNode(c.contextNode));if(arguments.length==2)return arguments[1].evaluate(c).string();throw new Error("Function string expects (object?)")},me.concat=function(c){if(arguments.length<3)throw new Error("Function concat expects (string, string[, string]*)");for(var f="",y=1;y<arguments.length;y++)f+=arguments[y].evaluate(c).stringValue();return new he(f)},me.startsWith=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function startsWith expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();return new pe(f.substring(0,y.length)==y)},me.contains=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function contains expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();return new pe(f.indexOf(y)!==-1)},me.substringBefore=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function substring-before expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();return new he(f.substring(0,f.indexOf(y)))},me.substringAfter=function(){var c=arguments[0];if(arguments.length!=3)throw new Error("Function substring-after expects (string, string)");var f=arguments[1].evaluate(c).stringValue(),y=arguments[2].evaluate(c).stringValue();if(y.length==0)return new he(f);var b=f.indexOf(y);return b==-1?new he(""):new he(f.substring(b+y.length))},me.substring=function(){var c=arguments[0];if(!(arguments.length==3||arguments.length==4))throw new Error("Function substring expects (string, number, number?)");var f=arguments[1].evaluate(c).stringValue(),y=Math.round(arguments[2].evaluate(c).numberValue())-1,b=arguments.length==4?y+Math.round(arguments[3].evaluate(c).numberValue()):void 0;return new he(f.substring(y,b))},me.stringLength=function(){var c=arguments[0],f;if(arguments.length==1)f=ae.prototype.stringForNode(c.contextNode);else if(arguments.length==2)f=arguments[1].evaluate(c).stringValue();else throw new Error("Function string-length expects (string?)");return new ge(f.length)},me.normalizeSpace=function(){var c=arguments[0],f;if(arguments.length==1)f=ae.prototype.stringForNode(c.contextNode);else if(arguments.length==2)f=arguments[1].evaluate(c).stringValue();else throw new Error("Function normalize-space expects (string?)");for(var y=0,b=f.length-1;ce.isSpace(f.charCodeAt(b));)b--;for(var v="";y<=b&&ce.isSpace(f.charCodeAt(y));)y++;for(;y<=b;)if(ce.isSpace(f.charCodeAt(y)))for(v+=" ";y<=b&&ce.isSpace(f.charCodeAt(y));)y++;else v+=f.charAt(y),y++;return new he(v)},me.translate=function(c,f,y,b){if(arguments.length!=4)throw new Error("Function translate expects (string, string, string)");var v=f.evaluate(c).stringValue(),S=y.evaluate(c).stringValue(),W=b.evaluate(c).stringValue(),_e=s(function(oe,Ee,At){return Ee in oe||(oe[Ee]=At>W.length?"":W[At]),oe},{},S),Ce=h("",a(function(oe){return oe in _e?_e[oe]:oe},v));return new he(Ce)},me.boolean_=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function boolean expects (object)");return arguments[1].evaluate(c).bool()},me.not=function(c,f){if(arguments.length!=2)throw new Error("Function not expects (object)");return f.evaluate(c).bool().not()},me.true_=function(){if(arguments.length!=1)throw new Error("Function true expects ()");return pe.true_},me.false_=function(){if(arguments.length!=1)throw new Error("Function false expects ()");return pe.false_},me.lang=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function lang expects (string)");for(var f,y=c.contextNode;y!=null&&y.nodeType!=O.DOCUMENT_NODE;y=y.parentNode){var b=y.getAttributeNS(U.XML_NAMESPACE_URI,"lang");if(b!=null){f=String(b);break}}if(f==null)return pe.false_;var v=arguments[1].evaluate(c).stringValue();return new pe(f.substring(0,v.length)==v&&(f.length==v.length||f.charAt(v.length)=="-"))},me.number=function(){var c=arguments[0];if(!(arguments.length==1||arguments.length==2))throw new Error("Function number expects (object?)");return arguments.length==1?new ge(ae.prototype.stringForNode(c.contextNode)):arguments[1].evaluate(c).number()},me.sum=function(){var c=arguments[0],f;if(arguments.length!=2||!ce.instance_of(f=arguments[1].evaluate(c),ae))throw new Error("Function sum expects (node-set)");f=f.toUnsortedArray();for(var y=0,b=0;b<f.length;b++)y+=new ge(ae.prototype.stringForNode(f[b])).numberValue();return new ge(y)},me.floor=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function floor expects (number)");return new ge(Math.floor(arguments[1].evaluate(c).numberValue()))},me.ceiling=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function ceiling expects (number)");return new ge(Math.ceil(arguments[1].evaluate(c).numberValue()))},me.round=function(){var c=arguments[0];if(arguments.length!=2)throw new Error("Function round expects (number)");return new ge(Math.round(arguments[1].evaluate(c).numberValue()))};var ce=new Object;ce.isAttribute=function(c){return c&&(c.nodeType===O.ATTRIBUTE_NODE||c.ownerElement)},ce.splitQName=function(c){var f=c.indexOf(":");return f==-1?[null,c]:[c.substring(0,f),c.substring(f+1)]},ce.resolveQName=function(c,f,y,b){var v=ce.splitQName(c);return v[0]!=null?v[0]=f.getNamespace(v[0],y):b?(v[0]=f.getNamespace("",y),v[0]==null&&(v[0]="")):v[0]="",v},ce.isSpace=function(c){return c==9||c==13||c==10||c==32},ce.isLetter=function(c){return c>=65&&c<=90||c>=97&&c<=122||c>=192&&c<=214||c>=216&&c<=246||c>=248&&c<=255||c>=256&&c<=305||c>=308&&c<=318||c>=321&&c<=328||c>=330&&c<=382||c>=384&&c<=451||c>=461&&c<=496||c>=500&&c<=501||c>=506&&c<=535||c>=592&&c<=680||c>=699&&c<=705||c==902||c>=904&&c<=906||c==908||c>=910&&c<=929||c>=931&&c<=974||c>=976&&c<=982||c==986||c==988||c==990||c==992||c>=994&&c<=1011||c>=1025&&c<=1036||c>=1038&&c<=1103||c>=1105&&c<=1116||c>=1118&&c<=1153||c>=1168&&c<=1220||c>=1223&&c<=1224||c>=1227&&c<=1228||c>=1232&&c<=1259||c>=1262&&c<=1269||c>=1272&&c<=1273||c>=1329&&c<=1366||c==1369||c>=1377&&c<=1414||c>=1488&&c<=1514||c>=1520&&c<=1522||c>=1569&&c<=1594||c>=1601&&c<=1610||c>=1649&&c<=1719||c>=1722&&c<=1726||c>=1728&&c<=1742||c>=1744&&c<=1747||c==1749||c>=1765&&c<=1766||c>=2309&&c<=2361||c==2365||c>=2392&&c<=2401||c>=2437&&c<=2444||c>=2447&&c<=2448||c>=2451&&c<=2472||c>=2474&&c<=2480||c==2482||c>=2486&&c<=2489||c>=2524&&c<=2525||c>=2527&&c<=2529||c>=2544&&c<=2545||c>=2565&&c<=2570||c>=2575&&c<=2576||c>=2579&&c<=2600||c>=2602&&c<=2608||c>=2610&&c<=2611||c>=2613&&c<=2614||c>=2616&&c<=2617||c>=2649&&c<=2652||c==2654||c>=2674&&c<=2676||c>=2693&&c<=2699||c==2701||c>=2703&&c<=2705||c>=2707&&c<=2728||c>=2730&&c<=2736||c>=2738&&c<=2739||c>=2741&&c<=2745||c==2749||c==2784||c>=2821&&c<=2828||c>=2831&&c<=2832||c>=2835&&c<=2856||c>=2858&&c<=2864||c>=2866&&c<=2867||c>=2870&&c<=2873||c==2877||c>=2908&&c<=2909||c>=2911&&c<=2913||c>=2949&&c<=2954||c>=2958&&c<=2960||c>=2962&&c<=2965||c>=2969&&c<=2970||c==2972||c>=2974&&c<=2975||c>=2979&&c<=2980||c>=2984&&c<=2986||c>=2990&&c<=2997||c>=2999&&c<=3001||c>=3077&&c<=3084||c>=3086&&c<=3088||c>=3090&&c<=3112||c>=3114&&c<=3123||c>=3125&&c<=3129||c>=3168&&c<=3169||c>=3205&&c<=3212||c>=3214&&c<=3216||c>=3218&&c<=3240||c>=3242&&c<=3251||c>=3253&&c<=3257||c==3294||c>=3296&&c<=3297||c>=3333&&c<=3340||c>=3342&&c<=3344||c>=3346&&c<=3368||c>=3370&&c<=3385||c>=3424&&c<=3425||c>=3585&&c<=3630||c==3632||c>=3634&&c<=3635||c>=3648&&c<=3653||c>=3713&&c<=3714||c==3716||c>=3719&&c<=3720||c==3722||c==3725||c>=3732&&c<=3735||c>=3737&&c<=3743||c>=3745&&c<=3747||c==3749||c==3751||c>=3754&&c<=3755||c>=3757&&c<=3758||c==3760||c>=3762&&c<=3763||c==3773||c>=3776&&c<=3780||c>=3904&&c<=3911||c>=3913&&c<=3945||c>=4256&&c<=4293||c>=4304&&c<=4342||c==4352||c>=4354&&c<=4355||c>=4357&&c<=4359||c==4361||c>=4363&&c<=4364||c>=4366&&c<=4370||c==4412||c==4414||c==4416||c==4428||c==4430||c==4432||c>=4436&&c<=4437||c==4441||c>=4447&&c<=4449||c==4451||c==4453||c==4455||c==4457||c>=4461&&c<=4462||c>=4466&&c<=4467||c==4469||c==4510||c==4520||c==4523||c>=4526&&c<=4527||c>=4535&&c<=4536||c==4538||c>=4540&&c<=4546||c==4587||c==4592||c==4601||c>=7680&&c<=7835||c>=7840&&c<=7929||c>=7936&&c<=7957||c>=7960&&c<=7965||c>=7968&&c<=8005||c>=8008&&c<=8013||c>=8016&&c<=8023||c==8025||c==8027||c==8029||c>=8031&&c<=8061||c>=8064&&c<=8116||c>=8118&&c<=8124||c==8126||c>=8130&&c<=8132||c>=8134&&c<=8140||c>=8144&&c<=8147||c>=8150&&c<=8155||c>=8160&&c<=8172||c>=8178&&c<=8180||c>=8182&&c<=8188||c==8486||c>=8490&&c<=8491||c==8494||c>=8576&&c<=8578||c>=12353&&c<=12436||c>=12449&&c<=12538||c>=12549&&c<=12588||c>=44032&&c<=55203||c>=19968&&c<=40869||c==12295||c>=12321&&c<=12329},ce.isNCNameChar=function(c){return c>=48&&c<=57||c>=1632&&c<=1641||c>=1776&&c<=1785||c>=2406&&c<=2415||c>=2534&&c<=2543||c>=2662&&c<=2671||c>=2790&&c<=2799||c>=2918&&c<=2927||c>=3047&&c<=3055||c>=3174&&c<=3183||c>=3302&&c<=3311||c>=3430&&c<=3439||c>=3664&&c<=3673||c>=3792&&c<=3801||c>=3872&&c<=3881||c==46||c==45||c==95||ce.isLetter(c)||c>=768&&c<=837||c>=864&&c<=865||c>=1155&&c<=1158||c>=1425&&c<=1441||c>=1443&&c<=1465||c>=1467&&c<=1469||c==1471||c>=1473&&c<=1474||c==1476||c>=1611&&c<=1618||c==1648||c>=1750&&c<=1756||c>=1757&&c<=1759||c>=1760&&c<=1764||c>=1767&&c<=1768||c>=1770&&c<=1773||c>=2305&&c<=2307||c==2364||c>=2366&&c<=2380||c==2381||c>=2385&&c<=2388||c>=2402&&c<=2403||c>=2433&&c<=2435||c==2492||c==2494||c==2495||c>=2496&&c<=2500||c>=2503&&c<=2504||c>=2507&&c<=2509||c==2519||c>=2530&&c<=2531||c==2562||c==2620||c==2622||c==2623||c>=2624&&c<=2626||c>=2631&&c<=2632||c>=2635&&c<=2637||c>=2672&&c<=2673||c>=2689&&c<=2691||c==2748||c>=2750&&c<=2757||c>=2759&&c<=2761||c>=2763&&c<=2765||c>=2817&&c<=2819||c==2876||c>=2878&&c<=2883||c>=2887&&c<=2888||c>=2891&&c<=2893||c>=2902&&c<=2903||c>=2946&&c<=2947||c>=3006&&c<=3010||c>=3014&&c<=3016||c>=3018&&c<=3021||c==3031||c>=3073&&c<=3075||c>=3134&&c<=3140||c>=3142&&c<=3144||c>=3146&&c<=3149||c>=3157&&c<=3158||c>=3202&&c<=3203||c>=3262&&c<=3268||c>=3270&&c<=3272||c>=3274&&c<=3277||c>=3285&&c<=3286||c>=3330&&c<=3331||c>=3390&&c<=3395||c>=3398&&c<=3400||c>=3402&&c<=3405||c==3415||c==3633||c>=3636&&c<=3642||c>=3655&&c<=3662||c==3761||c>=3764&&c<=3769||c>=3771&&c<=3772||c>=3784&&c<=3789||c>=3864&&c<=3865||c==3893||c==3895||c==3897||c==3902||c==3903||c>=3953&&c<=3972||c>=3974&&c<=3979||c>=3984&&c<=3989||c==3991||c>=3993&&c<=4013||c>=4017&&c<=4023||c==4025||c>=8400&&c<=8412||c==8417||c>=12330&&c<=12335||c==12441||c==12442||c==183||c==720||c==721||c==903||c==1600||c==3654||c==3782||c==12293||c>=12337&&c<=12341||c>=12445&&c<=12446||c>=12540&&c<=12542},ce.coalesceText=function(c){for(var f=c.firstChild;f!=null;f=f.nextSibling)if(f.nodeType==O.TEXT_NODE||f.nodeType==O.CDATA_SECTION_NODE){var y=f.nodeValue,b=f;for(f=f.nextSibling;f!=null&&(f.nodeType==O.TEXT_NODE||f.nodeType==O.CDATA_SECTION_NODE);){y+=f.nodeValue;var v=f;f=f.nextSibling,v.parentNode.removeChild(v)}if(b.nodeType==O.CDATA_SECTION_NODE){var S=b.parentNode;if(b.nextSibling==null)S.removeChild(b),S.appendChild(S.ownerDocument.createTextNode(y));else{var W=b.nextSibling;S.removeChild(b),S.insertBefore(S.ownerDocument.createTextNode(y),W)}}else b.nodeValue=y;if(f==null)break}else f.nodeType==O.ELEMENT_NODE&&ce.coalesceText(f)},ce.instance_of=function(c,f){for(;c!=null;){if(c.constructor===f)return!0;if(c===Object)return!1;c=c.constructor.superclass}return!1},ce.getElementById=function(c,f){if(c.nodeType==O.ELEMENT_NODE&&(c.getAttribute("id")==f||c.getAttributeNS(null,"id")==f))return c;for(var y=c.firstChild;y!=null;y=y.nextSibling){var b=ce.getElementById(y,f);if(b!=null)return b}return null};var Kt=function(){function c(y,b){var v=b?": "+b.toString():"";switch(y){case f.INVALID_EXPRESSION_ERR:return"Invalid expression"+v;case f.TYPE_ERR:return"Type error"+v}return null}function f(y,b,v){var S=Error.call(this,c(y,b)||v);return S.code=y,S.exception=b,S}return f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,f.superclass=Error,f.prototype.toString=function(){return this.message},f.fromMessage=function(y,b){return new f(null,b,y)},f.INVALID_EXPRESSION_ERR=51,f.TYPE_ERR=52,f}();Pt.prototype={},Pt.prototype.constructor=Pt,Pt.superclass=Object.prototype;function Pt(c,f,y){this.xpath=y.parse(c),this.context=new Ht,this.context.namespaceResolver=new An(f)}Pt.getOwnerDocument=function(c){return c.nodeType===O.DOCUMENT_NODE?c:c.ownerDocument},Pt.detectHtmlDom=function(c){if(!c)return!1;var f=Pt.getOwnerDocument(c);try{return f.implementation.hasFeature("HTML","2.0")}catch{return!0}},Pt.prototype.evaluate=function(c,f,y){this.context.expressionContextNode=c,this.context.caseInsensitive=Pt.detectHtmlDom(c);var b=this.xpath.evaluate(this.context);return new I(b,f)},An.prototype={},An.prototype.constructor=An,An.superclass=Object.prototype;function An(c){this.xpathNSResolver=c}An.prototype.getNamespace=function(c,f){return this.xpathNSResolver==null?null:this.xpathNSResolver.lookupNamespaceURI(c)},D.prototype={},D.prototype.constructor=D,D.superclass=Object.prototype;function D(c){this.node=c,this.namespaceResolver=new rn}D.prototype.lookupNamespaceURI=function(c){return this.namespaceResolver.getNamespace(c,this.node)},I.prototype={},I.prototype.constructor=I,I.superclass=Object.prototype;function I(c,f){switch(f==I.ANY_TYPE&&(c.constructor===he?f=I.STRING_TYPE:c.constructor===ge?f=I.NUMBER_TYPE:c.constructor===pe?f=I.BOOLEAN_TYPE:c.constructor===ae&&(f=I.UNORDERED_NODE_ITERATOR_TYPE)),this.resultType=f,f){case I.NUMBER_TYPE:this.numberValue=c.numberValue();return;case I.STRING_TYPE:this.stringValue=c.stringValue();return;case I.BOOLEAN_TYPE:this.booleanValue=c.booleanValue();return;case I.ANY_UNORDERED_NODE_TYPE:case I.FIRST_ORDERED_NODE_TYPE:if(c.constructor===ae){this.singleNodeValue=c.first();return}break;case I.UNORDERED_NODE_ITERATOR_TYPE:case I.ORDERED_NODE_ITERATOR_TYPE:if(c.constructor===ae){this.invalidIteratorState=!1,this.nodes=c.toArray(),this.iteratorIndex=0;return}break;case I.UNORDERED_NODE_SNAPSHOT_TYPE:case I.ORDERED_NODE_SNAPSHOT_TYPE:if(c.constructor===ae){this.nodes=c.toArray(),this.snapshotLength=this.nodes.length;return}break}throw new Kt(Kt.TYPE_ERR)}I.prototype.iterateNext=function(){if(this.resultType!=I.UNORDERED_NODE_ITERATOR_TYPE&&this.resultType!=I.ORDERED_NODE_ITERATOR_TYPE)throw new Kt(Kt.TYPE_ERR);return this.nodes[this.iteratorIndex++]},I.prototype.snapshotItem=function(c){if(this.resultType!=I.UNORDERED_NODE_SNAPSHOT_TYPE&&this.resultType!=I.ORDERED_NODE_SNAPSHOT_TYPE)throw new Kt(Kt.TYPE_ERR);return this.nodes[c]},I.ANY_TYPE=0,I.NUMBER_TYPE=1,I.STRING_TYPE=2,I.BOOLEAN_TYPE=3,I.UNORDERED_NODE_ITERATOR_TYPE=4,I.ORDERED_NODE_ITERATOR_TYPE=5,I.UNORDERED_NODE_SNAPSHOT_TYPE=6,I.ORDERED_NODE_SNAPSHOT_TYPE=7,I.ANY_UNORDERED_NODE_TYPE=8,I.FIRST_ORDERED_NODE_TYPE=9;function M(c,f){c.createExpression=function(y,b){try{return new Pt(y,b,f)}catch(v){throw new Kt(Kt.INVALID_EXPRESSION_ERR,v)}},c.createNSResolver=function(y){return new D(y)},c.evaluate=function(y,b,v,S,W){if(S<0||S>9)throw{code:0,toString:function(){return"Request type not supported"}};return c.createExpression(y,v,f).evaluate(b,S,W)}}try{var te=!0;try{document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("XPath",null)&&(te=!1)}catch{}te&&M(document,new x)}catch{}M(n,new x),function(){var c=new x,f=new rn,y=new xt,b=new xn;function v(Z){return{getNamespace:function(ze,Et){var ur=Z(ze,Et);return ur||f.getNamespace(ze,Et)}}}function S(Z){return v(Z.getNamespace.bind(Z))}function W(Z){return v(function(ze){return Z[ze]})}function _e(Z){return Z&&typeof Z.getNamespace=="function"?S(Z):typeof Z=="function"?v(Z):typeof Z=="object"?W(Z):f}function Ce(Z){if(Z===null||typeof Z>"u"||Z instanceof he||Z instanceof pe||Z instanceof ge||Z instanceof ae)return Z;switch(typeof Z){case"string":return new he(Z);case"boolean":return new pe(Z);case"number":return new ge(Z)}var ze=new ae;return ze.addArray([].concat(Z)),ze}function oe(Z){return function(ze){var Et=Array.prototype.slice.call(arguments,1).map(function(Bw){return Bw.evaluate(ze)}),ur=Z.apply(this,[].concat(ze,Et));return Ce(ur)}}function Ee(Z){return{getFunction:function(ze,Et){var ur=Z(ze,Et);return ur?oe(ur):y.getFunction(ze,Et)}}}function At(Z){return Ee(Z.getFunction.bind(Z))}function Be(Z){return Ee(function(ze){return Z[ze]})}function cr(Z){return Z&&typeof Z.getFunction=="function"?At(Z):typeof Z=="function"?Ee(Z):typeof Z=="object"?Be(Z):y}function lr(Z){return{getVariable:function(ze,Et){var ur=Z(ze,Et);return Ce(ur)}}}function Ow(Z){if(Z){if(typeof Z.getVariable=="function")return lr(Z.getVariable.bind(Z));if(typeof Z=="function")return lr(Z);if(typeof Z=="object")return lr(function(ze){return Z[ze]})}return b}function sh(Z,ze,Et){Z in Et&&(ze[Z]=Et[Z])}function Dw(Z){var ze=new Ht;return Z?(ze.namespaceResolver=_e(Z.namespaces),ze.functionResolver=cr(Z.functions),ze.variableResolver=Ow(Z.variables),ze.expressionContextNode=Z.node,sh("allowAnyNamespaceForNoPrefix",ze,Z),sh("isHtml",ze,Z)):ze.namespaceResolver=f,ze}function Rw(Z,ze){var Et=Dw(ze);return Z.evaluate(Et)}var jw={evaluate:function(Z){return Rw(this.expression,Z)},evaluateNumber:function(Z){return this.evaluate(Z).numberValue()},evaluateString:function(Z){return this.evaluate(Z).stringValue()},evaluateBoolean:function(Z){return this.evaluate(Z).booleanValue()},evaluateNodeSet:function(Z){return this.evaluate(Z).nodeset()},select:function(Z){return this.evaluateNodeSet(Z).toArray()},select1:function(Z){return this.select(Z)[0]}};function Pw(Z){var ze=c.parse(Z);return Object.create(jw,{expression:{value:ze}})}n.parse=Pw}(),T(n,{XPath:U,XPathParser:x,XPathResult:I,Step:ee,PathExpr:ye,NodeTest:se,LocationPath:nn,OrOperation:J,AndOperation:Ae,BarOperation:Q,EqualsOperation:R,NotEqualOperation:L,LessThanOperation:j,GreaterThanOperation:N,LessThanOrEqualOperation:k,GreaterThanOrEqualOperation:B,PlusOperation:K,MinusOperation:de,MultiplyOperation:ie,DivOperation:ve,ModOperation:ke,UnaryMinusOperation:G,FunctionCall:Rt,VariableReference:tt,XPathContext:Ht,XNodeSet:ae,XBoolean:pe,XString:he,XNumber:ge,NamespaceResolver:rn,FunctionResolver:xt,VariableResolver:xn,Utilities:ce}),n.select=function(c,f,y){return n.selectWithResolver(c,f,null,y)},n.useNamespaces=function(c){var f={mappings:c||{},lookupNamespaceURI:function(y){return this.mappings[y]}};return function(y,b,v){return n.selectWithResolver(y,b,f,v)}},n.selectWithResolver=function(c,f,y,b){var v=new Pt(c,y,new x),S=I.ANY_TYPE,W=v.evaluate(f,S,null);return W.resultType==I.STRING_TYPE?W=W.stringValue:W.resultType==I.NUMBER_TYPE?W=W.numberValue:W.resultType==I.BOOLEAN_TYPE?W=W.booleanValue:(W=W.nodes,b&&(W=W[0])),W},n.select1=function(c,f){return n.select(c,f,!0)};var we=function(c){return c&&typeof c.nodeType=="number"&&Number.isInteger(c.nodeType)&&c.nodeType>=1&&c.nodeType<=11&&typeof c.nodeName=="string"},nt=function(c){return Array.isArray(c)&&c.every(we)},Re=function(c){return function(f){return we(f)&&f.nodeType===c}};T(n,{isNodeLike:we,isArrayOfNodes:nt,isElement:Re(O.ELEMENT_NODE),isAttribute:Re(O.ATTRIBUTE_NODE),isTextNode:Re(O.TEXT_NODE),isCDATASection:Re(O.CDATA_SECTION_NODE),isProcessingInstruction:Re(O.PROCESSING_INSTRUCTION_NODE),isComment:Re(O.COMMENT_NODE),isDocumentNode:Re(O.DOCUMENT_NODE),isDocumentTypeNode:Re(O.DOCUMENT_TYPE_NODE),isDocumentFragment:Re(O.DOCUMENT_FRAGMENT_NODE)})})(e)})(Ll);var $e={};Object.defineProperty($e,"__esModule",{value:!0});$e.assertIsDocumentFragmentNode=$e.assertIsDocumentTypeNode=$e.assertIsDocumentNode=$e.assertIsCommentNode=$e.assertIsProcessingInstructionNode=$e.assertIsCDATASectionNode=$e.assertIsTextNode=$e.assertIsAttributeNode=$e.assertIsElementNode=$e.isDocumentFragmentNode=$e.isDocumentTypeNode=$e.isDocumentNode=$e.isCommentNode=$e.isProcessingInstructionNode=$e.isCDATASectionNode=$e.isTextNode=$e.isAttributeNode=$e.isElementNode=$e.assertIsArrayOfNodes=$e.isArrayOfNodes=$e.assertIsNodeLike=$e.isNodeLike=$e.NodeTypes=void 0;var Ye;(function(t){t[t.ELEMENT_NODE=1]="ELEMENT_NODE",t[t.ATTRIBUTE_NODE=2]="ATTRIBUTE_NODE",t[t.TEXT_NODE=3]="TEXT_NODE",t[t.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",t[t.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",t[t.COMMENT_NODE=8]="COMMENT_NODE",t[t.DOCUMENT_NODE=9]="DOCUMENT_NODE",t[t.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",t[t.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"})(Ye||($e.NodeTypes=Ye={}));function Fl(t){return t&&typeof t=="object"&&Number.isInteger(t.nodeType)&&t.nodeType>=1&&t.nodeType<=11&&typeof t.nodeName=="string"&&typeof t.appendChild=="function"&&typeof t.removeChild=="function"}$e.isNodeLike=Fl;function L6(t){if(!Fl(t))throw new Error(`Value is not a Node-like object. Received: ${t}`)}$e.assertIsNodeLike=L6;function ew(t){return Array.isArray(t)&&t.every(Fl)}$e.isArrayOfNodes=ew;function F6(t){if(!ew(t))throw new Error("Value is not an array of Nodes")}$e.assertIsArrayOfNodes=F6;function Ln(t,e){return Fl(e)&&e.nodeType===t}function or(t,e){const n=Object.keys(Ye).find(r=>Ye[r]===t);if(!Ln(t,e))throw new Error(`Value is not of type ${n}`)}const U6=t=>Ln(Ye.ELEMENT_NODE,t);$e.isElementNode=U6;const M6=t=>Ln(Ye.ATTRIBUTE_NODE,t);$e.isAttributeNode=M6;const q6=t=>Ln(Ye.TEXT_NODE,t);$e.isTextNode=q6;const V6=t=>Ln(Ye.CDATA_SECTION_NODE,t);$e.isCDATASectionNode=V6;const H6=t=>Ln(Ye.PROCESSING_INSTRUCTION_NODE,t);$e.isProcessingInstructionNode=H6;const K6=t=>Ln(Ye.COMMENT_NODE,t);$e.isCommentNode=K6;const G6=t=>Ln(Ye.DOCUMENT_NODE,t);$e.isDocumentNode=G6;const W6=t=>Ln(Ye.DOCUMENT_TYPE_NODE,t);$e.isDocumentTypeNode=W6;const X6=t=>Ln(Ye.DOCUMENT_FRAGMENT_NODE,t);$e.isDocumentFragmentNode=X6;const J6=t=>{or(Ye.ELEMENT_NODE,t)};$e.assertIsElementNode=J6;const Y6=t=>or(Ye.ATTRIBUTE_NODE,t);$e.assertIsAttributeNode=Y6;const Z6=t=>or(Ye.TEXT_NODE,t);$e.assertIsTextNode=Z6;const Q6=t=>or(Ye.CDATA_SECTION_NODE,t);$e.assertIsCDATASectionNode=Q6;const eS=t=>or(Ye.PROCESSING_INSTRUCTION_NODE,t);$e.assertIsProcessingInstructionNode=eS;const tS=t=>or(Ye.COMMENT_NODE,t);$e.assertIsCommentNode=tS;const nS=t=>or(Ye.DOCUMENT_NODE,t);$e.assertIsDocumentNode=nS;const rS=t=>or(Ye.DOCUMENT_TYPE_NODE,t);$e.assertIsDocumentTypeNode=rS;const iS=t=>or(Ye.DOCUMENT_FRAGMENT_NODE,t);$e.assertIsDocumentFragmentNode=iS;(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.validateDigestValue=t.findAncestorNs=t.derToPem=t.pemToDer=t.normalizePem=t.BASE64_REGEX=t.EXTRACT_X509_CERTS=t.PEM_FORMAT_REGEX=t.encodeSpecialCharactersInText=t.encodeSpecialCharactersInAttribute=t.findChilds=t.findChildren=t.findAttr=t.isArrayHasLength=void 0;const e=Ll,n=$e;function r(F){return Array.isArray(F)&&F.length>0}t.isArrayHasLength=r;function i(F,H,G){return F.localName===H&&(F.namespaceURI===G||G==null)}function s(F,H,G,Y){return F.localName===H&&(!F.namespaceURI&&(Y==null?void 0:Y.namespaceURI)===G||G==null)}function a(F,H,G){for(let Y=0;Y<F.attributes.length;Y++){const J=F.attributes[Y];if(i(J,H,G)||s(J,H,G,F))return J}return null}t.findAttr=a;function l(F,H,G){const Y=F.documentElement??F,J=[];for(let Ae=0;Ae<Y.childNodes.length;Ae++){const R=Y.childNodes[Ae];n.isElementNode(R)&&R.localName===H&&(R.namespaceURI===G||G==null)&&J.push(R)}return J}t.findChildren=l;function u(F,H,G){return l(F,H,G)}t.findChilds=u;const d={"&":"&","<":"<",'"':""","\r":"
","\n":"
"," ":"	"},p={"&":"&","<":"<",">":">","\r":"
"};function h(F){return F.replace(/([&<"\r\n\t])/g,function(H,G){return d[G]})}t.encodeSpecialCharactersInAttribute=h;function g(F){return F.replace(/([&<>\r])/g,function(H,G){return p[G]})}t.encodeSpecialCharactersInText=g,t.PEM_FORMAT_REGEX=new RegExp("^-----BEGIN [A-Z ]{1,48}-----([^-]*)-----END [A-Z ]{1,48}-----$","s"),t.EXTRACT_X509_CERTS=new RegExp("-----BEGIN CERTIFICATE-----[^-]*-----END CERTIFICATE-----","g"),t.BASE64_REGEX=new RegExp("^(?:[A-Za-z0-9\\+\\/]{4}\\n{0,1})*(?:[A-Za-z0-9\\+\\/]{2}==|[A-Za-z0-9\\+\\/]{3}=)?$","s");function $(F){return`${(F.trim().replace(/(\r\n|\r)/g,`
|
|
286
286
|
`).match(/.{1,64}/g)??[]).join(`
|
|
287
287
|
`)}
|
|
288
|
-
`}t.normalizePem=$;function A(F){if(!t.PEM_FORMAT_REGEX.test(F.trim()))throw new Error("Invalid PEM format.");return Buffer.from(F.replace(/(\r\n|\r)/g,"").replace(/-----BEGIN [A-Z\x20]{1,48}-----\n?/,"").replace(/-----END [A-Z\x20]{1,48}-----\n?/,""),"base64")}t.pemToDer=A;function z(F,
|
|
288
|
+
`}t.normalizePem=$;function A(F){if(!t.PEM_FORMAT_REGEX.test(F.trim()))throw new Error("Invalid PEM format.");return Buffer.from(F.replace(/(\r\n|\r)/g,"").replace(/-----BEGIN [A-Z\x20]{1,48}-----\n?/,"").replace(/-----END [A-Z\x20]{1,48}-----\n?/,""),"base64")}t.pemToDer=A;function z(F,H){const G=Buffer.isBuffer(F)?F.toString("base64").trim():F.replace(/(\r\n|\r)/g,"").trim();if(t.PEM_FORMAT_REGEX.test(G))return $(G);if(t.BASE64_REGEX.test(G.replace(/ /g,""))){if(H==null)throw new Error("PEM label is required when DER is given.");const Y=`-----BEGIN ${H}-----
|
|
289
289
|
${G.replace(/ /g,"")}
|
|
290
|
-
-----END ${
|
|
290
|
+
-----END ${H}-----`;return $(Y)}throw new Error("Unknown DER format.")}t.derToPem=z;function T(F,H=[]){if(!n.isElementNode(F.parentNode))return H;const G=F.parentNode;if(!G)return H;if(G.attributes&&G.attributes.length>0)for(let Y=0;Y<G.attributes.length;Y++){const J=G.attributes[Y];J&&J.nodeName&&J.nodeName.search(/^xmlns:?/)!==-1&&H.push({prefix:J.nodeName.replace(/^xmlns:?/,""),namespaceURI:J.nodeValue||""})}return T(G,H)}function O(F){const H=F.attributes;for(let G=0;G<H.length;G++){const Y=H[G].nodeName;if(Y.search(/^xmlns:?/)!==-1)return Y.replace(/^xmlns:?/,"")}return F.prefix||""}function x(F){return F.every(H=>n.isElementNode(H))}function U(F,H,G){if(H==null)return[];const Y=e.selectWithResolver(H,F,G);if(!r(Y))return[];if(!x(Y))throw new Error("Document subset must be list of elements");const J=T(Y[0]),Ae=[];for(let j=0;j<J.length;j++){let N=!0;for(const k in Ae)if(Ae[k].prefix===J[j].prefix){N=!1;break}N&&Ae.push(J[j])}const R=[],L=O(Y[0]);for(const j of Ae)j.prefix!==L&&R.push(j);return R}t.findAncestorNs=U;function q(F,H){const G=Buffer.from(F,"base64"),Y=Buffer.from(H,"base64");if(typeof G.equals=="function")return G.equals(Y);if(G.length!==Y.length)return!1;for(let J=0;J<G.length;J++)if(G[J]!==Y[J])return!1;return!0}t.validateDigestValue=q})(Os);Object.defineProperty(ai,"__esModule",{value:!0});ai.C14nCanonicalizationWithComments=ai.C14nCanonicalization=void 0;const Xs=Os,vu=$e;class tw{constructor(){this.includeComments=!1,this.includeComments=!1}attrCompare(e,n){if(!e.namespaceURI&&n.namespaceURI)return-1;if(!n.namespaceURI&&e.namespaceURI)return 1;const r=e.namespaceURI+e.localName,i=n.namespaceURI+n.localName;return r===i?0:r<i?-1:1}nsCompare(e,n){const r=e.prefix,i=n.prefix;return r===i?0:r.localeCompare(i)}renderAttrs(e){let n,r;const i=[];if(vu.isCommentNode(e))return this.renderComment(e);if(e.attributes)for(n=0;n<e.attributes.length;++n)r=e.attributes[n],r.name.indexOf("xmlns")!==0&&i.push(r);return i.sort(this.attrCompare),i.map(a=>` ${a.name}="${Xs.encodeSpecialCharactersInAttribute(a.value)}"`).join("")}renderNs(e,n,r,i,s){let a,l;const u=[];let d=r;const p=[],h=e.namespaceURI||"";if(e.prefix?n.indexOf(e.prefix)===-1&&(p.push({prefix:e.prefix,namespaceURI:e.namespaceURI||i[e.prefix]}),n.push(e.prefix)):r!==h&&(d=e.namespaceURI||"",u.push(' xmlns="',d,'"')),e.attributes)for(a=0;a<e.attributes.length;++a)l=e.attributes[a],l.prefix==="xmlns"&&n.indexOf(l.localName)===-1&&(p.push({prefix:l.localName,namespaceURI:l.value}),n.push(l.localName)),l.prefix&&n.indexOf(l.prefix)===-1&&l.prefix!=="xmlns"&&l.prefix!=="xml"&&(p.push({prefix:l.prefix,namespaceURI:l.namespaceURI}),n.push(l.prefix));if(Xs.isArrayHasLength(s))for(const g of s){let $=!1;for(const A of p)A.prefix===g.prefix&&A.namespaceURI===g.namespaceURI&&($=!0);$||p.push(g)}return p.sort(this.nsCompare),u.push(...p.map(g=>g.prefix?` xmlns:${g.prefix}="${g.namespaceURI}"`:` xmlns="${g.namespaceURI}"`)),{rendered:u.join(""),newDefaultNs:d}}processInner(e,n,r,i,s){if(vu.isCommentNode(e))return this.renderComment(e);if(e.data)return Xs.encodeSpecialCharactersInText(e.data);if(vu.isElementNode(e)){let a,l;const u=this.renderNs(e,n,r,i,s),d=["<",e.tagName,u.rendered,this.renderAttrs(e),">"];for(a=0;a<e.childNodes.length;++a)l=n.slice(0),d.push(this.processInner(e.childNodes[a],l,u.newDefaultNs,i,[]));return d.push("</",e.tagName,">"),d.join("")}throw new Error(`Unable to canonicalize node type: ${e.nodeType}`)}renderComment(e){if(!this.includeComments)return"";const n=e.ownerDocument===e.parentNode;let r=!1,i=!1;if(n){let u=e,d=e;for(;u!==null;){if(u===e.ownerDocument.documentElement){r=!0;break}u=u.nextSibling}for(;d!==null;){if(d===e.ownerDocument.documentElement){i=!0;break}d=d.previousSibling}}const s=i?`
|
|
291
291
|
`:"",a=r?`
|
|
292
292
|
`:"",l=Xs.encodeSpecialCharactersInText(e.data);return`${s}<!--${l}-->${a}`}process(e,n){n=n||{};const r=n.defaultNs||"",i=n.defaultNsForPrefix||{},s=n.ancestorNamespaces||[],a=[];for(let u=0;u<s.length;u++)a.push(s[u].prefix);return this.processInner(e,a,r,i,s)}getAlgorithmName(){return"http://www.w3.org/TR/2001/REC-xml-c14n-20010315"}}ai.C14nCanonicalization=tw;class oS extends tw{constructor(){super(),this.includeComments=!0}getAlgorithmName(){return"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"}}ai.C14nCanonicalizationWithComments=oS;var ci={};Object.defineProperty(ci,"__esModule",{value:!0});ci.ExclusiveCanonicalizationWithComments=ci.ExclusiveCanonicalization=void 0;const zr=Os,bu=$e;function $u(t,e,n){let r=!1;return t.forEach(function(i){i.prefix===e&&i.namespaceURI===n&&(r=!0)}),r}class nw{constructor(){this.includeComments=!1,this.includeComments=!1}attrCompare(e,n){if(!e.namespaceURI&&n.namespaceURI)return-1;if(!n.namespaceURI&&e.namespaceURI)return 1;const r=e.namespaceURI+e.localName,i=n.namespaceURI+n.localName;return r===i?0:r<i?-1:1}nsCompare(e,n){const r=e.prefix,i=n.prefix;return r===i?0:r.localeCompare(i)}renderAttrs(e){let n,r;const i=[],s=[];if(bu.isCommentNode(e))return this.renderComment(e);if(e.attributes)for(n=0;n<e.attributes.length;++n)r=e.attributes[n],r.name.indexOf("xmlns")!==0&&s.push(r);s.sort(this.attrCompare);for(r of s)i.push(" ",r.name,'="',zr.encodeSpecialCharactersInAttribute(r.value),'"');return i.join("")}renderNs(e,n,r,i,s){let a,l;const u=[];let d=r;const p=[],h=e.namespaceURI||"";if(e.prefix?$u(n,e.prefix,e.namespaceURI||i[e.prefix])||(p.push({prefix:e.prefix,namespaceURI:e.namespaceURI||i[e.prefix]}),n.push({prefix:e.prefix,namespaceURI:e.namespaceURI||i[e.prefix]})):r!==h&&(d=e.namespaceURI,u.push(' xmlns="',d,'"')),e.attributes)for(a=0;a<e.attributes.length;++a)l=e.attributes[a],l.prefix&&!$u(n,l.localName,l.value)&&s.indexOf(l.localName)>=0&&(p.push({prefix:l.localName,namespaceURI:l.value}),n.push({prefix:l.localName,namespaceURI:l.value})),l.prefix&&!$u(n,l.prefix,l.namespaceURI)&&l.prefix!=="xmlns"&&l.prefix!=="xml"&&(p.push({prefix:l.prefix,namespaceURI:l.namespaceURI}),n.push({prefix:l.prefix,namespaceURI:l.namespaceURI}));p.sort(this.nsCompare);for(const g of p)u.push(" xmlns:",g.prefix,'="',g.namespaceURI,'"');return{rendered:u.join(""),newDefaultNs:d}}processInner(e,n,r,i,s){if(bu.isCommentNode(e))return this.renderComment(e);if(e.data)return zr.encodeSpecialCharactersInText(e.data);if(bu.isElementNode(e)){let a,l;const u=this.renderNs(e,n,r,i,s),d=["<",e.tagName,u.rendered,this.renderAttrs(e),">"];for(a=0;a<e.childNodes.length;++a)l=n.slice(0),d.push(this.processInner(e.childNodes[a],l,u.newDefaultNs,i,s));return d.push("</",e.tagName,">"),d.join("")}throw new Error(`Unable to exclusive canonicalize node type: ${e.nodeType}`)}renderComment(e){if(!this.includeComments)return"";const n=e.ownerDocument===e.parentNode;let r=!1,i=!1;if(n){let u=e,d=e;for(;u!=null;){if(u===e.ownerDocument.documentElement){r=!0;break}u=u.nextSibling}for(;d!=null;){if(d===e.ownerDocument.documentElement){i=!0;break}d=d.previousSibling}}const s=i?`
|
|
293
293
|
`:"",a=r?`
|
|
294
294
|
`:"",l=zr.encodeSpecialCharactersInText(e.data);return`${s}<!--${l}-->${a}`}process(e,n){n=n||{};let r=n.inclusiveNamespacesPrefixList||[];const i=n.defaultNs||"",s=n.defaultNsForPrefix||{},a=n.ancestorNamespaces||[];if(!zr.isArrayHasLength(r)){const u=zr.findChildren(e,"CanonicalizationMethod");if(u.length!==0){const d=zr.findChildren(u[0],"InclusiveNamespaces");d.length!==0&&(r=(d[0].getAttribute("PrefixList")||"").split(" "))}}return zr.isArrayHasLength(r)&&r.forEach(function(u){a&&a.forEach(function(d){u===d.prefix&&e.setAttributeNS("http://www.w3.org/2000/xmlns/",`xmlns:${u}`,d.namespaceURI)})}),this.processInner(e,[],i,s,r)}getAlgorithmName(){return"http://www.w3.org/2001/10/xml-exc-c14n#"}}ci.ExclusiveCanonicalization=nw;class sS extends nw{constructor(){super(),this.includeComments=!0}getAlgorithmName(){return"http://www.w3.org/2001/10/xml-exc-c14n#WithComments"}}ci.ExclusiveCanonicalizationWithComments=sS;var Ul={},Ml={},sr={},ar={};function aS(t,e,n){if(n===void 0&&(n=Array.prototype),t&&typeof n.find=="function")return n.find.call(t,e);for(var r=0;r<t.length;r++)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];if(e.call(void 0,i,r,t))return i}}function Xf(t,e){return e===void 0&&(e=Object),e&&typeof e.freeze=="function"?e.freeze(t):t}function cS(t,e){if(t===null||typeof t!="object")throw new TypeError("target is not an object");for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}var rw=Xf({HTML:"text/html",isHTML:function(t){return t===rw.HTML},XML_APPLICATION:"application/xml",XML_TEXT:"text/xml",XML_XHTML_APPLICATION:"application/xhtml+xml",XML_SVG_IMAGE:"image/svg+xml"}),iw=Xf({HTML:"http://www.w3.org/1999/xhtml",isHTML:function(t){return t===iw.HTML},SVG:"http://www.w3.org/2000/svg",XML:"http://www.w3.org/XML/1998/namespace",XMLNS:"http://www.w3.org/2000/xmlns/"});ar.assign=cS;ar.find=aS;ar.freeze=Xf;ar.MIME_TYPE=rw;ar.NAMESPACE=iw;var ow=ar,Tn=ow.find,rs=ow.NAMESPACE;function lS(t){return t!==""}function uS(t){return t?t.split(/[\t\n\f\r ]+/).filter(lS):[]}function dS(t,e){return t.hasOwnProperty(e)||(t[e]=!0),t}function mm(t){if(!t)return[];var e=uS(t);return Object.keys(e.reduce(dS,{}))}function pS(t){return function(e){return t&&t.indexOf(e)!==-1}}function Ds(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}function Ot(t,e){var n=t.prototype;if(!(n instanceof e)){let r=function(){};r.prototype=e.prototype,r=new r,Ds(n,r),t.prototype=n=r}n.constructor!=t&&(typeof t!="function"&&console.error("unknown Class:"+t),n.constructor=t)}var Dt={},mn=Dt.ELEMENT_NODE=1,Xi=Dt.ATTRIBUTE_NODE=2,xc=Dt.TEXT_NODE=3,sw=Dt.CDATA_SECTION_NODE=4,aw=Dt.ENTITY_REFERENCE_NODE=5,fS=Dt.ENTITY_NODE=6,cw=Dt.PROCESSING_INSTRUCTION_NODE=7,lw=Dt.COMMENT_NODE=8,uw=Dt.DOCUMENT_NODE=9,dw=Dt.DOCUMENT_TYPE_NODE=10,Qn=Dt.DOCUMENT_FRAGMENT_NODE=11,hS=Dt.NOTATION_NODE=12,_t={},st={};_t.INDEX_SIZE_ERR=(st[1]="Index size error",1);_t.DOMSTRING_SIZE_ERR=(st[2]="DOMString size error",2);var Nt=_t.HIERARCHY_REQUEST_ERR=(st[3]="Hierarchy request error",3);_t.WRONG_DOCUMENT_ERR=(st[4]="Wrong document",4);_t.INVALID_CHARACTER_ERR=(st[5]="Invalid character",5);_t.NO_DATA_ALLOWED_ERR=(st[6]="No data allowed",6);_t.NO_MODIFICATION_ALLOWED_ERR=(st[7]="No modification allowed",7);var pw=_t.NOT_FOUND_ERR=(st[8]="Not found",8);_t.NOT_SUPPORTED_ERR=(st[9]="Not supported",9);var _m=_t.INUSE_ATTRIBUTE_ERR=(st[10]="Attribute in use",10);_t.INVALID_STATE_ERR=(st[11]="Invalid state",11);_t.SYNTAX_ERR=(st[12]="Syntax error",12);_t.INVALID_MODIFICATION_ERR=(st[13]="Invalid modification",13);_t.NAMESPACE_ERR=(st[14]="Invalid namespace",14);_t.INVALID_ACCESS_ERR=(st[15]="Invalid access",15);function Qe(t,e){if(e instanceof Error)var n=e;else n=this,Error.call(this,st[t]),this.message=st[t],Error.captureStackTrace&&Error.captureStackTrace(this,Qe);return n.code=t,e&&(this.message=this.message+": "+e),n}Qe.prototype=Error.prototype;Ds(_t,Qe);function Hn(){}Hn.prototype={length:0,item:function(t){return t>=0&&t<this.length?this[t]:null},toString:function(t,e){for(var n=[],r=0;r<this.length;r++)ki(this[r],n,t,e);return n.join("")},filter:function(t){return Array.prototype.filter.call(this,t)},indexOf:function(t){return Array.prototype.indexOf.call(this,t)}};function Ji(t,e){this._node=t,this._refresh=e,Jf(this)}function Jf(t){var e=t._node._inc||t._node.ownerDocument._inc;if(t._inc!==e){var n=t._refresh(t._node);if(Aw(t,"length",n.length),!t.$$length||n.length<t.$$length)for(var r=n.length;r in t;r++)Object.prototype.hasOwnProperty.call(t,r)&&delete t[r];Ds(n,t),t._inc=e}}Ji.prototype.item=function(t){return Jf(this),this[t]||null};Ot(Ji,Hn);function Ac(){}function fw(t,e){for(var n=t.length;n--;)if(t[n]===e)return n}function ym(t,e,n,r){if(r?e[fw(e,r)]=n:e[e.length++]=n,t){n.ownerElement=t;var i=t.ownerDocument;i&&(r&&mw(i,t,r),gS(i,t,n))}}function wm(t,e,n){var r=fw(e,n);if(r>=0){for(var i=e.length-1;r<i;)e[r]=e[++r];if(e.length=i,t){var s=t.ownerDocument;s&&(mw(s,t,n),n.ownerElement=null)}}else throw new Qe(pw,new Error(t.tagName+"@"+n))}Ac.prototype={length:0,item:Hn.prototype.item,getNamedItem:function(t){for(var e=this.length;e--;){var n=this[e];if(n.nodeName==t)return n}},setNamedItem:function(t){var e=t.ownerElement;if(e&&e!=this._ownerElement)throw new Qe(_m);var n=this.getNamedItem(t.nodeName);return ym(this._ownerElement,this,t,n),n},setNamedItemNS:function(t){var e=t.ownerElement,n;if(e&&e!=this._ownerElement)throw new Qe(_m);return n=this.getNamedItemNS(t.namespaceURI,t.localName),ym(this._ownerElement,this,t,n),n},removeNamedItem:function(t){var e=this.getNamedItem(t);return wm(this._ownerElement,this,e),e},removeNamedItemNS:function(t,e){var n=this.getNamedItemNS(t,e);return wm(this._ownerElement,this,n),n},getNamedItemNS:function(t,e){for(var n=this.length;n--;){var r=this[n];if(r.localName==e&&r.namespaceURI==t)return r}return null}};function hw(){}hw.prototype={hasFeature:function(t,e){return!0},createDocument:function(t,e,n){var r=new Rs;if(r.implementation=this,r.childNodes=new Hn,r.doctype=n||null,n&&r.appendChild(n),e){var i=r.createElementNS(t,e);r.appendChild(i)}return r},createDocumentType:function(t,e,n){var r=new ql;return r.name=t,r.nodeName=t,r.publicId=e||"",r.systemId=n||"",r}};function je(){}je.prototype={firstChild:null,lastChild:null,previousSibling:null,nextSibling:null,attributes:null,parentNode:null,childNodes:null,ownerDocument:null,nodeValue:null,namespaceURI:null,prefix:null,localName:null,insertBefore:function(t,e){return Ec(this,t,e)},replaceChild:function(t,e){Ec(this,t,e,yw),e&&this.removeChild(e)},removeChild:function(t){return _w(this,t)},appendChild:function(t){return this.insertBefore(t,null)},hasChildNodes:function(){return this.firstChild!=null},cloneNode:function(t){return gp(this.ownerDocument||this,this,t)},normalize:function(){for(var t=this.firstChild;t;){var e=t.nextSibling;e&&e.nodeType==xc&&t.nodeType==xc?(this.removeChild(e),t.appendData(e.data)):(t.normalize(),t=e)}},isSupported:function(t,e){return this.ownerDocument.implementation.hasFeature(t,e)},hasAttributes:function(){return this.attributes.length>0},lookupPrefix:function(t){for(var e=this;e;){var n=e._nsMap;if(n){for(var r in n)if(Object.prototype.hasOwnProperty.call(n,r)&&n[r]===t)return r}e=e.nodeType==Xi?e.ownerDocument:e.parentNode}return null},lookupNamespaceURI:function(t){for(var e=this;e;){var n=e._nsMap;if(n&&Object.prototype.hasOwnProperty.call(n,t))return n[t];e=e.nodeType==Xi?e.ownerDocument:e.parentNode}return null},isDefaultNamespace:function(t){var e=this.lookupPrefix(t);return e==null}};function gw(t){return t=="<"&&"<"||t==">"&&">"||t=="&"&&"&"||t=='"'&&"""||"&#"+t.charCodeAt()+";"}Ds(Dt,je);Ds(Dt,je.prototype);function is(t,e){if(e(t))return!0;if(t=t.firstChild)do if(is(t,e))return!0;while(t=t.nextSibling)}function Rs(){this.ownerDocument=this}function gS(t,e,n){t&&t._inc++;var r=n.namespaceURI;r===rs.XMLNS&&(e._nsMap[n.prefix?n.localName:""]=n.value)}function mw(t,e,n,r){t&&t._inc++;var i=n.namespaceURI;i===rs.XMLNS&&delete e._nsMap[n.prefix?n.localName:""]}function Yf(t,e,n){if(t&&t._inc){t._inc++;var r=e.childNodes;if(n)r[r.length++]=n;else{for(var i=e.firstChild,s=0;i;)r[s++]=i,i=i.nextSibling;r.length=s,delete r[r.length]}}}function _w(t,e){var n=e.previousSibling,r=e.nextSibling;return n?n.nextSibling=r:t.firstChild=r,r?r.previousSibling=n:t.lastChild=n,e.parentNode=null,e.previousSibling=null,e.nextSibling=null,Yf(t.ownerDocument,t),e}function mS(t){return t&&(t.nodeType===je.DOCUMENT_NODE||t.nodeType===je.DOCUMENT_FRAGMENT_NODE||t.nodeType===je.ELEMENT_NODE)}function _S(t){return t&&(On(t)||Zf(t)||er(t)||t.nodeType===je.DOCUMENT_FRAGMENT_NODE||t.nodeType===je.COMMENT_NODE||t.nodeType===je.PROCESSING_INSTRUCTION_NODE)}function er(t){return t&&t.nodeType===je.DOCUMENT_TYPE_NODE}function On(t){return t&&t.nodeType===je.ELEMENT_NODE}function Zf(t){return t&&t.nodeType===je.TEXT_NODE}function vm(t,e){var n=t.childNodes||[];if(Tn(n,On)||er(e))return!1;var r=Tn(n,er);return!(e&&r&&n.indexOf(r)>n.indexOf(e))}function bm(t,e){var n=t.childNodes||[];function r(s){return On(s)&&s!==e}if(Tn(n,r))return!1;var i=Tn(n,er);return!(e&&i&&n.indexOf(i)>n.indexOf(e))}function yS(t,e,n){if(!mS(t))throw new Qe(Nt,"Unexpected parent node type "+t.nodeType);if(n&&n.parentNode!==t)throw new Qe(pw,"child not in parent");if(!_S(e)||er(e)&&t.nodeType!==je.DOCUMENT_NODE)throw new Qe(Nt,"Unexpected node type "+e.nodeType+" for parent node type "+t.nodeType)}function wS(t,e,n){var r=t.childNodes||[],i=e.childNodes||[];if(e.nodeType===je.DOCUMENT_FRAGMENT_NODE){var s=i.filter(On);if(s.length>1||Tn(i,Zf))throw new Qe(Nt,"More than one element or text in fragment");if(s.length===1&&!vm(t,n))throw new Qe(Nt,"Element in fragment can not be inserted before doctype")}if(On(e)&&!vm(t,n))throw new Qe(Nt,"Only one element can be added and only after doctype");if(er(e)){if(Tn(r,er))throw new Qe(Nt,"Only one doctype is allowed");var a=Tn(r,On);if(n&&r.indexOf(a)<r.indexOf(n))throw new Qe(Nt,"Doctype can only be inserted before an element");if(!n&&a)throw new Qe(Nt,"Doctype can not be appended since element is present")}}function yw(t,e,n){var r=t.childNodes||[],i=e.childNodes||[];if(e.nodeType===je.DOCUMENT_FRAGMENT_NODE){var s=i.filter(On);if(s.length>1||Tn(i,Zf))throw new Qe(Nt,"More than one element or text in fragment");if(s.length===1&&!bm(t,n))throw new Qe(Nt,"Element in fragment can not be inserted before doctype")}if(On(e)&&!bm(t,n))throw new Qe(Nt,"Only one element can be added and only after doctype");if(er(e)){if(Tn(r,function(u){return er(u)&&u!==n}))throw new Qe(Nt,"Only one doctype is allowed");var a=Tn(r,On);if(n&&r.indexOf(a)<r.indexOf(n))throw new Qe(Nt,"Doctype can only be inserted before an element")}}function Ec(t,e,n,r){yS(t,e,n),t.nodeType===je.DOCUMENT_NODE&&(r||wS)(t,e,n);var i=e.parentNode;if(i&&i.removeChild(e),e.nodeType===Qn){var s=e.firstChild;if(s==null)return e;var a=e.lastChild}else s=a=e;var l=n?n.previousSibling:t.lastChild;s.previousSibling=l,a.nextSibling=n,l?l.nextSibling=s:t.firstChild=s,n==null?t.lastChild=a:n.previousSibling=a;do s.parentNode=t;while(s!==a&&(s=s.nextSibling));return Yf(t.ownerDocument||t,t),e.nodeType==Qn&&(e.firstChild=e.lastChild=null),e}function vS(t,e){return e.parentNode&&e.parentNode.removeChild(e),e.parentNode=t,e.previousSibling=t.lastChild,e.nextSibling=null,e.previousSibling?e.previousSibling.nextSibling=e:t.firstChild=e,t.lastChild=e,Yf(t.ownerDocument,t,e),e}Rs.prototype={nodeName:"#document",nodeType:uw,doctype:null,documentElement:null,_inc:1,insertBefore:function(t,e){if(t.nodeType==Qn){for(var n=t.firstChild;n;){var r=n.nextSibling;this.insertBefore(n,e),n=r}return t}return Ec(this,t,e),t.ownerDocument=this,this.documentElement===null&&t.nodeType===mn&&(this.documentElement=t),t},removeChild:function(t){return this.documentElement==t&&(this.documentElement=null),_w(this,t)},replaceChild:function(t,e){Ec(this,t,e,yw),t.ownerDocument=this,e&&this.removeChild(e),On(t)&&(this.documentElement=t)},importNode:function(t,e){return xw(this,t,e)},getElementById:function(t){var e=null;return is(this.documentElement,function(n){if(n.nodeType==mn&&n.getAttribute("id")==t)return e=n,!0}),e},getElementsByClassName:function(t){var e=mm(t);return new Ji(this,function(n){var r=[];return e.length>0&&is(n.documentElement,function(i){if(i!==n&&i.nodeType===mn){var s=i.getAttribute("class");if(s){var a=t===s;if(!a){var l=mm(s);a=e.every(pS(l))}a&&r.push(i)}}}),r})},createElement:function(t){var e=new li;e.ownerDocument=this,e.nodeName=t,e.tagName=t,e.localName=t,e.childNodes=new Hn;var n=e.attributes=new Ac;return n._ownerElement=e,e},createDocumentFragment:function(){var t=new Vl;return t.ownerDocument=this,t.childNodes=new Hn,t},createTextNode:function(t){var e=new Qf;return e.ownerDocument=this,e.appendData(t),e},createComment:function(t){var e=new eh;return e.ownerDocument=this,e.appendData(t),e},createCDATASection:function(t){var e=new th;return e.ownerDocument=this,e.appendData(t),e},createProcessingInstruction:function(t,e){var n=new rh;return n.ownerDocument=this,n.tagName=n.nodeName=n.target=t,n.nodeValue=n.data=e,n},createAttribute:function(t){var e=new Sc;return e.ownerDocument=this,e.name=t,e.nodeName=t,e.localName=t,e.specified=!0,e},createEntityReference:function(t){var e=new nh;return e.ownerDocument=this,e.nodeName=t,e},createElementNS:function(t,e){var n=new li,r=e.split(":"),i=n.attributes=new Ac;return n.childNodes=new Hn,n.ownerDocument=this,n.nodeName=e,n.tagName=e,n.namespaceURI=t,r.length==2?(n.prefix=r[0],n.localName=r[1]):n.localName=e,i._ownerElement=n,n},createAttributeNS:function(t,e){var n=new Sc,r=e.split(":");return n.ownerDocument=this,n.nodeName=e,n.name=e,n.namespaceURI=t,n.specified=!0,r.length==2?(n.prefix=r[0],n.localName=r[1]):n.localName=e,n}};Ot(Rs,je);function li(){this._nsMap={}}li.prototype={nodeType:mn,hasAttribute:function(t){return this.getAttributeNode(t)!=null},getAttribute:function(t){var e=this.getAttributeNode(t);return e&&e.value||""},getAttributeNode:function(t){return this.attributes.getNamedItem(t)},setAttribute:function(t,e){var n=this.ownerDocument.createAttribute(t);n.value=n.nodeValue=""+e,this.setAttributeNode(n)},removeAttribute:function(t){var e=this.getAttributeNode(t);e&&this.removeAttributeNode(e)},appendChild:function(t){return t.nodeType===Qn?this.insertBefore(t,null):vS(this,t)},setAttributeNode:function(t){return this.attributes.setNamedItem(t)},setAttributeNodeNS:function(t){return this.attributes.setNamedItemNS(t)},removeAttributeNode:function(t){return this.attributes.removeNamedItem(t.nodeName)},removeAttributeNS:function(t,e){var n=this.getAttributeNodeNS(t,e);n&&this.removeAttributeNode(n)},hasAttributeNS:function(t,e){return this.getAttributeNodeNS(t,e)!=null},getAttributeNS:function(t,e){var n=this.getAttributeNodeNS(t,e);return n&&n.value||""},setAttributeNS:function(t,e,n){var r=this.ownerDocument.createAttributeNS(t,e);r.value=r.nodeValue=""+n,this.setAttributeNode(r)},getAttributeNodeNS:function(t,e){return this.attributes.getNamedItemNS(t,e)},getElementsByTagName:function(t){return new Ji(this,function(e){var n=[];return is(e,function(r){r!==e&&r.nodeType==mn&&(t==="*"||r.tagName==t)&&n.push(r)}),n})},getElementsByTagNameNS:function(t,e){return new Ji(this,function(n){var r=[];return is(n,function(i){i!==n&&i.nodeType===mn&&(t==="*"||i.namespaceURI===t)&&(e==="*"||i.localName==e)&&r.push(i)}),r})}};Rs.prototype.getElementsByTagName=li.prototype.getElementsByTagName;Rs.prototype.getElementsByTagNameNS=li.prototype.getElementsByTagNameNS;Ot(li,je);function Sc(){}Sc.prototype.nodeType=Xi;Ot(Sc,je);function js(){}js.prototype={data:"",substringData:function(t,e){return this.data.substring(t,t+e)},appendData:function(t){t=this.data+t,this.nodeValue=this.data=t,this.length=t.length},insertData:function(t,e){this.replaceData(t,0,e)},appendChild:function(t){throw new Error(st[Nt])},deleteData:function(t,e){this.replaceData(t,e,"")},replaceData:function(t,e,n){var r=this.data.substring(0,t),i=this.data.substring(t+e);n=r+n+i,this.nodeValue=this.data=n,this.length=n.length}};Ot(js,je);function Qf(){}Qf.prototype={nodeName:"#text",nodeType:xc,splitText:function(t){var e=this.data,n=e.substring(t);e=e.substring(0,t),this.data=this.nodeValue=e,this.length=e.length;var r=this.ownerDocument.createTextNode(n);return this.parentNode&&this.parentNode.insertBefore(r,this.nextSibling),r}};Ot(Qf,js);function eh(){}eh.prototype={nodeName:"#comment",nodeType:lw};Ot(eh,js);function th(){}th.prototype={nodeName:"#cdata-section",nodeType:sw};Ot(th,js);function ql(){}ql.prototype.nodeType=dw;Ot(ql,je);function ww(){}ww.prototype.nodeType=hS;Ot(ww,je);function vw(){}vw.prototype.nodeType=fS;Ot(vw,je);function nh(){}nh.prototype.nodeType=aw;Ot(nh,je);function Vl(){}Vl.prototype.nodeName="#document-fragment";Vl.prototype.nodeType=Qn;Ot(Vl,je);function rh(){}rh.prototype.nodeType=cw;Ot(rh,je);function bw(){}bw.prototype.serializeToString=function(t,e,n){return $w.call(t,e,n)};je.prototype.toString=$w;function $w(t,e){var n=[],r=this.nodeType==9&&this.documentElement||this,i=r.prefix,s=r.namespaceURI;if(s&&i==null){var i=r.lookupPrefix(s);if(i==null)var a=[{namespace:s,prefix:null}]}return ki(this,n,t,e,a),n.join("")}function $m(t,e,n){var r=t.prefix||"",i=t.namespaceURI;if(!i||r==="xml"&&i===rs.XML||i===rs.XMLNS)return!1;for(var s=n.length;s--;){var a=n[s];if(a.prefix===r)return a.namespace!==i}return!0}function xu(t,e,n){t.push(" ",e,'="',n.replace(/[<>&"\t\n\r]/g,gw),'"')}function ki(t,e,n,r,i){if(i||(i=[]),r)if(t=r(t),t){if(typeof t=="string"){e.push(t);return}}else return;switch(t.nodeType){case mn:var s=t.attributes,a=s.length,O=t.firstChild,l=t.tagName;n=rs.isHTML(t.namespaceURI)||n;var u=l;if(!n&&!t.prefix&&t.namespaceURI){for(var d,p=0;p<s.length;p++)if(s.item(p).name==="xmlns"){d=s.item(p).value;break}if(!d)for(var h=i.length-1;h>=0;h--){var g=i[h];if(g.prefix===""&&g.namespace===t.namespaceURI){d=g.namespace;break}}if(d!==t.namespaceURI)for(var h=i.length-1;h>=0;h--){var g=i[h];if(g.namespace===t.namespaceURI){g.prefix&&(u=g.prefix+":"+l);break}}}e.push("<",u);for(var $=0;$<a;$++){var A=s.item($);A.prefix=="xmlns"?i.push({prefix:A.localName,namespace:A.value}):A.nodeName=="xmlns"&&i.push({prefix:"",namespace:A.value})}for(var $=0;$<a;$++){var A=s.item($);if($m(A,n,i)){var z=A.prefix||"",T=A.namespaceURI;xu(e,z?"xmlns:"+z:"xmlns",T),i.push({prefix:z,namespace:T})}ki(A,e,n,r,i)}if(l===u&&$m(t,n,i)){var z=t.prefix||"",T=t.namespaceURI;xu(e,z?"xmlns:"+z:"xmlns",T),i.push({prefix:z,namespace:T})}if(O||n&&!/^(?:meta|link|img|br|hr|input)$/i.test(l)){if(e.push(">"),n&&/^script$/i.test(l))for(;O;)O.data?e.push(O.data):ki(O,e,n,r,i.slice()),O=O.nextSibling;else for(;O;)ki(O,e,n,r,i.slice()),O=O.nextSibling;e.push("</",u,">")}else e.push("/>");return;case uw:case Qn:for(var O=t.firstChild;O;)ki(O,e,n,r,i.slice()),O=O.nextSibling;return;case Xi:return xu(e,t.name,t.value);case xc:return e.push(t.data.replace(/[<&>]/g,gw));case sw:return e.push("<![CDATA[",t.data,"]]>");case lw:return e.push("<!--",t.data,"-->");case dw:var x=t.publicId,U=t.systemId;if(e.push("<!DOCTYPE ",t.name),x)e.push(" PUBLIC ",x),U&&U!="."&&e.push(" ",U),e.push(">");else if(U&&U!=".")e.push(" SYSTEM ",U,">");else{var q=t.internalSubset;q&&e.push(" [",q,"]"),e.push(">")}return;case cw:return e.push("<?",t.target," ",t.data,"?>");case aw:return e.push("&",t.nodeName,";");default:e.push("??",t.nodeName)}}function xw(t,e,n){var r;switch(e.nodeType){case mn:r=e.cloneNode(!1),r.ownerDocument=t;case Qn:break;case Xi:n=!0;break}if(r||(r=e.cloneNode(!1)),r.ownerDocument=t,r.parentNode=null,n)for(var i=e.firstChild;i;)r.appendChild(xw(t,i,n)),i=i.nextSibling;return r}function gp(t,e,n){var r=new e.constructor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var s=e[i];typeof s!="object"&&s!=r[i]&&(r[i]=s)}switch(e.childNodes&&(r.childNodes=new Hn),r.ownerDocument=t,r.nodeType){case mn:var a=e.attributes,l=r.attributes=new Ac,u=a.length;l._ownerElement=r;for(var d=0;d<u;d++)r.setAttributeNode(gp(t,a.item(d),!0));break;case Xi:n=!0}if(n)for(var p=e.firstChild;p;)r.appendChild(gp(t,p,n)),p=p.nextSibling;return r}function Aw(t,e,n){t[e]=n}try{if(Object.defineProperty){let t=function(e){switch(e.nodeType){case mn:case Qn:var n=[];for(e=e.firstChild;e;)e.nodeType!==7&&e.nodeType!==8&&n.push(t(e)),e=e.nextSibling;return n.join("");default:return e.nodeValue}};Object.defineProperty(Ji.prototype,"length",{get:function(){return Jf(this),this.$$length}}),Object.defineProperty(je.prototype,"textContent",{get:function(){return t(this)},set:function(e){switch(this.nodeType){case mn:case Qn:for(;this.firstChild;)this.removeChild(this.firstChild);(e||String(e))&&this.appendChild(this.ownerDocument.createTextNode(e));break;default:this.data=e,this.value=e,this.nodeValue=e}}}),Aw=function(e,n,r){e["$$"+n]=r}}}catch{}sr.DocumentType=ql;sr.DOMException=Qe;sr.DOMImplementation=hw;sr.Element=li;sr.Node=je;sr.NodeList=Hn;sr.XMLSerializer=bw;var Hl={},Ew={};(function(t){var e=ar.freeze;t.XML_ENTITIES=e({amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}),t.HTML_ENTITIES=e({Aacute:"Á",aacute:"á",Abreve:"Ă",abreve:"ă",ac:"∾",acd:"∿",acE:"∾̳",Acirc:"Â",acirc:"â",acute:"´",Acy:"А",acy:"а",AElig:"Æ",aelig:"æ",af:"",Afr:"𝔄",afr:"𝔞",Agrave:"À",agrave:"à",alefsym:"ℵ",aleph:"ℵ",Alpha:"Α",alpha:"α",Amacr:"Ā",amacr:"ā",amalg:"⨿",AMP:"&",amp:"&",And:"⩓",and:"∧",andand:"⩕",andd:"⩜",andslope:"⩘",andv:"⩚",ang:"∠",ange:"⦤",angle:"∠",angmsd:"∡",angmsdaa:"⦨",angmsdab:"⦩",angmsdac:"⦪",angmsdad:"⦫",angmsdae:"⦬",angmsdaf:"⦭",angmsdag:"⦮",angmsdah:"⦯",angrt:"∟",angrtvb:"⊾",angrtvbd:"⦝",angsph:"∢",angst:"Å",angzarr:"⍼",Aogon:"Ą",aogon:"ą",Aopf:"𝔸",aopf:"𝕒",ap:"≈",apacir:"⩯",apE:"⩰",ape:"≊",apid:"≋",apos:"'",ApplyFunction:"",approx:"≈",approxeq:"≊",Aring:"Å",aring:"å",Ascr:"𝒜",ascr:"𝒶",Assign:"≔",ast:"*",asymp:"≈",asympeq:"≍",Atilde:"Ã",atilde:"ã",Auml:"Ä",auml:"ä",awconint:"∳",awint:"⨑",backcong:"≌",backepsilon:"϶",backprime:"‵",backsim:"∽",backsimeq:"⋍",Backslash:"∖",Barv:"⫧",barvee:"⊽",Barwed:"⌆",barwed:"⌅",barwedge:"⌅",bbrk:"⎵",bbrktbrk:"⎶",bcong:"≌",Bcy:"Б",bcy:"б",bdquo:"„",becaus:"∵",Because:"∵",because:"∵",bemptyv:"⦰",bepsi:"϶",bernou:"ℬ",Bernoullis:"ℬ",Beta:"Β",beta:"β",beth:"ℶ",between:"≬",Bfr:"𝔅",bfr:"𝔟",bigcap:"⋂",bigcirc:"◯",bigcup:"⋃",bigodot:"⨀",bigoplus:"⨁",bigotimes:"⨂",bigsqcup:"⨆",bigstar:"★",bigtriangledown:"▽",bigtriangleup:"△",biguplus:"⨄",bigvee:"⋁",bigwedge:"⋀",bkarow:"⤍",blacklozenge:"⧫",blacksquare:"▪",blacktriangle:"▴",blacktriangledown:"▾",blacktriangleleft:"◂",blacktriangleright:"▸",blank:"␣",blk12:"▒",blk14:"░",blk34:"▓",block:"█",bne:"=⃥",bnequiv:"≡⃥",bNot:"⫭",bnot:"⌐",Bopf:"𝔹",bopf:"𝕓",bot:"⊥",bottom:"⊥",bowtie:"⋈",boxbox:"⧉",boxDL:"╗",boxDl:"╖",boxdL:"╕",boxdl:"┐",boxDR:"╔",boxDr:"╓",boxdR:"╒",boxdr:"┌",boxH:"═",boxh:"─",boxHD:"╦",boxHd:"╤",boxhD:"╥",boxhd:"┬",boxHU:"╩",boxHu:"╧",boxhU:"╨",boxhu:"┴",boxminus:"⊟",boxplus:"⊞",boxtimes:"⊠",boxUL:"╝",boxUl:"╜",boxuL:"╛",boxul:"┘",boxUR:"╚",boxUr:"╙",boxuR:"╘",boxur:"└",boxV:"║",boxv:"│",boxVH:"╬",boxVh:"╫",boxvH:"╪",boxvh:"┼",boxVL:"╣",boxVl:"╢",boxvL:"╡",boxvl:"┤",boxVR:"╠",boxVr:"╟",boxvR:"╞",boxvr:"├",bprime:"‵",Breve:"˘",breve:"˘",brvbar:"¦",Bscr:"ℬ",bscr:"𝒷",bsemi:"⁏",bsim:"∽",bsime:"⋍",bsol:"\\",bsolb:"⧅",bsolhsub:"⟈",bull:"•",bullet:"•",bump:"≎",bumpE:"⪮",bumpe:"≏",Bumpeq:"≎",bumpeq:"≏",Cacute:"Ć",cacute:"ć",Cap:"⋒",cap:"∩",capand:"⩄",capbrcup:"⩉",capcap:"⩋",capcup:"⩇",capdot:"⩀",CapitalDifferentialD:"ⅅ",caps:"∩︀",caret:"⁁",caron:"ˇ",Cayleys:"ℭ",ccaps:"⩍",Ccaron:"Č",ccaron:"č",Ccedil:"Ç",ccedil:"ç",Ccirc:"Ĉ",ccirc:"ĉ",Cconint:"∰",ccups:"⩌",ccupssm:"⩐",Cdot:"Ċ",cdot:"ċ",cedil:"¸",Cedilla:"¸",cemptyv:"⦲",cent:"¢",CenterDot:"·",centerdot:"·",Cfr:"ℭ",cfr:"𝔠",CHcy:"Ч",chcy:"ч",check:"✓",checkmark:"✓",Chi:"Χ",chi:"χ",cir:"○",circ:"ˆ",circeq:"≗",circlearrowleft:"↺",circlearrowright:"↻",circledast:"⊛",circledcirc:"⊚",circleddash:"⊝",CircleDot:"⊙",circledR:"®",circledS:"Ⓢ",CircleMinus:"⊖",CirclePlus:"⊕",CircleTimes:"⊗",cirE:"⧃",cire:"≗",cirfnint:"⨐",cirmid:"⫯",cirscir:"⧂",ClockwiseContourIntegral:"∲",CloseCurlyDoubleQuote:"”",CloseCurlyQuote:"’",clubs:"♣",clubsuit:"♣",Colon:"∷",colon:":",Colone:"⩴",colone:"≔",coloneq:"≔",comma:",",commat:"@",comp:"∁",compfn:"∘",complement:"∁",complexes:"ℂ",cong:"≅",congdot:"⩭",Congruent:"≡",Conint:"∯",conint:"∮",ContourIntegral:"∮",Copf:"ℂ",copf:"𝕔",coprod:"∐",Coproduct:"∐",COPY:"©",copy:"©",copysr:"℗",CounterClockwiseContourIntegral:"∳",crarr:"↵",Cross:"⨯",cross:"✗",Cscr:"𝒞",cscr:"𝒸",csub:"⫏",csube:"⫑",csup:"⫐",csupe:"⫒",ctdot:"⋯",cudarrl:"⤸",cudarrr:"⤵",cuepr:"⋞",cuesc:"⋟",cularr:"↶",cularrp:"⤽",Cup:"⋓",cup:"∪",cupbrcap:"⩈",CupCap:"≍",cupcap:"⩆",cupcup:"⩊",cupdot:"⊍",cupor:"⩅",cups:"∪︀",curarr:"↷",curarrm:"⤼",curlyeqprec:"⋞",curlyeqsucc:"⋟",curlyvee:"⋎",curlywedge:"⋏",curren:"¤",curvearrowleft:"↶",curvearrowright:"↷",cuvee:"⋎",cuwed:"⋏",cwconint:"∲",cwint:"∱",cylcty:"⌭",Dagger:"‡",dagger:"†",daleth:"ℸ",Darr:"↡",dArr:"⇓",darr:"↓",dash:"‐",Dashv:"⫤",dashv:"⊣",dbkarow:"⤏",dblac:"˝",Dcaron:"Ď",dcaron:"ď",Dcy:"Д",dcy:"д",DD:"ⅅ",dd:"ⅆ",ddagger:"‡",ddarr:"⇊",DDotrahd:"⤑",ddotseq:"⩷",deg:"°",Del:"∇",Delta:"Δ",delta:"δ",demptyv:"⦱",dfisht:"⥿",Dfr:"𝔇",dfr:"𝔡",dHar:"⥥",dharl:"⇃",dharr:"⇂",DiacriticalAcute:"´",DiacriticalDot:"˙",DiacriticalDoubleAcute:"˝",DiacriticalGrave:"`",DiacriticalTilde:"˜",diam:"⋄",Diamond:"⋄",diamond:"⋄",diamondsuit:"♦",diams:"♦",die:"¨",DifferentialD:"ⅆ",digamma:"ϝ",disin:"⋲",div:"÷",divide:"÷",divideontimes:"⋇",divonx:"⋇",DJcy:"Ђ",djcy:"ђ",dlcorn:"⌞",dlcrop:"⌍",dollar:"$",Dopf:"𝔻",dopf:"𝕕",Dot:"¨",dot:"˙",DotDot:"⃜",doteq:"≐",doteqdot:"≑",DotEqual:"≐",dotminus:"∸",dotplus:"∔",dotsquare:"⊡",doublebarwedge:"⌆",DoubleContourIntegral:"∯",DoubleDot:"¨",DoubleDownArrow:"⇓",DoubleLeftArrow:"⇐",DoubleLeftRightArrow:"⇔",DoubleLeftTee:"⫤",DoubleLongLeftArrow:"⟸",DoubleLongLeftRightArrow:"⟺",DoubleLongRightArrow:"⟹",DoubleRightArrow:"⇒",DoubleRightTee:"⊨",DoubleUpArrow:"⇑",DoubleUpDownArrow:"⇕",DoubleVerticalBar:"∥",DownArrow:"↓",Downarrow:"⇓",downarrow:"↓",DownArrowBar:"⤓",DownArrowUpArrow:"⇵",DownBreve:"̑",downdownarrows:"⇊",downharpoonleft:"⇃",downharpoonright:"⇂",DownLeftRightVector:"⥐",DownLeftTeeVector:"⥞",DownLeftVector:"↽",DownLeftVectorBar:"⥖",DownRightTeeVector:"⥟",DownRightVector:"⇁",DownRightVectorBar:"⥗",DownTee:"⊤",DownTeeArrow:"↧",drbkarow:"⤐",drcorn:"⌟",drcrop:"⌌",Dscr:"𝒟",dscr:"𝒹",DScy:"Ѕ",dscy:"ѕ",dsol:"⧶",Dstrok:"Đ",dstrok:"đ",dtdot:"⋱",dtri:"▿",dtrif:"▾",duarr:"⇵",duhar:"⥯",dwangle:"⦦",DZcy:"Џ",dzcy:"џ",dzigrarr:"⟿",Eacute:"É",eacute:"é",easter:"⩮",Ecaron:"Ě",ecaron:"ě",ecir:"≖",Ecirc:"Ê",ecirc:"ê",ecolon:"≕",Ecy:"Э",ecy:"э",eDDot:"⩷",Edot:"Ė",eDot:"≑",edot:"ė",ee:"ⅇ",efDot:"≒",Efr:"𝔈",efr:"𝔢",eg:"⪚",Egrave:"È",egrave:"è",egs:"⪖",egsdot:"⪘",el:"⪙",Element:"∈",elinters:"⏧",ell:"ℓ",els:"⪕",elsdot:"⪗",Emacr:"Ē",emacr:"ē",empty:"∅",emptyset:"∅",EmptySmallSquare:"◻",emptyv:"∅",EmptyVerySmallSquare:"▫",emsp:" ",emsp13:" ",emsp14:" ",ENG:"Ŋ",eng:"ŋ",ensp:" ",Eogon:"Ę",eogon:"ę",Eopf:"𝔼",eopf:"𝕖",epar:"⋕",eparsl:"⧣",eplus:"⩱",epsi:"ε",Epsilon:"Ε",epsilon:"ε",epsiv:"ϵ",eqcirc:"≖",eqcolon:"≕",eqsim:"≂",eqslantgtr:"⪖",eqslantless:"⪕",Equal:"⩵",equals:"=",EqualTilde:"≂",equest:"≟",Equilibrium:"⇌",equiv:"≡",equivDD:"⩸",eqvparsl:"⧥",erarr:"⥱",erDot:"≓",Escr:"ℰ",escr:"ℯ",esdot:"≐",Esim:"⩳",esim:"≂",Eta:"Η",eta:"η",ETH:"Ð",eth:"ð",Euml:"Ë",euml:"ë",euro:"€",excl:"!",exist:"∃",Exists:"∃",expectation:"ℰ",ExponentialE:"ⅇ",exponentiale:"ⅇ",fallingdotseq:"≒",Fcy:"Ф",fcy:"ф",female:"♀",ffilig:"ffi",fflig:"ff",ffllig:"ffl",Ffr:"𝔉",ffr:"𝔣",filig:"fi",FilledSmallSquare:"◼",FilledVerySmallSquare:"▪",fjlig:"fj",flat:"♭",fllig:"fl",fltns:"▱",fnof:"ƒ",Fopf:"𝔽",fopf:"𝕗",ForAll:"∀",forall:"∀",fork:"⋔",forkv:"⫙",Fouriertrf:"ℱ",fpartint:"⨍",frac12:"½",frac13:"⅓",frac14:"¼",frac15:"⅕",frac16:"⅙",frac18:"⅛",frac23:"⅔",frac25:"⅖",frac34:"¾",frac35:"⅗",frac38:"⅜",frac45:"⅘",frac56:"⅚",frac58:"⅝",frac78:"⅞",frasl:"⁄",frown:"⌢",Fscr:"ℱ",fscr:"𝒻",gacute:"ǵ",Gamma:"Γ",gamma:"γ",Gammad:"Ϝ",gammad:"ϝ",gap:"⪆",Gbreve:"Ğ",gbreve:"ğ",Gcedil:"Ģ",Gcirc:"Ĝ",gcirc:"ĝ",Gcy:"Г",gcy:"г",Gdot:"Ġ",gdot:"ġ",gE:"≧",ge:"≥",gEl:"⪌",gel:"⋛",geq:"≥",geqq:"≧",geqslant:"⩾",ges:"⩾",gescc:"⪩",gesdot:"⪀",gesdoto:"⪂",gesdotol:"⪄",gesl:"⋛︀",gesles:"⪔",Gfr:"𝔊",gfr:"𝔤",Gg:"⋙",gg:"≫",ggg:"⋙",gimel:"ℷ",GJcy:"Ѓ",gjcy:"ѓ",gl:"≷",gla:"⪥",glE:"⪒",glj:"⪤",gnap:"⪊",gnapprox:"⪊",gnE:"≩",gne:"⪈",gneq:"⪈",gneqq:"≩",gnsim:"⋧",Gopf:"𝔾",gopf:"𝕘",grave:"`",GreaterEqual:"≥",GreaterEqualLess:"⋛",GreaterFullEqual:"≧",GreaterGreater:"⪢",GreaterLess:"≷",GreaterSlantEqual:"⩾",GreaterTilde:"≳",Gscr:"𝒢",gscr:"ℊ",gsim:"≳",gsime:"⪎",gsiml:"⪐",Gt:"≫",GT:">",gt:">",gtcc:"⪧",gtcir:"⩺",gtdot:"⋗",gtlPar:"⦕",gtquest:"⩼",gtrapprox:"⪆",gtrarr:"⥸",gtrdot:"⋗",gtreqless:"⋛",gtreqqless:"⪌",gtrless:"≷",gtrsim:"≳",gvertneqq:"≩︀",gvnE:"≩︀",Hacek:"ˇ",hairsp:" ",half:"½",hamilt:"ℋ",HARDcy:"Ъ",hardcy:"ъ",hArr:"⇔",harr:"↔",harrcir:"⥈",harrw:"↭",Hat:"^",hbar:"ℏ",Hcirc:"Ĥ",hcirc:"ĥ",hearts:"♥",heartsuit:"♥",hellip:"…",hercon:"⊹",Hfr:"ℌ",hfr:"𝔥",HilbertSpace:"ℋ",hksearow:"⤥",hkswarow:"⤦",hoarr:"⇿",homtht:"∻",hookleftarrow:"↩",hookrightarrow:"↪",Hopf:"ℍ",hopf:"𝕙",horbar:"―",HorizontalLine:"─",Hscr:"ℋ",hscr:"𝒽",hslash:"ℏ",Hstrok:"Ħ",hstrok:"ħ",HumpDownHump:"≎",HumpEqual:"≏",hybull:"⁃",hyphen:"‐",Iacute:"Í",iacute:"í",ic:"",Icirc:"Î",icirc:"î",Icy:"И",icy:"и",Idot:"İ",IEcy:"Е",iecy:"е",iexcl:"¡",iff:"⇔",Ifr:"ℑ",ifr:"𝔦",Igrave:"Ì",igrave:"ì",ii:"ⅈ",iiiint:"⨌",iiint:"∭",iinfin:"⧜",iiota:"℩",IJlig:"IJ",ijlig:"ij",Im:"ℑ",Imacr:"Ī",imacr:"ī",image:"ℑ",ImaginaryI:"ⅈ",imagline:"ℐ",imagpart:"ℑ",imath:"ı",imof:"⊷",imped:"Ƶ",Implies:"⇒",in:"∈",incare:"℅",infin:"∞",infintie:"⧝",inodot:"ı",Int:"∬",int:"∫",intcal:"⊺",integers:"ℤ",Integral:"∫",intercal:"⊺",Intersection:"⋂",intlarhk:"⨗",intprod:"⨼",InvisibleComma:"",InvisibleTimes:"",IOcy:"Ё",iocy:"ё",Iogon:"Į",iogon:"į",Iopf:"𝕀",iopf:"𝕚",Iota:"Ι",iota:"ι",iprod:"⨼",iquest:"¿",Iscr:"ℐ",iscr:"𝒾",isin:"∈",isindot:"⋵",isinE:"⋹",isins:"⋴",isinsv:"⋳",isinv:"∈",it:"",Itilde:"Ĩ",itilde:"ĩ",Iukcy:"І",iukcy:"і",Iuml:"Ï",iuml:"ï",Jcirc:"Ĵ",jcirc:"ĵ",Jcy:"Й",jcy:"й",Jfr:"𝔍",jfr:"𝔧",jmath:"ȷ",Jopf:"𝕁",jopf:"𝕛",Jscr:"𝒥",jscr:"𝒿",Jsercy:"Ј",jsercy:"ј",Jukcy:"Є",jukcy:"є",Kappa:"Κ",kappa:"κ",kappav:"ϰ",Kcedil:"Ķ",kcedil:"ķ",Kcy:"К",kcy:"к",Kfr:"𝔎",kfr:"𝔨",kgreen:"ĸ",KHcy:"Х",khcy:"х",KJcy:"Ќ",kjcy:"ќ",Kopf:"𝕂",kopf:"𝕜",Kscr:"𝒦",kscr:"𝓀",lAarr:"⇚",Lacute:"Ĺ",lacute:"ĺ",laemptyv:"⦴",lagran:"ℒ",Lambda:"Λ",lambda:"λ",Lang:"⟪",lang:"⟨",langd:"⦑",langle:"⟨",lap:"⪅",Laplacetrf:"ℒ",laquo:"«",Larr:"↞",lArr:"⇐",larr:"←",larrb:"⇤",larrbfs:"⤟",larrfs:"⤝",larrhk:"↩",larrlp:"↫",larrpl:"⤹",larrsim:"⥳",larrtl:"↢",lat:"⪫",lAtail:"⤛",latail:"⤙",late:"⪭",lates:"⪭︀",lBarr:"⤎",lbarr:"⤌",lbbrk:"❲",lbrace:"{",lbrack:"[",lbrke:"⦋",lbrksld:"⦏",lbrkslu:"⦍",Lcaron:"Ľ",lcaron:"ľ",Lcedil:"Ļ",lcedil:"ļ",lceil:"⌈",lcub:"{",Lcy:"Л",lcy:"л",ldca:"⤶",ldquo:"“",ldquor:"„",ldrdhar:"⥧",ldrushar:"⥋",ldsh:"↲",lE:"≦",le:"≤",LeftAngleBracket:"⟨",LeftArrow:"←",Leftarrow:"⇐",leftarrow:"←",LeftArrowBar:"⇤",LeftArrowRightArrow:"⇆",leftarrowtail:"↢",LeftCeiling:"⌈",LeftDoubleBracket:"⟦",LeftDownTeeVector:"⥡",LeftDownVector:"⇃",LeftDownVectorBar:"⥙",LeftFloor:"⌊",leftharpoondown:"↽",leftharpoonup:"↼",leftleftarrows:"⇇",LeftRightArrow:"↔",Leftrightarrow:"⇔",leftrightarrow:"↔",leftrightarrows:"⇆",leftrightharpoons:"⇋",leftrightsquigarrow:"↭",LeftRightVector:"⥎",LeftTee:"⊣",LeftTeeArrow:"↤",LeftTeeVector:"⥚",leftthreetimes:"⋋",LeftTriangle:"⊲",LeftTriangleBar:"⧏",LeftTriangleEqual:"⊴",LeftUpDownVector:"⥑",LeftUpTeeVector:"⥠",LeftUpVector:"↿",LeftUpVectorBar:"⥘",LeftVector:"↼",LeftVectorBar:"⥒",lEg:"⪋",leg:"⋚",leq:"≤",leqq:"≦",leqslant:"⩽",les:"⩽",lescc:"⪨",lesdot:"⩿",lesdoto:"⪁",lesdotor:"⪃",lesg:"⋚︀",lesges:"⪓",lessapprox:"⪅",lessdot:"⋖",lesseqgtr:"⋚",lesseqqgtr:"⪋",LessEqualGreater:"⋚",LessFullEqual:"≦",LessGreater:"≶",lessgtr:"≶",LessLess:"⪡",lesssim:"≲",LessSlantEqual:"⩽",LessTilde:"≲",lfisht:"⥼",lfloor:"⌊",Lfr:"𝔏",lfr:"𝔩",lg:"≶",lgE:"⪑",lHar:"⥢",lhard:"↽",lharu:"↼",lharul:"⥪",lhblk:"▄",LJcy:"Љ",ljcy:"љ",Ll:"⋘",ll:"≪",llarr:"⇇",llcorner:"⌞",Lleftarrow:"⇚",llhard:"⥫",lltri:"◺",Lmidot:"Ŀ",lmidot:"ŀ",lmoust:"⎰",lmoustache:"⎰",lnap:"⪉",lnapprox:"⪉",lnE:"≨",lne:"⪇",lneq:"⪇",lneqq:"≨",lnsim:"⋦",loang:"⟬",loarr:"⇽",lobrk:"⟦",LongLeftArrow:"⟵",Longleftarrow:"⟸",longleftarrow:"⟵",LongLeftRightArrow:"⟷",Longleftrightarrow:"⟺",longleftrightarrow:"⟷",longmapsto:"⟼",LongRightArrow:"⟶",Longrightarrow:"⟹",longrightarrow:"⟶",looparrowleft:"↫",looparrowright:"↬",lopar:"⦅",Lopf:"𝕃",lopf:"𝕝",loplus:"⨭",lotimes:"⨴",lowast:"∗",lowbar:"_",LowerLeftArrow:"↙",LowerRightArrow:"↘",loz:"◊",lozenge:"◊",lozf:"⧫",lpar:"(",lparlt:"⦓",lrarr:"⇆",lrcorner:"⌟",lrhar:"⇋",lrhard:"⥭",lrm:"",lrtri:"⊿",lsaquo:"‹",Lscr:"ℒ",lscr:"𝓁",Lsh:"↰",lsh:"↰",lsim:"≲",lsime:"⪍",lsimg:"⪏",lsqb:"[",lsquo:"‘",lsquor:"‚",Lstrok:"Ł",lstrok:"ł",Lt:"≪",LT:"<",lt:"<",ltcc:"⪦",ltcir:"⩹",ltdot:"⋖",lthree:"⋋",ltimes:"⋉",ltlarr:"⥶",ltquest:"⩻",ltri:"◃",ltrie:"⊴",ltrif:"◂",ltrPar:"⦖",lurdshar:"⥊",luruhar:"⥦",lvertneqq:"≨︀",lvnE:"≨︀",macr:"¯",male:"♂",malt:"✠",maltese:"✠",Map:"⤅",map:"↦",mapsto:"↦",mapstodown:"↧",mapstoleft:"↤",mapstoup:"↥",marker:"▮",mcomma:"⨩",Mcy:"М",mcy:"м",mdash:"—",mDDot:"∺",measuredangle:"∡",MediumSpace:" ",Mellintrf:"ℳ",Mfr:"𝔐",mfr:"𝔪",mho:"℧",micro:"µ",mid:"∣",midast:"*",midcir:"⫰",middot:"·",minus:"−",minusb:"⊟",minusd:"∸",minusdu:"⨪",MinusPlus:"∓",mlcp:"⫛",mldr:"…",mnplus:"∓",models:"⊧",Mopf:"𝕄",mopf:"𝕞",mp:"∓",Mscr:"ℳ",mscr:"𝓂",mstpos:"∾",Mu:"Μ",mu:"μ",multimap:"⊸",mumap:"⊸",nabla:"∇",Nacute:"Ń",nacute:"ń",nang:"∠⃒",nap:"≉",napE:"⩰̸",napid:"≋̸",napos:"ʼn",napprox:"≉",natur:"♮",natural:"♮",naturals:"ℕ",nbsp:" ",nbump:"≎̸",nbumpe:"≏̸",ncap:"⩃",Ncaron:"Ň",ncaron:"ň",Ncedil:"Ņ",ncedil:"ņ",ncong:"≇",ncongdot:"⩭̸",ncup:"⩂",Ncy:"Н",ncy:"н",ndash:"–",ne:"≠",nearhk:"⤤",neArr:"⇗",nearr:"↗",nearrow:"↗",nedot:"≐̸",NegativeMediumSpace:"",NegativeThickSpace:"",NegativeThinSpace:"",NegativeVeryThinSpace:"",nequiv:"≢",nesear:"⤨",nesim:"≂̸",NestedGreaterGreater:"≫",NestedLessLess:"≪",NewLine:`
|
|
295
|
-
`,nexist:"∄",nexists:"∄",Nfr:"𝔑",nfr:"𝔫",ngE:"≧̸",nge:"≱",ngeq:"≱",ngeqq:"≧̸",ngeqslant:"⩾̸",nges:"⩾̸",nGg:"⋙̸",ngsim:"≵",nGt:"≫⃒",ngt:"≯",ngtr:"≯",nGtv:"≫̸",nhArr:"⇎",nharr:"↮",nhpar:"⫲",ni:"∋",nis:"⋼",nisd:"⋺",niv:"∋",NJcy:"Њ",njcy:"њ",nlArr:"⇍",nlarr:"↚",nldr:"‥",nlE:"≦̸",nle:"≰",nLeftarrow:"⇍",nleftarrow:"↚",nLeftrightarrow:"⇎",nleftrightarrow:"↮",nleq:"≰",nleqq:"≦̸",nleqslant:"⩽̸",nles:"⩽̸",nless:"≮",nLl:"⋘̸",nlsim:"≴",nLt:"≪⃒",nlt:"≮",nltri:"⋪",nltrie:"⋬",nLtv:"≪̸",nmid:"∤",NoBreak:"",NonBreakingSpace:" ",Nopf:"ℕ",nopf:"𝕟",Not:"⫬",not:"¬",NotCongruent:"≢",NotCupCap:"≭",NotDoubleVerticalBar:"∦",NotElement:"∉",NotEqual:"≠",NotEqualTilde:"≂̸",NotExists:"∄",NotGreater:"≯",NotGreaterEqual:"≱",NotGreaterFullEqual:"≧̸",NotGreaterGreater:"≫̸",NotGreaterLess:"≹",NotGreaterSlantEqual:"⩾̸",NotGreaterTilde:"≵",NotHumpDownHump:"≎̸",NotHumpEqual:"≏̸",notin:"∉",notindot:"⋵̸",notinE:"⋹̸",notinva:"∉",notinvb:"⋷",notinvc:"⋶",NotLeftTriangle:"⋪",NotLeftTriangleBar:"⧏̸",NotLeftTriangleEqual:"⋬",NotLess:"≮",NotLessEqual:"≰",NotLessGreater:"≸",NotLessLess:"≪̸",NotLessSlantEqual:"⩽̸",NotLessTilde:"≴",NotNestedGreaterGreater:"⪢̸",NotNestedLessLess:"⪡̸",notni:"∌",notniva:"∌",notnivb:"⋾",notnivc:"⋽",NotPrecedes:"⊀",NotPrecedesEqual:"⪯̸",NotPrecedesSlantEqual:"⋠",NotReverseElement:"∌",NotRightTriangle:"⋫",NotRightTriangleBar:"⧐̸",NotRightTriangleEqual:"⋭",NotSquareSubset:"⊏̸",NotSquareSubsetEqual:"⋢",NotSquareSuperset:"⊐̸",NotSquareSupersetEqual:"⋣",NotSubset:"⊂⃒",NotSubsetEqual:"⊈",NotSucceeds:"⊁",NotSucceedsEqual:"⪰̸",NotSucceedsSlantEqual:"⋡",NotSucceedsTilde:"≿̸",NotSuperset:"⊃⃒",NotSupersetEqual:"⊉",NotTilde:"≁",NotTildeEqual:"≄",NotTildeFullEqual:"≇",NotTildeTilde:"≉",NotVerticalBar:"∤",npar:"∦",nparallel:"∦",nparsl:"⫽⃥",npart:"∂̸",npolint:"⨔",npr:"⊀",nprcue:"⋠",npre:"⪯̸",nprec:"⊀",npreceq:"⪯̸",nrArr:"⇏",nrarr:"↛",nrarrc:"⤳̸",nrarrw:"↝̸",nRightarrow:"⇏",nrightarrow:"↛",nrtri:"⋫",nrtrie:"⋭",nsc:"⊁",nsccue:"⋡",nsce:"⪰̸",Nscr:"𝒩",nscr:"𝓃",nshortmid:"∤",nshortparallel:"∦",nsim:"≁",nsime:"≄",nsimeq:"≄",nsmid:"∤",nspar:"∦",nsqsube:"⋢",nsqsupe:"⋣",nsub:"⊄",nsubE:"⫅̸",nsube:"⊈",nsubset:"⊂⃒",nsubseteq:"⊈",nsubseteqq:"⫅̸",nsucc:"⊁",nsucceq:"⪰̸",nsup:"⊅",nsupE:"⫆̸",nsupe:"⊉",nsupset:"⊃⃒",nsupseteq:"⊉",nsupseteqq:"⫆̸",ntgl:"≹",Ntilde:"Ñ",ntilde:"ñ",ntlg:"≸",ntriangleleft:"⋪",ntrianglelefteq:"⋬",ntriangleright:"⋫",ntrianglerighteq:"⋭",Nu:"Ν",nu:"ν",num:"#",numero:"№",numsp:" ",nvap:"≍⃒",nVDash:"⊯",nVdash:"⊮",nvDash:"⊭",nvdash:"⊬",nvge:"≥⃒",nvgt:">⃒",nvHarr:"⤄",nvinfin:"⧞",nvlArr:"⤂",nvle:"≤⃒",nvlt:"<⃒",nvltrie:"⊴⃒",nvrArr:"⤃",nvrtrie:"⊵⃒",nvsim:"∼⃒",nwarhk:"⤣",nwArr:"⇖",nwarr:"↖",nwarrow:"↖",nwnear:"⤧",Oacute:"Ó",oacute:"ó",oast:"⊛",ocir:"⊚",Ocirc:"Ô",ocirc:"ô",Ocy:"О",ocy:"о",odash:"⊝",Odblac:"Ő",odblac:"ő",odiv:"⨸",odot:"⊙",odsold:"⦼",OElig:"Œ",oelig:"œ",ofcir:"⦿",Ofr:"𝔒",ofr:"𝔬",ogon:"˛",Ograve:"Ò",ograve:"ò",ogt:"⧁",ohbar:"⦵",ohm:"Ω",oint:"∮",olarr:"↺",olcir:"⦾",olcross:"⦻",oline:"‾",olt:"⧀",Omacr:"Ō",omacr:"ō",Omega:"Ω",omega:"ω",Omicron:"Ο",omicron:"ο",omid:"⦶",ominus:"⊖",Oopf:"𝕆",oopf:"𝕠",opar:"⦷",OpenCurlyDoubleQuote:"“",OpenCurlyQuote:"‘",operp:"⦹",oplus:"⊕",Or:"⩔",or:"∨",orarr:"↻",ord:"⩝",order:"ℴ",orderof:"ℴ",ordf:"ª",ordm:"º",origof:"⊶",oror:"⩖",orslope:"⩗",orv:"⩛",oS:"Ⓢ",Oscr:"𝒪",oscr:"ℴ",Oslash:"Ø",oslash:"ø",osol:"⊘",Otilde:"Õ",otilde:"õ",Otimes:"⨷",otimes:"⊗",otimesas:"⨶",Ouml:"Ö",ouml:"ö",ovbar:"⌽",OverBar:"‾",OverBrace:"⏞",OverBracket:"⎴",OverParenthesis:"⏜",par:"∥",para:"¶",parallel:"∥",parsim:"⫳",parsl:"⫽",part:"∂",PartialD:"∂",Pcy:"П",pcy:"п",percnt:"%",period:".",permil:"‰",perp:"⊥",pertenk:"‱",Pfr:"𝔓",pfr:"𝔭",Phi:"Φ",phi:"φ",phiv:"ϕ",phmmat:"ℳ",phone:"☎",Pi:"Π",pi:"π",pitchfork:"⋔",piv:"ϖ",planck:"ℏ",planckh:"ℎ",plankv:"ℏ",plus:"+",plusacir:"⨣",plusb:"⊞",pluscir:"⨢",plusdo:"∔",plusdu:"⨥",pluse:"⩲",PlusMinus:"±",plusmn:"±",plussim:"⨦",plustwo:"⨧",pm:"±",Poincareplane:"ℌ",pointint:"⨕",Popf:"ℙ",popf:"𝕡",pound:"£",Pr:"⪻",pr:"≺",prap:"⪷",prcue:"≼",prE:"⪳",pre:"⪯",prec:"≺",precapprox:"⪷",preccurlyeq:"≼",Precedes:"≺",PrecedesEqual:"⪯",PrecedesSlantEqual:"≼",PrecedesTilde:"≾",preceq:"⪯",precnapprox:"⪹",precneqq:"⪵",precnsim:"⋨",precsim:"≾",Prime:"″",prime:"′",primes:"ℙ",prnap:"⪹",prnE:"⪵",prnsim:"⋨",prod:"∏",Product:"∏",profalar:"⌮",profline:"⌒",profsurf:"⌓",prop:"∝",Proportion:"∷",Proportional:"∝",propto:"∝",prsim:"≾",prurel:"⊰",Pscr:"𝒫",pscr:"𝓅",Psi:"Ψ",psi:"ψ",puncsp:" ",Qfr:"𝔔",qfr:"𝔮",qint:"⨌",Qopf:"ℚ",qopf:"𝕢",qprime:"⁗",Qscr:"𝒬",qscr:"𝓆",quaternions:"ℍ",quatint:"⨖",quest:"?",questeq:"≟",QUOT:'"',quot:'"',rAarr:"⇛",race:"∽̱",Racute:"Ŕ",racute:"ŕ",radic:"√",raemptyv:"⦳",Rang:"⟫",rang:"⟩",rangd:"⦒",range:"⦥",rangle:"⟩",raquo:"»",Rarr:"↠",rArr:"⇒",rarr:"→",rarrap:"⥵",rarrb:"⇥",rarrbfs:"⤠",rarrc:"⤳",rarrfs:"⤞",rarrhk:"↪",rarrlp:"↬",rarrpl:"⥅",rarrsim:"⥴",Rarrtl:"⤖",rarrtl:"↣",rarrw:"↝",rAtail:"⤜",ratail:"⤚",ratio:"∶",rationals:"ℚ",RBarr:"⤐",rBarr:"⤏",rbarr:"⤍",rbbrk:"❳",rbrace:"}",rbrack:"]",rbrke:"⦌",rbrksld:"⦎",rbrkslu:"⦐",Rcaron:"Ř",rcaron:"ř",Rcedil:"Ŗ",rcedil:"ŗ",rceil:"⌉",rcub:"}",Rcy:"Р",rcy:"р",rdca:"⤷",rdldhar:"⥩",rdquo:"”",rdquor:"”",rdsh:"↳",Re:"ℜ",real:"ℜ",realine:"ℛ",realpart:"ℜ",reals:"ℝ",rect:"▭",REG:"®",reg:"®",ReverseElement:"∋",ReverseEquilibrium:"⇋",ReverseUpEquilibrium:"⥯",rfisht:"⥽",rfloor:"⌋",Rfr:"ℜ",rfr:"𝔯",rHar:"⥤",rhard:"⇁",rharu:"⇀",rharul:"⥬",Rho:"Ρ",rho:"ρ",rhov:"ϱ",RightAngleBracket:"⟩",RightArrow:"→",Rightarrow:"⇒",rightarrow:"→",RightArrowBar:"⇥",RightArrowLeftArrow:"⇄",rightarrowtail:"↣",RightCeiling:"⌉",RightDoubleBracket:"⟧",RightDownTeeVector:"⥝",RightDownVector:"⇂",RightDownVectorBar:"⥕",RightFloor:"⌋",rightharpoondown:"⇁",rightharpoonup:"⇀",rightleftarrows:"⇄",rightleftharpoons:"⇌",rightrightarrows:"⇉",rightsquigarrow:"↝",RightTee:"⊢",RightTeeArrow:"↦",RightTeeVector:"⥛",rightthreetimes:"⋌",RightTriangle:"⊳",RightTriangleBar:"⧐",RightTriangleEqual:"⊵",RightUpDownVector:"⥏",RightUpTeeVector:"⥜",RightUpVector:"↾",RightUpVectorBar:"⥔",RightVector:"⇀",RightVectorBar:"⥓",ring:"˚",risingdotseq:"≓",rlarr:"⇄",rlhar:"⇌",rlm:"",rmoust:"⎱",rmoustache:"⎱",rnmid:"⫮",roang:"⟭",roarr:"⇾",robrk:"⟧",ropar:"⦆",Ropf:"ℝ",ropf:"𝕣",roplus:"⨮",rotimes:"⨵",RoundImplies:"⥰",rpar:")",rpargt:"⦔",rppolint:"⨒",rrarr:"⇉",Rrightarrow:"⇛",rsaquo:"›",Rscr:"ℛ",rscr:"𝓇",Rsh:"↱",rsh:"↱",rsqb:"]",rsquo:"’",rsquor:"’",rthree:"⋌",rtimes:"⋊",rtri:"▹",rtrie:"⊵",rtrif:"▸",rtriltri:"⧎",RuleDelayed:"⧴",ruluhar:"⥨",rx:"℞",Sacute:"Ś",sacute:"ś",sbquo:"‚",Sc:"⪼",sc:"≻",scap:"⪸",Scaron:"Š",scaron:"š",sccue:"≽",scE:"⪴",sce:"⪰",Scedil:"Ş",scedil:"ş",Scirc:"Ŝ",scirc:"ŝ",scnap:"⪺",scnE:"⪶",scnsim:"⋩",scpolint:"⨓",scsim:"≿",Scy:"С",scy:"с",sdot:"⋅",sdotb:"⊡",sdote:"⩦",searhk:"⤥",seArr:"⇘",searr:"↘",searrow:"↘",sect:"§",semi:";",seswar:"⤩",setminus:"∖",setmn:"∖",sext:"✶",Sfr:"𝔖",sfr:"𝔰",sfrown:"⌢",sharp:"♯",SHCHcy:"Щ",shchcy:"щ",SHcy:"Ш",shcy:"ш",ShortDownArrow:"↓",ShortLeftArrow:"←",shortmid:"∣",shortparallel:"∥",ShortRightArrow:"→",ShortUpArrow:"↑",shy:"",Sigma:"Σ",sigma:"σ",sigmaf:"ς",sigmav:"ς",sim:"∼",simdot:"⩪",sime:"≃",simeq:"≃",simg:"⪞",simgE:"⪠",siml:"⪝",simlE:"⪟",simne:"≆",simplus:"⨤",simrarr:"⥲",slarr:"←",SmallCircle:"∘",smallsetminus:"∖",smashp:"⨳",smeparsl:"⧤",smid:"∣",smile:"⌣",smt:"⪪",smte:"⪬",smtes:"⪬︀",SOFTcy:"Ь",softcy:"ь",sol:"/",solb:"⧄",solbar:"⌿",Sopf:"𝕊",sopf:"𝕤",spades:"♠",spadesuit:"♠",spar:"∥",sqcap:"⊓",sqcaps:"⊓︀",sqcup:"⊔",sqcups:"⊔︀",Sqrt:"√",sqsub:"⊏",sqsube:"⊑",sqsubset:"⊏",sqsubseteq:"⊑",sqsup:"⊐",sqsupe:"⊒",sqsupset:"⊐",sqsupseteq:"⊒",squ:"□",Square:"□",square:"□",SquareIntersection:"⊓",SquareSubset:"⊏",SquareSubsetEqual:"⊑",SquareSuperset:"⊐",SquareSupersetEqual:"⊒",SquareUnion:"⊔",squarf:"▪",squf:"▪",srarr:"→",Sscr:"𝒮",sscr:"𝓈",ssetmn:"∖",ssmile:"⌣",sstarf:"⋆",Star:"⋆",star:"☆",starf:"★",straightepsilon:"ϵ",straightphi:"ϕ",strns:"¯",Sub:"⋐",sub:"⊂",subdot:"⪽",subE:"⫅",sube:"⊆",subedot:"⫃",submult:"⫁",subnE:"⫋",subne:"⊊",subplus:"⪿",subrarr:"⥹",Subset:"⋐",subset:"⊂",subseteq:"⊆",subseteqq:"⫅",SubsetEqual:"⊆",subsetneq:"⊊",subsetneqq:"⫋",subsim:"⫇",subsub:"⫕",subsup:"⫓",succ:"≻",succapprox:"⪸",succcurlyeq:"≽",Succeeds:"≻",SucceedsEqual:"⪰",SucceedsSlantEqual:"≽",SucceedsTilde:"≿",succeq:"⪰",succnapprox:"⪺",succneqq:"⪶",succnsim:"⋩",succsim:"≿",SuchThat:"∋",Sum:"∑",sum:"∑",sung:"♪",Sup:"⋑",sup:"⊃",sup1:"¹",sup2:"²",sup3:"³",supdot:"⪾",supdsub:"⫘",supE:"⫆",supe:"⊇",supedot:"⫄",Superset:"⊃",SupersetEqual:"⊇",suphsol:"⟉",suphsub:"⫗",suplarr:"⥻",supmult:"⫂",supnE:"⫌",supne:"⊋",supplus:"⫀",Supset:"⋑",supset:"⊃",supseteq:"⊇",supseteqq:"⫆",supsetneq:"⊋",supsetneqq:"⫌",supsim:"⫈",supsub:"⫔",supsup:"⫖",swarhk:"⤦",swArr:"⇙",swarr:"↙",swarrow:"↙",swnwar:"⤪",szlig:"ß",Tab:" ",target:"⌖",Tau:"Τ",tau:"τ",tbrk:"⎴",Tcaron:"Ť",tcaron:"ť",Tcedil:"Ţ",tcedil:"ţ",Tcy:"Т",tcy:"т",tdot:"⃛",telrec:"⌕",Tfr:"𝔗",tfr:"𝔱",there4:"∴",Therefore:"∴",therefore:"∴",Theta:"Θ",theta:"θ",thetasym:"ϑ",thetav:"ϑ",thickapprox:"≈",thicksim:"∼",ThickSpace:" ",thinsp:" ",ThinSpace:" ",thkap:"≈",thksim:"∼",THORN:"Þ",thorn:"þ",Tilde:"∼",tilde:"˜",TildeEqual:"≃",TildeFullEqual:"≅",TildeTilde:"≈",times:"×",timesb:"⊠",timesbar:"⨱",timesd:"⨰",tint:"∭",toea:"⤨",top:"⊤",topbot:"⌶",topcir:"⫱",Topf:"𝕋",topf:"𝕥",topfork:"⫚",tosa:"⤩",tprime:"‴",TRADE:"™",trade:"™",triangle:"▵",triangledown:"▿",triangleleft:"◃",trianglelefteq:"⊴",triangleq:"≜",triangleright:"▹",trianglerighteq:"⊵",tridot:"◬",trie:"≜",triminus:"⨺",TripleDot:"⃛",triplus:"⨹",trisb:"⧍",tritime:"⨻",trpezium:"⏢",Tscr:"𝒯",tscr:"𝓉",TScy:"Ц",tscy:"ц",TSHcy:"Ћ",tshcy:"ћ",Tstrok:"Ŧ",tstrok:"ŧ",twixt:"≬",twoheadleftarrow:"↞",twoheadrightarrow:"↠",Uacute:"Ú",uacute:"ú",Uarr:"↟",uArr:"⇑",uarr:"↑",Uarrocir:"⥉",Ubrcy:"Ў",ubrcy:"ў",Ubreve:"Ŭ",ubreve:"ŭ",Ucirc:"Û",ucirc:"û",Ucy:"У",ucy:"у",udarr:"⇅",Udblac:"Ű",udblac:"ű",udhar:"⥮",ufisht:"⥾",Ufr:"𝔘",ufr:"𝔲",Ugrave:"Ù",ugrave:"ù",uHar:"⥣",uharl:"↿",uharr:"↾",uhblk:"▀",ulcorn:"⌜",ulcorner:"⌜",ulcrop:"⌏",ultri:"◸",Umacr:"Ū",umacr:"ū",uml:"¨",UnderBar:"_",UnderBrace:"⏟",UnderBracket:"⎵",UnderParenthesis:"⏝",Union:"⋃",UnionPlus:"⊎",Uogon:"Ų",uogon:"ų",Uopf:"𝕌",uopf:"𝕦",UpArrow:"↑",Uparrow:"⇑",uparrow:"↑",UpArrowBar:"⤒",UpArrowDownArrow:"⇅",UpDownArrow:"↕",Updownarrow:"⇕",updownarrow:"↕",UpEquilibrium:"⥮",upharpoonleft:"↿",upharpoonright:"↾",uplus:"⊎",UpperLeftArrow:"↖",UpperRightArrow:"↗",Upsi:"ϒ",upsi:"υ",upsih:"ϒ",Upsilon:"Υ",upsilon:"υ",UpTee:"⊥",UpTeeArrow:"↥",upuparrows:"⇈",urcorn:"⌝",urcorner:"⌝",urcrop:"⌎",Uring:"Ů",uring:"ů",urtri:"◹",Uscr:"𝒰",uscr:"𝓊",utdot:"⋰",Utilde:"Ũ",utilde:"ũ",utri:"▵",utrif:"▴",uuarr:"⇈",Uuml:"Ü",uuml:"ü",uwangle:"⦧",vangrt:"⦜",varepsilon:"ϵ",varkappa:"ϰ",varnothing:"∅",varphi:"ϕ",varpi:"ϖ",varpropto:"∝",vArr:"⇕",varr:"↕",varrho:"ϱ",varsigma:"ς",varsubsetneq:"⊊︀",varsubsetneqq:"⫋︀",varsupsetneq:"⊋︀",varsupsetneqq:"⫌︀",vartheta:"ϑ",vartriangleleft:"⊲",vartriangleright:"⊳",Vbar:"⫫",vBar:"⫨",vBarv:"⫩",Vcy:"В",vcy:"в",VDash:"⊫",Vdash:"⊩",vDash:"⊨",vdash:"⊢",Vdashl:"⫦",Vee:"⋁",vee:"∨",veebar:"⊻",veeeq:"≚",vellip:"⋮",Verbar:"‖",verbar:"|",Vert:"‖",vert:"|",VerticalBar:"∣",VerticalLine:"|",VerticalSeparator:"❘",VerticalTilde:"≀",VeryThinSpace:" ",Vfr:"𝔙",vfr:"𝔳",vltri:"⊲",vnsub:"⊂⃒",vnsup:"⊃⃒",Vopf:"𝕍",vopf:"𝕧",vprop:"∝",vrtri:"⊳",Vscr:"𝒱",vscr:"𝓋",vsubnE:"⫋︀",vsubne:"⊊︀",vsupnE:"⫌︀",vsupne:"⊋︀",Vvdash:"⊪",vzigzag:"⦚",Wcirc:"Ŵ",wcirc:"ŵ",wedbar:"⩟",Wedge:"⋀",wedge:"∧",wedgeq:"≙",weierp:"℘",Wfr:"𝔚",wfr:"𝔴",Wopf:"𝕎",wopf:"𝕨",wp:"℘",wr:"≀",wreath:"≀",Wscr:"𝒲",wscr:"𝓌",xcap:"⋂",xcirc:"◯",xcup:"⋃",xdtri:"▽",Xfr:"𝔛",xfr:"𝔵",xhArr:"⟺",xharr:"⟷",Xi:"Ξ",xi:"ξ",xlArr:"⟸",xlarr:"⟵",xmap:"⟼",xnis:"⋻",xodot:"⨀",Xopf:"𝕏",xopf:"𝕩",xoplus:"⨁",xotime:"⨂",xrArr:"⟹",xrarr:"⟶",Xscr:"𝒳",xscr:"𝓍",xsqcup:"⨆",xuplus:"⨄",xutri:"△",xvee:"⋁",xwedge:"⋀",Yacute:"Ý",yacute:"ý",YAcy:"Я",yacy:"я",Ycirc:"Ŷ",ycirc:"ŷ",Ycy:"Ы",ycy:"ы",yen:"¥",Yfr:"𝔜",yfr:"𝔶",YIcy:"Ї",yicy:"ї",Yopf:"𝕐",yopf:"𝕪",Yscr:"𝒴",yscr:"𝓎",YUcy:"Ю",yucy:"ю",Yuml:"Ÿ",yuml:"ÿ",Zacute:"Ź",zacute:"ź",Zcaron:"Ž",zcaron:"ž",Zcy:"З",zcy:"з",Zdot:"Ż",zdot:"ż",zeetrf:"ℨ",ZeroWidthSpace:"",Zeta:"Ζ",zeta:"ζ",Zfr:"ℨ",zfr:"𝔷",ZHcy:"Ж",zhcy:"ж",zigrarr:"⇝",Zopf:"ℤ",zopf:"𝕫",Zscr:"𝒵",zscr:"𝓏",zwj:"",zwnj:""}),t.entityMap=t.HTML_ENTITIES})(Ew);var ih={},os=ar.NAMESPACE,mp=/[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,xm=new RegExp("[\\-\\.0-9"+mp.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]"),Am=new RegExp("^"+mp.source+xm.source+"*(?::"+mp.source+xm.source+"*)?$"),bo=0,dr=1,yi=2,$o=3,wi=4,vi=5,xo=6,Js=7;function Yi(t,e){this.message=t,this.locator=e,Error.captureStackTrace&&Error.captureStackTrace(this,Yi)}Yi.prototype=new Error;Yi.prototype.name=Yi.name;function Sw(){}Sw.prototype={parse:function(t,e,n){var r=this.domBuilder;r.startDocument(),kw(e,e={}),bS(t,e,n,r,this.errorHandler),r.endDocument()}};function bS(t,e,n,r,i){function s(B){if(B>65535){B-=65536;var H=55296+(B>>10),de=56320+(B&1023);return String.fromCharCode(H,de)}else return String.fromCharCode(B)}function a(B){var H=B.slice(1,-1);return Object.hasOwnProperty.call(n,H)?n[H]:H.charAt(0)==="#"?s(parseInt(H.substr(1).replace("x","0x"))):(i.error("entity not found:"+B),B)}function l(B){if(B>z){var H=t.substring(z,B).replace(/&#?\w+;/g,a);g&&u(z),r.characters(H,0,B-z),z=B}}function u(B,H){for(;B>=p&&(H=h.exec(t));)d=H.index,p=d+H[0].length,g.lineNumber++;g.columnNumber=B-d+1}for(var d=0,p=0,h=/.*(?:\r\n?|\n)|.*$/g,g=r.locator,$=[{currentNSMap:e}],A={},z=0;;){try{var T=t.indexOf("<",z);if(T<0){if(!t.substr(z).match(/^\s*$/)){var O=r.doc,x=O.createTextNode(t.substr(z));O.appendChild(x),r.currentElement=x}return}switch(T>z&&l(T),t.charAt(T+1)){case"/":var R=t.indexOf(">",T+3),U=t.substring(T+2,R).replace(/[ \t\n\r]+$/g,""),q=$.pop();R<0?(U=t.substring(T+2).replace(/[\s<].*/,""),i.error("end tag name: "+U+" is not complete:"+q.tagName),R=T+1+U.length):U.match(/\s</)&&(U=U.replace(/[\s<].*/,""),i.error("end tag name: "+U+" maybe not complete"),R=T+1+U.length);var F=q.localNSMap,K=q.tagName==U,G=K||q.tagName&&q.tagName.toLowerCase()==U.toLowerCase();if(G){if(r.endElement(q.uri,q.localName,U),F)for(var Y in F)Object.prototype.hasOwnProperty.call(F,Y)&&r.endPrefixMapping(Y);K||i.fatalError("end tag name: "+U+" is not match the current start tagName:"+q.tagName)}else $.push(q);R++;break;case"?":g&&u(T),R=SS(t,T,r);break;case"!":g&&u(T),R=ES(t,T,r,i);break;default:g&&u(T);var J=new Nw,Ae=$[$.length-1].currentNSMap,R=$S(t,T,J,Ae,a,i),L=J.length;if(!J.closed&&AS(t,R,J.tagName,A)&&(J.closed=!0,n.nbsp||i.warning("unclosed xml attribute")),g&&L){for(var j=Em(g,{}),N=0;N<L;N++){var k=J[N];u(k.offset),k.locator=Em(g,{})}r.locator=j,Sm(J,r,Ae)&&$.push(J),r.locator=g}else Sm(J,r,Ae)&&$.push(J);os.isHTML(J.uri)&&!J.closed?R=xS(t,R,J.tagName,a,r):R++}}catch(B){if(B instanceof Yi)throw B;i.error("element parse error: "+B),R=-1}R>z?z=R:l(Math.max(T,z)+1)}}function Em(t,e){return e.lineNumber=t.lineNumber,e.columnNumber=t.columnNumber,e}function $S(t,e,n,r,i,s){function a(g,$,A){n.attributeNames.hasOwnProperty(g)&&s.fatalError("Attribute "+g+" redefined"),n.addValue(g,$.replace(/[\t\n\r]/g," ").replace(/&#?\w+;/g,i),A)}for(var l,u,d=++e,p=bo;;){var h=t.charAt(d);switch(h){case"=":if(p===dr)l=t.slice(e,d),p=$o;else if(p===yi)p=$o;else throw new Error("attribute equal must after attrName");break;case"'":case'"':if(p===$o||p===dr)if(p===dr&&(s.warning('attribute value must after "="'),l=t.slice(e,d)),e=d+1,d=t.indexOf(h,e),d>0)u=t.slice(e,d),a(l,u,e-1),p=vi;else throw new Error("attribute value no end '"+h+"' match");else if(p==wi)u=t.slice(e,d),a(l,u,e),s.warning('attribute "'+l+'" missed start quot('+h+")!!"),e=d+1,p=vi;else throw new Error('attribute value must after "="');break;case"/":switch(p){case bo:n.setTagName(t.slice(e,d));case vi:case xo:case Js:p=Js,n.closed=!0;case wi:case dr:break;case yi:n.closed=!0;break;default:throw new Error("attribute invalid close char('/')")}break;case"":return s.error("unexpected end of input"),p==bo&&n.setTagName(t.slice(e,d)),d;case">":switch(p){case bo:n.setTagName(t.slice(e,d));case vi:case xo:case Js:break;case wi:case dr:u=t.slice(e,d),u.slice(-1)==="/"&&(n.closed=!0,u=u.slice(0,-1));case yi:p===yi&&(u=l),p==wi?(s.warning('attribute "'+u+'" missed quot(")!'),a(l,u,e)):((!os.isHTML(r[""])||!u.match(/^(?:disabled|checked|selected)$/i))&&s.warning('attribute "'+u+'" missed value!! "'+u+'" instead!!'),a(u,u,e));break;case $o:throw new Error("attribute value missed!!")}return d;case"":h=" ";default:if(h<=" ")switch(p){case bo:n.setTagName(t.slice(e,d)),p=xo;break;case dr:l=t.slice(e,d),p=yi;break;case wi:var u=t.slice(e,d);s.warning('attribute "'+u+'" missed quot(")!!'),a(l,u,e);case vi:p=xo;break}else switch(p){case yi:n.tagName,(!os.isHTML(r[""])||!l.match(/^(?:disabled|checked|selected)$/i))&&s.warning('attribute "'+l+'" missed value!! "'+l+'" instead2!!'),a(l,l,e),e=d,p=dr;break;case vi:s.warning('attribute space is required"'+l+'"!!');case xo:p=dr,e=d;break;case $o:p=wi,e=d;break;case Js:throw new Error("elements closed character '/' and '>' must be connected to")}}d++}}function Sm(t,e,n){for(var r=t.tagName,i=null,h=t.length;h--;){var s=t[h],a=s.qName,l=s.value,g=a.indexOf(":");if(g>0)var u=s.prefix=a.slice(0,g),d=a.slice(g+1),p=u==="xmlns"&&d;else d=a,u=null,p=a==="xmlns"&&"";s.localName=d,p!==!1&&(i==null&&(i={},kw(n,n={})),n[p]=i[p]=l,s.uri=os.XMLNS,e.startPrefixMapping(p,l))}for(var h=t.length;h--;){s=t[h];var u=s.prefix;u&&(u==="xml"&&(s.uri=os.XML),u!=="xmlns"&&(s.uri=n[u||""]))}var g=r.indexOf(":");g>0?(u=t.prefix=r.slice(0,g),d=t.localName=r.slice(g+1)):(u=null,d=t.localName=r);var $=t.uri=n[u||""];if(e.startElement($,d,r,t),t.closed){if(e.endElement($,d,r),i)for(u in i)Object.prototype.hasOwnProperty.call(i,u)&&e.endPrefixMapping(u)}else return t.currentNSMap=n,t.localNSMap=i,!0}function xS(t,e,n,r,i){if(/^(?:script|textarea)$/i.test(n)){var s=t.indexOf("</"+n+">",e),a=t.substring(e+1,s);if(/[&<]/.test(a))return/^script$/i.test(n)?(i.characters(a,0,a.length),s):(a=a.replace(/&#?\w+;/g,r),i.characters(a,0,a.length),s)}return e+1}function AS(t,e,n,r){var i=r[n];return i==null&&(i=t.lastIndexOf("</"+n+">"),i<e&&(i=t.lastIndexOf("</"+n)),r[n]=i),i<e}function kw(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}function ES(t,e,n,r){var i=t.charAt(e+2);switch(i){case"-":if(t.charAt(e+3)==="-"){var s=t.indexOf("-->",e+4);return s>e?(n.comment(t,e+4,s-e-4),s+3):(r.error("Unclosed comment"),-1)}else return-1;default:if(t.substr(e+3,6)=="CDATA["){var s=t.indexOf("]]>",e+9);return n.startCDATA(),n.characters(t,e+9,s-e-9),n.endCDATA(),s+3}var a=kS(t,e),l=a.length;if(l>1&&/!doctype/i.test(a[0][0])){var u=a[1][0],d=!1,p=!1;l>3&&(/^public$/i.test(a[2][0])?(d=a[3][0],p=l>4&&a[4][0]):/^system$/i.test(a[2][0])&&(p=a[3][0]));var h=a[l-1];return n.startDTD(u,d,p),n.endDTD(),h.index+h[0].length}}return-1}function SS(t,e,n){var r=t.indexOf("?>",e);if(r){var i=t.substring(e,r).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);return i?(i[0].length,n.processingInstruction(i[1],i[2]),r+2):-1}return-1}function Nw(){this.attributeNames={}}Nw.prototype={setTagName:function(t){if(!Am.test(t))throw new Error("invalid tagName:"+t);this.tagName=t},addValue:function(t,e,n){if(!Am.test(t))throw new Error("invalid attribute:"+t);this.attributeNames[t]=this.length,this[this.length++]={qName:t,value:e,offset:n}},length:0,getLocalName:function(t){return this[t].localName},getLocator:function(t){return this[t].locator},getQName:function(t){return this[t].qName},getURI:function(t){return this[t].uri},getValue:function(t){return this[t].value}};function kS(t,e){var n,r=[],i=/'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;for(i.lastIndex=e,i.exec(t);n=i.exec(t);)if(r.push(n),n[1])return r}ih.XMLReader=Sw;ih.ParseError=Yi;var NS=ar,CS=sr,km=Ew,Cw=ih,zS=CS.DOMImplementation,Nm=NS.NAMESPACE,IS=Cw.ParseError,TS=Cw.XMLReader;function zw(t){return t.replace(/\r[\n\u0085]/g,`
|
|
295
|
+
`,nexist:"∄",nexists:"∄",Nfr:"𝔑",nfr:"𝔫",ngE:"≧̸",nge:"≱",ngeq:"≱",ngeqq:"≧̸",ngeqslant:"⩾̸",nges:"⩾̸",nGg:"⋙̸",ngsim:"≵",nGt:"≫⃒",ngt:"≯",ngtr:"≯",nGtv:"≫̸",nhArr:"⇎",nharr:"↮",nhpar:"⫲",ni:"∋",nis:"⋼",nisd:"⋺",niv:"∋",NJcy:"Њ",njcy:"њ",nlArr:"⇍",nlarr:"↚",nldr:"‥",nlE:"≦̸",nle:"≰",nLeftarrow:"⇍",nleftarrow:"↚",nLeftrightarrow:"⇎",nleftrightarrow:"↮",nleq:"≰",nleqq:"≦̸",nleqslant:"⩽̸",nles:"⩽̸",nless:"≮",nLl:"⋘̸",nlsim:"≴",nLt:"≪⃒",nlt:"≮",nltri:"⋪",nltrie:"⋬",nLtv:"≪̸",nmid:"∤",NoBreak:"",NonBreakingSpace:" ",Nopf:"ℕ",nopf:"𝕟",Not:"⫬",not:"¬",NotCongruent:"≢",NotCupCap:"≭",NotDoubleVerticalBar:"∦",NotElement:"∉",NotEqual:"≠",NotEqualTilde:"≂̸",NotExists:"∄",NotGreater:"≯",NotGreaterEqual:"≱",NotGreaterFullEqual:"≧̸",NotGreaterGreater:"≫̸",NotGreaterLess:"≹",NotGreaterSlantEqual:"⩾̸",NotGreaterTilde:"≵",NotHumpDownHump:"≎̸",NotHumpEqual:"≏̸",notin:"∉",notindot:"⋵̸",notinE:"⋹̸",notinva:"∉",notinvb:"⋷",notinvc:"⋶",NotLeftTriangle:"⋪",NotLeftTriangleBar:"⧏̸",NotLeftTriangleEqual:"⋬",NotLess:"≮",NotLessEqual:"≰",NotLessGreater:"≸",NotLessLess:"≪̸",NotLessSlantEqual:"⩽̸",NotLessTilde:"≴",NotNestedGreaterGreater:"⪢̸",NotNestedLessLess:"⪡̸",notni:"∌",notniva:"∌",notnivb:"⋾",notnivc:"⋽",NotPrecedes:"⊀",NotPrecedesEqual:"⪯̸",NotPrecedesSlantEqual:"⋠",NotReverseElement:"∌",NotRightTriangle:"⋫",NotRightTriangleBar:"⧐̸",NotRightTriangleEqual:"⋭",NotSquareSubset:"⊏̸",NotSquareSubsetEqual:"⋢",NotSquareSuperset:"⊐̸",NotSquareSupersetEqual:"⋣",NotSubset:"⊂⃒",NotSubsetEqual:"⊈",NotSucceeds:"⊁",NotSucceedsEqual:"⪰̸",NotSucceedsSlantEqual:"⋡",NotSucceedsTilde:"≿̸",NotSuperset:"⊃⃒",NotSupersetEqual:"⊉",NotTilde:"≁",NotTildeEqual:"≄",NotTildeFullEqual:"≇",NotTildeTilde:"≉",NotVerticalBar:"∤",npar:"∦",nparallel:"∦",nparsl:"⫽⃥",npart:"∂̸",npolint:"⨔",npr:"⊀",nprcue:"⋠",npre:"⪯̸",nprec:"⊀",npreceq:"⪯̸",nrArr:"⇏",nrarr:"↛",nrarrc:"⤳̸",nrarrw:"↝̸",nRightarrow:"⇏",nrightarrow:"↛",nrtri:"⋫",nrtrie:"⋭",nsc:"⊁",nsccue:"⋡",nsce:"⪰̸",Nscr:"𝒩",nscr:"𝓃",nshortmid:"∤",nshortparallel:"∦",nsim:"≁",nsime:"≄",nsimeq:"≄",nsmid:"∤",nspar:"∦",nsqsube:"⋢",nsqsupe:"⋣",nsub:"⊄",nsubE:"⫅̸",nsube:"⊈",nsubset:"⊂⃒",nsubseteq:"⊈",nsubseteqq:"⫅̸",nsucc:"⊁",nsucceq:"⪰̸",nsup:"⊅",nsupE:"⫆̸",nsupe:"⊉",nsupset:"⊃⃒",nsupseteq:"⊉",nsupseteqq:"⫆̸",ntgl:"≹",Ntilde:"Ñ",ntilde:"ñ",ntlg:"≸",ntriangleleft:"⋪",ntrianglelefteq:"⋬",ntriangleright:"⋫",ntrianglerighteq:"⋭",Nu:"Ν",nu:"ν",num:"#",numero:"№",numsp:" ",nvap:"≍⃒",nVDash:"⊯",nVdash:"⊮",nvDash:"⊭",nvdash:"⊬",nvge:"≥⃒",nvgt:">⃒",nvHarr:"⤄",nvinfin:"⧞",nvlArr:"⤂",nvle:"≤⃒",nvlt:"<⃒",nvltrie:"⊴⃒",nvrArr:"⤃",nvrtrie:"⊵⃒",nvsim:"∼⃒",nwarhk:"⤣",nwArr:"⇖",nwarr:"↖",nwarrow:"↖",nwnear:"⤧",Oacute:"Ó",oacute:"ó",oast:"⊛",ocir:"⊚",Ocirc:"Ô",ocirc:"ô",Ocy:"О",ocy:"о",odash:"⊝",Odblac:"Ő",odblac:"ő",odiv:"⨸",odot:"⊙",odsold:"⦼",OElig:"Œ",oelig:"œ",ofcir:"⦿",Ofr:"𝔒",ofr:"𝔬",ogon:"˛",Ograve:"Ò",ograve:"ò",ogt:"⧁",ohbar:"⦵",ohm:"Ω",oint:"∮",olarr:"↺",olcir:"⦾",olcross:"⦻",oline:"‾",olt:"⧀",Omacr:"Ō",omacr:"ō",Omega:"Ω",omega:"ω",Omicron:"Ο",omicron:"ο",omid:"⦶",ominus:"⊖",Oopf:"𝕆",oopf:"𝕠",opar:"⦷",OpenCurlyDoubleQuote:"“",OpenCurlyQuote:"‘",operp:"⦹",oplus:"⊕",Or:"⩔",or:"∨",orarr:"↻",ord:"⩝",order:"ℴ",orderof:"ℴ",ordf:"ª",ordm:"º",origof:"⊶",oror:"⩖",orslope:"⩗",orv:"⩛",oS:"Ⓢ",Oscr:"𝒪",oscr:"ℴ",Oslash:"Ø",oslash:"ø",osol:"⊘",Otilde:"Õ",otilde:"õ",Otimes:"⨷",otimes:"⊗",otimesas:"⨶",Ouml:"Ö",ouml:"ö",ovbar:"⌽",OverBar:"‾",OverBrace:"⏞",OverBracket:"⎴",OverParenthesis:"⏜",par:"∥",para:"¶",parallel:"∥",parsim:"⫳",parsl:"⫽",part:"∂",PartialD:"∂",Pcy:"П",pcy:"п",percnt:"%",period:".",permil:"‰",perp:"⊥",pertenk:"‱",Pfr:"𝔓",pfr:"𝔭",Phi:"Φ",phi:"φ",phiv:"ϕ",phmmat:"ℳ",phone:"☎",Pi:"Π",pi:"π",pitchfork:"⋔",piv:"ϖ",planck:"ℏ",planckh:"ℎ",plankv:"ℏ",plus:"+",plusacir:"⨣",plusb:"⊞",pluscir:"⨢",plusdo:"∔",plusdu:"⨥",pluse:"⩲",PlusMinus:"±",plusmn:"±",plussim:"⨦",plustwo:"⨧",pm:"±",Poincareplane:"ℌ",pointint:"⨕",Popf:"ℙ",popf:"𝕡",pound:"£",Pr:"⪻",pr:"≺",prap:"⪷",prcue:"≼",prE:"⪳",pre:"⪯",prec:"≺",precapprox:"⪷",preccurlyeq:"≼",Precedes:"≺",PrecedesEqual:"⪯",PrecedesSlantEqual:"≼",PrecedesTilde:"≾",preceq:"⪯",precnapprox:"⪹",precneqq:"⪵",precnsim:"⋨",precsim:"≾",Prime:"″",prime:"′",primes:"ℙ",prnap:"⪹",prnE:"⪵",prnsim:"⋨",prod:"∏",Product:"∏",profalar:"⌮",profline:"⌒",profsurf:"⌓",prop:"∝",Proportion:"∷",Proportional:"∝",propto:"∝",prsim:"≾",prurel:"⊰",Pscr:"𝒫",pscr:"𝓅",Psi:"Ψ",psi:"ψ",puncsp:" ",Qfr:"𝔔",qfr:"𝔮",qint:"⨌",Qopf:"ℚ",qopf:"𝕢",qprime:"⁗",Qscr:"𝒬",qscr:"𝓆",quaternions:"ℍ",quatint:"⨖",quest:"?",questeq:"≟",QUOT:'"',quot:'"',rAarr:"⇛",race:"∽̱",Racute:"Ŕ",racute:"ŕ",radic:"√",raemptyv:"⦳",Rang:"⟫",rang:"⟩",rangd:"⦒",range:"⦥",rangle:"⟩",raquo:"»",Rarr:"↠",rArr:"⇒",rarr:"→",rarrap:"⥵",rarrb:"⇥",rarrbfs:"⤠",rarrc:"⤳",rarrfs:"⤞",rarrhk:"↪",rarrlp:"↬",rarrpl:"⥅",rarrsim:"⥴",Rarrtl:"⤖",rarrtl:"↣",rarrw:"↝",rAtail:"⤜",ratail:"⤚",ratio:"∶",rationals:"ℚ",RBarr:"⤐",rBarr:"⤏",rbarr:"⤍",rbbrk:"❳",rbrace:"}",rbrack:"]",rbrke:"⦌",rbrksld:"⦎",rbrkslu:"⦐",Rcaron:"Ř",rcaron:"ř",Rcedil:"Ŗ",rcedil:"ŗ",rceil:"⌉",rcub:"}",Rcy:"Р",rcy:"р",rdca:"⤷",rdldhar:"⥩",rdquo:"”",rdquor:"”",rdsh:"↳",Re:"ℜ",real:"ℜ",realine:"ℛ",realpart:"ℜ",reals:"ℝ",rect:"▭",REG:"®",reg:"®",ReverseElement:"∋",ReverseEquilibrium:"⇋",ReverseUpEquilibrium:"⥯",rfisht:"⥽",rfloor:"⌋",Rfr:"ℜ",rfr:"𝔯",rHar:"⥤",rhard:"⇁",rharu:"⇀",rharul:"⥬",Rho:"Ρ",rho:"ρ",rhov:"ϱ",RightAngleBracket:"⟩",RightArrow:"→",Rightarrow:"⇒",rightarrow:"→",RightArrowBar:"⇥",RightArrowLeftArrow:"⇄",rightarrowtail:"↣",RightCeiling:"⌉",RightDoubleBracket:"⟧",RightDownTeeVector:"⥝",RightDownVector:"⇂",RightDownVectorBar:"⥕",RightFloor:"⌋",rightharpoondown:"⇁",rightharpoonup:"⇀",rightleftarrows:"⇄",rightleftharpoons:"⇌",rightrightarrows:"⇉",rightsquigarrow:"↝",RightTee:"⊢",RightTeeArrow:"↦",RightTeeVector:"⥛",rightthreetimes:"⋌",RightTriangle:"⊳",RightTriangleBar:"⧐",RightTriangleEqual:"⊵",RightUpDownVector:"⥏",RightUpTeeVector:"⥜",RightUpVector:"↾",RightUpVectorBar:"⥔",RightVector:"⇀",RightVectorBar:"⥓",ring:"˚",risingdotseq:"≓",rlarr:"⇄",rlhar:"⇌",rlm:"",rmoust:"⎱",rmoustache:"⎱",rnmid:"⫮",roang:"⟭",roarr:"⇾",robrk:"⟧",ropar:"⦆",Ropf:"ℝ",ropf:"𝕣",roplus:"⨮",rotimes:"⨵",RoundImplies:"⥰",rpar:")",rpargt:"⦔",rppolint:"⨒",rrarr:"⇉",Rrightarrow:"⇛",rsaquo:"›",Rscr:"ℛ",rscr:"𝓇",Rsh:"↱",rsh:"↱",rsqb:"]",rsquo:"’",rsquor:"’",rthree:"⋌",rtimes:"⋊",rtri:"▹",rtrie:"⊵",rtrif:"▸",rtriltri:"⧎",RuleDelayed:"⧴",ruluhar:"⥨",rx:"℞",Sacute:"Ś",sacute:"ś",sbquo:"‚",Sc:"⪼",sc:"≻",scap:"⪸",Scaron:"Š",scaron:"š",sccue:"≽",scE:"⪴",sce:"⪰",Scedil:"Ş",scedil:"ş",Scirc:"Ŝ",scirc:"ŝ",scnap:"⪺",scnE:"⪶",scnsim:"⋩",scpolint:"⨓",scsim:"≿",Scy:"С",scy:"с",sdot:"⋅",sdotb:"⊡",sdote:"⩦",searhk:"⤥",seArr:"⇘",searr:"↘",searrow:"↘",sect:"§",semi:";",seswar:"⤩",setminus:"∖",setmn:"∖",sext:"✶",Sfr:"𝔖",sfr:"𝔰",sfrown:"⌢",sharp:"♯",SHCHcy:"Щ",shchcy:"щ",SHcy:"Ш",shcy:"ш",ShortDownArrow:"↓",ShortLeftArrow:"←",shortmid:"∣",shortparallel:"∥",ShortRightArrow:"→",ShortUpArrow:"↑",shy:"",Sigma:"Σ",sigma:"σ",sigmaf:"ς",sigmav:"ς",sim:"∼",simdot:"⩪",sime:"≃",simeq:"≃",simg:"⪞",simgE:"⪠",siml:"⪝",simlE:"⪟",simne:"≆",simplus:"⨤",simrarr:"⥲",slarr:"←",SmallCircle:"∘",smallsetminus:"∖",smashp:"⨳",smeparsl:"⧤",smid:"∣",smile:"⌣",smt:"⪪",smte:"⪬",smtes:"⪬︀",SOFTcy:"Ь",softcy:"ь",sol:"/",solb:"⧄",solbar:"⌿",Sopf:"𝕊",sopf:"𝕤",spades:"♠",spadesuit:"♠",spar:"∥",sqcap:"⊓",sqcaps:"⊓︀",sqcup:"⊔",sqcups:"⊔︀",Sqrt:"√",sqsub:"⊏",sqsube:"⊑",sqsubset:"⊏",sqsubseteq:"⊑",sqsup:"⊐",sqsupe:"⊒",sqsupset:"⊐",sqsupseteq:"⊒",squ:"□",Square:"□",square:"□",SquareIntersection:"⊓",SquareSubset:"⊏",SquareSubsetEqual:"⊑",SquareSuperset:"⊐",SquareSupersetEqual:"⊒",SquareUnion:"⊔",squarf:"▪",squf:"▪",srarr:"→",Sscr:"𝒮",sscr:"𝓈",ssetmn:"∖",ssmile:"⌣",sstarf:"⋆",Star:"⋆",star:"☆",starf:"★",straightepsilon:"ϵ",straightphi:"ϕ",strns:"¯",Sub:"⋐",sub:"⊂",subdot:"⪽",subE:"⫅",sube:"⊆",subedot:"⫃",submult:"⫁",subnE:"⫋",subne:"⊊",subplus:"⪿",subrarr:"⥹",Subset:"⋐",subset:"⊂",subseteq:"⊆",subseteqq:"⫅",SubsetEqual:"⊆",subsetneq:"⊊",subsetneqq:"⫋",subsim:"⫇",subsub:"⫕",subsup:"⫓",succ:"≻",succapprox:"⪸",succcurlyeq:"≽",Succeeds:"≻",SucceedsEqual:"⪰",SucceedsSlantEqual:"≽",SucceedsTilde:"≿",succeq:"⪰",succnapprox:"⪺",succneqq:"⪶",succnsim:"⋩",succsim:"≿",SuchThat:"∋",Sum:"∑",sum:"∑",sung:"♪",Sup:"⋑",sup:"⊃",sup1:"¹",sup2:"²",sup3:"³",supdot:"⪾",supdsub:"⫘",supE:"⫆",supe:"⊇",supedot:"⫄",Superset:"⊃",SupersetEqual:"⊇",suphsol:"⟉",suphsub:"⫗",suplarr:"⥻",supmult:"⫂",supnE:"⫌",supne:"⊋",supplus:"⫀",Supset:"⋑",supset:"⊃",supseteq:"⊇",supseteqq:"⫆",supsetneq:"⊋",supsetneqq:"⫌",supsim:"⫈",supsub:"⫔",supsup:"⫖",swarhk:"⤦",swArr:"⇙",swarr:"↙",swarrow:"↙",swnwar:"⤪",szlig:"ß",Tab:" ",target:"⌖",Tau:"Τ",tau:"τ",tbrk:"⎴",Tcaron:"Ť",tcaron:"ť",Tcedil:"Ţ",tcedil:"ţ",Tcy:"Т",tcy:"т",tdot:"⃛",telrec:"⌕",Tfr:"𝔗",tfr:"𝔱",there4:"∴",Therefore:"∴",therefore:"∴",Theta:"Θ",theta:"θ",thetasym:"ϑ",thetav:"ϑ",thickapprox:"≈",thicksim:"∼",ThickSpace:" ",thinsp:" ",ThinSpace:" ",thkap:"≈",thksim:"∼",THORN:"Þ",thorn:"þ",Tilde:"∼",tilde:"˜",TildeEqual:"≃",TildeFullEqual:"≅",TildeTilde:"≈",times:"×",timesb:"⊠",timesbar:"⨱",timesd:"⨰",tint:"∭",toea:"⤨",top:"⊤",topbot:"⌶",topcir:"⫱",Topf:"𝕋",topf:"𝕥",topfork:"⫚",tosa:"⤩",tprime:"‴",TRADE:"™",trade:"™",triangle:"▵",triangledown:"▿",triangleleft:"◃",trianglelefteq:"⊴",triangleq:"≜",triangleright:"▹",trianglerighteq:"⊵",tridot:"◬",trie:"≜",triminus:"⨺",TripleDot:"⃛",triplus:"⨹",trisb:"⧍",tritime:"⨻",trpezium:"⏢",Tscr:"𝒯",tscr:"𝓉",TScy:"Ц",tscy:"ц",TSHcy:"Ћ",tshcy:"ћ",Tstrok:"Ŧ",tstrok:"ŧ",twixt:"≬",twoheadleftarrow:"↞",twoheadrightarrow:"↠",Uacute:"Ú",uacute:"ú",Uarr:"↟",uArr:"⇑",uarr:"↑",Uarrocir:"⥉",Ubrcy:"Ў",ubrcy:"ў",Ubreve:"Ŭ",ubreve:"ŭ",Ucirc:"Û",ucirc:"û",Ucy:"У",ucy:"у",udarr:"⇅",Udblac:"Ű",udblac:"ű",udhar:"⥮",ufisht:"⥾",Ufr:"𝔘",ufr:"𝔲",Ugrave:"Ù",ugrave:"ù",uHar:"⥣",uharl:"↿",uharr:"↾",uhblk:"▀",ulcorn:"⌜",ulcorner:"⌜",ulcrop:"⌏",ultri:"◸",Umacr:"Ū",umacr:"ū",uml:"¨",UnderBar:"_",UnderBrace:"⏟",UnderBracket:"⎵",UnderParenthesis:"⏝",Union:"⋃",UnionPlus:"⊎",Uogon:"Ų",uogon:"ų",Uopf:"𝕌",uopf:"𝕦",UpArrow:"↑",Uparrow:"⇑",uparrow:"↑",UpArrowBar:"⤒",UpArrowDownArrow:"⇅",UpDownArrow:"↕",Updownarrow:"⇕",updownarrow:"↕",UpEquilibrium:"⥮",upharpoonleft:"↿",upharpoonright:"↾",uplus:"⊎",UpperLeftArrow:"↖",UpperRightArrow:"↗",Upsi:"ϒ",upsi:"υ",upsih:"ϒ",Upsilon:"Υ",upsilon:"υ",UpTee:"⊥",UpTeeArrow:"↥",upuparrows:"⇈",urcorn:"⌝",urcorner:"⌝",urcrop:"⌎",Uring:"Ů",uring:"ů",urtri:"◹",Uscr:"𝒰",uscr:"𝓊",utdot:"⋰",Utilde:"Ũ",utilde:"ũ",utri:"▵",utrif:"▴",uuarr:"⇈",Uuml:"Ü",uuml:"ü",uwangle:"⦧",vangrt:"⦜",varepsilon:"ϵ",varkappa:"ϰ",varnothing:"∅",varphi:"ϕ",varpi:"ϖ",varpropto:"∝",vArr:"⇕",varr:"↕",varrho:"ϱ",varsigma:"ς",varsubsetneq:"⊊︀",varsubsetneqq:"⫋︀",varsupsetneq:"⊋︀",varsupsetneqq:"⫌︀",vartheta:"ϑ",vartriangleleft:"⊲",vartriangleright:"⊳",Vbar:"⫫",vBar:"⫨",vBarv:"⫩",Vcy:"В",vcy:"в",VDash:"⊫",Vdash:"⊩",vDash:"⊨",vdash:"⊢",Vdashl:"⫦",Vee:"⋁",vee:"∨",veebar:"⊻",veeeq:"≚",vellip:"⋮",Verbar:"‖",verbar:"|",Vert:"‖",vert:"|",VerticalBar:"∣",VerticalLine:"|",VerticalSeparator:"❘",VerticalTilde:"≀",VeryThinSpace:" ",Vfr:"𝔙",vfr:"𝔳",vltri:"⊲",vnsub:"⊂⃒",vnsup:"⊃⃒",Vopf:"𝕍",vopf:"𝕧",vprop:"∝",vrtri:"⊳",Vscr:"𝒱",vscr:"𝓋",vsubnE:"⫋︀",vsubne:"⊊︀",vsupnE:"⫌︀",vsupne:"⊋︀",Vvdash:"⊪",vzigzag:"⦚",Wcirc:"Ŵ",wcirc:"ŵ",wedbar:"⩟",Wedge:"⋀",wedge:"∧",wedgeq:"≙",weierp:"℘",Wfr:"𝔚",wfr:"𝔴",Wopf:"𝕎",wopf:"𝕨",wp:"℘",wr:"≀",wreath:"≀",Wscr:"𝒲",wscr:"𝓌",xcap:"⋂",xcirc:"◯",xcup:"⋃",xdtri:"▽",Xfr:"𝔛",xfr:"𝔵",xhArr:"⟺",xharr:"⟷",Xi:"Ξ",xi:"ξ",xlArr:"⟸",xlarr:"⟵",xmap:"⟼",xnis:"⋻",xodot:"⨀",Xopf:"𝕏",xopf:"𝕩",xoplus:"⨁",xotime:"⨂",xrArr:"⟹",xrarr:"⟶",Xscr:"𝒳",xscr:"𝓍",xsqcup:"⨆",xuplus:"⨄",xutri:"△",xvee:"⋁",xwedge:"⋀",Yacute:"Ý",yacute:"ý",YAcy:"Я",yacy:"я",Ycirc:"Ŷ",ycirc:"ŷ",Ycy:"Ы",ycy:"ы",yen:"¥",Yfr:"𝔜",yfr:"𝔶",YIcy:"Ї",yicy:"ї",Yopf:"𝕐",yopf:"𝕪",Yscr:"𝒴",yscr:"𝓎",YUcy:"Ю",yucy:"ю",Yuml:"Ÿ",yuml:"ÿ",Zacute:"Ź",zacute:"ź",Zcaron:"Ž",zcaron:"ž",Zcy:"З",zcy:"з",Zdot:"Ż",zdot:"ż",zeetrf:"ℨ",ZeroWidthSpace:"",Zeta:"Ζ",zeta:"ζ",Zfr:"ℨ",zfr:"𝔷",ZHcy:"Ж",zhcy:"ж",zigrarr:"⇝",Zopf:"ℤ",zopf:"𝕫",Zscr:"𝒵",zscr:"𝓏",zwj:"",zwnj:""}),t.entityMap=t.HTML_ENTITIES})(Ew);var ih={},os=ar.NAMESPACE,mp=/[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,xm=new RegExp("[\\-\\.0-9"+mp.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]"),Am=new RegExp("^"+mp.source+xm.source+"*(?::"+mp.source+xm.source+"*)?$"),bo=0,dr=1,yi=2,$o=3,wi=4,vi=5,xo=6,Js=7;function Yi(t,e){this.message=t,this.locator=e,Error.captureStackTrace&&Error.captureStackTrace(this,Yi)}Yi.prototype=new Error;Yi.prototype.name=Yi.name;function Sw(){}Sw.prototype={parse:function(t,e,n){var r=this.domBuilder;r.startDocument(),kw(e,e={}),bS(t,e,n,r,this.errorHandler),r.endDocument()}};function bS(t,e,n,r,i){function s(B){if(B>65535){B-=65536;var K=55296+(B>>10),de=56320+(B&1023);return String.fromCharCode(K,de)}else return String.fromCharCode(B)}function a(B){var K=B.slice(1,-1);return Object.hasOwnProperty.call(n,K)?n[K]:K.charAt(0)==="#"?s(parseInt(K.substr(1).replace("x","0x"))):(i.error("entity not found:"+B),B)}function l(B){if(B>z){var K=t.substring(z,B).replace(/&#?\w+;/g,a);g&&u(z),r.characters(K,0,B-z),z=B}}function u(B,K){for(;B>=p&&(K=h.exec(t));)d=K.index,p=d+K[0].length,g.lineNumber++;g.columnNumber=B-d+1}for(var d=0,p=0,h=/.*(?:\r\n?|\n)|.*$/g,g=r.locator,$=[{currentNSMap:e}],A={},z=0;;){try{var T=t.indexOf("<",z);if(T<0){if(!t.substr(z).match(/^\s*$/)){var O=r.doc,x=O.createTextNode(t.substr(z));O.appendChild(x),r.currentElement=x}return}switch(T>z&&l(T),t.charAt(T+1)){case"/":var R=t.indexOf(">",T+3),U=t.substring(T+2,R).replace(/[ \t\n\r]+$/g,""),q=$.pop();R<0?(U=t.substring(T+2).replace(/[\s<].*/,""),i.error("end tag name: "+U+" is not complete:"+q.tagName),R=T+1+U.length):U.match(/\s</)&&(U=U.replace(/[\s<].*/,""),i.error("end tag name: "+U+" maybe not complete"),R=T+1+U.length);var F=q.localNSMap,H=q.tagName==U,G=H||q.tagName&&q.tagName.toLowerCase()==U.toLowerCase();if(G){if(r.endElement(q.uri,q.localName,U),F)for(var Y in F)Object.prototype.hasOwnProperty.call(F,Y)&&r.endPrefixMapping(Y);H||i.fatalError("end tag name: "+U+" is not match the current start tagName:"+q.tagName)}else $.push(q);R++;break;case"?":g&&u(T),R=SS(t,T,r);break;case"!":g&&u(T),R=ES(t,T,r,i);break;default:g&&u(T);var J=new Nw,Ae=$[$.length-1].currentNSMap,R=$S(t,T,J,Ae,a,i),L=J.length;if(!J.closed&&AS(t,R,J.tagName,A)&&(J.closed=!0,n.nbsp||i.warning("unclosed xml attribute")),g&&L){for(var j=Em(g,{}),N=0;N<L;N++){var k=J[N];u(k.offset),k.locator=Em(g,{})}r.locator=j,Sm(J,r,Ae)&&$.push(J),r.locator=g}else Sm(J,r,Ae)&&$.push(J);os.isHTML(J.uri)&&!J.closed?R=xS(t,R,J.tagName,a,r):R++}}catch(B){if(B instanceof Yi)throw B;i.error("element parse error: "+B),R=-1}R>z?z=R:l(Math.max(T,z)+1)}}function Em(t,e){return e.lineNumber=t.lineNumber,e.columnNumber=t.columnNumber,e}function $S(t,e,n,r,i,s){function a(g,$,A){n.attributeNames.hasOwnProperty(g)&&s.fatalError("Attribute "+g+" redefined"),n.addValue(g,$.replace(/[\t\n\r]/g," ").replace(/&#?\w+;/g,i),A)}for(var l,u,d=++e,p=bo;;){var h=t.charAt(d);switch(h){case"=":if(p===dr)l=t.slice(e,d),p=$o;else if(p===yi)p=$o;else throw new Error("attribute equal must after attrName");break;case"'":case'"':if(p===$o||p===dr)if(p===dr&&(s.warning('attribute value must after "="'),l=t.slice(e,d)),e=d+1,d=t.indexOf(h,e),d>0)u=t.slice(e,d),a(l,u,e-1),p=vi;else throw new Error("attribute value no end '"+h+"' match");else if(p==wi)u=t.slice(e,d),a(l,u,e),s.warning('attribute "'+l+'" missed start quot('+h+")!!"),e=d+1,p=vi;else throw new Error('attribute value must after "="');break;case"/":switch(p){case bo:n.setTagName(t.slice(e,d));case vi:case xo:case Js:p=Js,n.closed=!0;case wi:case dr:break;case yi:n.closed=!0;break;default:throw new Error("attribute invalid close char('/')")}break;case"":return s.error("unexpected end of input"),p==bo&&n.setTagName(t.slice(e,d)),d;case">":switch(p){case bo:n.setTagName(t.slice(e,d));case vi:case xo:case Js:break;case wi:case dr:u=t.slice(e,d),u.slice(-1)==="/"&&(n.closed=!0,u=u.slice(0,-1));case yi:p===yi&&(u=l),p==wi?(s.warning('attribute "'+u+'" missed quot(")!'),a(l,u,e)):((!os.isHTML(r[""])||!u.match(/^(?:disabled|checked|selected)$/i))&&s.warning('attribute "'+u+'" missed value!! "'+u+'" instead!!'),a(u,u,e));break;case $o:throw new Error("attribute value missed!!")}return d;case"":h=" ";default:if(h<=" ")switch(p){case bo:n.setTagName(t.slice(e,d)),p=xo;break;case dr:l=t.slice(e,d),p=yi;break;case wi:var u=t.slice(e,d);s.warning('attribute "'+u+'" missed quot(")!!'),a(l,u,e);case vi:p=xo;break}else switch(p){case yi:n.tagName,(!os.isHTML(r[""])||!l.match(/^(?:disabled|checked|selected)$/i))&&s.warning('attribute "'+l+'" missed value!! "'+l+'" instead2!!'),a(l,l,e),e=d,p=dr;break;case vi:s.warning('attribute space is required"'+l+'"!!');case xo:p=dr,e=d;break;case $o:p=wi,e=d;break;case Js:throw new Error("elements closed character '/' and '>' must be connected to")}}d++}}function Sm(t,e,n){for(var r=t.tagName,i=null,h=t.length;h--;){var s=t[h],a=s.qName,l=s.value,g=a.indexOf(":");if(g>0)var u=s.prefix=a.slice(0,g),d=a.slice(g+1),p=u==="xmlns"&&d;else d=a,u=null,p=a==="xmlns"&&"";s.localName=d,p!==!1&&(i==null&&(i={},kw(n,n={})),n[p]=i[p]=l,s.uri=os.XMLNS,e.startPrefixMapping(p,l))}for(var h=t.length;h--;){s=t[h];var u=s.prefix;u&&(u==="xml"&&(s.uri=os.XML),u!=="xmlns"&&(s.uri=n[u||""]))}var g=r.indexOf(":");g>0?(u=t.prefix=r.slice(0,g),d=t.localName=r.slice(g+1)):(u=null,d=t.localName=r);var $=t.uri=n[u||""];if(e.startElement($,d,r,t),t.closed){if(e.endElement($,d,r),i)for(u in i)Object.prototype.hasOwnProperty.call(i,u)&&e.endPrefixMapping(u)}else return t.currentNSMap=n,t.localNSMap=i,!0}function xS(t,e,n,r,i){if(/^(?:script|textarea)$/i.test(n)){var s=t.indexOf("</"+n+">",e),a=t.substring(e+1,s);if(/[&<]/.test(a))return/^script$/i.test(n)?(i.characters(a,0,a.length),s):(a=a.replace(/&#?\w+;/g,r),i.characters(a,0,a.length),s)}return e+1}function AS(t,e,n,r){var i=r[n];return i==null&&(i=t.lastIndexOf("</"+n+">"),i<e&&(i=t.lastIndexOf("</"+n)),r[n]=i),i<e}function kw(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}function ES(t,e,n,r){var i=t.charAt(e+2);switch(i){case"-":if(t.charAt(e+3)==="-"){var s=t.indexOf("-->",e+4);return s>e?(n.comment(t,e+4,s-e-4),s+3):(r.error("Unclosed comment"),-1)}else return-1;default:if(t.substr(e+3,6)=="CDATA["){var s=t.indexOf("]]>",e+9);return n.startCDATA(),n.characters(t,e+9,s-e-9),n.endCDATA(),s+3}var a=kS(t,e),l=a.length;if(l>1&&/!doctype/i.test(a[0][0])){var u=a[1][0],d=!1,p=!1;l>3&&(/^public$/i.test(a[2][0])?(d=a[3][0],p=l>4&&a[4][0]):/^system$/i.test(a[2][0])&&(p=a[3][0]));var h=a[l-1];return n.startDTD(u,d,p),n.endDTD(),h.index+h[0].length}}return-1}function SS(t,e,n){var r=t.indexOf("?>",e);if(r){var i=t.substring(e,r).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);return i?(i[0].length,n.processingInstruction(i[1],i[2]),r+2):-1}return-1}function Nw(){this.attributeNames={}}Nw.prototype={setTagName:function(t){if(!Am.test(t))throw new Error("invalid tagName:"+t);this.tagName=t},addValue:function(t,e,n){if(!Am.test(t))throw new Error("invalid attribute:"+t);this.attributeNames[t]=this.length,this[this.length++]={qName:t,value:e,offset:n}},length:0,getLocalName:function(t){return this[t].localName},getLocator:function(t){return this[t].locator},getQName:function(t){return this[t].qName},getURI:function(t){return this[t].uri},getValue:function(t){return this[t].value}};function kS(t,e){var n,r=[],i=/'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;for(i.lastIndex=e,i.exec(t);n=i.exec(t);)if(r.push(n),n[1])return r}ih.XMLReader=Sw;ih.ParseError=Yi;var NS=ar,CS=sr,km=Ew,Cw=ih,zS=CS.DOMImplementation,Nm=NS.NAMESPACE,IS=Cw.ParseError,TS=Cw.XMLReader;function zw(t){return t.replace(/\r[\n\u0085]/g,`
|
|
296
296
|
`).replace(/[\r\u0085\u2028]/g,`
|
|
297
297
|
`)}function Iw(t){this.options=t||{locator:{}}}Iw.prototype.parseFromString=function(t,e){var n=this.options,r=new TS,i=n.domBuilder||new Ps,s=n.errorHandler,a=n.locator,l=n.xmlns||{},u=/\/x?html?$/.test(e),d=u?km.HTML_ENTITIES:km.XML_ENTITIES;a&&i.setDocumentLocator(a),r.errorHandler=OS(s,i,a),r.domBuilder=n.domBuilder||i,u&&(l[""]=Nm.HTML),l.xml=l.xml||Nm.XML;var p=n.normalizeLineEndings||zw;return t&&typeof t=="string"?r.parse(p(t),l,d):r.errorHandler.error("invalid doc source"),i.doc};function OS(t,e,n){if(!t){if(e instanceof Ps)return e;t=e}var r={},i=t instanceof Function;n=n||{};function s(a){var l=t[a];!l&&i&&(l=t.length==2?function(u){t(a,u)}:t),r[a]=l&&function(u){l("[xmldom "+a+"] "+u+_p(n))}||function(){}}return s("warning"),s("error"),s("fatalError"),r}function Ps(){this.cdata=!1}function bi(t,e){e.lineNumber=t.lineNumber,e.columnNumber=t.columnNumber}Ps.prototype={startDocument:function(){this.doc=new zS().createDocument(null,null,null),this.locator&&(this.doc.documentURI=this.locator.systemId)},startElement:function(t,e,n,r){var i=this.doc,s=i.createElementNS(t,n||e),a=r.length;Ys(this,s),this.currentElement=s,this.locator&&bi(this.locator,s);for(var l=0;l<a;l++){var t=r.getURI(l),u=r.getValue(l),n=r.getQName(l),d=i.createAttributeNS(t,n);this.locator&&bi(r.getLocator(l),d),d.value=d.nodeValue=u,s.setAttributeNode(d)}},endElement:function(t,e,n){var r=this.currentElement;r.tagName,this.currentElement=r.parentNode},startPrefixMapping:function(t,e){},endPrefixMapping:function(t){},processingInstruction:function(t,e){var n=this.doc.createProcessingInstruction(t,e);this.locator&&bi(this.locator,n),Ys(this,n)},ignorableWhitespace:function(t,e,n){},characters:function(t,e,n){if(t=Cm.apply(this,arguments),t){if(this.cdata)var r=this.doc.createCDATASection(t);else var r=this.doc.createTextNode(t);this.currentElement?this.currentElement.appendChild(r):/^\s*$/.test(t)&&this.doc.appendChild(r),this.locator&&bi(this.locator,r)}},skippedEntity:function(t){},endDocument:function(){this.doc.normalize()},setDocumentLocator:function(t){(this.locator=t)&&(t.lineNumber=0)},comment:function(t,e,n){t=Cm.apply(this,arguments);var r=this.doc.createComment(t);this.locator&&bi(this.locator,r),Ys(this,r)},startCDATA:function(){this.cdata=!0},endCDATA:function(){this.cdata=!1},startDTD:function(t,e,n){var r=this.doc.implementation;if(r&&r.createDocumentType){var i=r.createDocumentType(t,e,n);this.locator&&bi(this.locator,i),Ys(this,i),this.doc.doctype=i}},warning:function(t){console.warn("[xmldom warning] "+t,_p(this.locator))},error:function(t){console.error("[xmldom error] "+t,_p(this.locator))},fatalError:function(t){throw new IS(t,this.locator)}};function _p(t){if(t)return`
|
|
298
|
-
@`+(t.systemId||"")+"#[line:"+t.lineNumber+",col:"+t.columnNumber+"]"}function Cm(t,e,n){return typeof t=="string"?t.substr(e,n):t.length>=e+n||e?new java.lang.String(t,e,n)+"":t}"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(t){Ps.prototype[t]=function(){return null}});function Ys(t,e){t.currentElement?t.currentElement.appendChild(e):t.doc.appendChild(e)}Hl.__DOMHandler=Ps;Hl.normalizeLineEndings=zw;Hl.DOMParser=Iw;var Tw=sr;Ml.DOMImplementation=Tw.DOMImplementation;Ml.XMLSerializer=Tw.XMLSerializer;Ml.DOMParser=Hl.DOMParser;var Kl={};Object.defineProperty(Kl,"__esModule",{value:!0});Kl.EnvelopedSignature=void 0;const Zs=Ll,Au=$e;class DS{constructor(){this.includeComments=!1,this.includeComments=!1}process(e,n){if(n.signatureNode==null){const s=Zs.select1("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",e);return Au.isNodeLike(s)&&s.parentNode&&s.parentNode.removeChild(s),e}const r=n.signatureNode,i=Zs.select1(".//*[local-name(.)='SignatureValue']/text()",r);if(Au.isTextNode(i)){const s=i.data,a=Zs.select(".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",e);for(const l of Array.isArray(a)?a:[]){const u=Zs.select1(".//*[local-name(.)='SignatureValue']/text()",l);if(Au.isTextNode(u)){const d=u.data;s===d&&l.parentNode&&l.parentNode.removeChild(l)}}}return e}getAlgorithmName(){return"http://www.w3.org/2000/09/xmldsig#enveloped-signature"}}Kl.EnvelopedSignature=DS;var vr={};Object.defineProperty(vr,"__esModule",{value:!0});vr.Sha512=vr.Sha256=vr.Sha1=void 0;const oh=Oc;class RS{constructor(){this.getHash=function(e){const n=oh.createHash("sha1");return n.update(e,"utf8"),n.digest("base64")},this.getAlgorithmName=function(){return"http://www.w3.org/2000/09/xmldsig#sha1"}}}vr.Sha1=RS;class jS{constructor(){this.getHash=function(e){const n=oh.createHash("sha256");return n.update(e,"utf8"),n.digest("base64")},this.getAlgorithmName=function(){return"http://www.w3.org/2001/04/xmlenc#sha256"}}}vr.Sha256=jS;class PS{constructor(){this.getHash=function(e){const n=oh.createHash("sha512");return n.update(e,"utf8"),n.digest("base64")},this.getAlgorithmName=function(){return"http://www.w3.org/2001/04/xmlenc#sha512"}}}vr.Sha512=PS;var Cn={},Bs={};Object.defineProperty(Bs,"__esModule",{value:!0});Bs.createOptionalCallbackFunction=void 0;function BS(t){return typeof t=="function"}function LS(t){return(...e)=>{const n=e[e.length-1];if(BS(n))try{const r=t(...e.slice(0,-1));n(null,r)}catch(r){n(r instanceof Error?r:new Error("Unknown error"))}else return t(...e)}}Bs.createOptionalCallbackFunction=LS;Object.defineProperty(Cn,"__esModule",{value:!0});Cn.HmacSha1=Cn.RsaSha512=Cn.RsaSha256=Cn.RsaSha1=void 0;const Er=Oc,Sr=Bs;class FS{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createSign("RSA-SHA1");return r.update(e),r.sign(n,"base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createVerify("RSA-SHA1");return i.update(e),i.verify(n,r,"base64")}),this.getAlgorithmName=()=>"http://www.w3.org/2000/09/xmldsig#rsa-sha1"}}Cn.RsaSha1=FS;class US{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createSign("RSA-SHA256");return r.update(e),r.sign(n,"base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createVerify("RSA-SHA256");return i.update(e),i.verify(n,r,"base64")}),this.getAlgorithmName=()=>"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"}}Cn.RsaSha256=US;class MS{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createSign("RSA-SHA512");return r.update(e),r.sign(n,"base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createVerify("RSA-SHA512");return i.update(e),i.verify(n,r,"base64")}),this.getAlgorithmName=()=>"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"}}Cn.RsaSha512=MS;class qS{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createHmac("SHA1",n);return r.update(e),r.digest("base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createHmac("SHA1",n);return i.update(e),i.digest("base64")===r}),this.getAlgorithmName=()=>"http://www.w3.org/2000/09/xmldsig#hmac-sha1"}}Cn.HmacSha1=qS;Object.defineProperty(Ul,"__esModule",{value:!0});Ul.SignedXml=void 0;const Bt=$e,Ir=Ml,VS=Oc,Gt=Ll,zm=ai,HS=Kl,Im=ci,Eu=vr,Qs=Cn,Te=Os;class qn{constructor(e={}){this.signatureAlgorithm=void 0,this.canonicalizationAlgorithm=void 0,this.inclusiveNamespacesPrefixList=[],this.namespaceResolver={lookupNamespaceURI:function(){throw new Error("Not implemented")}},this.implicitTransforms=[],this.keyInfoAttributes={},this.getKeyInfoContent=qn.getKeyInfoContent,this.getCertFromKeyInfo=qn.getCertFromKeyInfo,this.id=0,this.signedXml="",this.signatureXml="",this.signatureNode=null,this.signatureValue="",this.originalXmlWithIds="",this.keyInfo=null,this.references=[],this.signedReferences=[],this.CanonicalizationAlgorithms={"http://www.w3.org/TR/2001/REC-xml-c14n-20010315":zm.C14nCanonicalization,"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments":zm.C14nCanonicalizationWithComments,"http://www.w3.org/2001/10/xml-exc-c14n#":Im.ExclusiveCanonicalization,"http://www.w3.org/2001/10/xml-exc-c14n#WithComments":Im.ExclusiveCanonicalizationWithComments,"http://www.w3.org/2000/09/xmldsig#enveloped-signature":HS.EnvelopedSignature},this.HashAlgorithms={"http://www.w3.org/2000/09/xmldsig#sha1":Eu.Sha1,"http://www.w3.org/2001/04/xmlenc#sha256":Eu.Sha256,"http://www.w3.org/2001/04/xmlenc#sha512":Eu.Sha512},this.SignatureAlgorithms={"http://www.w3.org/2000/09/xmldsig#rsa-sha1":Qs.RsaSha1,"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256":Qs.RsaSha256,"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512":Qs.RsaSha512};const{idMode:n,idAttribute:r,privateKey:i,publicCert:s,signatureAlgorithm:a,canonicalizationAlgorithm:l,inclusiveNamespacesPrefixList:u,implicitTransforms:d,keyInfoAttributes:p,getKeyInfoContent:h,getCertFromKeyInfo:g}=e;this.idMode=n,this.idAttributes=["Id","ID","id"],r&&this.idAttributes.unshift(r),this.privateKey=i,this.publicCert=s,this.signatureAlgorithm=a??this.signatureAlgorithm,this.canonicalizationAlgorithm=l,typeof u=="string"?this.inclusiveNamespacesPrefixList=u.split(" "):Te.isArrayHasLength(u)&&(this.inclusiveNamespacesPrefixList=u),this.implicitTransforms=d??this.implicitTransforms,this.keyInfoAttributes=p??this.keyInfoAttributes,this.getKeyInfoContent=h??this.getKeyInfoContent,this.getCertFromKeyInfo=g??qn.noop,this.CanonicalizationAlgorithms,this.HashAlgorithms,this.SignatureAlgorithms}enableHMAC(){this.SignatureAlgorithms={"http://www.w3.org/2000/09/xmldsig#hmac-sha1":Qs.HmacSha1},this.getKeyInfoContent=qn.noop}static getKeyInfoContent({publicCert:e,prefix:n}){if(e==null)return null;n=n?`${n}:`:"";let r="";Buffer.isBuffer(e)&&(e=e.toString("latin1"));let i=[];return typeof e=="string"&&(i=e.match(Te.EXTRACT_X509_CERTS)||[]),i.length>0&&(r=i.map(s=>`<${n}X509Certificate>${Te.pemToDer(s).toString("base64")}</${n}X509Certificate>`).join("")),`<${n}X509Data>${r}</${n}X509Data>`}static getCertFromKeyInfo(e){if(e!=null){const n=Gt.select1(".//*[local-name(.)='X509Certificate']",e);if(Bt.isNodeLike(n))return Te.derToPem(n.textContent??"","CERTIFICATE")}return null}checkSignature(e,n){if(n!=null&&typeof n!="function")throw new Error("Last parameter must be a callback function");this.signedXml=e;const r=new Ir.DOMParser().parseFromString(e);this.references=[];const i=this.getCanonSignedInfoXml(r);if(!i){if(n){n(new Error("Canonical signed info cannot be empty"),!1);return}throw new Error("Canonical signed info cannot be empty")}const a=new Ir.DOMParser().parseFromString(i,"text/xml").documentElement;if(!a){if(n){n(new Error("Could not parse unverifiedSignedInfoCanon into a document"),!1);return}throw new Error("Could not parse unverifiedSignedInfoCanon into a document")}const l=Te.findChildren(a,"Reference");if(!Te.isArrayHasLength(l)){if(n){n(new Error("could not find any Reference elements"),!1);return}throw new Error("could not find any Reference elements")}for(const h of l)this.loadReference(h);if(!this.getReferences().every(h=>this.validateReference(h,r))){if(this.signedReferences=[],this.references.forEach(h=>{h.signedReference=void 0}),n){n(new Error("Could not validate all references"),!1);return}return!1}const u=this.findSignatureAlgorithm(this.signatureAlgorithm),d=this.getCertFromKeyInfo(this.keyInfo)||this.publicCert||this.privateKey;if(d==null)throw new Error("KeyInfo or publicCert or privateKey is required to validate signature");if(u.verifySignature(i,d,this.signatureValue)===!0)if(n)n(null,!0);else return!0;else if(this.signedReferences=[],this.references.forEach(h=>{h.signedReference=void 0}),n){n(new Error(`invalid signature: the signature value ${this.signatureValue} is incorrect`));return}else throw new Error(`invalid signature: the signature value ${this.signatureValue} is incorrect`)}getCanonSignedInfoXml(e){if(this.signatureNode==null)throw new Error("No signature found.");if(typeof this.canonicalizationAlgorithm!="string")throw new Error("Missing canonicalizationAlgorithm when trying to get signed info for XML");const n=Te.findChildren(this.signatureNode,"SignedInfo");if(n.length===0)throw new Error("could not find SignedInfo element in the message");if(n.length>1)throw new Error("could not get canonicalized signed info for a signature that contains multiple SignedInfo nodes");if((this.canonicalizationAlgorithm==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"||this.canonicalizationAlgorithm==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments")&&(!e||typeof e!="object"))throw new Error("When canonicalization method is non-exclusive, whole xml dom must be provided as an argument");const i={ancestorNamespaces:Te.findAncestorNs(e,"//*[local-name()='SignedInfo']")};return this.getCanonXml([this.canonicalizationAlgorithm],n[0],i)}getCanonReferenceXml(e,n,r){Array.isArray(n.transforms)&&(n.ancestorNamespaces=Te.findAncestorNs(e,n.xpath,this.namespaceResolver));const i={inclusiveNamespacesPrefixList:n.inclusiveNamespacesPrefixList,ancestorNamespaces:n.ancestorNamespaces};return this.getCanonXml(n.transforms,r,i)}calculateSignatureValue(e,n){const r=this.getCanonSignedInfoXml(e),i=this.findSignatureAlgorithm(this.signatureAlgorithm);if(this.privateKey==null)throw new Error("Private key is required to compute signature");typeof n=="function"?i.getSignature(r,this.privateKey,n):this.signatureValue=i.getSignature(r,this.privateKey)}findSignatureAlgorithm(e){if(e==null)throw new Error("signatureAlgorithm is required");const n=this.SignatureAlgorithms[e];if(n)return new n;throw new Error(`signature algorithm '${e}' is not supported`)}findCanonicalizationAlgorithm(e){if(e!=null){const n=this.CanonicalizationAlgorithms[e];if(n)return new n}throw new Error(`canonicalization algorithm '${e}' is not supported`)}findHashAlgorithm(e){const n=this.HashAlgorithms[e];if(n)return new n;throw new Error(`hash algorithm '${e}' is not supported`)}validateElementAgainstReferences(e,n){var i;let r;if(typeof e=="string"){const s=Gt.select1(e,n);Bt.assertIsElementNode(s),r=s}else r=e;for(const s of this.getReferences()){const a=((i=s.uri)==null?void 0:i[0])==="#"?s.uri.substring(1):s.uri;for(const p of this.idAttributes){const h=r.getAttribute(p);if(a===h){s.xpath=`//*[@*[local-name(.)='${p}']='${a}']`;break}}const l=this.getCanonReferenceXml(n,s,r),d=this.findHashAlgorithm(s.digestAlgorithm).getHash(l);if(Te.validateDigestValue(d,s.digestValue))return s}throw new Error("No references passed validation")}validateReference(e,n){var u;const r=((u=e.uri)==null?void 0:u[0])==="#"?e.uri.substring(1):e.uri;let i=null;if(r==="")i=Gt.select1("//*",n);else{if((r==null?void 0:r.indexOf("'"))!==-1)throw new Error("Cannot validate a uri with quotes inside it");{let d=0;for(const p of this.idAttributes){const h=`//*[@*[local-name(.)='${p}']='${r}']`,g=Gt.select(h,n);if(Te.isArrayHasLength(g)){if(d+=g.length,d>1)throw new Error("Cannot validate a document which contains multiple elements with the same value for the ID / Id / Id attributes, in order to prevent signature wrapping attack.");i=g[0],e.xpath=h}}}}if(e.getValidatedNode=(0,VS.deprecate)(d=>{if(d=d||e.xpath,typeof d!="string"||e.validationError!=null)return null;const p=Gt.select1(d,n);return Bt.isNodeLike(p)?p:null},"`ref.getValidatedNode()` is deprecated and insecure. Use `ref.signedReference` or `this.getSignedReferences()` instead."),!Bt.isNodeLike(i)){const d=new Error(`invalid signature: the signature references an element with uri ${e.uri} but could not find such element in the xml`);return e.validationError=d,!1}const s=this.getCanonReferenceXml(n,e,i),l=this.findHashAlgorithm(e.digestAlgorithm).getHash(s);if(!Te.validateDigestValue(l,e.digestValue)){const d=new Error(`invalid signature: for uri ${e.uri} calculated digest is ${l} but the xml to validate supplies digest ${e.digestValue}`);return e.validationError=d,!1}return this.signedReferences.push(s),e.signedReference=s,!0}findSignatures(e){const n=Gt.select("//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",e);return Bt.isArrayOfNodes(n)?n:[]}loadSignature(e){typeof e=="string"?this.signatureNode=e=new Ir.DOMParser().parseFromString(e):this.signatureNode=e,this.signatureXml=e.toString();const n=Gt.select1(".//*[local-name(.)='CanonicalizationMethod']/@Algorithm",e);if(!Bt.isNodeLike(n))throw new Error("could not find CanonicalizationMethod/@Algorithm element");Bt.isAttributeNode(n)&&(this.canonicalizationAlgorithm=n.value);const r=Gt.select1(".//*[local-name(.)='SignatureMethod']/@Algorithm",e);Bt.isAttributeNode(r)&&(this.signatureAlgorithm=r.value);const i=Te.findChildren(this.signatureNode,"SignedInfo");if(!Te.isArrayHasLength(i))throw new Error("no signed info node found");if(i.length>1)throw new Error("could not load signature that contains multiple SignedInfo nodes");let s=this.canonicalizationAlgorithm;(!s||s==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"||s==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments")&&(s="http://www.w3.org/2001/10/xml-exc-c14n#");const a=this.getCanonXml([s],i[0]),u=new Ir.DOMParser().parseFromString(a,"text/xml").documentElement;this.references=[];const d=Te.findChildren(u,"Reference");if(!Te.isArrayHasLength(d))throw new Error("could not find any Reference elements");for(const g of d)this.loadReference(g);const p=Gt.select1(".//*[local-name(.)='SignatureValue']/text()",e);Bt.isTextNode(p)&&(this.signatureValue=p.data.replace(/\r?\n/g,""));const h=Gt.select1(".//*[local-name(.)='KeyInfo']",e);Bt.isNodeLike(h)&&(this.keyInfo=h)}loadReference(e){let n=Te.findChildren(e,"DigestMethod");if(n.length===0)throw new Error(`could not find DigestMethod in reference ${e.toString()}`);const r=n[0],i=Te.findAttr(r,"Algorithm");if(!i)throw new Error(`could not find Algorithm attribute in node ${r.toString()}`);const s=i.value;if(n=Te.findChildren(e,"DigestValue"),n.length===0)throw new Error(`could not find DigestValue node in reference ${e.toString()}`);if(n.length>1)throw new Error(`could not load reference for a node that contains multiple DigestValue nodes: ${e.toString()}`);const a=n[0].textContent;if(!a)throw new Error(`could not find the value of DigestValue in ${e.toString()}`);const l=[];let u=[];if(n=Te.findChildren(e,"Transforms"),n.length!==0){const p=n[0],h=Te.findChildren(p,"Transform");for(const $ of h){const A=Te.findAttr($,"Algorithm");A&&l.push(A.value)}const g=Te.findChildren(h[h.length-1],"InclusiveNamespaces");Te.isArrayHasLength(g)&&(u=g.flatMap($=>($.getAttribute("PrefixList")??"").split(" ")).filter($=>$.length>0))}Te.isArrayHasLength(this.implicitTransforms)&&this.implicitTransforms.forEach(function(p){l.push(p)}),(l.length===0||l[l.length-1]==="http://www.w3.org/2000/09/xmldsig#enveloped-signature")&&l.push("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");const d=Bt.isElementNode(e)&&e.getAttribute("URI")||void 0;this.addReference({transforms:l,digestAlgorithm:s,uri:d,digestValue:a,inclusiveNamespacesPrefixList:u,isEmptyUri:!1})}addReference({xpath:e,transforms:n,digestAlgorithm:r,uri:i="",digestValue:s,inclusiveNamespacesPrefixList:a=[],isEmptyUri:l=!1}){if(r==null)throw new Error("digestAlgorithm is required");if(!Te.isArrayHasLength(n))throw new Error("transforms must contain at least one transform algorithm");this.references.push({xpath:e,transforms:n,digestAlgorithm:r,uri:i,digestValue:s,inclusiveNamespacesPrefixList:a,isEmptyUri:l,getValidatedNode:()=>{throw new Error("Reference has not been validated yet; Did you call `sig.checkSignature()`?")}})}getReferences(){return this.references}getSignedReferences(){return[...this.signedReferences]}computeSignature(e,n,r){let i;typeof n=="function"&&r==null?(i=n,n={}):(i=r,n=n??{});const s=new Ir.DOMParser().parseFromString(e);let a="xmlns";const l=[];let u;const d=["append","prepend","before","after"],p=n.prefix,h=n.attrs||{},g=n.location||{},$=n.existingPrefixes||{};if(this.namespaceResolver={lookupNamespaceURI:function(K){return K?$[K]:null}},g.reference=g.reference||"/*",g.action=g.action||"append",d.indexOf(g.action)===-1){const K=new Error(`location.action option has an invalid action: ${g.action}, must be any of the following values: ${d.join(", ")}`);if(i){i(K);return}else throw K}p?(a+=`:${p}`,u=`${p}:`):u="",Object.keys(h).forEach(function(K){K!=="xmlns"&&K!==a&&l.push(`${K}="${h[K]}"`)}),l.push(`${a}="http://www.w3.org/2000/09/xmldsig#"`);let A=`<${u}Signature ${l.join(" ")}>`;A+=this.createSignedInfo(s,p),A+=this.getKeyInfo(p),A+=`</${u}Signature>`,this.originalXmlWithIds=s.toString();let z="";Object.keys($).forEach(function(K){z+=`xmlns:${K}="${$[K]}" `});const T=`<Dummy ${z}>${A}</Dummy>`,x=new Ir.DOMParser().parseFromString(T).documentElement.firstChild,U=Gt.select1(g.reference,s);if(!Bt.isNodeLike(U)){const K=new Error(`the following xpath cannot be used because it was not found: ${g.reference}`);if(i){i(K);return}else throw K}if(g.action==="append")U.appendChild(x);else if(g.action==="prepend")U.insertBefore(x,U.firstChild);else if(g.action==="before"){if(U.parentNode==null)throw new Error("`location.reference` refers to the root node (by default), so we can't insert `before`");U.parentNode.insertBefore(x,U)}else if(g.action==="after"){if(U.parentNode==null)throw new Error("`location.reference` refers to the root node (by default), so we can't insert `after`");U.parentNode.insertBefore(x,U.nextSibling)}this.signatureNode=x;const q=Te.findChildren(this.signatureNode,"SignedInfo");if(q.length===0){const K=new Error("could not find SignedInfo element in the message");if(i){i(K);return}else throw K}const F=q[0];typeof i=="function"?this.calculateSignatureValue(s,(K,G)=>{K?i(K):(this.signatureValue=G||"",x.insertBefore(this.createSignature(p),F.nextSibling),this.signatureXml=x.toString(),this.signedXml=s.toString(),i(null,this))}):(this.calculateSignatureValue(s),x.insertBefore(this.createSignature(p),F.nextSibling),this.signatureXml=x.toString(),this.signedXml=s.toString())}getKeyInfo(e){const n=e?`${e}:`:"";let r="";this.keyInfoAttributes&&Object.keys(this.keyInfoAttributes).forEach(s=>{r+=` ${s}="${this.keyInfoAttributes[s]}"`});const i=this.getKeyInfoContent({publicCert:this.publicCert,prefix:e});return r||i?`<${n}KeyInfo${r}>${i}</${n}KeyInfo>`:""}createReferences(e,n){let r="";n=n||"",n=n&&`${n}:`;for(const i of this.getReferences()){const s=Gt.selectWithResolver(i.xpath??"",e,this.namespaceResolver);if(!Te.isArrayHasLength(s))throw new Error(`the following xpath cannot be signed because it was not found: ${i.xpath}`);for(const a of s){if(i.isEmptyUri)r+=`<${n}Reference URI="">`;else{const d=this.ensureHasId(a);i.uri=d,r+=`<${n}Reference URI="#${d}">`}r+=`<${n}Transforms>`;for(const d of i.transforms||[]){const p=this.findCanonicalizationAlgorithm(d);r+=`<${n}Transform Algorithm="${p.getAlgorithmName()}"`,Te.isArrayHasLength(i.inclusiveNamespacesPrefixList)?(r+=">",r+=`<InclusiveNamespaces PrefixList="${i.inclusiveNamespacesPrefixList.join(" ")}" xmlns="${p.getAlgorithmName()}"/>`,r+=`</${n}Transform>`):r+=" />"}const l=this.getCanonReferenceXml(e,i,a),u=this.findHashAlgorithm(i.digestAlgorithm);r+=`</${n}Transforms><${n}DigestMethod Algorithm="${u.getAlgorithmName()}" /><${n}DigestValue>${u.getHash(l)}</${n}DigestValue></${n}Reference>`}}return r}getCanonXml(e,n,r={}){r.defaultNsForPrefix=r.defaultNsForPrefix??qn.defaultNsForPrefix,r.signatureNode=this.signatureNode;let s=n.cloneNode(!0);return e.forEach(a=>{Bt.isNodeLike(s)&&(s=this.findCanonicalizationAlgorithm(a).process(s,r))}),s.toString()}ensureHasId(e){let n;if(this.idMode==="wssecurity"?n=Te.findAttr(e,"Id","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"):this.idAttributes.some(i=>(n=Te.findAttr(e,i),!!n)),n)return n.value;const r=`_${this.id++}`;return this.idMode==="wssecurity"?(e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"),e.setAttributeNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd","wsu:Id",r)):e.setAttribute("Id",r),r}createSignedInfo(e,n){if(typeof this.canonicalizationAlgorithm!="string")throw new Error("Missing canonicalizationAlgorithm when trying to create signed info for XML");const r=this.findCanonicalizationAlgorithm(this.canonicalizationAlgorithm),i=this.findSignatureAlgorithm(this.signatureAlgorithm);let s;s=n||"",s=s&&`${s}:`;let a=`<${s}SignedInfo>`;return a+=`<${s}CanonicalizationMethod Algorithm="${r.getAlgorithmName()}"`,Te.isArrayHasLength(this.inclusiveNamespacesPrefixList)?(a+=">",a+=`<InclusiveNamespaces PrefixList="${this.inclusiveNamespacesPrefixList.join(" ")}" xmlns="${r.getAlgorithmName()}"/>`,a+=`</${s}CanonicalizationMethod>`):a+=" />",a+=`<${s}SignatureMethod Algorithm="${i.getAlgorithmName()}" />`,a+=this.createReferences(e,n),a+=`</${s}SignedInfo>`,a}createSignature(e){let n="xmlns";e?(n+=`:${e}`,e+=":"):e="";const r=`<${e}SignatureValue>${this.signatureValue}</${e}SignatureValue>`,i=`<${e}Signature ${n}="http://www.w3.org/2000/09/xmldsig#">${r}</${e}Signature>`;return new Ir.DOMParser().parseFromString(i).documentElement.firstChild}getSignatureXml(){return this.signatureXml}getOriginalXmlWithIds(){return this.originalXmlWithIds}getSignedXml(){return this.signedXml}}Ul.SignedXml=qn;qn.defaultNsForPrefix={ds:"http://www.w3.org/2000/09/xmldsig#"};qn.noop=()=>null;(function(t){var e=Lr&&Lr.__createBinding||(Object.create?function(a,l,u,d){d===void 0&&(d=u);var p=Object.getOwnPropertyDescriptor(l,u);(!p||("get"in p?!l.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:function(){return l[u]}}),Object.defineProperty(a,d,p)}:function(a,l,u,d){d===void 0&&(d=u),a[d]=l[u]}),n=Lr&&Lr.__exportStar||function(a,l){for(var u in a)u!=="default"&&!Object.prototype.hasOwnProperty.call(l,u)&&e(l,a,u)};Object.defineProperty(t,"__esModule",{value:!0}),t.SignedXml=t.ExclusiveCanonicalizationWithComments=t.ExclusiveCanonicalization=t.C14nCanonicalizationWithComments=t.C14nCanonicalization=void 0;var r=ai;Object.defineProperty(t,"C14nCanonicalization",{enumerable:!0,get:function(){return r.C14nCanonicalization}}),Object.defineProperty(t,"C14nCanonicalizationWithComments",{enumerable:!0,get:function(){return r.C14nCanonicalizationWithComments}});var i=ci;Object.defineProperty(t,"ExclusiveCanonicalization",{enumerable:!0,get:function(){return i.ExclusiveCanonicalization}}),Object.defineProperty(t,"ExclusiveCanonicalizationWithComments",{enumerable:!0,get:function(){return i.ExclusiveCanonicalizationWithComments}});var s=Ul;Object.defineProperty(t,"SignedXml",{enumerable:!0,get:function(){return s.SignedXml}}),n(Bs,t),n(Os,t)})(B6);async function KS(t){const e=new DecompressionStream("deflate-raw"),n=new Blob([t]).stream().pipeThrough(e);return new Uint8Array(await new Response(n).arrayBuffer())}async function GS(t){const e=await j_.decode(t.replace(/ /g,"+"));try{const n=await KS(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 WS(t){const e=await GS(t),r=new Ip.XMLParser({attributeNamePrefix:"@_",alwaysCreateTextNode:!0,ignoreAttributes:!1}).parse(e);return R6.parse(r)}function XS(t){const e=t.certificates.map(i=>({":@":{"@_use":"signing"},KeyDescriptor:[{":@":{"@_xmlns":"http://www.w3.org/2000/09/xmldsig#"},KeyInfo:[{X509Data:[{X509Certificate:[{"#text":i}]}]}]}]})),n=[{":@":{"@_entityID":t.entityId,"@_xmlns":"urn:oasis:names:tc:SAML:2.0:metadata"},EntityDescriptor:[{":@":{"@_protocolSupportEnumeration":"urn:oasis:names:tc:SAML:2.0:protocol"},IDPSSODescriptor:[...e,{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.singleLogoutServiceUrl},SingleLogoutService:[]},{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.singleLogoutServiceUrl},SingleLogoutService:[]},{NameIDFormat:[{"#text":"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"}]},{NameIDFormat:[{"#text":"urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"}]},{NameIDFormat:[{"#text":"urn:oasis:names:tc:SAML:2.0:nameid-format:transient"}]},{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.assertionConsumerServiceUrl},SingleSignOnService:[]},{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.assertionConsumerServiceUrl},SingleSignOnService:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]}]}]}];return new Ip.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!0,format:!0}).build(n)}const JS=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 l,u;const{client_id:e}=t.req.valid("param"),n=await t.env.data.legacyClients.get(e);if(!n)throw new E(404,{message:"Client not found"});const{signingKeys:r}=await t.env.data.keys.list({q:"type:saml_encryption"});if(r.length===0)throw new E(500,{message:"No signing key found"});const i=r.map(d=>new Nl(d.cert).toString("base64")),s=t.env.ISSUER,a=XS({entityId:((u=(l=n.addons)==null?void 0:l.samlp)==null?void 0:u.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 E(404,{message:"Client not found"});t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id);const s=await WS(n),a=s["samlp:AuthnRequest"]["saml:Issuer"]["#text"],l=await t.env.data.loginSessions.create(t.var.tenant_id,{csrf_token:He(),authParams:{client_id:e,state:JSON.stringify({requestId:s["samlp:AuthnRequest"]["@_ID"],relayState:r}),response_mode:zn.SAML_POST,redirect_uri:s["samlp:AuthnRequest"]["@_AssertionConsumerServiceURL"],audience:a},expires_at:new Date(Date.now()+Hr*1e3).toISOString(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Yn(t.get("auth0_client"))});return t.redirect(`/u/login/identifier?state=${l.id}`)});function YS(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=as(r,t.dataAdapter),a=t.dataAdapter.cache||ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),l=t.dataAdapter.cache?300:0,u=Dl(s,{defaultTtl:l,cacheEntities:["tenants","connections","clients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=zl(r,u),i()}),e.use(Ol).use(Tl).use(Af(e));const n=e.route("/",JS);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"SAML API"},security:[{oauth2:["openid","email","profile"]}]}),xf(n),n}const ZS="Account detected",QS="Manage your account details",ek="Account",tk="We have detected that you have already created an account through",nk="By signing in, you agree to our",rk="and",ik="email address",ok="email or phone number",sk="phone number",ak="Callback URL mismatch",ck="The provided redirect_uri is not in the list of allowed callback URLs.",lk="Change email address",uk="continue with user",dk="Please click the button to create a new password account.",pk="Enter the code at {{vendorName}} to complete the login",fk="Welcome to {{vendorName}}! {{code}} is the login code",hk="Welcome to {{vendorName}}! {{code}} is the login code",gk="Code expired",mk="Invalid code",_k="Please check <0>{{username}}</0> and enter the six-digit code that we've sent you.",yk="The code is already used",wk="The code is valid for 30 minutes",vk="A configuration error occurred.",bk="Confirm password",$k="Are you sure you want to unlink this account?",xk="Need Help?",Ak="Contact us",Ek="or continue with social account",Sk="Continue with {{provider}}",kk="Would you like to continue with your existing account?",Nk="Copyright © 2023 SESAMY. All rights reserved.",Ck="©2023 Sesamy",zk="Choose a password with a mix of uppercase and lowercase letters, numbers, and symbols.",Ik="Please enter a valid email address.",Tk="The passwords didn't match. Try again.",Ok="Choose password",Dk="Password must be at least 8 characters long and contain at least one lowercase letter, one uppercase letter, one number and one symbol.",Rk="Create new account",jk="Sign up with password",Pk="Current email address",Bk="You are currently logged in as <0>{{email}}</0>",Lk="Edit",Fk="Email",Uk="Email is already taken",Mk="Email changed to <0>{{email}}</0> ",qk="Email or Phone Number",Vk="Email address",Hk="Your email address has been validated",Kk="Now enter your password to login again",Gk="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.",Wk="Email verification sent",Xk="Enter a code",Jk="We'll send you a verification link to ensure you own this email address.",Yk="Enter new email",Zk="Enter new password",Qk="Enter password",e9="Enter your email address and password to login.",t9="Enter your password",n9="Something went wrong",r9="The magic link has expired. Please click on the button below to receive a new link in your inbox.",i9="Hey! We updated our login experience. <0>Click here to learn more about it.</0>",o9="Send password reset email",s9="Click the button below and we’ll send instructions on how to reset your password.",a9="Password reset email sent",c9="Forgot password?",l9="Forgot password?",u9="Go back",d9="Hide password",p9="Invalid identifier",f9="Invalid password",h9=`The link is no longer valid.
|
|
298
|
+
@`+(t.systemId||"")+"#[line:"+t.lineNumber+",col:"+t.columnNumber+"]"}function Cm(t,e,n){return typeof t=="string"?t.substr(e,n):t.length>=e+n||e?new java.lang.String(t,e,n)+"":t}"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(t){Ps.prototype[t]=function(){return null}});function Ys(t,e){t.currentElement?t.currentElement.appendChild(e):t.doc.appendChild(e)}Hl.__DOMHandler=Ps;Hl.normalizeLineEndings=zw;Hl.DOMParser=Iw;var Tw=sr;Ml.DOMImplementation=Tw.DOMImplementation;Ml.XMLSerializer=Tw.XMLSerializer;Ml.DOMParser=Hl.DOMParser;var Kl={};Object.defineProperty(Kl,"__esModule",{value:!0});Kl.EnvelopedSignature=void 0;const Zs=Ll,Au=$e;class DS{constructor(){this.includeComments=!1,this.includeComments=!1}process(e,n){if(n.signatureNode==null){const s=Zs.select1("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",e);return Au.isNodeLike(s)&&s.parentNode&&s.parentNode.removeChild(s),e}const r=n.signatureNode,i=Zs.select1(".//*[local-name(.)='SignatureValue']/text()",r);if(Au.isTextNode(i)){const s=i.data,a=Zs.select(".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",e);for(const l of Array.isArray(a)?a:[]){const u=Zs.select1(".//*[local-name(.)='SignatureValue']/text()",l);if(Au.isTextNode(u)){const d=u.data;s===d&&l.parentNode&&l.parentNode.removeChild(l)}}}return e}getAlgorithmName(){return"http://www.w3.org/2000/09/xmldsig#enveloped-signature"}}Kl.EnvelopedSignature=DS;var vr={};Object.defineProperty(vr,"__esModule",{value:!0});vr.Sha512=vr.Sha256=vr.Sha1=void 0;const oh=Oc;class RS{constructor(){this.getHash=function(e){const n=oh.createHash("sha1");return n.update(e,"utf8"),n.digest("base64")},this.getAlgorithmName=function(){return"http://www.w3.org/2000/09/xmldsig#sha1"}}}vr.Sha1=RS;class jS{constructor(){this.getHash=function(e){const n=oh.createHash("sha256");return n.update(e,"utf8"),n.digest("base64")},this.getAlgorithmName=function(){return"http://www.w3.org/2001/04/xmlenc#sha256"}}}vr.Sha256=jS;class PS{constructor(){this.getHash=function(e){const n=oh.createHash("sha512");return n.update(e,"utf8"),n.digest("base64")},this.getAlgorithmName=function(){return"http://www.w3.org/2001/04/xmlenc#sha512"}}}vr.Sha512=PS;var Cn={},Bs={};Object.defineProperty(Bs,"__esModule",{value:!0});Bs.createOptionalCallbackFunction=void 0;function BS(t){return typeof t=="function"}function LS(t){return(...e)=>{const n=e[e.length-1];if(BS(n))try{const r=t(...e.slice(0,-1));n(null,r)}catch(r){n(r instanceof Error?r:new Error("Unknown error"))}else return t(...e)}}Bs.createOptionalCallbackFunction=LS;Object.defineProperty(Cn,"__esModule",{value:!0});Cn.HmacSha1=Cn.RsaSha512=Cn.RsaSha256=Cn.RsaSha1=void 0;const Er=Oc,Sr=Bs;class FS{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createSign("RSA-SHA1");return r.update(e),r.sign(n,"base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createVerify("RSA-SHA1");return i.update(e),i.verify(n,r,"base64")}),this.getAlgorithmName=()=>"http://www.w3.org/2000/09/xmldsig#rsa-sha1"}}Cn.RsaSha1=FS;class US{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createSign("RSA-SHA256");return r.update(e),r.sign(n,"base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createVerify("RSA-SHA256");return i.update(e),i.verify(n,r,"base64")}),this.getAlgorithmName=()=>"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"}}Cn.RsaSha256=US;class MS{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createSign("RSA-SHA512");return r.update(e),r.sign(n,"base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createVerify("RSA-SHA512");return i.update(e),i.verify(n,r,"base64")}),this.getAlgorithmName=()=>"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"}}Cn.RsaSha512=MS;class qS{constructor(){this.getSignature=(0,Sr.createOptionalCallbackFunction)((e,n)=>{const r=Er.createHmac("SHA1",n);return r.update(e),r.digest("base64")}),this.verifySignature=(0,Sr.createOptionalCallbackFunction)((e,n,r)=>{const i=Er.createHmac("SHA1",n);return i.update(e),i.digest("base64")===r}),this.getAlgorithmName=()=>"http://www.w3.org/2000/09/xmldsig#hmac-sha1"}}Cn.HmacSha1=qS;Object.defineProperty(Ul,"__esModule",{value:!0});Ul.SignedXml=void 0;const Bt=$e,Ir=Ml,VS=Oc,Gt=Ll,zm=ai,HS=Kl,Im=ci,Eu=vr,Qs=Cn,Te=Os;class qn{constructor(e={}){this.signatureAlgorithm=void 0,this.canonicalizationAlgorithm=void 0,this.inclusiveNamespacesPrefixList=[],this.namespaceResolver={lookupNamespaceURI:function(){throw new Error("Not implemented")}},this.implicitTransforms=[],this.keyInfoAttributes={},this.getKeyInfoContent=qn.getKeyInfoContent,this.getCertFromKeyInfo=qn.getCertFromKeyInfo,this.id=0,this.signedXml="",this.signatureXml="",this.signatureNode=null,this.signatureValue="",this.originalXmlWithIds="",this.keyInfo=null,this.references=[],this.signedReferences=[],this.CanonicalizationAlgorithms={"http://www.w3.org/TR/2001/REC-xml-c14n-20010315":zm.C14nCanonicalization,"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments":zm.C14nCanonicalizationWithComments,"http://www.w3.org/2001/10/xml-exc-c14n#":Im.ExclusiveCanonicalization,"http://www.w3.org/2001/10/xml-exc-c14n#WithComments":Im.ExclusiveCanonicalizationWithComments,"http://www.w3.org/2000/09/xmldsig#enveloped-signature":HS.EnvelopedSignature},this.HashAlgorithms={"http://www.w3.org/2000/09/xmldsig#sha1":Eu.Sha1,"http://www.w3.org/2001/04/xmlenc#sha256":Eu.Sha256,"http://www.w3.org/2001/04/xmlenc#sha512":Eu.Sha512},this.SignatureAlgorithms={"http://www.w3.org/2000/09/xmldsig#rsa-sha1":Qs.RsaSha1,"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256":Qs.RsaSha256,"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512":Qs.RsaSha512};const{idMode:n,idAttribute:r,privateKey:i,publicCert:s,signatureAlgorithm:a,canonicalizationAlgorithm:l,inclusiveNamespacesPrefixList:u,implicitTransforms:d,keyInfoAttributes:p,getKeyInfoContent:h,getCertFromKeyInfo:g}=e;this.idMode=n,this.idAttributes=["Id","ID","id"],r&&this.idAttributes.unshift(r),this.privateKey=i,this.publicCert=s,this.signatureAlgorithm=a??this.signatureAlgorithm,this.canonicalizationAlgorithm=l,typeof u=="string"?this.inclusiveNamespacesPrefixList=u.split(" "):Te.isArrayHasLength(u)&&(this.inclusiveNamespacesPrefixList=u),this.implicitTransforms=d??this.implicitTransforms,this.keyInfoAttributes=p??this.keyInfoAttributes,this.getKeyInfoContent=h??this.getKeyInfoContent,this.getCertFromKeyInfo=g??qn.noop,this.CanonicalizationAlgorithms,this.HashAlgorithms,this.SignatureAlgorithms}enableHMAC(){this.SignatureAlgorithms={"http://www.w3.org/2000/09/xmldsig#hmac-sha1":Qs.HmacSha1},this.getKeyInfoContent=qn.noop}static getKeyInfoContent({publicCert:e,prefix:n}){if(e==null)return null;n=n?`${n}:`:"";let r="";Buffer.isBuffer(e)&&(e=e.toString("latin1"));let i=[];return typeof e=="string"&&(i=e.match(Te.EXTRACT_X509_CERTS)||[]),i.length>0&&(r=i.map(s=>`<${n}X509Certificate>${Te.pemToDer(s).toString("base64")}</${n}X509Certificate>`).join("")),`<${n}X509Data>${r}</${n}X509Data>`}static getCertFromKeyInfo(e){if(e!=null){const n=Gt.select1(".//*[local-name(.)='X509Certificate']",e);if(Bt.isNodeLike(n))return Te.derToPem(n.textContent??"","CERTIFICATE")}return null}checkSignature(e,n){if(n!=null&&typeof n!="function")throw new Error("Last parameter must be a callback function");this.signedXml=e;const r=new Ir.DOMParser().parseFromString(e);this.references=[];const i=this.getCanonSignedInfoXml(r);if(!i){if(n){n(new Error("Canonical signed info cannot be empty"),!1);return}throw new Error("Canonical signed info cannot be empty")}const a=new Ir.DOMParser().parseFromString(i,"text/xml").documentElement;if(!a){if(n){n(new Error("Could not parse unverifiedSignedInfoCanon into a document"),!1);return}throw new Error("Could not parse unverifiedSignedInfoCanon into a document")}const l=Te.findChildren(a,"Reference");if(!Te.isArrayHasLength(l)){if(n){n(new Error("could not find any Reference elements"),!1);return}throw new Error("could not find any Reference elements")}for(const h of l)this.loadReference(h);if(!this.getReferences().every(h=>this.validateReference(h,r))){if(this.signedReferences=[],this.references.forEach(h=>{h.signedReference=void 0}),n){n(new Error("Could not validate all references"),!1);return}return!1}const u=this.findSignatureAlgorithm(this.signatureAlgorithm),d=this.getCertFromKeyInfo(this.keyInfo)||this.publicCert||this.privateKey;if(d==null)throw new Error("KeyInfo or publicCert or privateKey is required to validate signature");if(u.verifySignature(i,d,this.signatureValue)===!0)if(n)n(null,!0);else return!0;else if(this.signedReferences=[],this.references.forEach(h=>{h.signedReference=void 0}),n){n(new Error(`invalid signature: the signature value ${this.signatureValue} is incorrect`));return}else throw new Error(`invalid signature: the signature value ${this.signatureValue} is incorrect`)}getCanonSignedInfoXml(e){if(this.signatureNode==null)throw new Error("No signature found.");if(typeof this.canonicalizationAlgorithm!="string")throw new Error("Missing canonicalizationAlgorithm when trying to get signed info for XML");const n=Te.findChildren(this.signatureNode,"SignedInfo");if(n.length===0)throw new Error("could not find SignedInfo element in the message");if(n.length>1)throw new Error("could not get canonicalized signed info for a signature that contains multiple SignedInfo nodes");if((this.canonicalizationAlgorithm==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"||this.canonicalizationAlgorithm==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments")&&(!e||typeof e!="object"))throw new Error("When canonicalization method is non-exclusive, whole xml dom must be provided as an argument");const i={ancestorNamespaces:Te.findAncestorNs(e,"//*[local-name()='SignedInfo']")};return this.getCanonXml([this.canonicalizationAlgorithm],n[0],i)}getCanonReferenceXml(e,n,r){Array.isArray(n.transforms)&&(n.ancestorNamespaces=Te.findAncestorNs(e,n.xpath,this.namespaceResolver));const i={inclusiveNamespacesPrefixList:n.inclusiveNamespacesPrefixList,ancestorNamespaces:n.ancestorNamespaces};return this.getCanonXml(n.transforms,r,i)}calculateSignatureValue(e,n){const r=this.getCanonSignedInfoXml(e),i=this.findSignatureAlgorithm(this.signatureAlgorithm);if(this.privateKey==null)throw new Error("Private key is required to compute signature");typeof n=="function"?i.getSignature(r,this.privateKey,n):this.signatureValue=i.getSignature(r,this.privateKey)}findSignatureAlgorithm(e){if(e==null)throw new Error("signatureAlgorithm is required");const n=this.SignatureAlgorithms[e];if(n)return new n;throw new Error(`signature algorithm '${e}' is not supported`)}findCanonicalizationAlgorithm(e){if(e!=null){const n=this.CanonicalizationAlgorithms[e];if(n)return new n}throw new Error(`canonicalization algorithm '${e}' is not supported`)}findHashAlgorithm(e){const n=this.HashAlgorithms[e];if(n)return new n;throw new Error(`hash algorithm '${e}' is not supported`)}validateElementAgainstReferences(e,n){var i;let r;if(typeof e=="string"){const s=Gt.select1(e,n);Bt.assertIsElementNode(s),r=s}else r=e;for(const s of this.getReferences()){const a=((i=s.uri)==null?void 0:i[0])==="#"?s.uri.substring(1):s.uri;for(const p of this.idAttributes){const h=r.getAttribute(p);if(a===h){s.xpath=`//*[@*[local-name(.)='${p}']='${a}']`;break}}const l=this.getCanonReferenceXml(n,s,r),d=this.findHashAlgorithm(s.digestAlgorithm).getHash(l);if(Te.validateDigestValue(d,s.digestValue))return s}throw new Error("No references passed validation")}validateReference(e,n){var u;const r=((u=e.uri)==null?void 0:u[0])==="#"?e.uri.substring(1):e.uri;let i=null;if(r==="")i=Gt.select1("//*",n);else{if((r==null?void 0:r.indexOf("'"))!==-1)throw new Error("Cannot validate a uri with quotes inside it");{let d=0;for(const p of this.idAttributes){const h=`//*[@*[local-name(.)='${p}']='${r}']`,g=Gt.select(h,n);if(Te.isArrayHasLength(g)){if(d+=g.length,d>1)throw new Error("Cannot validate a document which contains multiple elements with the same value for the ID / Id / Id attributes, in order to prevent signature wrapping attack.");i=g[0],e.xpath=h}}}}if(e.getValidatedNode=(0,VS.deprecate)(d=>{if(d=d||e.xpath,typeof d!="string"||e.validationError!=null)return null;const p=Gt.select1(d,n);return Bt.isNodeLike(p)?p:null},"`ref.getValidatedNode()` is deprecated and insecure. Use `ref.signedReference` or `this.getSignedReferences()` instead."),!Bt.isNodeLike(i)){const d=new Error(`invalid signature: the signature references an element with uri ${e.uri} but could not find such element in the xml`);return e.validationError=d,!1}const s=this.getCanonReferenceXml(n,e,i),l=this.findHashAlgorithm(e.digestAlgorithm).getHash(s);if(!Te.validateDigestValue(l,e.digestValue)){const d=new Error(`invalid signature: for uri ${e.uri} calculated digest is ${l} but the xml to validate supplies digest ${e.digestValue}`);return e.validationError=d,!1}return this.signedReferences.push(s),e.signedReference=s,!0}findSignatures(e){const n=Gt.select("//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']",e);return Bt.isArrayOfNodes(n)?n:[]}loadSignature(e){typeof e=="string"?this.signatureNode=e=new Ir.DOMParser().parseFromString(e):this.signatureNode=e,this.signatureXml=e.toString();const n=Gt.select1(".//*[local-name(.)='CanonicalizationMethod']/@Algorithm",e);if(!Bt.isNodeLike(n))throw new Error("could not find CanonicalizationMethod/@Algorithm element");Bt.isAttributeNode(n)&&(this.canonicalizationAlgorithm=n.value);const r=Gt.select1(".//*[local-name(.)='SignatureMethod']/@Algorithm",e);Bt.isAttributeNode(r)&&(this.signatureAlgorithm=r.value);const i=Te.findChildren(this.signatureNode,"SignedInfo");if(!Te.isArrayHasLength(i))throw new Error("no signed info node found");if(i.length>1)throw new Error("could not load signature that contains multiple SignedInfo nodes");let s=this.canonicalizationAlgorithm;(!s||s==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"||s==="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments")&&(s="http://www.w3.org/2001/10/xml-exc-c14n#");const a=this.getCanonXml([s],i[0]),u=new Ir.DOMParser().parseFromString(a,"text/xml").documentElement;this.references=[];const d=Te.findChildren(u,"Reference");if(!Te.isArrayHasLength(d))throw new Error("could not find any Reference elements");for(const g of d)this.loadReference(g);const p=Gt.select1(".//*[local-name(.)='SignatureValue']/text()",e);Bt.isTextNode(p)&&(this.signatureValue=p.data.replace(/\r?\n/g,""));const h=Gt.select1(".//*[local-name(.)='KeyInfo']",e);Bt.isNodeLike(h)&&(this.keyInfo=h)}loadReference(e){let n=Te.findChildren(e,"DigestMethod");if(n.length===0)throw new Error(`could not find DigestMethod in reference ${e.toString()}`);const r=n[0],i=Te.findAttr(r,"Algorithm");if(!i)throw new Error(`could not find Algorithm attribute in node ${r.toString()}`);const s=i.value;if(n=Te.findChildren(e,"DigestValue"),n.length===0)throw new Error(`could not find DigestValue node in reference ${e.toString()}`);if(n.length>1)throw new Error(`could not load reference for a node that contains multiple DigestValue nodes: ${e.toString()}`);const a=n[0].textContent;if(!a)throw new Error(`could not find the value of DigestValue in ${e.toString()}`);const l=[];let u=[];if(n=Te.findChildren(e,"Transforms"),n.length!==0){const p=n[0],h=Te.findChildren(p,"Transform");for(const $ of h){const A=Te.findAttr($,"Algorithm");A&&l.push(A.value)}const g=Te.findChildren(h[h.length-1],"InclusiveNamespaces");Te.isArrayHasLength(g)&&(u=g.flatMap($=>($.getAttribute("PrefixList")??"").split(" ")).filter($=>$.length>0))}Te.isArrayHasLength(this.implicitTransforms)&&this.implicitTransforms.forEach(function(p){l.push(p)}),(l.length===0||l[l.length-1]==="http://www.w3.org/2000/09/xmldsig#enveloped-signature")&&l.push("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");const d=Bt.isElementNode(e)&&e.getAttribute("URI")||void 0;this.addReference({transforms:l,digestAlgorithm:s,uri:d,digestValue:a,inclusiveNamespacesPrefixList:u,isEmptyUri:!1})}addReference({xpath:e,transforms:n,digestAlgorithm:r,uri:i="",digestValue:s,inclusiveNamespacesPrefixList:a=[],isEmptyUri:l=!1}){if(r==null)throw new Error("digestAlgorithm is required");if(!Te.isArrayHasLength(n))throw new Error("transforms must contain at least one transform algorithm");this.references.push({xpath:e,transforms:n,digestAlgorithm:r,uri:i,digestValue:s,inclusiveNamespacesPrefixList:a,isEmptyUri:l,getValidatedNode:()=>{throw new Error("Reference has not been validated yet; Did you call `sig.checkSignature()`?")}})}getReferences(){return this.references}getSignedReferences(){return[...this.signedReferences]}computeSignature(e,n,r){let i;typeof n=="function"&&r==null?(i=n,n={}):(i=r,n=n??{});const s=new Ir.DOMParser().parseFromString(e);let a="xmlns";const l=[];let u;const d=["append","prepend","before","after"],p=n.prefix,h=n.attrs||{},g=n.location||{},$=n.existingPrefixes||{};if(this.namespaceResolver={lookupNamespaceURI:function(H){return H?$[H]:null}},g.reference=g.reference||"/*",g.action=g.action||"append",d.indexOf(g.action)===-1){const H=new Error(`location.action option has an invalid action: ${g.action}, must be any of the following values: ${d.join(", ")}`);if(i){i(H);return}else throw H}p?(a+=`:${p}`,u=`${p}:`):u="",Object.keys(h).forEach(function(H){H!=="xmlns"&&H!==a&&l.push(`${H}="${h[H]}"`)}),l.push(`${a}="http://www.w3.org/2000/09/xmldsig#"`);let A=`<${u}Signature ${l.join(" ")}>`;A+=this.createSignedInfo(s,p),A+=this.getKeyInfo(p),A+=`</${u}Signature>`,this.originalXmlWithIds=s.toString();let z="";Object.keys($).forEach(function(H){z+=`xmlns:${H}="${$[H]}" `});const T=`<Dummy ${z}>${A}</Dummy>`,x=new Ir.DOMParser().parseFromString(T).documentElement.firstChild,U=Gt.select1(g.reference,s);if(!Bt.isNodeLike(U)){const H=new Error(`the following xpath cannot be used because it was not found: ${g.reference}`);if(i){i(H);return}else throw H}if(g.action==="append")U.appendChild(x);else if(g.action==="prepend")U.insertBefore(x,U.firstChild);else if(g.action==="before"){if(U.parentNode==null)throw new Error("`location.reference` refers to the root node (by default), so we can't insert `before`");U.parentNode.insertBefore(x,U)}else if(g.action==="after"){if(U.parentNode==null)throw new Error("`location.reference` refers to the root node (by default), so we can't insert `after`");U.parentNode.insertBefore(x,U.nextSibling)}this.signatureNode=x;const q=Te.findChildren(this.signatureNode,"SignedInfo");if(q.length===0){const H=new Error("could not find SignedInfo element in the message");if(i){i(H);return}else throw H}const F=q[0];typeof i=="function"?this.calculateSignatureValue(s,(H,G)=>{H?i(H):(this.signatureValue=G||"",x.insertBefore(this.createSignature(p),F.nextSibling),this.signatureXml=x.toString(),this.signedXml=s.toString(),i(null,this))}):(this.calculateSignatureValue(s),x.insertBefore(this.createSignature(p),F.nextSibling),this.signatureXml=x.toString(),this.signedXml=s.toString())}getKeyInfo(e){const n=e?`${e}:`:"";let r="";this.keyInfoAttributes&&Object.keys(this.keyInfoAttributes).forEach(s=>{r+=` ${s}="${this.keyInfoAttributes[s]}"`});const i=this.getKeyInfoContent({publicCert:this.publicCert,prefix:e});return r||i?`<${n}KeyInfo${r}>${i}</${n}KeyInfo>`:""}createReferences(e,n){let r="";n=n||"",n=n&&`${n}:`;for(const i of this.getReferences()){const s=Gt.selectWithResolver(i.xpath??"",e,this.namespaceResolver);if(!Te.isArrayHasLength(s))throw new Error(`the following xpath cannot be signed because it was not found: ${i.xpath}`);for(const a of s){if(i.isEmptyUri)r+=`<${n}Reference URI="">`;else{const d=this.ensureHasId(a);i.uri=d,r+=`<${n}Reference URI="#${d}">`}r+=`<${n}Transforms>`;for(const d of i.transforms||[]){const p=this.findCanonicalizationAlgorithm(d);r+=`<${n}Transform Algorithm="${p.getAlgorithmName()}"`,Te.isArrayHasLength(i.inclusiveNamespacesPrefixList)?(r+=">",r+=`<InclusiveNamespaces PrefixList="${i.inclusiveNamespacesPrefixList.join(" ")}" xmlns="${p.getAlgorithmName()}"/>`,r+=`</${n}Transform>`):r+=" />"}const l=this.getCanonReferenceXml(e,i,a),u=this.findHashAlgorithm(i.digestAlgorithm);r+=`</${n}Transforms><${n}DigestMethod Algorithm="${u.getAlgorithmName()}" /><${n}DigestValue>${u.getHash(l)}</${n}DigestValue></${n}Reference>`}}return r}getCanonXml(e,n,r={}){r.defaultNsForPrefix=r.defaultNsForPrefix??qn.defaultNsForPrefix,r.signatureNode=this.signatureNode;let s=n.cloneNode(!0);return e.forEach(a=>{Bt.isNodeLike(s)&&(s=this.findCanonicalizationAlgorithm(a).process(s,r))}),s.toString()}ensureHasId(e){let n;if(this.idMode==="wssecurity"?n=Te.findAttr(e,"Id","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"):this.idAttributes.some(i=>(n=Te.findAttr(e,i),!!n)),n)return n.value;const r=`_${this.id++}`;return this.idMode==="wssecurity"?(e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"),e.setAttributeNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd","wsu:Id",r)):e.setAttribute("Id",r),r}createSignedInfo(e,n){if(typeof this.canonicalizationAlgorithm!="string")throw new Error("Missing canonicalizationAlgorithm when trying to create signed info for XML");const r=this.findCanonicalizationAlgorithm(this.canonicalizationAlgorithm),i=this.findSignatureAlgorithm(this.signatureAlgorithm);let s;s=n||"",s=s&&`${s}:`;let a=`<${s}SignedInfo>`;return a+=`<${s}CanonicalizationMethod Algorithm="${r.getAlgorithmName()}"`,Te.isArrayHasLength(this.inclusiveNamespacesPrefixList)?(a+=">",a+=`<InclusiveNamespaces PrefixList="${this.inclusiveNamespacesPrefixList.join(" ")}" xmlns="${r.getAlgorithmName()}"/>`,a+=`</${s}CanonicalizationMethod>`):a+=" />",a+=`<${s}SignatureMethod Algorithm="${i.getAlgorithmName()}" />`,a+=this.createReferences(e,n),a+=`</${s}SignedInfo>`,a}createSignature(e){let n="xmlns";e?(n+=`:${e}`,e+=":"):e="";const r=`<${e}SignatureValue>${this.signatureValue}</${e}SignatureValue>`,i=`<${e}Signature ${n}="http://www.w3.org/2000/09/xmldsig#">${r}</${e}Signature>`;return new Ir.DOMParser().parseFromString(i).documentElement.firstChild}getSignatureXml(){return this.signatureXml}getOriginalXmlWithIds(){return this.originalXmlWithIds}getSignedXml(){return this.signedXml}}Ul.SignedXml=qn;qn.defaultNsForPrefix={ds:"http://www.w3.org/2000/09/xmldsig#"};qn.noop=()=>null;(function(t){var e=Lr&&Lr.__createBinding||(Object.create?function(a,l,u,d){d===void 0&&(d=u);var p=Object.getOwnPropertyDescriptor(l,u);(!p||("get"in p?!l.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:function(){return l[u]}}),Object.defineProperty(a,d,p)}:function(a,l,u,d){d===void 0&&(d=u),a[d]=l[u]}),n=Lr&&Lr.__exportStar||function(a,l){for(var u in a)u!=="default"&&!Object.prototype.hasOwnProperty.call(l,u)&&e(l,a,u)};Object.defineProperty(t,"__esModule",{value:!0}),t.SignedXml=t.ExclusiveCanonicalizationWithComments=t.ExclusiveCanonicalization=t.C14nCanonicalizationWithComments=t.C14nCanonicalization=void 0;var r=ai;Object.defineProperty(t,"C14nCanonicalization",{enumerable:!0,get:function(){return r.C14nCanonicalization}}),Object.defineProperty(t,"C14nCanonicalizationWithComments",{enumerable:!0,get:function(){return r.C14nCanonicalizationWithComments}});var i=ci;Object.defineProperty(t,"ExclusiveCanonicalization",{enumerable:!0,get:function(){return i.ExclusiveCanonicalization}}),Object.defineProperty(t,"ExclusiveCanonicalizationWithComments",{enumerable:!0,get:function(){return i.ExclusiveCanonicalizationWithComments}});var s=Ul;Object.defineProperty(t,"SignedXml",{enumerable:!0,get:function(){return s.SignedXml}}),n(Bs,t),n(Os,t)})(B6);async function KS(t){const e=new DecompressionStream("deflate-raw"),n=new Blob([t]).stream().pipeThrough(e);return new Uint8Array(await new Response(n).arrayBuffer())}async function GS(t){const e=await j_.decode(t.replace(/ /g,"+"));try{const n=await KS(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 WS(t){const e=await GS(t),r=new Ip.XMLParser({attributeNamePrefix:"@_",alwaysCreateTextNode:!0,ignoreAttributes:!1}).parse(e);return R6.parse(r)}function XS(t){const e=t.certificates.map(i=>({":@":{"@_use":"signing"},KeyDescriptor:[{":@":{"@_xmlns":"http://www.w3.org/2000/09/xmldsig#"},KeyInfo:[{X509Data:[{X509Certificate:[{"#text":i}]}]}]}]})),n=[{":@":{"@_entityID":t.entityId,"@_xmlns":"urn:oasis:names:tc:SAML:2.0:metadata"},EntityDescriptor:[{":@":{"@_protocolSupportEnumeration":"urn:oasis:names:tc:SAML:2.0:protocol"},IDPSSODescriptor:[...e,{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.singleLogoutServiceUrl},SingleLogoutService:[]},{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.singleLogoutServiceUrl},SingleLogoutService:[]},{NameIDFormat:[{"#text":"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"}]},{NameIDFormat:[{"#text":"urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"}]},{NameIDFormat:[{"#text":"urn:oasis:names:tc:SAML:2.0:nameid-format:transient"}]},{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.assertionConsumerServiceUrl},SingleSignOnService:[]},{":@":{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.assertionConsumerServiceUrl},SingleSignOnService:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]},{":@":{"@_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"},Attribute:[]}]}]}];return new Ip.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!0,format:!0}).build(n)}const JS=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 l,u;const{client_id:e}=t.req.valid("param"),n=await t.env.data.legacyClients.get(e);if(!n)throw new E(404,{message:"Client not found"});const{signingKeys:r}=await t.env.data.keys.list({q:"type:saml_encryption"});if(r.length===0)throw new E(500,{message:"No signing key found"});const i=r.map(d=>new Nl(d.cert).toString("base64")),s=t.env.ISSUER,a=XS({entityId:((u=(l=n.addons)==null?void 0:l.samlp)==null?void 0:u.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 E(404,{message:"Client not found"});t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id);const s=await WS(n),a=s["samlp:AuthnRequest"]["saml:Issuer"]["#text"],l=await t.env.data.loginSessions.create(t.var.tenant_id,{csrf_token:He(),authParams:{client_id:e,state:JSON.stringify({requestId:s["samlp:AuthnRequest"]["@_ID"],relayState:r}),response_mode:zn.SAML_POST,redirect_uri:s["samlp:AuthnRequest"]["@_AssertionConsumerServiceURL"],audience:a},expires_at:new Date(Date.now()+Hr*1e3).toISOString(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Yn(t.get("auth0_client"))});return t.redirect(`/u/login/identifier?state=${l.id}`)});function YS(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=as(r,t.dataAdapter),a=t.dataAdapter.cache||ks({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),l=t.dataAdapter.cache?300:0,u=Dl(s,{defaultTtl:l,cacheEntities:["tenants","connections","clients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=zl(r,u),i()}),e.use(Ol).use(Tl).use(Af(e));const n=e.route("/",JS);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"SAML API"},security:[{oauth2:["openid","email","profile"]}]}),xf(n),n}const ZS="Account detected",QS="Manage your account details",ek="Account",tk="We have detected that you have already created an account through",nk="By signing in, you agree to our",rk="and",ik="email address",ok="email or phone number",sk="phone number",ak="Callback URL mismatch",ck="The provided redirect_uri is not in the list of allowed callback URLs.",lk="Change email address",uk="continue with user",dk="Please click the button to create a new password account.",pk="Enter the code at {{vendorName}} to complete the login",fk="Welcome to {{vendorName}}! {{code}} is the login code",hk="Welcome to {{vendorName}}! {{code}} is the login code",gk="Code expired",mk="Invalid code",_k="Please check <0>{{username}}</0> and enter the six-digit code that we've sent you.",yk="The code is already used",wk="The code is valid for 30 minutes",vk="A configuration error occurred.",bk="Confirm password",$k="Are you sure you want to unlink this account?",xk="Need Help?",Ak="Contact us",Ek="or continue with social account",Sk="Continue with {{provider}}",kk="Would you like to continue with your existing account?",Nk="Copyright © 2023 SESAMY. All rights reserved.",Ck="©2023 Sesamy",zk="Choose a password with a mix of uppercase and lowercase letters, numbers, and symbols.",Ik="Please enter a valid email address.",Tk="The passwords didn't match. Try again.",Ok="Choose password",Dk="Password must be at least 8 characters long and contain at least one lowercase letter, one uppercase letter, one number and one symbol.",Rk="Create new account",jk="Sign up with password",Pk="Current email address",Bk="You are currently logged in as <0>{{email}}</0>",Lk="Edit",Fk="Email",Uk="Email is already taken",Mk="Email changed to <0>{{email}}</0> ",qk="Email or Phone Number",Vk="Email address",Hk="Your email address has been validated",Kk="Now enter your password to login again",Gk="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.",Wk="Email verification sent",Xk="Enter a code",Jk="We'll send you a verification link to ensure you own this email address.",Yk="Enter new email",Zk="Enter new password",Qk="Enter password",e9="Enter your email address and password to login.",t9="Enter your password",n9="Something went wrong",r9="The magic link has expired. Please click on the button below to receive a new link in your inbox.",i9="Hey! We updated our login experience. <0>Click here to learn more about it.</0>",o9="Send password reset email",s9="Click the button below and we’ll send instructions on how to reset your password.",a9="Password reset email sent",c9="Forgot password?",l9="Forgot password?",u9="Go back",d9="Hide password",p9="Invalid identifier",f9="Invalid password",h9=`The link is no longer valid.
|
|
299
299
|
|
|
300
300
|
Please make sure to open the login link in the same browser you started the login with.
|
|
301
301
|
|