@descope/react-sdk 0.0.0-next-dc07b682-20230521 → 0.0.0-next-ce3c752e-20230522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@descope/web-js-sdk");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=r(e),n=r(t);const u=o.default.createContext(void 0),i=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},a=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},c={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-dc07b682-20230521"},d="undefined"!=typeof window;let l;const f=e=>{const t=n.default({...e,persistTokens:d,autoRefresh:d});return l=t,t};l=f({projectId:"temp pid"});const p=()=>d?l?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),h=()=>d?l?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),m=a(((e=p(),t)=>l?.getJwtPermissions(e,t))),k=a(((e=p(),t)=>l?.getJwtRoles(e,t)));const b=({projectId:t,baseUrl:r,sessionTokenViaCookie:s,children:n})=>{const[a,d]=e.useState(),[l,p]=e.useState(),[h,m]=e.useState(!1),[k,b]=e.useState(!1),g=(({projectId:t,baseUrl:r,sessionTokenViaCookie:s})=>e.useMemo((()=>{if(t)return f({projectId:t,baseUrl:r,sessionTokenViaCookie:s,baseHeaders:c,persistToken:!0,autoRefresh:!0})}),[t,r,s]))({projectId:t,baseUrl:r,sessionTokenViaCookie:s});e.useEffect((()=>{if(g){const e=g.onSessionTokenChange(p),t=g.onUserChange(d);return()=>{e(),t()}}}),[g]);const w=e.useCallback((()=>{b(!0),i(g?.refresh)().then((()=>{b(!1)}))}),[g]),y=e.useCallback((()=>{m(!0),i(g.me)().then((()=>{m(!1)}))}),[g]),S=e.useMemo((()=>({fetchUser:y,user:a,isUserLoading:h,fetchSession:w,session:l,isSessionLoading:k,projectId:t,baseUrl:r,setUser:d,setSession:p,sdk:g})),[y,a,h,w,l,k,t,r,d,p,g]);return o.default.createElement(u.Provider,{value:S},n)};b.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const g=e.lazy((async()=>((await Promise.resolve().then((function(){return s(require("@descope/web-component"))}))).default.sdkConfigOverrides={baseHeaders:c},{default:({projectId:e,flowId:t,baseUrl:r,innerRef:s,tenant:n,theme:u,debug:i,telemetryKey:a,redirectUrl:c,autoFocus:d})=>o.default.createElement("descope-wc",{"project-id":e,"flow-id":t,"base-url":r,ref:s,tenant:n,theme:u,debug:i,telemetryKey:a,"redirect-url":c,"auto-focus":d})}))),w=o.default.forwardRef((({flowId:t,onSuccess:r,onError:s,tenant:n,theme:i,debug:a,telemetryKey:c,redirectUrl:d,autoFocus:l},f)=>{const[p,h]=e.useState(null);e.useImperativeHandle(f,(()=>p));const{projectId:m,baseUrl:k,sdk:b}=o.default.useContext(u),w=e.useCallback((async e=>{await b.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),r&&r(e)}),[r]);return e.useEffect((()=>{const e=p;return e?.addEventListener("success",w),s&&e?.addEventListener("error",s),()=>{s&&e?.removeEventListener("error",s),e?.removeEventListener("success",w)}}),[p,s,w]),o.default.createElement("form",null,o.default.createElement(e.Suspense,{fallback:null},o.default.createElement(g,{projectId:m,flowId:t,baseUrl:k,innerRef:h,tenant:n,theme:i,debug:a,telemetryKey:c,redirectUrl:d,autoFocus:l})))}));w.defaultProps={onError:void 0,onSuccess:void 0};var y=()=>{const t=e.useContext(u);if(!t)throw Error("You can only use this hook in the context of <AuthProvider />");return t};const S=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,v={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],v);if("function"==typeof e[t])return()=>{throw Error(S("function"))};throw Error(S("attribute"))}};exports.AuthProvider=b,exports.Descope=w,exports.SignInFlow=e=>o.default.createElement(w,{...e,flowId:"sign-in"}),exports.SignUpFlow=e=>o.default.createElement(w,{...e,flowId:"sign-up"}),exports.SignUpOrInFlow=e=>o.default.createElement(w,{...e,flowId:"sign-up-or-in"}),exports.getJwtPermissions=m,exports.getJwtRoles=k,exports.getRefreshToken=h,exports.getSessionToken=p,exports.refresh=(e=h())=>l?.refresh(e),exports.useDescope=()=>{const{sdk:t}=y();return e.useMemo((()=>t||new Proxy(f({projectId:"dummy"}),v)),[t])},exports.useSession=()=>{const{session:t,isSessionLoading:r,fetchSession:s}=y(),o=e.useRef(r);return e.useMemo((()=>{o.current=r}),[r]),e.useMemo((()=>{t||r||(o.current=!0)}),[s]),e.useEffect((()=>{t||r||s()}),[s]),{isSessionLoading:o.current,sessionToken:t,isAuthenticated:!!t}},exports.useUser=()=>{const{user:t,fetchUser:r,isUserLoading:s,session:o}=y(),[n,u]=e.useState(!1),i=e.useRef(s),a=e.useMemo((()=>!t&&!s&&o&&!n),[r,o,n]);return e.useMemo((()=>{i.current=s}),[s]),e.useMemo((()=>{a&&(i.current=!0)}),[a]),e.useEffect((()=>{a&&(u(!0),r())}),[a]),{isUserLoading:i.current,user:t}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@descope/web-js-sdk");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=r(e),n=r(t);const u=o.default.createContext(void 0),i=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},a=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},c={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-ce3c752e-20230522"},d="undefined"!=typeof window;let l;const f=e=>{const t=n.default({...e,persistTokens:d,autoRefresh:d});return l=t,t};l=f({projectId:"temp pid"});const p=()=>d?l?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),h=()=>d?l?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),m=a(((e=p(),t)=>l?.getJwtPermissions(e,t))),k=a(((e=p(),t)=>l?.getJwtRoles(e,t)));const b=({projectId:t,baseUrl:r,sessionTokenViaCookie:s,children:n})=>{const[a,d]=e.useState(),[l,p]=e.useState(),[h,m]=e.useState(!1),[k,b]=e.useState(!1),g=(({projectId:t,baseUrl:r,sessionTokenViaCookie:s})=>e.useMemo((()=>{if(t)return f({projectId:t,baseUrl:r,sessionTokenViaCookie:s,baseHeaders:c,persistToken:!0,autoRefresh:!0})}),[t,r,s]))({projectId:t,baseUrl:r,sessionTokenViaCookie:s});e.useEffect((()=>{if(g){const e=g.onSessionTokenChange(p),t=g.onUserChange(d);return()=>{e(),t()}}}),[g]);const w=e.useCallback((()=>{b(!0),i(g?.refresh)().then((()=>{b(!1)}))}),[g]),y=e.useCallback((()=>{m(!0),i(g.me)().then((()=>{m(!1)}))}),[g]),S=e.useMemo((()=>({fetchUser:y,user:a,isUserLoading:h,fetchSession:w,session:l,isSessionLoading:k,projectId:t,baseUrl:r,setUser:d,setSession:p,sdk:g})),[y,a,h,w,l,k,t,r,d,p,g]);return o.default.createElement(u.Provider,{value:S},n)};b.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const g=e.lazy((async()=>((await Promise.resolve().then((function(){return s(require("@descope/web-component"))}))).default.sdkConfigOverrides={baseHeaders:c},{default:({projectId:e,flowId:t,baseUrl:r,innerRef:s,tenant:n,theme:u,debug:i,telemetryKey:a,redirectUrl:c,autoFocus:d})=>o.default.createElement("descope-wc",{"project-id":e,"flow-id":t,"base-url":r,ref:s,tenant:n,theme:u,debug:i,telemetryKey:a,"redirect-url":c,"auto-focus":d})}))),w=o.default.forwardRef((({flowId:t,onSuccess:r,onError:s,tenant:n,theme:i,debug:a,telemetryKey:c,redirectUrl:d,autoFocus:l},f)=>{const[p,h]=e.useState(null);e.useImperativeHandle(f,(()=>p));const{projectId:m,baseUrl:k,sdk:b}=o.default.useContext(u),w=e.useCallback((async e=>{await b.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),r&&r(e)}),[r]);return e.useEffect((()=>{const e=p;return e?.addEventListener("success",w),s&&e?.addEventListener("error",s),()=>{s&&e?.removeEventListener("error",s),e?.removeEventListener("success",w)}}),[p,s,w]),o.default.createElement("form",null,o.default.createElement(e.Suspense,{fallback:null},o.default.createElement(g,{projectId:m,flowId:t,baseUrl:k,innerRef:h,tenant:n,theme:i,debug:a,telemetryKey:c,redirectUrl:d,autoFocus:l})))}));w.defaultProps={onError:void 0,onSuccess:void 0};var y=()=>{const t=e.useContext(u);if(!t)throw Error("You can only use this hook in the context of <AuthProvider />");return t};const S=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,v={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],v);if("function"==typeof e[t])return()=>{throw Error(S("function"))};throw Error(S("attribute"))}};exports.AuthProvider=b,exports.Descope=w,exports.SignInFlow=e=>o.default.createElement(w,{...e,flowId:"sign-in"}),exports.SignUpFlow=e=>o.default.createElement(w,{...e,flowId:"sign-up"}),exports.SignUpOrInFlow=e=>o.default.createElement(w,{...e,flowId:"sign-up-or-in"}),exports.getJwtPermissions=m,exports.getJwtRoles=k,exports.getRefreshToken=h,exports.getSessionToken=p,exports.refresh=(e=h())=>l?.refresh(e),exports.useDescope=()=>{const{sdk:t}=y();return e.useMemo((()=>t||new Proxy(f({projectId:"dummy"}),v)),[t])},exports.useSession=()=>{const{session:t,isSessionLoading:r,fetchSession:s}=y(),o=e.useRef(r);return e.useMemo((()=>{o.current=r}),[r]),e.useMemo((()=>{t||r||(o.current=!0)}),[s]),e.useEffect((()=>{t||r||s()}),[s]),{isSessionLoading:o.current,sessionToken:t,isAuthenticated:!!t}},exports.useUser=()=>{const{user:t,fetchUser:r,isUserLoading:s,session:o}=y(),[n,u]=e.useState(!1),i=e.useRef(s),a=e.useMemo((()=>!t&&!s&&o&&!n),[r,o,n]);return e.useMemo((()=>{i.current=s}),[s]),e.useMemo((()=>{a&&(i.current=!0)}),[a]),e.useEffect((()=>{a&&(u(!0),r())}),[a]),{isUserLoading:i.current,user:t}};
2
2
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{useMemo as t,useState as r,useEffect as o,useCallback as s,lazy as n,useImperativeHandle as i,Suspense as c,useContext as a,useRef as d}from"react";import u from"@descope/web-js-sdk";const l=e.createContext(void 0),f=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},p=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},h={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-dc07b682-20230521"},m="undefined"!=typeof window;let k;const w=e=>{const t=u({...e,persistTokens:m,autoRefresh:m});return k=t,t};k=w({projectId:"temp pid"});const y=()=>m?k?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),b=()=>m?k?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),g=p(((e=y(),t)=>k?.getJwtPermissions(e,t))),U=p(((e=y(),t)=>k?.getJwtRoles(e,t))),v=(e=b())=>k?.refresh(e);const E=({projectId:n,baseUrl:i,sessionTokenViaCookie:c,children:a})=>{const[d,u]=r(),[p,m]=r(),[k,y]=r(!1),[b,g]=r(!1),U=(({projectId:e,baseUrl:r,sessionTokenViaCookie:o})=>t((()=>{if(e)return w({projectId:e,baseUrl:r,sessionTokenViaCookie:o,baseHeaders:h,persistToken:!0,autoRefresh:!0})}),[e,r,o]))({projectId:n,baseUrl:i,sessionTokenViaCookie:c});o((()=>{if(U){const e=U.onSessionTokenChange(m),t=U.onUserChange(u);return()=>{e(),t()}}}),[U]);const v=s((()=>{g(!0),f(U?.refresh)().then((()=>{g(!1)}))}),[U]),E=s((()=>{y(!0),f(U.me)().then((()=>{y(!1)}))}),[U]),I=t((()=>({fetchUser:E,user:d,isUserLoading:k,fetchSession:v,session:p,isSessionLoading:b,projectId:n,baseUrl:i,setUser:u,setSession:m,sdk:U})),[E,d,k,v,p,b,n,i,u,m,U]);return e.createElement(l.Provider,{value:I},a)};E.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const I=n((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:h},{default:({projectId:t,flowId:r,baseUrl:o,innerRef:s,tenant:n,theme:i,debug:c,telemetryKey:a,redirectUrl:d,autoFocus:u})=>e.createElement("descope-wc",{"project-id":t,"flow-id":r,"base-url":o,ref:s,tenant:n,theme:i,debug:c,telemetryKey:a,"redirect-url":d,"auto-focus":u})}))),j=e.forwardRef((({flowId:t,onSuccess:n,onError:a,tenant:d,theme:u,debug:f,telemetryKey:p,redirectUrl:h,autoFocus:m},k)=>{const[w,y]=r(null);i(k,(()=>w));const{projectId:b,baseUrl:g,sdk:U}=e.useContext(l),v=s((async e=>{await U.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),n&&n(e)}),[n]);return o((()=>{const e=w;return e?.addEventListener("success",v),a&&e?.addEventListener("error",a),()=>{a&&e?.removeEventListener("error",a),e?.removeEventListener("success",v)}}),[w,a,v]),e.createElement("form",null,e.createElement(c,{fallback:null},e.createElement(I,{projectId:b,flowId:t,baseUrl:g,innerRef:y,tenant:d,theme:u,debug:f,telemetryKey:p,redirectUrl:h,autoFocus:m})))}));j.defaultProps={onError:void 0,onSuccess:void 0};const S=t=>e.createElement(j,{...t,flowId:"sign-in"}),C=t=>e.createElement(j,{...t,flowId:"sign-up"}),R=t=>e.createElement(j,{...t,flowId:"sign-up-or-in"});var T=()=>{const e=a(l);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const x=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,L={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],L);if("function"==typeof e[t])return()=>{throw Error(x("function"))};throw Error(x("attribute"))}},P=()=>{const{sdk:e}=T();return t((()=>e||new Proxy(w({projectId:"dummy"}),L)),[e])},V=()=>{const{session:e,isSessionLoading:r,fetchSession:s}=T(),n=d(r);return t((()=>{n.current=r}),[r]),t((()=>{e||r||(n.current=!0)}),[s]),o((()=>{e||r||s()}),[s]),{isSessionLoading:n.current,sessionToken:e,isAuthenticated:!!e}},A=()=>{const{user:e,fetchUser:s,isUserLoading:n,session:i}=T(),[c,a]=r(!1),u=d(n),l=t((()=>!e&&!n&&i&&!c),[s,i,c]);return t((()=>{u.current=n}),[n]),t((()=>{l&&(u.current=!0)}),[l]),o((()=>{l&&(a(!0),s())}),[l]),{isUserLoading:u.current,user:e}};export{E as AuthProvider,j as Descope,S as SignInFlow,C as SignUpFlow,R as SignUpOrInFlow,g as getJwtPermissions,U as getJwtRoles,b as getRefreshToken,y as getSessionToken,v as refresh,P as useDescope,V as useSession,A as useUser};
1
+ import e,{useMemo as t,useState as r,useEffect as o,useCallback as s,lazy as n,useImperativeHandle as i,Suspense as c,useContext as a,useRef as d}from"react";import u from"@descope/web-js-sdk";const l=e.createContext(void 0),f=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},p=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},h={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-ce3c752e-20230522"},m="undefined"!=typeof window;let k;const w=e=>{const t=u({...e,persistTokens:m,autoRefresh:m});return k=t,t};k=w({projectId:"temp pid"});const y=()=>m?k?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),g=()=>m?k?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),b=p(((e=y(),t)=>k?.getJwtPermissions(e,t))),U=p(((e=y(),t)=>k?.getJwtRoles(e,t))),v=(e=g())=>k?.refresh(e);const E=({projectId:n,baseUrl:i,sessionTokenViaCookie:c,children:a})=>{const[d,u]=r(),[p,m]=r(),[k,y]=r(!1),[g,b]=r(!1),U=(({projectId:e,baseUrl:r,sessionTokenViaCookie:o})=>t((()=>{if(e)return w({projectId:e,baseUrl:r,sessionTokenViaCookie:o,baseHeaders:h,persistToken:!0,autoRefresh:!0})}),[e,r,o]))({projectId:n,baseUrl:i,sessionTokenViaCookie:c});o((()=>{if(U){const e=U.onSessionTokenChange(m),t=U.onUserChange(u);return()=>{e(),t()}}}),[U]);const v=s((()=>{b(!0),f(U?.refresh)().then((()=>{b(!1)}))}),[U]),E=s((()=>{y(!0),f(U.me)().then((()=>{y(!1)}))}),[U]),I=t((()=>({fetchUser:E,user:d,isUserLoading:k,fetchSession:v,session:p,isSessionLoading:g,projectId:n,baseUrl:i,setUser:u,setSession:m,sdk:U})),[E,d,k,v,p,g,n,i,u,m,U]);return e.createElement(l.Provider,{value:I},a)};E.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const I=n((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:h},{default:({projectId:t,flowId:r,baseUrl:o,innerRef:s,tenant:n,theme:i,debug:c,telemetryKey:a,redirectUrl:d,autoFocus:u})=>e.createElement("descope-wc",{"project-id":t,"flow-id":r,"base-url":o,ref:s,tenant:n,theme:i,debug:c,telemetryKey:a,"redirect-url":d,"auto-focus":u})}))),j=e.forwardRef((({flowId:t,onSuccess:n,onError:a,tenant:d,theme:u,debug:f,telemetryKey:p,redirectUrl:h,autoFocus:m},k)=>{const[w,y]=r(null);i(k,(()=>w));const{projectId:g,baseUrl:b,sdk:U}=e.useContext(l),v=s((async e=>{await U.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),n&&n(e)}),[n]);return o((()=>{const e=w;return e?.addEventListener("success",v),a&&e?.addEventListener("error",a),()=>{a&&e?.removeEventListener("error",a),e?.removeEventListener("success",v)}}),[w,a,v]),e.createElement("form",null,e.createElement(c,{fallback:null},e.createElement(I,{projectId:g,flowId:t,baseUrl:b,innerRef:y,tenant:d,theme:u,debug:f,telemetryKey:p,redirectUrl:h,autoFocus:m})))}));j.defaultProps={onError:void 0,onSuccess:void 0};const S=t=>e.createElement(j,{...t,flowId:"sign-in"}),C=t=>e.createElement(j,{...t,flowId:"sign-up"}),R=t=>e.createElement(j,{...t,flowId:"sign-up-or-in"});var T=()=>{const e=a(l);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const x=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,L={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],L);if("function"==typeof e[t])return()=>{throw Error(x("function"))};throw Error(x("attribute"))}},P=()=>{const{sdk:e}=T();return t((()=>e||new Proxy(w({projectId:"dummy"}),L)),[e])},V=()=>{const{session:e,isSessionLoading:r,fetchSession:s}=T(),n=d(r);return t((()=>{n.current=r}),[r]),t((()=>{e||r||(n.current=!0)}),[s]),o((()=>{e||r||s()}),[s]),{isSessionLoading:n.current,sessionToken:e,isAuthenticated:!!e}},A=()=>{const{user:e,fetchUser:s,isUserLoading:n,session:i}=T(),[c,a]=r(!1),u=d(n),l=t((()=>!e&&!n&&i&&!c),[s,i,c]);return t((()=>{u.current=n}),[n]),t((()=>{l&&(u.current=!0)}),[l]),o((()=>{l&&(a(!0),s())}),[l]),{isUserLoading:u.current,user:e}};export{E as AuthProvider,j as Descope,S as SignInFlow,C as SignUpFlow,R as SignUpOrInFlow,b as getJwtPermissions,U as getJwtRoles,g as getRefreshToken,y as getSessionToken,v as refresh,P as useDescope,V as useSession,A as useUser};
2
2
  //# sourceMappingURL=index.esm.js.map
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Descope={},e.React)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t);const r=o.default.createContext(void 0),i=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},s=e=>(...t)=>{let n;try{n=e(...t)}catch(e){console.error(e)}return n},a={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-dc07b682-20230521"},l="undefined"!=typeof window;var c=function(){return c=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},c.apply(this,arguments)};function u(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function d(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function a(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}function h(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function p(e,t,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?r.call(e,n):r?r.value=n:t.set(e,n),n}function f(e){this.message=e}f.prototype=new Error,f.prototype.name="InvalidCharacterError";var g="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new f("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,s="";o=t.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function v(e){this.message=e}function m(e,t){if("string"!=typeof e)throw new v("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(g(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 g(t)}}(e.split(".")[n]))}catch(e){throw new v("Invalid token specified: "+e.message)}}v.prototype=new Error,v.prototype.name="InvalidTokenError";var b="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function w(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var y="__lodash_hash_undefined__",k="[object Function]",I="[object GeneratorFunction]",x=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,j=/^\w*$/,O=/^\./,S=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,C=/\\(\\)?/g,E=/^\[object .+?Constructor\]$/,A="object"==typeof b&&b&&b.Object===Object&&b,U="object"==typeof self&&self&&self.Object===Object&&self,_=A||U||Function("return this")();var P,R=Array.prototype,T=Function.prototype,L=Object.prototype,M=_["__core-js_shared__"],q=(P=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||""))?"Symbol(src)_1."+P:"",$=T.toString,D=L.hasOwnProperty,F=L.toString,N=RegExp("^"+$.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),K=_.Symbol,W=R.splice,J=te(_,"Map"),H=te(Object,"create"),z=K?K.prototype:void 0,V=z?z.toString:void 0;function B(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function G(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Y(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Z(e,t){for(var n,o,r=e.length;r--;)if((n=e[r][0])===(o=t)||n!=n&&o!=o)return r;return-1}function X(e,t){var n;t=function(e,t){if(ie(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ae(e))return!0;return j.test(e)||!x.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:ie(n=t)?n:ne(n);for(var o=0,r=t.length;null!=e&&o<r;)e=e[oe(t[o++])];return o&&o==r?e:void 0}function Q(e){if(!se(e)||(t=e,q&&q in t))return!1;var t,n=function(e){var t=se(e)?F.call(e):"";return t==k||t==I}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?N:E;return n.test(function(e){if(null!=e){try{return $.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function ee(e,t){var n,o,r=e.__data__;return("string"==(o=typeof(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?r["string"==typeof t?"string":"hash"]:r.map}function te(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Q(n)?n:void 0}B.prototype.clear=function(){this.__data__=H?H(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(H){var n=t[e];return n===y?void 0:n}return D.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return H?void 0!==t[e]:D.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=H&&void 0===t?y:t,this},G.prototype.clear=function(){this.__data__=[]},G.prototype.delete=function(e){var t=this.__data__,n=Z(t,e);return!(n<0)&&(n==t.length-1?t.pop():W.call(t,n,1),!0)},G.prototype.get=function(e){var t=this.__data__,n=Z(t,e);return n<0?void 0:t[n][1]},G.prototype.has=function(e){return Z(this.__data__,e)>-1},G.prototype.set=function(e,t){var n=this.__data__,o=Z(n,e);return o<0?n.push([e,t]):n[o][1]=t,this},Y.prototype.clear=function(){this.__data__={hash:new B,map:new(J||G),string:new B}},Y.prototype.delete=function(e){return ee(this,e).delete(e)},Y.prototype.get=function(e){return ee(this,e).get(e)},Y.prototype.has=function(e){return ee(this,e).has(e)},Y.prototype.set=function(e,t){return ee(this,e).set(e,t),this};var ne=re((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ae(e))return V?V.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return O.test(e)&&n.push(""),e.replace(S,(function(e,t,o,r){n.push(o?r.replace(C,"$1"):t||e)})),n}));function oe(e){if("string"==typeof e||ae(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function re(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var o=arguments,r=t?t.apply(this,o):o[0],i=n.cache;if(i.has(r))return i.get(r);var s=e.apply(this,o);return n.cache=i.set(r,s),s};return n.cache=new(re.Cache||Y),n}re.Cache=Y;var ie=Array.isArray;function se(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ae(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==F.call(e)}var le=function(e,t,n){var o=null==e?void 0:X(e,t);return void 0===o?n:o},ce="/v1/auth/accesskey/exchange",ue="/v1/auth/otp/verify",de="/v1/auth/otp/signin",he="/v1/auth/otp/signup",pe={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},fe="/v1/auth/otp/signup-in",ge="/v1/auth/magiclink/verify",ve="/v1/auth/magiclink/signin",me="/v1/auth/magiclink/signup",be={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},we="/v1/auth/magiclink/signup-in",ye="/v1/auth/enchantedlink/verify",ke="/v1/auth/enchantedlink/signin",Ie="/v1/auth/enchantedlink/signup",xe="/v1/auth/enchantedlink/pending-session",je={email:"/v1/auth/enchantedlink/update/email"},Oe="/v1/auth/enchantedlink/signup-in",Se="/v1/auth/oauth/authorize",Ce="/v1/auth/oauth/exchange",Ee="/v1/auth/saml/authorize",Ae="/v1/auth/saml/exchange",Ue="/v1/auth/totp/verify",_e="/v1/auth/totp/signup",Pe="/v1/auth/totp/update",Re={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Te={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Le={start:"/v1/auth/webauthn/signup-in/start"},Me={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},qe="/v1/auth/password/signup",$e="/v1/auth/password/signin",De="/v1/auth/password/reset",Fe="/v1/auth/password/update",Ne="/v1/auth/password/replace",Ke="/v1/auth/password/policy",We="/v1/auth/refresh",Je="/v1/auth/logout",He="/v1/auth/logoutall",ze="/v1/auth/me",Ve="/v1/flow/start",Be="/v1/flow/next";const Ge=6e5,Ye=()=>{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")}};var Ze;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ze||(Ze={}));const Xe=(...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,o])=>(e[n]=o,e)),e),e}),{})),Qe=e=>void 0===e?void 0:JSON.stringify(e),et=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},tt=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:s})=>{const a=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.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"),e?async(...t)=>{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");e.log((e=>Ye().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return Ye().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(o)),o}:n})(o,s),l=async o=>{const s=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=s,f=await a((({path:e,baseUrl:t,queryParams:n})=>{const o=new URL(e,t);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:e,queryParams:d}),{headers:Xe(et(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.3"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Qe(c),credentials:i||"include"});return(null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:Ze.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:r}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ze.post,token:r}),put:(e,t,{headers:n,queryParams:o,token:r}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ze.put,token:r}),delete:(e,t,{headers:n,queryParams:o,token:r}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ze.delete,token:r}),hooks:r}};var nt=429;function ot(e,t,n){var o;let r=rt(e);t&&(r=null===(o=null==r?void 0:r.tenants)||void 0===o?void 0:o[t]);const i=null==r?void 0:r[n];return Array.isArray(i)?i:[]}function rt(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return m(e)}function it(e){const{exp:t}=rt(e);return(new Date).getTime()/1e3>t}function st(e,t){return ot(e,t,"permissions")}function at(e,t){return ot(e,t,"roles")}const lt=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function ct(e,t){var n;const o=await e,r={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?r.data=t?t(i):i:(r.error=i,o.status===nt&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const ut=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),dt=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),ht=e=>t=>e.test(t),pt=ht(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),ft=ht(/^\+[1-9]{1}[0-9]{3,14}$/),gt=ut(pt,'"{val}" is not a valid email'),vt=ut(ft,'"{val}" is not a valid phone number'),mt=ut((1,e=>e.length>=1),"Minimum length is 1");const bt=ut((e=>"string"==typeof e),"Input is not a string"),wt=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>dt(...e).validate(n[t]))),t(...n)),yt=e=>[bt(`"${e}" must be a string`),mt(`"${e}" must not be empty`)],kt=e=>[bt(`"${e}" must be a string`),gt()],It=e=>[bt(`"${e}" must be a string`),vt()],xt=wt(yt("accessKey")),jt=e=>({exchange:xt((t=>ct(e.post(ce,{},{token:t}))))});var Ot,St;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Ot||(Ot={})),function(e){e.email="email"}(St||(St={}));const Ct=Object.assign(Object.assign({},Ot),St);var Et;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Et||(Et={}));const At=yt("loginId"),Ut=wt(yt("token")),_t=wt(At),Pt=wt(yt("pendingRef")),Rt=wt(At,kt("email")),Tt=e=>({verify:Ut((t=>ct(e.post(ye,{token:t})))),signIn:_t(((t,n,o,r)=>ct(e.post(lt(ke,Ct.email),{loginId:t,URI:n,loginOptions:o},{token:r})))),signUpOrIn:_t(((t,n)=>ct(e.post(lt(Oe,Ct.email),{loginId:t,URI:n})))),signUp:_t(((t,n,o)=>ct(e.post(lt(Ie,Ct.email),{loginId:t,URI:n,user:o})))),waitForSession:Pt(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||Ge,Ge)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(xe,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ct(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Rt(((t,n,o,r,i)=>ct(e.post(je.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r}))))}}),Lt=wt(yt("flowId")),Mt=wt(yt("executionId"),yt("stepId"),yt("interactionId")),qt=e=>({start:Lt(((t,n,o,r,i,s)=>ct(e.post(Ve,{flowId:t,options:n,conditionInteractionId:o,interactionId:r,input:i,version:s})))),next:Mt(((t,n,o,r,i)=>ct(e.post(Be,{executionId:t,stepId:n,interactionId:o,input:r,version:i}))))}),$t=yt("loginId"),Dt=wt(yt("token")),Ft=wt($t),Nt=wt($t,It("phone")),Kt=wt($t,kt("email")),Wt=e=>({verify:Dt((t=>ct(e.post(ge,{token:t})))),signIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ft(((t,o,r,i)=>ct(e.post(lt(ve,n),{loginId:t,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ft(((t,o,r)=>ct(e.post(lt(me,n),{loginId:t,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ft(((t,o)=>ct(e.post(lt(we,n),{loginId:t,URI:o}))))})),{}),update:{email:Kt(((t,n,o,r,i)=>ct(e.post(be.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r})))),phone:Object.keys(Ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Nt(((t,o,r,i,s)=>ct(e.post(lt(be.phone,n),Object.assign({loginId:t,phone:o,URI:r},s),{token:i}))))})),{})}});var Jt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin"}(Jt||(Jt={}));const Ht=wt(yt("code")),zt=e=>({start:Object.keys(Jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,r)=>ct(e.post(Se,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:r}))})),{}),exchange:Ht((t=>ct(e.post(Ce,{code:t}))))}),Vt=yt("loginId"),Bt=wt(Vt,yt("code")),Gt=wt(Vt),Yt=wt(Vt,It("phone")),Zt=wt(Vt,kt("email")),Xt=e=>({verify:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Bt(((t,o)=>ct(e.post(lt(ue,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt(((t,o,r)=>ct(e.post(lt(de,n),{loginId:t,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt(((t,o)=>ct(e.post(lt(he,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt((t=>ct(e.post(lt(fe,n),{loginId:t}))))})),{}),update:{email:Zt(((t,n,o,r)=>ct(e.post(pe.email,Object.assign({loginId:t,email:n},r),{token:o})))),phone:Object.keys(Ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,o,r,i)=>ct(e.post(lt(pe.phone,n),Object.assign({loginId:t,phone:o},i),{token:r}))))})),{})}}),Qt=wt(yt("tenant")),en=wt(yt("code")),tn=e=>({start:Qt(((t,n,o,r)=>ct(e.post(Ee,o||{},{queryParams:{tenant:t,redirectURL:n},token:r})))),exchange:en((t=>ct(e.post(Ae,{code:t}))))}),nn=yt("loginId"),on=wt(nn,yt("code")),rn=wt(nn),sn=wt(nn),an=e=>({signUp:rn(((t,n)=>ct(e.post(_e,{loginId:t,user:n})))),verify:on(((t,n,o,r)=>ct(e.post(Ue,{loginId:t,code:n,loginOptions:o},{token:r})))),update:sn(((t,n)=>ct(e.post(Pe,{loginId:t},{token:n}))))}),ln=yt("loginId"),cn=yt("newPassword"),un=wt(ln,yt("password")),dn=wt(ln),hn=wt(ln,cn),pn=wt(ln,yt("oldPassword"),cn),fn=e=>({signUp:un(((t,n,o)=>ct(e.post(qe,{loginId:t,password:n,user:o})))),signIn:un(((t,n)=>ct(e.post($e,{loginId:t,password:n})))),sendReset:dn(((t,n)=>ct(e.post(De,{loginId:t,redirectUrl:n})))),update:hn(((t,n,o)=>ct(e.post(Fe,{loginId:t,newPassword:n},{token:o})))),replace:pn(((t,n,o)=>ct(e.post(Ne,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>ct(e.get(Ke))}),gn=[bt('"loginId" must be a string')],vn=yt("loginId"),mn=yt("origin"),bn=wt(vn,mn,yt("name")),wn=wt(vn,mn),yn=wt(gn,mn),kn=wt(vn,mn,yt("token")),In=wt(yt("transactionId"),yt("response")),xn=e=>({signUp:{start:bn(((t,n,o)=>ct(e.post(Re.start,{user:{loginId:t,name:o},origin:n})))),finish:In(((t,n)=>ct(e.post(Re.finish,{transactionId:t,response:n}))))},signIn:{start:yn(((t,n,o,r)=>ct(e.post(Te.start,{loginId:t,origin:n,loginOptions:o},{token:r})))),finish:In(((t,n)=>ct(e.post(Te.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:wn(((t,n)=>ct(e.post(Le.start,{loginId:t,origin:n}))))},update:{start:kn(((t,n,o)=>ct(e.post(Me.start,{loginId:t,origin:n},{token:o})))),finish:In(((t,n)=>ct(e.post(Me.finish,{transactionId:t,response:n}))))}}),jn=wt(yt("token"));var On,Sn=wt([("projectId",On=yt("projectId"),ut(((e,t)=>n=>dt(...t).validate(le(n,e)))("projectId",On))())])((e=>{var t,n;const o=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),r=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:s})=>{return a=tt({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:s}),{accessKey:jt(a),otp:Xt(a),magicLink:Wt(a),enchantedLink:Tt(a),oauth:zt(a),saml:tn(a),totp:an(a),webauthn:xn(a),password:fn(a),flow:qt(a),refresh:e=>ct(a.post(We,{},{token:e})),logout:e=>ct(a.post(Je,{},{token:e})),logoutAll:e=>ct(a.post(He,{},{token:e})),me:e=>ct(a.get(ze,{token:e})),isJwtExpired:jn(it),getJwtPermissions:jn(st),getJwtRoles:jn(at),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(t,n)=>{(await Promise.allSettled(null==r?void 0:r.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))}));const Cn=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let r=o.shift(),i=e;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${t}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${t}" is not a function`);const s=i[r];i[r]=n(s)})),e);var En=Object.assign(Sn,{DeliveryMethods:Ct});var An="Blocked by CSP",Un="9319";function _n(e,t){var n=[];return function(e,t){var n,o,r=(o=function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0),{current:function(){return o[0]},postpone:function(){var e=o.shift();void 0!==e&&o.push(e)},exclude:function(){o.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=r.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return t===An||t===Un}(e)?r.postpone():r.exclude();var t,o=r.current();if(void 0===o)throw e;return(t=i(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(e,(function(e){var o=new Date,r=function(){return n.push({url:e,startedAt:o,finishedAt:new Date})},i=t(e);return i.then(r,r),i})).then((function(e){return[e,{attempts:n}]}))}var Pn="Failed to load the JS script of the agent";function Rn(e){var t;e.scriptUrlPattern;var n=e.token,o=e.apiKey,r=void 0===o?n:o,i=u(e,["scriptUrlPattern","token","apiKey"]),s=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!r||"string"!=typeof r)throw new Error("API key required");var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.8.3"):e}))}(String(e),t)}))}(s,r);return _n(e,Tn).catch(Mn)})).then((function(e){var t=e[0],n=e[1];return t.load(c(c({},i),{ldi:n}))}))}function Tn(e){return function(e,t,n,o){var r,i=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(r=t,l())};i.addEventListener(s,a);var l=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return l(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(l(),r)return function(){throw new Error(An)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){var o=document.createElement("script"),r=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),t()},o.onerror=function(){r(),n(new Error(Pn))},o.async=!0,o.src=e,i.appendChild(o)}))}(e)})).then(Ln)}function Ln(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(Un);return n}function Mn(e){throw e instanceof Error&&e.message===Un?new Error(Pn):e}var qn={},$n={get exports(){return qn},set exports(e){qn=e}},Dn={},Fn={get exports(){return Dn},set exports(e){Dn=e}};
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Descope={},e.React)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t);const i=o.default.createContext(void 0),r=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},s=e=>(...t)=>{let n;try{n=e(...t)}catch(e){console.error(e)}return n},a={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-ce3c752e-20230522"},l="undefined"!=typeof window;var c=function(){return c=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},c.apply(this,arguments)};function u(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function d(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}function h(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function p(e,t,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 t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}function f(e){this.message=e}f.prototype=new Error,f.prototype.name="InvalidCharacterError";var g="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new f("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,r=0,s="";o=t.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 v(e){this.message=e}function b(e,t){if("string"!=typeof e)throw new v("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(g(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 g(t)}}(e.split(".")[n]))}catch(e){throw new v("Invalid token specified: "+e.message)}}v.prototype=new Error,v.prototype.name="InvalidTokenError";var m="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function w(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var y="__lodash_hash_undefined__",k="[object Function]",I="[object GeneratorFunction]",O=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,j=/^\w*$/,S=/^\./,x=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,C=/\\(\\)?/g,U=/^\[object .+?Constructor\]$/,E="object"==typeof m&&m&&m.Object===Object&&m,A="object"==typeof self&&self&&self.Object===Object&&self,P=E||A||Function("return this")();var R,_=Array.prototype,T=Function.prototype,q=Object.prototype,L=P["__core-js_shared__"],M=(R=/[^.]+$/.exec(L&&L.keys&&L.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"",D=T.toString,$=q.hasOwnProperty,J=q.toString,N=RegExp("^"+D.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),K=P.Symbol,F=_.splice,H=te(P,"Map"),W=te(Object,"create"),z=K?K.prototype:void 0,V=z?z.toString:void 0;function B(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function G(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Z(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Y(e,t){for(var n,o,i=e.length;i--;)if((n=e[i][0])===(o=t)||n!=n&&o!=o)return i;return-1}function X(e,t){var n;t=function(e,t){if(re(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ae(e))return!0;return j.test(e)||!O.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:re(n=t)?n:ne(n);for(var o=0,i=t.length;null!=e&&o<i;)e=e[oe(t[o++])];return o&&o==i?e:void 0}function Q(e){if(!se(e)||(t=e,M&&M in t))return!1;var t,n=function(e){var t=se(e)?J.call(e):"";return t==k||t==I}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?N:U;return n.test(function(e){if(null!=e){try{return D.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function ee(e,t){var n,o,i=e.__data__;return("string"==(o=typeof(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function te(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Q(n)?n:void 0}B.prototype.clear=function(){this.__data__=W?W(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(W){var n=t[e];return n===y?void 0:n}return $.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return W?void 0!==t[e]:$.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=W&&void 0===t?y:t,this},G.prototype.clear=function(){this.__data__=[]},G.prototype.delete=function(e){var t=this.__data__,n=Y(t,e);return!(n<0)&&(n==t.length-1?t.pop():F.call(t,n,1),!0)},G.prototype.get=function(e){var t=this.__data__,n=Y(t,e);return n<0?void 0:t[n][1]},G.prototype.has=function(e){return Y(this.__data__,e)>-1},G.prototype.set=function(e,t){var n=this.__data__,o=Y(n,e);return o<0?n.push([e,t]):n[o][1]=t,this},Z.prototype.clear=function(){this.__data__={hash:new B,map:new(H||G),string:new B}},Z.prototype.delete=function(e){return ee(this,e).delete(e)},Z.prototype.get=function(e){return ee(this,e).get(e)},Z.prototype.has=function(e){return ee(this,e).has(e)},Z.prototype.set=function(e,t){return ee(this,e).set(e,t),this};var ne=ie((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ae(e))return V?V.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return S.test(e)&&n.push(""),e.replace(x,(function(e,t,o,i){n.push(o?i.replace(C,"$1"):t||e)})),n}));function oe(e){if("string"==typeof e||ae(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function ie(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=t?t.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=e.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(ie.Cache||Z),n}ie.Cache=Z;var re=Array.isArray;function se(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ae(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==J.call(e)}var le=function(e,t,n){var o=null==e?void 0:X(e,t);return void 0===o?n:o},ce="/v1/auth/accesskey/exchange",ue="/v1/auth/otp/verify",de="/v1/auth/otp/signin",he="/v1/auth/otp/signup",pe={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},fe="/v1/auth/otp/signup-in",ge="/v1/auth/magiclink/verify",ve="/v1/auth/magiclink/signin",be="/v1/auth/magiclink/signup",me={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},we="/v1/auth/magiclink/signup-in",ye="/v1/auth/enchantedlink/verify",ke="/v1/auth/enchantedlink/signin",Ie="/v1/auth/enchantedlink/signup",Oe="/v1/auth/enchantedlink/pending-session",je={email:"/v1/auth/enchantedlink/update/email"},Se="/v1/auth/enchantedlink/signup-in",xe="/v1/auth/oauth/authorize",Ce="/v1/auth/oauth/exchange",Ue="/v1/auth/saml/authorize",Ee="/v1/auth/saml/exchange",Ae="/v1/auth/totp/verify",Pe="/v1/auth/totp/signup",Re="/v1/auth/totp/update",_e={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Te={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},qe={start:"/v1/auth/webauthn/signup-in/start"},Le={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Me="/v1/auth/password/signup",De="/v1/auth/password/signin",$e="/v1/auth/password/reset",Je="/v1/auth/password/update",Ne="/v1/auth/password/replace",Ke="/v1/auth/password/policy",Fe="/v1/auth/refresh",He="/v1/auth/logout",We="/v1/auth/logoutall",ze="/v1/auth/me",Ve="/v1/flow/start",Be="/v1/flow/next";const Ge=6e5,Ze=()=>{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")}};var Ye;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ye||(Ye={}));const Xe=(...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,o])=>(e[n]=o,e)),e),e}),{})),Qe=e=>void 0===e?void 0:JSON.stringify(e),et=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},tt=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.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"),e?async(...t)=>{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");e.log((e=>Ze().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return Ze().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).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:e,baseUrl:t,queryParams:n})=>{const o=new URL(e,t);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:e,queryParams:d}),{headers:Xe(et(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.3"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Qe(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:Ye.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ye.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ye.put,token:i}),delete:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ye.delete,token:i}),hooks:i}};var nt=429;function ot(e,t,n){var o;let i=it(e);t&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[t]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function it(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return b(e)}function rt(e){const{exp:t}=it(e);return(new Date).getTime()/1e3>t}function st(e,t){return ot(e,t,"permissions")}function at(e,t){return ot(e,t,"roles")}const lt=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function ct(e,t){var n;const o=await e,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=t?t(r):r:(i.error=r,o.status===nt&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const ut=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),dt=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),ht=e=>t=>e.test(t),pt=ht(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),ft=ht(/^\+[1-9]{1}[0-9]{3,14}$/),gt=ut(pt,'"{val}" is not a valid email'),vt=ut(ft,'"{val}" is not a valid phone number'),bt=ut((1,e=>e.length>=1),"Minimum length is 1");const mt=ut((e=>"string"==typeof e),"Input is not a string"),wt=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>dt(...e).validate(n[t]))),t(...n)),yt=e=>[mt(`"${e}" must be a string`),bt(`"${e}" must not be empty`)],kt=e=>[mt(`"${e}" must be a string`),gt()],It=e=>[mt(`"${e}" must be a string`),vt()],Ot=wt(yt("accessKey")),jt=e=>({exchange:Ot((t=>ct(e.post(ce,{},{token:t}))))});var St,xt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(St||(St={})),function(e){e.email="email"}(xt||(xt={}));const Ct=Object.assign(Object.assign({},St),xt);var Ut;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Ut||(Ut={}));const Et=yt("loginId"),At=wt(yt("token")),Pt=wt(Et),Rt=wt(yt("pendingRef")),_t=wt(Et,kt("email")),Tt=e=>({verify:At((t=>ct(e.post(ye,{token:t})))),signIn:Pt(((t,n,o,i)=>ct(e.post(lt(ke,Ct.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Pt(((t,n)=>ct(e.post(lt(Se,Ct.email),{loginId:t,URI:n})))),signUp:Pt(((t,n,o)=>ct(e.post(lt(Ie,Ct.email),{loginId:t,URI:n,user:o})))),waitForSession:Rt(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||Ge,Ge)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(Oe,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ct(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:_t(((t,n,o,i,r)=>ct(e.post(je.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),qt=wt(yt("flowId")),Lt=wt(yt("executionId"),yt("stepId"),yt("interactionId")),Mt=e=>({start:qt(((t,n,o,i,r,s)=>ct(e.post(Ve,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,input:r,version:s})))),next:Lt(((t,n,o,i,r)=>ct(e.post(Be,{executionId:t,stepId:n,interactionId:o,input:i,version:r}))))}),Dt=yt("loginId"),$t=wt(yt("token")),Jt=wt(Dt),Nt=wt(Dt,It("phone")),Kt=wt(Dt,kt("email")),Ft=e=>({verify:$t((t=>ct(e.post(ge,{token:t})))),signIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,o,i,r)=>ct(e.post(lt(ve,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,o,i)=>ct(e.post(lt(be,n),{loginId:t,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,o)=>ct(e.post(lt(we,n),{loginId:t,URI:o}))))})),{}),update:{email:Kt(((t,n,o,i,r)=>ct(e.post(me.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Nt(((t,o,i,r,s)=>ct(e.post(lt(me.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var Ht;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin"}(Ht||(Ht={}));const Wt=wt(yt("code")),zt=e=>({start:Object.keys(Ht).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>ct(e.post(xe,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{}),exchange:Wt((t=>ct(e.post(Ce,{code:t}))))}),Vt=yt("loginId"),Bt=wt(Vt,yt("code")),Gt=wt(Vt),Zt=wt(Vt,It("phone")),Yt=wt(Vt,kt("email")),Xt=e=>({verify:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Bt(((t,o)=>ct(e.post(lt(ue,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt(((t,o,i)=>ct(e.post(lt(de,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt(((t,o)=>ct(e.post(lt(he,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt((t=>ct(e.post(lt(fe,n),{loginId:t}))))})),{}),update:{email:Yt(((t,n,o,i)=>ct(e.post(pe.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Zt(((t,o,i,r)=>ct(e.post(lt(pe.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),Qt=wt(yt("tenant")),en=wt(yt("code")),tn=e=>({start:Qt(((t,n,o,i)=>ct(e.post(Ue,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:en((t=>ct(e.post(Ee,{code:t}))))}),nn=yt("loginId"),on=wt(nn,yt("code")),rn=wt(nn),sn=wt(nn),an=e=>({signUp:rn(((t,n)=>ct(e.post(Pe,{loginId:t,user:n})))),verify:on(((t,n,o,i)=>ct(e.post(Ae,{loginId:t,code:n,loginOptions:o},{token:i})))),update:sn(((t,n)=>ct(e.post(Re,{loginId:t},{token:n}))))}),ln=yt("loginId"),cn=yt("newPassword"),un=wt(ln,yt("password")),dn=wt(ln),hn=wt(ln,cn),pn=wt(ln,yt("oldPassword"),cn),fn=e=>({signUp:un(((t,n,o)=>ct(e.post(Me,{loginId:t,password:n,user:o})))),signIn:un(((t,n)=>ct(e.post(De,{loginId:t,password:n})))),sendReset:dn(((t,n)=>ct(e.post($e,{loginId:t,redirectUrl:n})))),update:hn(((t,n,o)=>ct(e.post(Je,{loginId:t,newPassword:n},{token:o})))),replace:pn(((t,n,o)=>ct(e.post(Ne,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>ct(e.get(Ke))}),gn=[mt('"loginId" must be a string')],vn=yt("loginId"),bn=yt("origin"),mn=wt(vn,bn,yt("name")),wn=wt(vn,bn),yn=wt(gn,bn),kn=wt(vn,bn,yt("token")),In=wt(yt("transactionId"),yt("response")),On=e=>({signUp:{start:mn(((t,n,o)=>ct(e.post(_e.start,{user:{loginId:t,name:o},origin:n})))),finish:In(((t,n)=>ct(e.post(_e.finish,{transactionId:t,response:n}))))},signIn:{start:yn(((t,n,o,i)=>ct(e.post(Te.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:In(((t,n)=>ct(e.post(Te.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:wn(((t,n)=>ct(e.post(qe.start,{loginId:t,origin:n}))))},update:{start:kn(((t,n,o)=>ct(e.post(Le.start,{loginId:t,origin:n},{token:o})))),finish:In(((t,n)=>ct(e.post(Le.finish,{transactionId:t,response:n}))))}}),jn=wt(yt("token"));var Sn,xn=wt([("projectId",Sn=yt("projectId"),ut(((e,t)=>n=>dt(...t).validate(le(n,e)))("projectId",Sn))())])((e=>{var t,n;const o=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),i=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=tt({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:jt(a),otp:Xt(a),magicLink:Ft(a),enchantedLink:Tt(a),oauth:zt(a),saml:tn(a),totp:an(a),webauthn:On(a),password:fn(a),flow:Mt(a),refresh:e=>ct(a.post(Fe,{},{token:e})),logout:e=>ct(a.post(He,{},{token:e})),logoutAll:e=>ct(a.post(We,{},{token:e})),me:e=>ct(a.get(ze,{token:e})),isJwtExpired:jn(rt),getJwtPermissions:jn(st),getJwtRoles:jn(at),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(t,n)=>{(await Promise.allSettled(null==i?void 0:i.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))}));const Cn=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let i=o.shift(),r=e;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${t}" is not a function`);const s=r[i];r[i]=n(s)})),e);var Un=Object.assign(xn,{DeliveryMethods:Ct});var En="Blocked by CSP",An="9319";function Pn(e,t){var n=[];return function(e,t){var n,o,i=(o=function(e,t,n){if(n||2===arguments.length)for(var o,i=0,r=t.length;i<r;i++)!o&&i in t||(o||(o=Array.prototype.slice.call(t,0,i)),o[i]=t[i]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0),{current:function(){return o[0]},postpone:function(){var e=o.shift();void 0!==e&&o.push(e)},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(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return t===En||t===An}(e)?i.postpone():i.exclude();var t,o=i.current();if(void 0===o)throw e;return(t=r(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(e,(function(e){var o=new Date,i=function(){return n.push({url:e,startedAt:o,finishedAt:new Date})},r=t(e);return r.then(i,i),r})).then((function(e){return[e,{attempts:n}]}))}var Rn="Failed to load the JS script of the agent";function _n(e){var t;e.scriptUrlPattern;var n=e.token,o=e.apiKey,i=void 0===o?n:o,r=u(e,["scriptUrlPattern","token","apiKey"]),s=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!i||"string"!=typeof i)throw new Error("API key required");var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.8.3"):e}))}(String(e),t)}))}(s,i);return Pn(e,Tn).catch(Ln)})).then((function(e){var t=e[0],n=e[1];return t.load(c(c({},r),{ldi:n}))}))}function Tn(e){return function(e,t,n,o){var i,r=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=t,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return l(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(l(),i)return function(){throw new Error(En)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){var o=document.createElement("script"),i=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),t()},o.onerror=function(){i(),n(new Error(Rn))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then(qn)}function qn(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(An);return n}function Ln(e){throw e instanceof Error&&e.message===An?new Error(Rn):e}var Mn={},Dn={get exports(){return Mn},set exports(e){Mn=e}},$n={},Jn={get exports(){return $n},set exports(e){$n=e}};
2
2
  /*! js-cookie v3.0.5 | MIT */
3
- !function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}function t(n,o){function r(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,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(r,t)+s}}function i(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},r=0;r<t.length;r++){var i=t[r].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=n.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}}return Object.create({set:r,get:i,remove:function(t,n){r(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(o)},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:"/"})}()}(Fn),function(e){e.exports=Dn}($n);var Nn=w(qn);const Kn=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=e.hooks)||void 0===r?void 0:r[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},Wn=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},Jn=async e=>{const t=await Wn(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},Hn="undefined"!=typeof localStorage,zn=(e,t)=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),Vn=e=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),Bn=e=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),Gn="undefined"!=typeof window,Yn=Gn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Zn=(e="",t="")=>({vsid:e,vrid:t}),Xn=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Qn=e=>(e.body&&(e.body.fpData=Xn(!0)||Zn()),e),eo="dls_last_user_login_id",to="dls_last_user_display_name",no=()=>Vn(eo),oo=()=>Vn(to),ro=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,r=no(),i=oo();return r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i),await e(...t)},io=e=>async(...t)=>{const n=await e(...t);return Bn(eo),Bn(to),n};function so(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const ao="DS",lo="DSR";function co(){return Vn(lo)||""}function uo(){return Nn.get(ao)||Vn(ao)||""}function ho(){Bn(lo),Bn(ao),Nn.remove(ao)}const po=e=>Object.assign(e,{token:e.token||co()}),fo=e=>async(...t)=>{const n=await e(...t);return ho(),n};async function go(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ko(n.publicKey.challenge),n.publicKey.user.id=ko(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=ko(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Io(n.rawId),type:n.type,response:{attestationObject:Io(n.response.attestationObject),clientDataJSON:Io(n.response.clientDataJSON)}});var n}async function vo(e){const t=wo(e);return yo(await navigator.credentials.get(t))}async function mo(e,t){const n=wo(e);return n.signal=t.signal,n.mediation="conditional",yo(await navigator.credentials.get(n))}async function bo(e=!1){if(!Gn)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function wo(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ko(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=ko(e.id)})),n}function yo(e){return JSON.stringify({id:e.id,rawId:Io(e.rawId),type:e.type,response:{authenticatorData:Io(e.response.authenticatorData),clientDataJSON:Io(e.response.clientDataJSON),signature:Io(e.response.signature),userHandle:e.response.userHandle?Io(e.response.userHandle):void 0}})}function ko(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Io(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var xo,jo=(xo=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const r=await go(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await vo(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await go(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await vo(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const r=await go(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:go,get:vo,isSupported:bo,conditional:mo}}),(...e)=>{const t=xo(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),Oo=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await bo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=o,e.flow.start(...t)}});const So=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{var{fpKey:n,fpLoad:o}=t,r=u(t,["fpKey","fpLoad"]);return n?(Gn?o&&(async e=>{try{if(Xn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Rn({apiKey:e,endpoint:Yn}),o=await n,{requestId:r}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(Zn(t,r))}catch(e){global.FB_DEBUG&&console.error(e)}})(n).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(Kn(r,{beforeRequest:Qn}))):e(Object.assign({},r))}),(e=>t=>{var{autoRefresh:n}=t,o=u(t,["autoRefresh"]);if(!n)return e(o);const{clearAllTimers:r,setTimer:i}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),s=e(Kn(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Wn(t);if(401===(null==t?void 0:t.status))r();else if(o){const e=((a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;r(),i((()=>s.refresh(n)),e)}var a}}));return Cn(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.2.3"},t.baseHeaders)}))),(e=>t=>{const n=so(),o=so(),r=e(Kn(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await Jn(t);e&&o.pub(e);const{sessionJwt:r}=await Wn(t);r&&n.pub(r)}}})),i=Cn(r,["logout","logoutAll"],(e=>async(...t)=>{const r=await e(...t);return n.pub(null),o.pub(null),r}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(Kn(t,{afterRequest:async(e,t)=>{var n;const o=await Jn(t),r=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;r&&((e=>{zn(eo,e)})(r),(e=>{zn(to,e)})(i))}}));let o=Cn(n,["flow.start"],ro);return o=Cn(o,["logout","logoutAll"],io),Object.assign(o,{getLastUserLoginId:no,getLastUserDisplayName:oo})}),(e=>t=>{var{persistTokens:n,sessionTokenViaCookie:o}=t,r=u(t,["persistTokens","sessionTokenViaCookie"]);if(!n||!Gn)return n&&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"),e(r);const i=e(Kn(r,{beforeRequest:po,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?ho():((e={},t)=>{var{refreshJwt:n,sessionJwt:o}=e,r=u(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&zn(lo,n),o&&(t?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(t){const i=new Date(1e3*r);Nn.set(e,t,{path:n,domain:o,expires:i,sameSite:"Strict",secure:!0})}}(ao,o,r):zn(ao,o))})(await Wn(t),o)}})),s=Cn(i,["logout","logoutAll"],fo);return Object.assign(s,{getRefreshToken:co,getSessionToken:uo})}))(((...e)=>{const t=En(...e);return Object.assign(Object.assign({},t),{flow:Oo(t),webauthn:jo(t)})}));let Co;const Eo=e=>{const t=So({...e,persistTokens:l,autoRefresh:l});return Co=t,t};Co=Eo({projectId:"temp pid"});const Ao=()=>l?Co?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),Uo=()=>l?Co?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),_o=s(((e=Ao(),t)=>Co?.getJwtPermissions(e,t))),Po=s(((e=Ao(),t)=>Co?.getJwtRoles(e,t)));const Ro=({projectId:e,baseUrl:n,sessionTokenViaCookie:s,children:l})=>{const[c,u]=t.useState(),[d,h]=t.useState(),[p,f]=t.useState(!1),[g,v]=t.useState(!1),m=(({projectId:e,baseUrl:n,sessionTokenViaCookie:o})=>t.useMemo((()=>{if(e)return Eo({projectId:e,baseUrl:n,sessionTokenViaCookie:o,baseHeaders:a,persistToken:!0,autoRefresh:!0})}),[e,n,o]))({projectId:e,baseUrl:n,sessionTokenViaCookie:s});t.useEffect((()=>{if(m){const e=m.onSessionTokenChange(h),t=m.onUserChange(u);return()=>{e(),t()}}}),[m]);const b=t.useCallback((()=>{v(!0),i(m?.refresh)().then((()=>{v(!1)}))}),[m]),w=t.useCallback((()=>{f(!0),i(m.me)().then((()=>{f(!1)}))}),[m]),y=t.useMemo((()=>({fetchUser:w,user:c,isUserLoading:p,fetchSession:b,session:d,isSessionLoading:g,projectId:e,baseUrl:n,setUser:u,setSession:h,sdk:m})),[w,c,p,b,d,g,e,n,u,h,m]);return o.default.createElement(r.Provider,{value:y},l)};Ro.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const To=t.lazy((async()=>((await Promise.resolve().then((function(){return si}))).default.sdkConfigOverrides={baseHeaders:a},{default:({projectId:e,flowId:t,baseUrl:n,innerRef:r,tenant:i,theme:s,debug:a,telemetryKey:l,redirectUrl:c,autoFocus:u})=>o.default.createElement("descope-wc",{"project-id":e,"flow-id":t,"base-url":n,ref:r,tenant:i,theme:s,debug:a,telemetryKey:l,"redirect-url":c,"auto-focus":u})}))),Lo=o.default.forwardRef((({flowId:e,onSuccess:n,onError:i,tenant:s,theme:a,debug:l,telemetryKey:c,redirectUrl:u,autoFocus:d},h)=>{const[p,f]=t.useState(null);t.useImperativeHandle(h,(()=>p));const{projectId:g,baseUrl:v,sdk:m}=o.default.useContext(r),b=t.useCallback((async e=>{await m.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),n&&n(e)}),[n]);return t.useEffect((()=>{const e=p;return e?.addEventListener("success",b),i&&e?.addEventListener("error",i),()=>{i&&e?.removeEventListener("error",i),e?.removeEventListener("success",b)}}),[p,i,b]),o.default.createElement("form",null,o.default.createElement(t.Suspense,{fallback:null},o.default.createElement(To,{projectId:g,flowId:e,baseUrl:v,innerRef:f,tenant:s,theme:a,debug:l,telemetryKey:c,redirectUrl:u,autoFocus:d})))}));Lo.defaultProps={onError:void 0,onSuccess:void 0};var Mo=()=>{const e=t.useContext(r);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const qo=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,$o={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],$o);if("function"==typeof e[t])return()=>{throw Error(qo("function"))};throw Error(qo("attribute"))}},Do="undefined"!=typeof localStorage,Fo=Do&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",No="descope-login-flow",Ko="code",Wo="ra-challenge",Jo="ra-callback",Ho="data-exclude-field",zo="dls_last_auth",Vo="data-type",Bo="poll",Go="webauthnCreate",Yo="submit",Zo="polling";var Xo,Qo,er;function tr(e){return new URLSearchParams(window.location.search).get(e)}function nr(e){if(window.history.replaceState&&tr(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())}}function or(e,t){return d(this,void 0,void 0,(function*(){const n=yield fetch(e,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${e}`);return{body:yield n[t||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(e){e.backward="backward",e.forward="forward"}(Xo||(Xo={}));function rr(e,t){const n=new URL(Fo);return n.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(n.pathname,e,"v2-alpha",t),n.toString()}function ir(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?Xo.forward:e<t?Xo.backward:void 0}const sr=()=>{const[e="",t=""]=(tr(No)||"").split("_");return{executionId:e,stepId:t}};function ar(){nr(No)}const lr=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),cr=e=>{let t,n;return(...o)=>{return t&&(i=o,(r=t).length===i.length&&r.every(((e,t)=>e===i[t])))||(t=o,n=e(...o)),n;var r,i}},ur=null===(er=null===(Qo=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===Qo?void 0:Qo.brands)||void 0===er?void 0:er.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));var dr,hr,pr,fr;function gr(e,t){const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const r=n[o],i=e[r],s=t[r];if(null===i||null===s){if(i!==s)return!1}else if("object"==typeof i&&"object"==typeof s){if(!gr(i,s))return!1}else if(i!==s)return!1}return!0}class vr{constructor(e={},{updateOnlyOnChange:t=!0}={}){dr.set(this,void 0),hr.set(this,{}),pr.set(this,0),fr.set(this,!1),this.update=e=>{const t="function"==typeof e?e(h(this,dr,"f")):e,n=Object.assign(Object.assign({},h(this,dr,"f")),t);if(!h(this,fr,"f")||!gr(h(this,dr,"f"),n)){const e=h(this,dr,"f");p(this,dr,n,"f"),Object.freeze(h(this,dr,"f")),setTimeout((()=>{Object.values(h(this,hr,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},p(this,dr,e,"f"),p(this,fr,t,"f")}get current(){return Object.assign({},h(this,dr,"f"))}subscribe(e){return p(this,pr,h(this,pr,"f")+1,"f"),h(this,hr,"f")[h(this,pr,"f")]=e,h(this,pr,"f").toString()}unsubscribe(e){const t=!!h(this,hr,"f")[e];return t&&delete h(this,hr,"f")[e],t}unsubscribeAll(){return p(this,hr,{},"f"),!0}}dr=new WeakMap,hr=new WeakMap,pr=new WeakMap,fr=new WeakMap;const mr=cr((()=>d(void 0,void 0,void 0,(function*(){var e,t;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const n=Promise.all([null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isConditionalMediationAvailable(),null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isUserVerifyingPlatformAuthenticatorAvailable()]).then((e=>e.every((e=>!!e)))),o=108;return yield Promise.race([n,(100,new Promise(((e,t)=>{setTimeout((()=>{t(new Error("Promise timed out after 100 ms"))}),100)}))).catch((()=>ur()>=o))])}catch(e){return console.warn("webauthn","Conditional login check failed",e),!1}})))),br={"lastAuth.loginId":{"not-empty":e=>!!e.loginId,empty:e=>!e.loginId},idpInitiated:{"is-true":e=>!!e.code,"is-false":e=>!e.code}},wr=document.createElement("template");var yr,kr,Ir,xr,jr,Or,Sr,Cr,Er,Ar,Ur,_r,Pr,Rr,Tr,Lr,Mr,qr,$r,Dr,Fr,Nr,Kr,Wr,Jr,Hr,zr,Vr,Br,Gr,Yr,Zr,Xr,Qr,ei,ti,ni,oi;wr.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 ri extends HTMLElement{constructor(e){super(),yr.add(this),kr.set(this,!1),Ir.set(this,new vr),xr.set(this,new vr),this.nextRequestStatus=new vr({isLoading:!1}),jr.set(this,void 0),Or.set(this,{popstate:h(this,yr,"m",_r).bind(this)}),Sr.set(this,void 0),Tr.set(this,cr((()=>d(this,void 0,void 0,(function*(){const e=rr(this.projectId,"config.json");try{const{body:t,headers:n}=yield or(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),this.logger={error:(e,t="")=>{console.error(e,t,new Error),h(this,yr,"m",Nr).call(this,e,t)},info:(e,t="")=>{console.log(e,t)}},p(this,Sr,e,"f"),h(this,yr,"m",Cr).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 e,t;const n=this.getAttribute("theme");return"os"===n?window.matchMedia&&(null===(t=null===(e=window.matchMedia)||void 0===e?void 0:e.call(window,"(prefers-color-scheme: dark)"))||void 0===t?void 0:t.matches)?"dark":"light":n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}getExecutionContext(){return d(this,void 0,void 0,(function*(){const{executionContext:e}=yield h(this,Tr,"f").call(this);return e}))}getFlowConfig(){var e,t;return d(this,void 0,void 0,(function*(){const{projectConfig:n}=yield h(this,Tr,"f").call(this),o=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}connectedCallback(){return d(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(h(this,yr,"m",Er).call(this))return void h(this,yr,"m",Ar).call(this);h(this,yr,"m",Ur).call(this),h(this,yr,"m",Mr).call(this),h(this,yr,"m",Lr).call(this),h(this,yr,"m",Kr).call(this);const{executionId:e,stepId:t,token:n,code:o,exchangeError:r,redirectAuthCallbackUrl:i,redirectAuthCodeChallenge:s}=(()=>{const{executionId:e,stepId:t}=sr();(e||t)&&ar();const n=tr("t")||void 0;n&&nr("t");const o=tr(Ko)||void 0;o&&nr(Ko);const r=tr("err")||void 0;r&&nr("err");const{redirectAuthCodeChallenge:i,redirectAuthCallbackUrl:s}={redirectAuthCodeChallenge:tr(Wo),redirectAuthCallbackUrl:tr(Jo)};return(i||s)&&(nr(Wo),nr(Jo)),{executionId:e,stepId:t,token:n,code:o,exchangeError:r,redirectAuthCodeChallenge:i,redirectAuthCallbackUrl:s}})();window.addEventListener("popstate",h(this,Or,"f").popstate),h(this,Ir,"f").subscribe(h(this,yr,"m",Rr).bind(this)),h(this,xr,"f").subscribe(h(this,yr,"m",Fr).bind(this)),h(this,Ir,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:t,executionId:e,token:n,code:o,exchangeError:r,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:i,redirectAuthCodeChallenge:s}),h(this,xr,"f").update({isDebug:this.debug}),p(this,kr,!0,"f")}}))}disconnectedCallback(){h(this,Ir,"f").unsubscribeAll(),h(this,xr,"f").unsubscribeAll(),h(this,yr,"m",Dr).call(this),window.removeEventListener("popstate",h(this,Or,"f").popstate)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&h(this,kr,"f")&&t!==n&&ri.observedAttributes.includes(e)){h(this,yr,"m",Ur).call(this);const o=null===t;h(this,Ir,"f").update((({stepId:t,executionId:r})=>{let i=t,s=r;return o||(s=null,i=null,ar()),{[lr(e)]:n,stepId:i,executionId:s}})),h(this,xr,"f").update({isDebug:this.debug})}}}kr=new WeakMap,Ir=new WeakMap,xr=new WeakMap,jr=new WeakMap,Or=new WeakMap,Sr=new WeakMap,Tr=new WeakMap,yr=new WeakSet,Cr=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(wr.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Er=function(){const e=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&e},Ar=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},Ur=function(){const e=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(ri.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[lr(t)])throw Error(`${t} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},_r=function(){const{stepId:e,executionId:t}=sr();h(this,Ir,"f").update({stepId:e,executionId:t})},Pr=function(e,t,n){const o=n||void 0,r=!!o;this.sdk=So(Object.assign(Object.assign({persistTokens:!0},ri.sdkConfigOverrides),{projectId:e,baseUrl:t,fpKey:o,fpLoad:r})),["start","next"].forEach((e=>{const t=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>d(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield t(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Rr=function(e,t,n){return d(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:r}=e;if(n("projectId")||n("baseUrl")||n("telemetryKey")){if(!t)return;h(this,yr,"m",Pr).call(this,t,o,r)}h(this,Sr,"f").call(this,e)}))},Lr=function(){var e,t,n,o;return d(this,void 0,void 0,(function*(){const{projectConfig:r}=yield h(this,Tr,"f").call(this);null===(o=null===(n=null===(t=null===(e=null==r?void 0:r.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===t?void 0:t.typography)||void 0===n?void 0:n.fontFamilies)||void 0===o||o.forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},Mr=function(){h(this,yr,"m",qr).call(this),h(this,yr,"m",$r).call(this)},qr=function(){return d(this,void 0,void 0,(function*(){const e=document.createElement("style"),t=rr(this.projectId,"theme.css");try{const{body:n}=yield or(t,"text");e.innerText=n}catch(e){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(e)}))},$r=function(){this.rootElement.setAttribute("data-theme",this.theme)},Dr=function(){var e;null===(e=h(this,jr,"f"))||void 0===e||e.remove(),p(this,jr,null,"f")},Fr=function({isDebug:e}){return d(this,void 0,void 0,(function*(){e?(yield Promise.resolve().then((function(){return yi})),p(this,jr,document.createElement("descope-debugger"),"f"),Object.assign(h(this,jr,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(h(this,jr,"f"))):h(this,yr,"m",Dr).call(this)}))},Nr=function(e,t){var n;e&&this.debug&&(null===(n=h(this,jr,"f"))||void 0===n||n.updateData({title:e,description:t}))},Kr=function(){this.rootElement.onkeydown=e=>{if("Enter"!==e.key)return;e.preventDefault();const t=this.rootElement.querySelectorAll("button");if(1===t.length)return void t[0].click();const n=Array.from(t).filter((e=>"button"===e.getAttribute("data-type")));1===n.length&&n[0].click()}},ri.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.3.4"}};class ii extends ri{constructor(){const e=new vr;super(e.update.bind(e)),Wr.add(this),this.stepState=new vr({},{updateOnlyOnChange:!1}),Jr.set(this,void 0),Hr.set(this,null),zr.set(this,(()=>{clearInterval(h(this,Jr,"f")),p(this,Jr,null,"f")})),Vr.set(this,(e=>{var t,n,o,r,i,s,a,l,c;if(!(null==e?void 0:e.ok)){h(this,zr,"f").call(this),h(this,Wr,"m",oi).call(this,"error",null==e?void 0:e.error);const s=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,a=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(o=null==e?void 0:e.response)||void 0===o?void 0:o.statusText}`;return void this.logger.error((null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorDescription)||s,(null===(i=null==e?void 0:e.error)||void 0===i?void 0:i.errorMessage)||a)}const u=null===(l=null===(a=null===(s=e.data)||void 0===s?void 0:s.screen)||void 0===a?void 0:a.state)||void 0===l?void 0:l.errorText;u&&this.logger.error(u),(null===(c=e.data)||void 0===c?void 0:c.error)&&this.logger.error(`[${e.data.error.code}]: ${e.data.error.description}`,e.data.error.message);const{status:d,authInfo:p,lastAuth:f}=e.data;if("completed"===d)return function(e){(null==e?void 0:e.authMethod)&&Do&&localStorage.setItem(zo,JSON.stringify(e))}(f),h(this,zr,"f").call(this),void h(this,Wr,"m",oi).call(this,"success",p);const{executionId:g,stepId:v,action:m,screen:b,redirect:w,webauthn:y}=e.data;m!==Bo?this.flowState.update({stepId:v,executionId:g,action:m,redirectTo:null==w?void 0:w.url,screenId:null==b?void 0:b.id,screenState:null==b?void 0:b.state,webauthnTransactionId:null==y?void 0:y.transactionId,webauthnOptions:null==y?void 0:y.options}):this.flowState.update({action:m})})),Br.set(this,cr((()=>d(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.logger.error("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.logger.error("Webauthn start failed",e.message)}}))))),this.flowState=e}static set sdkConfigOverrides(e){ri.sdkConfigOverrides=e}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var t,n;return d(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.subscribe(this.onFlowChange.bind(this)),null===(n=this.stepState)||void 0===n||n.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(e,t,n){var o,r;return d(this,void 0,void 0,(function*(){const{projectId:i,flowId:s,tenant:a,stepId:l,executionId:c,action:u,screenId:f,screenState:g,redirectTo:v,redirectUrl:m,token:b,code:w,exchangeError:y,webauthnTransactionId:k,webauthnOptions:I,redirectAuthCodeChallenge:x,redirectAuthCallbackUrl:j}=e;let O,S;h(this,Jr,"f")&&h(this,zr,"f").call(this);const C=this.sdk.getLastUserLoginId(),E=yield this.getFlowConfig(),A=j&&x?{callbackUrl:j,codeChallenge:x}:void 0;if(!c&&(E.conditions?({startScreenId:O,conditionInteractionId:S}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n})=>{var o;if("ELSE"===t)return!0;const r=null===(o=br[t])||void 0===o?void 0:o[n];return!!(null==r?void 0:r(e))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:C,code:w},E.conditions)):E.condition?({startScreenId:O,conditionInteractionId:S}=((e,t)=>{var n;const o=null===(n=br[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const r=o(t)?e.met:e.unmet;return{startScreenId:null==r?void 0:r.screenId,conditionInteractionId:null==r?void 0:r.interactionId}})(E.condition,{loginId:C,code:w})):O=E.startScreenId,!O)){const e=w?{exchangeCode:w,idpInitiated:!0}:void 0,t=yield this.sdk.flow.start(s,Object.assign({tenant:a,redirectAuth:A},m&&{redirectUrl:m}),S,"",e,E.version);return h(this,Vr,"f").call(this,t),void("completed"!==(null===(o=null==t?void 0:t.data)||void 0===o?void 0:o.status)&&this.flowState.update({code:void 0}))}if(c&&(n("token")&&b||n("code")&&w||n("exchangeError")&&y)){const e=yield this.sdk.flow.next(c,l,Yo,{token:b,exchangeCode:w,exchangeError:y},E.version);return h(this,Vr,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if("redirect"===u)return v||this.logger.error("Did not get redirect url"),void window.location.assign(v);if(u===Go||"webauthnGet"===u){if(!k||!I)return void this.logger.error("Did not get webauthn transaction id or options");let e,t;null===(r=h(this,Hr,"f"))||void 0===r||r.abort(),p(this,Hr,null,"f");try{e=u===Go?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(e){if("NotAllowedError"!==e.name)return void this.logger.error(e.message);t=!0}const n=yield this.sdk.flow.next(c,l,Yo,{transactionId:k,response:e,cancelWebauthn:t},E.version);h(this,Vr,"f").call(this,n)}if(u===Bo&&p(this,Jr,setInterval((()=>d(this,void 0,void 0,(function*(){const e=yield this.sdk.flow.next(c,l,Zo,{},E.version);h(this,Vr,"f").call(this,e)}))),2e3),"f"),!f&&!O)return void this.logger.info("Refreshing the page during a flow is not supported yet");const U={direction:ir(+l,+t.stepId),screenState:Object.assign(Object.assign({},g),{lastAuth:{loginId:C,name:this.sdk.getLastUserDisplayName()||C}}),htmlUrl:rr(i,`${O||f}.html`)},_=function(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(zo)))}catch(e){}return t}(C);O?U.next=(e,t)=>this.sdk.flow.start(s,Object.assign({tenant:a,redirectAuth:A,lastAuth:_},m&&{redirectUrl:m}),S,e,Object.assign(Object.assign({},t),w&&{exchangeCode:w,idpInitiated:!0}),E.version):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(U.next=(...e)=>this.sdk.flow.next(c,l,...e)),this.stepState.update(U)}))}onStepChange(e,t){var n;return d(this,void 0,void 0,(function*(){const{htmlUrl:o,direction:r,next:i,screenState:s}=e,a=document.createElement("template"),{body:l}=yield or(o,"text");a.innerHTML=l;const c=a.content.cloneNode(!0),u=((e,t)=>{var n;const o=Array.from(e.querySelectorAll("script[data-id]")).map((n=>{var o;const r=n.getAttribute("data-id"),i=null===(o=e.getElementById(r))||void 0===o?void 0:o.innerHTML,s=Function(i).bind(n.previousSibling,t);return n.remove(),s}));return null===(n=e.querySelector("scripts"))||void 0===n||n.remove(),o})(c,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield h(this,Wr,"m",Yr).call(this,c,i):c.querySelectorAll(`button[${Vo}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),((e,t)=>{var n;((e,t,n="")=>{e.querySelectorAll(`[${Vo}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",null==t?void 0:t.errorText),((e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`.descope-input[name="${t}"]:not([${Ho}])`)).forEach((e=>{e.value=n}))}))})(e,null==t?void 0:t.inputs),((e,t)=>{e.querySelectorAll(`[${Vo}="totp-link"]`).forEach((e=>{e.href=t}))})(e,null===(n=null==t?void 0:t.totp)||void 0===n?void 0:n.provisionUrl),((e,t)=>{e.querySelectorAll(".descope-text,.descope-link").forEach((e=>{e.textContent=((e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})))(e.textContent,t)}))})(e,t)})(c,s),((e,t)=>{var n;t&&(null===(n=null==e?void 0:e.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${t})`))})(c.querySelector("div"),null===(n=null==s?void 0:s.totp)||void 0===n?void 0:n.image);const p=()=>d(this,void 0,void 0,(function*(){try{u.forEach((e=>{e()}))}catch(e){this.logger.error(e.message)}this.rootElement.replaceChildren(c);const e=!t.htmlUrl;if(((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector('input:not([aria-hidden="true"])');null==t||t.focus()}})(this.rootElement,this.autoFocus,e),h(this,Wr,"m",ti).call(this,i),h(this,Wr,"m",oi).call(this,"page-updated",{}),this.rootElement.querySelector(`[${Vo}="polling"]`)){const e=yield i(Zo,{});h(this,Vr,"f").call(this,e)}}));r?h(this,Wr,"m",ni).call(this,p,r):p()}))}}Jr=new WeakMap,Hr=new WeakMap,zr=new WeakMap,Vr=new WeakMap,Br=new WeakMap,Wr=new WeakSet,Gr=function(e){const t=e.name;if(!["email"].includes(t)){const n=`user-${t}`;e.name=n,e.addEventListener("input",(()=>{e.name=e.value?t:n}))}},Yr=function(e,t){var n;return d(this,void 0,void 0,(function*(){null===(n=h(this,Hr,"f"))||void 0===n||n.abort();const o=e.querySelector('input[autocomplete="webauthn"]');if(o&&(yield mr())){const{options:e,transactionId:n}=(yield h(this,Br,"f").call(this))||{};e&&n&&(h(this,Wr,"m",Gr).call(this,o),p(this,Hr,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(e,h(this,Hr,"f")).then((e=>d(this,void 0,void 0,(function*(){const r=yield t(o.id,{transactionId:n,response:e});h(this,Vr,"f").call(this,r)})))).catch((e=>{"AbortError"!==e.name&&this.logger.error("Conditional login failed",e.message)})))}}))},Zr=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((e=>(e.reportValidity(),e.checkValidity())))},Xr=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${Ho}])`)).reduce(((e,t)=>t.name?Object.assign(e,{[t.name]:t["checkbox"===t.type?"checked":"value"]}):e),{})},Qr=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,r;n?null===(o=null==e?void 0:e.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(t),null===(r=null==e?void 0:e.classList)||void 0===r||r.remove("loading"))}))},ei=function(e,t){return d(this,void 0,void 0,(function*(){if(e.formNoValidate||h(this,Wr,"m",Zr).call(this)){const o=null==e?void 0:e.getAttribute("id");h(this,Wr,"m",Qr).call(this,e);const r=h(this,Wr,"m",Xr).call(this),i=(n=e,Array.from((null==n?void 0:n.attributes)||[]).reduce(((e,t)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),s=Object.assign(Object.assign(Object.assign({},i),r),{origin:window.location.origin}),a=yield t(o,s);h(this,Vr,"f").call(this,a)}var n}))},ti=function(e){this.rootElement.querySelectorAll("button").forEach((t=>{t.onclick=()=>{h(this,Wr,"m",ei).call(this,t,e)}}))},ni=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===Xo.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),this.rootElement.classList.add("fade-out")},oi=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",ii);var si=Object.freeze({__proto__:null,default:ii});const ai=(e,t,n,o={})=>{var r,i,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(r=o.left)&&void 0!==r?r:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(i=o.right)&&void 0!==i?i:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]};var li,ci,ui,di,hi,pi,fi,gi,vi,mi;const bi=document.createElement("template");bi.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class wi extends HTMLElement{constructor(){super(),li.add(this),ci.set(this,new vr({messages:[]})),ui.set(this,void 0),di.set(this,void 0),hi.set(this,void 0),pi.set(this,{resize:h(this,li,"m",mi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(bi.content.cloneNode(!0)),p(this,ui,this.shadowRoot.querySelector(".debugger"),"f"),p(this,di,h(this,ui,"f").querySelector(".content"),"f"),p(this,hi,h(this,ui,"f").querySelector(".header"),"f")}updateData(e){h(this,ci,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,r=0,i=0,s=0;function a(t){t.preventDefault(),o=i-t.clientX,r=s-t.clientY,i=t.clientX,s=t.clientY;const[a,l]=ai(e,e.offsetLeft-o,e.offsetTop-r,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),i=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(h(this,ui,"f"),h(this,hi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",h(this,pi,"f").resize),(e=h(this,ui,"f")).onmousemove=t=>{(t.target.w&&t.target.w!==t.target.offsetWidth||t.target.h&&t.target.h!==t.target.offsetHeight)&&e.onresize(t),t.target.w=t.target.offsetWidth,t.target.h=t.target.offsetHeight},h(this,ui,"f").onresize=h(this,li,"m",vi).bind(this),h(this,ci,"f").subscribe(h(this,li,"m",fi).bind(this))}disconnectedCallback(){h(this,ci,"f").unsubscribeAll(),window.removeEventListener("resize",h(this,pi,"f").resize)}}ci=new WeakMap,ui=new WeakMap,di=new WeakMap,hi=new WeakMap,pi=new WeakMap,li=new WeakSet,fi=function(e){h(this,li,"m",gi).call(this,e),h(this,li,"m",vi).call(this)},gi=function(e){h(this,di,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},vi=function(){h(this,di,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},mi=function(){const[e,t]=ai(h(this,ui,"f"),Number.parseInt(h(this,ui,"f").style.left,10),Number.parseInt(h(this,ui,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});h(this,ui,"f").style.top=`${t}px`,h(this,ui,"f").style.left=`${e}px`},customElements.define("descope-debugger",wi);var yi=Object.freeze({__proto__:null,default:wi});e.AuthProvider=Ro,e.Descope=Lo,e.SignInFlow=e=>o.default.createElement(Lo,{...e,flowId:"sign-in"}),e.SignUpFlow=e=>o.default.createElement(Lo,{...e,flowId:"sign-up"}),e.SignUpOrInFlow=e=>o.default.createElement(Lo,{...e,flowId:"sign-up-or-in"}),e.getJwtPermissions=_o,e.getJwtRoles=Po,e.getRefreshToken=Uo,e.getSessionToken=Ao,e.refresh=(e=Uo())=>Co?.refresh(e),e.useDescope=()=>{const{sdk:e}=Mo();return t.useMemo((()=>e||new Proxy(Eo({projectId:"dummy"}),$o)),[e])},e.useSession=()=>{const{session:e,isSessionLoading:n,fetchSession:o}=Mo(),r=t.useRef(n);return t.useMemo((()=>{r.current=n}),[n]),t.useMemo((()=>{e||n||(r.current=!0)}),[o]),t.useEffect((()=>{e||n||o()}),[o]),{isSessionLoading:r.current,sessionToken:e,isAuthenticated:!!e}},e.useUser=()=>{const{user:e,fetchUser:n,isUserLoading:o,session:r}=Mo(),[i,s]=t.useState(!1),a=t.useRef(o),l=t.useMemo((()=>!e&&!o&&r&&!i),[n,r,i]);return t.useMemo((()=>{a.current=o}),[o]),t.useMemo((()=>{l&&(a.current=!0)}),[l]),t.useEffect((()=>{l&&(s(!0),n())}),[l]),{isUserLoading:a.current,user:e}},Object.defineProperty(e,"__esModule",{value:!0})}));
3
+ !function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}function t(n,o){function i(t,i,r){if("undefined"!=typeof document){"number"==typeof(r=e({},o,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in r)r[a]&&(s+="; "+a,!0!==r[a]&&(s+="="+r[a].split(";")[0]));return document.cookie=t+"="+n.write(i,t)+s}}function r(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},i=0;i<t.length;i++){var r=t[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=n.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}}return Object.create({set:i,get:r,remove:function(t,n){i(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(o)},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:"/"})}()}(Jn),function(e){e.exports=$n}(Dn);var Nn=w(Mn);const Kn=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},Fn=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},Hn=async e=>{const t=await Fn(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},Wn="undefined"!=typeof localStorage,zn=(e,t)=>Wn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),Vn=e=>Wn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),Bn=e=>Wn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),Gn="undefined"!=typeof window,Zn=Gn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Yn=(e="",t="")=>({vsid:e,vrid:t}),Xn=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Qn=e=>(e.body&&(e.body.fpData=Xn(!0)||Yn()),e),eo="dls_last_user_login_id",to="dls_last_user_display_name",no=()=>Vn(eo),oo=()=>Vn(to),io=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=no(),r=oo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},ro=e=>async(...t)=>{const n=await e(...t);return Bn(eo),Bn(to),n};function so(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const ao="DS",lo="DSR";function co(){return Vn(lo)||""}function uo(){return Nn.get(ao)||Vn(ao)||""}function ho(){Bn(lo),Bn(ao),Nn.remove(ao)}const po=e=>Object.assign(e,{token:e.token||co()}),fo=e=>async(...t)=>{const n=await e(...t);return ho(),n};async function go(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ko(n.publicKey.challenge),n.publicKey.user.id=ko(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=ko(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Io(n.rawId),type:n.type,response:{attestationObject:Io(n.response.attestationObject),clientDataJSON:Io(n.response.clientDataJSON)}});var n}async function vo(e){const t=wo(e);return yo(await navigator.credentials.get(t))}async function bo(e,t){const n=wo(e);return n.signal=t.signal,n.mediation="conditional",yo(await navigator.credentials.get(n))}async function mo(e=!1){if(!Gn)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function wo(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ko(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=ko(e.id)})),n}function yo(e){return JSON.stringify({id:e.id,rawId:Io(e.rawId),type:e.type,response:{authenticatorData:Io(e.response.authenticatorData),clientDataJSON:Io(e.response.clientDataJSON),signature:Io(e.response.signature),userHandle:e.response.userHandle?Io(e.response.userHandle):void 0}})}function ko(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Io(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Oo,jo=(Oo=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const i=await go(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await vo(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await go(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await vo(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const i=await go(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:go,get:vo,isSupported:mo,conditional:bo}}),(...e)=>{const t=Oo(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),So=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await mo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=o,e.flow.start(...t)}});const xo=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{var{fpKey:n,fpLoad:o}=t,i=u(t,["fpKey","fpLoad"]);return n?(Gn?o&&(async e=>{try{if(Xn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=_n({apiKey:e,endpoint:Zn}),o=await n,{requestId:i}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(Yn(t,i))}catch(e){global.FB_DEBUG&&console.error(e)}})(n).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(Kn(i,{beforeRequest:Qn}))):e(Object.assign({},i))}),(e=>t=>{var{autoRefresh:n}=t,o=u(t,["autoRefresh"]);if(!n)return e(o);const{clearAllTimers:i,setTimer:r}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),s=e(Kn(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Fn(t);if(401===(null==t?void 0:t.status))i();else if(o){const e=((a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;i(),r((()=>s.refresh(n)),e)}var a}}));return Cn(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.2.3"},t.baseHeaders)}))),(e=>t=>{const n=so(),o=so(),i=e(Kn(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await Hn(t);e&&o.pub(e);const{sessionJwt:i}=await Fn(t);i&&n.pub(i)}}})),r=Cn(i,["logout","logoutAll"],(e=>async(...t)=>{const i=await e(...t);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(Kn(t,{afterRequest:async(e,t)=>{var n;const o=await Hn(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{zn(eo,e)})(i),(e=>{zn(to,e)})(r))}}));let o=Cn(n,["flow.start"],io);return o=Cn(o,["logout","logoutAll"],ro),Object.assign(o,{getLastUserLoginId:no,getLastUserDisplayName:oo})}),(e=>t=>{var{persistTokens:n,sessionTokenViaCookie:o}=t,i=u(t,["persistTokens","sessionTokenViaCookie"]);if(!n||!Gn)return n&&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"),e(i);const r=e(Kn(i,{beforeRequest:po,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?ho():((e={},t)=>{var{refreshJwt:n,sessionJwt:o}=e,i=u(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&zn(lo,n),o&&(t?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i);Nn.set(e,t,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(ao,o,i):zn(ao,o))})(await Fn(t),o)}})),s=Cn(r,["logout","logoutAll"],fo);return Object.assign(s,{getRefreshToken:co,getSessionToken:uo})}))(((...e)=>{const t=Un(...e);return Object.assign(Object.assign({},t),{flow:So(t),webauthn:jo(t)})}));let Co;const Uo=e=>{const t=xo({...e,persistTokens:l,autoRefresh:l});return Co=t,t};Co=Uo({projectId:"temp pid"});const Eo=()=>l?Co?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),Ao=()=>l?Co?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),Po=s(((e=Eo(),t)=>Co?.getJwtPermissions(e,t))),Ro=s(((e=Eo(),t)=>Co?.getJwtRoles(e,t)));const _o=({projectId:e,baseUrl:n,sessionTokenViaCookie:s,children:l})=>{const[c,u]=t.useState(),[d,h]=t.useState(),[p,f]=t.useState(!1),[g,v]=t.useState(!1),b=(({projectId:e,baseUrl:n,sessionTokenViaCookie:o})=>t.useMemo((()=>{if(e)return Uo({projectId:e,baseUrl:n,sessionTokenViaCookie:o,baseHeaders:a,persistToken:!0,autoRefresh:!0})}),[e,n,o]))({projectId:e,baseUrl:n,sessionTokenViaCookie:s});t.useEffect((()=>{if(b){const e=b.onSessionTokenChange(h),t=b.onUserChange(u);return()=>{e(),t()}}}),[b]);const m=t.useCallback((()=>{v(!0),r(b?.refresh)().then((()=>{v(!1)}))}),[b]),w=t.useCallback((()=>{f(!0),r(b.me)().then((()=>{f(!1)}))}),[b]),y=t.useMemo((()=>({fetchUser:w,user:c,isUserLoading:p,fetchSession:m,session:d,isSessionLoading:g,projectId:e,baseUrl:n,setUser:u,setSession:h,sdk:b})),[w,c,p,m,d,g,e,n,u,h,b]);return o.default.createElement(i.Provider,{value:y},l)};_o.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const To=t.lazy((async()=>((await Promise.resolve().then((function(){return ul}))).default.sdkConfigOverrides={baseHeaders:a},{default:({projectId:e,flowId:t,baseUrl:n,innerRef:i,tenant:r,theme:s,debug:a,telemetryKey:l,redirectUrl:c,autoFocus:u})=>o.default.createElement("descope-wc",{"project-id":e,"flow-id":t,"base-url":n,ref:i,tenant:r,theme:s,debug:a,telemetryKey:l,"redirect-url":c,"auto-focus":u})}))),qo=o.default.forwardRef((({flowId:e,onSuccess:n,onError:r,tenant:s,theme:a,debug:l,telemetryKey:c,redirectUrl:u,autoFocus:d},h)=>{const[p,f]=t.useState(null);t.useImperativeHandle(h,(()=>p));const{projectId:g,baseUrl:v,sdk:b}=o.default.useContext(i),m=t.useCallback((async e=>{await b.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),n&&n(e)}),[n]);return t.useEffect((()=>{const e=p;return e?.addEventListener("success",m),r&&e?.addEventListener("error",r),()=>{r&&e?.removeEventListener("error",r),e?.removeEventListener("success",m)}}),[p,r,m]),o.default.createElement("form",null,o.default.createElement(t.Suspense,{fallback:null},o.default.createElement(To,{projectId:g,flowId:e,baseUrl:v,innerRef:f,tenant:s,theme:a,debug:l,telemetryKey:c,redirectUrl:u,autoFocus:d})))}));qo.defaultProps={onError:void 0,onSuccess:void 0};var Lo=()=>{const e=t.useContext(i);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const Mo=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,Do={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],Do);if("function"==typeof e[t])return()=>{throw Error(Mo("function"))};throw Error(Mo("attribute"))}};var $o="/v1/auth/accesskey/exchange",Jo="/v1/auth/otp/verify",No="/v1/auth/otp/signin",Ko="/v1/auth/otp/signup",Fo={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Ho="/v1/auth/otp/signup-in",Wo="/v1/auth/magiclink/verify",zo="/v1/auth/magiclink/signin",Vo="/v1/auth/magiclink/signup",Bo={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Go="/v1/auth/magiclink/signup-in",Zo="/v1/auth/enchantedlink/verify",Yo="/v1/auth/enchantedlink/signin",Xo="/v1/auth/enchantedlink/signup",Qo="/v1/auth/enchantedlink/pending-session",ei={email:"/v1/auth/enchantedlink/update/email"},ti="/v1/auth/enchantedlink/signup-in",ni="/v1/auth/oauth/authorize",oi="/v1/auth/oauth/exchange",ii="/v1/auth/saml/authorize",ri="/v1/auth/saml/exchange",si="/v1/auth/totp/verify",ai="/v1/auth/totp/signup",li="/v1/auth/totp/update",ci={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ui={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},di={start:"/v1/auth/webauthn/signup-in/start"},hi={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},pi="/v1/auth/password/signup",fi="/v1/auth/password/signin",gi="/v1/auth/password/reset",vi="/v1/auth/password/update",bi="/v1/auth/password/replace",mi="/v1/auth/password/policy",wi="/v1/auth/refresh",yi="/v1/auth/logout",ki="/v1/auth/logoutall",Ii="/v1/auth/me",Oi="/v1/flow/start",ji="/v1/flow/next";const Si=6e5,xi=()=>{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")}};var Ci;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ci||(Ci={}));const Ui=(...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,o])=>(e[n]=o,e)),e),e}),{})),Ei=e=>void 0===e?void 0:JSON.stringify(e),Ai=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Pi=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.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"),e?async(...t)=>{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");e.log((e=>xi().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return xi().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).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:e,baseUrl:t,queryParams:n})=>{const o=new URL(e,t);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:e,queryParams:d}),{headers:Ui(Ai(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.6"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Ei(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:Ci.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ci.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:Ci.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:Ci.delete,token:o}),hooks:i}};var Ri=429;function _i(e,t,n){var o;let i=Ti(e);t&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[t]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function Ti(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return b(e)}function qi(e){const{exp:t}=Ti(e);return(new Date).getTime()/1e3>t}function Li(e,t){return _i(e,t,"permissions")}function Mi(e,t){return _i(e,t,"roles")}const Di=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function $i(e,t){var n;const o=await e,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=t?t(r):r:(i.error=r,o.status===Ri&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Ji=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Ni=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ki=e=>t=>e.test(t),Fi=Ki(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Hi=Ki(/^\+[1-9]{1}[0-9]{3,14}$/),Wi=Ji(Fi,'"{val}" is not a valid email'),zi=Ji(Hi,'"{val}" is not a valid phone number'),Vi=Ji((1,e=>e.length>=1),"Minimum length is 1");const Bi=Ji((e=>"string"==typeof e),"Input is not a string"),Gi=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ni(...e).validate(n[t]))),t(...n)),Zi=e=>[Bi(`"${e}" must be a string`),Vi(`"${e}" must not be empty`)],Yi=e=>[Bi(`"${e}" must be a string`),Wi()],Xi=e=>[Bi(`"${e}" must be a string`),zi()],Qi=Gi(Zi("accessKey")),er=e=>({exchange:Qi((t=>$i(e.post($o,{},{token:t}))))});var tr,nr;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(tr||(tr={})),function(e){e.email="email"}(nr||(nr={}));const or=Object.assign(Object.assign({},tr),nr);var ir;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ir||(ir={}));const rr=Zi("loginId"),sr=Gi(Zi("token")),ar=Gi(rr),lr=Gi(Zi("pendingRef")),cr=Gi(rr,Yi("email")),ur=e=>({verify:sr((t=>$i(e.post(Zo,{token:t})))),signIn:ar(((t,n,o,i)=>$i(e.post(Di(Yo,or.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:ar(((t,n)=>$i(e.post(Di(ti,or.email),{loginId:t,URI:n})))),signUp:ar(((t,n,o)=>$i(e.post(Di(Xo,or.email),{loginId:t,URI:n,user:o})))),waitForSession:lr(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||Si,Si)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(Qo,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o($i(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:cr(((t,n,o,i,r)=>$i(e.post(ei.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),dr=Gi(Zi("flowId")),hr=Gi(Zi("executionId"),Zi("stepId"),Zi("interactionId")),pr=e=>({start:dr(((t,n,o,i,r,s)=>$i(e.post(Oi,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,input:r,version:s})))),next:hr(((t,n,o,i,r)=>$i(e.post(ji,{executionId:t,stepId:n,interactionId:o,input:i,version:r}))))}),fr=Zi("loginId"),gr=Gi(Zi("token")),vr=Gi(fr),br=Gi(fr,Xi("phone")),mr=Gi(fr,Yi("email")),wr=e=>({verify:gr((t=>$i(e.post(Wo,{token:t})))),signIn:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vr(((t,o,i,r)=>$i(e.post(Di(zo,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vr(((t,o,i)=>$i(e.post(Di(Vo,n),{loginId:t,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vr(((t,o)=>$i(e.post(Di(Go,n),{loginId:t,URI:o}))))})),{}),update:{email:mr(((t,n,o,i,r)=>$i(e.post(Bo.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys(tr).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:br(((t,o,i,r,s)=>$i(e.post(Di(Bo.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var yr;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin"}(yr||(yr={}));const kr=Gi(Zi("code")),Ir=e=>({start:Object.keys(yr).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>$i(e.post(ni,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{}),exchange:kr((t=>$i(e.post(oi,{code:t}))))}),Or=Zi("loginId"),jr=Gi(Or,Zi("code")),Sr=Gi(Or),xr=Gi(Or,Xi("phone")),Cr=Gi(Or,Yi("email")),Ur=e=>({verify:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:jr(((t,o)=>$i(e.post(Di(Jo,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Sr(((t,o,i)=>$i(e.post(Di(No,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Sr(((t,o)=>$i(e.post(Di(Ko,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(or).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Sr((t=>$i(e.post(Di(Ho,n),{loginId:t}))))})),{}),update:{email:Cr(((t,n,o,i)=>$i(e.post(Fo.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(tr).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xr(((t,o,i,r)=>$i(e.post(Di(Fo.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),Er=Gi(Zi("tenant")),Ar=Gi(Zi("code")),Pr=e=>({start:Er(((t,n,o,i)=>$i(e.post(ii,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:Ar((t=>$i(e.post(ri,{code:t}))))}),Rr=Zi("loginId"),_r=Gi(Rr,Zi("code")),Tr=Gi(Rr),qr=Gi(Rr),Lr=e=>({signUp:Tr(((t,n)=>$i(e.post(ai,{loginId:t,user:n})))),verify:_r(((t,n,o,i)=>$i(e.post(si,{loginId:t,code:n,loginOptions:o},{token:i})))),update:qr(((t,n)=>$i(e.post(li,{loginId:t},{token:n}))))}),Mr=Zi("loginId"),Dr=Zi("newPassword"),$r=Gi(Mr,Zi("password")),Jr=Gi(Mr),Nr=Gi(Mr,Dr),Kr=Gi(Mr,Zi("oldPassword"),Dr),Fr=e=>({signUp:$r(((t,n,o)=>$i(e.post(pi,{loginId:t,password:n,user:o})))),signIn:$r(((t,n)=>$i(e.post(fi,{loginId:t,password:n})))),sendReset:Jr(((t,n)=>$i(e.post(gi,{loginId:t,redirectUrl:n})))),update:Nr(((t,n,o)=>$i(e.post(vi,{loginId:t,newPassword:n},{token:o})))),replace:Kr(((t,n,o)=>$i(e.post(bi,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>$i(e.get(mi))}),Hr=[Bi('"loginId" must be a string')],Wr=Zi("loginId"),zr=Zi("origin"),Vr=Gi(Wr,zr,Zi("name")),Br=Gi(Wr,zr),Gr=Gi(Hr,zr),Zr=Gi(Wr,zr,Zi("token")),Yr=Gi(Zi("transactionId"),Zi("response")),Xr=e=>({signUp:{start:Vr(((t,n,o)=>$i(e.post(ci.start,{user:{loginId:t,name:o},origin:n})))),finish:Yr(((t,n)=>$i(e.post(ci.finish,{transactionId:t,response:n}))))},signIn:{start:Gr(((t,n,o,i)=>$i(e.post(ui.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:Yr(((t,n)=>$i(e.post(ui.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Br(((t,n)=>$i(e.post(di.start,{loginId:t,origin:n}))))},update:{start:Zr(((t,n,o)=>$i(e.post(hi.start,{loginId:t,origin:n},{token:o})))),finish:Yr(((t,n)=>$i(e.post(hi.finish,{transactionId:t,response:n}))))}}),Qr=Gi(Zi("token"));var es,ts=Gi([("projectId",es=Zi("projectId"),Ji(((e,t)=>n=>Ni(...t).validate(le(n,e)))("projectId",es))())])((e=>{var t,n;const o=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),i=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=Pi({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:er(a),otp:Ur(a),magicLink:wr(a),enchantedLink:ur(a),oauth:Ir(a),saml:Pr(a),totp:Lr(a),webauthn:Xr(a),password:Fr(a),flow:pr(a),refresh:e=>$i(a.post(wi,{},{token:e})),logout:e=>$i(a.post(yi,{},{token:e})),logoutAll:e=>$i(a.post(ki,{},{token:e})),me:e=>$i(a.get(Ii,{token:e})),isJwtExpired:Qr(qi),getJwtPermissions:Qr(Li),getJwtRoles:Qr(Mi),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(t,n)=>{(await Promise.allSettled(null==i?void 0:i.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))}));const ns=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let i=o.shift(),r=e;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${t}" is not a function`);const s=r[i];r[i]=n(s)})),e);var os=Object.assign(ts,{DeliveryMethods:or});const is=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},rs=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},ss=async e=>{const t=await rs(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},as="undefined"!=typeof localStorage,ls=(e,t)=>as&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),cs=e=>as&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),us=e=>as&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),ds="undefined"!=typeof window,hs=ds&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",ps=(e="",t="")=>({vsid:e,vrid:t}),fs=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},gs=e=>(e.body&&(e.body.fpData=fs(!0)||ps()),e),vs="dls_last_user_login_id",bs="dls_last_user_display_name",ms=()=>cs(vs),ws=()=>cs(bs),ys=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=ms(),r=ws();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},ks=e=>async(...t)=>{const n=await e(...t);return us(vs),us(bs),n};function Is(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const Os="DS",js="DSR";function Ss(){return cs(js)||""}function xs(){return Nn.get(Os)||cs(Os)||""}function Cs(){us(js),us(Os),Nn.remove(Os)}const Us=e=>Object.assign(e,{token:e.token||Ss()}),Es=e=>async(...t)=>{const n=await e(...t);return Cs(),n};async function As(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Ls(n.publicKey.challenge),n.publicKey.user.id=Ls(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Ls(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Ms(n.rawId),type:n.type,response:{attestationObject:Ms(n.response.attestationObject),clientDataJSON:Ms(n.response.clientDataJSON)}});var n}async function Ps(e){const t=Ts(e);return qs(await navigator.credentials.get(t))}async function Rs(e,t){const n=Ts(e);return n.signal=t.signal,n.mediation="conditional",qs(await navigator.credentials.get(n))}async function _s(e=!1){if(!ds)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Ts(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Ls(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Ls(e.id)})),n}function qs(e){return JSON.stringify({id:e.id,rawId:Ms(e.rawId),type:e.type,response:{authenticatorData:Ms(e.response.authenticatorData),clientDataJSON:Ms(e.response.clientDataJSON),signature:Ms(e.response.signature),userHandle:e.response.userHandle?Ms(e.response.userHandle):void 0}})}function Ls(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Ms(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ds,$s=(Ds=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const i=await As(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await Ps(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await As(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Ps(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const i=await As(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:As,get:Ps,isSupported:_s,conditional:Rs}}),(...e)=>{const t=Ds(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),Js=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await _s(),o=Object.assign(Object.assign({redirectUrl:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=o,e.flow.start(...t)}});const Ns=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{var{fpKey:n,fpLoad:o}=t,i=u(t,["fpKey","fpLoad"]);return n?(ds?o&&(async e=>{try{if(fs())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=_n({apiKey:e,endpoint:hs}),o=await n,{requestId:i}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(ps(t,i))}catch(e){global.FB_DEBUG&&console.error(e)}})(n).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(is(i,{beforeRequest:gs}))):e(Object.assign({},i))}),(e=>t=>{var{autoRefresh:n}=t,o=u(t,["autoRefresh"]);if(!n)return e(o);const{clearAllTimers:i,setTimer:r}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),s=e(is(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await rs(t);if(401===(null==t?void 0:t.status))i();else if(o){const e=((a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;i(),r((()=>s.refresh(n)),e)}var a}}));return ns(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.2.6"},t.baseHeaders)}))),(e=>t=>{const n=Is(),o=Is(),i=e(is(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await ss(t);e&&o.pub(e);const{sessionJwt:i}=await rs(t);i&&n.pub(i)}}})),r=ns(i,["logout","logoutAll"],(e=>async(...t)=>{const i=await e(...t);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(is(t,{afterRequest:async(e,t)=>{var n;const o=await ss(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{ls(vs,e)})(i),(e=>{ls(bs,e)})(r))}}));let o=ns(n,["flow.start"],ys);return o=ns(o,["logout","logoutAll"],ks),Object.assign(o,{getLastUserLoginId:ms,getLastUserDisplayName:ws})}),(e=>t=>{var{persistTokens:n,sessionTokenViaCookie:o}=t,i=u(t,["persistTokens","sessionTokenViaCookie"]);if(!n||!ds)return n&&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"),e(i);const r=e(is(i,{beforeRequest:Us,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?Cs():((e={},t)=>{var{refreshJwt:n,sessionJwt:o}=e,i=u(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&ls(js,n),o&&(t?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i);Nn.set(e,t,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Os,o,i):ls(Os,o))})(await rs(t),o)}})),s=ns(r,["logout","logoutAll"],Es);return Object.assign(s,{getRefreshToken:Ss,getSessionToken:xs})}))(((...e)=>{const t=os(...e);return Object.assign(Object.assign({},t),{flow:Js(t),webauthn:$s(t)})})),Ks="undefined"!=typeof localStorage,Fs=Ks&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",Hs="descope-login-flow",Ws="code",zs="ra-challenge",Vs="ra-callback",Bs="data-exclude-field",Gs="dls_last_auth",Zs="state_id",Ys="data-type",Xs="poll",Qs="webauthnCreate",ea="submit",ta="polling";var na,oa,ia;function ra(e){return new URLSearchParams(window.location.search).get(e)}function sa(e){if(window.history.replaceState&&ra(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())}}function aa(e,t){return d(this,void 0,void 0,(function*(){const n=yield fetch(e,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${e}`);return{body:yield n[t||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}function la(e,t){const n=new URL(Fs);return n.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(n.pathname,e,"v2-alpha",t),n.toString()}function ca(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?na.forward:e<t?na.backward:void 0}!function(e){e.backward="backward",e.forward="forward"}(na||(na={}));const ua=()=>{const[e="",t=""]=(ra(Hs)||"").split("_");return{executionId:e,stepId:t}};function da(){sa(Hs)}const ha=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),pa=e=>{let t,n;return(...o)=>{return t&&(r=o,(i=t).length===r.length&&i.every(((e,t)=>e===r[t])))||(t=o,n=e(...o)),n;var i,r}},fa=null===(ia=null===(oa=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===oa?void 0:oa.brands)||void 0===ia?void 0:ia.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));var ga,va,ba,ma;function wa(e,t){const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=e[i],s=t[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!wa(r,s))return!1}else if(r!==s)return!1}return!0}class ya{constructor(e={},{updateOnlyOnChange:t=!0}={}){ga.set(this,void 0),va.set(this,{}),ba.set(this,0),ma.set(this,!1),this.update=e=>{const t="function"==typeof e?e(h(this,ga,"f")):e,n=Object.assign(Object.assign({},h(this,ga,"f")),t);if(!h(this,ma,"f")||!wa(h(this,ga,"f"),n)){const e=h(this,ga,"f");p(this,ga,n,"f"),Object.freeze(h(this,ga,"f")),setTimeout((()=>{Object.values(h(this,va,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},p(this,ga,e,"f"),p(this,ma,t,"f")}get current(){return Object.assign({},h(this,ga,"f"))}subscribe(e){return p(this,ba,h(this,ba,"f")+1,"f"),h(this,va,"f")[h(this,ba,"f")]=e,h(this,ba,"f").toString()}unsubscribe(e){const t=!!h(this,va,"f")[e];return t&&delete h(this,va,"f")[e],t}unsubscribeAll(){return p(this,va,{},"f"),!0}}ga=new WeakMap,va=new WeakMap,ba=new WeakMap,ma=new WeakMap;const ka=pa((()=>d(void 0,void 0,void 0,(function*(){var e,t;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const n=Promise.all([null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isConditionalMediationAvailable(),null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isUserVerifyingPlatformAuthenticatorAvailable()]).then((e=>e.every((e=>!!e)))),o=108;return yield Promise.race([n,(100,new Promise(((e,t)=>{setTimeout((()=>{t(new Error("Promise timed out after 100 ms"))}),100)}))).catch((()=>fa()>=o))])}catch(e){return console.warn("webauthn","Conditional login check failed",e),!1}})))),Ia={"lastAuth.loginId":{"not-empty":e=>!!e.loginId,empty:e=>!e.loginId},idpInitiated:{"is-true":e=>!!e.code,"is-false":e=>!e.code}},Oa=document.createElement("template");var ja,Sa,xa,Ca,Ua,Ea,Aa,Pa,Ra,_a,Ta,qa,La,Ma,Da,$a,Ja,Na,Ka,Fa,Ha,Wa,za,Va,Ba,Ga,Za,Ya,Xa,Qa,el,tl,nl,ol,il,rl,sl,al;Oa.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 ll extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}constructor(e){super(),ja.add(this),Sa.set(this,!1),xa.set(this,new ya),Ca.set(this,new ya),this.nextRequestStatus=new ya({isLoading:!1}),Ua.set(this,void 0),Ea.set(this,{popstate:h(this,ja,"m",qa).bind(this)}),Aa.set(this,void 0),Da.set(this,pa((()=>d(this,void 0,void 0,(function*(){const e=la(this.projectId,"config.json");try{const{body:t,headers:n}=yield aa(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),this.logger={error:(e,t="")=>{console.error(e,t,new Error),h(this,ja,"m",Wa).call(this,e,t)},info:(e,t="")=>{console.log(e,t)}},p(this,Aa,e,"f"),h(this,ja,"m",Pa).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get theme(){var e,t;const n=this.getAttribute("theme");return"os"===n?window.matchMedia&&(null===(t=null===(e=window.matchMedia)||void 0===e?void 0:e.call(window,"(prefers-color-scheme: dark)"))||void 0===t?void 0:t.matches)?"dark":"light":n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}getExecutionContext(){return d(this,void 0,void 0,(function*(){const{executionContext:e}=yield h(this,Da,"f").call(this);return e}))}getFlowConfig(){var e,t;return d(this,void 0,void 0,(function*(){const{projectConfig:n}=yield h(this,Da,"f").call(this),o=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}connectedCallback(){return d(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(h(this,ja,"m",Ra).call(this))return void h(this,ja,"m",_a).call(this);h(this,ja,"m",Ta).call(this),h(this,ja,"m",Ja).call(this),h(this,ja,"m",$a).call(this),h(this,ja,"m",za).call(this);const{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCallbackUrl:r,redirectAuthCodeChallenge:s,oidcIdpStateId:a}=(()=>{const{executionId:e,stepId:t}=ua();(e||t)&&da();const n=ra("t")||void 0;n&&sa("t");const o=ra(Ws)||void 0;o&&sa(Ws);const i=ra("err")||void 0;i&&sa("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s}={redirectAuthCodeChallenge:ra(zs),redirectAuthCallbackUrl:ra(Vs)};(r||s)&&(sa(zs),sa(Vs));const a=ra(Zs);return a&&sa(Zs),{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,oidcIdpStateId:a}})();window.addEventListener("popstate",h(this,Ea,"f").popstate),h(this,xa,"f").subscribe(h(this,ja,"m",Ma).bind(this)),h(this,Ca,"f").subscribe(h(this,ja,"m",Ha).bind(this)),h(this,xa,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:t,executionId:e,token:n,code:o,exchangeError:i,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:r,redirectAuthCodeChallenge:s,oidcIdpStateId:a}),h(this,Ca,"f").update({isDebug:this.debug}),p(this,Sa,!0,"f")}}))}disconnectedCallback(){h(this,xa,"f").unsubscribeAll(),h(this,Ca,"f").unsubscribeAll(),h(this,ja,"m",Fa).call(this),window.removeEventListener("popstate",h(this,Ea,"f").popstate)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&h(this,Sa,"f")&&t!==n&&ll.observedAttributes.includes(e)){h(this,ja,"m",Ta).call(this);const o=null===t;h(this,xa,"f").update((({stepId:t,executionId:i})=>{let r=t,s=i;return o||(s=null,r=null,da()),{[ha(e)]:n,stepId:r,executionId:s}})),h(this,Ca,"f").update({isDebug:this.debug})}}}Sa=new WeakMap,xa=new WeakMap,Ca=new WeakMap,Ua=new WeakMap,Ea=new WeakMap,Aa=new WeakMap,Da=new WeakMap,ja=new WeakSet,Pa=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Oa.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Ra=function(){const e=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&e},_a=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},Ta=function(){const e=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(ll.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[ha(t)])throw Error(`${t} 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')},qa=function(){const{stepId:e,executionId:t}=ua();h(this,xa,"f").update({stepId:e,executionId:t})},La=function(e,t,n){const o=n||void 0,i=!!o;this.sdk=Ns(Object.assign(Object.assign({persistTokens:!0},ll.sdkConfigOverrides),{projectId:e,baseUrl:t,fpKey:o,fpLoad:i})),["start","next"].forEach((e=>{const t=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>d(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield t(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Ma=function(e,t,n){return d(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:i}=e;if(n("projectId")||n("baseUrl")||n("telemetryKey")){if(!t)return;h(this,ja,"m",La).call(this,t,o,i)}h(this,Aa,"f").call(this,e)}))},$a=function(){var e,t,n,o;return d(this,void 0,void 0,(function*(){const{projectConfig:i}=yield h(this,Da,"f").call(this);null===(o=null===(n=null===(t=null===(e=null==i?void 0:i.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===t?void 0:t.typography)||void 0===n?void 0:n.fontFamilies)||void 0===o||o.forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},Ja=function(){h(this,ja,"m",Na).call(this),h(this,ja,"m",Ka).call(this)},Na=function(){return d(this,void 0,void 0,(function*(){const e=document.createElement("style"),t=la(this.projectId,"theme.css");try{const{body:n}=yield aa(t,"text");e.innerText=n}catch(e){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(e)}))},Ka=function(){this.rootElement.setAttribute("data-theme",this.theme)},Fa=function(){var e;null===(e=h(this,Ua,"f"))||void 0===e||e.remove(),p(this,Ua,null,"f")},Ha=function({isDebug:e}){return d(this,void 0,void 0,(function*(){e?(yield Promise.resolve().then((function(){return jl})),p(this,Ua,document.createElement("descope-debugger"),"f"),Object.assign(h(this,Ua,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(h(this,Ua,"f"))):h(this,ja,"m",Fa).call(this)}))},Wa=function(e,t){var n;e&&this.debug&&(null===(n=h(this,Ua,"f"))||void 0===n||n.updateData({title:e,description:t}))},za=function(){this.rootElement.onkeydown=e=>{if("Enter"!==e.key)return;e.preventDefault();const t=this.rootElement.querySelectorAll("button");if(1===t.length)return void t[0].click();const n=Array.from(t).filter((e=>"button"===e.getAttribute("data-type")));1===n.length&&n[0].click()}},ll.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.3.7"}};class cl extends ll{static set sdkConfigOverrides(e){ll.sdkConfigOverrides=e}constructor(){const e=new ya;super(e.update.bind(e)),Va.add(this),this.stepState=new ya({},{updateOnlyOnChange:!1}),Ba.set(this,void 0),Ga.set(this,null),Za.set(this,(()=>{clearInterval(h(this,Ba,"f")),p(this,Ba,null,"f")})),Ya.set(this,(e=>{var t,n,o,i,r,s,a,l,c;if(!(null==e?void 0:e.ok)){h(this,Za,"f").call(this),h(this,Va,"m",al).call(this,"error",null==e?void 0:e.error);const s=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,a=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(o=null==e?void 0:e.response)||void 0===o?void 0:o.statusText}`;return void this.logger.error((null===(i=null==e?void 0:e.error)||void 0===i?void 0:i.errorDescription)||s,(null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorMessage)||a)}const u=null===(l=null===(a=null===(s=e.data)||void 0===s?void 0:s.screen)||void 0===a?void 0:a.state)||void 0===l?void 0:l.errorText;u&&this.logger.error(u),(null===(c=e.data)||void 0===c?void 0:c.error)&&this.logger.error(`[${e.data.error.code}]: ${e.data.error.description}`,e.data.error.message);const{status:d,authInfo:p,lastAuth:f}=e.data;if("completed"===d)return function(e){(null==e?void 0:e.authMethod)&&Ks&&localStorage.setItem(Gs,JSON.stringify(e))}(f),h(this,Za,"f").call(this),void h(this,Va,"m",al).call(this,"success",p);const{executionId:g,stepId:v,action:b,screen:m,redirect:w,webauthn:y}=e.data;b!==Xs?this.flowState.update({stepId:v,executionId:g,action:b,redirectTo:null==w?void 0:w.url,screenId:null==m?void 0:m.id,screenState:null==m?void 0:m.state,webauthnTransactionId:null==y?void 0:y.transactionId,webauthnOptions:null==y?void 0:y.options}):this.flowState.update({action:b})})),Xa.set(this,pa((()=>d(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.logger.error("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.logger.error("Webauthn start failed",e.message)}}))))),this.flowState=e}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var t,n;return d(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.subscribe(this.onFlowChange.bind(this)),null===(n=this.stepState)||void 0===n||n.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(e,t,n){var o,i;return d(this,void 0,void 0,(function*(){const{projectId:r,flowId:s,tenant:a,stepId:l,executionId:c,action:u,screenId:f,screenState:g,redirectTo:v,redirectUrl:b,token:m,code:w,exchangeError:y,webauthnTransactionId:k,webauthnOptions:I,redirectAuthCodeChallenge:O,redirectAuthCallbackUrl:j,oidcIdpStateId:S}=e;let x,C;h(this,Ba,"f")&&h(this,Za,"f").call(this);const U=this.sdk.getLastUserLoginId(),E=yield this.getFlowConfig(),A=j&&O?{callbackUrl:j,codeChallenge:O}:void 0;if(!c&&(E.conditions?({startScreenId:x,conditionInteractionId:C}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n})=>{var o;if("ELSE"===t)return!0;const i=null===(o=Ia[t])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(e))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:U,code:w},E.conditions)):E.condition?({startScreenId:x,conditionInteractionId:C}=((e,t)=>{var n;const o=null===(n=Ia[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t)?e.met:e.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(E.condition,{loginId:U,code:w})):x=E.startScreenId,!x)){const e=w?{exchangeCode:w,idpInitiated:!0}:void 0,t=yield this.sdk.flow.start(s,Object.assign({tenant:a,redirectAuth:A,oidcIdpStateId:S},b&&{redirectUrl:b}),C,"",e,E.version);return h(this,Ya,"f").call(this,t),void("completed"!==(null===(o=null==t?void 0:t.data)||void 0===o?void 0:o.status)&&this.flowState.update({code:void 0}))}if(c&&(n("token")&&m||n("code")&&w||n("exchangeError")&&y)){const e=yield this.sdk.flow.next(c,l,ea,{token:m,exchangeCode:w,exchangeError:y},E.version);return h(this,Ya,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if("redirect"===u)return v||this.logger.error("Did not get redirect url"),void window.location.assign(v);if(u===Qs||"webauthnGet"===u){if(!k||!I)return void this.logger.error("Did not get webauthn transaction id or options");let e,t;null===(i=h(this,Ga,"f"))||void 0===i||i.abort(),p(this,Ga,null,"f");try{e=u===Qs?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(e){if("NotAllowedError"!==e.name)return void this.logger.error(e.message);t=!0}const n=yield this.sdk.flow.next(c,l,ea,{transactionId:k,response:e,cancelWebauthn:t},E.version);h(this,Ya,"f").call(this,n)}if(u===Xs&&p(this,Ba,setInterval((()=>d(this,void 0,void 0,(function*(){const e=yield this.sdk.flow.next(c,l,ta,{},E.version);h(this,Ya,"f").call(this,e)}))),2e3),"f"),!f&&!x)return void this.logger.info("Refreshing the page during a flow is not supported yet");const P={direction:ca(+l,+t.stepId),screenState:Object.assign(Object.assign({},g),{lastAuth:{loginId:U,name:this.sdk.getLastUserDisplayName()||U}}),htmlUrl:la(r,`${x||f}.html`)},R=function(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(Gs)))}catch(e){}return t}(U);x?P.next=(e,t)=>this.sdk.flow.start(s,Object.assign({tenant:a,redirectAuth:A,oidcIdpStateId:S,lastAuth:R},b&&{redirectUrl:b}),C,e,Object.assign(Object.assign({},t),w&&{exchangeCode:w,idpInitiated:!0}),E.version):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(P.next=(...e)=>this.sdk.flow.next(c,l,...e)),this.stepState.update(P)}))}onStepChange(e,t){var n;return d(this,void 0,void 0,(function*(){const{htmlUrl:o,direction:i,next:r,screenState:s}=e,a=document.createElement("template"),{body:l}=yield aa(o,"text");a.innerHTML=l;const c=a.content.cloneNode(!0),u=((e,t)=>{var n;const o=Array.from(e.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=e.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,t);return n.remove(),s}));return null===(n=e.querySelector("scripts"))||void 0===n||n.remove(),o})(c,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield h(this,Va,"m",el).call(this,c,r):c.querySelectorAll(`button[${Ys}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),((e,t)=>{var n;((e,t,n="")=>{e.querySelectorAll(`[${Ys}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",null==t?void 0:t.errorText),((e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`.descope-input[name="${t}"]:not([${Bs}])`)).forEach((e=>{e.value=n}))}))})(e,null==t?void 0:t.inputs),((e,t)=>{e.querySelectorAll(`[${Ys}="totp-link"]`).forEach((e=>{e.href=t}))})(e,null===(n=null==t?void 0:t.totp)||void 0===n?void 0:n.provisionUrl),((e,t)=>{e.querySelectorAll(".descope-text,.descope-link").forEach((e=>{e.textContent=((e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})))(e.textContent,t)}))})(e,t)})(c,s),((e,t)=>{var n;t&&(null===(n=null==e?void 0:e.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${t})`))})(c.querySelector("div"),null===(n=null==s?void 0:s.totp)||void 0===n?void 0:n.image);const p=()=>d(this,void 0,void 0,(function*(){try{u.forEach((e=>{e()}))}catch(e){this.logger.error(e.message)}this.rootElement.replaceChildren(c);const e=!t.htmlUrl;if(((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector('input:not([aria-hidden="true"])');null==t||t.focus()}})(this.rootElement,this.autoFocus,e),h(this,Va,"m",rl).call(this,r),h(this,Va,"m",al).call(this,"page-updated",{}),this.rootElement.querySelector(`[${Ys}="polling"]`)){const e=yield r(ta,{});h(this,Ya,"f").call(this,e)}}));i?h(this,Va,"m",sl).call(this,p,i):p()}))}}Ba=new WeakMap,Ga=new WeakMap,Za=new WeakMap,Ya=new WeakMap,Xa=new WeakMap,Va=new WeakSet,Qa=function(e){const t=e.name;if(!["email"].includes(t)){const n=`user-${t}`;e.name=n,e.addEventListener("input",(()=>{e.name=e.value?t:n}))}},el=function(e,t){var n;return d(this,void 0,void 0,(function*(){null===(n=h(this,Ga,"f"))||void 0===n||n.abort();const o=e.querySelector('input[autocomplete="webauthn"]');if(o&&(yield ka())){const{options:e,transactionId:n}=(yield h(this,Xa,"f").call(this))||{};e&&n&&(h(this,Va,"m",Qa).call(this,o),p(this,Ga,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(e,h(this,Ga,"f")).then((e=>d(this,void 0,void 0,(function*(){const i=yield t(o.id,{transactionId:n,response:e});h(this,Ya,"f").call(this,i)})))).catch((e=>{"AbortError"!==e.name&&this.logger.error("Conditional login failed",e.message)})))}}))},tl=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((e=>(e.reportValidity(),e.checkValidity())))},nl=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${Bs}])`)).reduce(((e,t)=>t.name?Object.assign(e,{[t.name]:t["checkbox"===t.type?"checked":"value"]}):e),{})},ol=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,i;n?null===(o=null==e?void 0:e.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(t),null===(i=null==e?void 0:e.classList)||void 0===i||i.remove("loading"))}))},il=function(e,t){return d(this,void 0,void 0,(function*(){if(e.formNoValidate||h(this,Va,"m",tl).call(this)){const o=null==e?void 0:e.getAttribute("id");h(this,Va,"m",ol).call(this,e);const i=h(this,Va,"m",nl).call(this),r=(n=e,Array.from((null==n?void 0:n.attributes)||[]).reduce(((e,t)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),s=Object.assign(Object.assign(Object.assign({},r),i),{origin:window.location.origin}),a=yield t(o,s);h(this,Ya,"f").call(this,a)}var n}))},rl=function(e){this.rootElement.querySelectorAll("button").forEach((t=>{t.onclick=()=>{h(this,Va,"m",il).call(this,t,e)}}))},sl=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===na.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),this.rootElement.classList.add("fade-out")},al=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",cl);var ul=Object.freeze({__proto__:null,default:cl});const dl=(e,t,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]};var hl,pl,fl,gl,vl,bl,ml,wl,yl,kl;const Il=document.createElement("template");Il.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class Ol extends HTMLElement{constructor(){super(),hl.add(this),pl.set(this,new ya({messages:[]})),fl.set(this,void 0),gl.set(this,void 0),vl.set(this,void 0),bl.set(this,{resize:h(this,hl,"m",kl).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Il.content.cloneNode(!0)),p(this,fl,this.shadowRoot.querySelector(".debugger"),"f"),p(this,gl,h(this,fl,"f").querySelector(".content"),"f"),p(this,vl,h(this,fl,"f").querySelector(".header"),"f")}updateData(e){h(this,pl,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,i=0,r=0,s=0;function a(t){t.preventDefault(),o=r-t.clientX,i=s-t.clientY,r=t.clientX,s=t.clientY;const[a,l]=dl(e,e.offsetLeft-o,e.offsetTop-i,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),r=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(h(this,fl,"f"),h(this,vl,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",h(this,bl,"f").resize),(e=h(this,fl,"f")).onmousemove=t=>{(t.target.w&&t.target.w!==t.target.offsetWidth||t.target.h&&t.target.h!==t.target.offsetHeight)&&e.onresize(t),t.target.w=t.target.offsetWidth,t.target.h=t.target.offsetHeight},h(this,fl,"f").onresize=h(this,hl,"m",yl).bind(this),h(this,pl,"f").subscribe(h(this,hl,"m",ml).bind(this))}disconnectedCallback(){h(this,pl,"f").unsubscribeAll(),window.removeEventListener("resize",h(this,bl,"f").resize)}}pl=new WeakMap,fl=new WeakMap,gl=new WeakMap,vl=new WeakMap,bl=new WeakMap,hl=new WeakSet,ml=function(e){h(this,hl,"m",wl).call(this,e),h(this,hl,"m",yl).call(this)},wl=function(e){h(this,gl,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},yl=function(){h(this,gl,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},kl=function(){const[e,t]=dl(h(this,fl,"f"),Number.parseInt(h(this,fl,"f").style.left,10),Number.parseInt(h(this,fl,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});h(this,fl,"f").style.top=`${t}px`,h(this,fl,"f").style.left=`${e}px`},customElements.define("descope-debugger",Ol);var jl=Object.freeze({__proto__:null,default:Ol});e.AuthProvider=_o,e.Descope=qo,e.SignInFlow=e=>o.default.createElement(qo,{...e,flowId:"sign-in"}),e.SignUpFlow=e=>o.default.createElement(qo,{...e,flowId:"sign-up"}),e.SignUpOrInFlow=e=>o.default.createElement(qo,{...e,flowId:"sign-up-or-in"}),e.getJwtPermissions=Po,e.getJwtRoles=Ro,e.getRefreshToken=Ao,e.getSessionToken=Eo,e.refresh=(e=Ao())=>Co?.refresh(e),e.useDescope=()=>{const{sdk:e}=Lo();return t.useMemo((()=>e||new Proxy(Uo({projectId:"dummy"}),Do)),[e])},e.useSession=()=>{const{session:e,isSessionLoading:n,fetchSession:o}=Lo(),i=t.useRef(n);return t.useMemo((()=>{i.current=n}),[n]),t.useMemo((()=>{e||n||(i.current=!0)}),[o]),t.useEffect((()=>{e||n||o()}),[o]),{isSessionLoading:i.current,sessionToken:e,isAuthenticated:!!e}},e.useUser=()=>{const{user:e,fetchUser:n,isUserLoading:o,session:i}=Lo(),[r,s]=t.useState(!1),a=t.useRef(o),l=t.useMemo((()=>!e&&!o&&i&&!r),[n,i,r]);return t.useMemo((()=>{a.current=o}),[o]),t.useMemo((()=>{l&&(a.current=!0)}),[l]),t.useEffect((()=>{l&&(s(!0),n())}),[l]),{isUserLoading:a.current,user:e}},Object.defineProperty(e,"__esModule",{value:!0})}));
4
4
  //# sourceMappingURL=index.umd.js.map