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.38 to 0.0.41-alpha.39

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

@@ -19,3 +19,3 @@ declare type SdkFn$1 = (...args: any[]) => Promise<SdkResponse<ResponseData>>;

declare type UserResponse = User & {
externalIds: string[];
loginIds: string[];
userId: string;

@@ -22,0 +22,0 @@ verifiedEmail?: boolean;

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