@descope/web-component 2.0.2 → 2.0.3
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-9bccbb90.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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
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="t",c="code",u="err",d="data-exclude-field",h="dls_last_auth",p="data-type",f="redirect",g="poll",v="webauthnCreate",b="webauthnGet",y="v2-alpha",m="submit",w="polling";var k;function I(t){return new URLSearchParams(window.location.search).get(t)}function O(t){if(window.history.replaceState&&I(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())}}function j(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{body:yield n[e||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(k||(k={}));const S=(...t)=>t.join("/").replace(/\/+/g,"/");function E(t,e){const n=new URL(s);return n.pathname=S(n.pathname,t,y,e),n.toString()}function x(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?k.forward:t<e?k.backward:void 0}const _=()=>{const[t="",e=""]=(I(a)||"").split("_");return{executionId:t,stepId:e}};function C(){O(a)}const A=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),U=()=>{const{executionId:t,stepId:e}=_();(t||e)&&C();const n=I(l)||void 0;n&&O(l);const o=I(c)||void 0;o&&O(c);const i=I(u)||void 0;return i&&O(u),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},R=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 P,T,q,M;function D(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(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!D(r,s))return!1}else if(r!==s)return!1}return!0}class ${constructor(t={},{updateOnlyOnChange:e=!0}={}){P.set(this,void 0),T.set(this,{}),q.set(this,0),M.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,P,"f")):t,n=Object.assign(Object.assign({},o(this,P,"f")),e);if(!o(this,M,"f")||!D(o(this,P,"f"),n)){const t=o(this,P,"f");i(this,P,n,"f"),Object.freeze(o(this,P,"f")),setTimeout((()=>{Object.values(o(this,T,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,P,t,"f"),i(this,M,e,"f")}get current(){return Object.assign({},o(this,P,"f"))}subscribe(t){return i(this,q,o(this,q,"f")+1,"f"),o(this,T,"f")[o(this,q,"f")]=t,o(this,q,"f").toString()}unsubscribe(t){const e=!!o(this,T,"f")[t];return e&&delete o(this,T,"f")[t],e}unsubscribeAll(){return i(this,T,{},"f"),!0}}P=new WeakMap,T=new WeakMap,q=new WeakMap,M=new WeakMap;const L=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${p}="${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}"]:not([${d}])`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${p}="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)},N=R((()=>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}})))),K={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function J(t){this.message=t}J.prototype=new Error,J.prototype.name="InvalidCharacterError";var F="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new J("'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 H(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(F(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 F(e)}}(t.split(".")[n]))}catch(t){throw new W("Invalid token specified: "+t.message)}}W.prototype=new Error,W.prototype.name="InvalidTokenError";var B="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},V="Expected a function",z="__lodash_hash_undefined__",G=1/0,Z="[object Function]",Q="[object GeneratorFunction]",Y="[object Symbol]",X=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tt=/^\w*$/,et=/^\./,nt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ot=/\\(\\)?/g,it=/^\[object .+?Constructor\]$/,rt="object"==typeof B&&B&&B.Object===Object&&B,st="object"==typeof self&&self&&self.Object===Object&&self,at=rt||st||Function("return this")();var lt,ct=Array.prototype,ut=Function.prototype,dt=Object.prototype,ht=at["__core-js_shared__"],pt=(lt=/[^.]+$/.exec(ht&&ht.keys&&ht.keys.IE_PROTO||""))?"Symbol(src)_1."+lt:"",ft=ut.toString,gt=dt.hasOwnProperty,vt=dt.toString,bt=RegExp("^"+ft.call(gt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),yt=at.Symbol,mt=ct.splice,wt=Ut(at,"Map"),kt=Ut(Object,"create"),It=yt?yt.prototype:void 0,Ot=It?It.toString:void 0;function jt(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 St(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 Et(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 xt(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 _t(t,e){var n;e=function(t,e){if(qt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Dt(t))return!0;return tt.test(t)||!X.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:qt(n=e)?n:Rt(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Pt(e[o++])];return o&&o==i?t:void 0}function Ct(t){if(!Mt(t)||(e=t,pt&&pt in e))return!1;var e,n=function(t){var e=Mt(t)?vt.call(t):"";return e==Z||e==Q}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?bt:it;return n.test(function(t){if(null!=t){try{return ft.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function At(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 Ut(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return Ct(n)?n:void 0}jt.prototype.clear=function(){this.__data__=kt?kt(null):{}},jt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},jt.prototype.get=function(t){var e=this.__data__;if(kt){var n=e[t];return n===z?void 0:n}return gt.call(e,t)?e[t]:void 0},jt.prototype.has=function(t){var e=this.__data__;return kt?void 0!==e[t]:gt.call(e,t)},jt.prototype.set=function(t,e){return this.__data__[t]=kt&&void 0===e?z:e,this},St.prototype.clear=function(){this.__data__=[]},St.prototype.delete=function(t){var e=this.__data__,n=xt(e,t);return!(n<0)&&(n==e.length-1?e.pop():mt.call(e,n,1),!0)},St.prototype.get=function(t){var e=this.__data__,n=xt(e,t);return n<0?void 0:e[n][1]},St.prototype.has=function(t){return xt(this.__data__,t)>-1},St.prototype.set=function(t,e){var n=this.__data__,o=xt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},Et.prototype.clear=function(){this.__data__={hash:new jt,map:new(wt||St),string:new jt}},Et.prototype.delete=function(t){return At(this,t).delete(t)},Et.prototype.get=function(t){return At(this,t).get(t)},Et.prototype.has=function(t){return At(this,t).has(t)},Et.prototype.set=function(t,e){return At(this,t).set(t,e),this};var Rt=Tt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Dt(t))return Ot?Ot.call(t):"";var e=t+"";return"0"==e&&1/t==-G?"-0":e}(e);var n=[];return et.test(t)&&n.push(""),t.replace(nt,(function(t,e,o,i){n.push(o?i.replace(ot,"$1"):e||t)})),n}));function Pt(t){if("string"==typeof t||Dt(t))return t;var e=t+"";return"0"==e&&1/t==-G?"-0":e}function Tt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(V);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(Tt.Cache||Et),n}Tt.Cache=Et;var qt=Array.isArray;function Mt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Dt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&vt.call(t)==Y}var $t=function(t,e,n){var o=null==t?void 0:_t(t,e);return void 0===o?n:o},Lt="/v1/auth/accesskey/exchange",Nt="/v1/auth/otp/verify",Kt="/v1/auth/otp/signin",Jt="/v1/auth/otp/signup",Ft={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Wt="/v1/auth/otp/signup-in",Ht="/v1/auth/magiclink/verify",Bt="/v1/auth/magiclink/signin",Vt="/v1/auth/magiclink/signup",zt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Gt="/v1/auth/magiclink/signup-in",Zt="/v1/auth/enchantedlink/verify",Qt="/v1/auth/enchantedlink/signin",Yt="/v1/auth/enchantedlink/signup",Xt="/v1/auth/enchantedlink/pending-session",te={email:"/v1/auth/enchantedlink/update/email"},ee="/v1/auth/enchantedlink/signup-in",ne="/v1/auth/oauth/authorize",oe="/v1/auth/oauth/exchange",ie="/v1/auth/saml/authorize",re="/v1/auth/saml/exchange",se="/v1/auth/totp/verify",ae="/v1/auth/totp/signup",le="/v1/auth/totp/update",ce={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ue={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},de={start:"/v1/auth/webauthn/signup-in/start"},he={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},pe="/v1/auth/refresh",fe="/v1/auth/logout",ge="/v1/auth/logoutall",ve="/v1/auth/me",be="/v1/flow/start",ye="/v1/flow/next";const me=()=>{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 we;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(we||(we={}));const ke=(...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}),{})),Ie=t=>void 0===t?void 0:JSON.stringify(t),Oe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},je=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((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=>me().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)),me().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o,s),l=async o=>{const s=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=s,f=await a((({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:ke(Oe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.1"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Ie(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}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:we.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:we.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:we.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:we.delete,token:i}),hooks:i}};var Se={TOO_MANY_REQUESTS:429};function Ee(t,e,n){var o;let i=xe(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 xe(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return H(t)}function _e(t){const{exp:e}=xe(t);return(new Date).getTime()/1e3>e}function Ce(t,e){return Ee(t,e,"permissions")}function Ae(t,e){return Ee(t,e,"roles")}const Ue=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Re(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===Se.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Pe=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Te=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),qe=t=>e=>t.test(e),Me=qe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),De=qe(/^\+[1-9]{1}[0-9]{3,14}$/),$e=Pe(Me,'"{val}" is not a valid email'),Le=Pe(De,'"{val}" is not a valid phone number'),Ne=Pe((1,t=>t.length>=1),"Minimum length is 1");const Ke=Pe((t=>"string"==typeof t),"Input is not a string"),Je=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Te(...t).validate(n[e]))),e(...n)),Fe=t=>[Ke(`"${t}" must be a string`),Ne(`"${t}" must not be empty`)],We=t=>[Ke(`"${t}" must be a string`),$e()],He=t=>[Ke(`"${t}" must be a string`),Le()],Be=Je(Fe("accessKey")),Ve=t=>({exchange:Be((e=>Re(t.post(Lt,{},{token:e}))))});var ze,Ge,Ze,Qe;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(ze||(ze={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ge||(Ge={})),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"}(Qe||(Qe={}));const Ye=Fe("loginId"),Xe=Je(Fe("token")),tn=Je(Ye),en=Je(Fe("pendingRef")),nn=Je(Ye,We("email")),on=t=>({verify:Xe((e=>Re(t.post(Zt,{token:e})))),signIn:tn(((e,n,o,i)=>Re(t.post(Ue(Qt,Ge.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:tn(((e,n)=>Re(t.post(Ue(ee,Ge.email),{loginId:e,URI:n})))),signUp:tn(((e,n,o)=>Re(t.post(Ue(Yt,Ge.email),{loginId:e,URI:n,user:o})))),waitForSession:en(((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(Xt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Re(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:nn(((e,n,o,i)=>Re(t.post(te.email,{loginId:e,email:n,URI:o},{token:i}))))}}),rn=Je(Fe("flowId")),sn=Je(Fe("executionId"),Fe("stepId"),Fe("interactionId")),an=t=>({start:rn(((e,n,o,i,r)=>Re(t.post(be,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:sn(((e,n,o,i)=>Re(t.post(ye,{executionId:e,stepId:n,interactionId:o,input:i}))))}),ln=Fe("loginId"),cn=Je(Fe("token")),un=Je(ln),dn=Je(ln,He("phone")),hn=Je(ln,We("email")),pn=t=>({verify:cn((e=>Re(t.post(Ht,{token:e})))),signIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o,i,r)=>Re(t.post(Ue(Bt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o,i)=>Re(t.post(Ue(Vt,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o)=>Re(t.post(Ue(Gt,n),{loginId:e,URI:o}))))})),{}),update:{email:hn(((e,n,o,i)=>Re(t.post(zt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o,i,r)=>Re(t.post(Ue(zt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var fn;!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"}(fn||(fn={}));const gn=Je(Fe("code")),vn=t=>({start:Object.keys(fn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(ne,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Re(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:gn((e=>Re(t.post(oe,{code:e}))))});var bn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(bn||(bn={}));const yn=Fe("loginId"),mn=Je(yn,Fe("code")),wn=Je(yn),kn=Je(yn,He("phone")),In=Je(yn,We("email")),On=t=>({verify:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o)=>Re(t.post(Ue(Nt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o,i)=>Re(t.post(Ue(Kt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o)=>Re(t.post(Ue(Jt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn((e=>Re(t.post(Ue(Wt,n),{loginId:e}))))})),{}),update:{email:In(((e,n,o)=>Re(t.post(Ft.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:kn(((e,o,i)=>Re(t.post(Ue(Ft.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),jn=Je(Fe("tenant")),Sn=Je(Fe("code")),En=t=>({start:jn((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(ie,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Re(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:Sn((e=>Re(t.post(re,{code:e}))))}),xn=Fe("loginId"),_n=Je(xn,Fe("code")),Cn=Je(xn),An=Je(xn),Un=t=>({signUp:Cn(((e,n)=>Re(t.post(ae,{loginId:e,user:n})))),verify:_n(((e,n,o,i)=>Re(t.post(se,{loginId:e,code:n,loginOptions:o},{token:i})))),update:An(((e,n)=>Re(t.post(le,{loginId:e},{token:n}))))}),Rn=[Ke('"loginId" must be a string')],Pn=Fe("loginId"),Tn=Fe("origin"),qn=Je(Pn,Tn,Fe("name")),Mn=Je(Pn,Tn),Dn=Je(Rn,Tn),$n=Je(Pn,Tn,Fe("token")),Ln=Je(Fe("transactionId"),Fe("response")),Nn=t=>({signUp:{start:qn(((e,n,o)=>Re(t.post(ce.start,{user:{loginId:e,name:o},origin:n})))),finish:Ln(((e,n)=>Re(t.post(ce.finish,{transactionId:e,response:n}))))},signIn:{start:Dn(((e,n,o,i)=>Re(t.post(ue.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Ln(((e,n)=>Re(t.post(ue.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Mn(((e,n)=>Re(t.post(de.start,{loginId:e,origin:n}))))},update:{start:$n(((e,n,o)=>Re(t.post(he.start,{loginId:e,origin:n},{token:o})))),finish:Ln(((e,n)=>Re(t.post(he.finish,{transactionId:e,response:n}))))}}),Kn=Je(Fe("token"));var Jn,Fn=Je([("projectId",Jn=Fe("projectId"),Pe(((t,e)=>n=>Te(...e).validate($t(n,t)))("projectId",Jn))())])((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={},fetch:s})=>{return a=je({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Ve(a),otp:On(a),magicLink:pn(a),enchantedLink:on(a),oauth:vn(a),saml:En(a),totp:Un(a),webauthn:Nn(a),flow:an(a),refresh:t=>Re(a.post(pe,{},{token:t})),logout:t=>Re(a.post(fe,{},{token:t})),logoutAll:t=>Re(a.post(ge,{},{token:t})),me:t=>Re(a.get(ve,{token:t})),isJwtExpired:Kn(_e),getJwtPermissions:Kn(Ce),getJwtRoles:Kn(Ae),httpClient:a};var a})(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 Wn=(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 Hn=Object.assign(Fn,{DeliveryMethods:Ge});var Bn="Blocked by CSP",Vn="API key required",zn="3.8.2",Gn="9319";function Zn(t,e){var n=[];return function(t,e){var n,o,i=(o=function(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}([],t,!0),{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 e===Bn||e===Gn}(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 Qn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Yn="Failed to load the JS script of the agent";function Xn(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:Qn;return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error(Vn);var t=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(zn):t}))}(String(t),e)}))}(l,s);return Zn(t,to).catch(no)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function to(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(Bn)}();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(Yn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(eo)}function eo(){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(Gn);return n}function no(t){throw t instanceof Error&&t.message===Gn?new Error(Yn):t}
|
|
2
|
-
/*! js-cookie v3.0.1 | MIT */function oo(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 io=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=oo({},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,"",oo({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,oo({},this.attributes,e))},withConverter:function(e){return t(oo({},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 ro=(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},so=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||{}},ao=async t=>{const e=await so(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},lo="undefined"!=typeof localStorage,co=(t,e)=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),uo=t=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),ho=t=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),po="undefined"!=typeof window,fo=po&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",go=(t="",e="")=>({vsid:t,vrid:e}),vo=(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},bo=t=>(t.body&&(t.body.fpData=vo(!0)||go()),t),yo=()=>uo("dls_last_user_login_id"),mo=()=>uo("dls_last_user_display_name"),wo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=yo(),r=mo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},ko=t=>async(...e)=>{const n=await t(...e);return ho("dls_last_user_login_id"),ho("dls_last_user_display_name"),n};function Io(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Oo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&co("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);io.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):co("DS",i))};function jo(){return uo("DSR")||""}function So(){return io.get("DS")||uo("DS")||""}function Eo(){ho("DSR"),ho("DS"),io.remove("DS")}const xo=t=>Object.assign(t,{token:t.token||jo()}),_o=t=>async(...e)=>{const n=await t(...e);return Eo(),n};async function Co(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=qo(n.publicKey.challenge),n.publicKey.user.id=qo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=qo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Mo(n.rawId),type:n.type,response:{attestationObject:Mo(n.response.attestationObject),clientDataJSON:Mo(n.response.clientDataJSON)}});var n}async function Ao(t){const e=Po(t);return To(await navigator.credentials.get(e))}async function Uo(t,e){const n=Po(t);return n.signal=e.signal,n.mediation="conditional",To(await navigator.credentials.get(n))}async function Ro(t=!1){if(!po)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Po(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=qo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=qo(t.id)})),n}function To(t){return JSON.stringify({id:t.id,rawId:Mo(t.rawId),type:t.type,response:{authenticatorData:Mo(t.response.authenticatorData),clientDataJSON:Mo(t.response.clientDataJSON),signature:Mo(t.response.signature),userHandle:t.response.userHandle?Mo(t.response.userHandle):void 0}})}function qo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Mo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Do,$o=(Do=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 Co(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 Ao(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 Co(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Ao(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 Co(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Co,get:Ao,isSupported:Ro,conditional:Uo}}),(...t)=>{const e=Do(...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}),Lo=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Ro(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const No=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?(po?i&&(async t=>{try{if(vo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Xn({apiKey:t,endpoint:fo}),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))})(go(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(ro(r,{beforeRequest:bo}))):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(ro(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await so(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 Wn(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":"1.0.0"},e.baseHeaders)}))),(t=>e=>{const n=Io(),o=Io(),i=t(ro(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await ao(e);t&&o.pub(t);const{sessionJwt:i}=await so(e);i&&n.pub(i)}}})),r=Wn(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(ro(e,{afterRequest:async(t,e)=>{var n;const o=await ao(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=>{co("dls_last_user_login_id",t)})(i),(t=>{co("dls_last_user_display_name",t)})(r))}}));let o=Wn(n,["flow.start"],wo);return o=Wn(o,["logout","logoutAll"],ko),Object.assign(o,{getLastUserLoginId:yo,getLastUserDisplayName:mo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!po)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(ro(r,{beforeRequest:xo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Eo():Oo(await so(e),i)}})),a=Wn(s,["logout","logoutAll"],_o);return Object.assign(a,{getRefreshToken:jo,getSessionToken:So})}))(((...t)=>{const e=Hn(...t);return Object.assign(Object.assign({},e),{flow:Lo(e),webauthn:$o(e)})})),Ko=document.createElement("template");var Jo,Fo,Wo,Ho,Bo,Vo,zo,Go,Zo,Qo,Yo,Xo,ti,ei,ni,oi,ii,ri,si,ai,li,ci,ui,di,hi,pi,fi,gi,vi,bi,yi,mi,wi,ki,Ii,Oi,ji,Si;Ko.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 Ei extends HTMLElement{constructor(t){super(),Jo.add(this),Fo.set(this,!1),Wo.set(this,new $),Ho.set(this,new $),this.nextRequestStatus=new $({isLoading:!1}),Bo.set(this,void 0),Vo.set(this,{popstate:o(this,Jo,"m",Xo).bind(this)}),zo.set(this,void 0),ni.set(this,R((()=>n(this,void 0,void 0,(function*(){const t=E(this.projectId,"config.json");try{const{body:e,headers:n}=yield j(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}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,Jo,"m",ci).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,zo,t,"f"),o(this,Jo,"m",Go).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,ni,"f").call(this);return t}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,ni,"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,Jo,"m",Zo).call(this))return void o(this,Jo,"m",Qo).call(this);o(this,Jo,"m",Yo).call(this),o(this,Jo,"m",ii).call(this),o(this,Jo,"m",oi).call(this),o(this,Jo,"m",ui).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=U();window.addEventListener("popstate",o(this,Vo,"f").popstate),o(this,Wo,"f").subscribe(o(this,Jo,"m",ei).bind(this)),o(this,Ho,"f").subscribe(o(this,Jo,"m",li).bind(this)),o(this,Wo,"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,Ho,"f").update({isDebug:this.debug}),i(this,Fo,!0,"f")}}))}disconnectedCallback(){o(this,Wo,"f").unsubscribeAll(),o(this,Ho,"f").unsubscribeAll(),o(this,Jo,"m",ai).call(this),window.removeEventListener("popstate",o(this,Vo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Fo,"f")&&e!==n&&Ei.observedAttributes.includes(t)){o(this,Jo,"m",Yo).call(this);const i=null===e;o(this,Wo,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,C()),{[A(t)]:n,stepId:r,executionId:s}})),o(this,Ho,"f").update({isDebug:this.debug})}}}Fo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,zo=new WeakMap,ni=new WeakMap,Jo=new WeakSet,Go=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ko.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Zo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Qo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Yo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Ei.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},Xo=function(){const{stepId:t,executionId:e}=_();o(this,Wo,"f").update({stepId:t,executionId:e})},ti=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=No(Object.assign(Object.assign({},Ei.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})}}))}))},ei=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,Jo,"m",ti).call(this,e,n,r)}o(this,zo,"f").call(this,t)}))},oi=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,ni,"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)))}))},ii=function(){o(this,Jo,"m",ri).call(this),o(this,Jo,"m",si).call(this)},ri=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=E(this.projectId,"theme.css");try{const{body:n}=yield j(e,"text");t.innerText=n}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},si=function(){this.rootElement.setAttribute("data-theme",this.theme)},ai=function(){var t;null===(t=o(this,Bo,"f"))||void 0===t||t.remove(),i(this,Bo,null,"f")},li=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-9f02a743.js"),i(this,Bo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Bo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Bo,"f"))):o(this,Jo,"m",ai).call(this)}))},ci=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Bo,"f"))||void 0===n||n.updateData({title:t,description:e}))},ui=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()}},Ei.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.2"}};class xi extends Ei{constructor(){const t=new $;super(t.update.bind(t)),di.add(this),this.stepState=new $({},{updateOnlyOnChange:!1}),hi.set(this,void 0),pi.set(this,null),fi.set(this,(()=>{clearInterval(o(this,hi,"f")),i(this,hi,null,"f")})),gi.set(this,(t=>{var e,n,i,s,a,l,c,u,d;if(!(null==t?void 0:t.ok)){o(this,fi,"f").call(this),o(this,di,"m",Si).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 p=null===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(null===(d=t.data)||void 0===d?void 0:d.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:v,lastAuth:b}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(b),o(this,fi,"f").call(this),void o(this,di,"m",Si).call(this,"success",v);const{executionId:y,stepId:m,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==g?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})})),vi.set(this,R((()=>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){Ei.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,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:u,stepId:d,executionId:p,action:y,screenId:k,screenState:I,redirectTo:O,redirectUrl:j,token:S,code:_,exchangeError:C,webauthnTransactionId:A,webauthnOptions:U}=t;let R,P;o(this,hi,"f")&&o(this,fi,"f").call(this);const T=this.sdk.getLastUserLoginId();if(!p){if(!c)return;const t=yield this.getFlowConfig();if(({startScreenId:R=t.startScreenId,conditionInteractionId:P}=((t,e)=>{var n;const o=null===(n=K[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(t.condition,{loginId:T,code:_})),!R){const t=_?{exchangeCode:_,idpInitiated:!0}:void 0,e=yield this.sdk.flow.start(c,Object.assign({tenant:u},j&&{redirectUrl:j}),P,"",t);return o(this,gi,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0}))}}if(p&&(r("token")&&S||r("code")&&_||r("exchangeError")&&C)){const t=yield this.sdk.flow.next(p,d,m,{token:S,exchangeCode:_,exchangeError:C});return o(this,gi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(y===f)return O||this.logger.error("Did not get redirect url"),void window.location.assign(O);if(y===v||y===b){if(!A||!U)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,pi,"f"))||void 0===a||a.abort(),i(this,pi,null,"f");try{t=y===v?yield this.sdk.webauthn.helpers.create(U):yield this.sdk.webauthn.helpers.get(U)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(p,d,m,{transactionId:A,response:t,cancelWebauthn:e});o(this,gi,"f").call(this,n)}if(y===g&&i(this,hi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,d,w,{});o(this,gi,"f").call(this,t)}))),2e3),"f"),!k&&!R)return void this.logger.info("Refreshing the page during a flow is not supported yet");const q={direction:x(+d,+e.stepId),screenState:Object.assign(Object.assign({},I),{lastAuth:{loginId:T,name:this.sdk.getLastUserDisplayName()||T}}),htmlUrl:E(l,`${R||k}.html`)},M=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}(T);R?q.next=(t,e)=>this.sdk.flow.start(c,{tenant:u,lastAuth:M},P,t,Object.assign(Object.assign({},e),_&&{exchangeCode:_,idpInitiated:!0})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(q.next=(...t)=>this.sdk.flow.next(p,d,...t)),this.stepState.update(q)}))}onStepChange(t,e){var i;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:s,next:a,screenState:l}=t,c=document.createElement("template"),{body:u}=yield j(r,"text");c.innerHTML=u;const d=c.content.cloneNode(!0),h=((t,e)=>{var n;const o=Array.from(t.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=t.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,e);return n.remove(),s}));return null===(n=t.querySelector("scripts"))||void 0===n||n.remove(),o})(d,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,di,"m",yi).call(this,d,a):d.querySelectorAll(`button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(d,l),((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})`))})(d.querySelector("div"),null===(i=null==l?void 0:l.totp)||void 0===i?void 0:i.image);const f=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(d);const t=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),o(this,di,"m",Oi).call(this,a),o(this,di,"m",Si).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield a(w,{});o(this,gi,"f").call(this,t)}}));s?o(this,di,"m",ji).call(this,f,s):f()}))}}hi=new WeakMap,pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,di=new WeakSet,bi=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}))}},yi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,pi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:r}=(yield o(this,vi,"f").call(this))||{};t&&r&&(o(this,di,"m",bi).call(this,s),i(this,pi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,pi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,gi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},mi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},wi=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${d}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},ki=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"))}))},Ii=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,di,"m",mi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,di,"m",ki).call(this,t);const r=o(this,di,"m",wi).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,gi,"f").call(this,l)}var n}))},Oi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,di,"m",Ii).call(this,e,t)}}))},ji=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===k.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")},Si=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",xi);export{xi as D,$ as S,o as _,i as a};
|
|
2
|
+
/*! js-cookie v3.0.1 | MIT */function oo(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 io=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=oo({},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,"",oo({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,oo({},this.attributes,e))},withConverter:function(e){return t(oo({},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 ro=(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},so=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||{}},ao=async t=>{const e=await so(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},lo="undefined"!=typeof localStorage,co=(t,e)=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),uo=t=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),ho=t=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),po="undefined"!=typeof window,fo=po&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",go=(t="",e="")=>({vsid:t,vrid:e}),vo=(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},bo=t=>(t.body&&(t.body.fpData=vo(!0)||go()),t),yo=()=>uo("dls_last_user_login_id"),mo=()=>uo("dls_last_user_display_name"),wo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=yo(),r=mo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},ko=t=>async(...e)=>{const n=await t(...e);return ho("dls_last_user_login_id"),ho("dls_last_user_display_name"),n};function Io(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Oo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&co("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);io.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):co("DS",i))};function jo(){return uo("DSR")||""}function So(){return io.get("DS")||uo("DS")||""}function Eo(){ho("DSR"),ho("DS"),io.remove("DS")}const xo=t=>Object.assign(t,{token:t.token||jo()}),_o=t=>async(...e)=>{const n=await t(...e);return Eo(),n};async function Co(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=qo(n.publicKey.challenge),n.publicKey.user.id=qo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=qo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Mo(n.rawId),type:n.type,response:{attestationObject:Mo(n.response.attestationObject),clientDataJSON:Mo(n.response.clientDataJSON)}});var n}async function Ao(t){const e=Po(t);return To(await navigator.credentials.get(e))}async function Uo(t,e){const n=Po(t);return n.signal=e.signal,n.mediation="conditional",To(await navigator.credentials.get(n))}async function Ro(t=!1){if(!po)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Po(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=qo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=qo(t.id)})),n}function To(t){return JSON.stringify({id:t.id,rawId:Mo(t.rawId),type:t.type,response:{authenticatorData:Mo(t.response.authenticatorData),clientDataJSON:Mo(t.response.clientDataJSON),signature:Mo(t.response.signature),userHandle:t.response.userHandle?Mo(t.response.userHandle):void 0}})}function qo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Mo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Do,$o=(Do=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 Co(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 Ao(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 Co(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Ao(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 Co(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Co,get:Ao,isSupported:Ro,conditional:Uo}}),(...t)=>{const e=Do(...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}),Lo=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Ro(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const No=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?(po?i&&(async t=>{try{if(vo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Xn({apiKey:t,endpoint:fo}),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))})(go(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(ro(r,{beforeRequest:bo}))):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(ro(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await so(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 Wn(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":"1.0.0"},e.baseHeaders)}))),(t=>e=>{const n=Io(),o=Io(),i=t(ro(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await ao(e);t&&o.pub(t);const{sessionJwt:i}=await so(e);i&&n.pub(i)}}})),r=Wn(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(ro(e,{afterRequest:async(t,e)=>{var n;const o=await ao(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=>{co("dls_last_user_login_id",t)})(i),(t=>{co("dls_last_user_display_name",t)})(r))}}));let o=Wn(n,["flow.start"],wo);return o=Wn(o,["logout","logoutAll"],ko),Object.assign(o,{getLastUserLoginId:yo,getLastUserDisplayName:mo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!po)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(ro(r,{beforeRequest:xo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Eo():Oo(await so(e),i)}})),a=Wn(s,["logout","logoutAll"],_o);return Object.assign(a,{getRefreshToken:jo,getSessionToken:So})}))(((...t)=>{const e=Hn(...t);return Object.assign(Object.assign({},e),{flow:Lo(e),webauthn:$o(e)})})),Ko=document.createElement("template");var Jo,Fo,Wo,Ho,Bo,Vo,zo,Go,Zo,Qo,Yo,Xo,ti,ei,ni,oi,ii,ri,si,ai,li,ci,ui,di,hi,pi,fi,gi,vi,bi,yi,mi,wi,ki,Ii,Oi,ji,Si;Ko.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 Ei extends HTMLElement{constructor(t){super(),Jo.add(this),Fo.set(this,!1),Wo.set(this,new $),Ho.set(this,new $),this.nextRequestStatus=new $({isLoading:!1}),Bo.set(this,void 0),Vo.set(this,{popstate:o(this,Jo,"m",Xo).bind(this)}),zo.set(this,void 0),ni.set(this,R((()=>n(this,void 0,void 0,(function*(){const t=E(this.projectId,"config.json");try{const{body:e,headers:n}=yield j(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}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,Jo,"m",ci).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,zo,t,"f"),o(this,Jo,"m",Go).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,ni,"f").call(this);return t}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,ni,"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,Jo,"m",Zo).call(this))return void o(this,Jo,"m",Qo).call(this);o(this,Jo,"m",Yo).call(this),o(this,Jo,"m",ii).call(this),o(this,Jo,"m",oi).call(this),o(this,Jo,"m",ui).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=U();window.addEventListener("popstate",o(this,Vo,"f").popstate),o(this,Wo,"f").subscribe(o(this,Jo,"m",ei).bind(this)),o(this,Ho,"f").subscribe(o(this,Jo,"m",li).bind(this)),o(this,Wo,"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,Ho,"f").update({isDebug:this.debug}),i(this,Fo,!0,"f")}}))}disconnectedCallback(){o(this,Wo,"f").unsubscribeAll(),o(this,Ho,"f").unsubscribeAll(),o(this,Jo,"m",ai).call(this),window.removeEventListener("popstate",o(this,Vo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Fo,"f")&&e!==n&&Ei.observedAttributes.includes(t)){o(this,Jo,"m",Yo).call(this);const i=null===e;o(this,Wo,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,C()),{[A(t)]:n,stepId:r,executionId:s}})),o(this,Ho,"f").update({isDebug:this.debug})}}}Fo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,zo=new WeakMap,ni=new WeakMap,Jo=new WeakSet,Go=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ko.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Zo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Qo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Yo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Ei.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},Xo=function(){const{stepId:t,executionId:e}=_();o(this,Wo,"f").update({stepId:t,executionId:e})},ti=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=No(Object.assign(Object.assign({persistTokens:!0},Ei.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r})),["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})}}))}))},ei=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,Jo,"m",ti).call(this,e,n,r)}o(this,zo,"f").call(this,t)}))},oi=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,ni,"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)))}))},ii=function(){o(this,Jo,"m",ri).call(this),o(this,Jo,"m",si).call(this)},ri=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=E(this.projectId,"theme.css");try{const{body:n}=yield j(e,"text");t.innerText=n}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},si=function(){this.rootElement.setAttribute("data-theme",this.theme)},ai=function(){var t;null===(t=o(this,Bo,"f"))||void 0===t||t.remove(),i(this,Bo,null,"f")},li=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-37141c4a.js"),i(this,Bo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Bo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Bo,"f"))):o(this,Jo,"m",ai).call(this)}))},ci=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Bo,"f"))||void 0===n||n.updateData({title:t,description:e}))},ui=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()}},Ei.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.3"}};class xi extends Ei{constructor(){const t=new $;super(t.update.bind(t)),di.add(this),this.stepState=new $({},{updateOnlyOnChange:!1}),hi.set(this,void 0),pi.set(this,null),fi.set(this,(()=>{clearInterval(o(this,hi,"f")),i(this,hi,null,"f")})),gi.set(this,(t=>{var e,n,i,s,a,l,c,u,d;if(!(null==t?void 0:t.ok)){o(this,fi,"f").call(this),o(this,di,"m",Si).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 p=null===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(null===(d=t.data)||void 0===d?void 0:d.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:v,lastAuth:b}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(b),o(this,fi,"f").call(this),void o(this,di,"m",Si).call(this,"success",v);const{executionId:y,stepId:m,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==g?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})})),vi.set(this,R((()=>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){Ei.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,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:u,stepId:d,executionId:p,action:y,screenId:k,screenState:I,redirectTo:O,redirectUrl:j,token:S,code:_,exchangeError:C,webauthnTransactionId:A,webauthnOptions:U}=t;let R,P;o(this,hi,"f")&&o(this,fi,"f").call(this);const T=this.sdk.getLastUserLoginId();if(!p){if(!c)return;const t=yield this.getFlowConfig();if(({startScreenId:R=t.startScreenId,conditionInteractionId:P}=((t,e)=>{var n;const o=null===(n=K[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(t.condition,{loginId:T,code:_})),!R){const t=_?{exchangeCode:_,idpInitiated:!0}:void 0,e=yield this.sdk.flow.start(c,Object.assign({tenant:u},j&&{redirectUrl:j}),P,"",t);return o(this,gi,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0}))}}if(p&&(r("token")&&S||r("code")&&_||r("exchangeError")&&C)){const t=yield this.sdk.flow.next(p,d,m,{token:S,exchangeCode:_,exchangeError:C});return o(this,gi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(y===f)return O||this.logger.error("Did not get redirect url"),void window.location.assign(O);if(y===v||y===b){if(!A||!U)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,pi,"f"))||void 0===a||a.abort(),i(this,pi,null,"f");try{t=y===v?yield this.sdk.webauthn.helpers.create(U):yield this.sdk.webauthn.helpers.get(U)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(p,d,m,{transactionId:A,response:t,cancelWebauthn:e});o(this,gi,"f").call(this,n)}if(y===g&&i(this,hi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,d,w,{});o(this,gi,"f").call(this,t)}))),2e3),"f"),!k&&!R)return void this.logger.info("Refreshing the page during a flow is not supported yet");const q={direction:x(+d,+e.stepId),screenState:Object.assign(Object.assign({},I),{lastAuth:{loginId:T,name:this.sdk.getLastUserDisplayName()||T}}),htmlUrl:E(l,`${R||k}.html`)},M=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}(T);R?q.next=(t,e)=>this.sdk.flow.start(c,{tenant:u,lastAuth:M},P,t,Object.assign(Object.assign({},e),_&&{exchangeCode:_,idpInitiated:!0})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(q.next=(...t)=>this.sdk.flow.next(p,d,...t)),this.stepState.update(q)}))}onStepChange(t,e){var i;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:s,next:a,screenState:l}=t,c=document.createElement("template"),{body:u}=yield j(r,"text");c.innerHTML=u;const d=c.content.cloneNode(!0),h=((t,e)=>{var n;const o=Array.from(t.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=t.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,e);return n.remove(),s}));return null===(n=t.querySelector("scripts"))||void 0===n||n.remove(),o})(d,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,di,"m",yi).call(this,d,a):d.querySelectorAll(`button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(d,l),((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})`))})(d.querySelector("div"),null===(i=null==l?void 0:l.totp)||void 0===i?void 0:i.image);const f=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(d);const t=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),o(this,di,"m",Oi).call(this,a),o(this,di,"m",Si).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield a(w,{});o(this,gi,"f").call(this,t)}}));s?o(this,di,"m",ji).call(this,f,s):f()}))}}hi=new WeakMap,pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,di=new WeakSet,bi=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}))}},yi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,pi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:r}=(yield o(this,vi,"f").call(this))||{};t&&r&&(o(this,di,"m",bi).call(this,s),i(this,pi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,pi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,gi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},mi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},wi=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${d}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},ki=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"))}))},Ii=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,di,"m",mi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,di,"m",ki).call(this,t);const r=o(this,di,"m",wi).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,gi,"f").call(this,l)}var n}))},Oi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,di,"m",Ii).call(this,e,t)}}))},ji=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===k.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")},Si=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",xi);export{xi as D,$ as S,o as _,i as a};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-9bccbb90.js";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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="t",c="code",u="err",d="data-exclude-field",h="dls_last_auth",p="data-type",f="redirect",g="poll",v="webauthnCreate",m="webauthnGet",b="v2-alpha",w="submit",y="polling";var k;function I(t){return new URLSearchParams(window.location.search).get(t)}function x(t){if(window.history.replaceState&&I(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())}}function O(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{body:yield n[e||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(k||(k={}));const j=(...t)=>t.join("/").replace(/\/+/g,"/");function S(t,e){const n=new URL(s);return n.pathname=j(n.pathname,t,b,e),n.toString()}function C(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?k.forward:t<e?k.backward:void 0}const E=()=>{const[t="",e=""]=(I(a)||"").split("_");return{executionId:t,stepId:e}};function _(){x(a)}const A=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),U=()=>{const{executionId:t,stepId:e}=E();(t||e)&&_();const n=I(l)||void 0;n&&x(l);const o=I(c)||void 0;o&&x(c);const i=I(u)||void 0;return i&&x(u),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},R=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 P,T,L,M;function q(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(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!q(r,s))return!1}else if(r!==s)return!1}return!0}class ${constructor(t={},{updateOnlyOnChange:e=!0}={}){P.set(this,void 0),T.set(this,{}),L.set(this,0),M.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,P,"f")):t,n=Object.assign(Object.assign({},o(this,P,"f")),e);if(!o(this,M,"f")||!q(o(this,P,"f"),n)){const t=o(this,P,"f");i(this,P,n,"f"),Object.freeze(o(this,P,"f")),setTimeout((()=>{Object.values(o(this,T,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,P,t,"f"),i(this,M,e,"f")}get current(){return Object.assign({},o(this,P,"f"))}subscribe(t){return i(this,L,o(this,L,"f")+1,"f"),o(this,T,"f")[o(this,L,"f")]=t,o(this,L,"f").toString()}unsubscribe(t){const e=!!o(this,T,"f")[t];return e&&delete o(this,T,"f")[t],e}unsubscribeAll(){return i(this,T,{},"f"),!0}}P=new WeakMap,T=new WeakMap,L=new WeakMap,M=new WeakMap;const D=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${p}="${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}"]:not([${d}])`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${p}="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)},N=R((()=>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}})))),W=(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))]},F={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};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 H(t){this.message=t}function z(t,e){if("string"!=typeof t)throw new H("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 H("Invalid token specified: "+t.message)}}H.prototype=new Error,H.prototype.name="InvalidTokenError";var B="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},V="Expected a function",Z="__lodash_hash_undefined__",G=1/0,X="[object Function]",Y="[object GeneratorFunction]",Q="[object Symbol]",tt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,et=/^\w*$/,nt=/^\./,ot=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,it=/\\(\\)?/g,rt=/^\[object .+?Constructor\]$/,st="object"==typeof B&&B&&B.Object===Object&&B,at="object"==typeof self&&self&&self.Object===Object&&self,lt=st||at||Function("return this")();var ct,ut=Array.prototype,dt=Function.prototype,ht=Object.prototype,pt=lt["__core-js_shared__"],ft=(ct=/[^.]+$/.exec(pt&&pt.keys&&pt.keys.IE_PROTO||""))?"Symbol(src)_1."+ct:"",gt=dt.toString,vt=ht.hasOwnProperty,mt=ht.toString,bt=RegExp("^"+gt.call(vt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),wt=lt.Symbol,yt=ut.splice,kt=Rt(lt,"Map"),It=Rt(Object,"create"),xt=wt?wt.prototype:void 0,Ot=xt?xt.toString:void 0;function jt(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 St(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 Ct(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 Et(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 _t(t,e){var n;e=function(t,e){if(Mt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||$t(t))return!0;return et.test(t)||!tt.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Mt(n=e)?n:Pt(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Tt(e[o++])];return o&&o==i?t:void 0}function At(t){if(!qt(t)||(e=t,ft&&ft in e))return!1;var e,n=function(t){var e=qt(t)?mt.call(t):"";return e==X||e==Y}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?bt:rt;return n.test(function(t){if(null!=t){try{return gt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function Ut(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 Rt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return At(n)?n:void 0}jt.prototype.clear=function(){this.__data__=It?It(null):{}},jt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},jt.prototype.get=function(t){var e=this.__data__;if(It){var n=e[t];return n===Z?void 0:n}return vt.call(e,t)?e[t]:void 0},jt.prototype.has=function(t){var e=this.__data__;return It?void 0!==e[t]:vt.call(e,t)},jt.prototype.set=function(t,e){return this.__data__[t]=It&&void 0===e?Z:e,this},St.prototype.clear=function(){this.__data__=[]},St.prototype.delete=function(t){var e=this.__data__,n=Et(e,t);return!(n<0)&&(n==e.length-1?e.pop():yt.call(e,n,1),!0)},St.prototype.get=function(t){var e=this.__data__,n=Et(e,t);return n<0?void 0:e[n][1]},St.prototype.has=function(t){return Et(this.__data__,t)>-1},St.prototype.set=function(t,e){var n=this.__data__,o=Et(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},Ct.prototype.clear=function(){this.__data__={hash:new jt,map:new(kt||St),string:new jt}},Ct.prototype.delete=function(t){return Ut(this,t).delete(t)},Ct.prototype.get=function(t){return Ut(this,t).get(t)},Ct.prototype.has=function(t){return Ut(this,t).has(t)},Ct.prototype.set=function(t,e){return Ut(this,t).set(t,e),this};var Pt=Lt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if($t(t))return Ot?Ot.call(t):"";var e=t+"";return"0"==e&&1/t==-G?"-0":e}(e);var n=[];return nt.test(t)&&n.push(""),t.replace(ot,(function(t,e,o,i){n.push(o?i.replace(it,"$1"):e||t)})),n}));function Tt(t){if("string"==typeof t||$t(t))return t;var e=t+"";return"0"==e&&1/t==-G?"-0":e}function Lt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(V);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(Lt.Cache||Ct),n}Lt.Cache=Ct;var Mt=Array.isArray;function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function $t(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&mt.call(t)==Q}var Dt=function(t,e,n){var o=null==t?void 0:_t(t,e);return void 0===o?n:o},Nt="/v1/auth/accesskey/exchange",Wt="/v1/auth/otp/verify",Ft="/v1/auth/otp/signin",Kt="/v1/auth/otp/signup",Jt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Ht="/v1/auth/otp/signup-in",zt="/v1/auth/magiclink/verify",Bt="/v1/auth/magiclink/signin",Vt="/v1/auth/magiclink/signup",Zt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Gt="/v1/auth/magiclink/signup-in",Xt="/v1/auth/enchantedlink/verify",Yt="/v1/auth/enchantedlink/signin",Qt="/v1/auth/enchantedlink/signup",te="/v1/auth/enchantedlink/pending-session",ee={email:"/v1/auth/enchantedlink/update/email"},ne="/v1/auth/enchantedlink/signup-in",oe="/v1/auth/oauth/authorize",ie="/v1/auth/oauth/exchange",re="/v1/auth/saml/authorize",se="/v1/auth/saml/exchange",ae="/v1/auth/totp/verify",le="/v1/auth/totp/signup",ce="/v1/auth/totp/update",ue={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},de={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},he={start:"/v1/auth/webauthn/signup-in/start"},pe={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},fe="/v1/auth/refresh",ge="/v1/auth/logout",ve="/v1/auth/logoutall",me="/v1/auth/me",be="/v1/flow/start",we="/v1/flow/next";const ye=()=>{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 ke;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ke||(ke={}));const Ie=(...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}),{})),xe=t=>void 0===t?void 0:JSON.stringify(t),Oe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},je=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((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=>ye().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)),ye().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o,s),l=async o=>{const s=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=s,f=await a((({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:Ie(Oe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.1"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:xe(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}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:ke.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:ke.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:ke.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:ke.delete,token:i}),hooks:i}};var Se={TOO_MANY_REQUESTS:429};function Ce(t,e,n){var o;let i=Ee(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 Ee(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return z(t)}function _e(t){const{exp:e}=Ee(t);return(new Date).getTime()/1e3>e}function Ae(t,e){return Ce(t,e,"permissions")}function Ue(t,e){return Ce(t,e,"roles")}const Re=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Pe(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===Se.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Te=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Le=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Me=t=>e=>t.test(e),qe=Me(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),$e=Me(/^\+[1-9]{1}[0-9]{3,14}$/),De=Te(qe,'"{val}" is not a valid email'),Ne=Te($e,'"{val}" is not a valid phone number'),We=Te((1,t=>t.length>=1),"Minimum length is 1");const Fe=Te((t=>"string"==typeof t),"Input is not a string"),Ke=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Le(...t).validate(n[e]))),e(...n)),Je=t=>[Fe(`"${t}" must be a string`),We(`"${t}" must not be empty`)],He=t=>[Fe(`"${t}" must be a string`),De()],ze=t=>[Fe(`"${t}" must be a string`),Ne()],Be=Ke(Je("accessKey")),Ve=t=>({exchange:Be((e=>Pe(t.post(Nt,{},{token:e}))))});var Ze,Ge,Xe,Ye;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Ze||(Ze={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ge||(Ge={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Xe||(Xe={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ye||(Ye={}));const Qe=Je("loginId"),tn=Ke(Je("token")),en=Ke(Qe),nn=Ke(Je("pendingRef")),on=Ke(Qe,He("email")),rn=t=>({verify:tn((e=>Pe(t.post(Xt,{token:e})))),signIn:en(((e,n,o,i)=>Pe(t.post(Re(Yt,Ge.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:en(((e,n)=>Pe(t.post(Re(ne,Ge.email),{loginId:e,URI:n})))),signUp:en(((e,n,o)=>Pe(t.post(Re(Qt,Ge.email),{loginId:e,URI:n,user:o})))),waitForSession:nn(((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(te,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Pe(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:on(((e,n,o,i)=>Pe(t.post(ee.email,{loginId:e,email:n,URI:o},{token:i}))))}}),sn=Ke(Je("flowId")),an=Ke(Je("executionId"),Je("stepId"),Je("interactionId")),ln=t=>({start:sn(((e,n,o,i,r)=>Pe(t.post(be,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:an(((e,n,o,i)=>Pe(t.post(we,{executionId:e,stepId:n,interactionId:o,input:i}))))}),cn=Je("loginId"),un=Ke(Je("token")),dn=Ke(cn),hn=Ke(cn,ze("phone")),pn=Ke(cn,He("email")),fn=t=>({verify:un((e=>Pe(t.post(zt,{token:e})))),signIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o,i,r)=>Pe(t.post(Re(Bt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o,i)=>Pe(t.post(Re(Vt,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o)=>Pe(t.post(Re(Gt,n),{loginId:e,URI:o}))))})),{}),update:{email:pn(((e,n,o,i)=>Pe(t.post(Zt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o,i,r)=>Pe(t.post(Re(Zt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var gn;!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"}(gn||(gn={}));const vn=Ke(Je("code")),mn=t=>({start:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(oe,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Pe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:vn((e=>Pe(t.post(ie,{code:e}))))});var bn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(bn||(bn={}));const wn=Je("loginId"),yn=Ke(wn,Je("code")),kn=Ke(wn),In=Ke(wn,ze("phone")),xn=Ke(wn,He("email")),On=t=>({verify:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o)=>Pe(t.post(Re(Wt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:kn(((e,o,i)=>Pe(t.post(Re(Ft,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:kn(((e,o)=>Pe(t.post(Re(Kt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ge).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:kn((e=>Pe(t.post(Re(Ht,n),{loginId:e}))))})),{}),update:{email:xn(((e,n,o)=>Pe(t.post(Jt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:In(((e,o,i)=>Pe(t.post(Re(Jt.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),jn=Ke(Je("tenant")),Sn=Ke(Je("code")),Cn=t=>({start:jn((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(re,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Pe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:Sn((e=>Pe(t.post(se,{code:e}))))}),En=Je("loginId"),_n=Ke(En,Je("code")),An=Ke(En),Un=Ke(En),Rn=t=>({signUp:An(((e,n)=>Pe(t.post(le,{loginId:e,user:n})))),verify:_n(((e,n,o,i)=>Pe(t.post(ae,{loginId:e,code:n,loginOptions:o},{token:i})))),update:Un(((e,n)=>Pe(t.post(ce,{loginId:e},{token:n}))))}),Pn=[Fe('"loginId" must be a string')],Tn=Je("loginId"),Ln=Je("origin"),Mn=Ke(Tn,Ln,Je("name")),qn=Ke(Tn,Ln),$n=Ke(Pn,Ln),Dn=Ke(Tn,Ln,Je("token")),Nn=Ke(Je("transactionId"),Je("response")),Wn=t=>({signUp:{start:Mn(((e,n,o)=>Pe(t.post(ue.start,{user:{loginId:e,name:o},origin:n})))),finish:Nn(((e,n)=>Pe(t.post(ue.finish,{transactionId:e,response:n}))))},signIn:{start:$n(((e,n,o,i)=>Pe(t.post(de.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Nn(((e,n)=>Pe(t.post(de.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:qn(((e,n)=>Pe(t.post(he.start,{loginId:e,origin:n}))))},update:{start:Dn(((e,n,o)=>Pe(t.post(pe.start,{loginId:e,origin:n},{token:o})))),finish:Nn(((e,n)=>Pe(t.post(pe.finish,{transactionId:e,response:n}))))}}),Fn=Ke(Je("token"));var Kn,Jn=Ke([("projectId",Kn=Je("projectId"),Te(((t,e)=>n=>Le(...e).validate(Dt(n,t)))("projectId",Kn))())])((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={},fetch:s})=>{return a=je({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Ve(a),otp:On(a),magicLink:fn(a),enchantedLink:rn(a),oauth:mn(a),saml:Cn(a),totp:Rn(a),webauthn:Wn(a),flow:ln(a),refresh:t=>Pe(a.post(fe,{},{token:t})),logout:t=>Pe(a.post(ge,{},{token:t})),logoutAll:t=>Pe(a.post(ve,{},{token:t})),me:t=>Pe(a.get(me,{token:t})),isJwtExpired:Fn(_e),getJwtPermissions:Fn(Ae),getJwtRoles:Fn(Ue),httpClient:a};var a})(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 Hn=(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 zn=Object.assign(Jn,{DeliveryMethods:Ge});var Bn="Blocked by CSP",Vn="API key required",Zn="3.8.2",Gn="9319";function Xn(t,e){var n=[];return function(t,e){var n,o,i=(o=function(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}([],t,!0),{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 e===Bn||e===Gn}(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 Yn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Qn="Failed to load the JS script of the agent";function to(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:Yn;return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error(Vn);var t=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(Zn):t}))}(String(t),e)}))}(l,s);return Xn(t,eo).catch(oo)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function eo(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(Bn)}();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(Qn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(no)}function no(){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(Gn);return n}function oo(t){throw t instanceof Error&&t.message===Gn?new Error(Qn):t}
|
|
2
|
-
/*! js-cookie v3.0.1 | MIT */function io(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 ro=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=io({},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,"",io({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,io({},this.attributes,e))},withConverter:function(e){return t(io({},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 so=(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},ao=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||{}},lo=async t=>{const e=await ao(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},co="undefined"!=typeof localStorage,uo=(t,e)=>co&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),ho=t=>co&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),po=t=>co&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),fo="undefined"!=typeof window,go=fo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",vo=(t="",e="")=>({vsid:t,vrid:e}),mo=(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},bo=t=>(t.body&&(t.body.fpData=mo(!0)||vo()),t),wo=()=>ho("dls_last_user_login_id"),yo=()=>ho("dls_last_user_display_name"),ko=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=wo(),r=yo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},Io=t=>async(...e)=>{const n=await t(...e);return po("dls_last_user_login_id"),po("dls_last_user_display_name"),n};function xo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Oo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&uo("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);ro.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):uo("DS",i))};function jo(){return ho("DSR")||""}function So(){return ro.get("DS")||ho("DS")||""}function Co(){po("DSR"),po("DS"),ro.remove("DS")}const Eo=t=>Object.assign(t,{token:t.token||jo()}),_o=t=>async(...e)=>{const n=await t(...e);return Co(),n};async function Ao(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Mo(n.publicKey.challenge),n.publicKey.user.id=Mo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Mo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:qo(n.rawId),type:n.type,response:{attestationObject:qo(n.response.attestationObject),clientDataJSON:qo(n.response.clientDataJSON)}});var n}async function Uo(t){const e=To(t);return Lo(await navigator.credentials.get(e))}async function Ro(t,e){const n=To(t);return n.signal=e.signal,n.mediation="conditional",Lo(await navigator.credentials.get(n))}async function Po(t=!1){if(!fo)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function To(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Mo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Mo(t.id)})),n}function Lo(t){return JSON.stringify({id:t.id,rawId:qo(t.rawId),type:t.type,response:{authenticatorData:qo(t.response.authenticatorData),clientDataJSON:qo(t.response.clientDataJSON),signature:qo(t.response.signature),userHandle:t.response.userHandle?qo(t.response.userHandle):void 0}})}function Mo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function qo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var $o,Do=($o=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 Ao(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 Uo(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 Ao(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Uo(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 Ao(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Ao,get:Uo,isSupported:Po,conditional:Ro}}),(...t)=>{const e=$o(...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}),No=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Po(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Wo=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?(fo?i&&(async t=>{try{if(mo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=to({apiKey:t,endpoint:go}),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))})(vo(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(so(r,{beforeRequest:bo}))):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(so(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await ao(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 Hn(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":"1.0.0"},e.baseHeaders)}))),(t=>e=>{const n=xo(),o=xo(),i=t(so(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await lo(e);t&&o.pub(t);const{sessionJwt:i}=await ao(e);i&&n.pub(i)}}})),r=Hn(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(so(e,{afterRequest:async(t,e)=>{var n;const o=await lo(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=>{uo("dls_last_user_login_id",t)})(i),(t=>{uo("dls_last_user_display_name",t)})(r))}}));let o=Hn(n,["flow.start"],ko);return o=Hn(o,["logout","logoutAll"],Io),Object.assign(o,{getLastUserLoginId:wo,getLastUserDisplayName:yo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!fo)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(so(r,{beforeRequest:Eo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Co():Oo(await ao(e),i)}})),a=Hn(s,["logout","logoutAll"],_o);return Object.assign(a,{getRefreshToken:jo,getSessionToken:So})}))(((...t)=>{const e=zn(...t);return Object.assign(Object.assign({},e),{flow:No(e),webauthn:Do(e)})})),Fo=document.createElement("template");var Ko,Jo,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,xi,Oi,ji,Si,Ci,Ei,_i,Ai,Ui,Ri,Pi,Ti,Li,Mi;Fo.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 qi extends HTMLElement{constructor(t){super(),Ko.add(this),Jo.set(this,!1),Ho.set(this,new $),zo.set(this,new $),this.nextRequestStatus=new $({isLoading:!1}),Bo.set(this,void 0),Vo.set(this,{popstate:o(this,Ko,"m",ti).bind(this)}),Zo.set(this,void 0),oi.set(this,R((()=>n(this,void 0,void 0,(function*(){const t=S(this.projectId,"config.json");try{const{body:e,headers:n}=yield O(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}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,Ko,"m",ui).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,Zo,t,"f"),o(this,Ko,"m",Go).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,oi,"f").call(this);return t}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,oi,"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,Ko,"m",Xo).call(this))return void o(this,Ko,"m",Yo).call(this);o(this,Ko,"m",Qo).call(this),o(this,Ko,"m",ri).call(this),o(this,Ko,"m",ii).call(this),o(this,Ko,"m",di).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=U();window.addEventListener("popstate",o(this,Vo,"f").popstate),o(this,Ho,"f").subscribe(o(this,Ko,"m",ni).bind(this)),o(this,zo,"f").subscribe(o(this,Ko,"m",ci).bind(this)),o(this,Ho,"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,zo,"f").update({isDebug:this.debug}),i(this,Jo,!0,"f")}}))}disconnectedCallback(){o(this,Ho,"f").unsubscribeAll(),o(this,zo,"f").unsubscribeAll(),o(this,Ko,"m",li).call(this),window.removeEventListener("popstate",o(this,Vo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Jo,"f")&&e!==n&&qi.observedAttributes.includes(t)){o(this,Ko,"m",Qo).call(this);const i=null===e;o(this,Ho,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,_()),{[A(t)]:n,stepId:r,executionId:s}})),o(this,zo,"f").update({isDebug:this.debug})}}}Jo=new WeakMap,Ho=new WeakMap,zo=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,Zo=new WeakMap,oi=new WeakMap,Ko=new WeakSet,Go=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Fo.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Xo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Yo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Qo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(qi.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},ti=function(){const{stepId:t,executionId:e}=E();o(this,Ho,"f").update({stepId:t,executionId:e})},ei=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=Wo(Object.assign(Object.assign({},qi.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})}}))}))},ni=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,Ko,"m",ei).call(this,e,n,r)}o(this,Zo,"f").call(this,t)}))},ii=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,oi,"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)))}))},ri=function(){o(this,Ko,"m",si).call(this),o(this,Ko,"m",ai).call(this)},si=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=S(this.projectId,"theme.css");try{const{body:n}=yield O(e,"text");t.innerText=n}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},ai=function(){this.rootElement.setAttribute("data-theme",this.theme)},li=function(){var t;null===(t=o(this,Bo,"f"))||void 0===t||t.remove(),i(this,Bo,null,"f")},ci=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return Wi})),i(this,Bo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Bo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Bo,"f"))):o(this,Ko,"m",li).call(this)}))},ui=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Bo,"f"))||void 0===n||n.updateData({title:t,description:e}))},di=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()}},qi.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.2"}};class $i extends qi{constructor(){const t=new $;super(t.update.bind(t)),hi.add(this),this.stepState=new $({},{updateOnlyOnChange:!1}),pi.set(this,void 0),fi.set(this,null),gi.set(this,(()=>{clearInterval(o(this,pi,"f")),i(this,pi,null,"f")})),vi.set(this,(t=>{var e,n,i,s,a,l,c,u,d;if(!(null==t?void 0:t.ok)){o(this,gi,"f").call(this),o(this,hi,"m",Si).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 p=null===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(null===(d=t.data)||void 0===d?void 0:d.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:v,lastAuth:m}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(m),o(this,gi,"f").call(this),void o(this,hi,"m",Si).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:x}=t.data;y!==g?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==x?void 0:x.transactionId,webauthnOptions:null==x?void 0:x.options}):this.flowState.update({action:y})})),mi.set(this,R((()=>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){qi.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,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:u,stepId:d,executionId:p,action:b,screenId:k,screenState:I,redirectTo:x,redirectUrl:O,token:j,code:E,exchangeError:_,webauthnTransactionId:A,webauthnOptions:U}=t;let R,P;o(this,pi,"f")&&o(this,gi,"f").call(this);const T=this.sdk.getLastUserLoginId();if(!p){if(!c)return;const t=yield this.getFlowConfig();if(({startScreenId:R=t.startScreenId,conditionInteractionId:P}=((t,e)=>{var n;const o=null===(n=F[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(t.condition,{loginId:T,code:E})),!R){const t=E?{exchangeCode:E,idpInitiated:!0}:void 0,e=yield this.sdk.flow.start(c,Object.assign({tenant:u},O&&{redirectUrl:O}),P,"",t);return o(this,vi,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0}))}}if(p&&(r("token")&&j||r("code")&&E||r("exchangeError")&&_)){const t=yield this.sdk.flow.next(p,d,w,{token:j,exchangeCode:E,exchangeError:_});return o(this,vi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(b===f)return x||this.logger.error("Did not get redirect url"),void window.location.assign(x);if(b===v||b===m){if(!A||!U)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,fi,"f"))||void 0===a||a.abort(),i(this,fi,null,"f");try{t=b===v?yield this.sdk.webauthn.helpers.create(U):yield this.sdk.webauthn.helpers.get(U)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(p,d,w,{transactionId:A,response:t,cancelWebauthn:e});o(this,vi,"f").call(this,n)}if(b===g&&i(this,pi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,d,y,{});o(this,vi,"f").call(this,t)}))),2e3),"f"),!k&&!R)return void this.logger.info("Refreshing the page during a flow is not supported yet");const L={direction:C(+d,+e.stepId),screenState:Object.assign(Object.assign({},I),{lastAuth:{loginId:T,name:this.sdk.getLastUserDisplayName()||T}}),htmlUrl:S(l,`${R||k}.html`)},M=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}(T);R?L.next=(t,e)=>this.sdk.flow.start(c,{tenant:u,lastAuth:M},P,t,Object.assign(Object.assign({},e),E&&{exchangeCode:E,idpInitiated:!0})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(L.next=(...t)=>this.sdk.flow.next(p,d,...t)),this.stepState.update(L)}))}onStepChange(t,e){var i;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:s,next:a,screenState:l}=t,c=document.createElement("template"),{body:u}=yield O(r,"text");c.innerHTML=u;const d=c.content.cloneNode(!0),h=((t,e)=>{var n;const o=Array.from(t.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=t.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,e);return n.remove(),s}));return null===(n=t.querySelector("scripts"))||void 0===n||n.remove(),o})(d,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,hi,"m",wi).call(this,d,a):d.querySelectorAll(`button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),D(d,l),((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})`))})(d.querySelector("div"),null===(i=null==l?void 0:l.totp)||void 0===i?void 0:i.image);const f=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(d);const t=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),o(this,hi,"m",Oi).call(this,a),o(this,hi,"m",Si).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield a(y,{});o(this,vi,"f").call(this,t)}}));s?o(this,hi,"m",ji).call(this,f,s):f()}))}}pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,mi=new WeakMap,hi=new WeakSet,bi=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}))}},wi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,fi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:r}=(yield o(this,mi,"f").call(this))||{};t&&r&&(o(this,hi,"m",bi).call(this,s),i(this,fi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,fi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,vi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},yi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},ki=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${d}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},Ii=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"))}))},xi=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,hi,"m",yi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,hi,"m",Ii).call(this,t);const r=o(this,hi,"m",ki).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,vi,"f").call(this,l)}var n}))},Oi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,hi,"m",xi).call(this,e,t)}}))},ji=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===k.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")},Si=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",$i);const Di=document.createElement("template");Di.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 Ni extends HTMLElement{constructor(){super(),Ci.add(this),Ei.set(this,new $({messages:[]})),_i.set(this,void 0),Ai.set(this,void 0),Ui.set(this,void 0),Ri.set(this,{resize:o(this,Ci,"m",Mi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Di.content.cloneNode(!0)),i(this,_i,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ai,o(this,_i,"f").querySelector(".content"),"f"),i(this,Ui,o(this,_i,"f").querySelector(".header"),"f")}updateData(t){o(this,Ei,"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]=W(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,_i,"f"),o(this,Ui,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ri,"f").resize),(t=o(this,_i,"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,_i,"f").onresize=o(this,Ci,"m",Li).bind(this),o(this,Ei,"f").subscribe(o(this,Ci,"m",Pi).bind(this))}disconnectedCallback(){o(this,Ei,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ri,"f").resize)}}Ei=new WeakMap,_i=new WeakMap,Ai=new WeakMap,Ui=new WeakMap,Ri=new WeakMap,Ci=new WeakSet,Pi=function(t){o(this,Ci,"m",Ti).call(this,t),o(this,Ci,"m",Li).call(this)},Ti=function(t){o(this,Ai,"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("")},Li=function(){o(this,Ai,"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)}))},Mi=function(){const[t,e]=W(o(this,_i,"f"),Number.parseInt(o(this,_i,"f").style.left,10),Number.parseInt(o(this,_i,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,_i,"f").style.top=`${e}px`,o(this,_i,"f").style.left=`${t}px`},customElements.define("descope-debugger",Ni);var Wi=Object.freeze({__proto__:null,default:Ni})}();
|
|
2
|
+
/*! js-cookie v3.0.1 | MIT */function io(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 ro=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=io({},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,"",io({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,io({},this.attributes,e))},withConverter:function(e){return t(io({},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 so=(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},ao=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||{}},lo=async t=>{const e=await ao(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},co="undefined"!=typeof localStorage,uo=(t,e)=>co&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),ho=t=>co&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),po=t=>co&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),fo="undefined"!=typeof window,go=fo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",vo=(t="",e="")=>({vsid:t,vrid:e}),mo=(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},bo=t=>(t.body&&(t.body.fpData=mo(!0)||vo()),t),wo=()=>ho("dls_last_user_login_id"),yo=()=>ho("dls_last_user_display_name"),ko=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=wo(),r=yo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},Io=t=>async(...e)=>{const n=await t(...e);return po("dls_last_user_login_id"),po("dls_last_user_display_name"),n};function xo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Oo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&uo("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);ro.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):uo("DS",i))};function jo(){return ho("DSR")||""}function So(){return ro.get("DS")||ho("DS")||""}function Co(){po("DSR"),po("DS"),ro.remove("DS")}const Eo=t=>Object.assign(t,{token:t.token||jo()}),_o=t=>async(...e)=>{const n=await t(...e);return Co(),n};async function Ao(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Mo(n.publicKey.challenge),n.publicKey.user.id=Mo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Mo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:qo(n.rawId),type:n.type,response:{attestationObject:qo(n.response.attestationObject),clientDataJSON:qo(n.response.clientDataJSON)}});var n}async function Uo(t){const e=To(t);return Lo(await navigator.credentials.get(e))}async function Ro(t,e){const n=To(t);return n.signal=e.signal,n.mediation="conditional",Lo(await navigator.credentials.get(n))}async function Po(t=!1){if(!fo)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function To(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Mo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Mo(t.id)})),n}function Lo(t){return JSON.stringify({id:t.id,rawId:qo(t.rawId),type:t.type,response:{authenticatorData:qo(t.response.authenticatorData),clientDataJSON:qo(t.response.clientDataJSON),signature:qo(t.response.signature),userHandle:t.response.userHandle?qo(t.response.userHandle):void 0}})}function Mo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function qo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var $o,Do=($o=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 Ao(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 Uo(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 Ao(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Uo(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 Ao(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Ao,get:Uo,isSupported:Po,conditional:Ro}}),(...t)=>{const e=$o(...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}),No=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Po(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Wo=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?(fo?i&&(async t=>{try{if(mo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=to({apiKey:t,endpoint:go}),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))})(vo(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(so(r,{beforeRequest:bo}))):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(so(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await ao(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 Hn(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":"1.0.0"},e.baseHeaders)}))),(t=>e=>{const n=xo(),o=xo(),i=t(so(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await lo(e);t&&o.pub(t);const{sessionJwt:i}=await ao(e);i&&n.pub(i)}}})),r=Hn(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(so(e,{afterRequest:async(t,e)=>{var n;const o=await lo(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=>{uo("dls_last_user_login_id",t)})(i),(t=>{uo("dls_last_user_display_name",t)})(r))}}));let o=Hn(n,["flow.start"],ko);return o=Hn(o,["logout","logoutAll"],Io),Object.assign(o,{getLastUserLoginId:wo,getLastUserDisplayName:yo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!fo)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(so(r,{beforeRequest:Eo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Co():Oo(await ao(e),i)}})),a=Hn(s,["logout","logoutAll"],_o);return Object.assign(a,{getRefreshToken:jo,getSessionToken:So})}))(((...t)=>{const e=zn(...t);return Object.assign(Object.assign({},e),{flow:No(e),webauthn:Do(e)})})),Fo=document.createElement("template");var Ko,Jo,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,xi,Oi,ji,Si,Ci,Ei,_i,Ai,Ui,Ri,Pi,Ti,Li,Mi;Fo.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 qi extends HTMLElement{constructor(t){super(),Ko.add(this),Jo.set(this,!1),Ho.set(this,new $),zo.set(this,new $),this.nextRequestStatus=new $({isLoading:!1}),Bo.set(this,void 0),Vo.set(this,{popstate:o(this,Ko,"m",ti).bind(this)}),Zo.set(this,void 0),oi.set(this,R((()=>n(this,void 0,void 0,(function*(){const t=S(this.projectId,"config.json");try{const{body:e,headers:n}=yield O(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}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,Ko,"m",ui).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,Zo,t,"f"),o(this,Ko,"m",Go).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,oi,"f").call(this);return t}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,oi,"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,Ko,"m",Xo).call(this))return void o(this,Ko,"m",Yo).call(this);o(this,Ko,"m",Qo).call(this),o(this,Ko,"m",ri).call(this),o(this,Ko,"m",ii).call(this),o(this,Ko,"m",di).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=U();window.addEventListener("popstate",o(this,Vo,"f").popstate),o(this,Ho,"f").subscribe(o(this,Ko,"m",ni).bind(this)),o(this,zo,"f").subscribe(o(this,Ko,"m",ci).bind(this)),o(this,Ho,"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,zo,"f").update({isDebug:this.debug}),i(this,Jo,!0,"f")}}))}disconnectedCallback(){o(this,Ho,"f").unsubscribeAll(),o(this,zo,"f").unsubscribeAll(),o(this,Ko,"m",li).call(this),window.removeEventListener("popstate",o(this,Vo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Jo,"f")&&e!==n&&qi.observedAttributes.includes(t)){o(this,Ko,"m",Qo).call(this);const i=null===e;o(this,Ho,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,_()),{[A(t)]:n,stepId:r,executionId:s}})),o(this,zo,"f").update({isDebug:this.debug})}}}Jo=new WeakMap,Ho=new WeakMap,zo=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,Zo=new WeakMap,oi=new WeakMap,Ko=new WeakSet,Go=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Fo.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Xo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Yo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Qo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(qi.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},ti=function(){const{stepId:t,executionId:e}=E();o(this,Ho,"f").update({stepId:t,executionId:e})},ei=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=Wo(Object.assign(Object.assign({persistTokens:!0},qi.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r})),["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})}}))}))},ni=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,Ko,"m",ei).call(this,e,n,r)}o(this,Zo,"f").call(this,t)}))},ii=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,oi,"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)))}))},ri=function(){o(this,Ko,"m",si).call(this),o(this,Ko,"m",ai).call(this)},si=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=S(this.projectId,"theme.css");try{const{body:n}=yield O(e,"text");t.innerText=n}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},ai=function(){this.rootElement.setAttribute("data-theme",this.theme)},li=function(){var t;null===(t=o(this,Bo,"f"))||void 0===t||t.remove(),i(this,Bo,null,"f")},ci=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return Wi})),i(this,Bo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Bo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Bo,"f"))):o(this,Ko,"m",li).call(this)}))},ui=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Bo,"f"))||void 0===n||n.updateData({title:t,description:e}))},di=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()}},qi.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.3"}};class $i extends qi{constructor(){const t=new $;super(t.update.bind(t)),hi.add(this),this.stepState=new $({},{updateOnlyOnChange:!1}),pi.set(this,void 0),fi.set(this,null),gi.set(this,(()=>{clearInterval(o(this,pi,"f")),i(this,pi,null,"f")})),vi.set(this,(t=>{var e,n,i,s,a,l,c,u,d;if(!(null==t?void 0:t.ok)){o(this,gi,"f").call(this),o(this,hi,"m",Si).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 p=null===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(null===(d=t.data)||void 0===d?void 0:d.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:v,lastAuth:m}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(m),o(this,gi,"f").call(this),void o(this,hi,"m",Si).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:x}=t.data;y!==g?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==x?void 0:x.transactionId,webauthnOptions:null==x?void 0:x.options}):this.flowState.update({action:y})})),mi.set(this,R((()=>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){qi.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,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:u,stepId:d,executionId:p,action:b,screenId:k,screenState:I,redirectTo:x,redirectUrl:O,token:j,code:E,exchangeError:_,webauthnTransactionId:A,webauthnOptions:U}=t;let R,P;o(this,pi,"f")&&o(this,gi,"f").call(this);const T=this.sdk.getLastUserLoginId();if(!p){if(!c)return;const t=yield this.getFlowConfig();if(({startScreenId:R=t.startScreenId,conditionInteractionId:P}=((t,e)=>{var n;const o=null===(n=F[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(t.condition,{loginId:T,code:E})),!R){const t=E?{exchangeCode:E,idpInitiated:!0}:void 0,e=yield this.sdk.flow.start(c,Object.assign({tenant:u},O&&{redirectUrl:O}),P,"",t);return o(this,vi,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0}))}}if(p&&(r("token")&&j||r("code")&&E||r("exchangeError")&&_)){const t=yield this.sdk.flow.next(p,d,w,{token:j,exchangeCode:E,exchangeError:_});return o(this,vi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(b===f)return x||this.logger.error("Did not get redirect url"),void window.location.assign(x);if(b===v||b===m){if(!A||!U)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,fi,"f"))||void 0===a||a.abort(),i(this,fi,null,"f");try{t=b===v?yield this.sdk.webauthn.helpers.create(U):yield this.sdk.webauthn.helpers.get(U)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(p,d,w,{transactionId:A,response:t,cancelWebauthn:e});o(this,vi,"f").call(this,n)}if(b===g&&i(this,pi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,d,y,{});o(this,vi,"f").call(this,t)}))),2e3),"f"),!k&&!R)return void this.logger.info("Refreshing the page during a flow is not supported yet");const L={direction:C(+d,+e.stepId),screenState:Object.assign(Object.assign({},I),{lastAuth:{loginId:T,name:this.sdk.getLastUserDisplayName()||T}}),htmlUrl:S(l,`${R||k}.html`)},M=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}(T);R?L.next=(t,e)=>this.sdk.flow.start(c,{tenant:u,lastAuth:M},P,t,Object.assign(Object.assign({},e),E&&{exchangeCode:E,idpInitiated:!0})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(L.next=(...t)=>this.sdk.flow.next(p,d,...t)),this.stepState.update(L)}))}onStepChange(t,e){var i;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:s,next:a,screenState:l}=t,c=document.createElement("template"),{body:u}=yield O(r,"text");c.innerHTML=u;const d=c.content.cloneNode(!0),h=((t,e)=>{var n;const o=Array.from(t.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=t.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,e);return n.remove(),s}));return null===(n=t.querySelector("scripts"))||void 0===n||n.remove(),o})(d,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,hi,"m",wi).call(this,d,a):d.querySelectorAll(`button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),D(d,l),((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})`))})(d.querySelector("div"),null===(i=null==l?void 0:l.totp)||void 0===i?void 0:i.image);const f=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(d);const t=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),o(this,hi,"m",Oi).call(this,a),o(this,hi,"m",Si).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield a(y,{});o(this,vi,"f").call(this,t)}}));s?o(this,hi,"m",ji).call(this,f,s):f()}))}}pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,mi=new WeakMap,hi=new WeakSet,bi=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}))}},wi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,fi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:r}=(yield o(this,mi,"f").call(this))||{};t&&r&&(o(this,hi,"m",bi).call(this,s),i(this,fi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,fi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,vi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},yi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},ki=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${d}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},Ii=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"))}))},xi=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,hi,"m",yi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,hi,"m",Ii).call(this,t);const r=o(this,hi,"m",ki).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,vi,"f").call(this,l)}var n}))},Oi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,hi,"m",xi).call(this,e,t)}}))},ji=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===k.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")},Si=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",$i);const Di=document.createElement("template");Di.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 Ni extends HTMLElement{constructor(){super(),Ci.add(this),Ei.set(this,new $({messages:[]})),_i.set(this,void 0),Ai.set(this,void 0),Ui.set(this,void 0),Ri.set(this,{resize:o(this,Ci,"m",Mi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Di.content.cloneNode(!0)),i(this,_i,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ai,o(this,_i,"f").querySelector(".content"),"f"),i(this,Ui,o(this,_i,"f").querySelector(".header"),"f")}updateData(t){o(this,Ei,"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]=W(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,_i,"f"),o(this,Ui,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ri,"f").resize),(t=o(this,_i,"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,_i,"f").onresize=o(this,Ci,"m",Li).bind(this),o(this,Ei,"f").subscribe(o(this,Ci,"m",Pi).bind(this))}disconnectedCallback(){o(this,Ei,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ri,"f").resize)}}Ei=new WeakMap,_i=new WeakMap,Ai=new WeakMap,Ui=new WeakMap,Ri=new WeakMap,Ci=new WeakSet,Pi=function(t){o(this,Ci,"m",Ti).call(this,t),o(this,Ci,"m",Li).call(this)},Ti=function(t){o(this,Ai,"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("")},Li=function(){o(this,Ai,"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)}))},Mi=function(){const[t,e]=W(o(this,_i,"f"),Number.parseInt(o(this,_i,"f").style.left,10),Number.parseInt(o(this,_i,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,_i,"f").style.top=`${e}px`,o(this,_i,"f").style.left=`${t}px`},customElements.define("descope-debugger",Ni);var Wi=Object.freeze({__proto__:null,default:Ni})}();
|