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

@descope/core-js-sdk

Package Overview
Dependencies
Maintainers
3
Versions
207
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 2.11.15 to 2.12.0

2

dist/cjs/index.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},o={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},i={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},u={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",p="/v1/auth/tenant/select",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v="/v1/auth/me/history",f={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",I=`https://api.${m}descope.com`,b=1e3,y=6e5,k=()=>{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=>k().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 k().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.11.15"},(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 A(e,t){return q(e,t,"permissions")}function T(e,t){return q(e,t,"roles")}const M=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function N(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 L=(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)}),_=e=>t=>e.test(t),z=_(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=_(/^\+[1-9]{1}[0-9]{3,14}$/),J=(e,t)=>n=>H(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),o=s.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<o;)a=a[s[i++]];return i&&i===o&&void 0!==a?a:n})(n,e)),D=L(z,'"{val}" is not a valid email'),Z=L(C,'"{val}" is not a valid phone number'),B=L((F=1,e=>e.length>=F),"Minimum length is 1");var F;const K=L((e=>"string"==typeof e),"Input is not a string"),Q=L((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(((n,s)=>N(e.post(t.exchange,{loginOptions:s},{token:n}))))});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=>N(e.post(o.verify,{token:t})))),signIn:le(((t,n,s,i)=>N(e.post(M(o.signIn,ae.email),{loginId:t,URI:n,loginOptions:s},{token:i})))),signUpOrIn:le(((t,n,s)=>N(e.post(M(o.signUpOrIn,ae.email),{loginId:t,URI:n,loginOptions:s})))),signUp:le(((t,n,s,i)=>N(e.post(M(o.signUp,ae.email),{loginId:t,URI:n,user:s,loginOptions:i})))),waitForSession:pe(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||b,b),timeoutMs:Math.min(t||y,y)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(o.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(N(Promise.resolve(n))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:ce(((t,n,s,i,a)=>N(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i}))))}}),he=W(X("flowId")),ve=W(X("executionId"),X("stepId"),X("interactionId")),fe=e=>({start:he(((t,n,s,o,i,a,r)=>N(e.post(f.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,version:i,componentsVersion:a,input:r})))),next:ve(((t,n,s,o,i,a)=>N(e.post(f.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=>N(e.post(s.verify,{token:t})))),signIn:Object.keys(ae).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>N(e.post(M(s.signIn,n),{loginId:t,URI:o,loginOptions:i},{token:a}))))})),{}),signUp:Object.keys(ae).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>N(e.post(M(s.signUp,n),{loginId:t,URI:o,user:i,loginOptions:a}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i)=>N(e.post(M(s.signUpOrIn,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:ke(((t,n,o,i,a)=>N(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:o},a),{token:i})))),phone:Object.keys(oe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i,a,r)=>N(e.post(M(s.update.phone,n),Object.assign({loginId:t,phone:o,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)=>N(e.post(i.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)=>N(e.post(i.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{})),exchange:je((t=>N(e.post(i.exchange,{code:t})))),startNative:(t,n)=>N(e.post(i.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,o,a)=>N(e.post(i.finishNative,{provider:t,stateId:n,user:s,code:o,idToken:a}))}),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,s)=>Object.assign(Object.assign({},t),{[s]:xe(((t,o)=>N(e.post(M(n.verify,s),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Pe(((t,o,i)=>N(e.post(M(n.signIn,s),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Pe(((t,o,i)=>N(e.post(M(n.signUp,s),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Pe(((t,o)=>N(e.post(M(n.signUpOrIn,s),{loginId:t,loginOptions:o}))))})),{}),update:{email:$e(((t,s,o,i)=>N(e.post(n.update.email,Object.assign({loginId:t,email:s},i),{token:o})))),phone:Object.keys(oe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i,a)=>N(e.post(M(n.update.phone,s),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),Se=W(X("tenant")),Ae=W(X("code")),Te=e=>({start:Se(((t,n,s,o)=>N(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:Ae((t=>N(e.post(a.exchange,{code:t}))))}),Me=X("loginId"),Ne=W(Me,X("code")),Le=W(Me),He=W(Me),_e=e=>({signUp:Le(((t,n)=>N(e.post(r.signUp,{loginId:t,user:n})))),verify:Ne(((t,n,s,o)=>N(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:He(((t,n)=>N(e.post(r.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)=>N(e.post(u.signUp,{loginId:t,password:n,user:s})))),signIn:Je(((t,n)=>N(e.post(u.signIn,{loginId:t,password:n})))),sendReset:De(((t,n,s)=>N(e.post(u.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Ze(((t,n,s)=>N(e.post(u.update,{loginId:t,newPassword:n},{token:s})))),replace:Be(((t,n,s)=>N(e.post(u.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>N(e.get(u.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)=>N(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:et(((t,n)=>N(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:We(((t,n,s,o)=>N(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:et(((t,n)=>N(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Ge(((t,n)=>N(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:Xe(((t,n,s)=>N(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:et(((t,n)=>N(e.post(d.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"),L(J(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||I,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:Te(r),totp:_e(r),webauthn:tt(r),password:Fe(r),flow:fe(r),refresh:st((e=>N(r.post(l,{},{token:e})))),selectTenant:W([K("tenantId")],[V('"token" must be string or undefined')])(((e,t)=>N(r.post(p,{tenant:e},{token:t})))),logout:st((e=>N(r.post(c,{},{token:e})))),logoutAll:st((e=>N(r.post(g,{},{token:e})))),me:st((e=>N(r.get(h,{token:e})))),history:st((e=>N(r.get(v,{token:e})))),isJwtExpired:nt(E),getTenants:nt(S),getJwtPermissions:nt(A),getJwtRoles:nt(T),httpClient:r};var r})));var rt=Object.assign(at,{DeliveryMethods:ae});exports.HttpStatusCodes=P,exports.default=rt,exports.transformResponse=N,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},o={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},i={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},u={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",p="/v1/auth/tenant/select",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v="/v1/auth/me/history",f={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",I=`https://api.${m}descope.com`,b=1e3,y=6e5,k=()=>{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=>k().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 k().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.12.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 A(e,t){return q(e,t,"permissions")}function T(e,t){return q(e,t,"roles")}const M=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function N(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 L=(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)}),_=e=>t=>e.test(t),z=_(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=_(/^\+[1-9]{1}[0-9]{3,14}$/),J=(e,t)=>n=>H(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),o=s.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<o;)a=a[s[i++]];return i&&i===o&&void 0!==a?a:n})(n,e)),D=L(z,'"{val}" is not a valid email'),Z=L(C,'"{val}" is not a valid phone number'),B=L((F=1,e=>e.length>=F),"Minimum length is 1");var F;const K=L((e=>"string"==typeof e),"Input is not a string"),Q=L((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(((n,s)=>N(e.post(t.exchange,{loginOptions:s},{token:n}))))});var oe,ie;!function(e){e.sms="sms",e.voice="voice",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=>N(e.post(o.verify,{token:t})))),signIn:le(((t,n,s,i)=>N(e.post(M(o.signIn,ae.email),{loginId:t,URI:n,loginOptions:s},{token:i})))),signUpOrIn:le(((t,n,s)=>N(e.post(M(o.signUpOrIn,ae.email),{loginId:t,URI:n,loginOptions:s})))),signUp:le(((t,n,s,i)=>N(e.post(M(o.signUp,ae.email),{loginId:t,URI:n,user:s,loginOptions:i})))),waitForSession:pe(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||b,b),timeoutMs:Math.min(t||y,y)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(o.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(N(Promise.resolve(n))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:ce(((t,n,s,i,a)=>N(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i}))))}}),he=W(X("flowId")),ve=W(X("executionId"),X("stepId"),X("interactionId")),fe=e=>({start:he(((t,n,s,o,i,a,r)=>N(e.post(f.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,version:i,componentsVersion:a,input:r})))),next:ve(((t,n,s,o,i,a)=>N(e.post(f.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=Object.keys(ae).filter((e=>e!==oe.voice)),we=e=>({verify:Ie((t=>N(e.post(s.verify,{token:t})))),signIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>N(e.post(M(s.signIn,n),{loginId:t,URI:o,loginOptions:i},{token:a}))))})),{}),signUp:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>N(e.post(M(s.signUp,n),{loginId:t,URI:o,user:i,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i)=>N(e.post(M(s.signUpOrIn,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:ke(((t,n,o,i,a)=>N(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:o},a),{token:i})))),phone:Object.keys(oe).filter((e=>e!==oe.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i,a,r)=>N(e.post(M(s.update.phone,n),Object.assign({loginId:t,phone:o,URI:i},r),{token:a}))))})),{})}});var je;!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"}(je||(je={}));const Ue=W(X("code")),Re=e=>({start:Object.assign(((t,n,s,o)=>N(e.post(i.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:o}))),Object.keys(je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>N(e.post(i.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{})),exchange:Ue((t=>N(e.post(i.exchange,{code:t})))),startNative:(t,n)=>N(e.post(i.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,o,a)=>N(e.post(i.finishNative,{provider:t,stateId:n,user:s,code:o,idToken:a}))}),xe=X("loginId"),Pe=W(xe,X("code")),qe=W(xe),$e=W(xe,te("phone")),Ee=W(xe,ee("email")),Se=e=>({verify:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Pe(((t,o)=>N(e.post(M(n.verify,s),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i)=>N(e.post(M(n.signIn,s),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i)=>N(e.post(M(n.signUp,s),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o)=>N(e.post(M(n.signUpOrIn,s),{loginId:t,loginOptions:o}))))})),{}),update:{email:Ee(((t,s,o,i)=>N(e.post(n.update.email,Object.assign({loginId:t,email:s},i),{token:o})))),phone:Object.keys(oe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,o,i,a)=>N(e.post(M(n.update.phone,s),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),Ae=W(X("tenant")),Te=W(X("code")),Me=e=>({start:Ae(((t,n,s,o)=>N(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:Te((t=>N(e.post(a.exchange,{code:t}))))}),Ne=X("loginId"),Le=W(Ne,X("code")),He=W(Ne),_e=W(Ne),ze=e=>({signUp:He(((t,n)=>N(e.post(r.signUp,{loginId:t,user:n})))),verify:Le(((t,n,s,o)=>N(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:_e(((t,n)=>N(e.post(r.update,{loginId:t},{token:n}))))}),Ce=X("loginId"),Je=X("newPassword"),De=W(Ce,X("password")),Ze=W(Ce),Be=W(Ce,Je),Fe=W(Ce,X("oldPassword"),Je),Ke=e=>({signUp:De(((t,n,s)=>N(e.post(u.signUp,{loginId:t,password:n,user:s})))),signIn:De(((t,n)=>N(e.post(u.signIn,{loginId:t,password:n})))),sendReset:Ze(((t,n,s)=>N(e.post(u.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Be(((t,n,s)=>N(e.post(u.update,{loginId:t,newPassword:n},{token:s})))),replace:Fe(((t,n,s)=>N(e.post(u.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>N(e.get(u.policy))}),Qe=[K(`"${"loginId"}" must be a string`)];const Ve=X("loginId"),Ye=X("origin"),Ge=W(Ve,Ye,X("name")),We=W(Ve,Ye),Xe=W(Qe,Ye),et=W(Ve,Ye,X("token")),tt=W(X("transactionId"),X("response")),nt=e=>({signUp:{start:Ge(((t,n,s)=>N(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:tt(((t,n)=>N(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Xe(((t,n,s,o)=>N(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:tt(((t,n)=>N(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:We(((t,n)=>N(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:et(((t,n,s)=>N(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:tt(((t,n)=>N(e.post(d.update.finish,{transactionId:t,response:n}))))}}),st=W(X("token")),ot=W((e=>[V(`"${e}" must be string or undefined`)])("token"));var it,at;var rt=W([(it="projectId",at=X("projectId"),L(J(it,at))())])((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||I,projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:se(r),otp:Se(r),magicLink:we(r),enchantedLink:ge(r),oauth:Re(r),saml:Me(r),totp:ze(r),webauthn:nt(r),password:Ke(r),flow:fe(r),refresh:ot((e=>N(r.post(l,{},{token:e})))),selectTenant:W([K("tenantId")],[V('"token" must be string or undefined')])(((e,t)=>N(r.post(p,{tenant:e},{token:t})))),logout:ot((e=>N(r.post(c,{},{token:e})))),logoutAll:ot((e=>N(r.post(g,{},{token:e})))),me:ot((e=>N(r.get(h,{token:e})))),history:ot((e=>N(r.get(v,{token:e})))),isJwtExpired:st(E),getTenants:st(S),getJwtPermissions:st(A),getJwtRoles:st(T),httpClient:r};var r})));var dt=Object.assign(rt,{DeliveryMethods:ae});exports.HttpStatusCodes=P,exports.default=dt,exports.transformResponse=N,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

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

sms = "sms",
voice = "voice",
whatsapp = "whatsapp"

@@ -151,2 +152,3 @@ }

readonly sms: DeliveryPhone.sms;
readonly voice: DeliveryPhone.voice;
readonly whatsapp: DeliveryPhone.whatsapp;

@@ -421,2 +423,3 @@ };

sms: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
voice: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
whatsapp: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;

@@ -427,2 +430,3 @@ email: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;

sms: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;

@@ -433,2 +437,3 @@ email: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedEmail>>;

sms: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;

@@ -439,2 +444,3 @@ email: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedEmail>>;

sms: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;

@@ -452,2 +458,3 @@ email: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedEmail>>;

sms: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;

@@ -458,2 +465,3 @@ email: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedEmail>>;

sms: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;

@@ -464,2 +472,3 @@ email: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedEmail>>;

sms: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;

@@ -542,2 +551,3 @@ email: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedEmail>>;

readonly sms: DeliveryPhone.sms;
readonly voice: DeliveryPhone.voice;
readonly whatsapp: DeliveryPhone.whatsapp;

@@ -544,0 +554,0 @@ };

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

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