@descope/web-component 0.1.0-alpha.21 → 0.1.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/debugger-wc-84d810bb.js +1 -0
- package/dist/esm/index-9045fb82.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +1 -0
- package/package.json +8 -8
- package/dist/debugger-wc-781f6337.js +0 -1
- package/dist/descope-wc-d680a346.js +0 -1
- package/dist/descope-wc.d.ts +0 -16
- package/dist/descope-wc.esm.js +0 -1
- package/dist/descope-wc.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e,_ as n,a as t}from"./index-9045fb82.js";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new e({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:n(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),t(this,l,this.shadowRoot.querySelector(".debugger"),"f"),t(this,a,n(this,l,"f").querySelector(".content"),"f"),t(this,r,n(this,l,"f").querySelector(".header"),"f")}updateData(e){n(this,o,"f").update((n=>({messages:n.messages.concat(e)})))}connectedCallback(){var e;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(n(this,l,"f"),n(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",n(this,d,"f").resize),(e=n(this,l,"f")).onmousemove=n=>{(n.target.w&&n.target.w!==n.target.offsetWidth||n.target.h&&n.target.h!==n.target.offsetHeight)&&e.onresize(n),n.target.w=n.target.offsetWidth,n.target.h=n.target.offsetHeight},n(this,l,"f").onresize=n(this,i,"m",p).bind(this),n(this,o,"f").subscribe(n(this,i,"m",c).bind(this))}disconnectedCallback(){n(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",n(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(e){n(this,i,"m",h).call(this,e),n(this,i,"m",p).call(this)},h=function(e){n(this,a,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){n(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[e,t]=s(n(this,l,"f"),Number.parseInt(n(this,l,"f").style.left,10),Number.parseInt(n(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});n(this,l,"f").style.top=`${t}px`,n(this,l,"f").style.left=`${e}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function r(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,n):o?o.value=n:e.set(t,n),n}const i="undefined"!=typeof window&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",c="data-type",u="redirect",l="poll",d="webauthnCreate",h="webauthnGet";function p(t){return new URLSearchParams(window.location.search).get(t)}function f(t){if(window.history.replaceState&&p(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var v;function g(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(v||(v={}));function b(t,e){const n=new URL(i);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function w(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?v.forward:t<e?v.backward:void 0}const m=()=>{const[t="",e=""]=(p(s)||"").split("_");return{executionId:t,stepId:e}};function y(){f(s)}const k=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),I=()=>{const{executionId:t,stepId:e}=m();(t||e)&&y();const n=p("t")||void 0;n&&f("t");const r=p(a)||void 0;return r&&f(a),{executionId:t,stepId:e,token:n,code:r}};var O,j,x;function S(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r],i=t[o],s=e[o];if("object"==typeof i&&"object"==typeof s){if(!S(i,s))return!1}else if(i!==s)return!1}return!0}class E{constructor(t={}){O.set(this,void 0),j.set(this,{}),x.set(this,0),o(this,O,t,"f")}get current(){return Object.assign({},r(this,O,"f"))}update(t){const e="function"==typeof t?t(r(this,O,"f")):t,n=Object.assign(Object.assign({},r(this,O,"f")),e);if(!S(r(this,O,"f"),n)){const t=r(this,O,"f");o(this,O,n,"f"),Object.freeze(r(this,O,"f")),setTimeout((()=>{Object.values(r(this,j,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}}subscribe(t){return o(this,x,r(this,x,"f")+1,"f"),r(this,j,"f")[r(this,x,"f")]=t,r(this,x,"f").toString()}unsubscribe(t){const e=!!r(this,j,"f")[t];return e&&delete r(this,j,"f")[t],e}unsubscribeAll(){return o(this,j,{},"f"),!0}}O=new WeakMap,j=new WeakMap,x=new WeakMap;const _=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${c}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${c}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return r=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),r);var r})))(t.textContent,e)}))})(t,e)};function U(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=yield navigator.credentials.create(e);return r=n,JSON.stringify({id:r.id,rawId:A(r.rawId),type:r.type,response:{attestationObject:A(r.response.attestationObject),clientDataJSON:A(r.response.clientDataJSON)}});var r}))}function C(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=yield navigator.credentials.get(e);return r=n,JSON.stringify({id:r.id,rawId:A(r.rawId),type:r.type,response:{authenticatorData:A(r.response.authenticatorData),clientDataJSON:A(r.response.clientDataJSON),signature:A(r.response.signature),userHandle:A(r.response.userHandle)}});var r}))}function R(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function A(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function P(t){this.message=t}P.prototype=new Error,P.prototype.name="InvalidCharacterError";var T="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new P("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,i=0,s="";r=e.charAt(i++);~r&&(n=o%4?64*n+r:r,o++%4)?s+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return s};function D(t){this.message=t}function q(t,e){if("string"!=typeof t)throw new D("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(T(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 T(e)}}(t.split(".")[n]))}catch(t){throw new D("Invalid token specified: "+t.message)}}D.prototype=new Error,D.prototype.name="InvalidTokenError";var M="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function L(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var N="__lodash_hash_undefined__",$="[object Function]",J="[object GeneratorFunction]",K=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,F=/^\w*$/,W=/^\./,H=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,B=/\\(\\)?/g,z=/^\[object .+?Constructor\]$/,V="object"==typeof M&&M&&M.Object===Object&&M,G="object"==typeof self&&self&&self.Object===Object&&self,Z=V||G||Function("return this")();var Q,X=Array.prototype,Y=Function.prototype,tt=Object.prototype,et=Z["__core-js_shared__"],nt=(Q=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||""))?"Symbol(src)_1."+Q:"",rt=Y.toString,ot=tt.hasOwnProperty,it=tt.toString,st=RegExp("^"+rt.call(ot).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),at=Z.Symbol,ct=X.splice,ut=yt(Z,"Map"),lt=yt(Object,"create"),dt=at?at.prototype:void 0,ht=dt?dt.toString:void 0;function pt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function ft(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function vt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function gt(t,e){for(var n,r,o=t.length;o--;)if((n=t[o][0])===(r=e)||n!=n&&r!=r)return o;return-1}function bt(t,e){var n;e=function(t,e){if(jt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||St(t))return!0;return F.test(t)||!K.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:jt(n=e)?n:kt(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[It(e[r++])];return r&&r==o?t:void 0}function wt(t){if(!xt(t)||(e=t,nt&&nt in e))return!1;var e,n=function(t){var e=xt(t)?it.call(t):"";return e==$||e==J}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?st:z;return n.test(function(t){if(null!=t){try{return rt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function mt(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function yt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return wt(n)?n:void 0}pt.prototype.clear=function(){this.__data__=lt?lt(null):{}},pt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},pt.prototype.get=function(t){var e=this.__data__;if(lt){var n=e[t];return n===N?void 0:n}return ot.call(e,t)?e[t]:void 0},pt.prototype.has=function(t){var e=this.__data__;return lt?void 0!==e[t]:ot.call(e,t)},pt.prototype.set=function(t,e){return this.__data__[t]=lt&&void 0===e?N:e,this},ft.prototype.clear=function(){this.__data__=[]},ft.prototype.delete=function(t){var e=this.__data__,n=gt(e,t);return!(n<0)&&(n==e.length-1?e.pop():ct.call(e,n,1),!0)},ft.prototype.get=function(t){var e=this.__data__,n=gt(e,t);return n<0?void 0:e[n][1]},ft.prototype.has=function(t){return gt(this.__data__,t)>-1},ft.prototype.set=function(t,e){var n=this.__data__,r=gt(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},vt.prototype.clear=function(){this.__data__={hash:new pt,map:new(ut||ft),string:new pt}},vt.prototype.delete=function(t){return mt(this,t).delete(t)},vt.prototype.get=function(t){return mt(this,t).get(t)},vt.prototype.has=function(t){return mt(this,t).has(t)},vt.prototype.set=function(t,e){return mt(this,t).set(t,e),this};var kt=Ot((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(St(t))return ht?ht.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return W.test(t)&&n.push(""),t.replace(H,(function(t,e,r,o){n.push(r?o.replace(B,"$1"):e||t)})),n}));function It(t){if("string"==typeof t||St(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Ot(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(Ot.Cache||vt),n}Ot.Cache=vt;var jt=Array.isArray;function xt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function St(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==it.call(t)}var Et=function(t,e,n){var r=null==t?void 0:bt(t,e);return void 0===r?n:r},_t="/v1/auth/accesskey/exchange",Ut="/v1/auth/otp/verify",Ct="/v1/auth/otp/signin",Rt="/v1/auth/otp/signup",At={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Pt="/v1/auth/otp/signup-in",Tt="/v1/auth/magiclink/verify",Dt="/v1/auth/magiclink/signin",qt="/v1/auth/magiclink/signup",Mt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Lt="/v1/auth/magiclink/signup-in",Nt="/v1/auth/enchantedlink/verify",$t="/v1/auth/enchantedlink/signin",Jt="/v1/auth/enchantedlink/signup",Kt="/v1/auth/enchantedlink/pending-session",Ft={email:"/v1/auth/enchantedlink/update/email"},Wt="/v1/auth/enchantedlink/signup-in",Ht="/v1/auth/oauth/authorize",Bt="/v1/auth/oauth/exchange",zt="/v1/auth/saml/authorize",Vt="/v1/auth/saml/exchange",Gt="/v1/auth/totp/verify",Zt="/v1/auth/totp/signup",Qt="/v1/user/totp/update",Xt={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Yt={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},te={start:"/v1/auth/webauthn/signup-in/start"},ee={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ne="/v1/auth/refresh",re="/v1/auth/logout",oe="/v1/auth/logoutall",ie="/v1/auth/me",se="/v1/flow/start",ae="/v1/flow/next";const ce=()=>{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 ue;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ue||(ue={}));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,r])=>(t[n]=r,t)),t),t}),{})),de=t=>void 0===t?void 0:JSON.stringify(t),he=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},pe=({baseUrl:t,projectId:e,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{t.log((t=>ce().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const r=await n(...e);return t[r.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),ce().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:t,queryParams:d}),{headers:le(he(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.36"},(null==n?void 0:n.baseHeaders)||{},l),method:h,body:de(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:r}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:ue.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:ue.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:ue.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:ue.delete,token:o}),hooks:o}};function fe(t,e,n){var r;let o=ve(t);e&&(o=null===(r=o.tenants)||void 0===r?void 0:r[e]);const i=o[n];return Array.isArray(i)?i:[]}function ve(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return q(t)}function ge(t){const{exp:e}=ve(t);return(new Date).getTime()/1e3>e}function be(t,e){return fe(t,e,"permissions")}function we(t,e){return fe(t,e,"roles")}const me=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function ye(t,e){const n=await t,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=e?e(o):o:r.error=o,r}const ke=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ie=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Oe=t=>e=>t.test(e),je=Oe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),xe=Oe(/^\+[1-9]{1}[0-9]{3,14}$/),Se=ke(je,'"{val}" is not a valid email'),Ee=ke(xe,'"{val}" is not a valid phone number'),_e=ke((1,t=>t.length>=1),"Minimum length is 1");const Ue=ke((t=>"string"==typeof t),"Input is not a string"),Ce=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ie(...t).validate(n[e]))),e(...n)),Re=t=>[Ue(`"${t}" must be a string`),_e(`"${t}" must not be empty`)],Ae=t=>[Ue(`"${t}" must be a string`),Se()],Pe=t=>[Ue(`"${t}" must be a string`),Ee()],Te=Ce(Re("accessKey")),De=t=>({exchange:Te((e=>ye(t.post(_t,{},{token:e}))))});var qe,Me,Le,Ne,$e;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(qe||(qe={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Me||(Me={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Le||(Le={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ne||(Ne={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}($e||($e={}));const Je=Re("identifier"),Ke=Ce(Je,Re("code")),Fe=Ce(Je),We=Ce(Je,Pe("phone")),He=Ce(Je,Ae("email")),Be=t=>({verify:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ke(((e,r)=>ye(t.post(me(Ut,n),{code:r,externalId:e}))))})),{}),signIn:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe(((e,r,o)=>ye(t.post(me(Ct,n),{externalId:e,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe(((e,r)=>ye(t.post(me(Rt,n),{externalId:e,user:r}))))})),{}),signUpOrIn:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe((e=>ye(t.post(me(Pt,n),{externalId:e}))))})),{}),update:{email:He(((e,n,r)=>ye(t.post(At.email,{externalId:e,email:n},{token:r})))),phone:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:We(((e,r,o)=>ye(t.post(me(At.phone,n),{externalId:e,phone:r},{token:o}))))})),{})}}),ze=Re("identifier"),Ve=Re("uri"),Ge=Ce(Re("token")),Ze=Ce(ze,Ve),Qe=Ce(ze,Pe("phone"),Ve),Xe=Ce(ze,Ae("email"),Ve),Ye=t=>({verify:Ge((e=>ye(t.post(Tt,{token:e})))),signIn:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ze(((e,r,o,i)=>ye(t.post(me(Dt,n),{externalId:e,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ze(((e,r,o)=>ye(t.post(me(qt,n),{externalId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ze(((e,r)=>ye(t.post(me(Lt,n),{externalId:e,URI:r}))))})),{}),update:{email:Xe(((e,n,r,o)=>ye(t.post(Mt.email,{externalId:e,email:n,URI:r},{token:o})))),phone:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Qe(((e,r,o,i)=>ye(t.post(me(Mt.phone,n),{externalId:e,phone:r,URI:o},{token:i}))))})),{})}}),tn=Re("identifier"),en=Re("uri"),nn=Ce(Re("token")),rn=Ce(tn,en),on=Ce(Re("pendingRef")),sn=Ce(tn,Ae("email"),en),an=t=>({verify:nn((e=>ye(t.post(Nt,{token:e})))),signIn:rn(((e,n,r,o)=>ye(t.post(me($t,Me.email),{externalId:e,URI:n,loginOptions:r},{token:o})))),signUpOrIn:rn(((e,n)=>ye(t.post(me(Wt,Me.email),{externalId:e,URI:n})))),signUp:rn(((e,n,r)=>ye(t.post(me(Jt,Me.email),{externalId:e,URI:n,user:r})))),waitForSession:on(((e,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Kt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(ye(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:sn(((e,n,r,o)=>ye(t.post(Ft.email,{externalId:e,email:n,URI:r},{token:o}))))}});var cn;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(cn||(cn={}));const un=Ce(Re("code")),ln=t=>({start:Object.keys(cn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:r=!1}={},o,i)=>{const s=await t.post(Ht,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!r||!s.ok)return ye(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:un((e=>ye(t.post(Bt,{code:e}))))}),dn=Ce(Re("flowId")),hn=Ce(Re("executionId"),Re("stepId"),Re("interactionId")),pn=t=>({start:dn(((e,n,r,o)=>ye(t.post(se,{flowId:e,options:n,interactionId:r,input:o})))),next:hn(((e,n,r,o)=>ye(t.post(ae,{executionId:e,stepId:n,interactionId:r,input:o}))))}),fn=Ce(Re("tenant")),vn=Ce(Re("code")),gn=t=>({start:fn((async(e,n,{redirect:r=!1}={},o,i)=>{const s=await t.post(zt,o||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!r||!s.ok)return ye(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:vn((e=>ye(t.post(Vt,{code:e}))))}),bn=Re("identifier"),wn=Ce(bn,Re("code")),mn=Ce(bn),yn=Ce(bn),kn=t=>({signUp:mn(((e,n)=>ye(t.post(Zt,{externalId:e,user:n})))),verify:wn(((e,n,r,o)=>ye(t.post(Gt,{externalId:e,code:n,loginOptions:r},{token:o})))),update:yn(((e,n)=>ye(t.post(Qt,{externalId:e},{token:n}))))}),In=Re("identifier"),On=Re("origin"),jn=Ce(In,On,Re("name")),xn=Ce(In,On),Sn=Ce(In,On,Re("token")),En=Ce(Re("transactionId"),Re("response")),_n=t=>({signUp:{start:jn(((e,n,r)=>ye(t.post(Xt.start,{user:{externalId:e,name:r},origin:n})))),finish:En(((e,n)=>ye(t.post(Xt.finish,{transactionId:e,response:n}))))},signIn:{start:xn(((e,n,r,o)=>ye(t.post(Yt.start,{externalId:e,origin:n,loginOptions:r},{token:o})))),finish:En(((e,n)=>ye(t.post(Yt.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:xn(((e,n)=>ye(t.post(te.start,{externalId:e,origin:n}))))},update:{start:Sn(((e,n,r)=>ye(t.post(ee.start,{externalId:e,origin:n},{token:r})))),finish:En(((e,n)=>ye(t.post(ee.finish,{transactionId:e,response:n}))))}}),Un=Ce(Re("token")),Cn=(t,e,n)=>(e.forEach((e=>{const r=e.split(".");let o=r.shift(),i=t;for(;r.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${e}", "${o}" is missing or has no value`);o=r.shift()}if("function"!=typeof i[o])throw Error(`"${e}" is not a function`);const s=i[o];i[o]=n(s)})),t);var Rn;let An=Ce([("projectId",Rn=Re("projectId"),ke(((t,e)=>n=>Ie(...e).validate(Et(n,t)))("projectId",Rn))())])((t=>{var e,n;const r=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=pe({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:r,cookiePolicy:o}),{accessKey:De(i),otp:Be(i),magicLink:Ye(i),enchantedLink:an(i),oauth:ln(i),saml:gn(i),totp:kn(i),webauthn:_n(i),flow:pn(i),refresh:t=>ye(i.post(ne,{},{token:t})),logout:t=>ye(i.post(re,{},{token:t})),logoutAll:t=>ye(i.post(oe,{},{token:t})),me:t=>ye(i.get(ie,{token:t})),isJwtExpired:Un(ge),getJwtPermissions:Un(be),getJwtRoles:Un(we),httpClient:i};var i})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==r?void 0:r.reduce(((t,e)=>e(t)),t),afterRequest:(t,e)=>{null==o||o.forEach((n=>n(t,null==e?void 0:e.clone())))}}}))}));var Pn=Object.assign(An,{DeliveryMethods:Me});function Tn(t,e){var n=[];return function(t,e){var n,r,o=(r=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,o++)r[o]=i[s];return r}(t),{current:function(){return r[0]},postpone:function(){var t=r.shift();void 0!==t&&r.push(t)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=o.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?o.postpone():o.exclude();var e,r=o.current();if(void 0===r)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(r,n+1)}))}))};return a(s,0)}(t,(function(t){var r=new Date,o=function(){return n.push({url:t,startedAt:r,finishedAt:new Date})},i=e(t);return i.then(o,o),i})).then((function(t){return[t,{attempts:n}]}))}var Dn="Failed to load the JS script of the agent";function qn(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,s=void 0===i?o:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(r=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Tn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(c,s),Mn).catch(Nn)})).then((function(e){var n=e[0],r=e[1];return n.load(t(t({},a),{ldi:r}))}))}function Mn(t){return function(t,e,n,r){var o,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),r=e.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=e,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var r=document.createElement("script"),o=function(){var t;return null===(t=r.parentNode)||void 0===t?void 0:t.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),e()},r.onerror=function(){o(),n(new Error(Dn))},r.async=!0,r.src=t,i.appendChild(r)}))}(t)})).then(Ln)}function Ln(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==r?void 0:r.configurable)?delete t[e]:r&&!r.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function Nn(t){throw t instanceof Error&&"9319"===t.message?new Error(Dn):t}var $n={exports:{}},Jn={exports:{}};Jn.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function e(n,r){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=t({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=e+"="+n.write(o,e)+s}}function i(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],r={},o=0;o<e.length;o++){var i=e[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=n.read(s,a),t===a)break}catch(t){}}return t?r[t]:r}}return Object.create({set:o,get:i,remove:function(e,n){o(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}return 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:"/"})}();var Kn=L($n.exports=Jn.exports);const Fn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,r)=>{var o;return n[r]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[r])||[]).concat((null==e?void 0:e[r])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Wn=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||{}},Hn=async t=>{const e=await Wn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Bn="undefined"!=typeof localStorage,zn=(t,e)=>Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Vn=t=>Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Gn=t=>Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),Zn=t=>Object.assign(t,{headers:Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.17"})}),Qn="undefined"!=typeof window,Xn=Qn&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",Yn=Qn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",tr=(t="",e="")=>({vsid:t,vrid:e}),er=(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},nr=t=>(t.body&&(t.body.fpData=er(!0)||tr()),t),rr=t=>async(...e)=>{e[1]=e[1]||{};const[,n]=e,r=Vn("dls_last_user_external_id");return r&&(n.lastUser={externalId:r}),await t(...e)},or=t=>async(...e)=>{const n=await t(...e);return Gn("dls_last_user_external_id"),n};function ir(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const sr=(t={},n)=>{var{refreshJwt:r,sessionJwt:o}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),r&&zn("DSR",r),o&&(n?function(t,e,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(e){const i=new Date(1e3*o);Kn.set(t,e,{path:n,domain:r,expires:i,sameSite:"None",secure:!0})}}("DS",o,i):zn("DS",o))};function ar(){return Vn("DSR")||""}function cr(){return Kn.get("DS")||Vn("DS")||""}function ur(){Gn("DSR"),Gn("DS"),Kn.remove("DS")}const lr=t=>Object.assign(t,{token:t.token||ar()}),dr=t=>async(...e)=>{const n=await t(...e);return ur(),n};async function hr(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=vr(n.publicKey.challenge),n.publicKey.user.id=vr(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=vr(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:gr(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:gr(n.response.attestationObject),clientDataJSON:gr(n.response.clientDataJSON)})}));var n}async function pr(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=vr(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=vr(t.id)})),n}(t);return n=await navigator.credentials.get(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:gr(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:gr(n.response.authenticatorData),clientDataJSON:gr(n.response.clientDataJSON),signature:gr(n.response.signature),userHandle:n.response.userHandle?gr(n.response.userHandle):void 0})}));var n}async function fr(t=!1){if(!Qn)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function vr(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function gr(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var br=t=>Object.assign(Object.assign({},t.flow),{start:async(e,n,r,o)=>{const i=await fr(),s=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}});return t.flow.start(e,s,r,o)}});const wr=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>e=>{const n=t(Fn(e,{afterRequest:async(t,e)=>{var n;const r=await Hn(e),o=null===(n=null==r?void 0:r.externalIds)||void 0===n?void 0:n[0];o&&(t=>{zn("dls_last_user_external_id",t)})(o)}}));let r=Cn(n,["flow.start"],rr);return r=Cn(r,["logout","logoutAll"],or),r}),(t=>n=>{var{fpKey:r,fpLoad:o}=n,i=e(n,["fpKey","fpLoad"]);return Qn?o&&(async t=>{try{if(er())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=qn({apiKey:t||Xn,endpoint:Yn}),r=await n,{requestId:o}=await r.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(tr(e,o))}catch(t){global.FB_DEBUG&&console.error(t)}})(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(Fn(i,{beforeRequest:nr}))}),(t=>n=>{var r=e(n,["autoRefresh"]);const{clearAllTimers:o,setTimer:i}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(Fn(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:r}=await Wn(e);if(401===(null==e?void 0:e.status))o();else if(r){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(r))?a.getTime()-(new Date).getTime():0)-2e4;o(),i((()=>s.refresh(n)),t)}var a}}));return Cn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o(),n}))}),(t=>e=>t(Fn(e,{beforeRequest:Zn}))),(t=>e=>{const n=ir(),r=ir(),o=t(Fn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),r.pub(null);else{const t=await Hn(e);t&&r.pub(t);const{sessionJwt:o}=await Wn(e);o&&n.pub(o)}}})),i=Cn(o,["logout","logoutAll"],(t=>async(...e)=>{const o=await t(...e);return n.pub(null),r.pub(null),o}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:r.sub})}),(t=>n=>{var{persistTokens:r,sessionTokenViaCookie:o}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(Qn||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"),!r||!Qn)return t(i);const s=t(Fn(i,{beforeRequest:lr,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?ur():sr(await Wn(e),o)}})),a=Cn(s,["logout","logoutAll"],dr);return Object.assign(a,{getRefreshToken:ar,getSessionToken:cr})}))(((...t)=>{const e=Pn(...t);return Object.assign(Object.assign({},e),{flow:br(e),webauthn:(n=e,{async signUp(t,e){const r=await n.webauthn.signUp.start(t,window.location.origin,e),o=await hr(r.data.options);return await n.webauthn.signUp.finish(r.data.transactionId,o)},async signIn(t){const e=await n.webauthn.signIn.start(t,window.location.origin),r=await pr(e.data.options);return await n.webauthn.signIn.finish(e.data.transactionId,r)},async signUpOrIn(t){var e;const r=await n.webauthn.signUpOrIn.start(t,window.location.origin);if(null===(e=r.data)||void 0===e?void 0:e.create){const t=await hr(r.data.options);return await n.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await pr(r.data.options);return await n.webauthn.signIn.finish(r.data.transactionId,t)}},async update(t,e){const r=await n.webauthn.update.start(t,window.location.origin,e),o=await hr(r.data.options);return await n.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:hr,get:pr,isSupported:fr}})});var n})),mr=document.createElement("template");var yr,kr,Ir,Or,jr,xr,Sr,Er,_r,Ur,Cr,Rr,Ar,Pr,Tr,Dr,qr,Mr,Lr,Nr,$r,Jr,Kr,Fr,Wr,Hr,Br,zr;mr.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\tform[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<form></form>\n\t";class Vr extends HTMLElement{constructor(t){super(),yr.add(this),kr.set(this,!1),Ir.set(this,new E),this.nextRequestStatus=new E({isLoading:!1}),Or.set(this,void 0),jr.set(this,{popstate:r(this,yr,"m",_r).bind(this)}),xr.set(this,void 0),Rr.set(this,(()=>{let t;return()=>n(this,void 0,void 0,(function*(){if(t)return t;const e=b(this.projectId,"config.json");try{t=yield g(e,"json")}catch(t){console.error("Cannot get config file")}return t}))})()),o(this,xr,t,"f"),r(this,yr,"m",Sr).call(this),r(this,Ir,"f").subscribe(r(this,yr,"m",Cr).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug"]}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if(n)return 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"}updateDebuggerMessages({title:t,description:e=""}){var n;t&&this.debug&&(null===(n=r(this,Or,"f"))||void 0===n||n.updateData({title:t,description:e}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield r(this,Rr,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){o(this,kr,!0,"f"),r(this,yr,"m",Er).call(this),r(this,yr,"m",Pr).call(this),r(this,yr,"m",Ar).call(this),r(this,yr,"m",qr).call(this),r(this,yr,"m",Mr).call(this);const{executionId:t,stepId:e,token:n,code:i}=I();window.addEventListener("popstate",r(this,jr,"f").popstate),r(this,Ir,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,stepId:e,executionId:t,token:n,code:i})}}))}disconnectedCallback(){r(this,Ir,"f").unsubscribeAll(),window.removeEventListener("popstate",r(this,jr,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&r(this,kr,"f")){if(e!==n&&Vr.observedAttributes.includes(t)){r(this,yr,"m",Er).call(this);const o=null===e;r(this,Ir,"f").update((({stepId:e,executionId:r})=>{let i=e,s=r;return o||(s=null,i=null,y()),{[k(t)]:n,stepId:i,executionId:s}}))}"debug"===t&&r(this,yr,"m",qr).call(this)}}}kr=new WeakMap,Ir=new WeakMap,Or=new WeakMap,jr=new WeakMap,xr=new WeakMap,Rr=new WeakMap,yr=new WeakSet,Sr=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(mr.content.cloneNode(!0)),this.formEle=this.shadowRoot.querySelector("form")},Er=function(){const t=["base-url","tenant","theme","debug"];if(Vr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[k(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')},_r=function(){const{stepId:t,executionId:e}=m();r(this,Ir,"f").update({stepId:t,executionId:e})},Ur=function(t,e){this.sdk=wr({projectId:t,baseUrl:e,fpLoad:!0}),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Cr=function(t,e,o){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n}=t;if(o("projectId")||o("baseUrl")){if(!e)return;r(this,yr,"m",Ur).call(this,e,n)}r(this,xr,"f").call(this,t)}))},Ar=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=yield r(this,Rr,"f").call(this);null===(i=null===(o=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===o?void 0:o.fontFamilies)||void 0===i||i.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Pr=function(){r(this,yr,"m",Tr).call(this),r(this,yr,"m",Dr).call(this)},Tr=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=b(this.projectId,"theme.css");t.innerText=yield g(e,"text"),this.shadowRoot.appendChild(t)}))},Dr=function(){this.formEle.setAttribute("data-theme",this.theme)},qr=function(){var t;return n(this,void 0,void 0,(function*(){this.debug?(yield import("./debugger-wc-84d810bb.js"),o(this,Or,document.createElement("descope-debugger"),"f"),Object.assign(r(this,Or,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(r(this,Or,"f"))):(null===(t=r(this,Or,"f"))||void 0===t||t.remove(),o(this,Or,null,"f"))}))},Mr=function(){this.formEle.onkeydown=t=>{if("Enter"===t.key){t.preventDefault();const e=this.formEle.querySelectorAll("button");1===e.length&&e[0].click()}}};class Gr extends Vr{constructor(){const t=new E;super(t.update.bind(t)),Lr.add(this),Nr.set(this,void 0),$r.set(this,new E),Jr.set(this,void 0),Fr.set(this,(t=>{var e,n,o,i,s;if(!(null==t?void 0:t.ok))return r(this,Lr,"m",zr).call(this,"error",null==t?void 0:t.error),void this.updateDebuggerMessages({title:null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorDescription,description:null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.message});const a=null===(s=null===(i=null===(o=t.data)||void 0===o?void 0:o.screen)||void 0===i?void 0:i.state)||void 0===s?void 0:s.errorText;a&&this.updateDebuggerMessages({title:a});const{status:c,authInfo:u}=t.data;if("completed"===c)return void r(this,Lr,"m",zr).call(this,"success",u);const{executionId:l,stepId:d,action:h,screen:p,redirect:f,webauthn:v}=t.data;r(this,Nr,"f").update({stepId:d,executionId:l,action:h,redirectUrl:null==f?void 0:f.url,screenId:null==p?void 0:p.id,screenState:null==p?void 0:p.state,webauthnTransactionId:null==v?void 0:v.transactionId,webauthnOptions:null==v?void 0:v.options})})),o(this,Nr,t,"f"),r(this,Nr,"f").subscribe(r(this,Lr,"m",Kr).bind(this)),r(this,$r,"f").subscribe(r(this,Lr,"m",Wr).bind(this))}}Nr=new WeakMap,$r=new WeakMap,Jr=new WeakMap,Fr=new WeakMap,Lr=new WeakSet,Kr=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,tenant:c,stepId:p,executionId:f,action:v,screenId:g,screenState:m,redirectUrl:y,token:k,code:I,webauthnTransactionId:O,webauthnOptions:j}=t;let x;if(r(this,Jr,"f")&&(clearInterval(r(this,Jr,"f")),o(this,Jr,null,"f")),!f){if(!a)return;const t=yield this.getFlowConfig();if(x=null==t?void 0:t.startScreenId,!x){const t=yield this.sdk.flow.start(a,{tenant:c});return void r(this,Fr,"f").call(this,t)}}if(i("token")&&k||i("code")&&I){const t=yield this.sdk.flow.next(f,p,"submit",{token:k,exchangeCode:I});return r(this,Fr,"f").call(this,t),void r(this,Nr,"f").update({token:void 0,code:void 0})}if(v===u)return y?void window.location.assign(y):void console.error("Did not get redirect url");if(v===d||v===h){if(!O||!j)return void console.error("Did not get webauthn transaction id or options");const t=v===d?yield U(j):yield C(j),e=yield this.sdk.flow.next(f,p,"submit",{transactionId:O,response:t});return void r(this,Fr,"f").call(this,e)}if(v===l&&o(this,Jr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(f,p,"submit",{});r(this,Fr,"f").call(this,t)}))),2e3),"f"),!g&&!x)return void console.error("Refreshing the page during a flow is not supported yet");const S={direction:w(+p,+e.stepId),screenState:m,htmlUrl:b(s,`${x||g}.html`)};x?S.next=(t,e)=>this.sdk.flow.start(a,{tenant:c},t,e):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(S.next=(...t)=>this.sdk.flow.next(f,p,...t)),r(this,$r,"f").update(S)}))},Wr=function(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:n,direction:o,next:i,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield g(n,"text");const u=a.content.cloneNode(!0),l=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const r=e.getAttribute("data-id"),o=null===(n=t.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(u);this.sdk.webauthn.helpers.isSupported()||u.querySelectorAll(`button[${c}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),_(u,s),((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===(e=null==s?void 0:s.totp)||void 0===e?void 0:e.image);const d=()=>{try{l.forEach((t=>{t()}))}catch(t){console.error(t)}this.formEle.replaceChildren(u),r(this,Lr,"m",Hr).call(this,i),r(this,Lr,"m",zr).call(this,"page-updated",{})};o?r(this,Lr,"m",Br).call(this,d,o):d()}))},Hr=function(t){this.formEle.onsubmit=e=>n(this,void 0,void 0,(function*(){var n;const o=null===(n=e.submitter)||void 0===n?void 0:n.getAttribute("id"),i=this.nextRequestStatus.subscribe((({isLoading:t})=>{var n,r,o,s;t?null===(r=null===(n=e.submitter)||void 0===n?void 0:n.classList)||void 0===r||r.add("loading"):(this.nextRequestStatus.unsubscribe(i),null===(s=null===(o=e.submitter)||void 0===o?void 0:o.classList)||void 0===s||s.remove("loading"))}));e.preventDefault();const s=Object.fromEntries(new FormData(e.target).entries()),a=(c=e.submitter,Array.from((null==c?void 0:c.attributes)||[]).reduce(((t,e)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return r?Object.assign(t,{[r]:e.value}):t}),{}));var c;const u=Object.assign(Object.assign(Object.assign({},a),s),{origin:window.location.origin}),l=yield t(o,u);r(this,Fr,"f").call(this,l)}))},Br=function(t,e){this.formEle.addEventListener("transitionend",(()=>{this.formEle.classList.remove("fade-out"),t()}),{once:!0});const n=e===v.forward?"slide-forward":"slide-backward";Array.from(this.formEle.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.formEle.classList.add("fade-out")},zr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Gr);export{Gr as D,E as S,r as _,o as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{D as default}from"./index-9045fb82.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import createSdk from '@descope/web-js-sdk';
|
|
2
|
+
|
|
3
|
+
declare const createIsChanged: <T extends Record<string, any>>(state: T, prevState: T) => (attrName: keyof T) => boolean;
|
|
4
|
+
|
|
5
|
+
declare type StateObject = Record<string, any>;
|
|
6
|
+
declare type SubscribeCb<T> = (state: T, prevState: T, isChanged: ReturnType<typeof createIsChanged>) => void | Promise<void>;
|
|
7
|
+
declare type UpdateStateCb<T> = (state: T) => Partial<T>;
|
|
8
|
+
declare class State<T extends StateObject> {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(init?: T);
|
|
11
|
+
get current(): T;
|
|
12
|
+
update(newState: Partial<T> | UpdateStateCb<T>): void;
|
|
13
|
+
subscribe(cb: SubscribeCb<T>): string;
|
|
14
|
+
unsubscribe(token: string): boolean;
|
|
15
|
+
unsubscribeAll(): boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ScreenState {
|
|
19
|
+
errorText?: string;
|
|
20
|
+
inputs?: Record<string, string>;
|
|
21
|
+
totp?: {
|
|
22
|
+
image?: string;
|
|
23
|
+
provisionUrl?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare type FlowState = {
|
|
28
|
+
flowId: string;
|
|
29
|
+
projectId: string;
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
tenant: string;
|
|
32
|
+
stepId: string;
|
|
33
|
+
executionId: string;
|
|
34
|
+
action: string;
|
|
35
|
+
redirectUrl: string;
|
|
36
|
+
screenId: string;
|
|
37
|
+
screenState: ScreenState;
|
|
38
|
+
token: string;
|
|
39
|
+
code: string;
|
|
40
|
+
webauthnTransactionId: string;
|
|
41
|
+
webauthnOptions: string;
|
|
42
|
+
};
|
|
43
|
+
declare type DebuggerMessage = {
|
|
44
|
+
title: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
};
|
|
47
|
+
declare type FlowStateUpdateFn = (state: FlowState) => void;
|
|
48
|
+
|
|
49
|
+
declare class BaseDescopeWc extends HTMLElement {
|
|
50
|
+
#private;
|
|
51
|
+
static get observedAttributes(): string[];
|
|
52
|
+
nextRequestStatus: State<{
|
|
53
|
+
isLoading: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
formEle: HTMLFormElement;
|
|
56
|
+
sdk: ReturnType<typeof createSdk>;
|
|
57
|
+
constructor(updateExecState: FlowStateUpdateFn);
|
|
58
|
+
get projectId(): string;
|
|
59
|
+
get flowId(): string;
|
|
60
|
+
get baseUrl(): string;
|
|
61
|
+
get tenant(): string;
|
|
62
|
+
get debug(): boolean;
|
|
63
|
+
get theme(): string;
|
|
64
|
+
updateDebuggerMessages({ title, description }: DebuggerMessage): void;
|
|
65
|
+
getFlowConfig(): Promise<any>;
|
|
66
|
+
connectedCallback(): Promise<void>;
|
|
67
|
+
disconnectedCallback(): void;
|
|
68
|
+
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare class DescopeWc extends BaseDescopeWc {
|
|
72
|
+
#private;
|
|
73
|
+
constructor();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { DescopeWc as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function r(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?r.call(t,n):r?r.value=n:e.set(t,n),n}const i="undefined"!=typeof window&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",c="data-type",l="redirect",u="poll",d="webauthnCreate",h="webauthnGet";function p(t){return new URLSearchParams(window.location.search).get(t)}function f(t){if(window.history.replaceState&&p(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var g;function v(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(g||(g={}));function m(t,e){const n=new URL(i);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function b(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?g.forward:t<e?g.backward:void 0}const w=()=>{const[t="",e=""]=(p(s)||"").split("_");return{executionId:t,stepId:e}};function y(){f(s)}const k=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),x=()=>{const{executionId:t,stepId:e}=w();(t||e)&&y();const n=p("t")||void 0;n&&f("t");const o=p(a)||void 0;return o&&f(a),{executionId:t,stepId:e,token:n,code:o}};var I,O,j;function S(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const r=n[o],i=t[r],s=e[r];if("object"==typeof i&&"object"==typeof s){if(!S(i,s))return!1}else if(i!==s)return!1}return!0}class E{constructor(t={}){I.set(this,void 0),O.set(this,{}),j.set(this,0),r(this,I,t,"f")}get current(){return Object.assign({},o(this,I,"f"))}update(t){const e="function"==typeof t?t(o(this,I,"f")):t,n=Object.assign(Object.assign({},o(this,I,"f")),e);if(!S(o(this,I,"f"),n)){const t=o(this,I,"f");r(this,I,n,"f"),Object.freeze(o(this,I,"f")),setTimeout((()=>{Object.values(o(this,O,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}}subscribe(t){return r(this,j,o(this,j,"f")+1,"f"),o(this,O,"f")[o(this,j,"f")]=t,o(this,j,"f").toString()}unsubscribe(t){const e=!!o(this,O,"f")[t];return e&&delete o(this,O,"f")[t],e}unsubscribeAll(){return r(this,O,{},"f"),!0}}I=new WeakMap,O=new WeakMap,j=new WeakMap;const _=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${c}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${c}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)};function C(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=A(n.publicKey.challenge),n.publicKey.user.id=A(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=A(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:R(o.rawId),type:o.type,response:{attestationObject:R(o.response.attestationObject),clientDataJSON:R(o.response.clientDataJSON)}});var o}))}function U(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=A(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=A(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:R(o.rawId),type:o.type,response:{authenticatorData:R(o.response.authenticatorData),clientDataJSON:R(o.response.clientDataJSON),signature:R(o.response.signature),userHandle:R(o.response.userHandle)}});var o}))}function A(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function R(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const P=(t,e,n,o={})=>{var r,i,s,a;return[Math.min(Math.max(e,("all"===o.left?t.offsetWidth:null!==(r=o.left)&&void 0!==r?r:0)-t.offsetWidth),window.innerWidth-("all"===o.right?t.offsetWidth:null!==(i=o.right)&&void 0!==i?i:0)),Math.min(Math.max(n,("all"===o.top?t.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-t.offsetHeight),window.innerHeight-("all"===o.bottom?t.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]};function L(t){this.message=t}L.prototype=new Error,L.prototype.name="InvalidCharacterError";var T="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new L("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,s="";o=e.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function D(t){this.message=t}function M(t,e){if("string"!=typeof t)throw new D("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(T(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 T(e)}}(t.split(".")[n]))}catch(t){throw new D("Invalid token specified: "+t.message)}}D.prototype=new Error,D.prototype.name="InvalidTokenError";var q="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function $(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var N="__lodash_hash_undefined__",J="[object Function]",W="[object GeneratorFunction]",K=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,F=/^\w*$/,H=/^\./,z=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,B=/\\(\\)?/g,V=/^\[object .+?Constructor\]$/,Z="object"==typeof q&&q&&q.Object===Object&&q,X="object"==typeof self&&self&&self.Object===Object&&self,G=Z||X||Function("return this")();var Y,Q=Array.prototype,tt=Function.prototype,et=Object.prototype,nt=G["__core-js_shared__"],ot=(Y=/[^.]+$/.exec(nt&&nt.keys&&nt.keys.IE_PROTO||""))?"Symbol(src)_1."+Y:"",rt=tt.toString,it=et.hasOwnProperty,st=et.toString,at=RegExp("^"+rt.call(it).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ct=G.Symbol,lt=Q.splice,ut=kt(G,"Map"),dt=kt(Object,"create"),ht=ct?ct.prototype:void 0,pt=ht?ht.toString:void 0;function ft(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 gt(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 vt(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 mt(t,e){for(var n,o,r=t.length;r--;)if((n=t[r][0])===(o=e)||n!=n&&o!=o)return r;return-1}function bt(t,e){var n;e=function(t,e){if(jt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Et(t))return!0;return F.test(t)||!K.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:jt(n=e)?n:xt(n);for(var o=0,r=e.length;null!=t&&o<r;)t=t[It(e[o++])];return o&&o==r?t:void 0}function wt(t){if(!St(t)||(e=t,ot&&ot in e))return!1;var e,n=function(t){var e=St(t)?st.call(t):"";return e==J||e==W}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?at:V;return n.test(function(t){if(null!=t){try{return rt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function yt(t,e){var n,o,r=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function kt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return wt(n)?n:void 0}ft.prototype.clear=function(){this.__data__=dt?dt(null):{}},ft.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},ft.prototype.get=function(t){var e=this.__data__;if(dt){var n=e[t];return n===N?void 0:n}return it.call(e,t)?e[t]:void 0},ft.prototype.has=function(t){var e=this.__data__;return dt?void 0!==e[t]:it.call(e,t)},ft.prototype.set=function(t,e){return this.__data__[t]=dt&&void 0===e?N:e,this},gt.prototype.clear=function(){this.__data__=[]},gt.prototype.delete=function(t){var e=this.__data__,n=mt(e,t);return!(n<0)&&(n==e.length-1?e.pop():lt.call(e,n,1),!0)},gt.prototype.get=function(t){var e=this.__data__,n=mt(e,t);return n<0?void 0:e[n][1]},gt.prototype.has=function(t){return mt(this.__data__,t)>-1},gt.prototype.set=function(t,e){var n=this.__data__,o=mt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},vt.prototype.clear=function(){this.__data__={hash:new ft,map:new(ut||gt),string:new ft}},vt.prototype.delete=function(t){return yt(this,t).delete(t)},vt.prototype.get=function(t){return yt(this,t).get(t)},vt.prototype.has=function(t){return yt(this,t).has(t)},vt.prototype.set=function(t,e){return yt(this,t).set(t,e),this};var xt=Ot((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Et(t))return pt?pt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return H.test(t)&&n.push(""),t.replace(z,(function(t,e,o,r){n.push(o?r.replace(B,"$1"):e||t)})),n}));function It(t){if("string"==typeof t||Et(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Ot(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,r=e?e.apply(this,o):o[0],i=n.cache;if(i.has(r))return i.get(r);var s=t.apply(this,o);return n.cache=i.set(r,s),s};return n.cache=new(Ot.Cache||vt),n}Ot.Cache=vt;var jt=Array.isArray;function St(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Et(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==st.call(t)}var _t=function(t,e,n){var o=null==t?void 0:bt(t,e);return void 0===o?n:o},Ct="/v1/auth/accesskey/exchange",Ut="/v1/auth/otp/verify",At="/v1/auth/otp/signin",Rt="/v1/auth/otp/signup",Pt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Lt="/v1/auth/otp/signup-in",Tt="/v1/auth/magiclink/verify",Dt="/v1/auth/magiclink/signin",Mt="/v1/auth/magiclink/signup",qt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},$t="/v1/auth/magiclink/signup-in",Nt="/v1/auth/enchantedlink/verify",Jt="/v1/auth/enchantedlink/signin",Wt="/v1/auth/enchantedlink/signup",Kt="/v1/auth/enchantedlink/pending-session",Ft={email:"/v1/auth/enchantedlink/update/email"},Ht="/v1/auth/enchantedlink/signup-in",zt="/v1/auth/oauth/authorize",Bt="/v1/auth/oauth/exchange",Vt="/v1/auth/saml/authorize",Zt="/v1/auth/saml/exchange",Xt="/v1/auth/totp/verify",Gt="/v1/auth/totp/signup",Yt="/v1/user/totp/update",Qt={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},te={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ee={start:"/v1/auth/webauthn/signup-in/start"},ne={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},oe="/v1/auth/refresh",re="/v1/auth/logout",ie="/v1/auth/logoutall",se="/v1/auth/me",ae="/v1/flow/start",ce="/v1/flow/next";const le=()=>{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 ue;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ue||(ue={}));const de=(...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}),{})),he=t=>void 0===t?void 0:JSON.stringify(t),pe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},fe=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:r,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{t.log((t=>le().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),le().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:c,body:l,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:c,baseUrl:t,queryParams:d}),{headers:de(pe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.36"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:he(l),credentials:i||"include"});return(null==r?void 0:r.afterRequest)&&r.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:ue.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ue.post,token:r}),put:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ue.put,token:r}),delete:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:ue.delete,token:r}),hooks:r}};function ge(t,e,n){var o;let r=ve(t);e&&(r=null===(o=r.tenants)||void 0===o?void 0:o[e]);const i=r[n];return Array.isArray(i)?i:[]}function ve(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return M(t)}function me(t){const{exp:e}=ve(t);return(new Date).getTime()/1e3>e}function be(t,e){return ge(t,e,"permissions")}function we(t,e){return ge(t,e,"roles")}const ye=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function ke(t,e){const n=await t,o={code:n.status,ok:n.ok,response:n},r=await n.clone().json();return n.ok?o.data=e?e(r):r:o.error=r,o}const xe=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ie=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Oe=t=>e=>t.test(e),je=Oe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Se=Oe(/^\+[1-9]{1}[0-9]{3,14}$/),Ee=xe(je,'"{val}" is not a valid email'),_e=xe(Se,'"{val}" is not a valid phone number'),Ce=xe((1,t=>t.length>=1),"Minimum length is 1");const Ue=xe((t=>"string"==typeof t),"Input is not a string"),Ae=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ie(...t).validate(n[e]))),e(...n)),Re=t=>[Ue(`"${t}" must be a string`),Ce(`"${t}" must not be empty`)],Pe=t=>[Ue(`"${t}" must be a string`),Ee()],Le=t=>[Ue(`"${t}" must be a string`),_e()],Te=Ae(Re("accessKey")),De=t=>({exchange:Te((e=>ke(t.post(Ct,{},{token:e}))))});var Me,qe,$e,Ne,Je;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Me||(Me={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(qe||(qe={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}($e||($e={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ne||(Ne={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(Je||(Je={}));const We=Re("identifier"),Ke=Ae(We,Re("code")),Fe=Ae(We),He=Ae(We,Le("phone")),ze=Ae(We,Pe("email")),Be=t=>({verify:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ke(((e,o)=>ke(t.post(ye(Ut,n),{code:o,externalId:e}))))})),{}),signIn:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe(((e,o,r)=>ke(t.post(ye(At,n),{externalId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe(((e,o)=>ke(t.post(ye(Rt,n),{externalId:e,user:o}))))})),{}),signUpOrIn:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe((e=>ke(t.post(ye(Lt,n),{externalId:e}))))})),{}),update:{email:ze(((e,n,o)=>ke(t.post(Pt.email,{externalId:e,email:n},{token:o})))),phone:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o,r)=>ke(t.post(ye(Pt.phone,n),{externalId:e,phone:o},{token:r}))))})),{})}}),Ve=Re("identifier"),Ze=Re("uri"),Xe=Ae(Re("token")),Ge=Ae(Ve,Ze),Ye=Ae(Ve,Le("phone"),Ze),Qe=Ae(Ve,Pe("email"),Ze),tn=t=>({verify:Xe((e=>ke(t.post(Tt,{token:e})))),signIn:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ge(((e,o,r,i)=>ke(t.post(ye(Dt,n),{externalId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ge(((e,o,r)=>ke(t.post(ye(Mt,n),{externalId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(qe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ge(((e,o)=>ke(t.post(ye($t,n),{externalId:e,URI:o}))))})),{}),update:{email:Qe(((e,n,o,r)=>ke(t.post(qt.email,{externalId:e,email:n,URI:o},{token:r})))),phone:Object.keys(Me).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ye(((e,o,r,i)=>ke(t.post(ye(qt.phone,n),{externalId:e,phone:o,URI:r},{token:i}))))})),{})}}),en=Re("identifier"),nn=Re("uri"),on=Ae(Re("token")),rn=Ae(en,nn),sn=Ae(Re("pendingRef")),an=Ae(en,Pe("email"),nn),cn=t=>({verify:on((e=>ke(t.post(Nt,{token:e})))),signIn:rn(((e,n,o,r)=>ke(t.post(ye(Jt,qe.email),{externalId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:rn(((e,n)=>ke(t.post(ye(Ht,qe.email),{externalId:e,URI:n})))),signUp:rn(((e,n,o)=>ke(t.post(ye(Wt,qe.email),{externalId:e,URI:n,user:o})))),waitForSession:sn(((e,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Kt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ke(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:an(((e,n,o,r)=>ke(t.post(Ft.email,{externalId:e,email:n,URI:o},{token:r}))))}});var ln;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(ln||(ln={}));const un=Ae(Re("code")),dn=t=>({start:Object.keys(ln).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(zt,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return ke(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:un((e=>ke(t.post(Bt,{code:e}))))}),hn=Ae(Re("flowId")),pn=Ae(Re("executionId"),Re("stepId"),Re("interactionId")),fn=t=>({start:hn(((e,n,o,r)=>ke(t.post(ae,{flowId:e,options:n,interactionId:o,input:r})))),next:pn(((e,n,o,r)=>ke(t.post(ce,{executionId:e,stepId:n,interactionId:o,input:r}))))}),gn=Ae(Re("tenant")),vn=Ae(Re("code")),mn=t=>({start:gn((async(e,n,{redirect:o=!1}={},r,i)=>{const s=await t.post(Vt,r||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!o||!s.ok)return ke(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:vn((e=>ke(t.post(Zt,{code:e}))))}),bn=Re("identifier"),wn=Ae(bn,Re("code")),yn=Ae(bn),kn=Ae(bn),xn=t=>({signUp:yn(((e,n)=>ke(t.post(Gt,{externalId:e,user:n})))),verify:wn(((e,n,o,r)=>ke(t.post(Xt,{externalId:e,code:n,loginOptions:o},{token:r})))),update:kn(((e,n)=>ke(t.post(Yt,{externalId:e},{token:n}))))}),In=Re("identifier"),On=Re("origin"),jn=Ae(In,On,Re("name")),Sn=Ae(In,On),En=Ae(In,On,Re("token")),_n=Ae(Re("transactionId"),Re("response")),Cn=t=>({signUp:{start:jn(((e,n,o)=>ke(t.post(Qt.start,{user:{externalId:e,name:o},origin:n})))),finish:_n(((e,n)=>ke(t.post(Qt.finish,{transactionId:e,response:n}))))},signIn:{start:Sn(((e,n,o,r)=>ke(t.post(te.start,{externalId:e,origin:n,loginOptions:o},{token:r})))),finish:_n(((e,n)=>ke(t.post(te.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Sn(((e,n)=>ke(t.post(ee.start,{externalId:e,origin:n}))))},update:{start:En(((e,n,o)=>ke(t.post(ne.start,{externalId:e,origin:n},{token:o})))),finish:_n(((e,n)=>ke(t.post(ne.finish,{transactionId:e,response:n}))))}}),Un=Ae(Re("token")),An=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let r=o.shift(),i=t;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${e}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${e}" is not a function`);const s=i[r];i[r]=n(s)})),t);var Rn;let Pn=Ae([("projectId",Rn=Re("projectId"),xe(((t,e)=>n=>Ie(...e).validate(_t(n,t)))("projectId",Rn))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),r=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:r})=>{return i=fe({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r}),{accessKey:De(i),otp:Be(i),magicLink:tn(i),enchantedLink:cn(i),oauth:dn(i),saml:mn(i),totp:xn(i),webauthn:Cn(i),flow:fn(i),refresh:t=>ke(i.post(oe,{},{token:t})),logout:t=>ke(i.post(re,{},{token:t})),logoutAll:t=>ke(i.post(ie,{},{token:t})),me:t=>ke(i.get(se,{token:t})),isJwtExpired:Un(me),getJwtPermissions:Un(be),getJwtRoles:Un(we),httpClient:i};var i})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:(t,e)=>{null==r||r.forEach((n=>n(t,null==e?void 0:e.clone())))}}}))}));var Ln=Object.assign(Pn,{DeliveryMethods:qe});function Tn(t,e){var n=[];return function(t,e){var n,o,r=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),r=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,r++)o[r]=i[s];return o}(t),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=r.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?r.postpone():r.exclude();var e,o=r.current();if(void 0===o)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(t,(function(t){var o=new Date,r=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},i=e(t);return i.then(r,r),i})).then((function(t){return[t,{attempts:n}]}))}var Dn="Failed to load the JS script of the agent";function Mn(n){var o;n.scriptUrlPattern;var r=n.token,i=n.apiKey,s=void 0===i?r:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Tn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(c,s),qn).catch(Nn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function qn(t){return function(t,e,n,o){var r,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),o=e.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(r=e,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),r)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),r=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),e()},o.onerror=function(){r(),n(new Error(Dn))},o.async=!0,o.src=t,i.appendChild(o)}))}(t)})).then($n)}function $n(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function Nn(t){throw t instanceof Error&&"9319"===t.message?new Error(Dn):t}var Jn={exports:{}},Wn={exports:{}};Wn.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}function e(n,o){function r(e,r,i){if("undefined"!=typeof document){"number"==typeof(i=t({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=e+"="+n.write(r,e)+s}}function i(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],o={},r=0;r<e.length;r++){var i=e[r].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=n.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}}return Object.create({set:r,get:i,remove:function(e,n){r(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}return 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:"/"})}(),function(t){t.exports=Wn.exports}(Jn);var Kn=$(Jn.exports);const Fn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=t.hooks)||void 0===r?void 0:r[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Hn=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||{}},zn=async t=>{const e=await Hn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Bn="undefined"!=typeof localStorage,Vn=(t,e)=>Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Zn=t=>Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Xn=t=>Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),Gn=t=>Object.assign(t,{headers:Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.17"})}),Yn="undefined"!=typeof window,Qn=Yn&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",to=Yn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",eo=(t="",e="")=>({vsid:t,vrid:e}),no=(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},oo=t=>(t.body&&(t.body.fpData=no(!0)||eo()),t),ro=t=>async(...e)=>{e[1]=e[1]||{};const[,n]=e,o=Zn("dls_last_user_external_id");return o&&(n.lastUser={externalId:o}),await t(...e)},io=t=>async(...e)=>{const n=await t(...e);return Xn("dls_last_user_external_id"),n};function so(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const ao=(t={},n)=>{var{refreshJwt:o,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Vn("DSR",o),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(e){const i=new Date(1e3*r);Kn.set(t,e,{path:n,domain:o,expires:i,sameSite:"None",secure:!0})}}("DS",r,i):Vn("DS",r))};function co(){return Zn("DSR")||""}function lo(){return Kn.get("DS")||Zn("DS")||""}function uo(){Xn("DSR"),Xn("DS"),Kn.remove("DS")}const ho=t=>Object.assign(t,{token:t.token||co()}),po=t=>async(...e)=>{const n=await t(...e);return uo(),n};async function fo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=mo(n.publicKey.challenge),n.publicKey.user.id=mo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=mo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:bo(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:bo(n.response.attestationObject),clientDataJSON:bo(n.response.clientDataJSON)})}));var n}async function go(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=mo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=mo(t.id)})),n}(t);return n=await navigator.credentials.get(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:bo(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:bo(n.response.authenticatorData),clientDataJSON:bo(n.response.clientDataJSON),signature:bo(n.response.signature),userHandle:n.response.userHandle?bo(n.response.userHandle):void 0})}));var n}async function vo(t=!1){if(!Yn)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function mo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function bo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var wo=t=>Object.assign(Object.assign({},t.flow),{start:async(e,n,o,r)=>{const i=await vo(),s=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}});return t.flow.start(e,s,o,r)}});const yo=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>e=>{const n=t(Fn(e,{afterRequest:async(t,e)=>{var n;const o=await zn(e),r=null===(n=null==o?void 0:o.externalIds)||void 0===n?void 0:n[0];r&&(t=>{Vn("dls_last_user_external_id",t)})(r)}}));let o=An(n,["flow.start"],ro);return o=An(o,["logout","logoutAll"],io),o}),(t=>n=>{var{fpKey:o,fpLoad:r}=n,i=e(n,["fpKey","fpLoad"]);return Yn?r&&(async t=>{try{if(no())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Mn({apiKey:t||Qn,endpoint:to}),o=await n,{requestId:r}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(eo(e,r))}catch(t){global.FB_DEBUG&&console.error(t)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(Fn(i,{beforeRequest:oo}))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:r,setTimer:i}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(Fn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Hn(e);if(401===(null==e?void 0:e.status))r();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;r(),i((()=>s.refresh(n)),t)}var a}}));return An(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return r(),n}))}),(t=>e=>t(Fn(e,{beforeRequest:Gn}))),(t=>e=>{const n=so(),o=so(),r=t(Fn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await zn(e);t&&o.pub(t);const{sessionJwt:r}=await Hn(e);r&&n.pub(r)}}})),i=An(r,["logout","logoutAll"],(t=>async(...e)=>{const r=await t(...e);return n.pub(null),o.pub(null),r}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(Yn||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"),!o||!Yn)return t(i);const s=t(Fn(i,{beforeRequest:ho,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?uo():ao(await Hn(e),r)}})),a=An(s,["logout","logoutAll"],po);return Object.assign(a,{getRefreshToken:co,getSessionToken:lo})}))(((...t)=>{const e=Ln(...t);return Object.assign(Object.assign({},e),{flow:wo(e),webauthn:(n=e,{async signUp(t,e){const o=await n.webauthn.signUp.start(t,window.location.origin,e),r=await fo(o.data.options);return await n.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(t){const e=await n.webauthn.signIn.start(t,window.location.origin),o=await go(e.data.options);return await n.webauthn.signIn.finish(e.data.transactionId,o)},async signUpOrIn(t){var e;const o=await n.webauthn.signUpOrIn.start(t,window.location.origin);if(null===(e=o.data)||void 0===e?void 0:e.create){const t=await fo(o.data.options);return await n.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await go(o.data.options);return await n.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,e){const o=await n.webauthn.update.start(t,window.location.origin,e),r=await fo(o.data.options);return await n.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:fo,get:go,isSupported:vo}})});var n})),ko=document.createElement("template");var xo,Io,Oo,jo,So,Eo,_o,Co,Uo,Ao,Ro,Po,Lo,To,Do,Mo,qo,$o,No,Jo,Wo,Ko,Fo,Ho,zo,Bo,Vo,Zo,Xo,Go,Yo,Qo,tr,er,nr,or,rr,ir;ko.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\tform[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<form></form>\n\t";class sr extends HTMLElement{constructor(t){super(),xo.add(this),Io.set(this,!1),Oo.set(this,new E),this.nextRequestStatus=new E({isLoading:!1}),jo.set(this,void 0),So.set(this,{popstate:o(this,xo,"m",Uo).bind(this)}),Eo.set(this,void 0),Po.set(this,(()=>{let t;return()=>n(this,void 0,void 0,(function*(){if(t)return t;const e=m(this.projectId,"config.json");try{t=yield v(e,"json")}catch(t){console.error("Cannot get config file")}return t}))})()),r(this,Eo,t,"f"),o(this,xo,"m",_o).call(this),o(this,Oo,"f").subscribe(o(this,xo,"m",Ro).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug"]}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if(n)return 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"}updateDebuggerMessages({title:t,description:e=""}){var n;t&&this.debug&&(null===(n=o(this,jo,"f"))||void 0===n||n.updateData({title:t,description:e}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,Po,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){r(this,Io,!0,"f"),o(this,xo,"m",Co).call(this),o(this,xo,"m",To).call(this),o(this,xo,"m",Lo).call(this),o(this,xo,"m",qo).call(this),o(this,xo,"m",$o).call(this);const{executionId:t,stepId:e,token:n,code:i}=x();window.addEventListener("popstate",o(this,So,"f").popstate),o(this,Oo,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,stepId:e,executionId:t,token:n,code:i})}}))}disconnectedCallback(){o(this,Oo,"f").unsubscribeAll(),window.removeEventListener("popstate",o(this,So,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Io,"f")){if(e!==n&&sr.observedAttributes.includes(t)){o(this,xo,"m",Co).call(this);const r=null===e;o(this,Oo,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,y()),{[k(t)]:n,stepId:i,executionId:s}}))}"debug"===t&&o(this,xo,"m",qo).call(this)}}}Io=new WeakMap,Oo=new WeakMap,jo=new WeakMap,So=new WeakMap,Eo=new WeakMap,Po=new WeakMap,xo=new WeakSet,_o=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ko.content.cloneNode(!0)),this.formEle=this.shadowRoot.querySelector("form")},Co=function(){const t=["base-url","tenant","theme","debug"];if(sr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[k(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')},Uo=function(){const{stepId:t,executionId:e}=w();o(this,Oo,"f").update({stepId:t,executionId:e})},Ao=function(t,e){this.sdk=yo({projectId:t,baseUrl:e,fpLoad:!0}),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Ro=function(t,e,r){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n}=t;if(r("projectId")||r("baseUrl")){if(!e)return;o(this,xo,"m",Ao).call(this,e,n)}o(this,Eo,"f").call(this,t)}))},Lo=function(){var t,e,r,i;return n(this,void 0,void 0,(function*(){const n=yield o(this,Po,"f").call(this);null===(i=null===(r=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===r?void 0:r.fontFamilies)||void 0===i||i.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},To=function(){o(this,xo,"m",Do).call(this),o(this,xo,"m",Mo).call(this)},Do=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=m(this.projectId,"theme.css");t.innerText=yield v(e,"text"),this.shadowRoot.appendChild(t)}))},Mo=function(){this.formEle.setAttribute("data-theme",this.theme)},qo=function(){var t;return n(this,void 0,void 0,(function*(){this.debug?(yield Promise.resolve().then((function(){return ur})),r(this,jo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,jo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,jo,"f"))):(null===(t=o(this,jo,"f"))||void 0===t||t.remove(),r(this,jo,null,"f"))}))},$o=function(){this.formEle.onkeydown=t=>{if("Enter"===t.key){t.preventDefault();const e=this.formEle.querySelectorAll("button");1===e.length&&e[0].click()}}};class ar extends sr{constructor(){const t=new E;super(t.update.bind(t)),No.add(this),Jo.set(this,void 0),Wo.set(this,new E),Ko.set(this,void 0),Ho.set(this,(t=>{var e,n,r,i,s;if(!(null==t?void 0:t.ok))return o(this,No,"m",Zo).call(this,"error",null==t?void 0:t.error),void this.updateDebuggerMessages({title:null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorDescription,description:null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.message});const a=null===(s=null===(i=null===(r=t.data)||void 0===r?void 0:r.screen)||void 0===i?void 0:i.state)||void 0===s?void 0:s.errorText;a&&this.updateDebuggerMessages({title:a});const{status:c,authInfo:l}=t.data;if("completed"===c)return void o(this,No,"m",Zo).call(this,"success",l);const{executionId:u,stepId:d,action:h,screen:p,redirect:f,webauthn:g}=t.data;o(this,Jo,"f").update({stepId:d,executionId:u,action:h,redirectUrl:null==f?void 0:f.url,screenId:null==p?void 0:p.id,screenState:null==p?void 0:p.state,webauthnTransactionId:null==g?void 0:g.transactionId,webauthnOptions:null==g?void 0:g.options})})),r(this,Jo,t,"f"),o(this,Jo,"f").subscribe(o(this,No,"m",Fo).bind(this)),o(this,Wo,"f").subscribe(o(this,No,"m",zo).bind(this))}}Jo=new WeakMap,Wo=new WeakMap,Ko=new WeakMap,Ho=new WeakMap,No=new WeakSet,Fo=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,tenant:c,stepId:p,executionId:f,action:g,screenId:v,screenState:w,redirectUrl:y,token:k,code:x,webauthnTransactionId:I,webauthnOptions:O}=t;let j;if(o(this,Ko,"f")&&(clearInterval(o(this,Ko,"f")),r(this,Ko,null,"f")),!f){if(!a)return;const t=yield this.getFlowConfig();if(j=null==t?void 0:t.startScreenId,!j){const t=yield this.sdk.flow.start(a,{tenant:c});return void o(this,Ho,"f").call(this,t)}}if(i("token")&&k||i("code")&&x){const t=yield this.sdk.flow.next(f,p,"submit",{token:k,exchangeCode:x});return o(this,Ho,"f").call(this,t),void o(this,Jo,"f").update({token:void 0,code:void 0})}if(g===l)return y?void window.location.assign(y):void console.error("Did not get redirect url");if(g===d||g===h){if(!I||!O)return void console.error("Did not get webauthn transaction id or options");const t=g===d?yield C(O):yield U(O),e=yield this.sdk.flow.next(f,p,"submit",{transactionId:I,response:t});return void o(this,Ho,"f").call(this,e)}if(g===u&&r(this,Ko,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(f,p,"submit",{});o(this,Ho,"f").call(this,t)}))),2e3),"f"),!v&&!j)return void console.error("Refreshing the page during a flow is not supported yet");const S={direction:b(+p,+e.stepId),screenState:w,htmlUrl:m(s,`${j||v}.html`)};j?S.next=(t,e)=>this.sdk.flow.start(a,{tenant:c},t,e):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(S.next=(...t)=>this.sdk.flow.next(f,p,...t)),o(this,Wo,"f").update(S)}))},zo=function(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:n,direction:r,next:i,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield v(n,"text");const l=a.content.cloneNode(!0),u=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),r=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,i=Function(r).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(l);this.sdk.webauthn.helpers.isSupported()||l.querySelectorAll(`button[${c}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),_(l,s),((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})`))})(l.querySelector("div"),null===(e=null==s?void 0:s.totp)||void 0===e?void 0:e.image);const d=()=>{try{u.forEach((t=>{t()}))}catch(t){console.error(t)}this.formEle.replaceChildren(l),o(this,No,"m",Bo).call(this,i),o(this,No,"m",Zo).call(this,"page-updated",{})};r?o(this,No,"m",Vo).call(this,d,r):d()}))},Bo=function(t){this.formEle.onsubmit=e=>n(this,void 0,void 0,(function*(){var n;const r=null===(n=e.submitter)||void 0===n?void 0:n.getAttribute("id"),i=this.nextRequestStatus.subscribe((({isLoading:t})=>{var n,o,r,s;t?null===(o=null===(n=e.submitter)||void 0===n?void 0:n.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(i),null===(s=null===(r=e.submitter)||void 0===r?void 0:r.classList)||void 0===s||s.remove("loading"))}));e.preventDefault();const s=Object.fromEntries(new FormData(e.target).entries()),a=(c=e.submitter,Array.from((null==c?void 0:c.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}),{}));var c;const l=Object.assign(Object.assign(Object.assign({},a),s),{origin:window.location.origin}),u=yield t(r,l);o(this,Ho,"f").call(this,u)}))},Vo=function(t,e){this.formEle.addEventListener("transitionend",(()=>{this.formEle.classList.remove("fade-out"),t()}),{once:!0});const n=e===g.forward?"slide-forward":"slide-backward";Array.from(this.formEle.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.formEle.classList.add("fade-out")},Zo=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ar);const cr=document.createElement("template");cr.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(),Xo.add(this),Go.set(this,new E({messages:[]})),Yo.set(this,void 0),Qo.set(this,void 0),tr.set(this,void 0),er.set(this,{resize:o(this,Xo,"m",ir).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(cr.content.cloneNode(!0)),r(this,Yo,this.shadowRoot.querySelector(".debugger"),"f"),r(this,Qo,o(this,Yo,"f").querySelector(".content"),"f"),r(this,tr,o(this,Yo,"f").querySelector(".header"),"f")}updateData(t){o(this,Go,"f").update((e=>({messages:e.messages.concat(t)})))}connectedCallback(){var t;((t,e,n)=>{let o=0,r=0,i=0,s=0;function a(e){e.preventDefault(),o=i-e.clientX,r=s-e.clientY,i=e.clientX,s=e.clientY;const[a,c]=P(t,t.offsetLeft-o,t.offsetTop-r,n);t.style.top=`${c}px`,t.style.left=`${a}px`}function c(){document.onmouseup=null,document.onmousemove=null}function l(t){t.preventDefault(),i=t.clientX,s=t.clientY,document.onmouseup=c,document.onmousemove=a}e?e.onmousedown=l:t.onmousedown=l})(o(this,Yo,"f"),o(this,tr,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,er,"f").resize),(t=o(this,Yo,"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,Yo,"f").onresize=o(this,Xo,"m",rr).bind(this),o(this,Go,"f").subscribe(o(this,Xo,"m",nr).bind(this))}disconnectedCallback(){o(this,Go,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,er,"f").resize)}}Go=new WeakMap,Yo=new WeakMap,Qo=new WeakMap,tr=new WeakMap,er=new WeakMap,Xo=new WeakSet,nr=function(t){o(this,Xo,"m",or).call(this,t),o(this,Xo,"m",rr).call(this)},or=function(t){o(this,Qo,"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("")},rr=function(){o(this,Qo,"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]=P(o(this,Yo,"f"),Number.parseInt(o(this,Yo,"f").style.left,10),Number.parseInt(o(this,Yo,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Yo,"f").style.top=`${e}px`,o(this,Yo,"f").style.left=`${t}px`},customElements.define("descope-debugger",lr);var ur=Object.freeze({__proto__:null,default:lr})}();
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"module": "dist/
|
|
6
|
-
"types": "dist/
|
|
3
|
+
"version": "0.1.0-alpha.23",
|
|
4
|
+
"main": "dist/inedx.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"description": "Descope WC",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"start": "rollup -c rollup.config.app.serve.js -w",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"@types/lodash.get": "^4.4.7",
|
|
44
44
|
"@types/lodash.set": "^4.3.7",
|
|
45
45
|
"dotenv": "^16.0.3",
|
|
46
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.30.0",
|
|
47
47
|
"eslint-config-airbnb": "19.0.4",
|
|
48
48
|
"eslint-config-airbnb-typescript": "17.0.0",
|
|
49
49
|
"eslint-config-prettier": "8.5.0",
|
|
50
50
|
"eslint-config-standard": "17.0.0",
|
|
51
51
|
"eslint-import-resolver-typescript": "3.4.0",
|
|
52
52
|
"eslint-plugin-import": "2.26.0",
|
|
53
|
-
"eslint-plugin-jest": "27.1.
|
|
53
|
+
"eslint-plugin-jest": "27.1.7",
|
|
54
54
|
"eslint-plugin-jest-dom": "4.0.3",
|
|
55
55
|
"eslint-plugin-jest-formatting": "3.1.0",
|
|
56
|
-
"eslint-plugin-n": "15.
|
|
56
|
+
"eslint-plugin-n": "15.6.0",
|
|
57
57
|
"eslint-plugin-no-only-tests": "3.1.0",
|
|
58
58
|
"eslint-plugin-prefer-arrow": "1.2.3",
|
|
59
59
|
"eslint-plugin-prettier": "4.2.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"typescript": "^4.5.3"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@descope/web-js-sdk": "0.1.0-alpha.
|
|
80
|
+
"@descope/web-js-sdk": "0.1.0-alpha.17"
|
|
81
81
|
},
|
|
82
82
|
"overrides": {
|
|
83
83
|
"terser": "5.16.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{S as e,_ as n,a as t}from"./descope-wc-d680a346.js";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new e({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:n(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),t(this,l,this.shadowRoot.querySelector(".debugger"),"f"),t(this,a,n(this,l,"f").querySelector(".content"),"f"),t(this,r,n(this,l,"f").querySelector(".header"),"f")}updateData(e){n(this,o,"f").update((n=>({messages:n.messages.concat(e)})))}connectedCallback(){var e;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(n(this,l,"f"),n(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",n(this,d,"f").resize),(e=n(this,l,"f")).onmousemove=n=>{(n.target.w&&n.target.w!==n.target.offsetWidth||n.target.h&&n.target.h!==n.target.offsetHeight)&&e.onresize(n),n.target.w=n.target.offsetWidth,n.target.h=n.target.offsetHeight},n(this,l,"f").onresize=n(this,i,"m",p).bind(this),n(this,o,"f").subscribe(n(this,i,"m",c).bind(this))}disconnectedCallback(){n(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",n(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(e){n(this,i,"m",h).call(this,e),n(this,i,"m",p).call(this)},h=function(e){n(this,a,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){n(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[e,t]=s(n(this,l,"f"),Number.parseInt(n(this,l,"f").style.left,10),Number.parseInt(n(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});n(this,l,"f").style.top=`${t}px`,n(this,l,"f").style.left=`${e}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function r(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,n):o?o.value=n:e.set(t,n),n}function i(t){this.message=t}i.prototype=new Error,i.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new i("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,s=0,a="";r=e.charAt(s++);~r&&(n=o%4?64*n+r:r,o++%4)?a+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};function a(t){this.message=t}function c(t,e){if("string"!=typeof t)throw new a("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(s(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 s(e)}}(t.split(".")[n]))}catch(t){throw new a("Invalid token specified: "+t.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var d="__lodash_hash_undefined__",h="[object Function]",p="[object GeneratorFunction]",f=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,v=/^\w*$/,g=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,w=/\\(\\)?/g,m=/^\[object .+?Constructor\]$/,y="object"==typeof l&&l&&l.Object===Object&&l,k="object"==typeof self&&self&&self.Object===Object&&self,I=y||k||Function("return this")();var O,j=Array.prototype,S=Function.prototype,x=Object.prototype,_=I["__core-js_shared__"],E=(O=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"",U=S.toString,C=x.hasOwnProperty,P=x.toString,A=RegExp("^"+U.call(C).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=I.Symbol,R=j.splice,D=H(I,"Map"),M=H(Object,"create"),L=T?T.prototype:void 0,N=L?L.toString:void 0;function $(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function q(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function J(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function K(t,e){for(var n,r,o=t.length;o--;)if((n=t[o][0])===(r=e)||n!=n&&r!=r)return o;return-1}function W(t,e){var n;e=function(t,e){if(Z(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||X(t))return!0;return v.test(t)||!f.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Z(n=e)?n:z(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[V(e[r++])];return r&&r==o?t:void 0}function B(t){if(!Q(t)||(e=t,E&&E in e))return!1;var e,n=function(t){var e=Q(t)?P.call(t):"";return e==h||e==p}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?A:m;return n.test(function(t){if(null!=t){try{return U.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function F(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function H(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return B(n)?n:void 0}$.prototype.clear=function(){this.__data__=M?M(null):{}},$.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},$.prototype.get=function(t){var e=this.__data__;if(M){var n=e[t];return n===d?void 0:n}return C.call(e,t)?e[t]:void 0},$.prototype.has=function(t){var e=this.__data__;return M?void 0!==e[t]:C.call(e,t)},$.prototype.set=function(t,e){return this.__data__[t]=M&&void 0===e?d:e,this},q.prototype.clear=function(){this.__data__=[]},q.prototype.delete=function(t){var e=this.__data__,n=K(e,t);return!(n<0)&&(n==e.length-1?e.pop():R.call(e,n,1),!0)},q.prototype.get=function(t){var e=this.__data__,n=K(e,t);return n<0?void 0:e[n][1]},q.prototype.has=function(t){return K(this.__data__,t)>-1},q.prototype.set=function(t,e){var n=this.__data__,r=K(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},J.prototype.clear=function(){this.__data__={hash:new $,map:new(D||q),string:new $}},J.prototype.delete=function(t){return F(this,t).delete(t)},J.prototype.get=function(t){return F(this,t).get(t)},J.prototype.has=function(t){return F(this,t).has(t)},J.prototype.set=function(t,e){return F(this,t).set(t,e),this};var z=G((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(X(t))return N?N.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return g.test(t)&&n.push(""),t.replace(b,(function(t,e,r,o){n.push(r?o.replace(w,"$1"):e||t)})),n}));function V(t){if("string"==typeof t||X(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function G(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(G.Cache||J),n}G.Cache=J;var Z=Array.isArray;function Q(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function X(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==P.call(t)}var Y=function(t,e,n){var r=null==t?void 0:W(t,e);return void 0===r?n:r},tt="/v1/auth/accesskey/exchange",et="/v1/auth/otp/verify",nt="/v1/auth/otp/signin",rt="/v1/auth/otp/signup",ot={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},it="/v1/auth/otp/signup-in",st="/v1/auth/magiclink/verify",at="/v1/auth/magiclink/signin",ct="/v1/auth/magiclink/signup",lt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ut="/v1/auth/magiclink/signup-in",dt="/v1/auth/enchantedlink/verify",ht="/v1/auth/enchantedlink/signin",pt="/v1/auth/enchantedlink/signup",ft="/v1/auth/enchantedlink/pending-session",vt={email:"/v1/auth/enchantedlink/update/email"},gt="/v1/auth/enchantedlink/signup-in",bt="/v1/auth/oauth/authorize",wt="/v1/auth/oauth/exchange",mt="/v1/auth/saml/authorize",yt="/v1/auth/saml/exchange",kt="/v1/auth/totp/verify",It="/v1/auth/totp/signup",Ot="/v1/user/totp/update",jt={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},St={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},xt={start:"/v1/auth/webauthn/signup-in/start"},_t={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Et="/v1/flow/start",Ut="/v1/flow/next";const Ct=()=>{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 Pt;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Pt||(Pt={}));const At=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,r])=>(t[n]=r,t)),t),t}),{})),Tt=t=>void 0===t?void 0:JSON.stringify(t),Rt=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Dt=({baseUrl:t,projectId:e,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{t.log((t=>Ct().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const r=await n(...e);return t[r.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),Ct().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:l,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:t,queryParams:d}),{headers:At(Rt(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.34"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Tt(l),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:r}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:Pt.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Pt.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Pt.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Pt.delete,token:o})}};function Mt(t,e,n){var r;let o=Lt(t);e&&(o=null===(r=o.tenants)||void 0===r?void 0:r[e]);const i=o[n];return Array.isArray(i)?i:[]}function Lt(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return c(t)}function Nt(t){const{exp:e}=Lt(t);return(new Date).getTime()/1e3>e}function $t(t,e){return Mt(t,e,"permissions")}function qt(t,e){return Mt(t,e,"roles")}const Jt=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Kt(t,e){const n=await t,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=e?e(o):o:r.error=o,r}const Wt=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Bt=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ft=t=>e=>t.test(e),Ht=Ft(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),zt=Ft(/^\+[1-9]{1}[0-9]{3,14}$/),Vt=Wt(Ht,'"{val}" is not a valid email'),Gt=Wt(zt,'"{val}" is not a valid phone number'),Zt=Wt((1,t=>t.length>=1),"Minimum length is 1");const Qt=Wt((t=>"string"==typeof t),"Input is not a string"),Xt=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Bt(...t).validate(n[e]))),e(...n)),Yt=t=>[Qt(`"${t}" must be a string`),Zt(`"${t}" must not be empty`)],te=t=>[Qt(`"${t}" must be a string`),Vt()],ee=t=>[Qt(`"${t}" must be a string`),Gt()],ne=Xt(Yt("accessKey")),re=t=>({exchange:ne((e=>Kt(t.post(tt,{},{token:e}))))});var oe,ie,se,ae,ce;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(oe||(oe={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(ie||(ie={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(se||(se={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(ae||(ae={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(ce||(ce={}));const le=Yt("identifier"),ue=Xt(le,Yt("code")),de=Xt(le),he=Xt(le,ee("phone")),pe=Xt(le,te("email")),fe=t=>({verify:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ue(((e,r)=>Kt(t.post(Jt(et,n),{code:r,externalId:e}))))})),{}),signIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,r,o)=>Kt(t.post(Jt(nt,n),{externalId:e,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,r)=>Kt(t.post(Jt(rt,n),{externalId:e,user:r}))))})),{}),signUpOrIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de((e=>Kt(t.post(Jt(it,n),{externalId:e}))))})),{}),update:{email:pe(((e,n,r)=>Kt(t.post(ot.email,{externalId:e,email:n},{token:r})))),phone:Object.keys(oe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:he(((e,r,o)=>Kt(t.post(Jt(ot.phone,n),{externalId:e,phone:r},{token:o}))))})),{})}}),ve=Yt("identifier"),ge=Yt("uri"),be=Xt(Yt("token")),we=Xt(ve,ge),me=Xt(ve,ee("phone"),ge),ye=Xt(ve,te("email"),ge),ke=t=>({verify:be((e=>Kt(t.post(st,{token:e})))),signIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r,o,i)=>Kt(t.post(Jt(at,n),{externalId:e,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r,o)=>Kt(t.post(Jt(ct,n),{externalId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r)=>Kt(t.post(Jt(ut,n),{externalId:e,URI:r}))))})),{}),update:{email:ye(((e,n,r,o)=>Kt(t.post(lt.email,{externalId:e,email:n,URI:r},{token:o})))),phone:Object.keys(oe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:me(((e,r,o,i)=>Kt(t.post(Jt(lt.phone,n),{externalId:e,phone:r,URI:o},{token:i}))))})),{})}}),Ie=Yt("identifier"),Oe=Yt("uri"),je=Xt(Yt("token")),Se=Xt(Ie,Oe),xe=Xt(Yt("pendingRef")),_e=Xt(Ie,te("email"),Oe),Ee=t=>({verify:je((e=>Kt(t.post(dt,{token:e})))),signIn:Se(((e,n,r,o)=>Kt(t.post(Jt(ht,ie.email),{externalId:e,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Se(((e,n)=>Kt(t.post(Jt(gt,ie.email),{externalId:e,URI:n})))),signUp:Se(((e,n,r)=>Kt(t.post(Jt(pt,ie.email),{externalId:e,URI:n,user:r})))),waitForSession:xe(((e,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(ft,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(Kt(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:_e(((e,n,r,o)=>Kt(t.post(vt.email,{externalId:e,email:n,URI:r},{token:o}))))}});var Ue;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(Ue||(Ue={}));const Ce=Xt(Yt("code")),Pe=t=>({start:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:r=!1}={},o,i)=>{const s=await t.post(bt,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!r||!s.ok)return Kt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:Ce((e=>Kt(t.post(wt,{code:e}))))}),Ae=Xt(Yt("flowId")),Te=Xt(Yt("executionId"),Yt("stepId"),Yt("interactionId")),Re=t=>({start:Ae(((e,n,r,o)=>Kt(t.post(Et,{flowId:e,options:o,interactionId:n,input:r})))),next:Te(((e,n,r,o)=>Kt(t.post(Ut,{executionId:e,stepId:n,interactionId:r,input:o}))))}),De=Xt(Yt("tenant")),Me=Xt(Yt("code")),Le=t=>({start:De((async(e,n,{redirect:r=!1}={},o,i)=>{const s=await t.post(mt,o||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!r||!s.ok)return Kt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:Me((e=>Kt(t.post(yt,{code:e}))))}),Ne=Yt("identifier"),$e=Xt(Ne,Yt("code")),qe=Xt(Ne),Je=Xt(Ne),Ke=t=>({signUp:qe(((e,n)=>Kt(t.post(It,{externalId:e,user:n})))),verify:$e(((e,n,r,o)=>Kt(t.post(kt,{externalId:e,code:n,loginOptions:r},{token:o})))),update:Je(((e,n)=>Kt(t.post(Ot,{externalId:e},{token:n}))))}),We=Yt("identifier"),Be=Yt("origin"),Fe=Xt(We,Be,Yt("name")),He=Xt(We,Be),ze=Xt(We,Be,Yt("token")),Ve=Xt(Yt("transactionId"),Yt("response")),Ge=t=>({signUp:{start:Fe(((e,n,r)=>Kt(t.post(jt.start,{user:{externalId:e,name:r},origin:n})))),finish:Ve(((e,n)=>Kt(t.post(jt.finish,{transactionId:e,response:n}))))},signIn:{start:He(((e,n,r,o)=>Kt(t.post(St.start,{externalId:e,origin:n,loginOptions:r},{token:o})))),finish:Ve(((e,n)=>Kt(t.post(St.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:He(((e,n)=>Kt(t.post(xt.start,{externalId:e,origin:n}))))},update:{start:ze(((e,n,r)=>Kt(t.post(_t.start,{externalId:e,origin:n},{token:r})))),finish:Ve(((e,n)=>Kt(t.post(_t.finish,{transactionId:e,response:n}))))}}),Ze=Xt(Yt("token"));var Qe;const Xe=Xt([("projectId",Qe=Yt("projectId"),Wt(((t,e)=>n=>Bt(...e).validate(Y(n,t)))("projectId",Qe))())])((({projectId:t,logger:e,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Dt({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:r,cookiePolicy:o}),{accessKey:re(i),otp:fe(i),magicLink:ke(i),enchantedLink:Ee(i),oauth:Pe(i),saml:Le(i),totp:Ke(i),webauthn:Ge(i),flow:Re(i),refresh:t=>Kt(i.post("/v1/auth/refresh",{},{token:t})),logout:t=>Kt(i.post("/v1/auth/logout",{},{token:t})),logoutAll:t=>Kt(i.post("/v1/auth/logoutall",{},{token:t})),me:t=>Kt(i.get("/v1/auth/me",{token:t})),isJwtExpired:Ze(Nt),getJwtPermissions:Ze($t),getJwtRoles:Ze(qt),httpClient:i};var i}));function Ye(t,e){var n=[];return function(t,e){var n,r,o=(r=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,o++)r[o]=i[s];return r}(t),{current:function(){return r[0]},postpone:function(){var t=r.shift();void 0!==t&&r.push(t)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=o.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?o.postpone():o.exclude();var e,r=o.current();if(void 0===r)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(r,n+1)}))}))};return a(s,0)}(t,(function(t){var r=new Date,o=function(){return n.push({url:t,startedAt:r,finishedAt:new Date})},i=e(t);return i.then(o,o),i})).then((function(t){return[t,{attempts:n}]}))}Xe.DeliveryMethods=ie;var tn="Failed to load the JS script of the agent";function en(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,s=void 0===i?o:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(r=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Ye(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(c,s),nn).catch(on)})).then((function(e){var n=e[0],r=e[1];return n.load(t(t({},a),{ldi:r}))}))}function nn(t){return function(t,e,n,r){var o,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),r=e.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=e,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var r=document.createElement("script"),o=function(){var t;return null===(t=r.parentNode)||void 0===t?void 0:t.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),e()},r.onerror=function(){o(),n(new Error(tn))},r.async=!0,r.src=t,i.appendChild(r)}))}(t)})).then(rn)}function rn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==r?void 0:r.configurable)?delete t[e]:r&&!r.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function on(t){throw t instanceof Error&&"9319"===t.message?new Error(tn):t}var sn={exports:{}},an={exports:{}};an.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function e(n,r){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=t({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=e+"="+n.write(o,e)+s}}function i(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],r={},o=0;o<e.length;o++){var i=e[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=n.read(s,a),t===a)break}catch(t){}}return t?r[t]:r}}return Object.create({set:o,get:i,remove:function(e,n){o(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}return 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:"/"})}();var cn=u(sn.exports=an.exports);const ln="undefined"!=typeof window,un=ln&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",dn=ln&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",hn=(t="",e="")=>({vsid:t,vrid:e}),pn=(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},fn=async t=>{try{if(pn())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=en({apiKey:t||un,endpoint:dn}),r=await n,{requestId:o}=await r.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(hn(e,o))}catch(t){global.FB_DEBUG&&console.error(t)}};var vn,gn,bn,wn,mn;const yn=t=>Object.assign({},t);class kn{constructor(t){vn.add(this),gn.set(this,void 0),bn.set(this,{}),wn.set(this,0),o(this,gn,t,"f")}get current(){return yn(r(this,gn,"f"))}update(t){const e=t;if(!((t,e)=>{const n=t&&Object.getOwnPropertyNames(t)||[],r=e&&Object.getOwnPropertyNames(e)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(t[o]!==e[o])return!1}return!0})(r(this,gn,"f"),e)){const t=r(this,gn,"f");o(this,gn,e,"f"),Object.freeze(r(this,gn,"f")),setTimeout((()=>{Object.values(r(this,bn,"f")).forEach((n=>n(yn(e),t)))}),0)}}subscribe(t){o(this,wn,r(this,wn,"f")+1,"f"),r(this,bn,"f")[r(this,wn,"f")]=t;const e=r(this,wn,"f");return()=>r(this,vn,"m",mn).call(this,e.toString())}unsubscribeAll(){o(this,bn,{},"f")}}gn=new WeakMap,bn=new WeakMap,wn=new WeakMap,vn=new WeakSet,mn=function(t){r(this,bn,"f")[t]&&delete r(this,bn,"f")[t]};let In=[];async function On(t,n,r,o){var i;try{if(401===n.status)return r.sessionToken.update({sessionToken:""}),void r.user.update({});const s=await(null==n?void 0:n.json());if(s){const n=function(t){return(null==t?void 0:t.authInfo)||t||{}}(s),{sessionJwt:a,refreshJwt:c,user:l}=n,u=e(n,["sessionJwt","refreshJwt","user"]);if(o.persistTokens&&(function(t,{cookiePath:e,cookieDomain:n,cookieExpiration:r},o){t&&(o?cn.set("DS",t,{path:e,domain:n,expires:r,sameSite:"None",secure:!0}):localStorage&&localStorage.setItem("DS",t))}(a,u,o.sessionTokenViaCookie),function(t){localStorage&&t&&localStorage.setItem("DSR",t)}(c)),a&&r.sessionToken.update({sessionToken:a}),l){const t=null===(i=null==l?void 0:l.externalIds)||void 0===i?void 0:i[0];ln&&t&&(null===localStorage||void 0===localStorage||localStorage.setItem("dls_last_user_external_id",t)),r.user.update(l)}a&&c&&o.autoRefresh&&function(t,e,n){const r=function(t){const e=t.split(".");try{if(3===e.length){const e=JSON.parse(window.atob(t.split(".")[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(t){}return null}(e);if(r){let e;for(;e=In.pop();)clearTimeout(e);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{t(n)}),o);In.push(i)}}(t,a,c)}}catch(t){console.error("Could not set tokens from body",t)}}function jn(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function Sn(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=En(n.publicKey.challenge),n.publicKey.user.id=En(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=En(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:Un(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:Un(n.response.attestationObject),clientDataJSON:Un(n.response.clientDataJSON)})}));var n}async function xn(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=En(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=En(t.id)})),n}(t);return n=await navigator.credentials.get(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:Un(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:Un(n.response.authenticatorData),clientDataJSON:Un(n.response.clientDataJSON),signature:Un(n.response.signature),userHandle:n.response.userHandle?Un(n.response.userHandle):void 0})}));var n}async function _n(t=!1){if(!ln)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function En(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Un(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}const Cn="undefined"!=typeof window&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",Pn="descope-login-flow",An="code",Tn="data-type",Rn="redirect",Dn="poll",Mn="webauthnCreate",Ln="webauthnGet";function Nn(t){return new URLSearchParams(window.location.search).get(t)}function $n(t){if(window.history.replaceState&&Nn(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var qn;function Jn(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(qn||(qn={}));function Kn(t,e){const n=new URL(Cn);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function Wn(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?qn.forward:t<e?qn.backward:void 0}const Bn=()=>{const[t="",e=""]=(Nn(Pn)||"").split("_");return{executionId:t,stepId:e}};function Fn(){$n(Pn)}const Hn=t=>t.replace(/-./g,(t=>t[1].toUpperCase()));var zn,Vn,Gn;function Zn(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r],i=t[o],s=e[o];if("object"==typeof i&&"object"==typeof s){if(!Zn(i,s))return!1}else if(i!==s)return!1}return!0}class Qn{constructor(t={}){zn.set(this,void 0),Vn.set(this,{}),Gn.set(this,0),o(this,zn,t,"f")}get current(){return Object.assign({},r(this,zn,"f"))}update(t){const e="function"==typeof t?t(r(this,zn,"f")):t,n=Object.assign(Object.assign({},r(this,zn,"f")),e);if(!Zn(r(this,zn,"f"),n)){const t=r(this,zn,"f");o(this,zn,n,"f"),Object.freeze(r(this,zn,"f")),setTimeout((()=>{Object.values(r(this,Vn,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}}subscribe(t){return o(this,Gn,r(this,Gn,"f")+1,"f"),r(this,Vn,"f")[r(this,Gn,"f")]=t,r(this,Gn,"f").toString()}unsubscribe(t){const e=!!r(this,Vn,"f")[t];return e&&delete r(this,Vn,"f")[t],e}unsubscribeAll(){return o(this,Vn,{},"f"),!0}}zn=new WeakMap,Vn=new WeakMap,Gn=new WeakMap;const Xn=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${Tn}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${Tn}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return r=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),r);var r})))(t.textContent,e)}))})(t,e)};function Yn(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=er(n.publicKey.challenge),n.publicKey.user.id=er(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=er(t.id)})),n}(t),n=yield navigator.credentials.create(e);return r=n,JSON.stringify({id:r.id,rawId:nr(r.rawId),type:r.type,response:{attestationObject:nr(r.response.attestationObject),clientDataJSON:nr(r.response.clientDataJSON)}});var r}))}function tr(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=er(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=er(t.id)})),n}(t),n=yield navigator.credentials.get(e);return r=n,JSON.stringify({id:r.id,rawId:nr(r.rawId),type:r.type,response:{authenticatorData:nr(r.response.authenticatorData),clientDataJSON:nr(r.response.clientDataJSON),signature:nr(r.response.signature),userHandle:nr(r.response.userHandle)}});var r}))}function er(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function nr(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var rr,or,ir,sr,ar,cr,lr,ur,dr,hr,pr,fr,vr,gr,br,wr,mr,yr,kr,Ir,Or,jr,Sr,xr,_r,Er,Ur,Cr,Pr,Ar;const Tr=document.createElement("template");Tr.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\tform[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<form></form>\n\t";class Rr extends HTMLElement{constructor(){super(),rr.add(this),or.set(this,!1),ir.set(this,new Qn),sr.set(this,new Qn),ar.set(this,new Qn({isLoading:!1})),cr.set(this,void 0),lr.set(this,void 0),ur.set(this,void 0),dr.set(this,void 0),hr.set(this,{popstate:r(this,rr,"m",br).bind(this)}),pr.set(this,void 0),fr.set(this,void 0),Ir.set(this,(t=>{var e,n,o,i,s;if(!(null==t?void 0:t.ok))return r(this,rr,"m",xr).call(this,"error",null==t?void 0:t.error),void r(this,rr,"m",Ar).call(this,{title:null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorDescription,description:null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.message});const a=null===(s=null===(i=null===(o=t.data)||void 0===o?void 0:o.screen)||void 0===i?void 0:i.state)||void 0===s?void 0:s.errorText;a&&r(this,rr,"m",Ar).call(this,{title:a});const{status:c,authInfo:l}=t.data;if("completed"===c)return void r(this,rr,"m",xr).call(this,"success",l);const{executionId:u,stepId:d,action:h,screen:p,redirect:f,webauthn:v}=t.data;r(this,ir,"f").update({stepId:d,executionId:u,action:h,redirectUrl:null==f?void 0:f.url,screenId:null==p?void 0:p.id,screenState:null==p?void 0:p.state,webauthnTransactionId:null==v?void 0:v.transactionId,webauthnOptions:null==v?void 0:v.options})})),_r.set(this,(()=>{let t;return()=>n(this,void 0,void 0,(function*(){if(t)return t;const e=Kn(this["project-id"],"config.json");try{t=yield Jn(e,"json")}catch(t){console.error("Cannot get config file")}return t}))})()),r(this,rr,"m",vr).call(this),r(this,ir,"f").subscribe(r(this,rr,"m",kr).bind(this)),r(this,sr,"f").subscribe(r(this,rr,"m",jr).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug"]}get"project-id"(){return this.getAttribute("project-id")}get"flow-id"(){return this.getAttribute("flow-id")}get"base-url"(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if(n)return 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"}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){o(this,or,!0,"f"),r(this,rr,"m",gr).call(this),r(this,rr,"m",Cr).call(this);const t=yield r(this,_r,"f").call(this),e=this["flow-id"];o(this,fr,((t,e)=>{var n;return(null===(n=null==t?void 0:t.flows)||void 0===n?void 0:n[e])||{}})(t,e),"f"),r(this,rr,"m",Ur).call(this,t),r(this,rr,"m",yr).call(this),r(this,rr,"m",Pr).call(this);const{executionId:n,stepId:i}=Bn();(n||i)&&Fn();const s=Nn("t")||void 0;s&&$n("t");const a=Nn(An)||void 0;a&&$n(An),r(this,ir,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],tenant:this.tenant,stepId:i,executionId:n,token:s,code:a}),window.addEventListener("popstate",r(this,hr,"f").popstate),r(this,cr,"f").onkeydown=t=>{if("Enter"===t.key){t.preventDefault();const e=r(this,cr,"f").querySelectorAll("button");1===e.length&&e[0].click()}}}}))}disconnectedCallback(){r(this,ir,"f").unsubscribeAll(),r(this,sr,"f").unsubscribeAll(),window.removeEventListener("popstate",r(this,hr,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&r(this,or,"f")){if(e!==n&&Rr.observedAttributes.includes(t)){r(this,rr,"m",gr).call(this);const o=null===e;r(this,ir,"f").update((({stepId:e,executionId:r})=>{let i=e,s=r;return o||(s=null,i=null,Fn()),{[Hn(t)]:n,stepId:i,executionId:s}}))}"debug"===t&&r(this,rr,"m",Pr).call(this)}}}or=new WeakMap,ir=new WeakMap,sr=new WeakMap,ar=new WeakMap,cr=new WeakMap,lr=new WeakMap,ur=new WeakMap,dr=new WeakMap,hr=new WeakMap,pr=new WeakMap,fr=new WeakMap,Ir=new WeakMap,_r=new WeakMap,rr=new WeakSet,vr=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Tr.content.cloneNode(!0)),o(this,cr,this.shadowRoot.querySelector("form"),"f"),o(this,lr,this.shadowRoot.querySelector("style"),"f")},gr=function(){const t=["base-url","tenant","theme","debug"];if(Rr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[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')},br=function(){const{stepId:t,executionId:e}=Bn();r(this,ir,"f").update({stepId:t,executionId:e})},wr=function(t){return(...e)=>n(this,void 0,void 0,(function*(){r(this,ar,"f").update({isLoading:!0});try{return yield t(...e)}finally{r(this,ar,"f").update({isLoading:!1})}}))},mr=function(t,n){o(this,pr,(t=>{var{autoRefresh:n=!0,persistTokens:r=!0,sessionTokenViaCookie:o,fpKey:i,fpLoad:s}=t,a=e(t,["autoRefresh","persistTokens","sessionTokenViaCookie","fpKey","fpLoad"]);ln?s&&fn(i).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const c=a;let l,u;const d=new kn({sessionToken:""}),h=new kn({});c.hooks={beforeRequest:t=>null==l?void 0:l(t),afterRequest:(t,e)=>null==u?void 0:u(t,e)};const p=Xe(c),f=(v=p,{async signUp(t,e){const n=await v.webauthn.signUp.start(t,window.location.origin,e),r=await Sn(n.data.options);return await v.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(t){const e=await v.webauthn.signIn.start(t,window.location.origin),n=await xn(e.data.options);return await v.webauthn.signIn.finish(e.data.transactionId,n)},async signUpOrIn(t){var e;const n=await v.webauthn.signUpOrIn.start(t,window.location.origin);if(null===(e=n.data)||void 0===e?void 0:e.create){const t=await Sn(n.data.options);return await v.webauthn.signUp.finish(n.data.transactionId,t)}{const t=await xn(n.data.options);return await v.webauthn.signIn.finish(n.data.transactionId,t)}},async update(t,e){const n=await v.webauthn.update.start(t,window.location.origin,e),r=await Sn(n.data.options);return await v.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:Sn,get:xn,isSupported:_n}});var v;const g=Object.assign(Object.assign({},p),{flow:Object.assign(Object.assign({},p.flow),{start:async(t,e,n,r)=>{const o=await f.helpers.isSupported(),i=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("dls_last_user_external_id"),s={tenant:null==r?void 0:r.tenant,redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:o}};return i&&(s.lastUser={externalId:i}),p.flow.start(t,e,n,s)}}),webauthn:f,onSessionTokenChange:t=>{var e;const n=null===(e=d.current)||void 0===e?void 0:e.sessionToken;return n&&t(n),d.subscribe((({sessionToken:e})=>{t(e)}))},onUserChange:t=>{const e=h.current;return e&&Object.entries(e).length>0&&t(e),h.subscribe((e=>{t(e)}))},getRefreshToken:jn});return ln?(n&&["logout","logoutAll"].forEach((t=>{const e=p[t];g[t]=(...t)=>{const n=jn(),r=[(null==t?void 0:t.shift())||n,...t],o=e(...r);return null===localStorage||void 0===localStorage||localStorage.removeItem("DSR"),null===localStorage||void 0===localStorage||localStorage.removeItem("DS"),cn.remove("DS"),ln&&(null===localStorage||void 0===localStorage||localStorage.removeItem("dls_last_user_external_id")),d.update({sessionToken:""}),o}})),l=t=>(t.body&&(t.body.fpData=pn(!0)||hn()),!t.token&&r&&(t.token=jn()),t.headers=Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.15"}),t),g.me=async(...t)=>{var e;const n=await p.me(...t);if(n.ok){const t=await(null===(e=n.response)||void 0===e?void 0:e.clone().json());h.update(t)}return n},(n||r)&&(u=(t,e)=>{On(g.refresh,e,{sessionToken:d,user:h},{autoRefresh:n,persistTokens:r,sessionTokenViaCookie:o})}),n&&jn()&&g.refresh(),g):(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"),g)})({projectId:t,baseUrl:n,autoRefresh:!1,fpLoad:!0}),"f");const i=r(this,pr,"f").flow.next;r(this,pr,"f").flow.next=r(this,rr,"m",wr).call(this,i)},yr=function(){r(this,cr,"f").setAttribute("data-theme",this.theme)},kr=function(t,e,i){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:c,baseUrl:l,tenant:u,stepId:d,executionId:h,action:p,screenId:f,screenState:v,redirectUrl:g,token:b,code:w,webauthnTransactionId:m,webauthnOptions:y}=t,k=i("projectId")||i("baseUrl");if(r(this,dr,"f")&&(clearInterval(r(this,dr,"f")),o(this,dr,null,"f")),k){if(!a)return;r(this,rr,"m",mr).call(this,a,l)}if(!h){if(!c)return;const t=null===(s=r(this,fr,"f"))||void 0===s?void 0:s.startScreenId;if(t){const e={htmlUrl:Kn(a,`${t}.html`)};return r(this,sr,"f").update(e),void(r(this,pr,"f").flow.start=r(this,rr,"m",wr).call(this,r(this,pr,"f").flow.start))}const e=yield r(this,pr,"f").flow.start(c,"",null,{tenant:u});return void r(this,Ir,"f").call(this,e)}if(i("token")&&b||i("code")&&w){const t=yield r(this,pr,"f").flow.next(h,d,"submit",{token:b,exchangeCode:w});return r(this,Ir,"f").call(this,t),void r(this,ir,"f").update({token:void 0,code:void 0})}if(p===Rn)return g?void window.location.assign(g):void console.error("Did not get redirect url");if(p===Mn||p===Ln){if(!m||!y)return void console.error("Did not get webauthn transaction id or options");const t=p===Mn?yield Yn(y):yield tr(y),e=yield r(this,pr,"f").flow.next(h,d,"submit",{transactionId:m,response:t});return void r(this,Ir,"f").call(this,e)}if(p===Dn&&o(this,dr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield r(this,pr,"f").flow.next(h,d,"submit",{});r(this,Ir,"f").call(this,t)}))),2e3),"f"),!f)return void console.error("Refreshing the page during a flow is not supported yet");const I={direction:Wn(+d,+e.stepId),screenState:v,htmlUrl:Kn(a,`${f}.html`)};(k||i("executionId")||i("stepId"))&&(I.next=(...t)=>r(this,pr,"f").flow.next(h,d,...t)),r(this,sr,"f").update(I)}))},Or=function(t){r(this,cr,"f").onsubmit=e=>n(this,void 0,void 0,(function*(){var n;const o=null===(n=e.submitter)||void 0===n?void 0:n.getAttribute("id"),i=r(this,ar,"f").subscribe((({isLoading:t})=>{var n,o,s,a;t?null===(o=null===(n=e.submitter)||void 0===n?void 0:n.classList)||void 0===o||o.add("loading"):(r(this,ar,"f").unsubscribe(i),null===(a=null===(s=e.submitter)||void 0===s?void 0:s.classList)||void 0===a||a.remove("loading"))}));e.preventDefault();const s=Object.fromEntries(new FormData(e.target).entries()),a=(c=e.submitter,Array.from((null==c?void 0:c.attributes)||[]).reduce(((t,e)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return r?Object.assign(t,{[r]:e.value}):t}),{}));var c;const l=Object.assign(Object.assign(Object.assign({},a),s),{origin:window.location.origin});let u;const{executionId:d,tenant:h,flowId:p}=r(this,ir,"f").current;u=d?yield t(o,l):yield r(this,pr,"f").flow.start(p,o,l,{tenant:h}),r(this,Ir,"f").call(this,u)}))},jr=function(t){return n(this,void 0,void 0,(function*(){const{htmlUrl:e,validations:n={},direction:o,next:i,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield Jn(e,"text");const c=a.content.cloneNode(!0),l=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const r=e.getAttribute("data-id"),o=null===(n=t.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c),u=()=>{var t;!function(t,e){Object.entries(e).forEach((([e,n])=>{const r=t.getElementById(e);if(!r)throw new Error(`Cannot find element with id: ${e}`);Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e.toString()),r.addEventListener("blur",(()=>r.classList.add("touched")),{once:!0})}))}))}(c,n),Xn(c,s);((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(t=null==s?void 0:s.totp)||void 0===t?void 0:t.image);try{l.forEach((t=>t()))}catch(t){console.error(t)}r(this,cr,"f").replaceChildren(c),r(this,rr,"m",Or).call(this,i),r(this,rr,"m",xr).call(this,"page-updated",{})};o?r(this,rr,"m",Sr).call(this,u,o):u()}))},Sr=function(t,e){r(this,cr,"f").addEventListener("transitionend",(()=>{r(this,cr,"f").classList.remove("fade-out"),t()}),{once:!0});const n=e===qn.forward?"slide-forward":"slide-backward";Array.from(r(this,cr,"f").getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),r(this,cr,"f").classList.add("fade-out")},xr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},Er=function(t){if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)},Ur=function(t){var e,n,o,i;null===(i=null===(o=null===(n=null===(e=null==t?void 0:t.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===n?void 0:n.typography)||void 0===o?void 0:o.fontFamilies)||void 0===i||i.forEach((t=>{r(this,rr,"m",Er).call(this,t.url)}))},Cr=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=Kn(this["project-id"],"theme.css");t.innerText=yield Jn(e,"text"),this.shadowRoot.appendChild(t)}))},Pr=function(){var t;return n(this,void 0,void 0,(function*(){this.debug?(yield import("./debugger-wc-781f6337.js"),o(this,ur,document.createElement("descope-debugger"),"f"),Object.assign(r(this,ur,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(r(this,ur,"f"))):(null===(t=r(this,ur,"f"))||void 0===t||t.remove(),o(this,ur,null,"f"))}))},Ar=function({title:t,description:e=""}){var n;t&&this.debug&&(null===(n=r(this,ur,"f"))||void 0===n||n.updateData({title:t,description:e}))},customElements.define("descope-wc",Rr);export{Rr as D,Qn as S,r as _,o as a};
|
package/dist/descope-wc.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare class DescopeWc extends HTMLElement {
|
|
2
|
-
#private;
|
|
3
|
-
static get observedAttributes(): string[];
|
|
4
|
-
constructor();
|
|
5
|
-
get 'project-id'(): string;
|
|
6
|
-
get 'flow-id'(): string;
|
|
7
|
-
get 'base-url'(): string;
|
|
8
|
-
get tenant(): string;
|
|
9
|
-
get debug(): boolean;
|
|
10
|
-
get theme(): string;
|
|
11
|
-
connectedCallback(): Promise<void>;
|
|
12
|
-
disconnectedCallback(): void;
|
|
13
|
-
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { DescopeWc as default };
|
package/dist/descope-wc.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{D as default}from"./descope-wc-d680a346.js";
|
package/dist/descope-wc.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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{c(o.next(t))}catch(t){r(t)}}function a(t){try{c(o.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((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}function r(t){this.message=t}r.prototype=new Error,r.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=e.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function a(t){this.message=t}function c(t,e){if("string"!=typeof t)throw new a("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(s(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 s(e)}}(t.split(".")[n]))}catch(t){throw new a("Invalid token specified: "+t.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var d="__lodash_hash_undefined__",h="[object Function]",p="[object GeneratorFunction]",f=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/,v=/^\./,m=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,b=/\\(\\)?/g,w=/^\[object .+?Constructor\]$/,y="object"==typeof l&&l&&l.Object===Object&&l,k="object"==typeof self&&self&&self.Object===Object&&self,x=y||k||Function("return this")();var I,O=Array.prototype,j=Function.prototype,S=Object.prototype,_=x["__core-js_shared__"],C=(I=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"",E=j.toString,U=S.hasOwnProperty,A=S.toString,P=RegExp("^"+E.call(U).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=x.Symbol,L=O.splice,R=z(x,"Map"),M=z(Object,"create"),D=T?T.prototype:void 0,N=D?D.toString:void 0;function $(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 q(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 W(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 J(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 K(t,e){var n;e=function(t,e){if(X(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Y(t))return!0;return g.test(t)||!f.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:X(n=e)?n:B(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[V(e[o++])];return o&&o==i?t:void 0}function F(t){if(!G(t)||(e=t,C&&C in e))return!1;var e,n=function(t){var e=G(t)?A.call(t):"";return e==h||e==p}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?P:w;return n.test(function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function H(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 z(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return F(n)?n:void 0}$.prototype.clear=function(){this.__data__=M?M(null):{}},$.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},$.prototype.get=function(t){var e=this.__data__;if(M){var n=e[t];return n===d?void 0:n}return U.call(e,t)?e[t]:void 0},$.prototype.has=function(t){var e=this.__data__;return M?void 0!==e[t]:U.call(e,t)},$.prototype.set=function(t,e){return this.__data__[t]=M&&void 0===e?d:e,this},q.prototype.clear=function(){this.__data__=[]},q.prototype.delete=function(t){var e=this.__data__,n=J(e,t);return!(n<0)&&(n==e.length-1?e.pop():L.call(e,n,1),!0)},q.prototype.get=function(t){var e=this.__data__,n=J(e,t);return n<0?void 0:e[n][1]},q.prototype.has=function(t){return J(this.__data__,t)>-1},q.prototype.set=function(t,e){var n=this.__data__,o=J(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},W.prototype.clear=function(){this.__data__={hash:new $,map:new(R||q),string:new $}},W.prototype.delete=function(t){return H(this,t).delete(t)},W.prototype.get=function(t){return H(this,t).get(t)},W.prototype.has=function(t){return H(this,t).has(t)},W.prototype.set=function(t,e){return H(this,t).set(t,e),this};var B=Z((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Y(t))return N?N.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return v.test(t)&&n.push(""),t.replace(m,(function(t,e,o,i){n.push(o?i.replace(b,"$1"):e||t)})),n}));function V(t){if("string"==typeof t||Y(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Z(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(Z.Cache||W),n}Z.Cache=W;var X=Array.isArray;function G(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Y(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==A.call(t)}var Q=function(t,e,n){var o=null==t?void 0:K(t,e);return void 0===o?n:o},tt="/v1/auth/accesskey/exchange",et="/v1/auth/otp/verify",nt="/v1/auth/otp/signin",ot="/v1/auth/otp/signup",it={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},rt="/v1/auth/otp/signup-in",st="/v1/auth/magiclink/verify",at="/v1/auth/magiclink/signin",ct="/v1/auth/magiclink/signup",lt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ut="/v1/auth/magiclink/signup-in",dt="/v1/auth/enchantedlink/verify",ht="/v1/auth/enchantedlink/signin",pt="/v1/auth/enchantedlink/signup",ft="/v1/auth/enchantedlink/pending-session",gt={email:"/v1/auth/enchantedlink/update/email"},vt="/v1/auth/enchantedlink/signup-in",mt="/v1/auth/oauth/authorize",bt="/v1/auth/oauth/exchange",wt="/v1/auth/saml/authorize",yt="/v1/auth/saml/exchange",kt="/v1/auth/totp/verify",xt="/v1/auth/totp/signup",It="/v1/user/totp/update",Ot={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},jt={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},St={start:"/v1/auth/webauthn/signup-in/start"},_t={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ct="/v1/flow/start",Et="/v1/flow/next";const Ut=()=>{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 At;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(At||(At={}));const Pt=(...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}),{})),Tt=t=>void 0===t?void 0:JSON.stringify(t),Lt=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Rt=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r})=>{const s=((t,e)=>{const n=e||fetch;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{t.log((t=>Ut().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),Ut().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:c,body:l,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:c,baseUrl:t,queryParams:d}),{headers:Pt(Lt(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.34"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Tt(l),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:At.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:At.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:At.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:At.delete,token:i})}};function Mt(t,e,n){var o;let i=Dt(t);e&&(i=null===(o=i.tenants)||void 0===o?void 0:o[e]);const r=i[n];return Array.isArray(r)?r:[]}function Dt(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return c(t)}function Nt(t){const{exp:e}=Dt(t);return(new Date).getTime()/1e3>e}function $t(t,e){return Mt(t,e,"permissions")}function qt(t,e){return Mt(t,e,"roles")}const Wt=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Jt(t,e){const n=await t,o={code:n.status,ok:n.ok,response:n},i=await n.clone().json();return n.ok?o.data=e?e(i):i:o.error=i,o}const Kt=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ft=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ht=t=>e=>t.test(e),zt=Ht(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Bt=Ht(/^\+[1-9]{1}[0-9]{3,14}$/),Vt=Kt(zt,'"{val}" is not a valid email'),Zt=Kt(Bt,'"{val}" is not a valid phone number'),Xt=Kt((1,t=>t.length>=1),"Minimum length is 1");const Gt=Kt((t=>"string"==typeof t),"Input is not a string"),Yt=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ft(...t).validate(n[e]))),e(...n)),Qt=t=>[Gt(`"${t}" must be a string`),Xt(`"${t}" must not be empty`)],te=t=>[Gt(`"${t}" must be a string`),Vt()],ee=t=>[Gt(`"${t}" must be a string`),Zt()],ne=Yt(Qt("accessKey")),oe=t=>({exchange:ne((e=>Jt(t.post(tt,{},{token:e}))))});var ie,re,se,ae,ce;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(ie||(ie={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(re||(re={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(se||(se={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(ae||(ae={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(ce||(ce={}));const le=Qt("identifier"),ue=Yt(le,Qt("code")),de=Yt(le),he=Yt(le,ee("phone")),pe=Yt(le,te("email")),fe=t=>({verify:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ue(((e,o)=>Jt(t.post(Wt(et,n),{code:o,externalId:e}))))})),{}),signIn:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,o,i)=>Jt(t.post(Wt(nt,n),{externalId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,o)=>Jt(t.post(Wt(ot,n),{externalId:e,user:o}))))})),{}),signUpOrIn:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de((e=>Jt(t.post(Wt(rt,n),{externalId:e}))))})),{}),update:{email:pe(((e,n,o)=>Jt(t.post(it.email,{externalId:e,email:n},{token:o})))),phone:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:he(((e,o,i)=>Jt(t.post(Wt(it.phone,n),{externalId:e,phone:o},{token:i}))))})),{})}}),ge=Qt("identifier"),ve=Qt("uri"),me=Yt(Qt("token")),be=Yt(ge,ve),we=Yt(ge,ee("phone"),ve),ye=Yt(ge,te("email"),ve),ke=t=>({verify:me((e=>Jt(t.post(st,{token:e})))),signIn:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:be(((e,o,i,r)=>Jt(t.post(Wt(at,n),{externalId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:be(((e,o,i)=>Jt(t.post(Wt(ct,n),{externalId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(re).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:be(((e,o)=>Jt(t.post(Wt(ut,n),{externalId:e,URI:o}))))})),{}),update:{email:ye(((e,n,o,i)=>Jt(t.post(lt.email,{externalId:e,email:n,URI:o},{token:i})))),phone:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,o,i,r)=>Jt(t.post(Wt(lt.phone,n),{externalId:e,phone:o,URI:i},{token:r}))))})),{})}}),xe=Qt("identifier"),Ie=Qt("uri"),Oe=Yt(Qt("token")),je=Yt(xe,Ie),Se=Yt(Qt("pendingRef")),_e=Yt(xe,te("email"),Ie),Ce=t=>({verify:Oe((e=>Jt(t.post(dt,{token:e})))),signIn:je(((e,n,o,i)=>Jt(t.post(Wt(ht,re.email),{externalId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:je(((e,n)=>Jt(t.post(Wt(vt,re.email),{externalId:e,URI:n})))),signUp:je(((e,n,o)=>Jt(t.post(Wt(pt,re.email),{externalId:e,URI:n,user:o})))),waitForSession:Se(((e,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(ft,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Jt(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{message:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:_e(((e,n,o,i)=>Jt(t.post(gt.email,{externalId:e,email:n,URI:o},{token:i}))))}});var Ee;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(Ee||(Ee={}));const Ue=Yt(Qt("code")),Ae=t=>({start:Object.keys(Ee).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(mt,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Jt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:Ue((e=>Jt(t.post(bt,{code:e}))))}),Pe=Yt(Qt("flowId")),Te=Yt(Qt("executionId"),Qt("stepId"),Qt("interactionId")),Le=t=>({start:Pe(((e,n,o,i)=>Jt(t.post(Ct,{flowId:e,options:i,interactionId:n,input:o})))),next:Te(((e,n,o,i)=>Jt(t.post(Et,{executionId:e,stepId:n,interactionId:o,input:i}))))}),Re=Yt(Qt("tenant")),Me=Yt(Qt("code")),De=t=>({start:Re((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(wt,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Jt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:Me((e=>Jt(t.post(yt,{code:e}))))}),Ne=Qt("identifier"),$e=Yt(Ne,Qt("code")),qe=Yt(Ne),We=Yt(Ne),Je=t=>({signUp:qe(((e,n)=>Jt(t.post(xt,{externalId:e,user:n})))),verify:$e(((e,n,o,i)=>Jt(t.post(kt,{externalId:e,code:n,loginOptions:o},{token:i})))),update:We(((e,n)=>Jt(t.post(It,{externalId:e},{token:n}))))}),Ke=Qt("identifier"),Fe=Qt("origin"),He=Yt(Ke,Fe,Qt("name")),ze=Yt(Ke,Fe),Be=Yt(Ke,Fe,Qt("token")),Ve=Yt(Qt("transactionId"),Qt("response")),Ze=t=>({signUp:{start:He(((e,n,o)=>Jt(t.post(Ot.start,{user:{externalId:e,name:o},origin:n})))),finish:Ve(((e,n)=>Jt(t.post(Ot.finish,{transactionId:e,response:n}))))},signIn:{start:ze(((e,n,o,i)=>Jt(t.post(jt.start,{externalId:e,origin:n,loginOptions:o},{token:i})))),finish:Ve(((e,n)=>Jt(t.post(jt.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:ze(((e,n)=>Jt(t.post(St.start,{externalId:e,origin:n}))))},update:{start:Be(((e,n,o)=>Jt(t.post(_t.start,{externalId:e,origin:n},{token:o})))),finish:Ve(((e,n)=>Jt(t.post(_t.finish,{transactionId:e,response:n}))))}}),Xe=Yt(Qt("token"));var Ge;const Ye=Yt([("projectId",Ge=Qt("projectId"),Kt(((t,e)=>n=>Ft(...e).validate(Q(n,t)))("projectId",Ge))())])((({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:i})=>{return r=Rt({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i}),{accessKey:oe(r),otp:fe(r),magicLink:ke(r),enchantedLink:Ce(r),oauth:Ae(r),saml:De(r),totp:Je(r),webauthn:Ze(r),flow:Le(r),refresh:t=>Jt(r.post("/v1/auth/refresh",{},{token:t})),logout:t=>Jt(r.post("/v1/auth/logout",{},{token:t})),logoutAll:t=>Jt(r.post("/v1/auth/logoutall",{},{token:t})),me:t=>Jt(r.get("/v1/auth/me",{token:t})),isJwtExpired:Xe(Nt),getJwtPermissions:Xe($t),getJwtRoles:Xe(qt),httpClient:r};var r}));function Qe(t,e){var n=[];return function(t,e){var n,o,i=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),i=0;for(e=0;e<n;e++)for(var r=arguments[e],s=0,a=r.length;s<a;s++,i++)o[i]=r[s];return o}(t),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?i.postpone():i.exclude();var e,o=i.current();if(void 0===o)throw t;return(e=r(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(t,(function(t){var o=new Date,i=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},r=e(t);return r.then(i,i),r})).then((function(t){return[t,{attempts:n}]}))}Ye.DeliveryMethods=re;var tn="Failed to load the JS script of the agent";function en(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Qe(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(c,s),nn).catch(rn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function nn(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,c())};r.addEventListener(s,a);var c=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),i)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),i=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),e()},o.onerror=function(){i(),n(new Error(tn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(on)}function on(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function rn(t){throw t instanceof Error&&"9319"===t.message?new Error(tn):t}var sn={exports:{}},an={exports:{}};an.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}function e(n,o){function i(e,i,r){if("undefined"!=typeof document){"number"==typeof(r=t({},o,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in r)r[a]&&(s+="; "+a,!0!==r[a]&&(s+="="+r[a].split(";")[0]));return document.cookie=e+"="+n.write(i,e)+s}}function r(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],o={},i=0;i<e.length;i++){var r=e[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=n.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}}return Object.create({set:i,get:r,remove:function(e,n){i(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}return 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:"/"})}(),function(t){t.exports=an.exports}(sn);var cn=u(sn.exports);const ln="undefined"!=typeof window,un=ln&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",dn=ln&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",hn=(t="",e="")=>({vsid:t,vrid:e}),pn=(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},fn=async t=>{try{if(pn())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=en({apiKey:t||un,endpoint:dn}),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))})(hn(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}};var gn,vn,mn,bn,wn;const yn=t=>Object.assign({},t);class kn{constructor(t){gn.add(this),vn.set(this,void 0),mn.set(this,{}),bn.set(this,0),i(this,vn,t,"f")}get current(){return yn(o(this,vn,"f"))}update(t){const e=t;if(!((t,e)=>{const n=t&&Object.getOwnPropertyNames(t)||[],o=e&&Object.getOwnPropertyNames(e)||[];if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o];if(t[i]!==e[i])return!1}return!0})(o(this,vn,"f"),e)){const t=o(this,vn,"f");i(this,vn,e,"f"),Object.freeze(o(this,vn,"f")),setTimeout((()=>{Object.values(o(this,mn,"f")).forEach((n=>n(yn(e),t)))}),0)}}subscribe(t){i(this,bn,o(this,bn,"f")+1,"f"),o(this,mn,"f")[o(this,bn,"f")]=t;const e=o(this,bn,"f");return()=>o(this,gn,"m",wn).call(this,e.toString())}unsubscribeAll(){i(this,mn,{},"f")}}vn=new WeakMap,mn=new WeakMap,bn=new WeakMap,gn=new WeakSet,wn=function(t){o(this,mn,"f")[t]&&delete o(this,mn,"f")[t]};let xn=[];async function In(t,n,o,i){var r;try{if(401===n.status)return o.sessionToken.update({sessionToken:""}),void o.user.update({});const s=await(null==n?void 0:n.json());if(s){const n=function(t){return(null==t?void 0:t.authInfo)||t||{}}(s),{sessionJwt:a,refreshJwt:c,user:l}=n,u=e(n,["sessionJwt","refreshJwt","user"]);if(i.persistTokens&&(function(t,{cookiePath:e,cookieDomain:n,cookieExpiration:o},i){t&&(i?cn.set("DS",t,{path:e,domain:n,expires:o,sameSite:"None",secure:!0}):localStorage&&localStorage.setItem("DS",t))}(a,u,i.sessionTokenViaCookie),function(t){localStorage&&t&&localStorage.setItem("DSR",t)}(c)),a&&o.sessionToken.update({sessionToken:a}),l){const t=null===(r=null==l?void 0:l.externalIds)||void 0===r?void 0:r[0];ln&&t&&(null===localStorage||void 0===localStorage||localStorage.setItem("dls_last_user_external_id",t)),o.user.update(l)}a&&c&&i.autoRefresh&&function(t,e,n){const o=function(t){const e=t.split(".");try{if(3===e.length){const e=JSON.parse(window.atob(t.split(".")[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(t){}return null}(e);if(o){let e;for(;e=xn.pop();)clearTimeout(e);const i=o.getTime()-2e4-(new Date).getTime(),r=setTimeout((()=>{t(n)}),i);xn.push(r)}}(t,a,c)}}catch(t){console.error("Could not set tokens from body",t)}}function On(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function jn(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Cn(n.publicKey.challenge),n.publicKey.user.id=Cn(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Cn(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:En(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:En(n.response.attestationObject),clientDataJSON:En(n.response.clientDataJSON)})}));var n}async function Sn(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Cn(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Cn(t.id)})),n}(t);return n=await navigator.credentials.get(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:En(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:En(n.response.authenticatorData),clientDataJSON:En(n.response.clientDataJSON),signature:En(n.response.signature),userHandle:n.response.userHandle?En(n.response.userHandle):void 0})}));var n}async function _n(t=!1){if(!ln)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Cn(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function En(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}const Un="undefined"!=typeof window&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",An="descope-login-flow",Pn="code",Tn="data-type",Ln="redirect",Rn="poll",Mn="webauthnCreate",Dn="webauthnGet";function Nn(t){return new URLSearchParams(window.location.search).get(t)}function $n(t){if(window.history.replaceState&&Nn(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var qn;function Wn(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(qn||(qn={}));function Jn(t,e){const n=new URL(Un);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function Kn(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?qn.forward:t<e?qn.backward:void 0}const Fn=()=>{const[t="",e=""]=(Nn(An)||"").split("_");return{executionId:t,stepId:e}};function Hn(){$n(An)}const zn=t=>t.replace(/-./g,(t=>t[1].toUpperCase()));var Bn,Vn,Zn;function Xn(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if("object"==typeof r&&"object"==typeof s){if(!Xn(r,s))return!1}else if(r!==s)return!1}return!0}class Gn{constructor(t={}){Bn.set(this,void 0),Vn.set(this,{}),Zn.set(this,0),i(this,Bn,t,"f")}get current(){return Object.assign({},o(this,Bn,"f"))}update(t){const e="function"==typeof t?t(o(this,Bn,"f")):t,n=Object.assign(Object.assign({},o(this,Bn,"f")),e);if(!Xn(o(this,Bn,"f"),n)){const t=o(this,Bn,"f");i(this,Bn,n,"f"),Object.freeze(o(this,Bn,"f")),setTimeout((()=>{Object.values(o(this,Vn,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}}subscribe(t){return i(this,Zn,o(this,Zn,"f")+1,"f"),o(this,Vn,"f")[o(this,Zn,"f")]=t,o(this,Zn,"f").toString()}unsubscribe(t){const e=!!o(this,Vn,"f")[t];return e&&delete o(this,Vn,"f")[t],e}unsubscribeAll(){return i(this,Vn,{},"f"),!0}}Bn=new WeakMap,Vn=new WeakMap,Zn=new WeakMap;const Yn=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${Tn}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${Tn}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)};function Qn(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=eo(n.publicKey.challenge),n.publicKey.user.id=eo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=eo(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:no(o.rawId),type:o.type,response:{attestationObject:no(o.response.attestationObject),clientDataJSON:no(o.response.clientDataJSON)}});var o}))}function to(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=eo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=eo(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:no(o.rawId),type:o.type,response:{authenticatorData:no(o.response.authenticatorData),clientDataJSON:no(o.response.clientDataJSON),signature:no(o.response.signature),userHandle:no(o.response.userHandle)}});var o}))}function eo(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function no(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const oo=(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))]};var io,ro,so,ao,co,lo,uo,ho,po,fo,go,vo,mo,bo,wo,yo,ko,xo,Io,Oo,jo,So,_o,Co,Eo,Uo,Ao,Po,To,Lo;const Ro=document.createElement("template");Ro.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\tform[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<form></form>\n\t";class Mo extends HTMLElement{constructor(){super(),io.add(this),ro.set(this,!1),so.set(this,new Gn),ao.set(this,new Gn),co.set(this,new Gn({isLoading:!1})),lo.set(this,void 0),uo.set(this,void 0),ho.set(this,void 0),po.set(this,void 0),fo.set(this,{popstate:o(this,io,"m",wo).bind(this)}),go.set(this,void 0),vo.set(this,void 0),Oo.set(this,(t=>{var e,n,i,r,s;if(!(null==t?void 0:t.ok))return o(this,io,"m",Co).call(this,"error",null==t?void 0:t.error),void o(this,io,"m",Lo).call(this,{title:null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorDescription,description:null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.message});const a=null===(s=null===(r=null===(i=t.data)||void 0===i?void 0:i.screen)||void 0===r?void 0:r.state)||void 0===s?void 0:s.errorText;a&&o(this,io,"m",Lo).call(this,{title:a});const{status:c,authInfo:l}=t.data;if("completed"===c)return void o(this,io,"m",Co).call(this,"success",l);const{executionId:u,stepId:d,action:h,screen:p,redirect:f,webauthn:g}=t.data;o(this,so,"f").update({stepId:d,executionId:u,action:h,redirectUrl:null==f?void 0:f.url,screenId:null==p?void 0:p.id,screenState:null==p?void 0:p.state,webauthnTransactionId:null==g?void 0:g.transactionId,webauthnOptions:null==g?void 0:g.options})})),Eo.set(this,(()=>{let t;return()=>n(this,void 0,void 0,(function*(){if(t)return t;const e=Jn(this["project-id"],"config.json");try{t=yield Wn(e,"json")}catch(t){console.error("Cannot get config file")}return t}))})()),o(this,io,"m",mo).call(this),o(this,so,"f").subscribe(o(this,io,"m",Io).bind(this)),o(this,ao,"f").subscribe(o(this,io,"m",So).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug"]}get"project-id"(){return this.getAttribute("project-id")}get"flow-id"(){return this.getAttribute("flow-id")}get"base-url"(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var t,e;const n=this.getAttribute("theme");if(n)return 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"}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){i(this,ro,!0,"f"),o(this,io,"m",bo).call(this),o(this,io,"m",Po).call(this);const t=yield o(this,Eo,"f").call(this),e=this["flow-id"];i(this,vo,((t,e)=>{var n;return(null===(n=null==t?void 0:t.flows)||void 0===n?void 0:n[e])||{}})(t,e),"f"),o(this,io,"m",Ao).call(this,t),o(this,io,"m",xo).call(this),o(this,io,"m",To).call(this);const{executionId:n,stepId:r}=Fn();(n||r)&&Hn();const s=Nn("t")||void 0;s&&$n("t");const a=Nn(Pn)||void 0;a&&$n(Pn),o(this,so,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],tenant:this.tenant,stepId:r,executionId:n,token:s,code:a}),window.addEventListener("popstate",o(this,fo,"f").popstate),o(this,lo,"f").onkeydown=t=>{if("Enter"===t.key){t.preventDefault();const e=o(this,lo,"f").querySelectorAll("button");1===e.length&&e[0].click()}}}}))}disconnectedCallback(){o(this,so,"f").unsubscribeAll(),o(this,ao,"f").unsubscribeAll(),window.removeEventListener("popstate",o(this,fo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,ro,"f")){if(e!==n&&Mo.observedAttributes.includes(t)){o(this,io,"m",bo).call(this);const i=null===e;o(this,so,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,Hn()),{[zn(t)]:n,stepId:r,executionId:s}}))}"debug"===t&&o(this,io,"m",To).call(this)}}}var Do,No,$o,qo,Wo,Jo,Ko,Fo,Ho,zo;ro=new WeakMap,so=new WeakMap,ao=new WeakMap,co=new WeakMap,lo=new WeakMap,uo=new WeakMap,ho=new WeakMap,po=new WeakMap,fo=new WeakMap,go=new WeakMap,vo=new WeakMap,Oo=new WeakMap,Eo=new WeakMap,io=new WeakSet,mo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ro.content.cloneNode(!0)),i(this,lo,this.shadowRoot.querySelector("form"),"f"),i(this,uo,this.shadowRoot.querySelector("style"),"f")},bo=function(){const t=["base-url","tenant","theme","debug"];if(Mo.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[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')},wo=function(){const{stepId:t,executionId:e}=Fn();o(this,so,"f").update({stepId:t,executionId:e})},yo=function(t){return(...e)=>n(this,void 0,void 0,(function*(){o(this,co,"f").update({isLoading:!0});try{return yield t(...e)}finally{o(this,co,"f").update({isLoading:!1})}}))},ko=function(t,n){i(this,go,(t=>{var{autoRefresh:n=!0,persistTokens:o=!0,sessionTokenViaCookie:i,fpKey:r,fpLoad:s}=t,a=e(t,["autoRefresh","persistTokens","sessionTokenViaCookie","fpKey","fpLoad"]);ln?s&&fn(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const c=a;let l,u;const d=new kn({sessionToken:""}),h=new kn({});c.hooks={beforeRequest:t=>null==l?void 0:l(t),afterRequest:(t,e)=>null==u?void 0:u(t,e)};const p=Ye(c),f=(g=p,{async signUp(t,e){const n=await g.webauthn.signUp.start(t,window.location.origin,e),o=await jn(n.data.options);return await g.webauthn.signUp.finish(n.data.transactionId,o)},async signIn(t){const e=await g.webauthn.signIn.start(t,window.location.origin),n=await Sn(e.data.options);return await g.webauthn.signIn.finish(e.data.transactionId,n)},async signUpOrIn(t){var e;const n=await g.webauthn.signUpOrIn.start(t,window.location.origin);if(null===(e=n.data)||void 0===e?void 0:e.create){const t=await jn(n.data.options);return await g.webauthn.signUp.finish(n.data.transactionId,t)}{const t=await Sn(n.data.options);return await g.webauthn.signIn.finish(n.data.transactionId,t)}},async update(t,e){const n=await g.webauthn.update.start(t,window.location.origin,e),o=await jn(n.data.options);return await g.webauthn.update.finish(n.data.transactionId,o)},helpers:{create:jn,get:Sn,isSupported:_n}});var g;const v=Object.assign(Object.assign({},p),{flow:Object.assign(Object.assign({},p.flow),{start:async(t,e,n,o)=>{const i=await f.helpers.isSupported(),r=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("dls_last_user_external_id"),s={tenant:null==o?void 0:o.tenant,redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}};return r&&(s.lastUser={externalId:r}),p.flow.start(t,e,n,s)}}),webauthn:f,onSessionTokenChange:t=>{var e;const n=null===(e=d.current)||void 0===e?void 0:e.sessionToken;return n&&t(n),d.subscribe((({sessionToken:e})=>{t(e)}))},onUserChange:t=>{const e=h.current;return e&&Object.entries(e).length>0&&t(e),h.subscribe((e=>{t(e)}))},getRefreshToken:On});return ln?(n&&["logout","logoutAll"].forEach((t=>{const e=p[t];v[t]=(...t)=>{const n=On(),o=[(null==t?void 0:t.shift())||n,...t],i=e(...o);return null===localStorage||void 0===localStorage||localStorage.removeItem("DSR"),null===localStorage||void 0===localStorage||localStorage.removeItem("DS"),cn.remove("DS"),ln&&(null===localStorage||void 0===localStorage||localStorage.removeItem("dls_last_user_external_id")),d.update({sessionToken:""}),i}})),l=t=>(t.body&&(t.body.fpData=pn(!0)||hn()),!t.token&&o&&(t.token=On()),t.headers=Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.15"}),t),v.me=async(...t)=>{var e;const n=await p.me(...t);if(n.ok){const t=await(null===(e=n.response)||void 0===e?void 0:e.clone().json());h.update(t)}return n},(n||o)&&(u=(t,e)=>{In(v.refresh,e,{sessionToken:d,user:h},{autoRefresh:n,persistTokens:o,sessionTokenViaCookie:i})}),n&&On()&&v.refresh(),v):(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"),v)})({projectId:t,baseUrl:n,autoRefresh:!1,fpLoad:!0}),"f");const r=o(this,go,"f").flow.next;o(this,go,"f").flow.next=o(this,io,"m",yo).call(this,r)},xo=function(){o(this,lo,"f").setAttribute("data-theme",this.theme)},Io=function(t,e,r){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:c,baseUrl:l,tenant:u,stepId:d,executionId:h,action:p,screenId:f,screenState:g,redirectUrl:v,token:m,code:b,webauthnTransactionId:w,webauthnOptions:y}=t,k=r("projectId")||r("baseUrl");if(o(this,po,"f")&&(clearInterval(o(this,po,"f")),i(this,po,null,"f")),k){if(!a)return;o(this,io,"m",ko).call(this,a,l)}if(!h){if(!c)return;const t=null===(s=o(this,vo,"f"))||void 0===s?void 0:s.startScreenId;if(t){const e={htmlUrl:Jn(a,`${t}.html`)};return o(this,ao,"f").update(e),void(o(this,go,"f").flow.start=o(this,io,"m",yo).call(this,o(this,go,"f").flow.start))}const e=yield o(this,go,"f").flow.start(c,"",null,{tenant:u});return void o(this,Oo,"f").call(this,e)}if(r("token")&&m||r("code")&&b){const t=yield o(this,go,"f").flow.next(h,d,"submit",{token:m,exchangeCode:b});return o(this,Oo,"f").call(this,t),void o(this,so,"f").update({token:void 0,code:void 0})}if(p===Ln)return v?void window.location.assign(v):void console.error("Did not get redirect url");if(p===Mn||p===Dn){if(!w||!y)return void console.error("Did not get webauthn transaction id or options");const t=p===Mn?yield Qn(y):yield to(y),e=yield o(this,go,"f").flow.next(h,d,"submit",{transactionId:w,response:t});return void o(this,Oo,"f").call(this,e)}if(p===Rn&&i(this,po,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield o(this,go,"f").flow.next(h,d,"submit",{});o(this,Oo,"f").call(this,t)}))),2e3),"f"),!f)return void console.error("Refreshing the page during a flow is not supported yet");const x={direction:Kn(+d,+e.stepId),screenState:g,htmlUrl:Jn(a,`${f}.html`)};(k||r("executionId")||r("stepId"))&&(x.next=(...t)=>o(this,go,"f").flow.next(h,d,...t)),o(this,ao,"f").update(x)}))},jo=function(t){o(this,lo,"f").onsubmit=e=>n(this,void 0,void 0,(function*(){var n;const i=null===(n=e.submitter)||void 0===n?void 0:n.getAttribute("id"),r=o(this,co,"f").subscribe((({isLoading:t})=>{var n,i,s,a;t?null===(i=null===(n=e.submitter)||void 0===n?void 0:n.classList)||void 0===i||i.add("loading"):(o(this,co,"f").unsubscribe(r),null===(a=null===(s=e.submitter)||void 0===s?void 0:s.classList)||void 0===a||a.remove("loading"))}));e.preventDefault();const s=Object.fromEntries(new FormData(e.target).entries()),a=(c=e.submitter,Array.from((null==c?void 0:c.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}),{}));var c;const l=Object.assign(Object.assign(Object.assign({},a),s),{origin:window.location.origin});let u;const{executionId:d,tenant:h,flowId:p}=o(this,so,"f").current;u=d?yield t(i,l):yield o(this,go,"f").flow.start(p,i,l,{tenant:h}),o(this,Oo,"f").call(this,u)}))},So=function(t){return n(this,void 0,void 0,(function*(){const{htmlUrl:e,validations:n={},direction:i,next:r,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield Wn(e,"text");const c=a.content.cloneNode(!0),l=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),i=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,r=Function(i).bind(e.previousSibling);return e.remove(),r}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c),u=()=>{var t;!function(t,e){Object.entries(e).forEach((([e,n])=>{const o=t.getElementById(e);if(!o)throw new Error(`Cannot find element with id: ${e}`);Object.entries(n).forEach((([t,e])=>{o.setAttribute(t,e.toString()),o.addEventListener("blur",(()=>o.classList.add("touched")),{once:!0})}))}))}(c,n),Yn(c,s);((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(t=null==s?void 0:s.totp)||void 0===t?void 0:t.image);try{l.forEach((t=>t()))}catch(t){console.error(t)}o(this,lo,"f").replaceChildren(c),o(this,io,"m",jo).call(this,r),o(this,io,"m",Co).call(this,"page-updated",{})};i?o(this,io,"m",_o).call(this,u,i):u()}))},_o=function(t,e){o(this,lo,"f").addEventListener("transitionend",(()=>{o(this,lo,"f").classList.remove("fade-out"),t()}),{once:!0});const n=e===qn.forward?"slide-forward":"slide-backward";Array.from(o(this,lo,"f").getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),o(this,lo,"f").classList.add("fade-out")},Co=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},Uo=function(t){if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)},Ao=function(t){var e,n,i,r;null===(r=null===(i=null===(n=null===(e=null==t?void 0:t.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===n?void 0:n.typography)||void 0===i?void 0:i.fontFamilies)||void 0===r||r.forEach((t=>{o(this,io,"m",Uo).call(this,t.url)}))},Po=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=Jn(this["project-id"],"theme.css");t.innerText=yield Wn(e,"text"),this.shadowRoot.appendChild(t)}))},To=function(){var t;return n(this,void 0,void 0,(function*(){this.debug?(yield Promise.resolve().then((function(){return Zo})),i(this,ho,document.createElement("descope-debugger"),"f"),Object.assign(o(this,ho,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,ho,"f"))):(null===(t=o(this,ho,"f"))||void 0===t||t.remove(),i(this,ho,null,"f"))}))},Lo=function({title:t,description:e=""}){var n;t&&this.debug&&(null===(n=o(this,ho,"f"))||void 0===n||n.updateData({title:t,description:e}))},customElements.define("descope-wc",Mo);const Bo=document.createElement("template");Bo.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 Vo extends HTMLElement{constructor(){super(),Do.add(this),No.set(this,new Gn({messages:[]})),$o.set(this,void 0),qo.set(this,void 0),Wo.set(this,void 0),Jo.set(this,{resize:o(this,Do,"m",zo).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Bo.content.cloneNode(!0)),i(this,$o,this.shadowRoot.querySelector(".debugger"),"f"),i(this,qo,o(this,$o,"f").querySelector(".content"),"f"),i(this,Wo,o(this,$o,"f").querySelector(".header"),"f")}updateData(t){o(this,No,"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,c]=oo(t,t.offsetLeft-o,t.offsetTop-i,n);t.style.top=`${c}px`,t.style.left=`${a}px`}function c(){document.onmouseup=null,document.onmousemove=null}function l(t){t.preventDefault(),r=t.clientX,s=t.clientY,document.onmouseup=c,document.onmousemove=a}e?e.onmousedown=l:t.onmousedown=l})(o(this,$o,"f"),o(this,Wo,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Jo,"f").resize),(t=o(this,$o,"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,$o,"f").onresize=o(this,Do,"m",Ho).bind(this),o(this,No,"f").subscribe(o(this,Do,"m",Ko).bind(this))}disconnectedCallback(){o(this,No,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Jo,"f").resize)}}No=new WeakMap,$o=new WeakMap,qo=new WeakMap,Wo=new WeakMap,Jo=new WeakMap,Do=new WeakSet,Ko=function(t){o(this,Do,"m",Fo).call(this,t),o(this,Do,"m",Ho).call(this)},Fo=function(t){o(this,qo,"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("")},Ho=function(){o(this,qo,"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)}))},zo=function(){const[t,e]=oo(o(this,$o,"f"),Number.parseInt(o(this,$o,"f").style.left,10),Number.parseInt(o(this,$o,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,$o,"f").style.top=`${e}px`,o(this,$o,"f").style.left=`${t}px`},customElements.define("descope-debugger",Vo);var Zo=Object.freeze({__proto__:null,default:Vo})}();
|