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

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