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

@descope/core-js-sdk

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

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

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

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