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