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

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

exchange: (code: string) => Promise<SdkResponse<JWTResponse>>;
startNative: (provider: string, loginOptions?: LoginOptions) => Promise<SdkResponse<ResponseData>>;
finishNative: (provider: string, stateId: string, user?: string, code?: string, idToken?: string) => Promise<SdkResponse<ResponseData>>;
};

@@ -475,0 +477,0 @@ saml: {

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