Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@descope/core-js-sdk

Package Overview
Dependencies
Maintainers
3
Versions
207
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@descope/core-js-sdk - npm Package Compare versions

Comparing version 2.13.0 to 2.14.0

2

dist/cjs/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},o={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},i={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},p={signIn:"/v1/auth/notp/whatsapp/signin",signUp:"/v1/auth/notp/whatsapp/signup",signUpOrIn:"/v1/auth/notp/whatsapp/signup-in",session:"/v1/auth/notp/pending-session"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},u="/v1/auth/refresh",g="/v1/auth/tenant/select",c="/v1/auth/logout",h="/v1/auth/logoutall",v="/v1/auth/me",f="/v1/auth/me/history",I={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",b=`https://api.${m}descope.com`,k=1e3,y=6e5,O=()=>{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")}},w=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),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=>O().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return O().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var j;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(j||(j={}));var U={TOO_MANY_REQUESTS:429};function R(e,t,n){var s;let o=x(e);t&&(o=null===(s=null==o?void 0:o.tenants)||void 0===s?void 0:s[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function x(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function P(e){const{exp:t}=x(e);return(new Date).getTime()/1e3>t}function q(e){let t=x(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function S(e,t){return R(e,t,"permissions")}function $(e,t){return R(e,t,"roles")}const E=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function T(e,t){var n;const s=await e,o={code:s.status,ok:s.ok,response:s},i=await s.clone().json();return s.ok?o.data=t?t(i):i:(o.error=i,s.status===U.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const A=(...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,s])=>(e[n]=s,e)),e),e}),{})),M=e=>void 0===e?void 0:JSON.stringify(e),N=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},C=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i,fetch:a})=>{const r=w(s,a),p=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:p,body:d,headers:l,queryParams:u,method:g,token:c}=a,h={headers:A(N(t,c),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.13.0"},(null==n?void 0:n.baseHeaders)||{},l),method:g,body:M(d)};null!==i&&(h.credentials=i||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const o=s.slice(1,-27);t=t.replace(m,o?o+".":"");const i=new URL(t);return i.pathname=E(i.pathname,e),n&&(i.search=new URLSearchParams(n).toString()),i})({path:p,baseUrl:e,queryParams:u,projectId:t}),h);return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.put,token:o}),delete:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.delete,token:s}),hooks:o}},L=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),z=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),H=e=>t=>e.test(t),_=H(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),J=H(/^\+[1-9]{1}[0-9]{3,14}$/),D=(e,t)=>n=>z(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),o=s.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<o;)a=a[s[i++]];return i&&i===o&&void 0!==a?a:n})(n,e)),F=L(_,'"{val}" is not a valid email'),Z=L(J,'"{val}" is not a valid phone number'),B=L((K=1,e=>e.length>=K),"Minimum length is 1");var K;const Q=L((e=>"string"==typeof e),"Input is not a string"),V=L((e=>void 0===e),"Input is defined"),W=(Y=[Q(),V()],G="Input is not a string or undefined",(e=G)=>t=>{const n=Y.filter((e=>e(t)));return!(n.length<Y.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Y,G;const X=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>z(...e).validate(n[t]))),t(...n)),ee=e=>[Q(`"${e}" must be a string`)],te=e=>[Q(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ne=e=>[Q(`"${e}" must be a string`),F()],se=e=>[Q(`"${e}" must be a string`),Z()],oe=X(te("accessKey")),ie=e=>({exchange:oe(((n,s)=>T(e.post(t.exchange,{loginOptions:s},{token:n}))))}),ae=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||k,k),timeoutMs:Math.min(t||y,y)});var re,pe;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(re||(re={})),function(e){e.email="email"}(pe||(pe={}));const de=Object.assign(Object.assign({},re),pe);var le;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(le||(le={}));const ue=te("loginId"),ge=X(te("token")),ce=X(ue),he=X(te("pendingRef")),ve=X(ue,ne("email")),fe=e=>({verify:ge((t=>T(e.post(o.verify,{token:t})))),signIn:ce(((t,n,s,i)=>T(e.post(E(o.signIn,de.email),{loginId:t,URI:n,loginOptions:s},{token:i})))),signUpOrIn:ce(((t,n,s)=>T(e.post(E(o.signUpOrIn,de.email),{loginId:t,URI:n,loginOptions:s})))),signUp:ce(((t,n,s,i)=>T(e.post(E(o.signUp,de.email),{loginId:t,URI:n,user:s,loginOptions:i})))),waitForSession:he(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=ae(n);let r;const p=setInterval((async()=>{const n=await e.post(o.session,{pendingRef:t});n.ok&&(clearInterval(p),r&&clearTimeout(r),s(T(Promise.resolve(n))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)})))),update:{email:ve(((t,n,s,i,a)=>T(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i}))))}}),Ie=X(te("flowId")),me=X(te("executionId"),te("stepId"),te("interactionId")),be=e=>({start:Ie(((t,n,s,o,i,a,r)=>T(e.post(I.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,version:i,componentsVersion:a,input:r})))),next:me(((t,n,s,o,i,a)=>T(e.post(I.next,{executionId:t,stepId:n,interactionId:s,version:o,componentsVersion:i,input:a}))))}),ke=te("loginId"),ye=X(te("token")),Oe=X(ke),we=X(ke,se("phone")),je=X(ke,ne("email")),Ue=Object.keys(de).filter((e=>e!==re.voice)),Re=e=>({verify:ye((t=>T(e.post(s.verify,{token:t})))),signIn:Ue.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,o,i,a)=>T(e.post(E(s.signIn,n),{loginId:t,URI:o,loginOptions:i},{token:a}))))})),{}),signUp:Ue.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,o,i,a)=>T(e.post(E(s.signUp,n),{loginId:t,URI:o,user:i,loginOptions:a}))))})),{}),signUpOrIn:Ue.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,o,i)=>T(e.post(E(s.signUpOrIn,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:je(((t,n,o,i,a)=>T(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:o},a),{token:i})))),phone:Object.keys(re).filter((e=>e!==re.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,o,i,a,r)=>T(e.post(E(s.update.phone,n),Object.assign({loginId:t,phone:o,URI:i},r),{token:a}))))})),{})}});var xe;!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",e.slack="slack"}(xe||(xe={}));const Pe=X(te("code")),qe=e=>({start:Object.assign(((t,n,s,o)=>T(e.post(i.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:o}))),Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>T(e.post(i.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{})),exchange:Pe((t=>T(e.post(i.exchange,{code:t})))),startNative:(t,n)=>T(e.post(i.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,o,a)=>T(e.post(i.finishNative,{provider:t,stateId:n,user:s,code:o,idToken:a}))}),Se=te("loginId"),$e=X(Se,te("code")),Ee=X(Se),Te=X(Se,se("phone")),Ae=X(Se,ne("email")),Me=e=>({verify:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,o)=>T(e.post(E(n.verify,s),{code:o,loginId:t}))))})),{}),signIn:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ee(((t,o,i)=>T(e.post(E(n.signIn,s),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ee(((t,o,i)=>T(e.post(E(n.signUp,s),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ee(((t,o)=>T(e.post(E(n.signUpOrIn,s),{loginId:t,loginOptions:o}))))})),{}),update:{email:Ae(((t,s,o,i)=>T(e.post(n.update.email,Object.assign({loginId:t,email:s},i),{token:o})))),phone:Object.keys(re).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,o,i,a)=>T(e.post(E(n.update.phone,s),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),Ne=X(te("tenant")),Ce=X(te("code")),Le=e=>({start:Ne(((t,n,s,o)=>T(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:Ce((t=>T(e.post(a.exchange,{code:t}))))}),ze=te("loginId"),He=X(ze,te("code")),_e=X(ze),Je=X(ze),De=e=>({signUp:_e(((t,n)=>T(e.post(r.signUp,{loginId:t,user:n})))),verify:He(((t,n,s,o)=>T(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:Je(((t,n)=>T(e.post(r.update,{loginId:t},{token:n}))))}),Fe=te("loginId"),Ze=te("newPassword"),Be=X(Fe,te("password")),Ke=X(Fe),Qe=X(Fe,Ze),Ve=X(Fe,te("oldPassword"),Ze),We=e=>({signUp:Be(((t,n,s)=>T(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Be(((t,n)=>T(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Ke(((t,n,s)=>T(e.post(l.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Qe(((t,n,s)=>T(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Ve(((t,n,s)=>T(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>T(e.get(l.policy))}),Ye=ee("loginId"),Ge=te("loginId"),Xe=te("origin"),et=X(Ge,Xe,te("name")),tt=X(Ge,Xe),nt=X(Ye,Xe),st=X(Ge,Xe,te("token")),ot=X(te("transactionId"),te("response")),it=e=>({signUp:{start:et(((t,n,s)=>T(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:ot(((t,n)=>T(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:nt(((t,n,s,o)=>T(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:ot(((t,n)=>T(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:tt(((t,n)=>T(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:st(((t,n,s)=>T(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:ot(((t,n)=>T(e.post(d.update.finish,{transactionId:t,response:n}))))}}),at=ee("loginId"),rt=X(at),pt=X(te("pendingRef")),dt=e=>({signUpOrIn:rt(((t,n)=>T(e.post(p.signUpOrIn,{loginId:t,loginOptions:n})))),signUp:rt(((t,n,s)=>T(e.post(p.signUp,{loginId:t,user:n,loginOptions:s})))),signIn:rt(((t,n,s)=>T(e.post(p.signIn,{loginId:t,loginOptions:n},{token:s})))),waitForSession:pt(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:i}=ae(n);let a;const r=setInterval((async()=>{const n=await e.post(p.session,{pendingRef:t});n.ok&&(clearInterval(r),a&&clearTimeout(a),s(T(Promise.resolve(n))))}),o);a=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(r)}),i)}))))}),lt=X(te("token")),ut=X([W(`"${"token"}" must be string or undefined`)]);var gt,ct;var ht=X([(gt="projectId",ct=te("projectId"),L(D(gt,ct))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const o=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(await Promise.allSettled(null==o?void 0:o.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}})))((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return r=C({baseUrl:n||b,projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:ie(r),otp:Me(r),magicLink:Re(r),enchantedLink:fe(r),oauth:qe(r),saml:Le(r),totp:De(r),notp:dt(r),webauthn:it(r),password:We(r),flow:be(r),refresh:ut((e=>T(r.post(u,{},{token:e})))),selectTenant:X([Q("tenantId")],[W('"token" must be string or undefined')])(((e,t)=>T(r.post(g,{tenant:e},{token:t})))),logout:ut((e=>T(r.post(c,{},{token:e})))),logoutAll:ut((e=>T(r.post(h,{},{token:e})))),me:ut((e=>T(r.get(v,{token:e})))),history:ut((e=>T(r.get(f,{token:e})))),isJwtExpired:lt(P),getTenants:lt(q),getJwtPermissions:lt(S),getJwtRoles:lt($),httpClient:r};var r}))),vt=Object.assign(ht,{DeliveryMethods:de});exports.HttpStatusCodes=U,exports.default=vt,exports.normalizeWaitForSessionConfig=ae,exports.transformResponse=T,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},o={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},i={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},p={signIn:"/v1/auth/notp/whatsapp/signin",signUp:"/v1/auth/notp/whatsapp/signup",signUpOrIn:"/v1/auth/notp/whatsapp/signup-in",session:"/v1/auth/notp/pending-session"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},u="/v1/auth/refresh",g="/v1/auth/tenant/select",c="/v1/auth/logout",h="/v1/auth/logoutall",v="/v1/auth/me",f="/v1/auth/me/history",I={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",b=`https://api.${m}descope.com`,k=1e3,y=6e5,O=()=>{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")}},w=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),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=>O().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return O().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var j;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(j||(j={}));var U={TOO_MANY_REQUESTS:429};function R(e,t,n){var s;let o=x(e);t&&(o=null===(s=null==o?void 0:o.tenants)||void 0===s?void 0:s[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function x(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function P(e){const{exp:t}=x(e);return(new Date).getTime()/1e3>t}function q(e){let t=x(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function S(e,t){return R(e,t,"permissions")}function $(e,t){return R(e,t,"roles")}const E=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function T(e,t){var n;const s=await e,o={code:s.status,ok:s.ok,response:s},i=await s.clone().json();return s.ok?o.data=t?t(i):i:(o.error=i,s.status===U.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const A=(...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,s])=>(e[n]=s,e)),e),e}),{})),M=e=>void 0===e?void 0:JSON.stringify(e),N=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},C=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i,fetch:a})=>{const r=w(s,a),p=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:p,body:d,headers:l,queryParams:u,method:g,token:c}=a,h={headers:A(N(t,c),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.14.0"},(null==n?void 0:n.baseHeaders)||{},l),method:g,body:M(d)};null!==i&&(h.credentials=i||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const o=s.slice(1,-27);t=t.replace(m,o?o+".":"");const i=new URL(t);return i.pathname=E(i.pathname,e),n&&(i.search=new URLSearchParams(n).toString()),i})({path:p,baseUrl:e,queryParams:u,projectId:t}),h);return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.put,token:o}),delete:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.delete,token:s}),hooks:o}},L=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),z=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),H=e=>t=>e.test(t),_=H(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),J=H(/^\+[1-9]{1}[0-9]{3,14}$/),D=(e,t)=>n=>z(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),o=s.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<o;)a=a[s[i++]];return i&&i===o&&void 0!==a?a:n})(n,e)),F=L(_,'"{val}" is not a valid email'),Z=L(J,'"{val}" is not a valid phone number'),B=L((K=1,e=>e.length>=K),"Minimum length is 1");var K;const Q=L((e=>"string"==typeof e),"Input is not a string"),V=L((e=>void 0===e),"Input is defined"),W=(Y=[Q(),V()],G="Input is not a string or undefined",(e=G)=>t=>{const n=Y.filter((e=>e(t)));return!(n.length<Y.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Y,G;const X=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>z(...e).validate(n[t]))),t(...n)),ee=e=>[Q(`"${e}" must be a string`)],te=e=>[Q(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ne=e=>[Q(`"${e}" must be a string`),F()],se=e=>[Q(`"${e}" must be a string`),Z()],oe=X(te("accessKey")),ie=e=>({exchange:oe(((n,s)=>T(e.post(t.exchange,{loginOptions:s},{token:n}))))}),ae=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||k,k),timeoutMs:Math.min(t||y,y)});var re,pe;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(re||(re={})),function(e){e.email="email"}(pe||(pe={}));const de=Object.assign(Object.assign({},re),pe);var le;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(le||(le={}));const ue=te("loginId"),ge=X(te("token")),ce=X(ue),he=X(te("pendingRef")),ve=X(ue,ne("email")),fe=e=>({verify:ge((t=>T(e.post(o.verify,{token:t})))),signIn:ce(((t,n,s,i)=>T(e.post(E(o.signIn,de.email),{loginId:t,URI:n,loginOptions:s},{token:i})))),signUpOrIn:ce(((t,n,s)=>T(e.post(E(o.signUpOrIn,de.email),{loginId:t,URI:n,loginOptions:s})))),signUp:ce(((t,n,s,i)=>T(e.post(E(o.signUp,de.email),{loginId:t,URI:n,user:s,loginOptions:i})))),waitForSession:he(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=ae(n);let r;const p=setInterval((async()=>{const n=await e.post(o.session,{pendingRef:t});n.ok&&(clearInterval(p),r&&clearTimeout(r),s(T(Promise.resolve(n))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)})))),update:{email:ve(((t,n,s,i,a)=>T(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i}))))}}),Ie=X(te("flowId")),me=X(te("executionId"),te("stepId"),te("interactionId")),be=e=>({start:Ie(((t,n,s,o,i,a,r)=>T(e.post(I.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,version:i,componentsVersion:a,input:r})))),next:me(((t,n,s,o,i,a)=>T(e.post(I.next,{executionId:t,stepId:n,interactionId:s,version:o,componentsVersion:i,input:a}))))}),ke=te("loginId"),ye=X(te("token")),Oe=X(ke),we=X(ke,se("phone")),je=X(ke,ne("email")),Ue=Object.keys(de).filter((e=>e!==re.voice)),Re=e=>({verify:ye((t=>T(e.post(s.verify,{token:t})))),signIn:Ue.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,o,i,a)=>T(e.post(E(s.signIn,n),{loginId:t,URI:o,loginOptions:i},{token:a}))))})),{}),signUp:Ue.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,o,i,a)=>T(e.post(E(s.signUp,n),{loginId:t,URI:o,user:i,loginOptions:a}))))})),{}),signUpOrIn:Ue.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,o,i)=>T(e.post(E(s.signUpOrIn,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:je(((t,n,o,i,a)=>T(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:o},a),{token:i})))),phone:Object.keys(re).filter((e=>e!==re.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,o,i,a,r)=>T(e.post(E(s.update.phone,n),Object.assign({loginId:t,phone:o,URI:i},r),{token:a}))))})),{})}});var xe;!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",e.slack="slack"}(xe||(xe={}));const Pe=X(te("code")),qe=e=>({start:Object.assign(((t,n,s,o)=>T(e.post(i.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:o}))),Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>T(e.post(i.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{})),exchange:Pe((t=>T(e.post(i.exchange,{code:t})))),startNative:(t,n)=>T(e.post(i.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,o,a)=>T(e.post(i.finishNative,{provider:t,stateId:n,user:s,code:o,idToken:a}))}),Se=te("loginId"),$e=X(Se,te("code")),Ee=X(Se),Te=X(Se,se("phone")),Ae=X(Se,ne("email")),Me=e=>({verify:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,o)=>T(e.post(E(n.verify,s),{code:o,loginId:t}))))})),{}),signIn:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ee(((t,o,i)=>T(e.post(E(n.signIn,s),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ee(((t,o,i)=>T(e.post(E(n.signUp,s),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(de).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ee(((t,o)=>T(e.post(E(n.signUpOrIn,s),{loginId:t,loginOptions:o}))))})),{}),update:{email:Ae(((t,s,o,i)=>T(e.post(n.update.email,Object.assign({loginId:t,email:s},i),{token:o})))),phone:Object.keys(re).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,o,i,a)=>T(e.post(E(n.update.phone,s),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),Ne=X(te("tenant")),Ce=X(te("code")),Le=e=>({start:Ne(((t,n,s,o)=>T(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:Ce((t=>T(e.post(a.exchange,{code:t}))))}),ze=te("loginId"),He=X(ze,te("code")),_e=X(ze),Je=X(ze),De=e=>({signUp:_e(((t,n)=>T(e.post(r.signUp,{loginId:t,user:n})))),verify:He(((t,n,s,o)=>T(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:Je(((t,n)=>T(e.post(r.update,{loginId:t},{token:n}))))}),Fe=te("loginId"),Ze=te("newPassword"),Be=X(Fe,te("password")),Ke=X(Fe),Qe=X(Fe,Ze),Ve=X(Fe,te("oldPassword"),Ze),We=e=>({signUp:Be(((t,n,s)=>T(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Be(((t,n)=>T(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Ke(((t,n,s)=>T(e.post(l.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Qe(((t,n,s)=>T(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Ve(((t,n,s)=>T(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>T(e.get(l.policy))}),Ye=ee("loginId"),Ge=te("loginId"),Xe=te("origin"),et=X(Ge,Xe,te("name")),tt=X(Ge,Xe),nt=X(Ye,Xe),st=X(Ge,Xe,te("token")),ot=X(te("transactionId"),te("response")),it=e=>({signUp:{start:et(((t,n,s)=>T(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:ot(((t,n)=>T(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:nt(((t,n,s,o)=>T(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:ot(((t,n)=>T(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:tt(((t,n)=>T(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:st(((t,n,s)=>T(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:ot(((t,n)=>T(e.post(d.update.finish,{transactionId:t,response:n}))))}}),at=ee("loginId"),rt=X(at),pt=X(te("pendingRef")),dt=e=>({signUpOrIn:rt(((t,n)=>T(e.post(p.signUpOrIn,{loginId:t,loginOptions:n})))),signUp:rt(((t,n,s)=>T(e.post(p.signUp,{loginId:t,user:n,loginOptions:s})))),signIn:rt(((t,n,s)=>T(e.post(p.signIn,{loginId:t,loginOptions:n},{token:s})))),waitForSession:pt(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:i}=ae(n);let a;const r=setInterval((async()=>{const n=await e.post(p.session,{pendingRef:t});n.ok&&(clearInterval(r),a&&clearTimeout(a),s(T(Promise.resolve(n))))}),o);a=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(r)}),i)}))))}),lt=X(te("token")),ut=X([W(`"${"token"}" must be string or undefined`)]);var gt,ct;var ht=X([(gt="projectId",ct=te("projectId"),L(D(gt,ct))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const o=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(await Promise.allSettled(null==o?void 0:o.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}})))((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return r=C({baseUrl:n||b,projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:ie(r),otp:Me(r),magicLink:Re(r),enchantedLink:fe(r),oauth:qe(r),saml:Le(r),totp:De(r),notp:dt(r),webauthn:it(r),password:We(r),flow:be(r),refresh:ut((e=>T(r.post(u,{},{token:e})))),selectTenant:X([Q("tenantId")],[W('"token" must be string or undefined')])(((e,t)=>T(r.post(g,{tenant:e},{token:t})))),logout:ut((e=>T(r.post(c,{},{token:e})))),logoutAll:ut((e=>T(r.post(h,{},{token:e})))),me:ut((e=>T(r.get(v,{token:e})))),history:ut((e=>T(r.get(f,{token:e})))),isJwtExpired:lt(P),getTenants:lt(q),getJwtPermissions:lt(S),getJwtRoles:lt($),httpClient:r};var r}))),vt=Object.assign(ht,{DeliveryMethods:de});exports.HttpStatusCodes=U,exports.default=vt,exports.normalizeWaitForSessionConfig=ae,exports.transformResponse=T,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);
//# sourceMappingURL=index.cjs.js.map

@@ -201,2 +201,3 @@ type JSONSerializable = string | number | boolean | null | Array<JSONSerializable>;

};
openInNewTabUrl?: string;
webauthn?: {

@@ -203,0 +204,0 @@ transactionId: string;

@@ -1,2 +0,2 @@

import e from"jwt-decode";var t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},i={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},o={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},p={signIn:"/v1/auth/notp/whatsapp/signin",signUp:"/v1/auth/notp/whatsapp/signup",signUpOrIn:"/v1/auth/notp/whatsapp/signup-in",session:"/v1/auth/notp/pending-session"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},u="/v1/auth/refresh",g="/v1/auth/tenant/select",c="/v1/auth/logout",h="/v1/auth/logoutall",v="/v1/auth/me",f="/v1/auth/me/history",I={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",b=`https://api.${m}descope.com`,k=1e3,y=6e5,O=()=>{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")}},w=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),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=>O().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return O().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var j;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(j||(j={}));var U={TOO_MANY_REQUESTS:429};function R(e,t,n){var s;let i=P(e);t&&(i=null===(s=null==i?void 0:i.tenants)||void 0===s?void 0:s[t]);const o=null==i?void 0:i[n];return Array.isArray(o)?o:[]}function P(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function x(e){const{exp:t}=P(e);return(new Date).getTime()/1e3>t}function q(e){let t=P(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function $(e,t){return R(e,t,"permissions")}function E(e,t){return R(e,t,"roles")}const S=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function T(e,t){var n;const s=await e,i={code:s.status,ok:s.ok,response:s},o=await s.clone().json();return s.ok?i.data=t?t(o):o:(i.error=o,s.status===U.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const A=(...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,s])=>(e[n]=s,e)),e),e}),{})),M=e=>void 0===e?void 0:JSON.stringify(e),N=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},L=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:i,cookiePolicy:o,fetch:a})=>{const r=w(s,a),p=async s=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(s):s,{path:p,body:d,headers:l,queryParams:u,method:g,token:c}=a,h={headers:A(N(t,c),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.13.0"},(null==n?void 0:n.baseHeaders)||{},l),method:g,body:M(d)};null!==o&&(h.credentials=o||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const i=s.slice(1,-27);t=t.replace(m,i?i+".":"");const o=new URL(t);return o.pathname=S(o.pathname,e),n&&(o.search=new URLSearchParams(n).toString()),o})({path:p,baseUrl:e,queryParams:u,projectId:t}),h);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:i}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.post,token:i}),put:(e,t,{headers:n,queryParams:s,token:i}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.put,token:i}),delete:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.delete,token:s}),hooks:i}},z=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),C=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),H=e=>t=>e.test(t),J=H(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),D=H(/^\+[1-9]{1}[0-9]{3,14}$/),_=(e,t)=>n=>C(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=s.length;let o=0,a=e===Object(e)?e:void 0;for(;null!=a&&o<i;)a=a[s[o++]];return o&&o===i&&void 0!==a?a:n})(n,e)),F=z(J,'"{val}" is not a valid email'),Z=z(D,'"{val}" is not a valid phone number'),B=z((K=1,e=>e.length>=K),"Minimum length is 1");var K;const Q=z((e=>"string"==typeof e),"Input is not a string"),V=z((e=>void 0===e),"Input is defined"),Y=(G=[Q(),V()],W="Input is not a string or undefined",(e=W)=>t=>{const n=G.filter((e=>e(t)));return!(n.length<G.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var G,W;const X=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>C(...e).validate(n[t]))),t(...n)),ee=e=>[Q(`"${e}" must be a string`)],te=e=>[Q(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ne=e=>[Q(`"${e}" must be a string`),F()],se=e=>[Q(`"${e}" must be a string`),Z()],ie=X(te("accessKey")),oe=e=>({exchange:ie(((n,s)=>T(e.post(t.exchange,{loginOptions:s},{token:n}))))}),ae=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let i=s.shift(),o=e;for(;s.length>0;){if(o=o[i],!i||!o)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=s.shift()}if("function"!=typeof o[i])throw Error(`"${t}" is not a function`);const a=o[i];o[i]=n(a)})),e),re=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||k,k),timeoutMs:Math.min(t||y,y)});var pe,de;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(pe||(pe={})),function(e){e.email="email"}(de||(de={}));const le=Object.assign(Object.assign({},pe),de);var ue;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ue||(ue={}));const ge=te("loginId"),ce=X(te("token")),he=X(ge),ve=X(te("pendingRef")),fe=X(ge,ne("email")),Ie=e=>({verify:ce((t=>T(e.post(i.verify,{token:t})))),signIn:he(((t,n,s,o)=>T(e.post(S(i.signIn,le.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:he(((t,n,s)=>T(e.post(S(i.signUpOrIn,le.email),{loginId:t,URI:n,loginOptions:s})))),signUp:he(((t,n,s,o)=>T(e.post(S(i.signUp,le.email),{loginId:t,URI:n,user:s,loginOptions:o})))),waitForSession:ve(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:a}=re(n);let r;const p=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(p),r&&clearTimeout(r),s(T(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)})))),update:{email:fe(((t,n,s,o,a)=>T(e.post(i.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:o}))))}}),me=X(te("flowId")),be=X(te("executionId"),te("stepId"),te("interactionId")),ke=e=>({start:me(((t,n,s,i,o,a,r)=>T(e.post(I.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:i,version:o,componentsVersion:a,input:r})))),next:be(((t,n,s,i,o,a)=>T(e.post(I.next,{executionId:t,stepId:n,interactionId:s,version:i,componentsVersion:o,input:a}))))}),ye=te("loginId"),Oe=X(te("token")),we=X(ye),je=X(ye,se("phone")),Ue=X(ye,ne("email")),Re=Object.keys(le).filter((e=>e!==pe.voice)),Pe=e=>({verify:Oe((t=>T(e.post(s.verify,{token:t})))),signIn:Re.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,i,o,a)=>T(e.post(S(s.signIn,n),{loginId:t,URI:i,loginOptions:o},{token:a}))))})),{}),signUp:Re.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,i,o,a)=>T(e.post(S(s.signUp,n),{loginId:t,URI:i,user:o,loginOptions:a}))))})),{}),signUpOrIn:Re.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,i,o)=>T(e.post(S(s.signUpOrIn,n),{loginId:t,URI:i,loginOptions:o}))))})),{}),update:{email:Ue(((t,n,i,o,a)=>T(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:i},a),{token:o})))),phone:Object.keys(pe).filter((e=>e!==pe.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:je(((t,i,o,a,r)=>T(e.post(S(s.update.phone,n),Object.assign({loginId:t,phone:i,URI:o},r),{token:a}))))})),{})}});var xe;!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",e.slack="slack"}(xe||(xe={}));const qe=X(te("code")),$e=e=>({start:Object.assign(((t,n,s,i)=>T(e.post(o.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,i)=>T(e.post(o.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:qe((t=>T(e.post(o.exchange,{code:t})))),startNative:(t,n)=>T(e.post(o.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,i,a)=>T(e.post(o.finishNative,{provider:t,stateId:n,user:s,code:i,idToken:a}))}),Ee=te("loginId"),Se=X(Ee,te("code")),Te=X(Ee),Ae=X(Ee,se("phone")),Me=X(Ee,ne("email")),Ne=e=>({verify:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Se(((t,i)=>T(e.post(S(n.verify,s),{code:i,loginId:t}))))})),{}),signIn:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,i,o)=>T(e.post(S(n.signIn,s),{loginId:t,loginOptions:i},{token:o}))))})),{}),signUp:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,i,o)=>T(e.post(S(n.signUp,s),{loginId:t,user:i,loginOptions:o}))))})),{}),signUpOrIn:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,i)=>T(e.post(S(n.signUpOrIn,s),{loginId:t,loginOptions:i}))))})),{}),update:{email:Me(((t,s,i,o)=>T(e.post(n.update.email,Object.assign({loginId:t,email:s},o),{token:i})))),phone:Object.keys(pe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ae(((t,i,o,a)=>T(e.post(S(n.update.phone,s),Object.assign({loginId:t,phone:i},a),{token:o}))))})),{})}}),Le=X(te("tenant")),ze=X(te("code")),Ce=e=>({start:Le(((t,n,s,i)=>T(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:ze((t=>T(e.post(a.exchange,{code:t}))))}),He=te("loginId"),Je=X(He,te("code")),De=X(He),_e=X(He),Fe=e=>({signUp:De(((t,n)=>T(e.post(r.signUp,{loginId:t,user:n})))),verify:Je(((t,n,s,i)=>T(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:i})))),update:_e(((t,n)=>T(e.post(r.update,{loginId:t},{token:n}))))}),Ze=te("loginId"),Be=te("newPassword"),Ke=X(Ze,te("password")),Qe=X(Ze),Ve=X(Ze,Be),Ye=X(Ze,te("oldPassword"),Be),Ge=e=>({signUp:Ke(((t,n,s)=>T(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Ke(((t,n)=>T(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Qe(((t,n,s)=>T(e.post(l.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Ve(((t,n,s)=>T(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Ye(((t,n,s)=>T(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>T(e.get(l.policy))}),We=ee("loginId"),Xe=te("loginId"),et=te("origin"),tt=X(Xe,et,te("name")),nt=X(Xe,et),st=X(We,et),it=X(Xe,et,te("token")),ot=X(te("transactionId"),te("response")),at=e=>({signUp:{start:tt(((t,n,s)=>T(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:ot(((t,n)=>T(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:st(((t,n,s,i)=>T(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:i})))),finish:ot(((t,n)=>T(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:nt(((t,n)=>T(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:it(((t,n,s)=>T(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:ot(((t,n)=>T(e.post(d.update.finish,{transactionId:t,response:n}))))}}),rt=ee("loginId"),pt=X(rt),dt=X(te("pendingRef")),lt=e=>({signUpOrIn:pt(((t,n)=>T(e.post(p.signUpOrIn,{loginId:t,loginOptions:n})))),signUp:pt(((t,n,s)=>T(e.post(p.signUp,{loginId:t,user:n,loginOptions:s})))),signIn:pt(((t,n,s)=>T(e.post(p.signIn,{loginId:t,loginOptions:n},{token:s})))),waitForSession:dt(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:o}=re(n);let a;const r=setInterval((async()=>{const n=await e.post(p.session,{pendingRef:t});n.ok&&(clearInterval(r),a&&clearTimeout(a),s(T(Promise.resolve(n))))}),i);a=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${o}ms`,errorCode:"0"},ok:!1}),clearInterval(r)}),o)}))))}),ut=X(te("token")),gt=X([Y(`"${"token"}" must be string or undefined`)]);var ct,ht;var vt=X([(ct="projectId",ht=te("projectId"),z(_(ct,ht))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const i=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}})))((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:i,baseHeaders:o={},fetch:a})=>{return r=L({baseUrl:n||b,projectId:e,logger:t,hooks:s,cookiePolicy:i,baseConfig:{baseHeaders:o},fetch:a}),{accessKey:oe(r),otp:Ne(r),magicLink:Pe(r),enchantedLink:Ie(r),oauth:$e(r),saml:Ce(r),totp:Fe(r),notp:lt(r),webauthn:at(r),password:Ge(r),flow:ke(r),refresh:gt((e=>T(r.post(u,{},{token:e})))),selectTenant:X([Q("tenantId")],[Y('"token" must be string or undefined')])(((e,t)=>T(r.post(g,{tenant:e},{token:t})))),logout:gt((e=>T(r.post(c,{},{token:e})))),logoutAll:gt((e=>T(r.post(h,{},{token:e})))),me:gt((e=>T(r.get(v,{token:e})))),history:gt((e=>T(r.get(f,{token:e})))),isJwtExpired:ut(x),getTenants:ut(q),getJwtPermissions:ut($),getJwtRoles:ut(E),httpClient:r};var r}))),ft=Object.assign(vt,{DeliveryMethods:le});export{U as HttpStatusCodes,ft as default,re as normalizeWaitForSessionConfig,T as transformResponse,ae as wrapWith};
import e from"jwt-decode";var t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},i={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},o={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},p={signIn:"/v1/auth/notp/whatsapp/signin",signUp:"/v1/auth/notp/whatsapp/signup",signUpOrIn:"/v1/auth/notp/whatsapp/signup-in",session:"/v1/auth/notp/pending-session"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},u="/v1/auth/refresh",g="/v1/auth/tenant/select",c="/v1/auth/logout",h="/v1/auth/logoutall",v="/v1/auth/me",f="/v1/auth/me/history",I={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",b=`https://api.${m}descope.com`,k=1e3,y=6e5,O=()=>{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")}},w=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),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=>O().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return O().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var j;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(j||(j={}));var U={TOO_MANY_REQUESTS:429};function R(e,t,n){var s;let i=P(e);t&&(i=null===(s=null==i?void 0:i.tenants)||void 0===s?void 0:s[t]);const o=null==i?void 0:i[n];return Array.isArray(o)?o:[]}function P(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function x(e){const{exp:t}=P(e);return(new Date).getTime()/1e3>t}function q(e){let t=P(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function $(e,t){return R(e,t,"permissions")}function E(e,t){return R(e,t,"roles")}const S=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function T(e,t){var n;const s=await e,i={code:s.status,ok:s.ok,response:s},o=await s.clone().json();return s.ok?i.data=t?t(o):o:(i.error=o,s.status===U.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const A=(...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,s])=>(e[n]=s,e)),e),e}),{})),M=e=>void 0===e?void 0:JSON.stringify(e),N=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},L=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:i,cookiePolicy:o,fetch:a})=>{const r=w(s,a),p=async s=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(s):s,{path:p,body:d,headers:l,queryParams:u,method:g,token:c}=a,h={headers:A(N(t,c),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.14.0"},(null==n?void 0:n.baseHeaders)||{},l),method:g,body:M(d)};null!==o&&(h.credentials=o||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const i=s.slice(1,-27);t=t.replace(m,i?i+".":"");const o=new URL(t);return o.pathname=S(o.pathname,e),n&&(o.search=new URLSearchParams(n).toString()),o})({path:p,baseUrl:e,queryParams:u,projectId:t}),h);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:i}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.post,token:i}),put:(e,t,{headers:n,queryParams:s,token:i}={})=>p({path:e,headers:n,queryParams:s,body:t,method:j.put,token:i}),delete:(e,{headers:t,queryParams:n,token:s}={})=>p({path:e,headers:t,queryParams:n,body:void 0,method:j.delete,token:s}),hooks:i}},z=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),C=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),H=e=>t=>e.test(t),J=H(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),D=H(/^\+[1-9]{1}[0-9]{3,14}$/),_=(e,t)=>n=>C(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=s.length;let o=0,a=e===Object(e)?e:void 0;for(;null!=a&&o<i;)a=a[s[o++]];return o&&o===i&&void 0!==a?a:n})(n,e)),F=z(J,'"{val}" is not a valid email'),Z=z(D,'"{val}" is not a valid phone number'),B=z((K=1,e=>e.length>=K),"Minimum length is 1");var K;const Q=z((e=>"string"==typeof e),"Input is not a string"),V=z((e=>void 0===e),"Input is defined"),Y=(G=[Q(),V()],W="Input is not a string or undefined",(e=W)=>t=>{const n=G.filter((e=>e(t)));return!(n.length<G.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var G,W;const X=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>C(...e).validate(n[t]))),t(...n)),ee=e=>[Q(`"${e}" must be a string`)],te=e=>[Q(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ne=e=>[Q(`"${e}" must be a string`),F()],se=e=>[Q(`"${e}" must be a string`),Z()],ie=X(te("accessKey")),oe=e=>({exchange:ie(((n,s)=>T(e.post(t.exchange,{loginOptions:s},{token:n}))))}),ae=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let i=s.shift(),o=e;for(;s.length>0;){if(o=o[i],!i||!o)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=s.shift()}if("function"!=typeof o[i])throw Error(`"${t}" is not a function`);const a=o[i];o[i]=n(a)})),e),re=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||k,k),timeoutMs:Math.min(t||y,y)});var pe,de;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(pe||(pe={})),function(e){e.email="email"}(de||(de={}));const le=Object.assign(Object.assign({},pe),de);var ue;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ue||(ue={}));const ge=te("loginId"),ce=X(te("token")),he=X(ge),ve=X(te("pendingRef")),fe=X(ge,ne("email")),Ie=e=>({verify:ce((t=>T(e.post(i.verify,{token:t})))),signIn:he(((t,n,s,o)=>T(e.post(S(i.signIn,le.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:he(((t,n,s)=>T(e.post(S(i.signUpOrIn,le.email),{loginId:t,URI:n,loginOptions:s})))),signUp:he(((t,n,s,o)=>T(e.post(S(i.signUp,le.email),{loginId:t,URI:n,user:s,loginOptions:o})))),waitForSession:ve(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:a}=re(n);let r;const p=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(p),r&&clearTimeout(r),s(T(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)})))),update:{email:fe(((t,n,s,o,a)=>T(e.post(i.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:o}))))}}),me=X(te("flowId")),be=X(te("executionId"),te("stepId"),te("interactionId")),ke=e=>({start:me(((t,n,s,i,o,a,r)=>T(e.post(I.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:i,version:o,componentsVersion:a,input:r})))),next:be(((t,n,s,i,o,a)=>T(e.post(I.next,{executionId:t,stepId:n,interactionId:s,version:i,componentsVersion:o,input:a}))))}),ye=te("loginId"),Oe=X(te("token")),we=X(ye),je=X(ye,se("phone")),Ue=X(ye,ne("email")),Re=Object.keys(le).filter((e=>e!==pe.voice)),Pe=e=>({verify:Oe((t=>T(e.post(s.verify,{token:t})))),signIn:Re.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,i,o,a)=>T(e.post(S(s.signIn,n),{loginId:t,URI:i,loginOptions:o},{token:a}))))})),{}),signUp:Re.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,i,o,a)=>T(e.post(S(s.signUp,n),{loginId:t,URI:i,user:o,loginOptions:a}))))})),{}),signUpOrIn:Re.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,i,o)=>T(e.post(S(s.signUpOrIn,n),{loginId:t,URI:i,loginOptions:o}))))})),{}),update:{email:Ue(((t,n,i,o,a)=>T(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:i},a),{token:o})))),phone:Object.keys(pe).filter((e=>e!==pe.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:je(((t,i,o,a,r)=>T(e.post(S(s.update.phone,n),Object.assign({loginId:t,phone:i,URI:o},r),{token:a}))))})),{})}});var xe;!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",e.slack="slack"}(xe||(xe={}));const qe=X(te("code")),$e=e=>({start:Object.assign(((t,n,s,i)=>T(e.post(o.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,i)=>T(e.post(o.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:qe((t=>T(e.post(o.exchange,{code:t})))),startNative:(t,n)=>T(e.post(o.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,i,a)=>T(e.post(o.finishNative,{provider:t,stateId:n,user:s,code:i,idToken:a}))}),Ee=te("loginId"),Se=X(Ee,te("code")),Te=X(Ee),Ae=X(Ee,se("phone")),Me=X(Ee,ne("email")),Ne=e=>({verify:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Se(((t,i)=>T(e.post(S(n.verify,s),{code:i,loginId:t}))))})),{}),signIn:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,i,o)=>T(e.post(S(n.signIn,s),{loginId:t,loginOptions:i},{token:o}))))})),{}),signUp:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,i,o)=>T(e.post(S(n.signUp,s),{loginId:t,user:i,loginOptions:o}))))})),{}),signUpOrIn:Object.keys(le).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Te(((t,i)=>T(e.post(S(n.signUpOrIn,s),{loginId:t,loginOptions:i}))))})),{}),update:{email:Me(((t,s,i,o)=>T(e.post(n.update.email,Object.assign({loginId:t,email:s},o),{token:i})))),phone:Object.keys(pe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Ae(((t,i,o,a)=>T(e.post(S(n.update.phone,s),Object.assign({loginId:t,phone:i},a),{token:o}))))})),{})}}),Le=X(te("tenant")),ze=X(te("code")),Ce=e=>({start:Le(((t,n,s,i)=>T(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:ze((t=>T(e.post(a.exchange,{code:t}))))}),He=te("loginId"),Je=X(He,te("code")),De=X(He),_e=X(He),Fe=e=>({signUp:De(((t,n)=>T(e.post(r.signUp,{loginId:t,user:n})))),verify:Je(((t,n,s,i)=>T(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:i})))),update:_e(((t,n)=>T(e.post(r.update,{loginId:t},{token:n}))))}),Ze=te("loginId"),Be=te("newPassword"),Ke=X(Ze,te("password")),Qe=X(Ze),Ve=X(Ze,Be),Ye=X(Ze,te("oldPassword"),Be),Ge=e=>({signUp:Ke(((t,n,s)=>T(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Ke(((t,n)=>T(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Qe(((t,n,s)=>T(e.post(l.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Ve(((t,n,s)=>T(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Ye(((t,n,s)=>T(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>T(e.get(l.policy))}),We=ee("loginId"),Xe=te("loginId"),et=te("origin"),tt=X(Xe,et,te("name")),nt=X(Xe,et),st=X(We,et),it=X(Xe,et,te("token")),ot=X(te("transactionId"),te("response")),at=e=>({signUp:{start:tt(((t,n,s)=>T(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:ot(((t,n)=>T(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:st(((t,n,s,i)=>T(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:i})))),finish:ot(((t,n)=>T(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:nt(((t,n)=>T(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:it(((t,n,s)=>T(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:ot(((t,n)=>T(e.post(d.update.finish,{transactionId:t,response:n}))))}}),rt=ee("loginId"),pt=X(rt),dt=X(te("pendingRef")),lt=e=>({signUpOrIn:pt(((t,n)=>T(e.post(p.signUpOrIn,{loginId:t,loginOptions:n})))),signUp:pt(((t,n,s)=>T(e.post(p.signUp,{loginId:t,user:n,loginOptions:s})))),signIn:pt(((t,n,s)=>T(e.post(p.signIn,{loginId:t,loginOptions:n},{token:s})))),waitForSession:dt(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:o}=re(n);let a;const r=setInterval((async()=>{const n=await e.post(p.session,{pendingRef:t});n.ok&&(clearInterval(r),a&&clearTimeout(a),s(T(Promise.resolve(n))))}),i);a=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${o}ms`,errorCode:"0"},ok:!1}),clearInterval(r)}),o)}))))}),ut=X(te("token")),gt=X([Y(`"${"token"}" must be string or undefined`)]);var ct,ht;var vt=X([(ct="projectId",ht=te("projectId"),z(_(ct,ht))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const i=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}})))((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:i,baseHeaders:o={},fetch:a})=>{return r=L({baseUrl:n||b,projectId:e,logger:t,hooks:s,cookiePolicy:i,baseConfig:{baseHeaders:o},fetch:a}),{accessKey:oe(r),otp:Ne(r),magicLink:Pe(r),enchantedLink:Ie(r),oauth:$e(r),saml:Ce(r),totp:Fe(r),notp:lt(r),webauthn:at(r),password:Ge(r),flow:ke(r),refresh:gt((e=>T(r.post(u,{},{token:e})))),selectTenant:X([Q("tenantId")],[Y('"token" must be string or undefined')])(((e,t)=>T(r.post(g,{tenant:e},{token:t})))),logout:gt((e=>T(r.post(c,{},{token:e})))),logoutAll:gt((e=>T(r.post(h,{},{token:e})))),me:gt((e=>T(r.get(v,{token:e})))),history:gt((e=>T(r.get(f,{token:e})))),isJwtExpired:ut(x),getTenants:ut(q),getJwtPermissions:ut($),getJwtRoles:ut(E),httpClient:r};var r}))),ft=Object.assign(vt,{DeliveryMethods:le});export{U as HttpStatusCodes,ft as default,re as normalizeWaitForSessionConfig,T as transformResponse,ae as wrapWith};
//# sourceMappingURL=index.esm.js.map
{
"name": "@descope/core-js-sdk",
"version": "2.13.0",
"version": "2.14.0",
"author": "Descope Team <info@descope.com>",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/descope/core-js-sdk",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc