@descope/web-component 0.1.0 → 0.1.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,_ as n,a as t}from"./index-
|
|
1
|
+
import{S as e,_ as n,a as t}from"./index-219b094f.js";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new e({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:n(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),t(this,l,this.shadowRoot.querySelector(".debugger"),"f"),t(this,a,n(this,l,"f").querySelector(".content"),"f"),t(this,r,n(this,l,"f").querySelector(".header"),"f")}updateData(e){n(this,o,"f").update((n=>({messages:n.messages.concat(e)})))}connectedCallback(){var e;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(n(this,l,"f"),n(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",n(this,d,"f").resize),(e=n(this,l,"f")).onmousemove=n=>{(n.target.w&&n.target.w!==n.target.offsetWidth||n.target.h&&n.target.h!==n.target.offsetHeight)&&e.onresize(n),n.target.w=n.target.offsetWidth,n.target.h=n.target.offsetHeight},n(this,l,"f").onresize=n(this,i,"m",p).bind(this),n(this,o,"f").subscribe(n(this,i,"m",c).bind(this))}disconnectedCallback(){n(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",n(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(e){n(this,i,"m",h).call(this,e),n(this,i,"m",p).call(this)},h=function(e){n(this,a,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){n(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[e,t]=s(n(this,l,"f"),Number.parseInt(n(this,l,"f").style.left,10),Number.parseInt(n(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});n(this,l,"f").style.top=`${t}px`,n(this,l,"f").style.left=`${e}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{l(r.next(t))}catch(t){i(t)}}function a(t){try{l(r.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((r=r.apply(t,e||[])).next())}))}function r(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,n):o?o.value=n:e.set(t,n),n}const i="undefined"!=typeof localStorage,s=i&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";function b(t){return new URLSearchParams(window.location.search).get(t)}function y(t){if(window.history.replaceState&&b(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var m;function w(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(m||(m={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?m.forward:t<e?m.backward:void 0}const O=()=>{const[t="",e=""]=(b(a)||"").split("_");return{executionId:t,stepId:e}};function j(){y(a)}const S=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),E=()=>{const{executionId:t,stepId:e}=O();(t||e)&&j();const n=b("t")||void 0;n&&y("t");const r=b(l)||void 0;r&&y(l);const o=b("err")||void 0;return o&&y("err"),{executionId:t,stepId:e,token:n,code:r,exchangeError:o}},_=t=>{let e,n;return(...r)=>{return e&&(i=r,(o=e).length===i.length&&o.every(((t,e)=>t===i[e])))||(e=r,n=t(...r)),n;var o,i}};var C,x,A,U;function P(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r],i=t[o],s=e[o];if("object"==typeof i&&"object"==typeof s){if(!P(i,s))return!1}else if(i!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){C.set(this,void 0),x.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(r(this,C,"f")):t,n=Object.assign(Object.assign({},r(this,C,"f")),e);if(!r(this,U,"f")||!P(r(this,C,"f"),n)){const t=r(this,C,"f");o(this,C,n,"f"),Object.freeze(r(this,C,"f")),setTimeout((()=>{Object.values(r(this,x,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},o(this,C,t,"f"),o(this,U,e,"f")}get current(){return Object.assign({},r(this,C,"f"))}subscribe(t){return o(this,A,r(this,A,"f")+1,"f"),r(this,x,"f")[r(this,A,"f")]=t,r(this,A,"f").toString()}unsubscribe(t){const e=!!r(this,x,"f")[t];return e&&delete r(this,x,"f")[t],e}unsubscribeAll(){return o(this,x,{},"f"),!0}}C=new WeakMap,x=new WeakMap,A=new WeakMap,U=new WeakMap;const T=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${u}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return r=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),r);var r})))(t.textContent,e)}))})(t,e)};function q(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),n.publicKey.user.id=M(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.create(e);return r=n,JSON.stringify({id:r.id,rawId:L(r.rawId),type:r.type,response:{attestationObject:L(r.response.attestationObject),clientDataJSON:L(r.response.clientDataJSON)}});var r}))}function D(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.get(e);return r=n,JSON.stringify({id:r.id,rawId:L(r.rawId),type:r.type,response:{authenticatorData:L(r.response.authenticatorData),clientDataJSON:L(r.response.clientDataJSON),signature:L(r.response.signature),userHandle:L(r.response.userHandle)}});var r}))}function M(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function L(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const N=_((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}}))));function K(t){this.message=t}K.prototype=new Error,K.prototype.name="InvalidCharacterError";var $="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new K("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,i=0,s="";r=e.charAt(i++);~r&&(n=o%4?64*n+r:r,o++%4)?s+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return s};function J(t){this.message=t}function W(t,e){if("string"!=typeof t)throw new J("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent($(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return $(e)}}(t.split(".")[n]))}catch(t){throw new J("Invalid token specified: "+t.message)}}J.prototype=new Error,J.prototype.name="InvalidTokenError";var F="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},H="__lodash_hash_undefined__",B="[object Function]",V="[object GeneratorFunction]",z=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,G=/^\w*$/,Z=/^\./,Q=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,X=/\\(\\)?/g,Y=/^\[object .+?Constructor\]$/,tt="object"==typeof F&&F&&F.Object===Object&&F,et="object"==typeof self&&self&&self.Object===Object&&self,nt=tt||et||Function("return this")();var rt,ot=Array.prototype,it=Function.prototype,st=Object.prototype,at=nt["__core-js_shared__"],lt=(rt=/[^.]+$/.exec(at&&at.keys&&at.keys.IE_PROTO||""))?"Symbol(src)_1."+rt:"",ct=it.toString,ut=st.hasOwnProperty,dt=st.toString,ht=RegExp("^"+ct.call(ut).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),pt=nt.Symbol,ft=ot.splice,gt=Et(nt,"Map"),vt=Et(Object,"create"),bt=pt?pt.prototype:void 0,yt=bt?bt.toString:void 0;function mt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function wt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function kt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function It(t,e){for(var n,r,o=t.length;o--;)if((n=t[o][0])===(r=e)||n!=n&&r!=r)return o;return-1}function Ot(t,e){var n;e=function(t,e){if(At(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Pt(t))return!0;return G.test(t)||!z.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:At(n=e)?n:_t(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[Ct(e[r++])];return r&&r==o?t:void 0}function jt(t){if(!Ut(t)||(e=t,lt&< in e))return!1;var e,n=function(t){var e=Ut(t)?dt.call(t):"";return e==B||e==V}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?ht:Y;return n.test(function(t){if(null!=t){try{return ct.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function St(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function Et(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return jt(n)?n:void 0}mt.prototype.clear=function(){this.__data__=vt?vt(null):{}},mt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},mt.prototype.get=function(t){var e=this.__data__;if(vt){var n=e[t];return n===H?void 0:n}return ut.call(e,t)?e[t]:void 0},mt.prototype.has=function(t){var e=this.__data__;return vt?void 0!==e[t]:ut.call(e,t)},mt.prototype.set=function(t,e){return this.__data__[t]=vt&&void 0===e?H:e,this},wt.prototype.clear=function(){this.__data__=[]},wt.prototype.delete=function(t){var e=this.__data__,n=It(e,t);return!(n<0)&&(n==e.length-1?e.pop():ft.call(e,n,1),!0)},wt.prototype.get=function(t){var e=this.__data__,n=It(e,t);return n<0?void 0:e[n][1]},wt.prototype.has=function(t){return It(this.__data__,t)>-1},wt.prototype.set=function(t,e){var n=this.__data__,r=It(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},kt.prototype.clear=function(){this.__data__={hash:new mt,map:new(gt||wt),string:new mt}},kt.prototype.delete=function(t){return St(this,t).delete(t)},kt.prototype.get=function(t){return St(this,t).get(t)},kt.prototype.has=function(t){return St(this,t).has(t)},kt.prototype.set=function(t,e){return St(this,t).set(t,e),this};var _t=xt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Pt(t))return yt?yt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return Z.test(t)&&n.push(""),t.replace(Q,(function(t,e,r,o){n.push(r?o.replace(X,"$1"):e||t)})),n}));function Ct(t){if("string"==typeof t||Pt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function xt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(xt.Cache||kt),n}xt.Cache=kt;var At=Array.isArray;function Ut(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Pt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==dt.call(t)}var Rt=function(t,e,n){var r=null==t?void 0:Ot(t,e);return void 0===r?n:r},Tt="/v1/auth/accesskey/exchange",qt="/v1/auth/otp/verify",Dt="/v1/auth/otp/signin",Mt="/v1/auth/otp/signup",Lt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Nt="/v1/auth/otp/signup-in",Kt="/v1/auth/magiclink/verify",$t="/v1/auth/magiclink/signin",Jt="/v1/auth/magiclink/signup",Wt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Ft="/v1/auth/magiclink/signup-in",Ht="/v1/auth/enchantedlink/verify",Bt="/v1/auth/enchantedlink/signin",Vt="/v1/auth/enchantedlink/signup",zt="/v1/auth/enchantedlink/pending-session",Gt={email:"/v1/auth/enchantedlink/update/email"},Zt="/v1/auth/enchantedlink/signup-in",Qt="/v1/auth/oauth/authorize",Xt="/v1/auth/oauth/exchange",Yt="/v1/auth/saml/authorize",te="/v1/auth/saml/exchange",ee="/v1/auth/totp/verify",ne="/v1/auth/totp/signup",re="/v1/auth/totp/update",oe={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ie={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},se={start:"/v1/auth/webauthn/signup-in/start"},ae={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},le="/v1/auth/refresh",ce="/v1/auth/logout",ue="/v1/auth/logoutall",de="/v1/auth/me",he="/v1/flow/start",pe="/v1/flow/next";const fe=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var ge;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ge||(ge={}));const ve=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,r])=>(t[n]=r,t)),t),t}),{})),be=t=>void 0===t?void 0:JSON.stringify(t),ye=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},me=({baseUrl:t,projectId:e,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>fe().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const r=await n(...e);return t[r.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),fe().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:l,baseUrl:t,queryParams:d}),{headers:ve(ye(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.56"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:be(c),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&await o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:r}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:ge.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:ge.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:ge.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:ge.delete,token:o}),hooks:o}};var we=429;function ke(t,e,n){var r;let o=Ie(t);e&&(o=null===(r=null==o?void 0:o.tenants)||void 0===r?void 0:r[e]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function Ie(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return W(t)}function Oe(t){const{exp:e}=Ie(t);return(new Date).getTime()/1e3>e}function je(t,e){return ke(t,e,"permissions")}function Se(t,e){return ke(t,e,"roles")}const Ee=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function _e(t,e){var n;const r=await t,o={code:r.status,ok:r.ok,response:r},i=await r.clone().json();return r.ok?o.data=e?e(i):i:(o.error=i,r.status===we&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=r.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const Ce=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),xe=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ae=t=>e=>t.test(e),Ue=Ae(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Pe=Ae(/^\+[1-9]{1}[0-9]{3,14}$/),Re=Ce(Ue,'"{val}" is not a valid email'),Te=Ce(Pe,'"{val}" is not a valid phone number'),qe=Ce((1,t=>t.length>=1),"Minimum length is 1");const De=Ce((t=>"string"==typeof t),"Input is not a string"),Me=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>xe(...t).validate(n[e]))),e(...n)),Le=t=>[De(`"${t}" must be a string`),qe(`"${t}" must not be empty`)],Ne=t=>[De(`"${t}" must be a string`),Re()],Ke=t=>[De(`"${t}" must be a string`),Te()],$e=Me(Le("accessKey")),Je=t=>({exchange:$e((e=>_e(t.post(Tt,{},{token:e}))))});var We,Fe,He,Be;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(We||(We={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Fe||(Fe={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(He||(He={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Be||(Be={}));const Ve=Le("loginId"),ze=Me(Le("token")),Ge=Me(Ve),Ze=Me(Le("pendingRef")),Qe=Me(Ve,Ne("email")),Xe=t=>({verify:ze((e=>_e(t.post(Ht,{token:e})))),signIn:Ge(((e,n,r,o)=>_e(t.post(Ee(Bt,Fe.email),{loginId:e,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Ge(((e,n)=>_e(t.post(Ee(Zt,Fe.email),{loginId:e,URI:n})))),signUp:Ge(((e,n,r)=>_e(t.post(Ee(Vt,Fe.email),{loginId:e,URI:n,user:r})))),waitForSession:Ze(((e,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(zt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(_e(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Qe(((e,n,r,o)=>_e(t.post(Gt.email,{loginId:e,email:n,URI:r},{token:o}))))}}),Ye=Me(Le("flowId")),tn=Me(Le("executionId"),Le("stepId"),Le("interactionId")),en=t=>({start:Ye(((e,n,r,o,i)=>_e(t.post(he,{flowId:e,options:n,conditionInteractionId:r,interactionId:o,input:i})))),next:tn(((e,n,r,o)=>_e(t.post(pe,{executionId:e,stepId:n,interactionId:r,input:o}))))}),nn=Le("loginId"),rn=Me(Le("token")),on=Me(nn),sn=Me(nn,Ke("phone")),an=Me(nn,Ne("email")),ln=t=>({verify:rn((e=>_e(t.post(Kt,{token:e})))),signIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:on(((e,r,o,i)=>_e(t.post(Ee($t,n),{loginId:e,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:on(((e,r,o)=>_e(t.post(Ee(Jt,n),{loginId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:on(((e,r)=>_e(t.post(Ee(Ft,n),{loginId:e,URI:r}))))})),{}),update:{email:an(((e,n,r,o)=>_e(t.post(Wt.email,{loginId:e,email:n,URI:r},{token:o})))),phone:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:sn(((e,r,o,i)=>_e(t.post(Ee(Wt.phone,n),{loginId:e,phone:r,URI:o},{token:i}))))})),{})}});var cn;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin"}(cn||(cn={}));const un=Me(Le("code")),dn=t=>({start:Object.keys(cn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:r=!1}={},o,i)=>{const s=await t.post(Qt,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!r||!s.ok)return _e(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:un((e=>_e(t.post(Xt,{code:e}))))});var hn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(hn||(hn={}));const pn=Le("loginId"),fn=Me(pn,Le("code")),gn=Me(pn),vn=Me(pn,Ke("phone")),bn=Me(pn,Ne("email")),yn=t=>({verify:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:fn(((e,r)=>_e(t.post(Ee(qt,n),{code:r,loginId:e}))))})),{}),signIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:gn(((e,r,o)=>_e(t.post(Ee(Dt,n),{loginId:e,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:gn(((e,r)=>_e(t.post(Ee(Mt,n),{loginId:e,user:r}))))})),{}),signUpOrIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:gn((e=>_e(t.post(Ee(Nt,n),{loginId:e}))))})),{}),update:{email:bn(((e,n,r)=>_e(t.post(Lt.email,{loginId:e,email:n},{token:r})))),phone:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:vn(((e,r,o)=>_e(t.post(Ee(Lt.phone,n),{loginId:e,phone:r},{token:o}))))})),{})}}),mn=Me(Le("tenant")),wn=Me(Le("code")),kn=t=>({start:mn((async(e,n,{redirect:r=!1}={},o,i)=>{const s=await t.post(Yt,o||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!r||!s.ok)return _e(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:wn((e=>_e(t.post(te,{code:e}))))}),In=Le("loginId"),On=Me(In,Le("code")),jn=Me(In),Sn=Me(In),En=t=>({signUp:jn(((e,n)=>_e(t.post(ne,{loginId:e,user:n})))),verify:On(((e,n,r,o)=>_e(t.post(ee,{loginId:e,code:n,loginOptions:r},{token:o})))),update:Sn(((e,n)=>_e(t.post(re,{loginId:e},{token:n}))))}),_n=[De('"loginId" must be a string')],Cn=Le("loginId"),xn=Le("origin"),An=Me(Cn,xn,Le("name")),Un=Me(Cn,xn),Pn=Me(_n,xn),Rn=Me(Cn,xn,Le("token")),Tn=Me(Le("transactionId"),Le("response")),qn=t=>({signUp:{start:An(((e,n,r)=>_e(t.post(oe.start,{user:{loginId:e,name:r},origin:n})))),finish:Tn(((e,n)=>_e(t.post(oe.finish,{transactionId:e,response:n}))))},signIn:{start:Pn(((e,n,r,o)=>_e(t.post(ie.start,{loginId:e,origin:n,loginOptions:r},{token:o})))),finish:Tn(((e,n)=>_e(t.post(ie.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Un(((e,n)=>_e(t.post(se.start,{loginId:e,origin:n}))))},update:{start:Rn(((e,n,r)=>_e(t.post(ae.start,{loginId:e,origin:n},{token:r})))),finish:Tn(((e,n)=>_e(t.post(ae.finish,{transactionId:e,response:n}))))}}),Dn=Me(Le("token"));var Mn,Ln=Me([("projectId",Mn=Le("projectId"),Ce(((t,e)=>n=>xe(...e).validate(Rt(n,t)))("projectId",Mn))())])((t=>{var e,n;const r=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:r,cookiePolicy:o,baseHeaders:i={}})=>{return s=me({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:r,cookiePolicy:o,baseConfig:{baseHeaders:i}}),{accessKey:Je(s),otp:yn(s),magicLink:ln(s),enchantedLink:Xe(s),oauth:dn(s),saml:kn(s),totp:En(s),webauthn:qn(s),flow:en(s),refresh:t=>_e(s.post(le,{},{token:t})),logout:t=>_e(s.post(ce,{},{token:t})),logoutAll:t=>_e(s.post(ue,{},{token:t})),me:t=>_e(s.get(de,{token:t})),isJwtExpired:Dn(Oe),getJwtPermissions:Dn(je),getJwtRoles:Dn(Se),httpClient:s};var s})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==r?void 0:r.reduce(((t,e)=>e(t)),t),afterRequest:async(e,n)=>{(await Promise.allSettled(null==o?void 0:o.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))}));const Nn=(t,e,n)=>(e.forEach((e=>{const r=e.split(".");let o=r.shift(),i=t;for(;r.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${e}", "${o}" is missing or has no value`);o=r.shift()}if("function"!=typeof i[o])throw Error(`"${e}" is not a function`);const s=i[o];i[o]=n(s)})),t);var Kn=Object.assign(Ln,{DeliveryMethods:Fe});function $n(t,e){var n=[];return function(t,e){var n,r,o=(r=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,o++)r[o]=i[s];return r}(t),{current:function(){return r[0]},postpone:function(){var t=r.shift();void 0!==t&&r.push(t)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=o.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?o.postpone():o.exclude();var e,r=o.current();if(void 0===r)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(r,n+1)}))}))};return a(s,0)}(t,(function(t){var r=new Date,o=function(){return n.push({url:t,startedAt:r,finishedAt:new Date})},i=e(t);return i.then(o,o),i})).then((function(t){return[t,{attempts:n}]}))}var Jn="Failed to load the JS script of the agent";function Wn(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,s=void 0===i?o:i,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(r=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return $n(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(l,s),Fn).catch(Bn)})).then((function(e){var n=e[0],r=e[1];return n.load(t(t({},a),{ldi:r}))}))}function Fn(t){return function(t,e,n,r){var o,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),r=e.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=e,l())};i.addEventListener(s,a);var l=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return l(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(l(),o)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var r=document.createElement("script"),o=function(){var t;return null===(t=r.parentNode)||void 0===t?void 0:t.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),e()},r.onerror=function(){o(),n(new Error(Jn))},r.async=!0,r.src=t,i.appendChild(r)}))}(t)})).then(Hn)}function Hn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==r?void 0:r.configurable)?delete t[e]:r&&!r.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function Bn(t){throw t instanceof Error&&"9319"===t.message?new Error(Jn):t}
|
|
2
|
+
/*! js-cookie v3.0.1 | MIT */function Vn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}var zn=function t(e,n){function r(t,r,o){if("undefined"!=typeof document){"number"==typeof(o=Vn({},n,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in o)o[s]&&(i+="; "+s,!0!==o[s]&&(i+="="+o[s].split(";")[0]));return document.cookie=t+"="+e.write(r,t)+i}}return Object.create({set:r,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],r={},o=0;o<n.length;o++){var i=n[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=e.read(s,a),t===a)break}catch(t){}}return t?r[t]:r}},remove:function(t,e){r(t,"",Vn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Vn({},this.attributes,e))},withConverter:function(e){return t(Vn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Gn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,r)=>{var o;return n[r]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[r])||[]).concat((null==e?void 0:e[r])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Zn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Qn=async t=>{const e=await Zn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Xn="undefined"!=typeof localStorage,Yn=(t,e)=>Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),tr=t=>Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),er=t=>Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),nr="undefined"!=typeof window,rr=nr&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",or=(t="",e="")=>({vsid:t,vrid:e}),ir=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},sr=t=>(t.body&&(t.body.fpData=ir(!0)||or()),t),ar=()=>tr("dls_last_user_login_id"),lr=()=>tr("dls_last_user_display_name"),cr=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,r={}]=e,o=ar(),i=lr();return o&&(null!==(n=r.lastAuth)&&void 0!==n||(r.lastAuth={}),r.lastAuth.loginId=o,r.lastAuth.name=i),await t(...e)},ur=t=>async(...e)=>{const n=await t(...e);return er("dls_last_user_login_id"),er("dls_last_user_display_name"),n};function dr(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const hr=(t={},n)=>{var{refreshJwt:r,sessionJwt:o}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),r&&Yn("DSR",r),o&&(n?function(t,e,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(e){const i=new Date(1e3*o);zn.set(t,e,{path:n,domain:r,expires:i,sameSite:"Strict",secure:!0})}}("DS",o,i):Yn("DS",o))};function pr(){return tr("DSR")||""}function fr(){return zn.get("DS")||tr("DS")||""}function gr(){er("DSR"),er("DS"),zn.remove("DS")}const vr=t=>Object.assign(t,{token:t.token||pr()}),br=t=>async(...e)=>{const n=await t(...e);return gr(),n};async function yr(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=jr(n.publicKey.challenge),n.publicKey.user.id=jr(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=jr(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Sr(n.rawId),type:n.type,response:{attestationObject:Sr(n.response.attestationObject),clientDataJSON:Sr(n.response.clientDataJSON)}});var n}async function mr(t){const e=Ir(t);return Or(await navigator.credentials.get(e))}async function wr(t,e){const n=Ir(t);return n.signal=e.signal,n.mediation="conditional",Or(await navigator.credentials.get(n))}async function kr(t=!1){if(!nr)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Ir(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=jr(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=jr(t.id)})),n}function Or(t){return JSON.stringify({id:t.id,rawId:Sr(t.rawId),type:t.type,response:{authenticatorData:Sr(t.response.authenticatorData),clientDataJSON:Sr(t.response.clientDataJSON),signature:Sr(t.response.signature),userHandle:t.response.userHandle?Sr(t.response.userHandle):void 0}})}function jr(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Sr(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Er,_r=(Er=t=>({async signUp(e,n){const r=await t.webauthn.signUp.start(e,window.location.origin,n);if(!r.ok)return r;const o=await yr(r.data.options);return await t.webauthn.signUp.finish(r.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const r=await mr(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,r)},async signUpOrIn(e){var n;const r=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!r.ok)return r;if(null===(n=r.data)||void 0===n?void 0:n.create){const e=await yr(r.data.options);return await t.webauthn.signUp.finish(r.data.transactionId,e)}{const e=await mr(r.data.options);return await t.webauthn.signIn.finish(r.data.transactionId,e)}},async update(e,n){const r=await t.webauthn.update.start(e,window.location.origin,n);if(!r.ok)return r;const o=await yr(r.data.options);return await t.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:yr,get:mr,isSupported:kr,conditional:wr}}),(...t)=>{const e=Er(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),Cr=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await kr(),r=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=r,t.flow.start(...e)}});const xr=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:r,fpLoad:o}=n,i=e(n,["fpKey","fpLoad"]);return r?(nr?o&&(async t=>{try{if(ir())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Wn({apiKey:t,endpoint:rr}),r=await n,{requestId:o}=await r.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(or(e,o))}catch(t){global.FB_DEBUG&&console.error(t)}})(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(Gn(i,{beforeRequest:sr}))):t(Object.assign({},i))}),(t=>n=>{var r=e(n,["autoRefresh"]);const{clearAllTimers:o,setTimer:i}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(Gn(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:r}=await Zn(e);if(401===(null==e?void 0:e.status))o();else if(r){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(r))?a.getTime()-(new Date).getTime():0)-2e4;o(),i((()=>s.refresh(n)),t)}var a}}));return Nn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.2"},e.baseHeaders)}))),(t=>e=>{const n=dr(),r=dr(),o=t(Gn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),r.pub(null);else{const t=await Qn(e);t&&r.pub(t);const{sessionJwt:o}=await Zn(e);o&&n.pub(o)}}})),i=Nn(o,["logout","logoutAll"],(t=>async(...e)=>{const o=await t(...e);return n.pub(null),r.pub(null),o}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:r.sub})}),(t=>e=>{const n=t(Gn(e,{afterRequest:async(t,e)=>{var n;const r=await Qn(e),o=null===(n=null==r?void 0:r.loginIds)||void 0===n?void 0:n[0],i=null==r?void 0:r.name;o&&((t=>{Yn("dls_last_user_login_id",t)})(o),(t=>{Yn("dls_last_user_display_name",t)})(i))}}));let r=Nn(n,["flow.start"],cr);return r=Nn(r,["logout","logoutAll"],ur),Object.assign(r,{getLastUserLoginId:ar,getLastUserDisplayName:lr})}),(t=>n=>{var{persistTokens:r,sessionTokenViaCookie:o}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(!r||!nr)return r&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(i);const s=t(Gn(i,{beforeRequest:vr,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?gr():hr(await Zn(e),o)}})),a=Nn(s,["logout","logoutAll"],br);return Object.assign(a,{getRefreshToken:pr,getSessionToken:fr})}))(((...t)=>{const e=Kn(...t);return Object.assign(Object.assign({},e),{flow:Cr(e),webauthn:_r(e)})})),Ar=document.createElement("template");var Ur,Pr,Rr,Tr,qr,Dr,Mr,Lr,Nr,Kr,$r,Jr,Wr,Fr,Hr,Br,Vr,zr,Gr,Zr,Qr,Xr,Yr,to,eo,no,ro,oo,io,so,ao,lo,co,uo,ho,po,fo,go;Ar.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class vo extends HTMLElement{constructor(t){super(),Ur.add(this),Pr.set(this,!1),Rr.set(this,new R),Tr.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),qr.set(this,void 0),Dr.set(this,{popstate:r(this,Ur,"m",Jr).bind(this)}),Mr.set(this,void 0),Hr.set(this,_((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield w(t,"json")}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),r(this,Ur,"m",Xr).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},o(this,Mr,t,"f"),r(this,Ur,"m",Lr).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url"]}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield r(this,Hr,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(r(this,Ur,"m",Nr).call(this))return void r(this,Ur,"m",Kr).call(this);r(this,Ur,"m",$r).call(this),r(this,Ur,"m",Vr).call(this),r(this,Ur,"m",Br).call(this),r(this,Ur,"m",Yr).call(this);const{executionId:t,stepId:e,token:n,code:i,exchangeError:s}=E();window.addEventListener("popstate",r(this,Dr,"f").popstate),r(this,Rr,"f").subscribe(r(this,Ur,"m",Fr).bind(this)),r(this,Tr,"f").subscribe(r(this,Ur,"m",Qr).bind(this)),r(this,Rr,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:e,executionId:t,token:n,code:i,exchangeError:s,telemetryKey:this.telemetryKey}),r(this,Tr,"f").update({isDebug:this.debug}),o(this,Pr,!0,"f")}}))}disconnectedCallback(){r(this,Rr,"f").unsubscribeAll(),r(this,Tr,"f").unsubscribeAll(),r(this,Ur,"m",Zr).call(this),window.removeEventListener("popstate",r(this,Dr,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&r(this,Pr,"f")&&e!==n&&vo.observedAttributes.includes(t)){r(this,Ur,"m",$r).call(this);const o=null===e;r(this,Rr,"f").update((({stepId:e,executionId:r})=>{let i=e,s=r;return o||(s=null,i=null,j()),{[S(t)]:n,stepId:i,executionId:s}})),r(this,Tr,"f").update({isDebug:this.debug})}}}Pr=new WeakMap,Rr=new WeakMap,Tr=new WeakMap,qr=new WeakMap,Dr=new WeakMap,Mr=new WeakMap,Hr=new WeakMap,Ur=new WeakSet,Lr=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ar.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Nr=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Kr=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},$r=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url"];if(vo.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[S(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},Jr=function(){const{stepId:t,executionId:e}=O();r(this,Rr,"f").update({stepId:t,executionId:e})},Wr=function(t,e,r){const o=r||void 0,i=!!o;this.sdk=xr(Object.assign(Object.assign({},vo.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:o,fpLoad:i,persistTokens:!0})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Fr=function(t,e,o){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:i}=t;if(o("projectId")||o("baseUrl")||o("telemetryKey")){if(!e)return;r(this,Ur,"m",Wr).call(this,e,n,i)}r(this,Mr,"f").call(this,t)}))},Br=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=yield r(this,Hr,"f").call(this);null===(i=null===(o=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===o?void 0:o.fontFamilies)||void 0===i||i.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Vr=function(){r(this,Ur,"m",zr).call(this),r(this,Ur,"m",Gr).call(this)},zr=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield w(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Gr=function(){this.rootElement.setAttribute("data-theme",this.theme)},Zr=function(){var t;null===(t=r(this,qr,"f"))||void 0===t||t.remove(),o(this,qr,null,"f")},Qr=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-d63e0372.js"),o(this,qr,document.createElement("descope-debugger"),"f"),Object.assign(r(this,qr,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(r(this,qr,"f"))):r(this,Ur,"m",Zr).call(this)}))},Xr=function(t,e){var n;t&&this.debug&&(null===(n=r(this,qr,"f"))||void 0===n||n.updateData({title:t,description:e}))},Yr=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const n=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===n.length&&n[0].click()}},vo.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.2"}};class bo extends vo{constructor(){const t=new R;super(t.update.bind(t)),to.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),eo.set(this,void 0),no.set(this,null),ro.set(this,(()=>{clearInterval(r(this,eo,"f")),o(this,eo,null,"f")})),oo.set(this,(t=>{var e,n,o,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){r(this,ro,"f").call(this),r(this,to,"m",go).call(this,"error",null==t?void 0:t.error);const i=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||i,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:g,authInfo:v,lastAuth:b}=t.data;if("completed"===g)return function(t){i&&localStorage.setItem(c,JSON.stringify(t))}(b),r(this,ro,"f").call(this),void r(this,to,"m",go).call(this,"success",v);const{executionId:y,stepId:m,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==h?this.flowState.update({stepId:m,executionId:y,action:w,redirectTo:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:w})})),io.set(this,_((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.logger.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.logger.error("Webauthn start failed",t.message)}}))))),this.flowState=t}static set sdkConfigOverrides(t){vo.sdkConfigOverrides=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,r;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(r=this.stepState)||void 0===r||r.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(t,e,i){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:u,stepId:b,executionId:y,action:m,screenId:w,screenState:O,redirectTo:j,redirectUrl:S,token:E,code:_,exchangeError:C,webauthnTransactionId:x,webauthnOptions:A}=t;let U,P;r(this,eo,"f")&&r(this,ro,"f").call(this);const R=this.sdk.getLastUserLoginId();if(!y){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:P}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,R)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:u},S&&{redirectUrl:S}));return void r(this,oo,"f").call(this,t)}}if(i("token")&&E||i("code")&&_||i("exchangeError")&&C){const t=yield this.sdk.flow.next(y,b,g,{token:E,exchangeCode:_,exchangeError:C});return r(this,oo,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(m===d)return j||this.logger.error("Did not get redirect url"),void window.location.assign(j);if(m===p||m===f){if(!x||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=r(this,no,"f"))||void 0===s||s.abort(),o(this,no,null,"f");try{t=m===p?yield q(A):yield D(A)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(y,b,g,{transactionId:x,response:t,cancelWebauthn:e});r(this,oo,"f").call(this,n)}if(m===h&&o(this,eo,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(y,b,v,{});r(this,oo,"f").call(this,t)}))),2e3),"f"),!w&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const T={direction:I(+b,+e.stepId),screenState:Object.assign(Object.assign({},O),{lastAuth:{loginId:R,name:this.sdk.getLastUserDisplayName()||R}}),htmlUrl:k(a,`${U||w}.html`)},M=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(R);U?T.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:M},P,...t):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(y,b,...t)),this.stepState.update(T)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:o,direction:i,next:s,screenState:a}=t,l=document.createElement("template");l.innerHTML=yield w(o,"text");const c=l.content.cloneNode(!0),d=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const r=e.getAttribute("data-id"),o=null===(n=t.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c);this.sdk.webauthn.helpers.isSupported()?yield r(this,to,"m",ao).call(this,c,s):c.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),T(c,a),((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(e=null==a?void 0:a.totp)||void 0===e?void 0:e.image);const h=()=>n(this,void 0,void 0,(function*(){try{d.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])');null==t||t.focus({preventScroll:!0}),r(this,to,"m",po).call(this,s),r(this,to,"m",go).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield s(v,{});r(this,oo,"f").call(this,t)}}));i?r(this,to,"m",fo).call(this,h,i):h()}))}}eo=new WeakMap,no=new WeakMap,ro=new WeakMap,oo=new WeakMap,io=new WeakMap,to=new WeakSet,so=function(t){const e=t.name;if(!["email"].includes(e)){const n=`user-${e}`;t.name=n,t.addEventListener("input",(()=>{t.name=t.value?e:n}))}},ao=function(t,e){var i;return n(this,void 0,void 0,(function*(){null===(i=r(this,no,"f"))||void 0===i||i.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:i}=(yield r(this,io,"f").call(this))||{};t&&i&&(r(this,to,"m",so).call(this,s),o(this,no,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,r(this,no,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:i,response:t});r(this,oo,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},lo=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},co=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},uo=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var r,o;n?null===(r=null==t?void 0:t.classList)||void 0===r||r.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(o=null==t?void 0:t.classList)||void 0===o||o.remove("loading"))}))},ho=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||r(this,to,"m",lo).call(this)){const o=null==t?void 0:t.getAttribute("id");r(this,to,"m",uo).call(this,t);const i=r(this,to,"m",co).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return r?Object.assign(t,{[r]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),i),{origin:window.location.origin}),l=yield e(o,a);r(this,oo,"f").call(this,l)}var n}))},po=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{r(this,to,"m",ho).call(this,e,t)}}))},fo=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===m.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},go=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",bo);export{bo as D,R as S,r as _,o as a};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-219b094f.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ declare type FlowState = {
|
|
|
47
47
|
stepId: string;
|
|
48
48
|
executionId: string;
|
|
49
49
|
action: string;
|
|
50
|
+
redirectTo: string;
|
|
50
51
|
redirectUrl: string;
|
|
51
52
|
screenId: string;
|
|
52
53
|
screenState: ScreenState;
|
|
@@ -82,6 +83,7 @@ declare class BaseDescopeWc extends HTMLElement {
|
|
|
82
83
|
get flowId(): string;
|
|
83
84
|
get baseUrl(): string;
|
|
84
85
|
get tenant(): string;
|
|
86
|
+
get redirectUrl(): string;
|
|
85
87
|
get debug(): boolean;
|
|
86
88
|
get theme(): string;
|
|
87
89
|
get telemetryKey(): string;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";function m(t){return new URLSearchParams(window.location.search).get(t)}function b(t){if(window.history.replaceState&&m(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var w;function y(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(w||(w={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?w.forward:t<e?w.backward:void 0}const O=()=>{const[t="",e=""]=(m(a)||"").split("_");return{executionId:t,stepId:e}};function x(){b(a)}const S=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),j=()=>{const{executionId:t,stepId:e}=O();(t||e)&&x();const n=m("t")||void 0;n&&b("t");const o=m(l)||void 0;o&&b(l);const i=m("err")||void 0;return i&&b("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},C=t=>{let e,n;return(...o)=>{return e&&(r=o,(i=e).length===r.length&&i.every(((t,e)=>t===r[e])))||(e=o,n=t(...o)),n;var i,r}};var E,_,A,U;function P(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if("object"==typeof r&&"object"==typeof s){if(!P(r,s))return!1}else if(r!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){E.set(this,void 0),_.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,E,"f")):t,n=Object.assign(Object.assign({},o(this,E,"f")),e);if(!o(this,U,"f")||!P(o(this,E,"f"),n)){const t=o(this,E,"f");i(this,E,n,"f"),Object.freeze(o(this,E,"f")),setTimeout((()=>{Object.values(o(this,_,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,E,t,"f"),i(this,U,e,"f")}get current(){return Object.assign({},o(this,E,"f"))}subscribe(t){return i(this,A,o(this,A,"f")+1,"f"),o(this,_,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,_,"f")[t];return e&&delete o(this,_,"f")[t],e}unsubscribeAll(){return i(this,_,{},"f"),!0}}E=new WeakMap,_=new WeakMap,A=new WeakMap,U=new WeakMap;const L=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${u}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)};function T(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),n.publicKey.user.id=M(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:D(o.rawId),type:o.type,response:{attestationObject:D(o.response.attestationObject),clientDataJSON:D(o.response.clientDataJSON)}});var o}))}function q(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:D(o.rawId),type:o.type,response:{authenticatorData:D(o.response.authenticatorData),clientDataJSON:D(o.response.clientDataJSON),signature:D(o.response.signature),userHandle:D(o.response.userHandle)}});var o}))}function M(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function D(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const $=C((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),N=(t,e,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(e,("all"===o.left?t.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-t.offsetWidth),window.innerWidth-("all"===o.right?t.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?t.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-t.offsetHeight),window.innerHeight-("all"===o.bottom?t.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]};function K(t){this.message=t}K.prototype=new Error,K.prototype.name="InvalidCharacterError";var J="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new K("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,r=0,s="";o=e.charAt(r++);~o&&(n=i%4?64*n+o:o,i++%4)?s+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function W(t){this.message=t}function F(t,e){if("string"!=typeof t)throw new W("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(J(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return J(e)}}(t.split(".")[n]))}catch(t){throw new W("Invalid token specified: "+t.message)}}W.prototype=new Error,W.prototype.name="InvalidTokenError";var H="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},z="__lodash_hash_undefined__",B="[object Function]",V="[object GeneratorFunction]",Z=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,G=/^\w*$/,X=/^\./,Y=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Q=/\\(\\)?/g,tt=/^\[object .+?Constructor\]$/,et="object"==typeof H&&H&&H.Object===Object&&H,nt="object"==typeof self&&self&&self.Object===Object&&self,ot=et||nt||Function("return this")();var it,rt=Array.prototype,st=Function.prototype,at=Object.prototype,lt=ot["__core-js_shared__"],ct=(it=/[^.]+$/.exec(lt&<.keys&<.keys.IE_PROTO||""))?"Symbol(src)_1."+it:"",ut=st.toString,dt=at.hasOwnProperty,ht=at.toString,pt=RegExp("^"+ut.call(dt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ft=ot.Symbol,gt=rt.splice,vt=Ct(ot,"Map"),mt=Ct(Object,"create"),bt=ft?ft.prototype:void 0,wt=bt?bt.toString:void 0;function yt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function kt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function It(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function Ot(t,e){for(var n,o,i=t.length;i--;)if((n=t[i][0])===(o=e)||n!=n&&o!=o)return i;return-1}function xt(t,e){var n;e=function(t,e){if(Ut(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Rt(t))return!0;return G.test(t)||!Z.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ut(n=e)?n:Et(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[_t(e[o++])];return o&&o==i?t:void 0}function St(t){if(!Pt(t)||(e=t,ct&&ct in e))return!1;var e,n=function(t){var e=Pt(t)?ht.call(t):"";return e==B||e==V}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?pt:tt;return n.test(function(t){if(null!=t){try{return ut.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function jt(t,e){var n,o,i=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function Ct(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return St(n)?n:void 0}yt.prototype.clear=function(){this.__data__=mt?mt(null):{}},yt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},yt.prototype.get=function(t){var e=this.__data__;if(mt){var n=e[t];return n===z?void 0:n}return dt.call(e,t)?e[t]:void 0},yt.prototype.has=function(t){var e=this.__data__;return mt?void 0!==e[t]:dt.call(e,t)},yt.prototype.set=function(t,e){return this.__data__[t]=mt&&void 0===e?z:e,this},kt.prototype.clear=function(){this.__data__=[]},kt.prototype.delete=function(t){var e=this.__data__,n=Ot(e,t);return!(n<0)&&(n==e.length-1?e.pop():gt.call(e,n,1),!0)},kt.prototype.get=function(t){var e=this.__data__,n=Ot(e,t);return n<0?void 0:e[n][1]},kt.prototype.has=function(t){return Ot(this.__data__,t)>-1},kt.prototype.set=function(t,e){var n=this.__data__,o=Ot(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},It.prototype.clear=function(){this.__data__={hash:new yt,map:new(vt||kt),string:new yt}},It.prototype.delete=function(t){return jt(this,t).delete(t)},It.prototype.get=function(t){return jt(this,t).get(t)},It.prototype.has=function(t){return jt(this,t).has(t)},It.prototype.set=function(t,e){return jt(this,t).set(t,e),this};var Et=At((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Rt(t))return wt?wt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return X.test(t)&&n.push(""),t.replace(Y,(function(t,e,o,i){n.push(o?i.replace(Q,"$1"):e||t)})),n}));function _t(t){if("string"==typeof t||Rt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function At(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(At.Cache||It),n}At.Cache=It;var Ut=Array.isArray;function Pt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Rt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==ht.call(t)}var Lt=function(t,e,n){var o=null==t?void 0:xt(t,e);return void 0===o?n:o},Tt="/v1/auth/accesskey/exchange",qt="/v1/auth/otp/verify",Mt="/v1/auth/otp/signin",Dt="/v1/auth/otp/signup",$t={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Nt="/v1/auth/otp/signup-in",Kt="/v1/auth/magiclink/verify",Jt="/v1/auth/magiclink/signin",Wt="/v1/auth/magiclink/signup",Ft={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Ht="/v1/auth/magiclink/signup-in",zt="/v1/auth/enchantedlink/verify",Bt="/v1/auth/enchantedlink/signin",Vt="/v1/auth/enchantedlink/signup",Zt="/v1/auth/enchantedlink/pending-session",Gt={email:"/v1/auth/enchantedlink/update/email"},Xt="/v1/auth/enchantedlink/signup-in",Yt="/v1/auth/oauth/authorize",Qt="/v1/auth/oauth/exchange",te="/v1/auth/saml/authorize",ee="/v1/auth/saml/exchange",ne="/v1/auth/totp/verify",oe="/v1/auth/totp/signup",ie="/v1/auth/totp/update",re={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},se={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ae={start:"/v1/auth/webauthn/signup-in/start"},le={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ce="/v1/auth/refresh",ue="/v1/auth/logout",de="/v1/auth/logoutall",he="/v1/auth/me",pe="/v1/flow/start",fe="/v1/flow/next";const ge=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var ve;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ve||(ve={}));const me=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),be=t=>void 0===t?void 0:JSON.stringify(t),we=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},ye=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r})=>{const s=((t,e)=>{const n=e||fetch;return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>ge().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),ge().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:t,queryParams:d}),{headers:me(we(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.55"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:be(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:ve.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ve.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ve.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ve.delete,token:i}),hooks:i}};var ke=429;function Ie(t,e,n){var o;let i=Oe(t);e&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[e]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function Oe(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return F(t)}function xe(t){const{exp:e}=Oe(t);return(new Date).getTime()/1e3>e}function Se(t,e){return Ie(t,e,"permissions")}function je(t,e){return Ie(t,e,"roles")}const Ce=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ee(t,e){var n;const o=await t,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=e?e(r):r:(i.error=r,o.status===ke&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const _e=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ae=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ue=t=>e=>t.test(e),Pe=Ue(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Re=Ue(/^\+[1-9]{1}[0-9]{3,14}$/),Le=_e(Pe,'"{val}" is not a valid email'),Te=_e(Re,'"{val}" is not a valid phone number'),qe=_e((1,t=>t.length>=1),"Minimum length is 1");const Me=_e((t=>"string"==typeof t),"Input is not a string"),De=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ae(...t).validate(n[e]))),e(...n)),$e=t=>[Me(`"${t}" must be a string`),qe(`"${t}" must not be empty`)],Ne=t=>[Me(`"${t}" must be a string`),Le()],Ke=t=>[Me(`"${t}" must be a string`),Te()],Je=De($e("accessKey")),We=t=>({exchange:Je((e=>Ee(t.post(Tt,{},{token:e}))))});var Fe,He,ze,Be;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Fe||(Fe={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(He||(He={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(ze||(ze={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Be||(Be={}));const Ve=$e("loginId"),Ze=$e("uri"),Ge=De($e("token")),Xe=De(Ve,Ze),Ye=De($e("pendingRef")),Qe=De(Ve,Ne("email"),Ze),tn=t=>({verify:Ge((e=>Ee(t.post(zt,{token:e})))),signIn:Xe(((e,n,o,i)=>Ee(t.post(Ce(Bt,He.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Xe(((e,n)=>Ee(t.post(Ce(Xt,He.email),{loginId:e,URI:n})))),signUp:Xe(((e,n,o)=>Ee(t.post(Ce(Vt,He.email),{loginId:e,URI:n,user:o})))),waitForSession:Ye(((e,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Zt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Ee(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Qe(((e,n,o,i)=>Ee(t.post(Gt.email,{loginId:e,email:n,URI:o},{token:i}))))}}),en=De($e("flowId")),nn=De($e("executionId"),$e("stepId"),$e("interactionId")),on=t=>({start:en(((e,n,o,i,r)=>Ee(t.post(pe,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:nn(((e,n,o,i)=>Ee(t.post(fe,{executionId:e,stepId:n,interactionId:o,input:i}))))}),rn=$e("loginId"),sn=$e("uri"),an=De($e("token")),ln=De(rn,sn),cn=De(rn,Ke("phone"),sn),un=De(rn,Ne("email"),sn),dn=t=>({verify:an((e=>Ee(t.post(Kt,{token:e})))),signIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,i,r)=>Ee(t.post(Ce(Jt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,i)=>Ee(t.post(Ce(Wt,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o)=>Ee(t.post(Ce(Ht,n),{loginId:e,URI:o}))))})),{}),update:{email:un(((e,n,o,i)=>Ee(t.post(Ft.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:cn(((e,o,i,r)=>Ee(t.post(Ce(Ft.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var hn;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin"}(hn||(hn={}));const pn=De($e("code")),fn=t=>({start:Object.keys(hn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(Yt,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Ee(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:pn((e=>Ee(t.post(Qt,{code:e}))))});var gn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(gn||(gn={}));const vn=$e("loginId"),mn=De(vn,$e("code")),bn=De(vn),wn=De(vn,Ke("phone")),yn=De(vn,Ne("email")),kn=t=>({verify:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o)=>Ee(t.post(Ce(qt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn(((e,o,i)=>Ee(t.post(Ce(Mt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn(((e,o)=>Ee(t.post(Ce(Dt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn((e=>Ee(t.post(Ce(Nt,n),{loginId:e}))))})),{}),update:{email:yn(((e,n,o)=>Ee(t.post($t.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o,i)=>Ee(t.post(Ce($t.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),In=De($e("tenant")),On=De($e("code")),xn=t=>({start:In((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(te,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Ee(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:On((e=>Ee(t.post(ee,{code:e}))))}),Sn=$e("loginId"),jn=De(Sn,$e("code")),Cn=De(Sn),En=De(Sn),_n=t=>({signUp:Cn(((e,n)=>Ee(t.post(oe,{loginId:e,user:n})))),verify:jn(((e,n,o,i)=>Ee(t.post(ne,{loginId:e,code:n,loginOptions:o},{token:i})))),update:En(((e,n)=>Ee(t.post(ie,{loginId:e},{token:n}))))}),An=[Me('"loginId" must be a string')],Un=$e("loginId"),Pn=$e("origin"),Rn=De(Un,Pn,$e("name")),Ln=De(Un,Pn),Tn=De(An,Pn),qn=De(Un,Pn,$e("token")),Mn=De($e("transactionId"),$e("response")),Dn=t=>({signUp:{start:Rn(((e,n,o)=>Ee(t.post(re.start,{user:{loginId:e,name:o},origin:n})))),finish:Mn(((e,n)=>Ee(t.post(re.finish,{transactionId:e,response:n}))))},signIn:{start:Tn(((e,n,o,i)=>Ee(t.post(se.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Mn(((e,n)=>Ee(t.post(se.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Ln(((e,n)=>Ee(t.post(ae.start,{loginId:e,origin:n}))))},update:{start:qn(((e,n,o)=>Ee(t.post(le.start,{loginId:e,origin:n},{token:o})))),finish:Mn(((e,n)=>Ee(t.post(le.finish,{transactionId:e,response:n}))))}}),$n=De($e("token"));var Nn,Kn=De([("projectId",Nn=$e("projectId"),_e(((t,e)=>n=>Ae(...e).validate(Lt(n,t)))("projectId",Nn))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),i=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={}})=>{return s=ye({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r}}),{accessKey:We(s),otp:kn(s),magicLink:dn(s),enchantedLink:tn(s),oauth:fn(s),saml:xn(s),totp:_n(s),webauthn:Dn(s),flow:on(s),refresh:t=>Ee(s.post(ce,{},{token:t})),logout:t=>Ee(s.post(ue,{},{token:t})),logoutAll:t=>Ee(s.post(de,{},{token:t})),me:t=>Ee(s.get(he,{token:t})),isJwtExpired:$n(xe),getJwtPermissions:$n(Se),getJwtRoles:$n(je),httpClient:s};var s})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))}));const Jn=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let i=o.shift(),r=t;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${e}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${e}" is not a function`);const s=r[i];r[i]=n(s)})),t);var Wn=Object.assign(Kn,{DeliveryMethods:He});function Fn(t,e){var n=[];return function(t,e){var n,o,i=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),i=0;for(e=0;e<n;e++)for(var r=arguments[e],s=0,a=r.length;s<a;s++,i++)o[i]=r[s];return o}(t),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?i.postpone():i.exclude();var e,o=i.current();if(void 0===o)throw t;return(e=r(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(t,(function(t){var o=new Date,i=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},r=e(t);return r.then(i,i),r})).then((function(t){return[t,{attempts:n}]}))}var Hn="Failed to load the JS script of the agent";function zn(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Fn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(l,s),Bn).catch(Zn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Bn(t){return function(t,e,n,o){var i,r=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),o=e.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=e,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return l(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(l(),i)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),i=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),e()},o.onerror=function(){i(),n(new Error(Hn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(Vn)}function Vn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function Zn(t){throw t instanceof Error&&"9319"===t.message?new Error(Hn):t}
|
|
2
|
-
/*! js-cookie v3.0.1 | MIT */function Gn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Xn=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=Gn({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+r}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",Gn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Gn({},this.attributes,e))},withConverter:function(e){return t(Gn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Yn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Qn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},to=async t=>{const e=await Qn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},eo="undefined"!=typeof localStorage,no=(t,e)=>eo&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),oo=t=>eo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),io=t=>eo&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),ro="undefined"!=typeof window,so=ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",ao=(t="",e="")=>({vsid:t,vrid:e}),lo=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},co=t=>(t.body&&(t.body.fpData=lo(!0)||ao()),t),uo=()=>oo("dls_last_user_login_id"),ho=()=>oo("dls_last_user_display_name"),po=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=uo(),r=ho();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},fo=t=>async(...e)=>{const n=await t(...e);return io("dls_last_user_login_id"),io("dls_last_user_display_name"),n};function go(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const vo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&no("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);Xn.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):no("DS",i))};function mo(){return oo("DSR")||""}function bo(){return Xn.get("DS")||oo("DS")||""}function wo(){io("DSR"),io("DS"),Xn.remove("DS")}const yo=t=>Object.assign(t,{token:t.token||mo()}),ko=t=>async(...e)=>{const n=await t(...e);return wo(),n};async function Io(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Eo(n.publicKey.challenge),n.publicKey.user.id=Eo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Eo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:_o(n.rawId),type:n.type,response:{attestationObject:_o(n.response.attestationObject),clientDataJSON:_o(n.response.clientDataJSON)}});var n}async function Oo(t){const e=jo(t);return Co(await navigator.credentials.get(e))}async function xo(t,e){const n=jo(t);return n.signal=e.signal,n.mediation="conditional",Co(await navigator.credentials.get(n))}async function So(t=!1){if(!ro)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function jo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Eo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Eo(t.id)})),n}function Co(t){return JSON.stringify({id:t.id,rawId:_o(t.rawId),type:t.type,response:{authenticatorData:_o(t.response.authenticatorData),clientDataJSON:_o(t.response.clientDataJSON),signature:_o(t.response.signature),userHandle:t.response.userHandle?_o(t.response.userHandle):void 0}})}function Eo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function _o(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ao,Uo=(Ao=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await Io(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await Oo(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await Io(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Oo(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const i=await Io(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Io,get:Oo,isSupported:So,conditional:xo}}),(...t)=>{const e=Ao(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),Po=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await So(),o=Object.assign(Object.assign({},e[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Ro=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return o?(ro?i&&(async t=>{try{if(lo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=zn({apiKey:t,endpoint:so}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(ao(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(Yn(r,{beforeRequest:co}))):t(Object.assign({},r))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:i,setTimer:r}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(Yn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Qn(e);if(401===(null==e?void 0:e.status))i();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;i(),r((()=>s.refresh(n)),t)}var a}}));return Jn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return i(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.1-alpha.0"},e.baseHeaders)}))),(t=>e=>{const n=go(),o=go(),i=t(Yn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await to(e);t&&o.pub(t);const{sessionJwt:i}=await Qn(e);i&&n.pub(i)}}})),r=Jn(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Yn(e,{afterRequest:async(t,e)=>{var n;const o=await to(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{no("dls_last_user_login_id",t)})(i),(t=>{no("dls_last_user_display_name",t)})(r))}}));let o=Jn(n,["flow.start"],po);return o=Jn(o,["logout","logoutAll"],fo),Object.assign(o,{getLastUserLoginId:uo,getLastUserDisplayName:ho})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!ro)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(r);const s=t(Yn(r,{beforeRequest:yo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?wo():vo(await Qn(e),i)}})),a=Jn(s,["logout","logoutAll"],ko);return Object.assign(a,{getRefreshToken:mo,getSessionToken:bo})}))(((...t)=>{const e=Wn(...t);return Object.assign(Object.assign({},e),{flow:Po(e),webauthn:Uo(e)})})),Lo=document.createElement("template");var To,qo,Mo,Do,$o,No,Ko,Jo,Wo,Fo,Ho,zo,Bo,Vo,Zo,Go,Xo,Yo,Qo,ti,ei,ni,oi,ii,ri,si,ai,li,ci,ui,di,hi,pi,fi,gi,vi,mi,bi,wi,yi,ki,Ii,Oi,xi,Si,ji,Ci,Ei;Lo.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class _i extends HTMLElement{constructor(t){super(),To.add(this),qo.set(this,!1),Mo.set(this,new R),Do.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),$o.set(this,void 0),No.set(this,{popstate:o(this,To,"m",zo).bind(this)}),Ko.set(this,void 0),Zo.set(this,C((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield y(t,"json")}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,To,"m",ni).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,Ko,t,"f"),o(this,To,"m",Jo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey"]}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,Zo,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,To,"m",Wo).call(this))return void o(this,To,"m",Fo).call(this);o(this,To,"m",Ho).call(this),o(this,To,"m",Xo).call(this),o(this,To,"m",Go).call(this),o(this,To,"m",oi).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=j();window.addEventListener("popstate",o(this,No,"f").popstate),o(this,Mo,"f").subscribe(o(this,To,"m",Vo).bind(this)),o(this,Do,"f").subscribe(o(this,To,"m",ei).bind(this)),o(this,Mo,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,stepId:e,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey}),o(this,Do,"f").update({isDebug:this.debug}),i(this,qo,!0,"f")}}))}disconnectedCallback(){o(this,Mo,"f").unsubscribeAll(),o(this,Do,"f").unsubscribeAll(),o(this,To,"m",ti).call(this),window.removeEventListener("popstate",o(this,No,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,qo,"f")&&e!==n&&_i.observedAttributes.includes(t)){o(this,To,"m",Ho).call(this);const i=null===e;o(this,Mo,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,x()),{[S(t)]:n,stepId:r,executionId:s}})),o(this,Do,"f").update({isDebug:this.debug})}}}qo=new WeakMap,Mo=new WeakMap,Do=new WeakMap,$o=new WeakMap,No=new WeakMap,Ko=new WeakMap,Zo=new WeakMap,To=new WeakSet,Jo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Lo.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Wo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Fo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Ho=function(){const t=["base-url","tenant","theme","debug","telemetryKey"];if(_i.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[S(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},zo=function(){const{stepId:t,executionId:e}=O();o(this,Mo,"f").update({stepId:t,executionId:e})},Bo=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=Ro(Object.assign(Object.assign({},_i.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r,persistTokens:!0})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Vo=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:r}=t;if(i("projectId")||i("baseUrl")||i("telemetryKey")){if(!e)return;o(this,To,"m",Bo).call(this,e,n,r)}o(this,Ko,"f").call(this,t)}))},Go=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const n=yield o(this,Zo,"f").call(this);null===(r=null===(i=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===i?void 0:i.fontFamilies)||void 0===r||r.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Xo=function(){o(this,To,"m",Yo).call(this),o(this,To,"m",Qo).call(this)},Yo=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield y(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Qo=function(){this.rootElement.setAttribute("data-theme",this.theme)},ti=function(){var t;null===(t=o(this,$o,"f"))||void 0===t||t.remove(),i(this,$o,null,"f")},ei=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return Ri})),i(this,$o,document.createElement("descope-debugger"),"f"),Object.assign(o(this,$o,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,$o,"f"))):o(this,To,"m",ti).call(this)}))},ni=function(t,e){var n;t&&this.debug&&(null===(n=o(this,$o,"f"))||void 0===n||n.updateData({title:t,description:e}))},oi=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const n=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===n.length&&n[0].click()}},_i.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.0"}};class Ai extends _i{constructor(){const t=new R;super(t.update.bind(t)),ii.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),ri.set(this,void 0),si.set(this,null),ai.set(this,(()=>{clearInterval(o(this,ri,"f")),i(this,ri,null,"f")})),li.set(this,(t=>{var e,n,i,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,ai,"f").call(this),o(this,ii,"m",bi).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:g,authInfo:v,lastAuth:m}=t.data;if("completed"===g)return function(t){r&&localStorage.setItem(c,JSON.stringify(t))}(m),o(this,ai,"f").call(this),void o(this,ii,"m",bi).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:O}=t.data;y!==h?this.flowState.update({stepId:w,executionId:b,action:y,redirectUrl:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:y})})),ci.set(this,C((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.logger.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.logger.error("Webauthn start failed",t.message)}}))))),this.flowState=t}static set sdkConfigOverrides(t){_i.sdkConfigOverrides=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(t,e,r){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:u,stepId:m,executionId:b,action:w,screenId:y,screenState:O,redirectUrl:x,token:S,code:j,exchangeError:C,webauthnTransactionId:E,webauthnOptions:_}=t;let A,U;o(this,ri,"f")&&o(this,ai,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!b){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:A=t.startScreenId,conditionInteractionId:U}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,P)),!A){const t=yield this.sdk.flow.start(l,{tenant:u});return void o(this,li,"f").call(this,t)}}if(r("token")&&S||r("code")&&j||r("exchangeError")&&C){const t=yield this.sdk.flow.next(b,m,g,{token:S,exchangeCode:j,exchangeError:C});return o(this,li,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(w===d)return x||this.logger.error("Did not get redirect url"),void window.location.assign(x);if(w===p||w===f){if(!E||!_)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,si,"f"))||void 0===s||s.abort(),i(this,si,null,"f");try{t=w===p?yield T(_):yield q(_)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(b,m,g,{transactionId:E,response:t,cancelWebauthn:e});o(this,li,"f").call(this,n)}if(w===h&&i(this,ri,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(b,m,v,{});o(this,li,"f").call(this,t)}))),2e3),"f"),!y&&!A)return void this.logger.info("Refreshing the page during a flow is not supported yet");const R={direction:I(+m,+e.stepId),screenState:Object.assign(Object.assign({},O),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:k(a,`${A||y}.html`)},L=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(P);A?R.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:L},U,...t):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(R.next=(...t)=>this.sdk.flow.next(b,m,...t)),this.stepState.update(R)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:i,direction:r,next:s,screenState:a}=t,l=document.createElement("template");l.innerHTML=yield y(i,"text");const c=l.content.cloneNode(!0),d=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),i=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,r=Function(i).bind(e.previousSibling);return e.remove(),r}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c);this.sdk.webauthn.helpers.isSupported()?yield o(this,ii,"m",di).call(this,c,s):c.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(c,a),((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(e=null==a?void 0:a.totp)||void 0===e?void 0:e.image);const h=()=>n(this,void 0,void 0,(function*(){try{d.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])');null==t||t.focus({preventScroll:!0}),o(this,ii,"m",vi).call(this,s),o(this,ii,"m",bi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield s(v,{});o(this,li,"f").call(this,t)}}));r?o(this,ii,"m",mi).call(this,h,r):h()}))}}ri=new WeakMap,si=new WeakMap,ai=new WeakMap,li=new WeakMap,ci=new WeakMap,ii=new WeakSet,ui=function(t){const e=t.name;if(!["email"].includes(e)){const n=`user-${e}`;t.name=n,t.addEventListener("input",(()=>{t.name=t.value?e:n}))}},di=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,si,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield $())){const{options:t,transactionId:r}=(yield o(this,ci,"f").call(this))||{};t&&r&&(o(this,ii,"m",ui).call(this,s),i(this,si,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,si,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,li,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},hi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},pi=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},fi=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,i;n?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(i=null==t?void 0:t.classList)||void 0===i||i.remove("loading"))}))},gi=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,ii,"m",hi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,ii,"m",fi).call(this,t);const r=o(this,ii,"m",pi).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),l=yield e(i,a);o(this,li,"f").call(this,l)}var n}))},vi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,ii,"m",gi).call(this,e,t)}}))},mi=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===w.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},bi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Ai);const Ui=document.createElement("template");Ui.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class Pi extends HTMLElement{constructor(){super(),wi.add(this),yi.set(this,new R({messages:[]})),ki.set(this,void 0),Ii.set(this,void 0),Oi.set(this,void 0),xi.set(this,{resize:o(this,wi,"m",Ei).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ui.content.cloneNode(!0)),i(this,ki,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ii,o(this,ki,"f").querySelector(".content"),"f"),i(this,Oi,o(this,ki,"f").querySelector(".header"),"f")}updateData(t){o(this,yi,"f").update((e=>({messages:e.messages.concat(t)})))}connectedCallback(){var t;((t,e,n)=>{let o=0,i=0,r=0,s=0;function a(e){e.preventDefault(),o=r-e.clientX,i=s-e.clientY,r=e.clientX,s=e.clientY;const[a,l]=N(t,t.offsetLeft-o,t.offsetTop-i,n);t.style.top=`${l}px`,t.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(t){t.preventDefault(),r=t.clientX,s=t.clientY,document.onmouseup=l,document.onmousemove=a}e?e.onmousedown=c:t.onmousedown=c})(o(this,ki,"f"),o(this,Oi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,xi,"f").resize),(t=o(this,ki,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&t.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},o(this,ki,"f").onresize=o(this,wi,"m",Ci).bind(this),o(this,yi,"f").subscribe(o(this,wi,"m",Si).bind(this))}disconnectedCallback(){o(this,yi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,xi,"f").resize)}}yi=new WeakMap,ki=new WeakMap,Ii=new WeakMap,Oi=new WeakMap,xi=new WeakMap,wi=new WeakSet,Si=function(t){o(this,wi,"m",ji).call(this,t),o(this,wi,"m",Ci).call(this)},ji=function(t){o(this,Ii,"f").innerHTML=t.messages.map((t=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.title}\n </div>\n <div class="msg_desc">\n ${t.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},Ci=function(){o(this,Ii,"f").querySelectorAll(".msg").forEach((t=>{const e=t.querySelector(".msg_desc"),n=e.scrollWidth>e.clientWidth,o=e.clientHeight>20;n||o?(t.classList.add("collapsible"),t.onclick=e=>{e.target.classList.contains("msg_desc")||t.classList.toggle("collapsed")}):(t.classList.remove("collapsible"),t.onclick=null)}))},Ei=function(){const[t,e]=N(o(this,ki,"f"),Number.parseInt(o(this,ki,"f").style.left,10),Number.parseInt(o(this,ki,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,ki,"f").style.top=`${e}px`,o(this,ki,"f").style.left=`${t}px`},customElements.define("descope-debugger",Pi);var Ri=Object.freeze({__proto__:null,default:Pi})}();
|
|
1
|
+
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";function m(t){return new URLSearchParams(window.location.search).get(t)}function b(t){if(window.history.replaceState&&m(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var w;function y(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(w||(w={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?w.forward:t<e?w.backward:void 0}const O=()=>{const[t="",e=""]=(m(a)||"").split("_");return{executionId:t,stepId:e}};function x(){b(a)}const S=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),j=()=>{const{executionId:t,stepId:e}=O();(t||e)&&x();const n=m("t")||void 0;n&&b("t");const o=m(l)||void 0;o&&b(l);const i=m("err")||void 0;return i&&b("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},C=t=>{let e,n;return(...o)=>{return e&&(r=o,(i=e).length===r.length&&i.every(((t,e)=>t===r[e])))||(e=o,n=t(...o)),n;var i,r}};var E,_,A,U;function P(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if("object"==typeof r&&"object"==typeof s){if(!P(r,s))return!1}else if(r!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){E.set(this,void 0),_.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,E,"f")):t,n=Object.assign(Object.assign({},o(this,E,"f")),e);if(!o(this,U,"f")||!P(o(this,E,"f"),n)){const t=o(this,E,"f");i(this,E,n,"f"),Object.freeze(o(this,E,"f")),setTimeout((()=>{Object.values(o(this,_,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,E,t,"f"),i(this,U,e,"f")}get current(){return Object.assign({},o(this,E,"f"))}subscribe(t){return i(this,A,o(this,A,"f")+1,"f"),o(this,_,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,_,"f")[t];return e&&delete o(this,_,"f")[t],e}unsubscribeAll(){return i(this,_,{},"f"),!0}}E=new WeakMap,_=new WeakMap,A=new WeakMap,U=new WeakMap;const L=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${u}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)};function T(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),n.publicKey.user.id=M(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:D(o.rawId),type:o.type,response:{attestationObject:D(o.response.attestationObject),clientDataJSON:D(o.response.clientDataJSON)}});var o}))}function q(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:D(o.rawId),type:o.type,response:{authenticatorData:D(o.response.authenticatorData),clientDataJSON:D(o.response.clientDataJSON),signature:D(o.response.signature),userHandle:D(o.response.userHandle)}});var o}))}function M(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function D(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const $=C((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),N=(t,e,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(e,("all"===o.left?t.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-t.offsetWidth),window.innerWidth-("all"===o.right?t.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?t.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-t.offsetHeight),window.innerHeight-("all"===o.bottom?t.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]};function K(t){this.message=t}K.prototype=new Error,K.prototype.name="InvalidCharacterError";var J="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new K("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,r=0,s="";o=e.charAt(r++);~o&&(n=i%4?64*n+o:o,i++%4)?s+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function W(t){this.message=t}function F(t,e){if("string"!=typeof t)throw new W("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(J(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return J(e)}}(t.split(".")[n]))}catch(t){throw new W("Invalid token specified: "+t.message)}}W.prototype=new Error,W.prototype.name="InvalidTokenError";var H="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},z="__lodash_hash_undefined__",B="[object Function]",V="[object GeneratorFunction]",Z=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,G=/^\w*$/,X=/^\./,Y=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Q=/\\(\\)?/g,tt=/^\[object .+?Constructor\]$/,et="object"==typeof H&&H&&H.Object===Object&&H,nt="object"==typeof self&&self&&self.Object===Object&&self,ot=et||nt||Function("return this")();var it,rt=Array.prototype,st=Function.prototype,at=Object.prototype,lt=ot["__core-js_shared__"],ct=(it=/[^.]+$/.exec(lt&<.keys&<.keys.IE_PROTO||""))?"Symbol(src)_1."+it:"",ut=st.toString,dt=at.hasOwnProperty,ht=at.toString,pt=RegExp("^"+ut.call(dt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ft=ot.Symbol,gt=rt.splice,vt=Ct(ot,"Map"),mt=Ct(Object,"create"),bt=ft?ft.prototype:void 0,wt=bt?bt.toString:void 0;function yt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function kt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function It(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function Ot(t,e){for(var n,o,i=t.length;i--;)if((n=t[i][0])===(o=e)||n!=n&&o!=o)return i;return-1}function xt(t,e){var n;e=function(t,e){if(Ut(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Rt(t))return!0;return G.test(t)||!Z.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ut(n=e)?n:Et(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[_t(e[o++])];return o&&o==i?t:void 0}function St(t){if(!Pt(t)||(e=t,ct&&ct in e))return!1;var e,n=function(t){var e=Pt(t)?ht.call(t):"";return e==B||e==V}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?pt:tt;return n.test(function(t){if(null!=t){try{return ut.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function jt(t,e){var n,o,i=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function Ct(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return St(n)?n:void 0}yt.prototype.clear=function(){this.__data__=mt?mt(null):{}},yt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},yt.prototype.get=function(t){var e=this.__data__;if(mt){var n=e[t];return n===z?void 0:n}return dt.call(e,t)?e[t]:void 0},yt.prototype.has=function(t){var e=this.__data__;return mt?void 0!==e[t]:dt.call(e,t)},yt.prototype.set=function(t,e){return this.__data__[t]=mt&&void 0===e?z:e,this},kt.prototype.clear=function(){this.__data__=[]},kt.prototype.delete=function(t){var e=this.__data__,n=Ot(e,t);return!(n<0)&&(n==e.length-1?e.pop():gt.call(e,n,1),!0)},kt.prototype.get=function(t){var e=this.__data__,n=Ot(e,t);return n<0?void 0:e[n][1]},kt.prototype.has=function(t){return Ot(this.__data__,t)>-1},kt.prototype.set=function(t,e){var n=this.__data__,o=Ot(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},It.prototype.clear=function(){this.__data__={hash:new yt,map:new(vt||kt),string:new yt}},It.prototype.delete=function(t){return jt(this,t).delete(t)},It.prototype.get=function(t){return jt(this,t).get(t)},It.prototype.has=function(t){return jt(this,t).has(t)},It.prototype.set=function(t,e){return jt(this,t).set(t,e),this};var Et=At((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Rt(t))return wt?wt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return X.test(t)&&n.push(""),t.replace(Y,(function(t,e,o,i){n.push(o?i.replace(Q,"$1"):e||t)})),n}));function _t(t){if("string"==typeof t||Rt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function At(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(At.Cache||It),n}At.Cache=It;var Ut=Array.isArray;function Pt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Rt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==ht.call(t)}var Lt=function(t,e,n){var o=null==t?void 0:xt(t,e);return void 0===o?n:o},Tt="/v1/auth/accesskey/exchange",qt="/v1/auth/otp/verify",Mt="/v1/auth/otp/signin",Dt="/v1/auth/otp/signup",$t={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Nt="/v1/auth/otp/signup-in",Kt="/v1/auth/magiclink/verify",Jt="/v1/auth/magiclink/signin",Wt="/v1/auth/magiclink/signup",Ft={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Ht="/v1/auth/magiclink/signup-in",zt="/v1/auth/enchantedlink/verify",Bt="/v1/auth/enchantedlink/signin",Vt="/v1/auth/enchantedlink/signup",Zt="/v1/auth/enchantedlink/pending-session",Gt={email:"/v1/auth/enchantedlink/update/email"},Xt="/v1/auth/enchantedlink/signup-in",Yt="/v1/auth/oauth/authorize",Qt="/v1/auth/oauth/exchange",te="/v1/auth/saml/authorize",ee="/v1/auth/saml/exchange",ne="/v1/auth/totp/verify",oe="/v1/auth/totp/signup",ie="/v1/auth/totp/update",re={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},se={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ae={start:"/v1/auth/webauthn/signup-in/start"},le={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ce="/v1/auth/refresh",ue="/v1/auth/logout",de="/v1/auth/logoutall",he="/v1/auth/me",pe="/v1/flow/start",fe="/v1/flow/next";const ge=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var ve;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ve||(ve={}));const me=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),be=t=>void 0===t?void 0:JSON.stringify(t),we=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},ye=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r})=>{const s=((t,e)=>{const n=e||fetch;return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>ge().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),ge().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:t,queryParams:d}),{headers:me(we(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.56"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:be(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:ve.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ve.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ve.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ve.delete,token:i}),hooks:i}};var ke=429;function Ie(t,e,n){var o;let i=Oe(t);e&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[e]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function Oe(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return F(t)}function xe(t){const{exp:e}=Oe(t);return(new Date).getTime()/1e3>e}function Se(t,e){return Ie(t,e,"permissions")}function je(t,e){return Ie(t,e,"roles")}const Ce=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ee(t,e){var n;const o=await t,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=e?e(r):r:(i.error=r,o.status===ke&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const _e=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ae=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ue=t=>e=>t.test(e),Pe=Ue(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Re=Ue(/^\+[1-9]{1}[0-9]{3,14}$/),Le=_e(Pe,'"{val}" is not a valid email'),Te=_e(Re,'"{val}" is not a valid phone number'),qe=_e((1,t=>t.length>=1),"Minimum length is 1");const Me=_e((t=>"string"==typeof t),"Input is not a string"),De=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ae(...t).validate(n[e]))),e(...n)),$e=t=>[Me(`"${t}" must be a string`),qe(`"${t}" must not be empty`)],Ne=t=>[Me(`"${t}" must be a string`),Le()],Ke=t=>[Me(`"${t}" must be a string`),Te()],Je=De($e("accessKey")),We=t=>({exchange:Je((e=>Ee(t.post(Tt,{},{token:e}))))});var Fe,He,ze,Be;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Fe||(Fe={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(He||(He={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(ze||(ze={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Be||(Be={}));const Ve=$e("loginId"),Ze=De($e("token")),Ge=De(Ve),Xe=De($e("pendingRef")),Ye=De(Ve,Ne("email")),Qe=t=>({verify:Ze((e=>Ee(t.post(zt,{token:e})))),signIn:Ge(((e,n,o,i)=>Ee(t.post(Ce(Bt,He.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Ge(((e,n)=>Ee(t.post(Ce(Xt,He.email),{loginId:e,URI:n})))),signUp:Ge(((e,n,o)=>Ee(t.post(Ce(Vt,He.email),{loginId:e,URI:n,user:o})))),waitForSession:Xe(((e,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Zt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Ee(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Ye(((e,n,o,i)=>Ee(t.post(Gt.email,{loginId:e,email:n,URI:o},{token:i}))))}}),tn=De($e("flowId")),en=De($e("executionId"),$e("stepId"),$e("interactionId")),nn=t=>({start:tn(((e,n,o,i,r)=>Ee(t.post(pe,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:en(((e,n,o,i)=>Ee(t.post(fe,{executionId:e,stepId:n,interactionId:o,input:i}))))}),on=$e("loginId"),rn=De($e("token")),sn=De(on),an=De(on,Ke("phone")),ln=De(on,Ne("email")),cn=t=>({verify:rn((e=>Ee(t.post(Kt,{token:e})))),signIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:sn(((e,o,i,r)=>Ee(t.post(Ce(Jt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:sn(((e,o,i)=>Ee(t.post(Ce(Wt,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:sn(((e,o)=>Ee(t.post(Ce(Ht,n),{loginId:e,URI:o}))))})),{}),update:{email:ln(((e,n,o,i)=>Ee(t.post(Ft.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:an(((e,o,i,r)=>Ee(t.post(Ce(Ft.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var un;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin"}(un||(un={}));const dn=De($e("code")),hn=t=>({start:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(Yt,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Ee(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:dn((e=>Ee(t.post(Qt,{code:e}))))});var pn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(pn||(pn={}));const fn=$e("loginId"),gn=De(fn,$e("code")),vn=De(fn),mn=De(fn,Ke("phone")),bn=De(fn,Ne("email")),wn=t=>({verify:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:gn(((e,o)=>Ee(t.post(Ce(qt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:vn(((e,o,i)=>Ee(t.post(Ce(Mt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:vn(((e,o)=>Ee(t.post(Ce(Dt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(He).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:vn((e=>Ee(t.post(Ce(Nt,n),{loginId:e}))))})),{}),update:{email:bn(((e,n,o)=>Ee(t.post($t.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o,i)=>Ee(t.post(Ce($t.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),yn=De($e("tenant")),kn=De($e("code")),In=t=>({start:yn((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(te,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Ee(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:kn((e=>Ee(t.post(ee,{code:e}))))}),On=$e("loginId"),xn=De(On,$e("code")),Sn=De(On),jn=De(On),Cn=t=>({signUp:Sn(((e,n)=>Ee(t.post(oe,{loginId:e,user:n})))),verify:xn(((e,n,o,i)=>Ee(t.post(ne,{loginId:e,code:n,loginOptions:o},{token:i})))),update:jn(((e,n)=>Ee(t.post(ie,{loginId:e},{token:n}))))}),En=[Me('"loginId" must be a string')],_n=$e("loginId"),An=$e("origin"),Un=De(_n,An,$e("name")),Pn=De(_n,An),Rn=De(En,An),Ln=De(_n,An,$e("token")),Tn=De($e("transactionId"),$e("response")),qn=t=>({signUp:{start:Un(((e,n,o)=>Ee(t.post(re.start,{user:{loginId:e,name:o},origin:n})))),finish:Tn(((e,n)=>Ee(t.post(re.finish,{transactionId:e,response:n}))))},signIn:{start:Rn(((e,n,o,i)=>Ee(t.post(se.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Tn(((e,n)=>Ee(t.post(se.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Pn(((e,n)=>Ee(t.post(ae.start,{loginId:e,origin:n}))))},update:{start:Ln(((e,n,o)=>Ee(t.post(le.start,{loginId:e,origin:n},{token:o})))),finish:Tn(((e,n)=>Ee(t.post(le.finish,{transactionId:e,response:n}))))}}),Mn=De($e("token"));var Dn,$n=De([("projectId",Dn=$e("projectId"),_e(((t,e)=>n=>Ae(...e).validate(Lt(n,t)))("projectId",Dn))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),i=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={}})=>{return s=ye({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r}}),{accessKey:We(s),otp:wn(s),magicLink:cn(s),enchantedLink:Qe(s),oauth:hn(s),saml:In(s),totp:Cn(s),webauthn:qn(s),flow:nn(s),refresh:t=>Ee(s.post(ce,{},{token:t})),logout:t=>Ee(s.post(ue,{},{token:t})),logoutAll:t=>Ee(s.post(de,{},{token:t})),me:t=>Ee(s.get(he,{token:t})),isJwtExpired:Mn(xe),getJwtPermissions:Mn(Se),getJwtRoles:Mn(je),httpClient:s};var s})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))}));const Nn=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let i=o.shift(),r=t;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${e}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${e}" is not a function`);const s=r[i];r[i]=n(s)})),t);var Kn=Object.assign($n,{DeliveryMethods:He});function Jn(t,e){var n=[];return function(t,e){var n,o,i=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),i=0;for(e=0;e<n;e++)for(var r=arguments[e],s=0,a=r.length;s<a;s++,i++)o[i]=r[s];return o}(t),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?i.postpone():i.exclude();var e,o=i.current();if(void 0===o)throw t;return(e=r(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(t,(function(t){var o=new Date,i=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},r=e(t);return r.then(i,i),r})).then((function(t){return[t,{attempts:n}]}))}var Wn="Failed to load the JS script of the agent";function Fn(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Jn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(l,s),Hn).catch(Bn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Hn(t){return function(t,e,n,o){var i,r=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),o=e.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=e,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return l(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(l(),i)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),i=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),e()},o.onerror=function(){i(),n(new Error(Wn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(zn)}function zn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function Bn(t){throw t instanceof Error&&"9319"===t.message?new Error(Wn):t}
|
|
2
|
+
/*! js-cookie v3.0.1 | MIT */function Vn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Zn=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=Vn({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+r}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",Vn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Vn({},this.attributes,e))},withConverter:function(e){return t(Vn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Gn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Xn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Yn=async t=>{const e=await Xn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Qn="undefined"!=typeof localStorage,to=(t,e)=>Qn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),eo=t=>Qn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),no=t=>Qn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),oo="undefined"!=typeof window,io=oo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",ro=(t="",e="")=>({vsid:t,vrid:e}),so=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},ao=t=>(t.body&&(t.body.fpData=so(!0)||ro()),t),lo=()=>eo("dls_last_user_login_id"),co=()=>eo("dls_last_user_display_name"),uo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=lo(),r=co();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},ho=t=>async(...e)=>{const n=await t(...e);return no("dls_last_user_login_id"),no("dls_last_user_display_name"),n};function po(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const fo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&to("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);Zn.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):to("DS",i))};function go(){return eo("DSR")||""}function vo(){return Zn.get("DS")||eo("DS")||""}function mo(){no("DSR"),no("DS"),Zn.remove("DS")}const bo=t=>Object.assign(t,{token:t.token||go()}),wo=t=>async(...e)=>{const n=await t(...e);return mo(),n};async function yo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=jo(n.publicKey.challenge),n.publicKey.user.id=jo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=jo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Co(n.rawId),type:n.type,response:{attestationObject:Co(n.response.attestationObject),clientDataJSON:Co(n.response.clientDataJSON)}});var n}async function ko(t){const e=xo(t);return So(await navigator.credentials.get(e))}async function Io(t,e){const n=xo(t);return n.signal=e.signal,n.mediation="conditional",So(await navigator.credentials.get(n))}async function Oo(t=!1){if(!oo)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function xo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=jo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=jo(t.id)})),n}function So(t){return JSON.stringify({id:t.id,rawId:Co(t.rawId),type:t.type,response:{authenticatorData:Co(t.response.authenticatorData),clientDataJSON:Co(t.response.clientDataJSON),signature:Co(t.response.signature),userHandle:t.response.userHandle?Co(t.response.userHandle):void 0}})}function jo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Co(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Eo,_o=(Eo=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await yo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await ko(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await yo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await ko(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const i=await yo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:yo,get:ko,isSupported:Oo,conditional:Io}}),(...t)=>{const e=Eo(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),Ao=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Oo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Uo=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return o?(oo?i&&(async t=>{try{if(so())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Fn({apiKey:t,endpoint:io}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(ro(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(Gn(r,{beforeRequest:ao}))):t(Object.assign({},r))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:i,setTimer:r}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(Gn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Xn(e);if(401===(null==e?void 0:e.status))i();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;i(),r((()=>s.refresh(n)),t)}var a}}));return Nn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return i(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.2"},e.baseHeaders)}))),(t=>e=>{const n=po(),o=po(),i=t(Gn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Yn(e);t&&o.pub(t);const{sessionJwt:i}=await Xn(e);i&&n.pub(i)}}})),r=Nn(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Gn(e,{afterRequest:async(t,e)=>{var n;const o=await Yn(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{to("dls_last_user_login_id",t)})(i),(t=>{to("dls_last_user_display_name",t)})(r))}}));let o=Nn(n,["flow.start"],uo);return o=Nn(o,["logout","logoutAll"],ho),Object.assign(o,{getLastUserLoginId:lo,getLastUserDisplayName:co})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!oo)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(r);const s=t(Gn(r,{beforeRequest:bo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?mo():fo(await Xn(e),i)}})),a=Nn(s,["logout","logoutAll"],wo);return Object.assign(a,{getRefreshToken:go,getSessionToken:vo})}))(((...t)=>{const e=Kn(...t);return Object.assign(Object.assign({},e),{flow:Ao(e),webauthn:_o(e)})})),Po=document.createElement("template");var Ro,Lo,To,qo,Mo,Do,$o,No,Ko,Jo,Wo,Fo,Ho,zo,Bo,Vo,Zo,Go,Xo,Yo,Qo,ti,ei,ni,oi,ii,ri,si,ai,li,ci,ui,di,hi,pi,fi,gi,vi,mi,bi,wi,yi,ki,Ii,Oi,xi,Si,ji;Po.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class Ci extends HTMLElement{constructor(t){super(),Ro.add(this),Lo.set(this,!1),To.set(this,new R),qo.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),Mo.set(this,void 0),Do.set(this,{popstate:o(this,Ro,"m",Fo).bind(this)}),$o.set(this,void 0),Bo.set(this,C((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield y(t,"json")}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,Ro,"m",ti).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,$o,t,"f"),o(this,Ro,"m",No).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url"]}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,Bo,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,Ro,"m",Ko).call(this))return void o(this,Ro,"m",Jo).call(this);o(this,Ro,"m",Wo).call(this),o(this,Ro,"m",Zo).call(this),o(this,Ro,"m",Vo).call(this),o(this,Ro,"m",ei).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=j();window.addEventListener("popstate",o(this,Do,"f").popstate),o(this,To,"f").subscribe(o(this,Ro,"m",zo).bind(this)),o(this,qo,"f").subscribe(o(this,Ro,"m",Qo).bind(this)),o(this,To,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:e,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey}),o(this,qo,"f").update({isDebug:this.debug}),i(this,Lo,!0,"f")}}))}disconnectedCallback(){o(this,To,"f").unsubscribeAll(),o(this,qo,"f").unsubscribeAll(),o(this,Ro,"m",Yo).call(this),window.removeEventListener("popstate",o(this,Do,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Lo,"f")&&e!==n&&Ci.observedAttributes.includes(t)){o(this,Ro,"m",Wo).call(this);const i=null===e;o(this,To,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,x()),{[S(t)]:n,stepId:r,executionId:s}})),o(this,qo,"f").update({isDebug:this.debug})}}}Lo=new WeakMap,To=new WeakMap,qo=new WeakMap,Mo=new WeakMap,Do=new WeakMap,$o=new WeakMap,Bo=new WeakMap,Ro=new WeakSet,No=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Po.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Ko=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Jo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Wo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url"];if(Ci.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[S(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},Fo=function(){const{stepId:t,executionId:e}=O();o(this,To,"f").update({stepId:t,executionId:e})},Ho=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=Uo(Object.assign(Object.assign({},Ci.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r,persistTokens:!0})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},zo=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:r}=t;if(i("projectId")||i("baseUrl")||i("telemetryKey")){if(!e)return;o(this,Ro,"m",Ho).call(this,e,n,r)}o(this,$o,"f").call(this,t)}))},Vo=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const n=yield o(this,Bo,"f").call(this);null===(r=null===(i=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===i?void 0:i.fontFamilies)||void 0===r||r.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Zo=function(){o(this,Ro,"m",Go).call(this),o(this,Ro,"m",Xo).call(this)},Go=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield y(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Xo=function(){this.rootElement.setAttribute("data-theme",this.theme)},Yo=function(){var t;null===(t=o(this,Mo,"f"))||void 0===t||t.remove(),i(this,Mo,null,"f")},Qo=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return Ui})),i(this,Mo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Mo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Mo,"f"))):o(this,Ro,"m",Yo).call(this)}))},ti=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Mo,"f"))||void 0===n||n.updateData({title:t,description:e}))},ei=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const n=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===n.length&&n[0].click()}},Ci.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.2"}};class Ei extends Ci{constructor(){const t=new R;super(t.update.bind(t)),ni.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),oi.set(this,void 0),ii.set(this,null),ri.set(this,(()=>{clearInterval(o(this,oi,"f")),i(this,oi,null,"f")})),si.set(this,(t=>{var e,n,i,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,ri,"f").call(this),o(this,ni,"m",vi).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:g,authInfo:v,lastAuth:m}=t.data;if("completed"===g)return function(t){r&&localStorage.setItem(c,JSON.stringify(t))}(m),o(this,ri,"f").call(this),void o(this,ni,"m",vi).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:O}=t.data;y!==h?this.flowState.update({stepId:w,executionId:b,action:y,redirectTo:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:y})})),ai.set(this,C((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.logger.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.logger.error("Webauthn start failed",t.message)}}))))),this.flowState=t}static set sdkConfigOverrides(t){Ci.sdkConfigOverrides=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(t,e,r){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:u,stepId:m,executionId:b,action:w,screenId:y,screenState:O,redirectTo:x,redirectUrl:S,token:j,code:C,exchangeError:E,webauthnTransactionId:_,webauthnOptions:A}=t;let U,P;o(this,oi,"f")&&o(this,ri,"f").call(this);const R=this.sdk.getLastUserLoginId();if(!b){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:P}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,R)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:u},S&&{redirectUrl:S}));return void o(this,si,"f").call(this,t)}}if(r("token")&&j||r("code")&&C||r("exchangeError")&&E){const t=yield this.sdk.flow.next(b,m,g,{token:j,exchangeCode:C,exchangeError:E});return o(this,si,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(w===d)return x||this.logger.error("Did not get redirect url"),void window.location.assign(x);if(w===p||w===f){if(!_||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,ii,"f"))||void 0===s||s.abort(),i(this,ii,null,"f");try{t=w===p?yield T(A):yield q(A)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(b,m,g,{transactionId:_,response:t,cancelWebauthn:e});o(this,si,"f").call(this,n)}if(w===h&&i(this,oi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(b,m,v,{});o(this,si,"f").call(this,t)}))),2e3),"f"),!y&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const L={direction:I(+m,+e.stepId),screenState:Object.assign(Object.assign({},O),{lastAuth:{loginId:R,name:this.sdk.getLastUserDisplayName()||R}}),htmlUrl:k(a,`${U||y}.html`)},M=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(R);U?L.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:M},P,...t):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(L.next=(...t)=>this.sdk.flow.next(b,m,...t)),this.stepState.update(L)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:i,direction:r,next:s,screenState:a}=t,l=document.createElement("template");l.innerHTML=yield y(i,"text");const c=l.content.cloneNode(!0),d=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),i=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,r=Function(i).bind(e.previousSibling);return e.remove(),r}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c);this.sdk.webauthn.helpers.isSupported()?yield o(this,ni,"m",ci).call(this,c,s):c.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(c,a),((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(e=null==a?void 0:a.totp)||void 0===e?void 0:e.image);const h=()=>n(this,void 0,void 0,(function*(){try{d.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])');null==t||t.focus({preventScroll:!0}),o(this,ni,"m",fi).call(this,s),o(this,ni,"m",vi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield s(v,{});o(this,si,"f").call(this,t)}}));r?o(this,ni,"m",gi).call(this,h,r):h()}))}}oi=new WeakMap,ii=new WeakMap,ri=new WeakMap,si=new WeakMap,ai=new WeakMap,ni=new WeakSet,li=function(t){const e=t.name;if(!["email"].includes(e)){const n=`user-${e}`;t.name=n,t.addEventListener("input",(()=>{t.name=t.value?e:n}))}},ci=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,ii,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield $())){const{options:t,transactionId:r}=(yield o(this,ai,"f").call(this))||{};t&&r&&(o(this,ni,"m",li).call(this,s),i(this,ii,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,ii,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,si,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},ui=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},di=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},hi=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,i;n?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(i=null==t?void 0:t.classList)||void 0===i||i.remove("loading"))}))},pi=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,ni,"m",ui).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,ni,"m",hi).call(this,t);const r=o(this,ni,"m",di).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),l=yield e(i,a);o(this,si,"f").call(this,l)}var n}))},fi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,ni,"m",pi).call(this,e,t)}}))},gi=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===w.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},vi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Ei);const _i=document.createElement("template");_i.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class Ai extends HTMLElement{constructor(){super(),mi.add(this),bi.set(this,new R({messages:[]})),wi.set(this,void 0),yi.set(this,void 0),ki.set(this,void 0),Ii.set(this,{resize:o(this,mi,"m",ji).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(_i.content.cloneNode(!0)),i(this,wi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,yi,o(this,wi,"f").querySelector(".content"),"f"),i(this,ki,o(this,wi,"f").querySelector(".header"),"f")}updateData(t){o(this,bi,"f").update((e=>({messages:e.messages.concat(t)})))}connectedCallback(){var t;((t,e,n)=>{let o=0,i=0,r=0,s=0;function a(e){e.preventDefault(),o=r-e.clientX,i=s-e.clientY,r=e.clientX,s=e.clientY;const[a,l]=N(t,t.offsetLeft-o,t.offsetTop-i,n);t.style.top=`${l}px`,t.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(t){t.preventDefault(),r=t.clientX,s=t.clientY,document.onmouseup=l,document.onmousemove=a}e?e.onmousedown=c:t.onmousedown=c})(o(this,wi,"f"),o(this,ki,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ii,"f").resize),(t=o(this,wi,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&t.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},o(this,wi,"f").onresize=o(this,mi,"m",Si).bind(this),o(this,bi,"f").subscribe(o(this,mi,"m",Oi).bind(this))}disconnectedCallback(){o(this,bi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ii,"f").resize)}}bi=new WeakMap,wi=new WeakMap,yi=new WeakMap,ki=new WeakMap,Ii=new WeakMap,mi=new WeakSet,Oi=function(t){o(this,mi,"m",xi).call(this,t),o(this,mi,"m",Si).call(this)},xi=function(t){o(this,yi,"f").innerHTML=t.messages.map((t=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.title}\n </div>\n <div class="msg_desc">\n ${t.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},Si=function(){o(this,yi,"f").querySelectorAll(".msg").forEach((t=>{const e=t.querySelector(".msg_desc"),n=e.scrollWidth>e.clientWidth,o=e.clientHeight>20;n||o?(t.classList.add("collapsible"),t.onclick=e=>{e.target.classList.contains("msg_desc")||t.classList.toggle("collapsed")}):(t.classList.remove("collapsible"),t.onclick=null)}))},ji=function(){const[t,e]=N(o(this,wi,"f"),Number.parseInt(o(this,wi,"f").style.left,10),Number.parseInt(o(this,wi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,wi,"f").style.top=`${e}px`,o(this,wi,"f").style.left=`${t}px`},customElements.define("descope-debugger",Ai);var Ui=Object.freeze({__proto__:null,default:Ai})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
"typescript": "^4.5.3"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@descope/web-js-sdk": "0.1.
|
|
78
|
+
"@descope/web-js-sdk": "0.1.2"
|
|
79
79
|
},
|
|
80
80
|
"overrides": {
|
|
81
|
-
"terser": "5.16.
|
|
81
|
+
"terser": "5.16.2"
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{l(o.next(t))}catch(t){i(t)}}function a(t){try{l(o.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function r(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?r.call(t,n):r?r.value=n:e.set(t,n),n}const i="undefined"!=typeof localStorage,s=i&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";function b(t){return new URLSearchParams(window.location.search).get(t)}function y(t){if(window.history.replaceState&&b(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var m;function w(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(m||(m={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?m.forward:t<e?m.backward:void 0}const O=()=>{const[t="",e=""]=(b(a)||"").split("_");return{executionId:t,stepId:e}};function j(){y(a)}const S=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),E=()=>{const{executionId:t,stepId:e}=O();(t||e)&&j();const n=b("t")||void 0;n&&y("t");const o=b(l)||void 0;o&&y(l);const r=b("err")||void 0;return r&&y("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:r}},_=t=>{let e,n;return(...o)=>{return e&&(i=o,(r=e).length===i.length&&r.every(((t,e)=>t===i[e])))||(e=o,n=t(...o)),n;var r,i}};var C,x,A,U;function P(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const r=n[o],i=t[r],s=e[r];if("object"==typeof i&&"object"==typeof s){if(!P(i,s))return!1}else if(i!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){C.set(this,void 0),x.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,C,"f")):t,n=Object.assign(Object.assign({},o(this,C,"f")),e);if(!o(this,U,"f")||!P(o(this,C,"f"),n)){const t=o(this,C,"f");r(this,C,n,"f"),Object.freeze(o(this,C,"f")),setTimeout((()=>{Object.values(o(this,x,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},r(this,C,t,"f"),r(this,U,e,"f")}get current(){return Object.assign({},o(this,C,"f"))}subscribe(t){return r(this,A,o(this,A,"f")+1,"f"),o(this,x,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,x,"f")[t];return e&&delete o(this,x,"f")[t],e}unsubscribeAll(){return r(this,x,{},"f"),!0}}C=new WeakMap,x=new WeakMap,A=new WeakMap,U=new WeakMap;const T=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${u}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)};function q(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),n.publicKey.user.id=M(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:L(o.rawId),type:o.type,response:{attestationObject:L(o.response.attestationObject),clientDataJSON:L(o.response.clientDataJSON)}});var o}))}function D(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=M(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=M(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:L(o.rawId),type:o.type,response:{authenticatorData:L(o.response.authenticatorData),clientDataJSON:L(o.response.clientDataJSON),signature:L(o.response.signature),userHandle:L(o.response.userHandle)}});var o}))}function M(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function L(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const N=_((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}}))));function K(t){this.message=t}K.prototype=new Error,K.prototype.name="InvalidCharacterError";var $="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new K("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,s="";o=e.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function J(t){this.message=t}function W(t,e){if("string"!=typeof t)throw new J("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent($(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return $(e)}}(t.split(".")[n]))}catch(t){throw new J("Invalid token specified: "+t.message)}}J.prototype=new Error,J.prototype.name="InvalidTokenError";var F="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},H="__lodash_hash_undefined__",B="[object Function]",V="[object GeneratorFunction]",z=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,G=/^\w*$/,Z=/^\./,Q=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,X=/\\(\\)?/g,Y=/^\[object .+?Constructor\]$/,tt="object"==typeof F&&F&&F.Object===Object&&F,et="object"==typeof self&&self&&self.Object===Object&&self,nt=tt||et||Function("return this")();var ot,rt=Array.prototype,it=Function.prototype,st=Object.prototype,at=nt["__core-js_shared__"],lt=(ot=/[^.]+$/.exec(at&&at.keys&&at.keys.IE_PROTO||""))?"Symbol(src)_1."+ot:"",ct=it.toString,ut=st.hasOwnProperty,dt=st.toString,ht=RegExp("^"+ct.call(ut).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),pt=nt.Symbol,ft=rt.splice,gt=Et(nt,"Map"),vt=Et(Object,"create"),bt=pt?pt.prototype:void 0,yt=bt?bt.toString:void 0;function mt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function wt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function kt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function It(t,e){for(var n,o,r=t.length;r--;)if((n=t[r][0])===(o=e)||n!=n&&o!=o)return r;return-1}function Ot(t,e){var n;e=function(t,e){if(At(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Pt(t))return!0;return G.test(t)||!z.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:At(n=e)?n:_t(n);for(var o=0,r=e.length;null!=t&&o<r;)t=t[Ct(e[o++])];return o&&o==r?t:void 0}function jt(t){if(!Ut(t)||(e=t,lt&< in e))return!1;var e,n=function(t){var e=Ut(t)?dt.call(t):"";return e==B||e==V}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?ht:Y;return n.test(function(t){if(null!=t){try{return ct.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function St(t,e){var n,o,r=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function Et(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return jt(n)?n:void 0}mt.prototype.clear=function(){this.__data__=vt?vt(null):{}},mt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},mt.prototype.get=function(t){var e=this.__data__;if(vt){var n=e[t];return n===H?void 0:n}return ut.call(e,t)?e[t]:void 0},mt.prototype.has=function(t){var e=this.__data__;return vt?void 0!==e[t]:ut.call(e,t)},mt.prototype.set=function(t,e){return this.__data__[t]=vt&&void 0===e?H:e,this},wt.prototype.clear=function(){this.__data__=[]},wt.prototype.delete=function(t){var e=this.__data__,n=It(e,t);return!(n<0)&&(n==e.length-1?e.pop():ft.call(e,n,1),!0)},wt.prototype.get=function(t){var e=this.__data__,n=It(e,t);return n<0?void 0:e[n][1]},wt.prototype.has=function(t){return It(this.__data__,t)>-1},wt.prototype.set=function(t,e){var n=this.__data__,o=It(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},kt.prototype.clear=function(){this.__data__={hash:new mt,map:new(gt||wt),string:new mt}},kt.prototype.delete=function(t){return St(this,t).delete(t)},kt.prototype.get=function(t){return St(this,t).get(t)},kt.prototype.has=function(t){return St(this,t).has(t)},kt.prototype.set=function(t,e){return St(this,t).set(t,e),this};var _t=xt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Pt(t))return yt?yt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return Z.test(t)&&n.push(""),t.replace(Q,(function(t,e,o,r){n.push(o?r.replace(X,"$1"):e||t)})),n}));function Ct(t){if("string"==typeof t||Pt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function xt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,r=e?e.apply(this,o):o[0],i=n.cache;if(i.has(r))return i.get(r);var s=t.apply(this,o);return n.cache=i.set(r,s),s};return n.cache=new(xt.Cache||kt),n}xt.Cache=kt;var At=Array.isArray;function Ut(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Pt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==dt.call(t)}var Rt=function(t,e,n){var o=null==t?void 0:Ot(t,e);return void 0===o?n:o},Tt="/v1/auth/accesskey/exchange",qt="/v1/auth/otp/verify",Dt="/v1/auth/otp/signin",Mt="/v1/auth/otp/signup",Lt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Nt="/v1/auth/otp/signup-in",Kt="/v1/auth/magiclink/verify",$t="/v1/auth/magiclink/signin",Jt="/v1/auth/magiclink/signup",Wt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Ft="/v1/auth/magiclink/signup-in",Ht="/v1/auth/enchantedlink/verify",Bt="/v1/auth/enchantedlink/signin",Vt="/v1/auth/enchantedlink/signup",zt="/v1/auth/enchantedlink/pending-session",Gt={email:"/v1/auth/enchantedlink/update/email"},Zt="/v1/auth/enchantedlink/signup-in",Qt="/v1/auth/oauth/authorize",Xt="/v1/auth/oauth/exchange",Yt="/v1/auth/saml/authorize",te="/v1/auth/saml/exchange",ee="/v1/auth/totp/verify",ne="/v1/auth/totp/signup",oe="/v1/auth/totp/update",re={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ie={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},se={start:"/v1/auth/webauthn/signup-in/start"},ae={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},le="/v1/auth/refresh",ce="/v1/auth/logout",ue="/v1/auth/logoutall",de="/v1/auth/me",he="/v1/flow/start",pe="/v1/flow/next";const fe=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var ge;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ge||(ge={}));const ve=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),be=t=>void 0===t?void 0:JSON.stringify(t),ye=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},me=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:r,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>fe().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),fe().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:t,queryParams:d}),{headers:ve(ye(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.55"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:be(c),credentials:i||"include"});return(null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:ge.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ge.post,token:r}),put:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ge.put,token:r}),delete:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ge.delete,token:r}),hooks:r}};var we=429;function ke(t,e,n){var o;let r=Ie(t);e&&(r=null===(o=null==r?void 0:r.tenants)||void 0===o?void 0:o[e]);const i=null==r?void 0:r[n];return Array.isArray(i)?i:[]}function Ie(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return W(t)}function Oe(t){const{exp:e}=Ie(t);return(new Date).getTime()/1e3>e}function je(t,e){return ke(t,e,"permissions")}function Se(t,e){return ke(t,e,"roles")}const Ee=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function _e(t,e){var n;const o=await t,r={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?r.data=e?e(i):i:(r.error=i,o.status===we&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const Ce=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),xe=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ae=t=>e=>t.test(e),Ue=Ae(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Pe=Ae(/^\+[1-9]{1}[0-9]{3,14}$/),Re=Ce(Ue,'"{val}" is not a valid email'),Te=Ce(Pe,'"{val}" is not a valid phone number'),qe=Ce((1,t=>t.length>=1),"Minimum length is 1");const De=Ce((t=>"string"==typeof t),"Input is not a string"),Me=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>xe(...t).validate(n[e]))),e(...n)),Le=t=>[De(`"${t}" must be a string`),qe(`"${t}" must not be empty`)],Ne=t=>[De(`"${t}" must be a string`),Re()],Ke=t=>[De(`"${t}" must be a string`),Te()],$e=Me(Le("accessKey")),Je=t=>({exchange:$e((e=>_e(t.post(Tt,{},{token:e}))))});var We,Fe,He,Be;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(We||(We={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Fe||(Fe={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(He||(He={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Be||(Be={}));const Ve=Le("loginId"),ze=Le("uri"),Ge=Me(Le("token")),Ze=Me(Ve,ze),Qe=Me(Le("pendingRef")),Xe=Me(Ve,Ne("email"),ze),Ye=t=>({verify:Ge((e=>_e(t.post(Ht,{token:e})))),signIn:Ze(((e,n,o,r)=>_e(t.post(Ee(Bt,Fe.email),{loginId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:Ze(((e,n)=>_e(t.post(Ee(Zt,Fe.email),{loginId:e,URI:n})))),signUp:Ze(((e,n,o)=>_e(t.post(Ee(Vt,Fe.email),{loginId:e,URI:n,user:o})))),waitForSession:Qe(((e,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(zt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(_e(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Xe(((e,n,o,r)=>_e(t.post(Gt.email,{loginId:e,email:n,URI:o},{token:r}))))}}),tn=Me(Le("flowId")),en=Me(Le("executionId"),Le("stepId"),Le("interactionId")),nn=t=>({start:tn(((e,n,o,r,i)=>_e(t.post(he,{flowId:e,options:n,conditionInteractionId:o,interactionId:r,input:i})))),next:en(((e,n,o,r)=>_e(t.post(pe,{executionId:e,stepId:n,interactionId:o,input:r}))))}),on=Le("loginId"),rn=Le("uri"),sn=Me(Le("token")),an=Me(on,rn),ln=Me(on,Ke("phone"),rn),cn=Me(on,Ne("email"),rn),un=t=>({verify:sn((e=>_e(t.post(Kt,{token:e})))),signIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:an(((e,o,r,i)=>_e(t.post(Ee($t,n),{loginId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:an(((e,o,r)=>_e(t.post(Ee(Jt,n),{loginId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:an(((e,o)=>_e(t.post(Ee(Ft,n),{loginId:e,URI:o}))))})),{}),update:{email:cn(((e,n,o,r)=>_e(t.post(Wt.email,{loginId:e,email:n,URI:o},{token:r})))),phone:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,r,i)=>_e(t.post(Ee(Wt.phone,n),{loginId:e,phone:o,URI:r},{token:i}))))})),{})}});var dn;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin"}(dn||(dn={}));const hn=Me(Le("code")),pn=t=>({start:Object.keys(dn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(Qt,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return _e(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:hn((e=>_e(t.post(Xt,{code:e}))))});var fn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(fn||(fn={}));const gn=Le("loginId"),vn=Me(gn,Le("code")),bn=Me(gn),yn=Me(gn,Ke("phone")),mn=Me(gn,Ne("email")),wn=t=>({verify:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:vn(((e,o)=>_e(t.post(Ee(qt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn(((e,o,r)=>_e(t.post(Ee(Dt,n),{loginId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn(((e,o)=>_e(t.post(Ee(Mt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Fe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn((e=>_e(t.post(Ee(Nt,n),{loginId:e}))))})),{}),update:{email:mn(((e,n,o)=>_e(t.post(Lt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o,r)=>_e(t.post(Ee(Lt.phone,n),{loginId:e,phone:o},{token:r}))))})),{})}}),kn=Me(Le("tenant")),In=Me(Le("code")),On=t=>({start:kn((async(e,n,{redirect:o=!1}={},r,i)=>{const s=await t.post(Yt,r||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!o||!s.ok)return _e(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:In((e=>_e(t.post(te,{code:e}))))}),jn=Le("loginId"),Sn=Me(jn,Le("code")),En=Me(jn),_n=Me(jn),Cn=t=>({signUp:En(((e,n)=>_e(t.post(ne,{loginId:e,user:n})))),verify:Sn(((e,n,o,r)=>_e(t.post(ee,{loginId:e,code:n,loginOptions:o},{token:r})))),update:_n(((e,n)=>_e(t.post(oe,{loginId:e},{token:n}))))}),xn=[De('"loginId" must be a string')],An=Le("loginId"),Un=Le("origin"),Pn=Me(An,Un,Le("name")),Rn=Me(An,Un),Tn=Me(xn,Un),qn=Me(An,Un,Le("token")),Dn=Me(Le("transactionId"),Le("response")),Mn=t=>({signUp:{start:Pn(((e,n,o)=>_e(t.post(re.start,{user:{loginId:e,name:o},origin:n})))),finish:Dn(((e,n)=>_e(t.post(re.finish,{transactionId:e,response:n}))))},signIn:{start:Tn(((e,n,o,r)=>_e(t.post(ie.start,{loginId:e,origin:n,loginOptions:o},{token:r})))),finish:Dn(((e,n)=>_e(t.post(ie.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Rn(((e,n)=>_e(t.post(se.start,{loginId:e,origin:n}))))},update:{start:qn(((e,n,o)=>_e(t.post(ae.start,{loginId:e,origin:n},{token:o})))),finish:Dn(((e,n)=>_e(t.post(ae.finish,{transactionId:e,response:n}))))}}),Ln=Me(Le("token"));var Nn,Kn=Me([("projectId",Nn=Le("projectId"),Ce(((t,e)=>n=>xe(...e).validate(Rt(n,t)))("projectId",Nn))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),r=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={}})=>{return s=me({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i}}),{accessKey:Je(s),otp:wn(s),magicLink:un(s),enchantedLink:Ye(s),oauth:pn(s),saml:On(s),totp:Cn(s),webauthn:Mn(s),flow:nn(s),refresh:t=>_e(s.post(le,{},{token:t})),logout:t=>_e(s.post(ce,{},{token:t})),logoutAll:t=>_e(s.post(ue,{},{token:t})),me:t=>_e(s.get(de,{token:t})),isJwtExpired:Ln(Oe),getJwtPermissions:Ln(je),getJwtRoles:Ln(Se),httpClient:s};var s})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:async(e,n)=>{(await Promise.allSettled(null==r?void 0:r.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))}));const $n=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let r=o.shift(),i=t;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${e}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${e}" is not a function`);const s=i[r];i[r]=n(s)})),t);var Jn=Object.assign(Kn,{DeliveryMethods:Fe});function Wn(t,e){var n=[];return function(t,e){var n,o,r=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),r=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,r++)o[r]=i[s];return o}(t),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=r.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?r.postpone():r.exclude();var e,o=r.current();if(void 0===o)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(t,(function(t){var o=new Date,r=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},i=e(t);return i.then(r,r),i})).then((function(t){return[t,{attempts:n}]}))}var Fn="Failed to load the JS script of the agent";function Hn(n){var o;n.scriptUrlPattern;var r=n.token,i=n.apiKey,s=void 0===i?r:i,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Wn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(l,s),Bn).catch(zn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Bn(t){return function(t,e,n,o){var r,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),o=e.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(r=e,l())};i.addEventListener(s,a);var l=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return l(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(l(),r)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),r=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),e()},o.onerror=function(){r(),n(new Error(Fn))},o.async=!0,o.src=t,i.appendChild(o)}))}(t)})).then(Vn)}function Vn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function zn(t){throw t instanceof Error&&"9319"===t.message?new Error(Fn):t}
|
|
2
|
-
/*! js-cookie v3.0.1 | MIT */function Gn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Zn=function t(e,n){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=Gn({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in r)r[s]&&(i+="; "+s,!0!==r[s]&&(i+="="+r[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+i}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},r=0;r<n.length;r++){var i=n[r].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",Gn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Gn({},this.attributes,e))},withConverter:function(e){return t(Gn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Qn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=t.hooks)||void 0===r?void 0:r[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Xn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Yn=async t=>{const e=await Xn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},to="undefined"!=typeof localStorage,eo=(t,e)=>to&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),no=t=>to&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),oo=t=>to&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),ro="undefined"!=typeof window,io=ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",so=(t="",e="")=>({vsid:t,vrid:e}),ao=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},lo=t=>(t.body&&(t.body.fpData=ao(!0)||so()),t),co=()=>no("dls_last_user_login_id"),uo=()=>no("dls_last_user_display_name"),ho=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,r=co(),i=uo();return r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i),await t(...e)},po=t=>async(...e)=>{const n=await t(...e);return oo("dls_last_user_login_id"),oo("dls_last_user_display_name"),n};function fo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const go=(t={},n)=>{var{refreshJwt:o,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&eo("DSR",o),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(e){const i=new Date(1e3*r);Zn.set(t,e,{path:n,domain:o,expires:i,sameSite:"Strict",secure:!0})}}("DS",r,i):eo("DS",r))};function vo(){return no("DSR")||""}function bo(){return Zn.get("DS")||no("DS")||""}function yo(){oo("DSR"),oo("DS"),Zn.remove("DS")}const mo=t=>Object.assign(t,{token:t.token||vo()}),wo=t=>async(...e)=>{const n=await t(...e);return yo(),n};async function ko(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=_o(n.publicKey.challenge),n.publicKey.user.id=_o(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=_o(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Co(n.rawId),type:n.type,response:{attestationObject:Co(n.response.attestationObject),clientDataJSON:Co(n.response.clientDataJSON)}});var n}async function Io(t){const e=So(t);return Eo(await navigator.credentials.get(e))}async function Oo(t,e){const n=So(t);return n.signal=e.signal,n.mediation="conditional",Eo(await navigator.credentials.get(n))}async function jo(t=!1){if(!ro)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function So(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=_o(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=_o(t.id)})),n}function Eo(t){return JSON.stringify({id:t.id,rawId:Co(t.rawId),type:t.type,response:{authenticatorData:Co(t.response.authenticatorData),clientDataJSON:Co(t.response.clientDataJSON),signature:Co(t.response.signature),userHandle:t.response.userHandle?Co(t.response.userHandle):void 0}})}function _o(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Co(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var xo,Ao=(xo=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const r=await ko(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await Io(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await ko(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Io(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const r=await ko(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:ko,get:Io,isSupported:jo,conditional:Oo}}),(...t)=>{const e=xo(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),Uo=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await jo(),o=Object.assign(Object.assign({},e[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Po=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:r}=n,i=e(n,["fpKey","fpLoad"]);return o?(ro?r&&(async t=>{try{if(ao())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Hn({apiKey:t,endpoint:io}),o=await n,{requestId:r}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(so(e,r))}catch(t){global.FB_DEBUG&&console.error(t)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(Qn(i,{beforeRequest:lo}))):t(Object.assign({},i))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:r,setTimer:i}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(Qn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Xn(e);if(401===(null==e?void 0:e.status))r();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;r(),i((()=>s.refresh(n)),t)}var a}}));return $n(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.1-alpha.0"},e.baseHeaders)}))),(t=>e=>{const n=fo(),o=fo(),r=t(Qn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Yn(e);t&&o.pub(t);const{sessionJwt:r}=await Xn(e);r&&n.pub(r)}}})),i=$n(r,["logout","logoutAll"],(t=>async(...e)=>{const r=await t(...e);return n.pub(null),o.pub(null),r}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Qn(e,{afterRequest:async(t,e)=>{var n;const o=await Yn(e),r=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;r&&((t=>{eo("dls_last_user_login_id",t)})(r),(t=>{eo("dls_last_user_display_name",t)})(i))}}));let o=$n(n,["flow.start"],ho);return o=$n(o,["logout","logoutAll"],po),Object.assign(o,{getLastUserLoginId:co,getLastUserDisplayName:uo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!ro)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(i);const s=t(Qn(i,{beforeRequest:mo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?yo():go(await Xn(e),r)}})),a=$n(s,["logout","logoutAll"],wo);return Object.assign(a,{getRefreshToken:vo,getSessionToken:bo})}))(((...t)=>{const e=Jn(...t);return Object.assign(Object.assign({},e),{flow:Uo(e),webauthn:Ao(e)})})),Ro=document.createElement("template");var To,qo,Do,Mo,Lo,No,Ko,$o,Jo,Wo,Fo,Ho,Bo,Vo,zo,Go,Zo,Qo,Xo,Yo,tr,er,nr,or,rr,ir,sr,ar,lr,cr,ur,dr,hr,pr,fr,gr,vr,br;Ro.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class yr extends HTMLElement{constructor(t){super(),To.add(this),qo.set(this,!1),Do.set(this,new R),Mo.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),Lo.set(this,void 0),No.set(this,{popstate:o(this,To,"m",Ho).bind(this)}),Ko.set(this,void 0),zo.set(this,_((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield w(t,"json")}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,To,"m",er).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},r(this,Ko,t,"f"),o(this,To,"m",$o).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey"]}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,zo,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,To,"m",Jo).call(this))return void o(this,To,"m",Wo).call(this);o(this,To,"m",Fo).call(this),o(this,To,"m",Zo).call(this),o(this,To,"m",Go).call(this),o(this,To,"m",nr).call(this);const{executionId:t,stepId:e,token:n,code:i,exchangeError:s}=E();window.addEventListener("popstate",o(this,No,"f").popstate),o(this,Do,"f").subscribe(o(this,To,"m",Vo).bind(this)),o(this,Mo,"f").subscribe(o(this,To,"m",tr).bind(this)),o(this,Do,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,stepId:e,executionId:t,token:n,code:i,exchangeError:s,telemetryKey:this.telemetryKey}),o(this,Mo,"f").update({isDebug:this.debug}),r(this,qo,!0,"f")}}))}disconnectedCallback(){o(this,Do,"f").unsubscribeAll(),o(this,Mo,"f").unsubscribeAll(),o(this,To,"m",Yo).call(this),window.removeEventListener("popstate",o(this,No,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,qo,"f")&&e!==n&&yr.observedAttributes.includes(t)){o(this,To,"m",Fo).call(this);const r=null===e;o(this,Do,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,j()),{[S(t)]:n,stepId:i,executionId:s}})),o(this,Mo,"f").update({isDebug:this.debug})}}}qo=new WeakMap,Do=new WeakMap,Mo=new WeakMap,Lo=new WeakMap,No=new WeakMap,Ko=new WeakMap,zo=new WeakMap,To=new WeakSet,$o=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ro.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Jo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Wo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Fo=function(){const t=["base-url","tenant","theme","debug","telemetryKey"];if(yr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[S(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},Ho=function(){const{stepId:t,executionId:e}=O();o(this,Do,"f").update({stepId:t,executionId:e})},Bo=function(t,e,o){const r=o||void 0,i=!!r;this.sdk=Po(Object.assign(Object.assign({},yr.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:r,fpLoad:i,persistTokens:!0})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Vo=function(t,e,r){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:i}=t;if(r("projectId")||r("baseUrl")||r("telemetryKey")){if(!e)return;o(this,To,"m",Bo).call(this,e,n,i)}o(this,Ko,"f").call(this,t)}))},Go=function(){var t,e,r,i;return n(this,void 0,void 0,(function*(){const n=yield o(this,zo,"f").call(this);null===(i=null===(r=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===r?void 0:r.fontFamilies)||void 0===i||i.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Zo=function(){o(this,To,"m",Qo).call(this),o(this,To,"m",Xo).call(this)},Qo=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield w(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Xo=function(){this.rootElement.setAttribute("data-theme",this.theme)},Yo=function(){var t;null===(t=o(this,Lo,"f"))||void 0===t||t.remove(),r(this,Lo,null,"f")},tr=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-bf46ac84.js"),r(this,Lo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Lo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Lo,"f"))):o(this,To,"m",Yo).call(this)}))},er=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Lo,"f"))||void 0===n||n.updateData({title:t,description:e}))},nr=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const n=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===n.length&&n[0].click()}},yr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.0"}};class mr extends yr{constructor(){const t=new R;super(t.update.bind(t)),or.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),rr.set(this,void 0),ir.set(this,null),sr.set(this,(()=>{clearInterval(o(this,rr,"f")),r(this,rr,null,"f")})),ar.set(this,(t=>{var e,n,r,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,sr,"f").call(this),o(this,or,"m",br).call(this,"error",null==t?void 0:t.error);const i=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||i,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:g,authInfo:v,lastAuth:b}=t.data;if("completed"===g)return function(t){i&&localStorage.setItem(c,JSON.stringify(t))}(b),o(this,sr,"f").call(this),void o(this,or,"m",br).call(this,"success",v);const{executionId:y,stepId:m,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==h?this.flowState.update({stepId:m,executionId:y,action:w,redirectUrl:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:w})})),lr.set(this,_((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.logger.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.logger.error("Webauthn start failed",t.message)}}))))),this.flowState=t}static set sdkConfigOverrides(t){yr.sdkConfigOverrides=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(t,e,i){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:u,stepId:b,executionId:y,action:m,screenId:w,screenState:O,redirectUrl:j,token:S,code:E,exchangeError:_,webauthnTransactionId:C,webauthnOptions:x}=t;let A,U;o(this,rr,"f")&&o(this,sr,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!y){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:A=t.startScreenId,conditionInteractionId:U}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,P)),!A){const t=yield this.sdk.flow.start(l,{tenant:u});return void o(this,ar,"f").call(this,t)}}if(i("token")&&S||i("code")&&E||i("exchangeError")&&_){const t=yield this.sdk.flow.next(y,b,g,{token:S,exchangeCode:E,exchangeError:_});return o(this,ar,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(m===d)return j||this.logger.error("Did not get redirect url"),void window.location.assign(j);if(m===p||m===f){if(!C||!x)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,ir,"f"))||void 0===s||s.abort(),r(this,ir,null,"f");try{t=m===p?yield q(x):yield D(x)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(y,b,g,{transactionId:C,response:t,cancelWebauthn:e});o(this,ar,"f").call(this,n)}if(m===h&&r(this,rr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(y,b,v,{});o(this,ar,"f").call(this,t)}))),2e3),"f"),!w&&!A)return void this.logger.info("Refreshing the page during a flow is not supported yet");const R={direction:I(+b,+e.stepId),screenState:Object.assign(Object.assign({},O),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:k(a,`${A||w}.html`)},T=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(P);A?R.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:T},U,...t):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(R.next=(...t)=>this.sdk.flow.next(y,b,...t)),this.stepState.update(R)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:i,next:s,screenState:a}=t,l=document.createElement("template");l.innerHTML=yield w(r,"text");const c=l.content.cloneNode(!0),d=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),r=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,i=Function(r).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c);this.sdk.webauthn.helpers.isSupported()?yield o(this,or,"m",ur).call(this,c,s):c.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),T(c,a),((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(e=null==a?void 0:a.totp)||void 0===e?void 0:e.image);const h=()=>n(this,void 0,void 0,(function*(){try{d.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])');null==t||t.focus({preventScroll:!0}),o(this,or,"m",gr).call(this,s),o(this,or,"m",br).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield s(v,{});o(this,ar,"f").call(this,t)}}));i?o(this,or,"m",vr).call(this,h,i):h()}))}}rr=new WeakMap,ir=new WeakMap,sr=new WeakMap,ar=new WeakMap,lr=new WeakMap,or=new WeakSet,cr=function(t){const e=t.name;if(!["email"].includes(e)){const n=`user-${e}`;t.name=n,t.addEventListener("input",(()=>{t.name=t.value?e:n}))}},ur=function(t,e){var i;return n(this,void 0,void 0,(function*(){null===(i=o(this,ir,"f"))||void 0===i||i.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:i}=(yield o(this,lr,"f").call(this))||{};t&&i&&(o(this,or,"m",cr).call(this,s),r(this,ir,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,ir,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:i,response:t});o(this,ar,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},dr=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},hr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},pr=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,r;n?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(r=null==t?void 0:t.classList)||void 0===r||r.remove("loading"))}))},fr=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,or,"m",dr).call(this)){const r=null==t?void 0:t.getAttribute("id");o(this,or,"m",pr).call(this,t);const i=o(this,or,"m",hr).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),i),{origin:window.location.origin}),l=yield e(r,a);o(this,ar,"f").call(this,l)}var n}))},gr=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,or,"m",fr).call(this,e,t)}}))},vr=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===m.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},br=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",mr);export{mr as D,R as S,o as _,r as a};
|