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 0.0.41-alpha.50 to 0.0.41-alpha.51

2

dist/cjs/index.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t=require("lodash.get");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(e),o=n(t),i={exchange:"/v1/auth/accesskey/exchange"},a={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"},r={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"},u={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"},d={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange"},l={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},c={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},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"}},g="/v1/auth/refresh",h="/v1/auth/logout",v="/v1/auth/logoutall",f="/v1/auth/me",m={start:"/v1/flow/start",next:"/v1/flow/next"};const b=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},I=(e,t)=>{const n=t||fetch;return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>b().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await(e.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),b().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var k;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(k||(k={}));const y=(...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}),{})),O=e=>void 0===e?void 0:JSON.stringify(e),w=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},j=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i})=>{const a=I(s),r=async s=>{const r=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:u,body:d,headers:l,queryParams:c,method:p,token:g}=r,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const s=new URL(e,t);return n&&(s.search=new URLSearchParams(n).toString()),s})({path:u,baseUrl:e,queryParams:c}),{headers:y(w(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.50"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:O(d),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:s}={})=>r({path:e,headers:t,queryParams:n,body:void 0,method:k.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>r({path:e,headers:n,queryParams:s,body:t,method:k.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>r({path:e,headers:n,queryParams:s,body:t,method:k.put,token:o}),delete:(e,t,{headers:n,queryParams:s,token:o}={})=>r({path:e,headers:n,queryParams:s,body:t,method:k.delete,token:o}),hooks:o}};var U={TOO_MANY_REQUESTS:429};function x(e,t,n){var s;let o=R(e);t&&(o=null===(s=o.tenants)||void 0===s?void 0:s[t]);const i=o[n];return Array.isArray(i)?i:[]}function R(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return s.default(e)}function P(e){const{exp:t}=R(e);return(new Date).getTime()/1e3>t}function q(e,t){return x(e,t,"permissions")}function E(e,t){return x(e,t,"roles")}const $=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function S(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===U.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const M=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),T=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),A=e=>t=>e.test(t),H=A(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=A(/^\+[1-9]{1}[0-9]{3,14}$/),L=M(H,'"{val}" is not a valid email'),_=M(C,'"{val}" is not a valid phone number'),z=M((J=1,e=>e.length>=J),"Minimum length is 1");var J;const N=M((e=>"string"==typeof e),"Input is not a string"),D=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>T(...e).validate(n[t]))),t(...n)),Z=e=>[N(`"${e}" must be a string`),z(`"${e}" must not be empty`)],B=e=>[N(`"${e}" must be a string`),L()],F=e=>[N(`"${e}" must be a string`),_()],K=D(Z("accessKey")),Q=e=>({exchange:K((t=>S(e.post(i.exchange,{},{token:t}))))});var Y,G,W,V;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Y||(Y={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(G||(G={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(W||(W={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(V||(V={}));const X=Z("loginId"),ee=Z("uri"),te=D(Z("token")),ne=D(X,ee),se=D(Z("pendingRef")),oe=D(X,B("email"),ee),ie=e=>({verify:te((t=>S(e.post(u.verify,{token:t})))),signIn:ne(((t,n,s,o)=>S(e.post($(u.signIn,G.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:ne(((t,n)=>S(e.post($(u.signUpOrIn,G.email),{loginId:t,URI:n})))),signUp:ne(((t,n,s)=>S(e.post($(u.signUp,G.email),{loginId:t,URI:n,user:s})))),waitForSession:se(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const r=setInterval((async()=>{const n=await e.post(u.session,{pendingRef:t});n.ok&&(clearInterval(r),a&&clearTimeout(a),s(S(Promise.resolve(n))))}),o);a=setTimeout((()=>{s({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(r)}),i)})))),update:{email:oe(((t,n,s,o)=>S(e.post(u.update.email,{loginId:t,email:n,URI:s},{token:o}))))}}),ae=D(Z("flowId")),re=D(Z("executionId"),Z("stepId"),Z("interactionId")),ue=e=>({start:ae(((t,n,s,o)=>S(e.post(m.start,{flowId:t,options:n,interactionId:s,input:o})))),next:re(((t,n,s,o)=>S(e.post(m.next,{executionId:t,stepId:n,interactionId:s,input:o}))))}),de=Z("loginId"),le=Z("uri"),ce=D(Z("token")),pe=D(de,le),ge=D(de,F("phone"),le),he=D(de,B("email"),le),ve=e=>({verify:ce((t=>S(e.post(r.verify,{token:t})))),signIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s,o,i)=>S(e.post($(r.signIn,n),{loginId:t,URI:s,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s,o)=>S(e.post($(r.signUp,n),{loginId:t,URI:s,user:o}))))})),{}),signUpOrIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s)=>S(e.post($(r.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:he(((t,n,s,o)=>S(e.post(r.update.email,{loginId:t,email:n,URI:s},{token:o})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ge(((t,s,o,i)=>S(e.post($(r.update.phone,n),{loginId:t,phone:s,URI:o},{token:i}))))})),{})}});var fe;!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"}(fe||(fe={}));const me=D(Z("code")),be=e=>({start:Object.keys(fe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:s=!1}={},o,i)=>{const a=await e.post(d.start,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!s||!a.ok)return S(Promise.resolve(a));const{url:r}=await a.json();window.location.href=r}})),{}),exchange:me((t=>S(e.post(d.exchange,{code:t}))))});var Ie;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(Ie||(Ie={}));const ke=Z("loginId"),ye=D(ke,Z("code")),Oe=D(ke),we=D(ke,F("phone")),je=D(ke,B("email")),Ue=e=>({verify:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,s)=>S(e.post($(a.verify,n),{code:s,loginId:t}))))})),{}),signIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,s,o)=>S(e.post($(a.signIn,n),{loginId:t,loginOptions:s},{token:o}))))})),{}),signUp:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,s)=>S(e.post($(a.signUp,n),{loginId:t,user:s}))))})),{}),signUpOrIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe((t=>S(e.post($(a.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:je(((t,n,s)=>S(e.post(a.update.email,{loginId:t,email:n},{token:s})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,s,o)=>S(e.post($(a.update.phone,n),{loginId:t,phone:s},{token:o}))))})),{})}}),xe=D(Z("tenant")),Re=D(Z("code")),Pe=e=>({start:xe((async(t,n,{redirect:s=!1}={},o,i)=>{const a=await e.post(l.start,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!s||!a.ok)return S(Promise.resolve(a));const{url:r}=await a.json();window.location.href=r})),exchange:Re((t=>S(e.post(l.exchange,{code:t}))))}),qe=Z("loginId"),Ee=D(qe,Z("code")),$e=D(qe),Se=D(qe),Me=e=>({signUp:$e(((t,n)=>S(e.post(c.signUp,{loginId:t,user:n})))),verify:Ee(((t,n,s,o)=>S(e.post(c.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:Se(((t,n)=>S(e.post(c.update,{loginId:t},{token:n}))))}),Te=[N(`"${"loginId"}" must be a string`)];const Ae=Z("loginId"),He=Z("origin"),Ce=D(Ae,He,Z("name")),Le=D(Ae,He),_e=D(Te,He),ze=D(Ae,He,Z("token")),Je=D(Z("transactionId"),Z("response")),Ne=e=>({signUp:{start:Ce(((t,n,s)=>S(e.post(p.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Je(((t,n)=>S(e.post(p.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:_e(((t,n,s,o)=>S(e.post(p.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Je(((t,n)=>S(e.post(p.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Le(((t,n)=>S(e.post(p.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:ze(((t,n,s)=>S(e.post(p.update.start,{loginId:t,origin:n},{token:s})))),finish:Je(((t,n)=>S(e.post(p.update.finish,{transactionId:t,response:n}))))}}),De=D(Z("token"));var Ze,Be;var Fe=D([(Ze="projectId",Be=Z("projectId"),M(((e,t)=>n=>T(...t).validate(o.default(n,e)))(Ze,Be))())])((e=>t=>{var n,s;const o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]),i=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);return e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))})((({projectId:e,logger:t=console,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={}})=>{return a=j({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i}}),{accessKey:Q(a),otp:Ue(a),magicLink:ve(a),enchantedLink:ie(a),oauth:be(a),saml:Pe(a),totp:Me(a),webauthn:Ne(a),flow:ue(a),refresh:e=>S(a.post(g,{},{token:e})),logout:e=>S(a.post(h,{},{token:e})),logoutAll:e=>S(a.post(v,{},{token:e})),me:e=>S(a.get(f,{token:e})),isJwtExpired:De(P),getJwtPermissions:De(q),getJwtRoles:De(E),httpClient:a};var a})));var Ke=Object.assign(Fe,{DeliveryMethods:G});exports.HttpStatusCodes=U,exports.addHooksToConfig=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,s)=>{var o;return n[s]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[s])||[]).concat((null==t?void 0:t[s])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},exports.default=Ke,exports.transformResponse=S,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t=require("lodash.get");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(e),o=n(t),i={exchange:"/v1/auth/accesskey/exchange"},a={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"},r={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"},u={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"},d={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange"},l={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},c={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},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"}},g="/v1/auth/refresh",h="/v1/auth/logout",v="/v1/auth/logoutall",f="/v1/auth/me",m={start:"/v1/flow/start",next:"/v1/flow/next"};const b=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},I=(e,t)=>{const n=t||fetch;return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>b().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await(e.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),b().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var k;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(k||(k={}));const y=(...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}),{})),O=e=>void 0===e?void 0:JSON.stringify(e),w=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},j=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i})=>{const a=I(s),r=async s=>{const r=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:u,body:d,headers:l,queryParams:c,method:p,token:g}=r,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const s=new URL(e,t);return n&&(s.search=new URLSearchParams(n).toString()),s})({path:u,baseUrl:e,queryParams:c}),{headers:y(w(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.51"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:O(d),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:s}={})=>r({path:e,headers:t,queryParams:n,body:void 0,method:k.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>r({path:e,headers:n,queryParams:s,body:t,method:k.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>r({path:e,headers:n,queryParams:s,body:t,method:k.put,token:o}),delete:(e,t,{headers:n,queryParams:s,token:o}={})=>r({path:e,headers:n,queryParams:s,body:t,method:k.delete,token:o}),hooks:o}};var U={TOO_MANY_REQUESTS:429};function x(e,t,n){var s;let o=R(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 R(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return s.default(e)}function P(e){const{exp:t}=R(e);return(new Date).getTime()/1e3>t}function q(e,t){return x(e,t,"permissions")}function E(e,t){return x(e,t,"roles")}const $=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function S(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===U.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const M=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),T=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),A=e=>t=>e.test(t),H=A(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=A(/^\+[1-9]{1}[0-9]{3,14}$/),L=M(H,'"{val}" is not a valid email'),_=M(C,'"{val}" is not a valid phone number'),z=M((J=1,e=>e.length>=J),"Minimum length is 1");var J;const N=M((e=>"string"==typeof e),"Input is not a string"),D=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>T(...e).validate(n[t]))),t(...n)),Z=e=>[N(`"${e}" must be a string`),z(`"${e}" must not be empty`)],B=e=>[N(`"${e}" must be a string`),L()],F=e=>[N(`"${e}" must be a string`),_()],K=D(Z("accessKey")),Q=e=>({exchange:K((t=>S(e.post(i.exchange,{},{token:t}))))});var Y,G,W,V;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Y||(Y={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(G||(G={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(W||(W={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(V||(V={}));const X=Z("loginId"),ee=Z("uri"),te=D(Z("token")),ne=D(X,ee),se=D(Z("pendingRef")),oe=D(X,B("email"),ee),ie=e=>({verify:te((t=>S(e.post(u.verify,{token:t})))),signIn:ne(((t,n,s,o)=>S(e.post($(u.signIn,G.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:ne(((t,n)=>S(e.post($(u.signUpOrIn,G.email),{loginId:t,URI:n})))),signUp:ne(((t,n,s)=>S(e.post($(u.signUp,G.email),{loginId:t,URI:n,user:s})))),waitForSession:se(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const r=setInterval((async()=>{const n=await e.post(u.session,{pendingRef:t});n.ok&&(clearInterval(r),a&&clearTimeout(a),s(S(Promise.resolve(n))))}),o);a=setTimeout((()=>{s({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(r)}),i)})))),update:{email:oe(((t,n,s,o)=>S(e.post(u.update.email,{loginId:t,email:n,URI:s},{token:o}))))}}),ae=D(Z("flowId")),re=D(Z("executionId"),Z("stepId"),Z("interactionId")),ue=e=>({start:ae(((t,n,s,o)=>S(e.post(m.start,{flowId:t,options:n,interactionId:s,input:o})))),next:re(((t,n,s,o)=>S(e.post(m.next,{executionId:t,stepId:n,interactionId:s,input:o}))))}),de=Z("loginId"),le=Z("uri"),ce=D(Z("token")),pe=D(de,le),ge=D(de,F("phone"),le),he=D(de,B("email"),le),ve=e=>({verify:ce((t=>S(e.post(r.verify,{token:t})))),signIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s,o,i)=>S(e.post($(r.signIn,n),{loginId:t,URI:s,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s,o)=>S(e.post($(r.signUp,n),{loginId:t,URI:s,user:o}))))})),{}),signUpOrIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s)=>S(e.post($(r.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:he(((t,n,s,o)=>S(e.post(r.update.email,{loginId:t,email:n,URI:s},{token:o})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ge(((t,s,o,i)=>S(e.post($(r.update.phone,n),{loginId:t,phone:s,URI:o},{token:i}))))})),{})}});var fe;!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"}(fe||(fe={}));const me=D(Z("code")),be=e=>({start:Object.keys(fe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:s=!1}={},o,i)=>{const a=await e.post(d.start,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!s||!a.ok)return S(Promise.resolve(a));const{url:r}=await a.json();window.location.href=r}})),{}),exchange:me((t=>S(e.post(d.exchange,{code:t}))))});var Ie;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(Ie||(Ie={}));const ke=Z("loginId"),ye=D(ke,Z("code")),Oe=D(ke),we=D(ke,F("phone")),je=D(ke,B("email")),Ue=e=>({verify:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,s)=>S(e.post($(a.verify,n),{code:s,loginId:t}))))})),{}),signIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,s,o)=>S(e.post($(a.signIn,n),{loginId:t,loginOptions:s},{token:o}))))})),{}),signUp:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe(((t,s)=>S(e.post($(a.signUp,n),{loginId:t,user:s}))))})),{}),signUpOrIn:Object.keys(G).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Oe((t=>S(e.post($(a.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:je(((t,n,s)=>S(e.post(a.update.email,{loginId:t,email:n},{token:s})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:we(((t,s,o)=>S(e.post($(a.update.phone,n),{loginId:t,phone:s},{token:o}))))})),{})}}),xe=D(Z("tenant")),Re=D(Z("code")),Pe=e=>({start:xe((async(t,n,{redirect:s=!1}={},o,i)=>{const a=await e.post(l.start,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!s||!a.ok)return S(Promise.resolve(a));const{url:r}=await a.json();window.location.href=r})),exchange:Re((t=>S(e.post(l.exchange,{code:t}))))}),qe=Z("loginId"),Ee=D(qe,Z("code")),$e=D(qe),Se=D(qe),Me=e=>({signUp:$e(((t,n)=>S(e.post(c.signUp,{loginId:t,user:n})))),verify:Ee(((t,n,s,o)=>S(e.post(c.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:Se(((t,n)=>S(e.post(c.update,{loginId:t},{token:n}))))}),Te=[N(`"${"loginId"}" must be a string`)];const Ae=Z("loginId"),He=Z("origin"),Ce=D(Ae,He,Z("name")),Le=D(Ae,He),_e=D(Te,He),ze=D(Ae,He,Z("token")),Je=D(Z("transactionId"),Z("response")),Ne=e=>({signUp:{start:Ce(((t,n,s)=>S(e.post(p.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Je(((t,n)=>S(e.post(p.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:_e(((t,n,s,o)=>S(e.post(p.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Je(((t,n)=>S(e.post(p.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Le(((t,n)=>S(e.post(p.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:ze(((t,n,s)=>S(e.post(p.update.start,{loginId:t,origin:n},{token:s})))),finish:Je(((t,n)=>S(e.post(p.update.finish,{transactionId:t,response:n}))))}}),De=D(Z("token"));var Ze,Be;var Fe=D([(Ze="projectId",Be=Z("projectId"),M(((e,t)=>n=>T(...t).validate(o.default(n,e)))(Ze,Be))())])((e=>t=>{var n,s;const o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]),i=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);return e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))})((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={}})=>{return a=j({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i}}),{accessKey:Q(a),otp:Ue(a),magicLink:ve(a),enchantedLink:ie(a),oauth:be(a),saml:Pe(a),totp:Me(a),webauthn:Ne(a),flow:ue(a),refresh:e=>S(a.post(g,{},{token:e})),logout:e=>S(a.post(h,{},{token:e})),logoutAll:e=>S(a.post(v,{},{token:e})),me:e=>S(a.get(f,{token:e})),isJwtExpired:De(P),getJwtPermissions:De(q),getJwtRoles:De(E),httpClient:a};var a})));var Ke=Object.assign(Fe,{DeliveryMethods:G});exports.HttpStatusCodes=U,exports.addHooksToConfig=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,s)=>{var o;return n[s]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[s])||[]).concat((null==t?void 0:t[s])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},exports.default=Ke,exports.transformResponse=S,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);
//# sourceMappingURL=index.cjs.js.map

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

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

@@ -5,0 +5,0 @@ "module": "dist/index.esm.js",

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