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
4
Versions
209
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.5.0 to 2.5.1

2

dist/cjs/index.cjs.js

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

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

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

sms = "sms",
whatsapp = "whatsapp",
embedded = "Embedded"
whatsapp = "whatsapp"
}

@@ -135,3 +134,2 @@ declare enum DeliveryEmail {

readonly whatsapp: DeliveryPhone.whatsapp;
readonly embedded: DeliveryPhone.embedded;
};

@@ -404,3 +402,2 @@ /** All flow execution statuses

whatsapp: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
Embedded: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
email: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;

@@ -411,3 +408,2 @@ };

whatsapp: (loginId: string) => Promise<SdkResponse<MaskedPhone>>;
Embedded: (loginId: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string) => Promise<SdkResponse<MaskedEmail>>;

@@ -418,3 +414,2 @@ }>;

whatsapp: (loginId: string, user?: User) => Promise<SdkResponse<MaskedPhone>>;
Embedded: (loginId: string, user?: User) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, user?: User) => Promise<SdkResponse<MaskedEmail>>;

@@ -425,3 +420,2 @@ }>;

whatsapp: (loginId: string) => Promise<SdkResponse<MaskedPhone>>;
Embedded: (loginId: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string) => Promise<SdkResponse<MaskedEmail>>;

@@ -439,3 +433,2 @@ }>;

whatsapp: (loginId: string, uri: string) => Promise<SdkResponse<MaskedPhone>>;
Embedded: (loginId: string, uri: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, uri: string) => Promise<SdkResponse<MaskedEmail>>;

@@ -446,3 +439,2 @@ }>;

whatsapp: (loginId: string, uri: string, user?: User) => Promise<SdkResponse<MaskedPhone>>;
Embedded: (loginId: string, uri: string, user?: User) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, uri: string, user?: User) => Promise<SdkResponse<MaskedEmail>>;

@@ -453,3 +445,2 @@ }>;

whatsapp: (loginId: string, uri: string) => Promise<SdkResponse<MaskedPhone>>;
Embedded: (loginId: string, uri: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, uri: string) => Promise<SdkResponse<MaskedEmail>>;

@@ -529,3 +520,2 @@ }>;

readonly whatsapp: DeliveryPhone.whatsapp;
readonly embedded: DeliveryPhone.embedded;
};

@@ -532,0 +522,0 @@ };

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

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