@descope/web-component 0.0.25 → 0.0.26-alpha.1

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/README.md CHANGED
@@ -33,7 +33,12 @@ render(){
33
33
 
34
34
  - Now you can add the custom element to your HTML
35
35
  ```html
36
- <descope-wc project="myProjectId"></descope-wc>
36
+ <descope-wc project-id="<project-id>" flow-id="<flow-id>"></descope-wc>
37
37
  ```
38
38
 
39
+ ### Run the demo app
40
+ - Install dependencies - `npm i`
41
+ - Edit the `src/app/index.html` - replace `<project-id>` and `<project-id>` with your project and a flow
42
+ - Run application - `npm run start`
43
+
39
44
  *TODO: we shoud host this file so it can be included without installing the package, once we will publish it to a public registry, we can also use unpkg.com/ to serve it*
@@ -1 +1 @@
1
- !function(){"use strict";function t(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 e(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 n(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 r(t){this.message=t}r.prototype=new Error,r.prototype.name="InvalidCharacterError";var o="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 i(t){this.message=t}function s(t,e){if("string"!=typeof t)throw new i("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(o(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 o(e)}}(t.split(".")[n]))}catch(t){throw new i("Invalid token specified: "+t.message)}}i.prototype=new Error,i.prototype.name="InvalidTokenError";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},c="__lodash_hash_undefined__",d="[object Function]",u="[object GeneratorFunction]",l=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,h=/^\w*$/,p=/^\./,f=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,g=/^\[object .+?Constructor\]$/,b="object"==typeof a&&a&&a.Object===Object&&a,m="object"==typeof self&&self&&self.Object===Object&&self,y=b||m||Function("return this")();var w,I=Array.prototype,j=Function.prototype,k=Object.prototype,O=y["__core-js_shared__"],x=(w=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"",_=j.toString,E=k.hasOwnProperty,U=k.toString,S=RegExp("^"+_.call(E).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),P=y.Symbol,T=I.splice,R=H(y,"Map"),M=H(Object,"create"),A=P?P.prototype:void 0,$=A?A.toString:void 0;function C(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 L(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 N(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||K(t))return!0;return h.test(t)||!l.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Z(n=e)?n:F(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[B(e[r++])];return r&&r==o?t:void 0}function D(t){if(!G(t)||(e=t,x&&x in e))return!1;var e,n=function(t){var e=G(t)?U.call(t):"";return e==d||e==u}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?S:g;return n.test(function(t){if(null!=t){try{return _.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function z(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 D(n)?n:void 0}C.prototype.clear=function(){this.__data__=M?M(null):{}},C.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},C.prototype.get=function(t){var e=this.__data__;if(M){var n=e[t];return n===c?void 0:n}return E.call(e,t)?e[t]:void 0},C.prototype.has=function(t){var e=this.__data__;return M?void 0!==e[t]:E.call(e,t)},C.prototype.set=function(t,e){return this.__data__[t]=M&&void 0===e?c:e,this},L.prototype.clear=function(){this.__data__=[]},L.prototype.delete=function(t){var e=this.__data__,n=N(e,t);return!(n<0)&&(n==e.length-1?e.pop():T.call(e,n,1),!0)},L.prototype.get=function(t){var e=this.__data__,n=N(e,t);return n<0?void 0:e[n][1]},L.prototype.has=function(t){return N(this.__data__,t)>-1},L.prototype.set=function(t,e){var n=this.__data__,r=N(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},q.prototype.clear=function(){this.__data__={hash:new C,map:new(R||L),string:new C}},q.prototype.delete=function(t){return z(this,t).delete(t)},q.prototype.get=function(t){return z(this,t).get(t)},q.prototype.has=function(t){return z(this,t).has(t)},q.prototype.set=function(t,e){return z(this,t).set(t,e),this};var F=J((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(K(t))return $?$.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return p.test(t)&&n.push(""),t.replace(f,(function(t,e,r,o){n.push(r?o.replace(v,"$1"):e||t)})),n}));function B(t){if("string"==typeof t||K(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function J(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(J.Cache||q),n}J.Cache=q;var Z=Array.isArray;function G(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function K(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==U.call(t)}var Q=function(t,e,n){var r=null==t?void 0:W(t,e);return void 0===r?n:r},V="/v1/auth/code/verify",X="/v1/auth/signin/otp",Y="/v1/auth/signup/otp",tt={email:"/v1/user/update/email/otp",phone:"/v1/user/update/phone/otp"},et="/v1/auth/sign-up-or-in/otp",nt="/v1/auth/magiclink/verify",rt="/v1/auth/signin/magiclink",ot="/v1/auth/signup/magiclink",it="/v1/auth/magiclink/session",st={email:"/v1/user/update/email/magiclink",phone:"/v1/user/update/phone/magiclink"},at="/v1/auth/sign-up-or-in/magiclink",ct="/v1/oauth/authorize",dt="/v1/auth/saml/authorize",ut="/v1/auth/verify/totp",lt="/v1/auth/signup/totp",ht="/v1/user/update/totp",pt={start:"/v1/webauthn/signup/start",finish:"/v1/webauthn/signup/finish"},ft={start:"/v1/webauthn/signin/start",finish:"/v1/webauthn/signin/finish"},vt={start:"/v1/webauthn/device/add/start",finish:"/v1/webauthn/device/add/finish"},gt="/v1/flow/start",bt="/v1/flow/next";const mt=()=>{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")}},yt=(...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}),{})),wt=t=>void 0===t?void 0:JSON.stringify(t);var It;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(It||(It={}));const jt=(t,e="")=>{let n=t;return""!==e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},kt=({baseUrl:e,projectId:n,baseConfig:r,logger:o})=>{const i=((e,n)=>{const r=n||fetch;if(!r)throw new Error("fetch is not defined");return e?(...n)=>t(void 0,void 0,void 0,(function*(){e.log((t=>mt().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(n));const o=yield r(...n);return e[o.ok?"log":"error"](yield(e=>t(void 0,void 0,void 0,(function*(){const t=yield e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),mt().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})))(o)),o})):r})(o),s=({path:t,body:o,headers:s,queryParams:a,method:c,token:d})=>i((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:t,baseUrl:e,queryParams:a}),{headers:yt(jt(n,d),(null==r?void 0:r.baseHeaders)||{},s),method:c,body:wt(o)});return{get:(t,{headers:e,queryParams:n,token:r}={})=>s({path:t,headers:e,queryParams:n,body:void 0,method:It.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>s({path:t,headers:n,queryParams:r,body:e,method:It.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>s({path:t,headers:n,queryParams:r,body:e,method:It.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>s({path:t,headers:n,queryParams:r,body:e,method:It.delete,token:o})}},Ot=t=>{if("string"!=typeof t||!t)throw new Error("Invalid token provided");const{exp:e}=s(t);return(new Date).getTime()/1e3>e},xt=(...t)=>t.join("/").replace(/\/{2,}/g,"/"),_t=e=>t(void 0,void 0,void 0,(function*(){const t=yield e,n={code:t.status,ok:t.ok,response:t},r=yield t.json();return t.ok?n.data=r:n.error=r,n}));var Et,Ut,St;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Et||(Et={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ut||(Ut={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(St||(St={}));const Pt=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Tt=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Rt=t=>e=>t.test(e),Mt=Rt(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),At=Rt(/^\+[1-9]{1}[0-9]{3,14}$/),$t=Pt(Mt,'"{val}" is not a valid email'),Ct=Pt(At,'"{val}" is not a valid phone number'),Lt=Pt((1,t=>t.length>=1),"Minimum length is 1");const qt=Pt((t=>"string"==typeof t),"Input is not a string"),Nt=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Tt(...t).validate(n[e]))),e(...n)),Wt=t=>[qt(`"${t}" must be a string`),Lt(`"${t}" must not be empty`)],Dt=t=>[qt(`"${t}" must be a string`),$t()],zt=t=>[qt(`"${t}" must be a string`),Ct()];var Ht;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(Ht||(Ht={}));const Ft=Wt("identifier"),Bt=Nt(Ft,Wt("code")),Jt=Nt(Ft),Zt=Nt(Ft,zt("phone")),Gt=Nt(Ft,Dt("email")),Kt=t=>({verify:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Bt(((e,r)=>_t(t.post(xt(V,n),{code:r,externalId:e}))))})),{}),signIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Jt((e=>_t(t.post(xt(X,n),{externalId:e}))))})),{}),signUp:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Jt(((e,r)=>_t(t.post(xt(Y,n),{externalId:e,user:r}))))})),{}),signUpOrIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Jt((e=>_t(t.post(xt(et,n),{externalId:e}))))})),{}),update:{email:Gt(((e,n,r)=>_t(t.post(tt.email,{externalId:e,email:n},{token:r})))),phone:Object.keys(Et).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Zt(((e,r,o)=>_t(t.post(xt(tt.phone,n),{externalId:e,phone:r},{token:o}))))})),{})}}),Qt=Wt("identifier"),Vt=Wt("uri"),Xt=Nt(Wt("token")),Yt=Nt(Qt,Vt),te=Nt(Wt("pendingRef")),ee=Nt(Qt,zt("phone"),Vt),ne=Nt(Qt,Dt("email"),Vt),re=e=>({verify:Xt((t=>_t(e.post(nt,{token:t})))),signIn:Object.keys(Ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,r)=>_t(e.post(xt(rt,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,r)=>_t(e.post(xt(at,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,r,o)=>_t(e.post(xt(ot,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:te(((n,r)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:s}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(r);let a;const c=setInterval((()=>t(void 0,void 0,void 0,(function*(){const t=yield e.post(it,{pendingRef:n});t.ok&&(clearInterval(c),a&&clearTimeout(a),o(_t(Promise.resolve(t))))}))),i);a=setTimeout((()=>{o({error:{message:`Session polling timeout exceeded: ${s}ms`,code:"0"},ok:!1}),clearInterval(c)}),s)})))),update:{email:ne(((t,n,r,o)=>_t(e.post(st.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(Et).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ee(((t,r,o,i)=>_t(e.post(xt(st.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),oe=t=>({verify:Xt((e=>_t(t.post(nt,{token:e})))),signIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Yt(((e,r)=>_t(t.post(xt(rt,n),{externalId:e,URI:r}))))})),{}),signUp:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Yt(((e,r,o)=>_t(t.post(xt(ot,n),{externalId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Yt(((e,r)=>_t(t.post(xt(at,n),{externalId:e,URI:r}))))})),{}),update:{email:ne(((e,n,r,o)=>_t(t.post(st.email,{externalId:e,email:n,URI:r},{token:o})))),phone:Object.keys(Et).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ee(((e,r,o,i)=>_t(t.post(xt(st.phone,n),{externalId:e,phone:r,URI:o},{token:i}))))})),{})},crossDevice:re(t)}),ie=Nt(Wt("code")),se=t=>({exchange:ie((e=>_t(t.get("/v1/auth/exchange",{queryParams:{code:e}}))))});var ae;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(ae||(ae={}));const ce=e=>Object.assign({start:Object.keys(ae).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:(n,{redirect:o=!1}={})=>t(void 0,void 0,void 0,(function*(){const t=yield e.get(ct,{queryParams:Object.assign({provider:r},n&&{redirectURL:n})});if(!o||!t.ok)return _t(Promise.resolve(t));const{url:i}=yield t.json();window.location.href=i}))})),{})},se(e)),de=Nt(Wt("flowId")),ue=Nt(Wt("executionId"),Wt("stepId"),Wt("actionId")),le=t=>({start:de((e=>_t(t.post(gt,{flowId:e})))),next:ue(((e,n,r,o)=>_t(t.post(bt,{executionId:e,stepId:n,actionId:r,input:o}))))}),he=Nt(Wt("tenant")),pe=e=>Object.assign({start:he(((n,r,{redirect:o=!1}={})=>t(void 0,void 0,void 0,(function*(){const t=yield e.get(dt,{queryParams:{tenant:n,redirectURL:r}});if(!o||!t.ok)return _t(Promise.resolve(t));const{url:i}=yield t.json();window.location.href=i}))))},se(e)),fe=Wt("identifier"),ve=Nt(fe,Wt("code")),ge=Nt(fe),be=Nt(fe),me=t=>({signUp:ge(((e,n)=>_t(t.post(lt,{externalId:e,user:n})))),verify:ve(((e,n)=>_t(t.post(ut,{externalId:e,code:n})))),update:be(((e,n)=>_t(t.post(ht,{externalId:e},{token:n}))))}),ye=Wt("identifier"),we=Wt("origin"),Ie=Nt(ye,we,Wt("name")),je=Nt(ye,we),ke=Nt(ye,we,Wt("token")),Oe=Nt(Wt("transactionId"),Wt("response")),xe=t=>({signUp:{start:Ie(((e,n,r)=>_t(t.post(pt.start,{user:{externalId:e,name:r},origin:n})))),finish:Oe(((e,n)=>_t(t.post(pt.finish,{transactionId:e,response:n}))))},signIn:{start:je(((e,n)=>_t(t.post(ft.start,{externalId:e,origin:n})))),finish:Oe(((e,n)=>_t(t.post(ft.finish,{transactionId:e,response:n}))))},add:{start:ke(((e,n,r)=>_t(t.post(vt.start,{externalId:e,origin:n},{token:r})))),finish:Oe(((e,n)=>_t(t.post(vt.finish,{transactionId:e,response:n}))))}}),_e=Nt(Wt("token"));var Ee;const Ue=Nt([("projectId",Ee=Wt("projectId"),Pt(((t,e)=>t=>Tt(...e).validate(Q(t,"projectId")))(0,Ee))())])((({projectId:t,logger:e,baseUrl:n})=>{return r=kt({baseUrl:n||"https://api.descope.com",projectId:t,logger:e}),{otp:Kt(r),magicLink:oe(r),oauth:ce(r),saml:pe(r),totp:me(r),webauthn:xe(r),flow:le(r),refresh:t=>_t(r.get("/v1/auth/refresh",{token:t})),logout:t=>_t(r.get("/v1/auth/logoutall",{token:t})),isJwtExpired:_e(Ot),httpClient:r};var r}));Ue.DeliveryMethods=Ut;const Se="descope-login-flow",Pe="code",Te="redirect",Re="poll";function Me(t){return new URLSearchParams(window.location.search).get(t)}function Ae(){return Me(Se)}function $e(t){if(window.history.replaceState&&Me(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 Ce;function Le(t){const e=`/${t}.html`,n=new URL("https://s3.eu-central-1.amazonaws.com/static.sandbox.descope.com/pages");return n.pathname+=e,n.toString()}function qe(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?Ce.forward:t<e?Ce.backward:void 0}!function(t){t.backward="backward",t.forward="forward"}(Ce||(Ce={}));const Ne=()=>{const[t="",e=""]=(Ae()||"").split("_");return{executionId:t,stepId:e}},We=(t,e)=>{!function(t){if(window.history.pushState&&t!==Ae()){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.set(Se,t),e.search=n.toString(),window.history.pushState({},"",e.toString())}}([t,e].join("_"))};const De=(t,e,n="")=>{const r=t.getElementById(e);r&&(r.innerText=n,r.classList[n?"remove":"add"]("hide"))};var ze,He,Fe,Be,Je,Ze,Ge,Ke,Qe,Ve,Xe,Ye,tn,en,nn,rn,on,sn,an,cn,dn,un,ln,hn;class pn{constructor(t={}){ze.set(this,void 0),He.set(this,{}),Fe.set(this,0),n(this,ze,t,"f")}get current(){return Object.assign({},e(this,ze,"f"))}update(t){const r="function"==typeof t?t(e(this,ze,"f")):t,o=Object.assign(Object.assign({},e(this,ze,"f")),r);if(!function(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];if(t[o]!==e[o])return!1}return!0}(e(this,ze,"f"),o)){const t=e(this,ze,"f");n(this,ze,o,"f"),Object.freeze(e(this,ze,"f")),setTimeout((()=>{Object.values(e(this,He,"f")).forEach((e=>e(o,t,((t,e)=>n=>t[n]!==e[n])(o,t))))}),0)}}subscribe(t){return n(this,Fe,e(this,Fe,"f")+1,"f"),e(this,He,"f")[e(this,Fe,"f")]=t,e(this,Fe,"f").toString()}unsubscribe(t){const n=!!e(this,He,"f")[t];return n&&delete e(this,He,"f")[t],n}unsubscribeAll(){return n(this,He,{},"f"),!0}}ze=new WeakMap,He=new WeakMap,Fe=new WeakMap,function(t){t.waiting="waiting",t.completed="completed",t.failed="failed",t.running="running"}(Be||(Be={}));const fn=document.createElement("template");fn.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\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<form></form>\n\t";class vn extends HTMLElement{constructor(){super(),Je.add(this),Ze.set(this,!1),Ge.set(this,new pn),Ke.set(this,new pn),Qe.set(this,void 0),Ve.set(this,void 0),Xe.set(this,void 0),Ye.set(this,{popstate:e(this,Je,"m",rn).bind(this)}),tn.set(this,void 0),cn.set(this,(t=>{var n,r;if(e(this,Je,"m",sn).call(this,t))return;const{executionId:o,stepId:i,status:s,action:a,screen:c,redirect:d,authInfo:u,error:l}=t.data;e(this,Je,"m",on).call(this,s,l,u)||e(this,Ge,"f").update({stepId:i,executionId:o,action:a,redirectUrl:null==d?void 0:d.url,screenId:null==c?void 0:c.id,screenErrorText:null===(n=null==c?void 0:c.state)||void 0===n?void 0:n.errorText,screenMessageText:null===(r=null==c?void 0:c.state)||void 0===r?void 0:r.messageText})})),e(this,Je,"m",en).call(this),e(this,Ge,"f").subscribe(e(this,Je,"m",an).bind(this)),e(this,Ke,"f").subscribe(e(this,Je,"m",un).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url"]}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}connectedCallback(){if(this.shadowRoot.isConnected){n(this,Ze,!0,"f"),e(this,Je,"m",nn).call(this);const{executionId:t,stepId:r}=Ne(),o=Me("t")||void 0;o&&$e("t");const i=Me(Pe)||void 0;i&&$e(Pe),e(this,Ge,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],stepId:r,executionId:t,token:o,code:i}),window.addEventListener("popstate",e(this,Ye,"f").popstate)}}disconnectedCallback(){e(this,Ge,"f").unsubscribeAll(),e(this,Ke,"f").unsubscribeAll(),window.removeEventListener("popstate",e(this,Ye,"f").popstate)}attributeChangedCallback(t,n,r){if(this.shadowRoot.isConnected&&e(this,Ze,"f")&&n!==r&&vn.observedAttributes.includes(t)){e(this,Je,"m",nn).call(this);const o=null===n;e(this,Ge,"f").update((({stepId:e,executionId:n})=>{let i=e,s=n;return o||(s=null,i=null,$e(Se)),{[(a=t,a.replace(/-./g,(t=>t[1].toUpperCase())))]:r,stepId:i,executionId:s};var a}))}}}Ze=new WeakMap,Ge=new WeakMap,Ke=new WeakMap,Qe=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Ye=new WeakMap,tn=new WeakMap,cn=new WeakMap,Je=new WeakSet,en=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(fn.content.cloneNode(!0)),n(this,Qe,this.shadowRoot.querySelector("form"),"f"),n(this,Ve,this.shadowRoot.querySelector("style"),"f")},nn=function(){const t=["base-url"];vn.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[e])throw Error(`${e} cannot be empty`)}))},rn=function(){const{stepId:t,executionId:n}=Ne();e(this,Ge,"f").update({stepId:t,executionId:n})},on=function(t,n,r){switch(t){case Be.failed:return e(this,Je,"m",hn).call(this,"error",n),!0;case Be.completed:return e(this,Je,"m",hn).call(this,"success",r),!0;default:return!1}},sn=function({ok:t,error:n}){return t||e(this,Je,"m",hn).call(this,"error",n),!t},an=function(r,o,i){return t(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,baseUrl:c,stepId:d,executionId:u,action:l,screenId:h,screenErrorText:p,screenMessageText:f,redirectUrl:v,token:g,code:b}=r,m=i("projectId")||i("baseUrl");if(e(this,Xe,"f")&&(clearInterval(e(this,Xe,"f")),n(this,Xe,null,"f")),m){if(!s)return;n(this,tn,Ue({projectId:s,baseUrl:c}),"f")}if(!u){if(!a)return;const t=yield e(this,tn,"f").flow.start(a);return void e(this,cn,"f").call(this,t)}if(i("token")&&g||i("code")&&b){const t=yield e(this,tn,"f").flow.next(u,d,"submit",{token:g,code:b});return e(this,cn,"f").call(this,t),We(t.data.executionId,t.data.stepId),void e(this,Ge,"f").update({token:void 0,code:void 0})}if(l===Te)return v?void window.location.assign(v):void console.error("Did not get redirect url");if(l===Re&&n(this,Xe,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield e(this,tn,"f").flow.next(u,d,"submit",{});e(this,cn,"f").call(this,t)}))),2e3),"f"),!h)return void console.error("Refreshing the page during a flow is not supported yet");const y={direction:qe(+d,+o.stepId),screenErrorText:p,screenMessageText:f,htmlUrl:Le(h)};(m||i("executionId")||i("stepId"))&&(y.next=(...t)=>e(this,tn,"f").flow.next(u,d,...t)),e(this,Ke,"f").update(y)}))},dn=function(n){this.shadowRoot.querySelectorAll('button[type="button"]').forEach((r=>{const o=(t=>Array.from(t.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}),{}))(r),{action:i}=o,s=function(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}(o,["action"]);r.onclick=()=>t(this,void 0,void 0,(function*(){const t=yield n(i,s);e(this,cn,"f").call(this,t),We(t.data.executionId,t.data.stepId)}))})),e(this,Qe,"f").onsubmit=r=>t(this,void 0,void 0,(function*(){r.preventDefault();const t=Object.fromEntries(new FormData(r.target).entries()),o=yield n("submit",t);e(this,cn,"f").call(this,o),We(o.data.executionId,o.data.stepId)}))},un=function(n,r,o){return t(this,void 0,void 0,(function*(){const r="error",i="info",{htmlUrl:s,validations:a={},direction:c,next:d,screenErrorText:u,screenMessageText:l}=n;if(!o("htmlUrl"))return o("next")&&e(this,Je,"m",dn).call(this,d),o("screenErrorText")&&De(this.shadowRoot,r,u),void(o("screenMessageText")&&De(this.shadowRoot,i,l));const h=document.createElement("template");h.innerHTML=yield function(e){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw new Error(e);return t.text()}))}(s);const p=h.content.cloneNode(!0),f=(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})(p),v=()=>{!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})}))}))}(p,a),De(p,r,u),De(p,i,l);try{f.forEach((t=>t()))}catch(t){console.error(t)}e(this,Qe,"f").replaceChildren(p),e(this,Je,"m",dn).call(this,d),e(this,Je,"m",hn).call(this,"page-updated",{})};c?e(this,Je,"m",ln).call(this,v,c):v()}))},ln=function(t,n){e(this,Qe,"f").addEventListener("transitionend",(()=>{e(this,Qe,"f").classList.remove("fade-out"),t()}),{once:!0});const r=n===Ce.forward?"slide-forward":"slide-backward";Array.from(e(this,Qe,"f").getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(r)})),e(this,Qe,"f").classList.add("fade-out")},hn=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",vn)}();
1
+ !function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function r(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function o(e,t,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 t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function i(e){this.message=e}i.prototype=new Error,i.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.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=t.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(e){this.message=e}function c(e,t){if("string"!=typeof e)throw new a("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(s(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return s(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d="__lodash_hash_undefined__",h="[object Function]",p="[object GeneratorFunction]",f=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,v=/^\w*$/,g=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,y=/\\(\\)?/g,m=/^\[object .+?Constructor\]$/,w="object"==typeof u&&u&&u.Object===Object&&u,I="object"==typeof self&&self&&self.Object===Object&&self,k=w||I||Function("return this")();var j,O=Array.prototype,x=Function.prototype,S=Object.prototype,_=k["__core-js_shared__"],E=(j=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+j:"",U=x.toString,P=S.hasOwnProperty,R=S.toString,C=RegExp("^"+U.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=k.Symbol,M=O.splice,A=z(k,"Map"),D=z(Object,"create"),q=T?T.prototype:void 0,L=q?q.toString:void 0;function $(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function N(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function J(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function B(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function K(e,t){var n;t=function(e,t){if(V(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||X(e))return!0;return v.test(e)||!f.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:V(n=t)?n:H(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[G(t[r++])];return r&&r==o?e:void 0}function W(e){if(!Q(e)||(t=e,E&&E in t))return!1;var t,n=function(e){var t=Q(e)?R.call(e):"";return t==h||t==p}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?C:m;return n.test(function(e){if(null!=e){try{return U.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function F(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function z(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return W(n)?n:void 0}$.prototype.clear=function(){this.__data__=D?D(null):{}},$.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},$.prototype.get=function(e){var t=this.__data__;if(D){var n=t[e];return n===d?void 0:n}return P.call(t,e)?t[e]:void 0},$.prototype.has=function(e){var t=this.__data__;return D?void 0!==t[e]:P.call(t,e)},$.prototype.set=function(e,t){return this.__data__[e]=D&&void 0===t?d:t,this},N.prototype.clear=function(){this.__data__=[]},N.prototype.delete=function(e){var t=this.__data__,n=B(t,e);return!(n<0)&&(n==t.length-1?t.pop():M.call(t,n,1),!0)},N.prototype.get=function(e){var t=this.__data__,n=B(t,e);return n<0?void 0:t[n][1]},N.prototype.has=function(e){return B(this.__data__,e)>-1},N.prototype.set=function(e,t){var n=this.__data__,r=B(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},J.prototype.clear=function(){this.__data__={hash:new $,map:new(A||N),string:new $}},J.prototype.delete=function(e){return F(this,e).delete(e)},J.prototype.get=function(e){return F(this,e).get(e)},J.prototype.has=function(e){return F(this,e).has(e)},J.prototype.set=function(e,t){return F(this,e).set(e,t),this};var H=Z((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(X(e))return L?L.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return g.test(e)&&n.push(""),e.replace(b,(function(e,t,r,o){n.push(r?o.replace(y,"$1"):t||e)})),n}));function G(e){if("string"==typeof e||X(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Z(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=e.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(Z.Cache||J),n}Z.Cache=J;var V=Array.isArray;function Q(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function X(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==R.call(e)}var Y,ee=function(e,t,n){var r=null==e?void 0:K(e,t);return void 0===r?n:r},te="/v1/auth/otp/verify",ne="/v1/auth/otp/signin",re="/v1/auth/otp/signup",oe={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},ie="/v1/auth/otp/signup-in",se="/v1/auth/magiclink/verify",ae="/v1/auth/magiclink/signin",ce="/v1/auth/magiclink/signup",ue="/v1/auth/magiclink/pending-session",le={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/email"},de="/v1/auth/magiclink/signup-in",he="/v1/auth/oauth/authorize",pe="/v1/auth/saml/authorize",fe="/v1/auth/totp/verify",ve="/v1/auth/totp/signup",ge="/v1/user/totp/update",be={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ye={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},me={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},we="/v1/flow/start",Ie="/v1/flow/next";!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Y||(Y={}));const ke=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},je=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),Oe=e=>void 0===e?void 0:JSON.stringify(e),xe=(e,t="")=>{let n=e;return""!==t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Se=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>ke().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),ke().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).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:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:je(xe(t,p),(null==n?void 0:n.baseHeaders)||{},l),method:h,body:Oe(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:r}={})=>a({path:e,headers:t,queryParams:n,body:void 0,method:Y.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Y.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Y.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Y.delete,token:o})}},_e=e=>{if("string"!=typeof e||!e)throw new Error("Invalid token provided");const{exp:t}=c(e);return(new Date).getTime()/1e3>t},Ee=(...e)=>e.join("/").replace(/\/{2,}/g,"/"),Ue=async e=>{const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.json();return t.ok?n.data=r:n.error=r,n};var Pe,Re,Ce;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Pe||(Pe={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Re||(Re={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(Ce||(Ce={}));const Te=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Me=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ae=e=>t=>e.test(t),De=Ae(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),qe=Ae(/^\+[1-9]{1}[0-9]{3,14}$/),Le=Te(De,'"{val}" is not a valid email'),$e=Te(qe,'"{val}" is not a valid phone number'),Ne=Te((1,e=>e.length>=1),"Minimum length is 1");const Je=Te((e=>"string"==typeof e),"Input is not a string"),Be=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Me(...e).validate(n[t]))),t(...n)),Ke=e=>[Je(`"${e}" must be a string`),Ne(`"${e}" must not be empty`)],We=e=>[Je(`"${e}" must be a string`),Le()],Fe=e=>[Je(`"${e}" must be a string`),$e()];var ze;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(ze||(ze={}));const He=Ke("identifier"),Ge=Be(He,Ke("code")),Ze=Be(He),Ve=Be(He,Fe("phone")),Qe=Be(He,We("email")),Xe=e=>({verify:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,r)=>Ue(e.post(Ee(te,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ze((t=>Ue(e.post(Ee(ne,n),{externalId:t}))))})),{}),signUp:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ze(((t,r)=>Ue(e.post(Ee(re,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ze((t=>Ue(e.post(Ee(ie,n),{externalId:t}))))})),{}),update:{email:Qe(((t,n,r)=>Ue(e.post(oe.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ve(((t,r,o)=>Ue(e.post(Ee(oe.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),Ye=Ke("identifier"),et=Ke("uri"),tt=Be(Ke("token")),nt=Be(Ye,et),rt=Be(Ke("pendingRef")),ot=Be(Ye,Fe("phone"),et),it=Be(Ye,We("email"),et),st=e=>({verify:tt((t=>Ue(e.post(se,{token:t})))),signIn:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r)=>Ue(e.post(Ee(ae,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r)=>Ue(e.post(Ee(de,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r,o)=>Ue(e.post(Ee(ce,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:rt(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(ue,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(Ue(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:it(((t,n,r,o)=>Ue(e.post(le.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ot(((t,r,o,i)=>Ue(e.post(Ee(le.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),at=e=>({verify:tt((t=>Ue(e.post(se,{token:t})))),signIn:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r)=>Ue(e.post(Ee(ae,n),{externalId:t,URI:r}))))})),{}),signUp:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r,o)=>Ue(e.post(Ee(ce,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Re).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r)=>Ue(e.post(Ee(de,n),{externalId:t,URI:r}))))})),{}),update:{email:it(((t,n,r,o)=>Ue(e.post(le.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ot(((t,r,o,i)=>Ue(e.post(Ee(le.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})},crossDevice:st(e)}),ct=Be(Ke("code")),ut=e=>({exchange:ct((t=>Ue(e.get("/v1/auth/exchange",{queryParams:{code:t}}))))});var lt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(lt||(lt={}));const dt=e=>Object.assign({start:Object.keys(lt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={})=>{const o=await e.get(he,{queryParams:Object.assign({provider:n},t&&{redirectURL:t})});if(!r||!o.ok)return Ue(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}})),{})},ut(e)),ht=Be(Ke("flowId")),pt=Be(Ke("executionId"),Ke("stepId"),Ke("actionId")),ft=e=>({start:ht((t=>Ue(e.post(we,{flowId:t})))),next:pt(((t,n,r,o)=>Ue(e.post(Ie,{executionId:t,stepId:n,interactionId:r,input:o}))))}),vt=Be(Ke("tenant")),gt=e=>Object.assign({start:vt((async(t,n,{redirect:r=!1}={})=>{const o=await e.get(pe,{queryParams:{tenant:t,redirectURL:n}});if(!r||!o.ok)return Ue(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}))},ut(e)),bt=Ke("identifier"),yt=Be(bt,Ke("code")),mt=Be(bt),wt=Be(bt),It=e=>({signUp:mt(((t,n)=>Ue(e.post(ve,{externalId:t,user:n})))),verify:yt(((t,n)=>Ue(e.post(fe,{externalId:t,code:n})))),update:wt(((t,n)=>Ue(e.post(ge,{externalId:t},{token:n}))))}),kt=Ke("identifier"),jt=Ke("origin"),Ot=Be(kt,jt,Ke("name")),xt=Be(kt,jt),St=Be(kt,jt,Ke("token")),_t=Be(Ke("transactionId"),Ke("response")),Et=e=>({signUp:{start:Ot(((t,n,r)=>Ue(e.post(be.start,{user:{externalId:t,name:r},origin:n})))),finish:_t(((t,n)=>Ue(e.post(be.finish,{transactionId:t,response:n}))))},signIn:{start:xt(((t,n)=>Ue(e.post(ye.start,{externalId:t,origin:n})))),finish:_t(((t,n)=>Ue(e.post(ye.finish,{transactionId:t,response:n}))))},update:{start:St(((t,n,r)=>Ue(e.post(me.start,{externalId:t,origin:n},{token:r})))),finish:_t(((t,n)=>Ue(e.post(me.finish,{transactionId:t,response:n}))))}}),Ut=Be(Ke("token"));var Pt;const Rt=Be([("projectId",Pt=Ke("projectId"),Te(((e,t)=>e=>Me(...t).validate(ee(e,"projectId")))(0,Pt))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Se({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{otp:Xe(i),magicLink:at(i),oauth:dt(i),saml:gt(i),totp:It(i),webauthn:Et(i),flow:ft(i),refresh:e=>Ue(i.get("/v1/auth/refresh",{token:e})),logout:e=>Ue(i.get("/v1/auth/logoutall",{token:e})),isJwtExpired:Ut(_e),httpClient:i};var i}));function Ct(e,t,n){return void 0===n&&(n=0),t(n).catch((function(r){if(n>=e.maxRetries||!e.shouldRetry(r))throw r;var o,i,s,a,c=(o=e.baseDelay,i=e.maxDelay,s=e.baseDelay*Math.pow(2,n),Math.max(o,Math.min(i,s)));return(a=c,new Promise((function(e){return setTimeout(e,a)}))).then((function(){return Ct(e,t,n+1)}))}))}Rt.DeliveryMethods=Re;var Tt="Failed to load the JS script of the agent";function Mt(n){var r,o=n.scriptUrlPattern,i=n.token,s=n.apiKey,a=void 0===s?i:s,c=t(n,["scriptUrlPattern","token","apiKey"]),u=(r=n,"scriptUrlPattern",Object.prototype.hasOwnProperty.call(r,"scriptUrlPattern")?o:void 0),l=[];return Promise.resolve().then((function(){if(!a||"string"!=typeof a)throw new Error("API key required");return Ct({maxRetries:5,baseDelay:100,maxDelay:3e3,shouldRetry:function(e){return!(e instanceof Error&&"Blocked by CSP"===e.message)}},(function(){var e,t=new Date,n=function(){return l.push({startedAt:t,finishedAt:new Date})},r=function(e,t,n,r){var o,i=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e=function(e,t){void 0===t&&(t="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js");var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.7.1"):t}))}(a,u),(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(Tt))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)}));return r.then(n,n),r}))})).then((function(){var t=window,n="__fpjs_p_l_b",r=t[n];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(t,n),"function"!=typeof(null==r?void 0:r.load))throw new Error(Tt);return r.load(e(e({},c),{ldi:{attempts:l}}))}))}var At={exports:{}},Dt={exports:{}};Dt.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}function t(n,r){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=e({},r,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 s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+s}}function i(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],r={},o=0;o<t.length;o++){var i=t[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=n.read(s,a),e===a)break}catch(e){}}return e?r[e]:r}}return Object.create({set:o,get:i,remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}(),function(e){e.exports=Dt.exports}(At);var qt=l(At.exports);const Lt=e=>{const t=Mt({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem("vsid");e||(e=(e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e])("vsid")),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem("vrid",r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}},$t=async e=>{try{const t=await(null==e?void 0:e.json());!function(e){const{sessionJwt:t,refreshJwt:n,cookieDomain:r,cookiePath:o,cookieExpiration:i}=e||{};t&&qt.set("DS",t,{path:o,domain:r,expires:i,secure:!0}),n&&localStorage&&localStorage.setItem("DSR",n)}((null==t?void 0:t.authInfo)||t)}catch(e){console.error("Could not set tokens from body")}};const Nt="descope-login-flow",Jt="code",Bt="redirect",Kt="poll",Wt="webauthnCreate",Ft="webauthnGet";function zt(e){return new URLSearchParams(window.location.search).get(e)}function Ht(){return zt(Nt)}function Gt(e){if(window.history.replaceState&&zt(e)){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.delete(e),t.search=n.toString(),window.history.replaceState({},"",t.toString())}}var Zt;function Vt(e){const t=`/${e}.html`,n=new URL("http://static.sandbox.descope.com.s3-website.eu-central-1.amazonaws.com/pages");return n.pathname+=t,n.toString()}function Qt(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?Zt.forward:e<t?Zt.backward:void 0}!function(e){e.backward="backward",e.forward="forward"}(Zt||(Zt={}));const Xt=()=>{const[e="",t=""]=(Ht()||"").split("_");return{executionId:e,stepId:t}},Yt=(e,t)=>{!function(e){if(window.history.pushState&&e!==Ht()){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.set(Nt,e),t.search=n.toString(),window.history.pushState({},"",t.toString())}}([e,t].join("_"))};const en=(e,t,n="")=>{const r=e.getElementById(t);r&&(r.innerText=n,r.classList[n?"remove":"add"]("hide"))},tn=e=>e.replace(/-./g,(e=>e[1].toUpperCase()));var nn,rn,on,sn,an,cn,un,ln,dn,hn,pn,fn,vn,gn,bn,yn,mn,wn,In,kn,jn,On,xn,Sn;class _n{constructor(e={}){nn.set(this,void 0),rn.set(this,{}),on.set(this,0),o(this,nn,e,"f")}get current(){return Object.assign({},r(this,nn,"f"))}update(e){const t="function"==typeof e?e(r(this,nn,"f")):e,n=Object.assign(Object.assign({},r(this,nn,"f")),t);if(!function(e,t){const n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(e[o]!==t[o])return!1}return!0}(r(this,nn,"f"),n)){const e=r(this,nn,"f");o(this,nn,n,"f"),Object.freeze(r(this,nn,"f")),setTimeout((()=>{Object.values(r(this,rn,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}}subscribe(e){return o(this,on,r(this,on,"f")+1,"f"),r(this,rn,"f")[r(this,on,"f")]=e,r(this,on,"f").toString()}unsubscribe(e){const t=!!r(this,rn,"f")[e];return t&&delete r(this,rn,"f")[e],t}unsubscribeAll(){return o(this,rn,{},"f"),!0}}function En(e){return n(this,void 0,void 0,(function*(){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Pn(n.publicKey.challenge),n.publicKey.user.id=Pn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Pn(e.id)})),n}(e),n=yield navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:Rn(r.rawId),type:r.type,response:{attestationObject:Rn(r.response.attestationObject),clientDataJSON:Rn(r.response.clientDataJSON)}});var r}))}function Un(e){return n(this,void 0,void 0,(function*(){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Pn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Pn(e.id)})),n}(e),n=yield navigator.credentials.get(t);return r=n,JSON.stringify({id:r.id,rawId:Rn(r.rawId),type:r.type,response:{authenticatorData:Rn(r.response.authenticatorData),clientDataJSON:Rn(r.response.clientDataJSON),signature:Rn(r.response.signature),userHandle:Rn(r.response.userHandle)}});var r}))}function Pn(e){const t=e.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Rn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}nn=new WeakMap,rn=new WeakMap,on=new WeakMap,function(e){e.waiting="waiting",e.completed="completed",e.failed="failed",e.running="running"}(sn||(sn={}));const Cn=document.createElement("template");Cn.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\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<form></form>\n\t";class Tn extends HTMLElement{constructor(){super(),an.add(this),cn.set(this,!1),un.set(this,new _n),ln.set(this,new _n),dn.set(this,void 0),hn.set(this,void 0),pn.set(this,void 0),fn.set(this,{popstate:r(this,an,"m",yn).bind(this)}),vn.set(this,void 0),kn.set(this,(e=>{var t,n;if(r(this,an,"m",wn).call(this,e))return;const{executionId:o,stepId:i,status:s,action:a,screen:c,redirect:u,authInfo:l,error:d,webauthn:h}=e.data;r(this,an,"m",mn).call(this,s,d,l)||r(this,un,"f").update({stepId:i,executionId:o,action:a,redirectUrl:null==u?void 0:u.url,screenId:null==c?void 0:c.id,screenErrorText:null===(t=null==c?void 0:c.state)||void 0===t?void 0:t.errorText,screenMessageText:null===(n=null==c?void 0:c.state)||void 0===n?void 0:n.messageText,webauthnTransactionId:null==h?void 0:h.transactionId,webauthnOptions:null==h?void 0:h.options})})),r(this,an,"m",gn).call(this),r(this,un,"f").subscribe(r(this,an,"m",In).bind(this)),r(this,ln,"f").subscribe(r(this,an,"m",On).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url"]}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}connectedCallback(){if(this.shadowRoot.isConnected){o(this,cn,!0,"f"),r(this,an,"m",bn).call(this);const{executionId:e,stepId:t}=Xt(),n=zt("t")||void 0;n&&Gt("t");const i=zt(Jt)||void 0;i&&Gt(Jt),r(this,un,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],stepId:t,executionId:e,token:n,code:i}),window.addEventListener("popstate",r(this,fn,"f").popstate)}}disconnectedCallback(){r(this,un,"f").unsubscribeAll(),r(this,ln,"f").unsubscribeAll(),window.removeEventListener("popstate",r(this,fn,"f").popstate)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&r(this,cn,"f")&&t!==n&&Tn.observedAttributes.includes(e)){r(this,an,"m",bn).call(this);const o=null===t;r(this,un,"f").update((({stepId:t,executionId:r})=>{let i=t,s=r;return o||(s=null,i=null,Gt(Nt)),{[tn(e)]:n,stepId:i,executionId:s}}))}}}cn=new WeakMap,un=new WeakMap,ln=new WeakMap,dn=new WeakMap,hn=new WeakMap,pn=new WeakMap,fn=new WeakMap,vn=new WeakMap,kn=new WeakMap,an=new WeakSet,gn=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Cn.content.cloneNode(!0)),o(this,dn,this.shadowRoot.querySelector("form"),"f"),o(this,hn,this.shadowRoot.querySelector("style"),"f")},bn=function(){const e=["base-url"];Tn.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[t])throw Error(`${t} cannot be empty`)}))},yn=function(){const{stepId:e,executionId:t}=Xt();r(this,un,"f").update({stepId:e,executionId:t})},mn=function(e,t,n){switch(e){case sn.failed:return r(this,an,"m",Sn).call(this,"error",t),!0;case sn.completed:return r(this,an,"m",Sn).call(this,"success",n),!0;default:return!1}},wn=function({ok:e,error:t}){return e||r(this,an,"m",Sn).call(this,"error",t),!e},In=function(e,i,s){return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:c,baseUrl:u,stepId:l,executionId:d,action:h,screenId:p,screenErrorText:f,screenMessageText:v,redirectUrl:g,token:b,code:y,webauthnTransactionId:m,webauthnOptions:w}=e,I=s("projectId")||s("baseUrl");if(r(this,pn,"f")&&(clearInterval(r(this,pn,"f")),o(this,pn,null,"f")),I){if(!a)return;o(this,vn,(e=>{var{persistTokens:n=!0}=e,r=t(e,["persistTokens"]);Lt(r.fpKey).get().catch((()=>null));const o=r;return o.hooks={beforeRequest:e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),n&&!e.token&&(e.token=localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""),e}},n&&(o.hooks.afterRequest=async(e,t)=>{$t(t)}),Rt(r)})({projectId:a,baseUrl:u}),"f")}if(!d){if(!c)return;const e=yield r(this,vn,"f").flow.start(c);return void r(this,kn,"f").call(this,e)}if(s("token")&&b||s("code")&&y){const e=yield r(this,vn,"f").flow.next(d,l,"submit",{token:b,code:y});return r(this,kn,"f").call(this,e),Yt(e.data.executionId,e.data.stepId),void r(this,un,"f").update({token:void 0,code:void 0})}if(h===Bt)return g?void window.location.assign(g):void console.error("Did not get redirect url");if(h===Wt||h===Ft){if(!m||!w)return void console.error("Did not get webauthn transaction id or options");const e=h===Wt?yield En(w):yield Un(w),t=yield r(this,vn,"f").flow.next(d,l,"submit",{transactionId:m,response:e});return void r(this,kn,"f").call(this,t)}if(h===Kt&&o(this,pn,setInterval((()=>n(this,void 0,void 0,(function*(){const e=yield r(this,vn,"f").flow.next(d,l,"submit",{});r(this,kn,"f").call(this,e)}))),2e3),"f"),!p)return void console.error("Refreshing the page during a flow is not supported yet");const k={direction:Qt(+l,+i.stepId),screenErrorText:f,screenMessageText:v,htmlUrl:Vt(p)};(I||s("executionId")||s("stepId"))&&(k.next=(...e)=>r(this,vn,"f").flow.next(d,l,...e)),r(this,ln,"f").update(k)}))},jn=function(e){this.shadowRoot.querySelectorAll('button[type="button"]').forEach((o=>{const i=(e=>Array.from(e.attributes).reduce(((e,t)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return r?Object.assign(e,{[r]:t.value}):e}),{}))(o),{action:s}=i,a=t(i,["action"]);o.onclick=()=>n(this,void 0,void 0,(function*(){const t=yield e(s,a);r(this,kn,"f").call(this,t),Yt(t.data.executionId,t.data.stepId)}))})),r(this,dn,"f").onsubmit=t=>n(this,void 0,void 0,(function*(){t.preventDefault();const n=Object.fromEntries(new FormData(t.target).entries()),o=yield e("submit",Object.assign(Object.assign({},n),{origin:window.location.origin}));r(this,kn,"f").call(this,o),Yt(o.data.executionId,o.data.stepId)}))},On=function(e,t,o){return n(this,void 0,void 0,(function*(){const t="error",i="info",{htmlUrl:s,validations:a={},direction:c,next:u,screenErrorText:l,screenMessageText:d}=e;if(!o("htmlUrl"))return o("next")&&r(this,an,"m",jn).call(this,u),o("screenErrorText")&&en(this.shadowRoot,t,l),void(o("screenMessageText")&&en(this.shadowRoot,i,d));const h=document.createElement("template");h.innerHTML=yield function(e){return n(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw new Error(e);return t.text()}))}(s);const p=h.content.cloneNode(!0),f=(e=>{var t;const n=Array.from(e.querySelectorAll("script[data-id]")).map((t=>{var n;const r=t.getAttribute("data-id"),o=null===(n=e.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(t.previousSibling);return t.remove(),i}));return null===(t=e.querySelector("scripts"))||void 0===t||t.remove(),n})(p),v=()=>{!function(e,t){Object.entries(t).forEach((([t,n])=>{const r=e.getElementById(t);if(!r)throw new Error(`Cannot find element with id: ${t}`);Object.entries(n).forEach((([e,t])=>{r.setAttribute(e,t.toString()),r.addEventListener("blur",(()=>r.classList.add("touched")),{once:!0})}))}))}(p,a),en(p,t,l),en(p,i,d);try{f.forEach((e=>e()))}catch(e){console.error(e)}r(this,dn,"f").replaceChildren(p),r(this,an,"m",jn).call(this,u),r(this,an,"m",Sn).call(this,"page-updated",{})};c?r(this,an,"m",xn).call(this,v,c):v()}))},xn=function(e,t){r(this,dn,"f").addEventListener("transitionend",(()=>{r(this,dn,"f").classList.remove("fade-out"),e()}),{once:!0});const n=t===Zt.forward?"slide-forward":"slide-backward";Array.from(r(this,dn,"f").getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),r(this,dn,"f").classList.add("fade-out")},Sn=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",Tn)}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/web-component",
3
- "version": "0.0.25",
3
+ "version": "0.0.26-alpha.1",
4
4
  "main": "dist/descope-wc",
5
5
  "types": "dist/descope-wc.d.ts",
6
6
  "description": "Descope WC",
@@ -39,7 +39,7 @@
39
39
  "eslint-plugin-jest": "26.8.2",
40
40
  "eslint-plugin-jest-dom": "4.0.2",
41
41
  "eslint-plugin-jest-formatting": "3.1.0",
42
- "eslint-plugin-n": "15.2.4",
42
+ "eslint-plugin-n": "15.2.5",
43
43
  "eslint-plugin-no-only-tests": "3.0.0",
44
44
  "eslint-plugin-prefer-arrow": "1.2.3",
45
45
  "eslint-plugin-prettier": "4.2.1",
@@ -54,12 +54,14 @@
54
54
  "rollup-plugin-dts": "^4.2.2",
55
55
  "rollup-plugin-livereload": "^2.0.5",
56
56
  "rollup-plugin-terser": "7.0.2",
57
+ "string-to-arraybuffer": "^1.0.2",
57
58
  "ts-jest": "^28.0.0",
58
59
  "ts-node": "10.9.1",
59
60
  "typescript": "^4.5.3"
60
61
  },
61
62
  "dependencies": {
62
- "@descope/core-js-sdk": "^0.0.41-alpha.9"
63
+ "@descope/core-js-sdk": "^0.0.41-alpha.16",
64
+ "@descope/web-js-sdk": "^0.0.1-alpha.4"
63
65
  },
64
66
  "overrides": {
65
67
  "terser": "5.14.2"