@descope/web-component 2.4.1 → 2.4.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{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-
|
|
1
|
+
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-cb1f954d.js";import"@descope/web-js-sdk";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 t({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:e(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,a,e(this,l,"f").querySelector(".content"),"f"),n(this,r,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,o,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((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})(e(this,l,"f"),e(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,i,"m",p).bind(this),e(this,o,"f").subscribe(e(this,i,"m",c).bind(this))}disconnectedCallback(){e(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(n){e(this,i,"m",h).call(this,n),e(this,i,"m",p).call(this)},h=function(n){e(this,a,"f").innerHTML=n.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(){e(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[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o from"@descope/web-js-sdk";const n="undefined"!=typeof localStorage,r=n&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",d="code",l="ra-challenge",a="ra-callback",c="ra-initiator",u="data-exclude-field",h="dls_last_auth",f="state_id",v="data-type",p="redirect",g="poll",m="webauthnCreate",b="webauthnGet",w="submit",y="polling";var I,k,C;function S(t){return new URLSearchParams(window.location.search).get(t)}function A(t){if(window.history.replaceState&&S(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function x(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e}`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(I||(I={}));function E(t,e){const i=new URL(r);return i.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(i.pathname,t,"v2-alpha",e),i.toString()}function j(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?I.forward:t<e?I.backward:void 0}const O=()=>{const[t="",e=""]=(S(s)||"").split("_");return{executionId:t,stepId:e}};function U(){A(s)}const L=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),M=()=>{const{executionId:t,stepId:e}=O();(t||e)&&U();const i=S("t")||void 0;i&&A("t");const o=S(d)||void 0;o&&A(d);const n=S("err")||void 0;n&&A("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:u}={redirectAuthCodeChallenge:S(l),redirectAuthCallbackUrl:S(a),redirectAuthInitiator:S(c)};(r||s||u)&&(A(l),A(a),A(c));const h=S(f);return h&&A(f),{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:u,oidcIdpStateId:h}},R=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}},q=null===(C=null===(k=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===k?void 0:k.brands)||void 0===C?void 0:C.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),W=(t,e)=>t&&!e;var T,$,N,P;function K(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const n=i[o],r=t[n],s=e[n];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!K(r,s))return!1}else if(r!==s)return!1}return!0}class D{constructor(t={},{updateOnlyOnChange:o=!0}={}){T.set(this,void 0),$.set(this,{}),N.set(this,0),P.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,T,"f")):t,n=Object.assign(Object.assign({},e(this,T,"f")),o);if(!e(this,P,"f")||!K(e(this,T,"f"),n)){const t=e(this,T,"f");i(this,T,n,"f"),Object.freeze(e(this,T,"f")),setTimeout((()=>{Object.values(e(this,$,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,T,t,"f"),i(this,P,o,"f")}get current(){return Object.assign({},e(this,T,"f"))}subscribe(t){return i(this,N,e(this,N,"f")+1,"f"),e(this,$,"f")[e(this,N,"f")]=t,e(this,N,"f").toString()}unsubscribe(t){const i=!!e(this,$,"f")[t];return i&&delete e(this,$,"f")[t],i}unsubscribeAll(){return i(this,$,{},"f"),!0}}T=new WeakMap,$=new WeakMap,N=new WeakMap,P=new WeakMap;const F=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${u}])`)).forEach((t=>{t.value=i}))}))},H=(t,e)=>{var i;((t,e,i="")=>{t.querySelectorAll(`[${v}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),F(t,null==e?void 0:e.inputs),F(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${v}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(i=null==e?void 0:e.totp)||void 0===i?void 0:i.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},V=R((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const n=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([n,(i=100,new Promise(((t,e)=>{const n=setTimeout((()=>{e(new Error(`Promise timed out after ${i} ms`))}),i);null==o||o((e=>{clearTimeout(n),t(e)}),(t=>{clearTimeout(n),e(t)}))}))).catch((()=>q()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),_={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function z(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}const B=document.createElement("template");var G,J,Q,X,Y,Z,tt,et,it,ot,nt,rt,st,dt,lt,at,ct,ut,ht,ft,vt,pt,gt,mt,bt,wt,yt,It,kt,Ct,St,At,xt,Et,jt,Ot,Ut,Lt,Mt;B.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 Rt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}constructor(o){super(),G.add(this),J.set(this,!1),Q.set(this,new D({deferredRedirect:!1})),X.set(this,new D),this.nextRequestStatus=new D({isLoading:!1}),Y.set(this,void 0),Z.set(this,{popstate:e(this,G,"m",rt).bind(this),visibilitychange:e(this,G,"m",st).bind(this)}),tt.set(this,void 0),at.set(this,R((()=>t(this,void 0,void 0,(function*(){const t=E(this.projectId,"config.json");try{const{body:e,headers:i}=yield x(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),this.logger={error:(t,i="")=>{console.error(t,i,new Error),e(this,G,"m",gt).call(this,t,i)},info:(t,e="")=>{console.log(t,e)}},i(this,tt,o,"f"),e(this,G,"m",et).call(this)}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 i=this.getAttribute("theme");if("os"===i){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 i||"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 t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,at,"f").call(this);return t}))}getFlowConfig(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,at,"f").call(this),n=(null===(i=null==t?void 0:t.flows)||void 0===i?void 0:i[this.flowId])||{};return null!==(o=n.version)&&void 0!==o||(n.version=0),n}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,G,"m",it).call(this))return void e(this,G,"m",ot).call(this);e(this,G,"m",nt).call(this),e(this,G,"m",ut).call(this),e(this,G,"m",ct).call(this),e(this,G,"m",mt).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:d,redirectAuthCodeChallenge:l,redirectAuthInitiator:a,oidcIdpStateId:c}=M();window.addEventListener("popstate",e(this,Z,"f").popstate),window.addEventListener("visibilitychange",e(this,Z,"f").visibilitychange),e(this,Q,"f").subscribe(e(this,G,"m",lt).bind(this)),e(this,X,"f").subscribe(e(this,G,"m",pt).bind(this)),e(this,Q,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:o,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:d,redirectAuthCodeChallenge:l,redirectAuthInitiator:a,oidcIdpStateId:c}),e(this,X,"f").update({isDebug:this.debug}),i(this,J,!0,"f")}}))}disconnectedCallback(){e(this,Q,"f").unsubscribeAll(),e(this,X,"f").unsubscribeAll(),e(this,G,"m",vt).call(this),window.removeEventListener("popstate",e(this,Z,"f").popstate)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,J,"f")&&i!==o&&Rt.observedAttributes.includes(t)){e(this,G,"m",nt).call(this);const n=null===i;e(this,Q,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,U()),{[L(t)]:o,stepId:r,executionId:s}})),e(this,X,"f").update({isDebug:this.debug})}}}J=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,at=new WeakMap,G=new WeakSet,et=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(B.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},it=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},ot=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},nt=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Rt.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[L(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')},rt=function(){const{stepId:t,executionId:i}=O();e(this,Q,"f").update({stepId:t,executionId:i})},st=function(){document.hidden||setTimeout((()=>{e(this,Q,"f").update({deferredRedirect:!1})}),300)},dt=function(e,i,n){const r=n||void 0,s=!!r;this.sdk=o(Object.assign(Object.assign({persistTokens:!0},Rt.sdkConfigOverrides),{projectId:e,baseUrl:i,fpKey:r,fpLoad:s})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},lt=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:r}=i;if(n("projectId")||n("baseUrl")||n("telemetryKey")){if(!t)return;e(this,G,"m",dt).call(this,t,o,r)}e(this,tt,"f").call(this,i)}))},ct=function(){var i,o,n,r;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,at,"f").call(this);null===(r=null===(n=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.typography)||void 0===n?void 0:n.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)))}))},ut=function(){e(this,G,"m",ht).call(this),e(this,G,"m",ft).call(this)},ht=function(){return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=E(this.projectId,"theme.css");try{const{body:i}=yield x(e,"text");t.innerText=i}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},ft=function(){this.rootElement.setAttribute("data-theme",this.theme)},vt=function(){var t;null===(t=e(this,Y,"f"))||void 0===t||t.remove(),i(this,Y,null,"f")},pt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(yield import("./debugger-wc-a7cfdb3e.js"),i(this,Y,document.createElement("descope-debugger"),"f"),Object.assign(e(this,Y,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(e(this,Y,"f"))):e(this,G,"m",vt).call(this)}))},gt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,Y,"f"))||void 0===o||o.updateData({title:t,description:i}))},mt=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 i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Rt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.4.1"}};class qt extends Rt{static set sdkConfigOverrides(t){Rt.sdkConfigOverrides=t}constructor(){const o=new D;super(o.update.bind(o)),bt.add(this),this.stepState=new D({},{updateOnlyOnChange:!1}),wt.set(this,void 0),yt.set(this,null),It.set(this,(()=>{clearInterval(e(this,wt,"f")),i(this,wt,null,"f")})),kt.set(this,(t=>{var i,o,r,s,d,l,a,c,u;if(!(null==t?void 0:t.ok)){e(this,It,"f").call(this),e(this,bt,"m",Mt).call(this,"error",null==t?void 0:t.error);const n=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||n,(null===(d=null==t?void 0:t.error)||void 0===d?void 0:d.errorMessage)||l)}const f=null===(c=null===(a=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===a?void 0:a.state)||void 0===c?void 0:c.errorText;f&&this.logger.error(f),(null===(u=t.data)||void 0===u?void 0:u.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:v,authInfo:p,lastAuth:m}=t.data;if("completed"===v)return function(t){(null==t?void 0:t.authMethod)&&n&&localStorage.setItem(h,JSON.stringify(t))}(m),e(this,It,"f").call(this),void e(this,bt,"m",Mt).call(this,"success",p);const{executionId:b,stepId:w,action:y,screen:I,redirect:k,webauthn:C}=t.data;y!==g?this.flowState.update({stepId:w,executionId:b,action:y,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options}):this.flowState.update({action:y})})),Ct.set(this,R((()=>t(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=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(o,n,r){var s,d;return t(this,void 0,void 0,(function*(){const{projectId:l,flowId:a,tenant:c,stepId:u,executionId:h,action:f,screenId:v,screenState:I,redirectTo:k,redirectUrl:C,token:S,code:A,exchangeError:x,webauthnTransactionId:O,webauthnOptions:U,redirectAuthCodeChallenge:L,redirectAuthCallbackUrl:M,redirectAuthInitiator:R,oidcIdpStateId:q}=o;let T,$;e(this,wt,"f")&&e(this,It,"f").call(this);const N=this.sdk.getLastUserLoginId(),P=yield this.getFlowConfig(),K=M&&L?{callbackUrl:M,codeChallenge:L}:void 0;if(!h&&(P.conditions?({startScreenId:T,conditionInteractionId:$}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i})=>{var o;if("ELSE"===e)return!0;const n=null===(o=_[e])||void 0===o?void 0:o[i];return!!(null==n?void 0:n(t))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:N,code:A},P.conditions)):P.condition?({startScreenId:T,conditionInteractionId:$}=((t,e)=>{var i;const o=null===(i=_[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(P.condition,{loginId:N,code:A})):T=P.startScreenId,!W(T,q))){const t=A?{exchangeCode:A,idpInitiated:!0}:void 0,i=yield this.sdk.flow.start(a,Object.assign(Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:q},C&&{redirectUrl:C}),{lastAuth:z(N)}),$,"",t,P.version);return e(this,kt,"f").call(this,i),void("completed"!==(null===(s=null==i?void 0:i.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0}))}if(h&&(r("token")&&S||r("code")&&A||r("exchangeError")&&x)){const t=yield this.sdk.flow.next(h,u,w,{token:S,exchangeCode:A,exchangeError:x},P.version);return e(this,kt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===p&&(r("redirectTo")||r("deferredRedirect")))return k?"android"===R&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(k):void this.logger.error("Did not get redirect url");if(f===m||f===b){if(!O||!U)return void this.logger.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,yt,"f"))||void 0===d||d.abort(),i(this,yt,null,"f");try{t=f===m?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);o=!0}const n=yield this.sdk.flow.next(h,u,w,{transactionId:O,response:t,cancelWebauthn:o},P.version);e(this,kt,"f").call(this,n)}if(f===g&&i(this,wt,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,y,{},P.version);e(this,kt,"f").call(this,t)}))),2e3),"f"),!v&&!T)return void this.logger.info("Refreshing the page during a flow is not supported yet");const D={direction:j(+u,+n.stepId),screenState:Object.assign(Object.assign({},I),{lastAuth:{loginId:N,name:this.sdk.getLastUserDisplayName()||N}}),htmlUrl:E(l,`${T||v}.html`)},F=z(N);W(T,q)?D.next=(t,e)=>this.sdk.flow.start(a,Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:q,lastAuth:F},C&&{redirectUrl:C}),$,t,Object.assign(Object.assign({},e),A&&{exchangeCode:A,idpInitiated:!0}),P.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(D.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(D)}))}onStepChange(i,o){var n;return t(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:s,next:d,screenState:l}=i,a=document.createElement("template"),{body:c}=yield x(r,"text");a.innerHTML=c;const u=a.content.cloneNode(!0),h=((t,e)=>{var i;const o=Array.from(t.querySelectorAll("script[data-id]")).map((i=>{var o;const n=i.getAttribute("data-id"),r=null===(o=t.getElementById(n))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(i.previousSibling,e);return i.remove(),s}));return null===(i=t.querySelector("scripts"))||void 0===i||i.remove(),o})(u,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield e(this,bt,"m",At).call(this,u,d):u.querySelectorAll(`button[${v}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),H(u,l),((t,e)=>{var i;e&&(null===(i=null==t?void 0:t.style)||void 0===i||i.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(u.querySelector("div"),null===(n=null==l?void 0:l.totp)||void 0===n?void 0:n.image);const f=()=>t(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(u);const t=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),e(this,bt,"m",Ut).call(this,d),e(this,bt,"m",Mt).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${v}="polling"]`)){const t=yield d(y,{});e(this,kt,"f").call(this,t)}}));s?e(this,bt,"m",Lt).call(this,f,s):f()}))}}wt=new WeakMap,yt=new WeakMap,It=new WeakMap,kt=new WeakMap,Ct=new WeakMap,bt=new WeakSet,St=function(t){const e=t.name;if(!["email"].includes(e)){const i=`user-${e}`;t.name=i,t.addEventListener("input",(()=>{t.name=t.value?e:i}))}},At=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,yt,"f"))||void 0===r||r.abort();const s=o.querySelector('input[autocomplete="webauthn"]');if(s&&(yield V())){const{options:o,transactionId:r}=(yield e(this,Ct,"f").call(this))||{};o&&r&&(e(this,bt,"m",St).call(this,s),i(this,yt,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(o,e(this,yt,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,{transactionId:r,response:i});e(this,kt,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},xt=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},Et=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${u}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e["checkbox"===e.type?"checked":"value"]}):t),{})},jt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{var o,n;i?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(n=null==t?void 0:t.classList)||void 0===n||n.remove("loading"))}))},Ot=function(i,o){return t(this,void 0,void 0,(function*(){if(i.formNoValidate||e(this,bt,"m",xt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,bt,"m",jt).call(this,i);const r=e(this,bt,"m",Et).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),d=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),l=yield o(n,d);e(this,kt,"f").call(this,l)}var t}))},Ut=function(t){this.rootElement.querySelectorAll("button").forEach((i=>{i.onclick=()=>{e(this,bt,"m",Ot).call(this,i,t)}}))},Lt=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===I.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(i)})),this.rootElement.classList.add("fade-out")},Mt=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",qt);export{qt as D,D as S};
|
|
1
|
+
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o from"@descope/web-js-sdk";const n="undefined"!=typeof localStorage,r=n&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",d="code",l="ra-challenge",a="ra-callback",c="ra-initiator",u="data-exclude-field",h="dls_last_auth",f="state_id",v="data-type",p="redirect",g="poll",m="webauthnCreate",b="webauthnGet",w="submit",y="polling";var I,k,C;function S(t){return new URLSearchParams(window.location.search).get(t)}function A(t){if(window.history.replaceState&&S(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function x(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e}`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(I||(I={}));function E(t,e){const i=new URL(r);return i.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(i.pathname,t,"v2-alpha",e),i.toString()}function j(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?I.forward:t<e?I.backward:void 0}const O=()=>{const[t="",e=""]=(S(s)||"").split("_");return{executionId:t,stepId:e}};function U(){A(s)}const L=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),M=()=>{const{executionId:t,stepId:e}=O();(t||e)&&U();const i=S("t")||void 0;i&&A("t");const o=S(d)||void 0;o&&A(d);const n=S("err")||void 0;n&&A("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:u}={redirectAuthCodeChallenge:S(l),redirectAuthCallbackUrl:S(a),redirectAuthInitiator:S(c)};(r||s||u)&&(A(l),A(a),A(c));const h=S(f);return h&&A(f),{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:u,oidcIdpStateId:h}},R=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}},q=null===(C=null===(k=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===k?void 0:k.brands)||void 0===C?void 0:C.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),W=(t,e)=>t&&!e;var T,$,N,P;function K(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const n=i[o],r=t[n],s=e[n];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!K(r,s))return!1}else if(r!==s)return!1}return!0}class D{constructor(t={},{updateOnlyOnChange:o=!0}={}){T.set(this,void 0),$.set(this,{}),N.set(this,0),P.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,T,"f")):t,n=Object.assign(Object.assign({},e(this,T,"f")),o);if(!e(this,P,"f")||!K(e(this,T,"f"),n)){const t=e(this,T,"f");i(this,T,n,"f"),Object.freeze(e(this,T,"f")),setTimeout((()=>{Object.values(e(this,$,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,T,t,"f"),i(this,P,o,"f")}get current(){return Object.assign({},e(this,T,"f"))}subscribe(t){return i(this,N,e(this,N,"f")+1,"f"),e(this,$,"f")[e(this,N,"f")]=t,e(this,N,"f").toString()}unsubscribe(t){const i=!!e(this,$,"f")[t];return i&&delete e(this,$,"f")[t],i}unsubscribeAll(){return i(this,$,{},"f"),!0}}T=new WeakMap,$=new WeakMap,N=new WeakMap,P=new WeakMap;const F=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${u}])`)).forEach((t=>{t.value=i}))}))},H=(t,e)=>{var i;((t,e,i="")=>{t.querySelectorAll(`[${v}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),F(t,null==e?void 0:e.inputs),F(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${v}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(i=null==e?void 0:e.totp)||void 0===i?void 0:i.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},V=R((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const n=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([n,(i=100,new Promise(((t,e)=>{const n=setTimeout((()=>{e(new Error(`Promise timed out after ${i} ms`))}),i);null==o||o((e=>{clearTimeout(n),t(e)}),(t=>{clearTimeout(n),e(t)}))}))).catch((()=>q()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),_={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function z(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}const B=document.createElement("template");var G,J,Q,X,Y,Z,tt,et,it,ot,nt,rt,st,dt,lt,at,ct,ut,ht,ft,vt,pt,gt,mt,bt,wt,yt,It,kt,Ct,St,At,xt,Et,jt,Ot,Ut,Lt,Mt;B.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 Rt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}constructor(o){super(),G.add(this),J.set(this,!1),Q.set(this,new D({deferredRedirect:!1})),X.set(this,new D),this.nextRequestStatus=new D({isLoading:!1}),Y.set(this,void 0),Z.set(this,{popstate:e(this,G,"m",rt).bind(this),visibilitychange:e(this,G,"m",st).bind(this)}),tt.set(this,void 0),at.set(this,R((()=>t(this,void 0,void 0,(function*(){const t=E(this.projectId,"config.json");try{const{body:e,headers:i}=yield x(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),this.logger={error:(t,i="")=>{console.error(t,i,new Error),e(this,G,"m",gt).call(this,t,i)},info:(t,e="")=>{console.log(t,e)}},i(this,tt,o,"f"),e(this,G,"m",et).call(this)}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 i=this.getAttribute("theme");if("os"===i){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 i||"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 t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,at,"f").call(this);return t}))}getFlowConfig(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,at,"f").call(this),n=(null===(i=null==t?void 0:t.flows)||void 0===i?void 0:i[this.flowId])||{};return null!==(o=n.version)&&void 0!==o||(n.version=0),n}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,G,"m",it).call(this))return void e(this,G,"m",ot).call(this);e(this,G,"m",nt).call(this),e(this,G,"m",ut).call(this),e(this,G,"m",ct).call(this),e(this,G,"m",mt).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:d,redirectAuthCodeChallenge:l,redirectAuthInitiator:a,oidcIdpStateId:c}=M();window.addEventListener("popstate",e(this,Z,"f").popstate),window.addEventListener("visibilitychange",e(this,Z,"f").visibilitychange),e(this,Q,"f").subscribe(e(this,G,"m",lt).bind(this)),e(this,X,"f").subscribe(e(this,G,"m",pt).bind(this)),e(this,Q,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:o,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:d,redirectAuthCodeChallenge:l,redirectAuthInitiator:a,oidcIdpStateId:c}),e(this,X,"f").update({isDebug:this.debug}),i(this,J,!0,"f")}}))}disconnectedCallback(){e(this,Q,"f").unsubscribeAll(),e(this,X,"f").unsubscribeAll(),e(this,G,"m",vt).call(this),window.removeEventListener("popstate",e(this,Z,"f").popstate)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,J,"f")&&i!==o&&Rt.observedAttributes.includes(t)){e(this,G,"m",nt).call(this);const n=null===i;e(this,Q,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,U()),{[L(t)]:o,stepId:r,executionId:s}})),e(this,X,"f").update({isDebug:this.debug})}}}J=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,at=new WeakMap,G=new WeakSet,et=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(B.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},it=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},ot=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},nt=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Rt.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[L(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')},rt=function(){const{stepId:t,executionId:i}=O();e(this,Q,"f").update({stepId:t,executionId:i})},st=function(){document.hidden||setTimeout((()=>{e(this,Q,"f").update({deferredRedirect:!1})}),300)},dt=function(e,i,n){const r=n||void 0,s=!!r;this.sdk=o(Object.assign(Object.assign({persistTokens:!0},Rt.sdkConfigOverrides),{projectId:e,baseUrl:i,fpKey:r,fpLoad:s})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},lt=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:r}=i;if(n("projectId")||n("baseUrl")||n("telemetryKey")){if(!t)return;e(this,G,"m",dt).call(this,t,o,r)}e(this,tt,"f").call(this,i)}))},ct=function(){var i,o,n,r;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,at,"f").call(this);null===(r=null===(n=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.typography)||void 0===n?void 0:n.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)))}))},ut=function(){e(this,G,"m",ht).call(this),e(this,G,"m",ft).call(this)},ht=function(){return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=E(this.projectId,"theme.css");try{const{body:i}=yield x(e,"text");t.innerText=i}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},ft=function(){this.rootElement.setAttribute("data-theme",this.theme)},vt=function(){var t;null===(t=e(this,Y,"f"))||void 0===t||t.remove(),i(this,Y,null,"f")},pt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(yield import("./debugger-wc-60b30355.js"),i(this,Y,document.createElement("descope-debugger"),"f"),Object.assign(e(this,Y,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(e(this,Y,"f"))):e(this,G,"m",vt).call(this)}))},gt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,Y,"f"))||void 0===o||o.updateData({title:t,description:i}))},mt=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 i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Rt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.4.3"}};class qt extends Rt{static set sdkConfigOverrides(t){Rt.sdkConfigOverrides=t}constructor(){const o=new D;super(o.update.bind(o)),bt.add(this),this.stepState=new D({},{updateOnlyOnChange:!1}),wt.set(this,void 0),yt.set(this,null),It.set(this,(()=>{clearInterval(e(this,wt,"f")),i(this,wt,null,"f")})),kt.set(this,(t=>{var i,o,r,s,d,l,a,c,u;if(!(null==t?void 0:t.ok)){e(this,It,"f").call(this),e(this,bt,"m",Mt).call(this,"error",null==t?void 0:t.error);const n=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||n,(null===(d=null==t?void 0:t.error)||void 0===d?void 0:d.errorMessage)||l)}const f=null===(c=null===(a=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===a?void 0:a.state)||void 0===c?void 0:c.errorText;f&&this.logger.error(f),(null===(u=t.data)||void 0===u?void 0:u.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:v,authInfo:p,lastAuth:m}=t.data;if("completed"===v)return function(t){(null==t?void 0:t.authMethod)&&n&&localStorage.setItem(h,JSON.stringify(t))}(m),e(this,It,"f").call(this),void e(this,bt,"m",Mt).call(this,"success",p);const{executionId:b,stepId:w,action:y,screen:I,redirect:k,webauthn:C}=t.data;y!==g?this.flowState.update({stepId:w,executionId:b,action:y,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options}):this.flowState.update({action:y})})),Ct.set(this,R((()=>t(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=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(o,n,r){var s,d;return t(this,void 0,void 0,(function*(){const{projectId:l,flowId:a,tenant:c,stepId:u,executionId:h,action:f,screenId:v,screenState:I,redirectTo:k,redirectUrl:C,token:S,code:A,exchangeError:x,webauthnTransactionId:O,webauthnOptions:U,redirectAuthCodeChallenge:L,redirectAuthCallbackUrl:M,redirectAuthInitiator:R,oidcIdpStateId:q}=o;let T,$;e(this,wt,"f")&&e(this,It,"f").call(this);const N=this.sdk.getLastUserLoginId(),P=yield this.getFlowConfig(),K=M&&L?{callbackUrl:M,codeChallenge:L}:void 0;if(!h&&(P.conditions?({startScreenId:T,conditionInteractionId:$}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i})=>{var o;if("ELSE"===e)return!0;const n=null===(o=_[e])||void 0===o?void 0:o[i];return!!(null==n?void 0:n(t))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:N,code:A},P.conditions)):P.condition?({startScreenId:T,conditionInteractionId:$}=((t,e)=>{var i;const o=null===(i=_[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(P.condition,{loginId:N,code:A})):T=P.startScreenId,!W(T,q))){const t=A?{exchangeCode:A,idpInitiated:!0}:void 0,i=yield this.sdk.flow.start(a,Object.assign(Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:q},C&&{redirectUrl:C}),{lastAuth:z(N)}),$,"",t,P.version);return e(this,kt,"f").call(this,i),void("completed"!==(null===(s=null==i?void 0:i.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0}))}if(h&&(r("token")&&S||r("code")&&A||r("exchangeError")&&x)){const t=yield this.sdk.flow.next(h,u,w,{token:S,exchangeCode:A,exchangeError:x},P.version);return e(this,kt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===p&&(r("redirectTo")||r("deferredRedirect")))return k?"android"===R&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(k):void this.logger.error("Did not get redirect url");if(f===m||f===b){if(!O||!U)return void this.logger.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,yt,"f"))||void 0===d||d.abort(),i(this,yt,null,"f");try{t=f===m?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);o=!0}const n=yield this.sdk.flow.next(h,u,w,{transactionId:O,response:t,cancelWebauthn:o},P.version);e(this,kt,"f").call(this,n)}if(f===g&&i(this,wt,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,y,{},P.version);e(this,kt,"f").call(this,t)}))),2e3),"f"),!v&&!T)return void this.logger.info("Refreshing the page during a flow is not supported yet");const D={direction:j(+u,+n.stepId),screenState:Object.assign(Object.assign({},I),{lastAuth:{loginId:N,name:this.sdk.getLastUserDisplayName()||N}}),htmlUrl:E(l,`${T||v}.html`)},F=z(N);W(T,q)?D.next=(t,e)=>this.sdk.flow.start(a,Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:q,lastAuth:F},C&&{redirectUrl:C}),$,t,Object.assign(Object.assign({},e),A&&{exchangeCode:A,idpInitiated:!0}),P.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(D.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(D)}))}onStepChange(i,o){var n;return t(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:s,next:d,screenState:l}=i,a=document.createElement("template"),{body:c}=yield x(r,"text");a.innerHTML=c;const u=a.content.cloneNode(!0),h=((t,e)=>{var i;const o=Array.from(t.querySelectorAll("script[data-id]")).map((i=>{var o;const n=i.getAttribute("data-id"),r=null===(o=t.getElementById(n))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(i.previousSibling,e);return i.remove(),s}));return null===(i=t.querySelector("scripts"))||void 0===i||i.remove(),o})(u,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield e(this,bt,"m",At).call(this,u,d):u.querySelectorAll(`button[${v}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),H(u,l),((t,e)=>{var i;e&&(null===(i=null==t?void 0:t.style)||void 0===i||i.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(u.querySelector("div"),null===(n=null==l?void 0:l.totp)||void 0===n?void 0:n.image);const f=()=>t(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(u);const t=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),e(this,bt,"m",Ut).call(this,d),e(this,bt,"m",Mt).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${v}="polling"]`)){const t=yield d(y,{});e(this,kt,"f").call(this,t)}}));s?e(this,bt,"m",Lt).call(this,f,s):f()}))}}wt=new WeakMap,yt=new WeakMap,It=new WeakMap,kt=new WeakMap,Ct=new WeakMap,bt=new WeakSet,St=function(t){const e=t.name;if(!["email"].includes(e)){const i=`user-${e}`;t.name=i,t.addEventListener("input",(()=>{t.name=t.value?e:i}))}},At=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,yt,"f"))||void 0===r||r.abort();const s=o.querySelector('input[autocomplete="webauthn"]');if(s&&(yield V())){const{options:o,transactionId:r}=(yield e(this,Ct,"f").call(this))||{};o&&r&&(e(this,bt,"m",St).call(this,s),i(this,yt,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(o,e(this,yt,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,{transactionId:r,response:i});e(this,kt,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},xt=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},Et=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${u}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e["checkbox"===e.type?"checked":"value"]}):t),{})},jt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{var o,n;i?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(n=null==t?void 0:t.classList)||void 0===n||n.remove("loading"))}))},Ot=function(i,o){return t(this,void 0,void 0,(function*(){if(i.formNoValidate||e(this,bt,"m",xt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,bt,"m",jt).call(this,i);const r=e(this,bt,"m",Et).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),d=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),l=yield o(n,d);e(this,kt,"f").call(this,l)}var t}))},Ut=function(t){this.rootElement.querySelectorAll("button").forEach((i=>{i.onclick=()=>{e(this,bt,"m",Ot).call(this,i,t)}}))},Lt=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===I.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(i)})),this.rootElement.classList.add("fade-out")},Mt=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",qt);export{qt as D,D as S};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-cb1f954d.js";import"tslib";import"@descope/web-js-sdk";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="ra-challenge",d="ra-callback",u="ra-initiator",h="data-exclude-field",p="dls_last_auth",f="state_id",g="data-type",v="redirect",m="poll",b="webauthnCreate",w="webauthnGet",y="submit",I="polling";var k,O,x;function j(t){return new URLSearchParams(window.location.search).get(t)}function C(t){if(window.history.replaceState&&j(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 S(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={}));function A(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function E(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?k.forward:t<e?k.backward:void 0}const _=()=>{const[t="",e=""]=(j(a)||"").split("_");return{executionId:t,stepId:e}};function U(){C(a)}const P=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),R=()=>{const{executionId:t,stepId:e}=_();(t||e)&&U();const n=j("t")||void 0;n&&C("t");const o=j(l)||void 0;o&&C(l);const i=j("err")||void 0;i&&C("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a}={redirectAuthCodeChallenge:j(c),redirectAuthCallbackUrl:j(d),redirectAuthInitiator:j(u)};(r||s||a)&&(C(c),C(d),C(u));const h=j(f);return h&&C(f),{executionId:t,stepId:e,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a,oidcIdpStateId:h}},T=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}},L=null===(x=null===(O=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===O?void 0:O.brands)||void 0===x?void 0:x.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),M=(t,e)=>t&&!e;var q,$,D,N;function W(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(!W(r,s))return!1}else if(r!==s)return!1}return!0}class F{constructor(t={},{updateOnlyOnChange:e=!0}={}){q.set(this,void 0),$.set(this,{}),D.set(this,0),N.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,q,"f")):t,n=Object.assign(Object.assign({},o(this,q,"f")),e);if(!o(this,N,"f")||!W(o(this,q,"f"),n)){const t=o(this,q,"f");i(this,q,n,"f"),Object.freeze(o(this,q,"f")),setTimeout((()=>{Object.values(o(this,$,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,q,t,"f"),i(this,N,e,"f")}get current(){return Object.assign({},o(this,q,"f"))}subscribe(t){return i(this,D,o(this,D,"f")+1,"f"),o(this,$,"f")[o(this,D,"f")]=t,o(this,D,"f").toString()}unsubscribe(t){const e=!!o(this,$,"f")[t];return e&&delete o(this,$,"f")[t],e}unsubscribeAll(){return i(this,$,{},"f"),!0}}q=new WeakMap,$=new WeakMap,D=new WeakMap,N=new WeakMap;const K=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${h}])`)).forEach((t=>{t.value=n}))}))},J=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${g}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),K(t,null==e?void 0:e.inputs),K(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${g}="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)},H=T((()=>n(void 0,void 0,void 0,(function*(){var t,e,n,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const i=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([i,(n=100,new Promise(((t,e)=>{const i=setTimeout((()=>{e(new Error(`Promise timed out after ${n} ms`))}),n);null==o||o((e=>{clearTimeout(i),t(e)}),(t=>{clearTimeout(i),e(t)}))}))).catch((()=>L()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),z=(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))]},B={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function V(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(p)))}catch(t){}return e}function Z(t){this.message=t}Z.prototype=new Error,Z.prototype.name="InvalidCharacterError";var G="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Z("'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 X(t){this.message=t}function Y(t,e){if("string"!=typeof t)throw new X("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(G(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 G(e)}}(t.split(".")[n]))}catch(t){throw new X("Invalid token specified: "+t.message)}}X.prototype=new Error,X.prototype.name="InvalidTokenError";var Q="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function tt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var et="__lodash_hash_undefined__",nt=1/0,ot="[object Function]",it="[object GeneratorFunction]",rt="[object Symbol]",st=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,at=/^\w*$/,lt=/^\./,ct=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dt=/\\(\\)?/g,ut=/^\[object .+?Constructor\]$/,ht="object"==typeof Q&&Q&&Q.Object===Object&&Q,pt="object"==typeof self&&self&&self.Object===Object&&self,ft=ht||pt||Function("return this")();var gt,vt=Array.prototype,mt=Function.prototype,bt=Object.prototype,wt=ft["__core-js_shared__"],yt=(gt=/[^.]+$/.exec(wt&&wt.keys&&wt.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",It=mt.toString,kt=bt.hasOwnProperty,Ot=bt.toString,xt=RegExp("^"+It.call(kt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),jt=ft.Symbol,Ct=vt.splice,St=$t(ft,"Map"),At=$t(Object,"create"),Et=jt?jt.prototype:void 0,_t=Et?Et.toString:void 0;function Ut(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 Pt(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 Rt(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 Tt(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 Lt(t,e){var n;e=function(t,e){if(Ft(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Jt(t))return!0;return at.test(t)||!st.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ft(n=e)?n:Dt(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Nt(e[o++])];return o&&o==i?t:void 0}function Mt(t){if(!Kt(t)||(e=t,yt&&yt in e))return!1;var e,n=function(t){var e=Kt(t)?Ot.call(t):"";return e==ot||e==it}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?xt:ut;return n.test(function(t){if(null!=t){try{return It.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function qt(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 $t(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return Mt(n)?n:void 0}Ut.prototype.clear=function(){this.__data__=At?At(null):{}},Ut.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},Ut.prototype.get=function(t){var e=this.__data__;if(At){var n=e[t];return n===et?void 0:n}return kt.call(e,t)?e[t]:void 0},Ut.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:kt.call(e,t)},Ut.prototype.set=function(t,e){return this.__data__[t]=At&&void 0===e?et:e,this},Pt.prototype.clear=function(){this.__data__=[]},Pt.prototype.delete=function(t){var e=this.__data__,n=Tt(e,t);return!(n<0)&&(n==e.length-1?e.pop():Ct.call(e,n,1),!0)},Pt.prototype.get=function(t){var e=this.__data__,n=Tt(e,t);return n<0?void 0:e[n][1]},Pt.prototype.has=function(t){return Tt(this.__data__,t)>-1},Pt.prototype.set=function(t,e){var n=this.__data__,o=Tt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},Rt.prototype.clear=function(){this.__data__={hash:new Ut,map:new(St||Pt),string:new Ut}},Rt.prototype.delete=function(t){return qt(this,t).delete(t)},Rt.prototype.get=function(t){return qt(this,t).get(t)},Rt.prototype.has=function(t){return qt(this,t).has(t)},Rt.prototype.set=function(t,e){return qt(this,t).set(t,e),this};var Dt=Wt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Jt(t))return _t?_t.call(t):"";var e=t+"";return"0"==e&&1/t==-nt?"-0":e}(e);var n=[];return lt.test(t)&&n.push(""),t.replace(ct,(function(t,e,o,i){n.push(o?i.replace(dt,"$1"):e||t)})),n}));function Nt(t){if("string"==typeof t||Jt(t))return t;var e=t+"";return"0"==e&&1/t==-nt?"-0":e}function Wt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(Wt.Cache||Rt),n}Wt.Cache=Rt;var Ft=Array.isArray;function Kt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Jt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&Ot.call(t)==rt}var Ht=tt((function(t,e,n){var o=null==t?void 0:Lt(t,e);return void 0===o?n:o})),zt="/v1/auth/accesskey/exchange",Bt="/v1/auth/otp/verify",Vt="/v1/auth/otp/signin",Zt="/v1/auth/otp/signup",Gt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Xt="/v1/auth/otp/signup-in",Yt="/v1/auth/magiclink/verify",Qt="/v1/auth/magiclink/signin",te="/v1/auth/magiclink/signup",ee={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ne="/v1/auth/magiclink/signup-in",oe="/v1/auth/enchantedlink/verify",ie="/v1/auth/enchantedlink/signin",re="/v1/auth/enchantedlink/signup",se="/v1/auth/enchantedlink/pending-session",ae={email:"/v1/auth/enchantedlink/update/email"},le="/v1/auth/enchantedlink/signup-in",ce="/v1/auth/oauth/authorize",de="/v1/auth/oauth/exchange",ue="/v1/auth/saml/authorize",he="/v1/auth/saml/exchange",pe="/v1/auth/totp/verify",fe="/v1/auth/totp/signup",ge="/v1/auth/totp/update",ve={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},me={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},be={start:"/v1/auth/webauthn/signup-in/start"},we={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ye="/v1/auth/password/signup",Ie="/v1/auth/password/signin",ke="/v1/auth/password/reset",Oe="/v1/auth/password/update",xe="/v1/auth/password/replace",je="/v1/auth/password/policy",Ce="/v1/auth/refresh",Se="/v1/auth/logout",Ae="/v1/auth/logoutall",Ee="/v1/auth/me",_e="/v1/flow/start",Ue="/v1/flow/next";const Pe=6e5,Re=()=>{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 Te;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Te||(Te={}));const Le=(...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}),{})),Me=t=>void 0===t?void 0:JSON.stringify(t),qe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},$e=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const n=(t=>async(...e)=>{const n=await t(...e),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,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=>Re().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.text();return Re().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:d,queryParams:u,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:u}),{headers:Le(qe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.7"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:Me(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:Te.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Te.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Te.put,token:i}),delete:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:Te.delete,token:o}),hooks:i}};var De=429;function Ne(t,e,n){var o;let i=We(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 We(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return Y(t)}function Fe(t){const{exp:e}=We(t);return(new Date).getTime()/1e3>e}function Ke(t,e){return Ne(t,e,"permissions")}function Je(t,e){return Ne(t,e,"roles")}const He=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function ze(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===De&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Be=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ve=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ze=t=>e=>t.test(e),Ge=Ze(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Xe=Ze(/^\+[1-9]{1}[0-9]{3,14}$/),Ye=Be(Ge,'"{val}" is not a valid email'),Qe=Be(Xe,'"{val}" is not a valid phone number'),tn=Be((1,t=>t.length>=1),"Minimum length is 1");const en=Be((t=>"string"==typeof t),"Input is not a string"),nn=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ve(...t).validate(n[e]))),e(...n)),on=t=>[en(`"${t}" must be a string`),tn(`"${t}" must not be empty`)],rn=t=>[en(`"${t}" must be a string`),Ye()],sn=t=>[en(`"${t}" must be a string`),Qe()],an=nn(on("accessKey")),ln=t=>({exchange:an((e=>ze(t.post(zt,{},{token:e}))))});var cn,dn;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(cn||(cn={})),function(t){t.email="email"}(dn||(dn={}));const un=Object.assign(Object.assign({},cn),dn);var hn;!function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(hn||(hn={}));const pn=on("loginId"),fn=nn(on("token")),gn=nn(pn),vn=nn(on("pendingRef")),mn=nn(pn,rn("email")),bn=t=>({verify:fn((e=>ze(t.post(oe,{token:e})))),signIn:gn(((e,n,o,i)=>ze(t.post(He(ie,un.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:gn(((e,n)=>ze(t.post(He(le,un.email),{loginId:e,URI:n})))),signUp:gn(((e,n,o)=>ze(t.post(He(re,un.email),{loginId:e,URI:n,user:o})))),waitForSession:vn(((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||Pe,Pe)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(se,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ze(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:mn(((e,n,o,i,r)=>ze(t.post(ae.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i}))))}}),wn=nn(on("flowId")),yn=nn(on("executionId"),on("stepId"),on("interactionId")),In=t=>({start:wn(((e,n,o,i,r,s)=>ze(t.post(_e,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r,version:s})))),next:yn(((e,n,o,i,r)=>ze(t.post(Ue,{executionId:e,stepId:n,interactionId:o,input:i,version:r}))))}),kn=on("loginId"),On=nn(on("token")),xn=nn(kn),jn=nn(kn,sn("phone")),Cn=nn(kn,rn("email")),Sn=t=>({verify:On((e=>ze(t.post(Yt,{token:e})))),signIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:xn(((e,o,i,r)=>ze(t.post(He(Qt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:xn(((e,o,i)=>ze(t.post(He(te,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:xn(((e,o)=>ze(t.post(He(ne,n),{loginId:e,URI:o}))))})),{}),update:{email:Cn(((e,n,o,i,r)=>ze(t.post(ee.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i})))),phone:Object.keys(cn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:jn(((e,o,i,r,s)=>ze(t.post(He(ee.phone,n),Object.assign({loginId:e,phone:o,URI:i},s),{token:r}))))})),{})}});var An;!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"}(An||(An={}));const En=nn(on("code")),_n=t=>({start:Object.keys(An).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:(e,o,i)=>ze(t.post(ce,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i}))})),{}),exchange:En((e=>ze(t.post(de,{code:e}))))}),Un=on("loginId"),Pn=nn(Un,on("code")),Rn=nn(Un),Tn=nn(Un,sn("phone")),Ln=nn(Un,rn("email")),Mn=t=>({verify:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Pn(((e,o)=>ze(t.post(He(Bt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Rn(((e,o,i)=>ze(t.post(He(Vt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Rn(((e,o)=>ze(t.post(He(Zt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Rn((e=>ze(t.post(He(Xt,n),{loginId:e}))))})),{}),update:{email:Ln(((e,n,o,i)=>ze(t.post(Gt.email,Object.assign({loginId:e,email:n},i),{token:o})))),phone:Object.keys(cn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Tn(((e,o,i,r)=>ze(t.post(He(Gt.phone,n),Object.assign({loginId:e,phone:o},r),{token:i}))))})),{})}}),qn=nn(on("tenant")),$n=nn(on("code")),Dn=t=>({start:qn(((e,n,o,i)=>ze(t.post(ue,o||{},{queryParams:{tenant:e,redirectURL:n},token:i})))),exchange:$n((e=>ze(t.post(he,{code:e}))))}),Nn=on("loginId"),Wn=nn(Nn,on("code")),Fn=nn(Nn),Kn=nn(Nn),Jn=t=>({signUp:Fn(((e,n)=>ze(t.post(fe,{loginId:e,user:n})))),verify:Wn(((e,n,o,i)=>ze(t.post(pe,{loginId:e,code:n,loginOptions:o},{token:i})))),update:Kn(((e,n)=>ze(t.post(ge,{loginId:e},{token:n}))))}),Hn=on("loginId"),zn=on("newPassword"),Bn=nn(Hn,on("password")),Vn=nn(Hn),Zn=nn(Hn,zn),Gn=nn(Hn,on("oldPassword"),zn),Xn=t=>({signUp:Bn(((e,n,o)=>ze(t.post(ye,{loginId:e,password:n,user:o})))),signIn:Bn(((e,n)=>ze(t.post(Ie,{loginId:e,password:n})))),sendReset:Vn(((e,n)=>ze(t.post(ke,{loginId:e,redirectUrl:n})))),update:Zn(((e,n,o)=>ze(t.post(Oe,{loginId:e,newPassword:n},{token:o})))),replace:Gn(((e,n,o)=>ze(t.post(xe,{loginId:e,oldPassword:n,newPassword:o})))),policy:()=>ze(t.get(je))}),Yn=[en('"loginId" must be a string')],Qn=on("loginId"),to=on("origin"),eo=nn(Qn,to,on("name")),no=nn(Qn,to),oo=nn(Yn,to),io=nn(Qn,to,on("token")),ro=nn(on("transactionId"),on("response")),so=t=>({signUp:{start:eo(((e,n,o)=>ze(t.post(ve.start,{user:{loginId:e,name:o},origin:n})))),finish:ro(((e,n)=>ze(t.post(ve.finish,{transactionId:e,response:n}))))},signIn:{start:oo(((e,n,o,i)=>ze(t.post(me.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:ro(((e,n)=>ze(t.post(me.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:no(((e,n)=>ze(t.post(be.start,{loginId:e,origin:n}))))},update:{start:io(((e,n,o)=>ze(t.post(we.start,{loginId:e,origin:n},{token:o})))),finish:ro(((e,n)=>ze(t.post(we.finish,{transactionId:e,response:n}))))}}),ao=nn(on("token"));var lo,co=nn([("projectId",lo=on("projectId"),Be(((t,e)=>n=>Ve(...e).validate(Ht(n,t)))("projectId",lo))())])((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=$e({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:ln(a),otp:Mn(a),magicLink:Sn(a),enchantedLink:bn(a),oauth:_n(a),saml:Dn(a),totp:Jn(a),webauthn:so(a),password:Xn(a),flow:In(a),refresh:t=>ze(a.post(Ce,{},{token:t})),logout:t=>ze(a.post(Se,{},{token:t})),logoutAll:t=>ze(a.post(Ae,{},{token:t})),me:t=>ze(a.get(Ee,{token:t})),isJwtExpired:ao(Fe),getJwtPermissions:ao(Ke),getJwtRoles:ao(Je),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 uo=(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 ho=Object.assign(co,{DeliveryMethods:un});var po="Blocked by CSP",fo="9319";function go(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===po||e===fo}(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 vo="Failed to load the JS script of the agent";function mo(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");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("3.8.3"):t}))}(String(t),e)}))}(l,s);return go(t,bo).catch(yo)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function bo(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(po)}();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(vo))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(wo)}function wo(){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(fo);return n}function yo(t){throw t instanceof Error&&t.message===fo?new Error(vo):t}
|
|
2
|
-
/*! js-cookie v3.0.5 | 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 ko=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 Oo=(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},xo=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||{}},jo=async t=>{const e=await xo(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Co="undefined"!=typeof localStorage,So=(t,e)=>Co&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Ao=t=>Co&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Eo=t=>Co&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),_o="undefined"!=typeof window,Uo=_o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Po=(t="",e="")=>({vsid:t,vrid:e}),Ro=(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},To=t=>(t.body&&(t.body.fpData=Ro(!0)||Po()),t),Lo="dls_last_user_login_id",Mo="dls_last_user_display_name",qo=()=>Ao(Lo),$o=()=>Ao(Mo),Do=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=qo(),r=$o();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},No=t=>async(...e)=>{const n=await t(...e);return Eo(Lo),Eo(Mo),n};function Wo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Fo="DS",Ko="DSR",Jo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&So(Ko,o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);ko.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Fo,i,r):So(Fo,i))};function Ho(){return Ao(Ko)||""}function zo(){return ko.get(Fo)||Ao(Fo)||""}function Bo(){Eo(Ko),Eo(Fo),ko.remove(Fo)}const Vo=t=>Object.assign(t,{token:t.token||Ho()}),Zo=t=>async(...e)=>{const n=await t(...e);return Bo(),n};async function Go(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ni(n.publicKey.challenge),n.publicKey.user.id=ni(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=ni(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:oi(n.rawId),type:n.type,response:{attestationObject:oi(n.response.attestationObject),clientDataJSON:oi(n.response.clientDataJSON)}});var n}async function Xo(t){const e=ti(t);return ei(await navigator.credentials.get(e))}async function Yo(t,e){const n=ti(t);return n.signal=e.signal,n.mediation="conditional",ei(await navigator.credentials.get(n))}async function Qo(t=!1){if(!_o)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function ti(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ni(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=ni(t.id)})),n}function ei(t){return JSON.stringify({id:t.id,rawId:oi(t.rawId),type:t.type,response:{authenticatorData:oi(t.response.authenticatorData),clientDataJSON:oi(t.response.clientDataJSON),signature:oi(t.response.signature),userHandle:t.response.userHandle?oi(t.response.userHandle):void 0}})}function ni(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function oi(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var ii,ri=(ii=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 Go(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 Xo(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 Go(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Xo(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 Go(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Go,get:Xo,isSupported:Qo,conditional:Yo}}),(...t)=>{const e=ii(...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}),si=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Qo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const ai=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?(_o?i&&(async t=>{try{if(Ro())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=mo({apiKey:t,endpoint:Uo}),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))})(Po(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(Oo(r,{beforeRequest:To}))):t(Object.assign({},r))}),(t=>n=>{var{autoRefresh:o}=n,i=e(n,["autoRefresh"]);if(!o)return t(i);const{clearAllTimers:r,setTimer:s}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),a=t(Oo(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await xo(e);if(401===(null==e?void 0:e.status))r();else if(o){const t=((i=(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))?i.getTime()-(new Date).getTime():0)-2e4;r(),s((()=>a.refresh(n)),t)}var i}}));return uo(a,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.2.7"},e.baseHeaders)}))),(t=>e=>{const n=Wo(),o=Wo(),i=t(Oo(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await jo(e);t&&o.pub(t);const{sessionJwt:i}=await xo(e);i&&n.pub(i)}}})),r=uo(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(Oo(e,{afterRequest:async(t,e)=>{var n;const o=await jo(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=>{So(Lo,t)})(i),(t=>{So(Mo,t)})(r))}}));let o=uo(n,["flow.start"],Do);return o=uo(o,["logout","logoutAll"],No),Object.assign(o,{getLastUserLoginId:qo,getLastUserDisplayName:$o})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!_o)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(Oo(r,{beforeRequest:Vo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Bo():Jo(await xo(e),i)}})),a=uo(s,["logout","logoutAll"],Zo);return Object.assign(a,{getRefreshToken:Ho,getSessionToken:zo})}))(((...t)=>{const e=ho(...t);return Object.assign(Object.assign({},e),{flow:si(e),webauthn:ri(e)})})),li=document.createElement("template");var ci,di,ui,hi,pi,fi,gi,vi,mi,bi,wi,yi,Ii,ki,Oi,xi,ji,Ci,Si,Ai,Ei,_i,Ui,Pi,Ri,Ti,Li,Mi,qi,$i,Di,Ni,Wi,Fi,Ki,Ji,Hi,zi,Bi,Vi,Zi,Gi,Xi,Yi,Qi,tr,er,nr,or;li.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 ir extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}constructor(t){super(),ci.add(this),di.set(this,!1),ui.set(this,new F({deferredRedirect:!1})),hi.set(this,new F),this.nextRequestStatus=new F({isLoading:!1}),pi.set(this,void 0),fi.set(this,{popstate:o(this,ci,"m",yi).bind(this),visibilitychange:o(this,ci,"m",Ii).bind(this)}),gi.set(this,void 0),xi.set(this,T((()=>n(this,void 0,void 0,(function*(){const t=A(this.projectId,"config.json");try{const{body:e,headers:n}=yield S(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")}return{}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,ci,"m",Ui).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,gi,t,"f"),o(this,ci,"m",vi).call(this)}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,xi,"f").call(this);return t}))}getFlowConfig(){var t,e;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,xi,"f").call(this),i=(null===(t=null==n?void 0:n.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=i.version)&&void 0!==e||(i.version=0),i}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,ci,"m",mi).call(this))return void o(this,ci,"m",bi).call(this);o(this,ci,"m",wi).call(this),o(this,ci,"m",Ci).call(this),o(this,ci,"m",ji).call(this),o(this,ci,"m",Pi).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}=R();window.addEventListener("popstate",o(this,fi,"f").popstate),window.addEventListener("visibilitychange",o(this,fi,"f").visibilitychange),o(this,ui,"f").subscribe(o(this,ci,"m",Oi).bind(this)),o(this,hi,"f").subscribe(o(this,ci,"m",_i).bind(this)),o(this,ui,"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,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}),o(this,hi,"f").update({isDebug:this.debug}),i(this,di,!0,"f")}}))}disconnectedCallback(){o(this,ui,"f").unsubscribeAll(),o(this,hi,"f").unsubscribeAll(),o(this,ci,"m",Ei).call(this),window.removeEventListener("popstate",o(this,fi,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,di,"f")&&e!==n&&ir.observedAttributes.includes(t)){o(this,ci,"m",wi).call(this);const i=null===e;o(this,ui,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,U()),{[P(t)]:n,stepId:r,executionId:s}})),o(this,hi,"f").update({isDebug:this.debug})}}}di=new WeakMap,ui=new WeakMap,hi=new WeakMap,pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,xi=new WeakMap,ci=new WeakSet,vi=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(li.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},mi=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},bi=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},wi=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(ir.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[P(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')},yi=function(){const{stepId:t,executionId:e}=_();o(this,ui,"f").update({stepId:t,executionId:e})},Ii=function(){document.hidden||setTimeout((()=>{o(this,ui,"f").update({deferredRedirect:!1})}),300)},ki=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=ai(Object.assign(Object.assign({persistTokens:!0},ir.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})}}))}))},Oi=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,ci,"m",ki).call(this,e,n,r)}o(this,gi,"f").call(this,t)}))},ji=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,xi,"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)))}))},Ci=function(){o(this,ci,"m",Si).call(this),o(this,ci,"m",Ai).call(this)},Si=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=A(this.projectId,"theme.css");try{const{body:n}=yield S(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)},Ei=function(){var t;null===(t=o(this,pi,"f"))||void 0===t||t.remove(),i(this,pi,null,"f")},_i=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return lr})),i(this,pi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,pi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,pi,"f"))):o(this,ci,"m",Ei).call(this)}))},Ui=function(t,e){var n;t&&this.debug&&(null===(n=o(this,pi,"f"))||void 0===n||n.updateData({title:t,description:e}))},Pi=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()}},ir.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.4.1"}};class rr extends ir{static set sdkConfigOverrides(t){ir.sdkConfigOverrides=t}constructor(){const t=new F;super(t.update.bind(t)),Ri.add(this),this.stepState=new F({},{updateOnlyOnChange:!1}),Ti.set(this,void 0),Li.set(this,null),Mi.set(this,(()=>{clearInterval(o(this,Ti,"f")),i(this,Ti,null,"f")})),qi.set(this,(t=>{var e,n,i,s,a,l,c,d,u;if(!(null==t?void 0:t.ok)){o(this,Mi,"f").call(this),o(this,Ri,"m",Bi).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(d=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===d?void 0:d.errorText;h&&this.logger.error(h),(null===(u=t.data)||void 0===u?void 0:u.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:g,lastAuth:v}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(p,JSON.stringify(t))}(v),o(this,Mi,"f").call(this),void o(this,Ri,"m",Bi).call(this,"success",g);const{executionId:b,stepId:w,action:y,screen:I,redirect:k,webauthn:O}=t.data;y!==m?this.flowState.update({stepId:w,executionId:b,action:y,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:y})})),$i.set(this,T((()=>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}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:d,stepId:u,executionId:h,action:p,screenId:f,screenState:g,redirectTo:k,redirectUrl:O,token:x,code:j,exchangeError:C,webauthnTransactionId:S,webauthnOptions:_,redirectAuthCodeChallenge:U,redirectAuthCallbackUrl:P,redirectAuthInitiator:R,oidcIdpStateId:T}=t;let L,q;o(this,Ti,"f")&&o(this,Mi,"f").call(this);const $=this.sdk.getLastUserLoginId(),D=yield this.getFlowConfig(),N=P&&U?{callbackUrl:P,codeChallenge:U}:void 0;if(!h&&(D.conditions?({startScreenId:L,conditionInteractionId:q}=((t,e)=>{const n=null==e?void 0:e.find((({key:e,operator:n})=>{var o;if("ELSE"===e)return!0;const i=null===(o=B[e])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(t))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:$,code:j},D.conditions)):D.condition?({startScreenId:L,conditionInteractionId:q}=((t,e)=>{var n;const o=null===(n=B[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}})(D.condition,{loginId:$,code:j})):L=D.startScreenId,!M(L,T))){const t=j?{exchangeCode:j,idpInitiated:!0}:void 0,e=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:d,redirectAuth:N,oidcIdpStateId:T},O&&{redirectUrl:O}),{lastAuth:V($)}),q,"",t,D.version);return o(this,qi,"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(h&&(r("token")&&x||r("code")&&j||r("exchangeError")&&C)){const t=yield this.sdk.flow.next(h,u,y,{token:x,exchangeCode:j,exchangeError:C},D.version);return o(this,qi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===v&&(r("redirectTo")||r("deferredRedirect")))return k?"android"===R&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(k):void this.logger.error("Did not get redirect url");if(p===b||p===w){if(!S||!_)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,Li,"f"))||void 0===a||a.abort(),i(this,Li,null,"f");try{t=p===b?yield this.sdk.webauthn.helpers.create(_):yield this.sdk.webauthn.helpers.get(_)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(h,u,y,{transactionId:S,response:t,cancelWebauthn:e},D.version);o(this,qi,"f").call(this,n)}if(p===m&&i(this,Ti,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,I,{},D.version);o(this,qi,"f").call(this,t)}))),2e3),"f"),!f&&!L)return void this.logger.info("Refreshing the page during a flow is not supported yet");const W={direction:E(+u,+e.stepId),screenState:Object.assign(Object.assign({},g),{lastAuth:{loginId:$,name:this.sdk.getLastUserDisplayName()||$}}),htmlUrl:A(l,`${L||f}.html`)},F=V($);M(L,T)?W.next=(t,e)=>this.sdk.flow.start(c,Object.assign({tenant:d,redirectAuth:N,oidcIdpStateId:T,lastAuth:F},O&&{redirectUrl:O}),q,t,Object.assign(Object.assign({},e),j&&{exchangeCode:j,idpInitiated:!0}),D.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(W.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(W)}))}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:d}=yield S(r,"text");c.innerHTML=d;const u=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})(u,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,Ri,"m",Ni).call(this,u,a):u.querySelectorAll(`button[${g}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),J(u,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})`))})(u.querySelector("div"),null===(i=null==l?void 0:l.totp)||void 0===i?void 0:i.image);const p=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(u);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,Ri,"m",Hi).call(this,a),o(this,Ri,"m",Bi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${g}="polling"]`)){const t=yield a(I,{});o(this,qi,"f").call(this,t)}}));s?o(this,Ri,"m",zi).call(this,p,s):p()}))}}Ti=new WeakMap,Li=new WeakMap,Mi=new WeakMap,qi=new WeakMap,$i=new WeakMap,Ri=new WeakSet,Di=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}))}},Ni=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,Li,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield H())){const{options:t,transactionId:r}=(yield o(this,$i,"f").call(this))||{};t&&r&&(o(this,Ri,"m",Di).call(this,s),i(this,Li,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,Li,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,qi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},Wi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},Fi=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${h}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e["checkbox"===e.type?"checked":"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"))}))},Ji=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Ri,"m",Wi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,Ri,"m",Ki).call(this,t);const r=o(this,Ri,"m",Fi).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,qi,"f").call(this,l)}var n}))},Hi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,Ri,"m",Ji).call(this,e,t)}}))},zi=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")},Bi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",rr);const sr=document.createElement("template");sr.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 ar extends HTMLElement{constructor(){super(),Vi.add(this),Zi.set(this,new F({messages:[]})),Gi.set(this,void 0),Xi.set(this,void 0),Yi.set(this,void 0),Qi.set(this,{resize:o(this,Vi,"m",or).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(sr.content.cloneNode(!0)),i(this,Gi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Xi,o(this,Gi,"f").querySelector(".content"),"f"),i(this,Yi,o(this,Gi,"f").querySelector(".header"),"f")}updateData(t){o(this,Zi,"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]=z(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,Gi,"f"),o(this,Yi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Qi,"f").resize),(t=o(this,Gi,"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,Gi,"f").onresize=o(this,Vi,"m",nr).bind(this),o(this,Zi,"f").subscribe(o(this,Vi,"m",tr).bind(this))}disconnectedCallback(){o(this,Zi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Qi,"f").resize)}}Zi=new WeakMap,Gi=new WeakMap,Xi=new WeakMap,Yi=new WeakMap,Qi=new WeakMap,Vi=new WeakSet,tr=function(t){o(this,Vi,"m",er).call(this,t),o(this,Vi,"m",nr).call(this)},er=function(t){o(this,Xi,"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("")},nr=function(){o(this,Xi,"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)}))},or=function(){const[t,e]=z(o(this,Gi,"f"),Number.parseInt(o(this,Gi,"f").style.left,10),Number.parseInt(o(this,Gi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Gi,"f").style.top=`${e}px`,o(this,Gi,"f").style.left=`${t}px`},customElements.define("descope-debugger",ar);var lr=Object.freeze({__proto__:null,default:ar})}();
|
|
1
|
+
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="ra-challenge",d="ra-callback",u="ra-initiator",h="data-exclude-field",p="dls_last_auth",f="state_id",g="data-type",v="redirect",m="poll",b="webauthnCreate",w="webauthnGet",y="submit",I="polling";var k,O,x;function j(t){return new URLSearchParams(window.location.search).get(t)}function C(t){if(window.history.replaceState&&j(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 S(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={}));function A(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function E(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?k.forward:t<e?k.backward:void 0}const _=()=>{const[t="",e=""]=(j(a)||"").split("_");return{executionId:t,stepId:e}};function U(){C(a)}const R=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),P=()=>{const{executionId:t,stepId:e}=_();(t||e)&&U();const n=j("t")||void 0;n&&C("t");const o=j(l)||void 0;o&&C(l);const i=j("err")||void 0;i&&C("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a}={redirectAuthCodeChallenge:j(c),redirectAuthCallbackUrl:j(d),redirectAuthInitiator:j(u)};(r||s||a)&&(C(c),C(d),C(u));const h=j(f);return h&&C(f),{executionId:t,stepId:e,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a,oidcIdpStateId:h}},T=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}},L=null===(x=null===(O=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===O?void 0:O.brands)||void 0===x?void 0:x.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),M=(t,e)=>t&&!e;var q,$,D,N;function W(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(!W(r,s))return!1}else if(r!==s)return!1}return!0}class F{constructor(t={},{updateOnlyOnChange:e=!0}={}){q.set(this,void 0),$.set(this,{}),D.set(this,0),N.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,q,"f")):t,n=Object.assign(Object.assign({},o(this,q,"f")),e);if(!o(this,N,"f")||!W(o(this,q,"f"),n)){const t=o(this,q,"f");i(this,q,n,"f"),Object.freeze(o(this,q,"f")),setTimeout((()=>{Object.values(o(this,$,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,q,t,"f"),i(this,N,e,"f")}get current(){return Object.assign({},o(this,q,"f"))}subscribe(t){return i(this,D,o(this,D,"f")+1,"f"),o(this,$,"f")[o(this,D,"f")]=t,o(this,D,"f").toString()}unsubscribe(t){const e=!!o(this,$,"f")[t];return e&&delete o(this,$,"f")[t],e}unsubscribeAll(){return i(this,$,{},"f"),!0}}q=new WeakMap,$=new WeakMap,D=new WeakMap,N=new WeakMap;const K=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${h}])`)).forEach((t=>{t.value=n}))}))},J=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${g}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),K(t,null==e?void 0:e.inputs),K(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${g}="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)},H=T((()=>n(void 0,void 0,void 0,(function*(){var t,e,n,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const i=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([i,(n=100,new Promise(((t,e)=>{const i=setTimeout((()=>{e(new Error(`Promise timed out after ${n} ms`))}),n);null==o||o((e=>{clearTimeout(i),t(e)}),(t=>{clearTimeout(i),e(t)}))}))).catch((()=>L()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),z=(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))]},B={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function V(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(p)))}catch(t){}return e}function Z(t){this.message=t}Z.prototype=new Error,Z.prototype.name="InvalidCharacterError";var G="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Z("'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 X(t){this.message=t}function Y(t,e){if("string"!=typeof t)throw new X("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(G(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 G(e)}}(t.split(".")[n]))}catch(t){throw new X("Invalid token specified: "+t.message)}}X.prototype=new Error,X.prototype.name="InvalidTokenError";var Q="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function tt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var et="__lodash_hash_undefined__",nt=1/0,ot="[object Function]",it="[object GeneratorFunction]",rt="[object Symbol]",st=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,at=/^\w*$/,lt=/^\./,ct=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dt=/\\(\\)?/g,ut=/^\[object .+?Constructor\]$/,ht="object"==typeof Q&&Q&&Q.Object===Object&&Q,pt="object"==typeof self&&self&&self.Object===Object&&self,ft=ht||pt||Function("return this")();var gt,vt=Array.prototype,mt=Function.prototype,bt=Object.prototype,wt=ft["__core-js_shared__"],yt=(gt=/[^.]+$/.exec(wt&&wt.keys&&wt.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",It=mt.toString,kt=bt.hasOwnProperty,Ot=bt.toString,xt=RegExp("^"+It.call(kt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),jt=ft.Symbol,Ct=vt.splice,St=$t(ft,"Map"),At=$t(Object,"create"),Et=jt?jt.prototype:void 0,_t=Et?Et.toString:void 0;function Ut(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 Rt(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 Pt(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 Tt(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 Lt(t,e){var n;e=function(t,e){if(Ft(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Jt(t))return!0;return at.test(t)||!st.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ft(n=e)?n:Dt(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Nt(e[o++])];return o&&o==i?t:void 0}function Mt(t){if(!Kt(t)||(e=t,yt&&yt in e))return!1;var e,n=function(t){var e=Kt(t)?Ot.call(t):"";return e==ot||e==it}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?xt:ut;return n.test(function(t){if(null!=t){try{return It.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function qt(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 $t(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return Mt(n)?n:void 0}Ut.prototype.clear=function(){this.__data__=At?At(null):{}},Ut.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},Ut.prototype.get=function(t){var e=this.__data__;if(At){var n=e[t];return n===et?void 0:n}return kt.call(e,t)?e[t]:void 0},Ut.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:kt.call(e,t)},Ut.prototype.set=function(t,e){return this.__data__[t]=At&&void 0===e?et:e,this},Rt.prototype.clear=function(){this.__data__=[]},Rt.prototype.delete=function(t){var e=this.__data__,n=Tt(e,t);return!(n<0)&&(n==e.length-1?e.pop():Ct.call(e,n,1),!0)},Rt.prototype.get=function(t){var e=this.__data__,n=Tt(e,t);return n<0?void 0:e[n][1]},Rt.prototype.has=function(t){return Tt(this.__data__,t)>-1},Rt.prototype.set=function(t,e){var n=this.__data__,o=Tt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},Pt.prototype.clear=function(){this.__data__={hash:new Ut,map:new(St||Rt),string:new Ut}},Pt.prototype.delete=function(t){return qt(this,t).delete(t)},Pt.prototype.get=function(t){return qt(this,t).get(t)},Pt.prototype.has=function(t){return qt(this,t).has(t)},Pt.prototype.set=function(t,e){return qt(this,t).set(t,e),this};var Dt=Wt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Jt(t))return _t?_t.call(t):"";var e=t+"";return"0"==e&&1/t==-nt?"-0":e}(e);var n=[];return lt.test(t)&&n.push(""),t.replace(ct,(function(t,e,o,i){n.push(o?i.replace(dt,"$1"):e||t)})),n}));function Nt(t){if("string"==typeof t||Jt(t))return t;var e=t+"";return"0"==e&&1/t==-nt?"-0":e}function Wt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(Wt.Cache||Pt),n}Wt.Cache=Pt;var Ft=Array.isArray;function Kt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Jt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&Ot.call(t)==rt}var Ht=tt((function(t,e,n){var o=null==t?void 0:Lt(t,e);return void 0===o?n:o})),zt="/v1/auth/accesskey/exchange",Bt="/v1/auth/otp/verify",Vt="/v1/auth/otp/signin",Zt="/v1/auth/otp/signup",Gt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Xt="/v1/auth/otp/signup-in",Yt="/v1/auth/magiclink/verify",Qt="/v1/auth/magiclink/signin",te="/v1/auth/magiclink/signup",ee={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ne="/v1/auth/magiclink/signup-in",oe="/v1/auth/enchantedlink/verify",ie="/v1/auth/enchantedlink/signin",re="/v1/auth/enchantedlink/signup",se="/v1/auth/enchantedlink/pending-session",ae={email:"/v1/auth/enchantedlink/update/email"},le="/v1/auth/enchantedlink/signup-in",ce="/v1/auth/oauth/authorize",de="/v1/auth/oauth/exchange",ue="/v1/auth/saml/authorize",he="/v1/auth/saml/exchange",pe="/v1/auth/totp/verify",fe="/v1/auth/totp/signup",ge="/v1/auth/totp/update",ve={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},me={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},be={start:"/v1/auth/webauthn/signup-in/start"},we={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ye="/v1/auth/password/signup",Ie="/v1/auth/password/signin",ke="/v1/auth/password/reset",Oe="/v1/auth/password/update",xe="/v1/auth/password/replace",je="/v1/auth/password/policy",Ce="/v1/auth/refresh",Se="/v1/auth/logout",Ae="/v1/auth/logoutall",Ee="/v1/auth/me",_e="/v1/flow/start",Ue="/v1/flow/next";const Re=6e5,Pe=()=>{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 Te;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Te||(Te={}));const Le=(...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}),{})),Me=t=>void 0===t?void 0:JSON.stringify(t),qe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},$e=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const n=(t=>async(...e)=>{const n=await t(...e),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,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=>Pe().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.text();return Pe().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:d,queryParams:u,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:u}),{headers:Le(qe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.8"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:Me(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:Te.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Te.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Te.put,token:i}),delete:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:Te.delete,token:o}),hooks:i}};var De=429;function Ne(t,e,n){var o;let i=We(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 We(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return Y(t)}function Fe(t){const{exp:e}=We(t);return(new Date).getTime()/1e3>e}function Ke(t,e){return Ne(t,e,"permissions")}function Je(t,e){return Ne(t,e,"roles")}const He=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function ze(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===De&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Be=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ve=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ze=t=>e=>t.test(e),Ge=Ze(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Xe=Ze(/^\+[1-9]{1}[0-9]{3,14}$/),Ye=Be(Ge,'"{val}" is not a valid email'),Qe=Be(Xe,'"{val}" is not a valid phone number'),tn=Be((1,t=>t.length>=1),"Minimum length is 1");const en=Be((t=>"string"==typeof t),"Input is not a string"),nn=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ve(...t).validate(n[e]))),e(...n)),on=t=>[en(`"${t}" must be a string`),tn(`"${t}" must not be empty`)],rn=t=>[en(`"${t}" must be a string`),Ye()],sn=t=>[en(`"${t}" must be a string`),Qe()],an=nn(on("accessKey")),ln=t=>({exchange:an((e=>ze(t.post(zt,{},{token:e}))))});var cn,dn;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(cn||(cn={})),function(t){t.email="email"}(dn||(dn={}));const un=Object.assign(Object.assign({},cn),dn);var hn;!function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(hn||(hn={}));const pn=on("loginId"),fn=nn(on("token")),gn=nn(pn),vn=nn(on("pendingRef")),mn=nn(pn,rn("email")),bn=t=>({verify:fn((e=>ze(t.post(oe,{token:e})))),signIn:gn(((e,n,o,i)=>ze(t.post(He(ie,un.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:gn(((e,n)=>ze(t.post(He(le,un.email),{loginId:e,URI:n})))),signUp:gn(((e,n,o)=>ze(t.post(He(re,un.email),{loginId:e,URI:n,user:o})))),waitForSession:vn(((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||Re,Re)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(se,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ze(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:mn(((e,n,o,i,r)=>ze(t.post(ae.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i}))))}}),wn=nn(on("flowId")),yn=nn(on("executionId"),on("stepId"),on("interactionId")),In=t=>({start:wn(((e,n,o,i,r,s)=>ze(t.post(_e,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r,version:s})))),next:yn(((e,n,o,i,r)=>ze(t.post(Ue,{executionId:e,stepId:n,interactionId:o,input:i,version:r}))))}),kn=on("loginId"),On=nn(on("token")),xn=nn(kn),jn=nn(kn,sn("phone")),Cn=nn(kn,rn("email")),Sn=t=>({verify:On((e=>ze(t.post(Yt,{token:e})))),signIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:xn(((e,o,i,r)=>ze(t.post(He(Qt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:xn(((e,o,i)=>ze(t.post(He(te,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:xn(((e,o)=>ze(t.post(He(ne,n),{loginId:e,URI:o}))))})),{}),update:{email:Cn(((e,n,o,i,r)=>ze(t.post(ee.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i})))),phone:Object.keys(cn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:jn(((e,o,i,r,s)=>ze(t.post(He(ee.phone,n),Object.assign({loginId:e,phone:o,URI:i},s),{token:r}))))})),{})}});var An;!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"}(An||(An={}));const En=nn(on("code")),_n=t=>({start:Object.keys(An).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:(e,o,i)=>ze(t.post(ce,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i}))})),{}),exchange:En((e=>ze(t.post(de,{code:e}))))}),Un=on("loginId"),Rn=nn(Un,on("code")),Pn=nn(Un),Tn=nn(Un,sn("phone")),Ln=nn(Un,rn("email")),Mn=t=>({verify:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Rn(((e,o)=>ze(t.post(He(Bt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Pn(((e,o,i)=>ze(t.post(He(Vt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Pn(((e,o)=>ze(t.post(He(Zt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Pn((e=>ze(t.post(He(Xt,n),{loginId:e}))))})),{}),update:{email:Ln(((e,n,o,i)=>ze(t.post(Gt.email,Object.assign({loginId:e,email:n},i),{token:o})))),phone:Object.keys(cn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Tn(((e,o,i,r)=>ze(t.post(He(Gt.phone,n),Object.assign({loginId:e,phone:o},r),{token:i}))))})),{})}}),qn=nn(on("tenant")),$n=nn(on("code")),Dn=t=>({start:qn(((e,n,o,i)=>ze(t.post(ue,o||{},{queryParams:{tenant:e,redirectURL:n},token:i})))),exchange:$n((e=>ze(t.post(he,{code:e}))))}),Nn=on("loginId"),Wn=nn(Nn,on("code")),Fn=nn(Nn),Kn=nn(Nn),Jn=t=>({signUp:Fn(((e,n)=>ze(t.post(fe,{loginId:e,user:n})))),verify:Wn(((e,n,o,i)=>ze(t.post(pe,{loginId:e,code:n,loginOptions:o},{token:i})))),update:Kn(((e,n)=>ze(t.post(ge,{loginId:e},{token:n}))))}),Hn=on("loginId"),zn=on("newPassword"),Bn=nn(Hn,on("password")),Vn=nn(Hn),Zn=nn(Hn,zn),Gn=nn(Hn,on("oldPassword"),zn),Xn=t=>({signUp:Bn(((e,n,o)=>ze(t.post(ye,{loginId:e,password:n,user:o})))),signIn:Bn(((e,n)=>ze(t.post(Ie,{loginId:e,password:n})))),sendReset:Vn(((e,n)=>ze(t.post(ke,{loginId:e,redirectUrl:n})))),update:Zn(((e,n,o)=>ze(t.post(Oe,{loginId:e,newPassword:n},{token:o})))),replace:Gn(((e,n,o)=>ze(t.post(xe,{loginId:e,oldPassword:n,newPassword:o})))),policy:()=>ze(t.get(je))}),Yn=[en('"loginId" must be a string')],Qn=on("loginId"),to=on("origin"),eo=nn(Qn,to,on("name")),no=nn(Qn,to),oo=nn(Yn,to),io=nn(Qn,to,on("token")),ro=nn(on("transactionId"),on("response")),so=t=>({signUp:{start:eo(((e,n,o)=>ze(t.post(ve.start,{user:{loginId:e,name:o},origin:n})))),finish:ro(((e,n)=>ze(t.post(ve.finish,{transactionId:e,response:n}))))},signIn:{start:oo(((e,n,o,i)=>ze(t.post(me.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:ro(((e,n)=>ze(t.post(me.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:no(((e,n)=>ze(t.post(be.start,{loginId:e,origin:n}))))},update:{start:io(((e,n,o)=>ze(t.post(we.start,{loginId:e,origin:n},{token:o})))),finish:ro(((e,n)=>ze(t.post(we.finish,{transactionId:e,response:n}))))}}),ao=nn(on("token"));var lo,co=nn([("projectId",lo=on("projectId"),Be(((t,e)=>n=>Ve(...e).validate(Ht(n,t)))("projectId",lo))())])((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=$e({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:ln(a),otp:Mn(a),magicLink:Sn(a),enchantedLink:bn(a),oauth:_n(a),saml:Dn(a),totp:Jn(a),webauthn:so(a),password:Xn(a),flow:In(a),refresh:t=>ze(a.post(Ce,{},{token:t})),logout:t=>ze(a.post(Se,{},{token:t})),logoutAll:t=>ze(a.post(Ae,{},{token:t})),me:t=>ze(a.get(Ee,{token:t})),isJwtExpired:ao(Fe),getJwtPermissions:ao(Ke),getJwtRoles:ao(Je),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 uo=(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 ho=Object.assign(co,{DeliveryMethods:un});var po="Blocked by CSP",fo="9319";function go(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===po||e===fo}(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 vo="Failed to load the JS script of the agent";function mo(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");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("3.8.3"):t}))}(String(t),e)}))}(l,s);return go(t,bo).catch(yo)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function bo(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(po)}();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(vo))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(wo)}function wo(){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(fo);return n}function yo(t){throw t instanceof Error&&t.message===fo?new Error(vo):t}
|
|
2
|
+
/*! js-cookie v3.0.5 | 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 ko=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 Oo=(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},xo=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||{}},jo=async t=>{const e=await xo(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Co="undefined"!=typeof localStorage,So=(t,e)=>Co&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Ao=t=>Co&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Eo=t=>Co&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),_o=(...t)=>{console.debug(...t)},Uo="undefined"!=typeof window,Ro=Uo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Po=(t="",e="")=>({vsid:t,vrid:e}),To=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},Lo=t=>(t.body&&(t.body.fpData=To(!0)||Po()),t),Mo="dls_last_user_login_id",qo="dls_last_user_display_name",$o=()=>Ao(Mo),Do=()=>Ao(qo),No=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=$o(),r=Do();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},Wo=t=>async(...e)=>{const n=await t(...e);return Eo(Mo),Eo(qo),n};function Fo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Ko="DS",Jo="DSR",Ho=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&So(Jo,o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);ko.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Ko,i,r):So(Ko,i))};function zo(){return Ao(Jo)||""}function Bo(){return ko.get(Ko)||Ao(Ko)||""}function Vo(){Eo(Jo),Eo(Ko),ko.remove(Ko)}const Zo=t=>Object.assign(t,{token:t.token||zo()}),Go=t=>async(...e)=>{const n=await t(...e);return Vo(),n};async function Xo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=oi(n.publicKey.challenge),n.publicKey.user.id=oi(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=oi(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:ii(n.rawId),type:n.type,response:{attestationObject:ii(n.response.attestationObject),clientDataJSON:ii(n.response.clientDataJSON)}});var n}async function Yo(t){const e=ei(t);return ni(await navigator.credentials.get(e))}async function Qo(t,e){const n=ei(t);return n.signal=e.signal,n.mediation="conditional",ni(await navigator.credentials.get(n))}async function ti(t=!1){if(!Uo)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function ei(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=oi(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=oi(t.id)})),n}function ni(t){return JSON.stringify({id:t.id,rawId:ii(t.rawId),type:t.type,response:{authenticatorData:ii(t.response.authenticatorData),clientDataJSON:ii(t.response.clientDataJSON),signature:ii(t.response.signature),userHandle:t.response.userHandle?ii(t.response.userHandle):void 0}})}function oi(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function ii(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var ri,si=(ri=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 Xo(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 Yo(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 Xo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Yo(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 Xo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Xo,get:Yo,isSupported:ti,conditional:Qo}}),(...t)=>{const e=ri(...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}),ai=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await ti(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const li=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?(Uo?i&&(async t=>{try{if(To())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=mo({apiKey:t,endpoint:Ro}),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))})(Po(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(Oo(r,{beforeRequest:Lo}))):t(Object.assign({},r))}),(t=>n=>{var{autoRefresh:o}=n,i=e(n,["autoRefresh"]);if(!o)return t(i);const{clearAllTimers:r,setTimer:s}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),a=t(Oo(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await xo(e);if(401===(null==e?void 0:e.status))_o("Received 401, canceling all timers"),r();else if(o){const t=((i=(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))?i.getTime()-(new Date).getTime():0)-2e4;r(),_o(`Setting refresh timer for ${t}ms`),s((()=>{_o("Refreshing session"),a.refresh(n)}),t)}var i}}));return uo(a,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return _o("Clearing all timers"),r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.2.9"},e.baseHeaders)}))),(t=>e=>{const n=Fo(),o=Fo(),i=t(Oo(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await jo(e);t&&o.pub(t);const{sessionJwt:i}=await xo(e);i&&n.pub(i)}}})),r=uo(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(Oo(e,{afterRequest:async(t,e)=>{var n;const o=await jo(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=>{So(Mo,t)})(i),(t=>{So(qo,t)})(r))}}));let o=uo(n,["flow.start"],No);return o=uo(o,["logout","logoutAll"],Wo),Object.assign(o,{getLastUserLoginId:$o,getLastUserDisplayName:Do})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!Uo)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(Oo(r,{beforeRequest:Zo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Vo():Ho(await xo(e),i)}})),a=uo(s,["logout","logoutAll"],Go);return Object.assign(a,{getRefreshToken:zo,getSessionToken:Bo})}))(((...t)=>{const e=ho(...t);return Object.assign(Object.assign({},e),{flow:ai(e),webauthn:si(e)})})),ci=document.createElement("template");var di,ui,hi,pi,fi,gi,vi,mi,bi,wi,yi,Ii,ki,Oi,xi,ji,Ci,Si,Ai,Ei,_i,Ui,Ri,Pi,Ti,Li,Mi,qi,$i,Di,Ni,Wi,Fi,Ki,Ji,Hi,zi,Bi,Vi,Zi,Gi,Xi,Yi,Qi,tr,er,nr,or,ir;ci.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 rr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}constructor(t){super(),di.add(this),ui.set(this,!1),hi.set(this,new F({deferredRedirect:!1})),pi.set(this,new F),this.nextRequestStatus=new F({isLoading:!1}),fi.set(this,void 0),gi.set(this,{popstate:o(this,di,"m",Ii).bind(this),visibilitychange:o(this,di,"m",ki).bind(this)}),vi.set(this,void 0),ji.set(this,T((()=>n(this,void 0,void 0,(function*(){const t=A(this.projectId,"config.json");try{const{body:e,headers:n}=yield S(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")}return{}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,di,"m",Ri).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,vi,t,"f"),o(this,di,"m",mi).call(this)}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,ji,"f").call(this);return t}))}getFlowConfig(){var t,e;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,ji,"f").call(this),i=(null===(t=null==n?void 0:n.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=i.version)&&void 0!==e||(i.version=0),i}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,di,"m",bi).call(this))return void o(this,di,"m",wi).call(this);o(this,di,"m",yi).call(this),o(this,di,"m",Si).call(this),o(this,di,"m",Ci).call(this),o(this,di,"m",Pi).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}=P();window.addEventListener("popstate",o(this,gi,"f").popstate),window.addEventListener("visibilitychange",o(this,gi,"f").visibilitychange),o(this,hi,"f").subscribe(o(this,di,"m",xi).bind(this)),o(this,pi,"f").subscribe(o(this,di,"m",Ui).bind(this)),o(this,hi,"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,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}),o(this,pi,"f").update({isDebug:this.debug}),i(this,ui,!0,"f")}}))}disconnectedCallback(){o(this,hi,"f").unsubscribeAll(),o(this,pi,"f").unsubscribeAll(),o(this,di,"m",_i).call(this),window.removeEventListener("popstate",o(this,gi,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,ui,"f")&&e!==n&&rr.observedAttributes.includes(t)){o(this,di,"m",yi).call(this);const i=null===e;o(this,hi,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,U()),{[R(t)]:n,stepId:r,executionId:s}})),o(this,pi,"f").update({isDebug:this.debug})}}}ui=new WeakMap,hi=new WeakMap,pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,ji=new WeakMap,di=new WeakSet,mi=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ci.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},bi=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},wi=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},yi=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(rr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[R(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')},Ii=function(){const{stepId:t,executionId:e}=_();o(this,hi,"f").update({stepId:t,executionId:e})},ki=function(){document.hidden||setTimeout((()=>{o(this,hi,"f").update({deferredRedirect:!1})}),300)},Oi=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=li(Object.assign(Object.assign({persistTokens:!0},rr.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})}}))}))},xi=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,di,"m",Oi).call(this,e,n,r)}o(this,vi,"f").call(this,t)}))},Ci=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,ji,"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)))}))},Si=function(){o(this,di,"m",Ai).call(this),o(this,di,"m",Ei).call(this)},Ai=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=A(this.projectId,"theme.css");try{const{body:n}=yield S(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)}))},Ei=function(){this.rootElement.setAttribute("data-theme",this.theme)},_i=function(){var t;null===(t=o(this,fi,"f"))||void 0===t||t.remove(),i(this,fi,null,"f")},Ui=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return cr})),i(this,fi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,fi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,fi,"f"))):o(this,di,"m",_i).call(this)}))},Ri=function(t,e){var n;t&&this.debug&&(null===(n=o(this,fi,"f"))||void 0===n||n.updateData({title:t,description:e}))},Pi=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()}},rr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.4.3"}};class sr extends rr{static set sdkConfigOverrides(t){rr.sdkConfigOverrides=t}constructor(){const t=new F;super(t.update.bind(t)),Ti.add(this),this.stepState=new F({},{updateOnlyOnChange:!1}),Li.set(this,void 0),Mi.set(this,null),qi.set(this,(()=>{clearInterval(o(this,Li,"f")),i(this,Li,null,"f")})),$i.set(this,(t=>{var e,n,i,s,a,l,c,d,u;if(!(null==t?void 0:t.ok)){o(this,qi,"f").call(this),o(this,Ti,"m",Vi).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(d=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===d?void 0:d.errorText;h&&this.logger.error(h),(null===(u=t.data)||void 0===u?void 0:u.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:g,lastAuth:v}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(p,JSON.stringify(t))}(v),o(this,qi,"f").call(this),void o(this,Ti,"m",Vi).call(this,"success",g);const{executionId:b,stepId:w,action:y,screen:I,redirect:k,webauthn:O}=t.data;y!==m?this.flowState.update({stepId:w,executionId:b,action:y,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:y})})),Di.set(this,T((()=>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}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:d,stepId:u,executionId:h,action:p,screenId:f,screenState:g,redirectTo:k,redirectUrl:O,token:x,code:j,exchangeError:C,webauthnTransactionId:S,webauthnOptions:_,redirectAuthCodeChallenge:U,redirectAuthCallbackUrl:R,redirectAuthInitiator:P,oidcIdpStateId:T}=t;let L,q;o(this,Li,"f")&&o(this,qi,"f").call(this);const $=this.sdk.getLastUserLoginId(),D=yield this.getFlowConfig(),N=R&&U?{callbackUrl:R,codeChallenge:U}:void 0;if(!h&&(D.conditions?({startScreenId:L,conditionInteractionId:q}=((t,e)=>{const n=null==e?void 0:e.find((({key:e,operator:n})=>{var o;if("ELSE"===e)return!0;const i=null===(o=B[e])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(t))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:$,code:j},D.conditions)):D.condition?({startScreenId:L,conditionInteractionId:q}=((t,e)=>{var n;const o=null===(n=B[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}})(D.condition,{loginId:$,code:j})):L=D.startScreenId,!M(L,T))){const t=j?{exchangeCode:j,idpInitiated:!0}:void 0,e=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:d,redirectAuth:N,oidcIdpStateId:T},O&&{redirectUrl:O}),{lastAuth:V($)}),q,"",t,D.version);return o(this,$i,"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(h&&(r("token")&&x||r("code")&&j||r("exchangeError")&&C)){const t=yield this.sdk.flow.next(h,u,y,{token:x,exchangeCode:j,exchangeError:C},D.version);return o(this,$i,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===v&&(r("redirectTo")||r("deferredRedirect")))return k?"android"===P&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(k):void this.logger.error("Did not get redirect url");if(p===b||p===w){if(!S||!_)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,Mi,"f"))||void 0===a||a.abort(),i(this,Mi,null,"f");try{t=p===b?yield this.sdk.webauthn.helpers.create(_):yield this.sdk.webauthn.helpers.get(_)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(h,u,y,{transactionId:S,response:t,cancelWebauthn:e},D.version);o(this,$i,"f").call(this,n)}if(p===m&&i(this,Li,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,I,{},D.version);o(this,$i,"f").call(this,t)}))),2e3),"f"),!f&&!L)return void this.logger.info("Refreshing the page during a flow is not supported yet");const W={direction:E(+u,+e.stepId),screenState:Object.assign(Object.assign({},g),{lastAuth:{loginId:$,name:this.sdk.getLastUserDisplayName()||$}}),htmlUrl:A(l,`${L||f}.html`)},F=V($);M(L,T)?W.next=(t,e)=>this.sdk.flow.start(c,Object.assign({tenant:d,redirectAuth:N,oidcIdpStateId:T,lastAuth:F},O&&{redirectUrl:O}),q,t,Object.assign(Object.assign({},e),j&&{exchangeCode:j,idpInitiated:!0}),D.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(W.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(W)}))}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:d}=yield S(r,"text");c.innerHTML=d;const u=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})(u,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,Ti,"m",Wi).call(this,u,a):u.querySelectorAll(`button[${g}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),J(u,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})`))})(u.querySelector("div"),null===(i=null==l?void 0:l.totp)||void 0===i?void 0:i.image);const p=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(u);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,Ti,"m",zi).call(this,a),o(this,Ti,"m",Vi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${g}="polling"]`)){const t=yield a(I,{});o(this,$i,"f").call(this,t)}}));s?o(this,Ti,"m",Bi).call(this,p,s):p()}))}}Li=new WeakMap,Mi=new WeakMap,qi=new WeakMap,$i=new WeakMap,Di=new WeakMap,Ti=new WeakSet,Ni=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,Mi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield H())){const{options:t,transactionId:r}=(yield o(this,Di,"f").call(this))||{};t&&r&&(o(this,Ti,"m",Ni).call(this,s),i(this,Mi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,Mi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,$i,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},Fi=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([${h}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e["checkbox"===e.type?"checked":"value"]}):t),{})},Ji=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"))}))},Hi=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Ti,"m",Fi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,Ti,"m",Ji).call(this,t);const r=o(this,Ti,"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,$i,"f").call(this,l)}var n}))},zi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,Ti,"m",Hi).call(this,e,t)}}))},Bi=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")},Vi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",sr);const ar=document.createElement("template");ar.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 lr extends HTMLElement{constructor(){super(),Zi.add(this),Gi.set(this,new F({messages:[]})),Xi.set(this,void 0),Yi.set(this,void 0),Qi.set(this,void 0),tr.set(this,{resize:o(this,Zi,"m",ir).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ar.content.cloneNode(!0)),i(this,Xi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Yi,o(this,Xi,"f").querySelector(".content"),"f"),i(this,Qi,o(this,Xi,"f").querySelector(".header"),"f")}updateData(t){o(this,Gi,"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]=z(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,Xi,"f"),o(this,Qi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,tr,"f").resize),(t=o(this,Xi,"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,Xi,"f").onresize=o(this,Zi,"m",or).bind(this),o(this,Gi,"f").subscribe(o(this,Zi,"m",er).bind(this))}disconnectedCallback(){o(this,Gi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,tr,"f").resize)}}Gi=new WeakMap,Xi=new WeakMap,Yi=new WeakMap,Qi=new WeakMap,tr=new WeakMap,Zi=new WeakSet,er=function(t){o(this,Zi,"m",nr).call(this,t),o(this,Zi,"m",or).call(this)},nr=function(t){o(this,Yi,"f").innerHTML=t.messages.map((t=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.title}\n </div>\n <div class="msg_desc">\n ${t.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},or=function(){o(this,Yi,"f").querySelectorAll(".msg").forEach((t=>{const e=t.querySelector(".msg_desc"),n=e.scrollWidth>e.clientWidth,o=e.clientHeight>20;n||o?(t.classList.add("collapsible"),t.onclick=e=>{e.target.classList.contains("msg_desc")||t.classList.toggle("collapsed")}):(t.classList.remove("collapsible"),t.onclick=null)}))},ir=function(){const[t,e]=z(o(this,Xi,"f"),Number.parseInt(o(this,Xi,"f").style.left,10),Number.parseInt(o(this,Xi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Xi,"f").style.top=`${e}px`,o(this,Xi,"f").style.left=`${t}px`},customElements.define("descope-debugger",lr);var cr=Object.freeze({__proto__:null,default:lr})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"author": "Descope Team <info@descope.com>",
|
|
5
5
|
"homepage": "https://github.com/descope/web-component",
|
|
6
6
|
"bugs": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@types/jest": "^29.0.0",
|
|
32
32
|
"@types/node": "18.15.0",
|
|
33
33
|
"dotenv": "^16.0.3",
|
|
34
|
-
"eslint": "8.
|
|
34
|
+
"eslint": "8.41.0",
|
|
35
35
|
"eslint-config-airbnb": "19.0.4",
|
|
36
36
|
"eslint-config-airbnb-typescript": "17.0.0",
|
|
37
37
|
"eslint-config-prettier": "8.8.0",
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"typescript": "^4.5.3"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"tslib": "2.5.
|
|
69
|
-
"@descope/web-js-sdk": "1.2.
|
|
68
|
+
"tslib": "2.5.2",
|
|
69
|
+
"@descope/web-js-sdk": "1.2.9"
|
|
70
70
|
},
|
|
71
71
|
"overrides": {
|
|
72
|
-
"terser": "5.17.
|
|
72
|
+
"terser": "5.17.4"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"start": "npx nx run web-component:build && rollup -c rollup.config.app.serve.js -w",
|