@descope/core-js-sdk
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t=require("lodash.get"),n={exchange:"/v1/auth/accesskey/exchange"},s={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},o={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},i={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},a={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange"},r={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},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,fetch:a})=>{const r=f(s,a),u=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:u,body:d,headers:l,queryParams:c,method:p,token:g}=a,h=await r((({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":"1.0.2"},(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}={})=>u({path:e,headers:t,queryParams:n,body:void 0,method:m.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>u({path:e,headers:n,queryParams:s,body:t,method:m.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>u({path:e,headers:n,queryParams:s,body:t,method:m.put,token:o}),delete:(e,t,{headers:n,queryParams:s,token:o}={})=>u({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 x(e,t){return w(e,t,"permissions")}function R(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'),H=E(T,'"{val}" is not a valid phone number'),C=E((L=1,e=>e.length>=L),"Minimum length is 1");var L;const _=E((e=>"string"==typeof e),"Input is not a string"),z=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>$(...e).validate(n[t]))),t(...n)),J=e=>[_(`"${e}" must be a string`),C(`"${e}" must not be empty`)],N=e=>[_(`"${e}" must be a string`),A()],D=e=>[_(`"${e}" must be a string`),H()],Z=z(J("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=J("loginId"),W=z(J("token")),V=z(G),X=z(J("pendingRef")),ee=z(G,N("email")),te=e=>({verify:W((t=>q(e.post(i.verify,{token:t})))),signIn:V(((t,n,s,o)=>q(e.post(P(i.signIn,K.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:V(((t,n)=>q(e.post(P(i.signUpOrIn,K.email),{loginId:t,URI:n})))),signUp:V(((t,n,s)=>q(e.post(P(i.signUp,K.email),{loginId:t,URI:n,user:s})))),waitForSession:X(((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:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(u)}),a)})))),update:{email:ee(((t,n,s,o)=>q(e.post(i.update.email,{loginId:t,email:n,URI:s},{token:o}))))}}),ne=z(J("flowId")),se=z(J("executionId"),J("stepId"),J("interactionId")),oe=e=>({start:ne(((t,n,s,o,i)=>q(e.post(h.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,input:i})))),next:se(((t,n,s,o)=>q(e.post(h.next,{executionId:t,stepId:n,interactionId:s,input:o}))))}),ie=J("loginId"),ae=z(J("token")),re=z(ie),ue=z(ie,D("phone")),de=z(ie,N("email")),le=e=>({verify:ae((t=>q(e.post(o.verify,{token:t})))),signIn:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:re(((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]:re(((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]:re(((t,s)=>q(e.post(P(o.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:de(((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]:ue(((t,s,i,a)=>q(e.post(P(o.update.phone,n),{loginId:t,phone:s,URI:i},{token:a}))))})),{})}});var ce;!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"}(ce||(ce={}));const pe=z(J("code")),ge=e=>({start:Object.keys(ce).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:pe((t=>q(e.post(a.exchange,{code:t}))))});var he;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(he||(he={}));const ve=J("loginId"),fe=z(ve,J("code")),me=z(ve),Ie=z(ve,D("phone")),be=z(ve,N("email")),ke=e=>({verify:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:fe(((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]:me(((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]:me(((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]:me((t=>q(e.post(P(s.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:be(((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]:Ie(((t,o,i)=>q(e.post(P(s.update.phone,n),{loginId:t,phone:o},{token:i}))))})),{})}}),ye=z(J("tenant")),Oe=z(J("code")),we=e=>({start:ye((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:Oe((t=>q(e.post(r.exchange,{code:t}))))}),je=J("loginId"),Ue=z(je,J("code")),xe=z(je),Re=z(je),Pe=e=>({signUp:xe(((t,n)=>q(e.post(u.signUp,{loginId:t,user:n})))),verify:Ue(((t,n,s,o)=>q(e.post(u.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:Re(((t,n)=>q(e.post(u.update,{loginId:t},{token:n}))))}),qe=[_(`"${"loginId"}" must be a string`)];const Ee=J("loginId"),$e=J("origin"),Se=z(Ee,$e,J("name")),Me=z(Ee,$e),Te=z(qe,$e),Ae=z(Ee,$e,J("token")),He=z(J("transactionId"),J("response")),Ce=e=>({signUp:{start:Se(((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:Te(((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:Me(((t,n)=>q(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:Ae(((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}))))}}),Le=z(J("token"));var _e,ze;var Je=z([(_e="projectId",ze=J("projectId"),E(((e,n)=>s=>$(...n).validate(t(s,e)))(_e,ze))())])((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={},fetch:a})=>{return r=y({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:B(r),otp:ke(r),magicLink:le(r),enchantedLink:te(r),oauth:ge(r),saml:we(r),totp:Pe(r),webauthn:Ce(r),flow:oe(r),refresh:e=>q(r.post(l,{},{token:e})),logout:e=>q(r.post(c,{},{token:e})),logoutAll:e=>q(r.post(p,{},{token:e})),me:e=>q(r.get(g,{token:e})),isJwtExpired:Le(U),getJwtPermissions:Le(x),getJwtRoles:Le(R),httpClient:r};var r})));var Ne=Object.assign(Je,{DeliveryMethods:K});exports.HttpStatusCodes=O,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=Ne,exports.transformResponse=q,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t=require("lodash.get"),n={exchange:"/v1/auth/accesskey/exchange"},s={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},o={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},i={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},a={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange"},r={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},d={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},u={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},p={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},l="/v1/auth/refresh",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v={start:"/v1/flow/start",next:"/v1/flow/next"};const f=()=>{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")}},m=(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=>f().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)),f().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var I;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(I||(I={}));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}),{})),b=e=>void 0===e?void 0:JSON.stringify(e),k=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},w=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i,fetch:a})=>{const r=m(s,a),d=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:d,body:u,headers:p,queryParams:l,method:c,token:g}=a,h=await r((({path:e,baseUrl:t,queryParams:n})=>{const s=new URL(e,t);return n&&(s.search=new URLSearchParams(n).toString()),s})({path:d,baseUrl:e,queryParams:l}),{headers:y(k(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.3"},(null==n?void 0:n.baseHeaders)||{},p),method:c,body:b(u),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}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:I.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:I.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:I.put,token:o}),delete:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:I.delete,token:o}),hooks:o}};var O={TOO_MANY_REQUESTS:429};function U(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 P(e){const{exp:t}=j(e);return(new Date).getTime()/1e3>t}function x(e,t){return U(e,t,"permissions")}function R(e,t){return U(e,t,"roles")}const q=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function E(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,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)}),M=e=>t=>e.test(t),T=M(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),A=M(/^\+[1-9]{1}[0-9]{3,14}$/),H=$(T,'"{val}" is not a valid email'),C=$(A,'"{val}" is not a valid phone number'),L=$((_=1,e=>e.length>=_),"Minimum length is 1");var _;const z=$((e=>"string"==typeof e),"Input is not a string"),J=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>S(...e).validate(n[t]))),t(...n)),N=e=>[z(`"${e}" must be a string`),L(`"${e}" must not be empty`)],D=e=>[z(`"${e}" must be a string`),H()],Z=e=>[z(`"${e}" must be a string`),C()],B=J(N("accessKey")),F=e=>({exchange:B((t=>E(e.post(n.exchange,{},{token:t}))))});var K,Q,Y,G;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(K||(K={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Q||(Q={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Y||(Y={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(G||(G={}));const W=N("loginId"),V=J(N("token")),X=J(W),ee=J(N("pendingRef")),te=J(W,D("email")),ne=e=>({verify:V((t=>E(e.post(i.verify,{token:t})))),signIn:X(((t,n,s,o)=>E(e.post(q(i.signIn,Q.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:X(((t,n)=>E(e.post(q(i.signUpOrIn,Q.email),{loginId:t,URI:n})))),signUp:X(((t,n,s)=>E(e.post(q(i.signUp,Q.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 d=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(E(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:te(((t,n,s,o)=>E(e.post(i.update.email,{loginId:t,email:n,URI:s},{token:o}))))}}),se=J(N("flowId")),oe=J(N("executionId"),N("stepId"),N("interactionId")),ie=e=>({start:se(((t,n,s,o,i)=>E(e.post(v.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,input:i})))),next:oe(((t,n,s,o)=>E(e.post(v.next,{executionId:t,stepId:n,interactionId:s,input:o}))))}),ae=N("loginId"),re=J(N("token")),de=J(ae),ue=J(ae,Z("phone")),pe=J(ae,D("email")),le=e=>({verify:re((t=>E(e.post(o.verify,{token:t})))),signIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:de(((t,s,i,a)=>E(e.post(q(o.signIn,n),{loginId:t,URI:s,loginOptions:i},{token:a}))))})),{}),signUp:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:de(((t,s,i)=>E(e.post(q(o.signUp,n),{loginId:t,URI:s,user:i}))))})),{}),signUpOrIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:de(((t,s)=>E(e.post(q(o.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:pe(((t,n,s,i)=>E(e.post(o.update.email,{loginId:t,email:n,URI:s},{token:i})))),phone:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ue(((t,s,i,a)=>E(e.post(q(o.update.phone,n),{loginId:t,phone:s,URI:i},{token:a}))))})),{})}});var ce;!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"}(ce||(ce={}));const ge=J(N("code")),he=e=>({start:Object.keys(ce).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 E(Promise.resolve(r));const{url:d}=await r.json();window.location.href=d}})),{}),exchange:ge((t=>E(e.post(a.exchange,{code:t}))))});var ve;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(ve||(ve={}));const fe=N("loginId"),me=J(fe,N("code")),Ie=J(fe),ye=J(fe,Z("phone")),be=J(fe,D("email")),ke=e=>({verify:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:me(((t,o)=>E(e.post(q(s.verify,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie(((t,o,i)=>E(e.post(q(s.signIn,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie(((t,o)=>E(e.post(q(s.signUp,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie((t=>E(e.post(q(s.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:be(((t,n,o)=>E(e.post(s.update.email,{loginId:t,email:n},{token:o})))),phone:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i)=>E(e.post(q(s.update.phone,n),{loginId:t,phone:o},{token:i}))))})),{})}}),we=J(N("tenant")),Oe=J(N("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 E(Promise.resolve(a));const{url:d}=await a.json();window.location.href=d})),exchange:Oe((t=>E(e.post(r.exchange,{code:t}))))}),je=N("loginId"),Pe=J(je,N("code")),xe=J(je),Re=J(je),qe=e=>({signUp:xe(((t,n)=>E(e.post(d.signUp,{loginId:t,user:n})))),verify:Pe(((t,n,s,o)=>E(e.post(d.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:Re(((t,n)=>E(e.post(d.update,{loginId:t},{token:n}))))}),Ee=N("loginId"),$e=N("newPassword"),Se=J(Ee,N("password")),Me=J(Ee),Te=J(Ee,$e),Ae=J(Ee,N("oldPassword"),$e),He=e=>({signUp:Se(((t,n,s)=>E(e.post(p.signUp,{loginId:t,password:n,user:s})))),signIn:Se(((t,n)=>E(e.post(p.signIn,{loginId:t,password:n})))),sendReset:Me(((t,n)=>E(e.post(p.sendReset,{loginId:t,redirectUrl:n})))),update:Te(((t,n,s)=>E(e.post(p.update,{loginId:t,newPassword:n},{token:s})))),replace:Ae(((t,n,s)=>E(e.post(p.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>E(e.get(p.policy))}),Ce=[z(`"${"loginId"}" must be a string`)];const Le=N("loginId"),_e=N("origin"),ze=J(Le,_e,N("name")),Je=J(Le,_e),Ne=J(Ce,_e),De=J(Le,_e,N("token")),Ze=J(N("transactionId"),N("response")),Be=e=>({signUp:{start:ze(((t,n,s)=>E(e.post(u.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Ze(((t,n)=>E(e.post(u.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Ne(((t,n,s,o)=>E(e.post(u.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Ze(((t,n)=>E(e.post(u.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Je(((t,n)=>E(e.post(u.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:De(((t,n,s)=>E(e.post(u.update.start,{loginId:t,origin:n},{token:s})))),finish:Ze(((t,n)=>E(e.post(u.update.finish,{transactionId:t,response:n}))))}}),Fe=J(N("token"));var Ke,Qe;var Ye=J([(Ke="projectId",Qe=N("projectId"),$(((e,n)=>s=>S(...n).validate(t(s,e)))(Ke,Qe))())])((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={},fetch:a})=>{return r=w({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:F(r),otp:ke(r),magicLink:le(r),enchantedLink:ne(r),oauth:he(r),saml:Ue(r),totp:qe(r),webauthn:Be(r),password:He(r),flow:ie(r),refresh:e=>E(r.post(l,{},{token:e})),logout:e=>E(r.post(c,{},{token:e})),logoutAll:e=>E(r.post(g,{},{token:e})),me:e=>E(r.get(h,{token:e})),isJwtExpired:Fe(P),getJwtPermissions:Fe(x),getJwtRoles:Fe(R),httpClient:r};var r})));var Ge=Object.assign(Ye,{DeliveryMethods:Q});exports.HttpStatusCodes=O,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=Ge,exports.transformResponse=E,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 |
@@ -15,2 +15,8 @@ declare type JSONSerializable = string | number | boolean | null | Array<JSONSerializable>; | ||
declare type AuthMethod = 'magiclink' | 'enchantedlink' | 'otp' | 'totp' | 'oauth' | 'saml' | 'webauthn'; | ||
declare type MaskedPhone = { | ||
maskedPhone: string; | ||
}; | ||
declare type MaskedEmail = { | ||
maskedEmail: string; | ||
}; | ||
/** User base details from Descope API */ | ||
@@ -72,3 +78,6 @@ declare type User = { | ||
linkId: string; | ||
/** Email to which the link was sent to */ | ||
maskedEmail: string; | ||
}; | ||
declare type MaskedAddress<T> = T extends DeliveryMethods.email ? MaskedEmail : T extends DeliveryMethods.sms ? MaskedPhone : T extends DeliveryMethods.whatsapp ? MaskedPhone : never; | ||
/** URL response to redirect user in case of OAuth or SSO */ | ||
@@ -84,2 +93,17 @@ declare type URLResponse = { | ||
}; | ||
/** Password reset response with details according to response method */ | ||
declare type PasswordResetResponse = { | ||
resetMethod: string; | ||
pendingRef?: string; | ||
linkId?: string; | ||
maskedEmail: string; | ||
}; | ||
/** A subset of the password policy that can be checked on the client side for better UX */ | ||
declare type PasswordPolicyResponse = { | ||
minLength: number; | ||
lowercase: boolean; | ||
uppercase: boolean; | ||
number: boolean; | ||
nonAlphanumeric: boolean; | ||
}; | ||
/** All delivery methods currently supported */ | ||
@@ -173,5 +197,5 @@ declare enum DeliveryMethods { | ||
declare type SignInFn = (loginId: string, uri: string) => Promise<SdkResponse<never>>; | ||
declare type SignUpFn = (loginId: string, uri: string, user?: User) => Promise<SdkResponse<never>>; | ||
declare type UpdatePhoneFn = (loginId: string, phone: string) => Promise<SdkResponse<never>>; | ||
declare type SignInFn<T> = (loginId: string, uri: string) => Promise<SdkResponse<MaskedAddress<T>>>; | ||
declare type SignUpFn<T> = (loginId: string, uri: string, user?: User) => Promise<SdkResponse<MaskedAddress<T>>>; | ||
declare type UpdatePhoneFn = (loginId: string, phone: string) => Promise<SdkResponse<MaskedAddress<DeliveryMethods.sms>>>; | ||
@@ -347,8 +371,42 @@ /** Request configuration including headers, query params and token */ | ||
verify: Deliveries<(loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>>; | ||
signIn: Deliveries<(loginId: string) => Promise<SdkResponse<never>>>; | ||
signUp: Deliveries<(loginId: string, user?: User) => Promise<SdkResponse<never>>>; | ||
signUpOrIn: Deliveries<(loginId: string) => Promise<SdkResponse<never>>>; | ||
signIn: { | ||
email: (loginId: string) => Promise<SdkResponse<{ | ||
maskedEmail: string; | ||
}>>; | ||
sms: (loginId: string) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>; | ||
whatsapp: (loginId: string) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>; | ||
}; | ||
signUp: { | ||
email: (loginId: string, user?: User) => Promise<SdkResponse<{ | ||
maskedEmail: string; | ||
}>>; | ||
sms: (loginId: string, user?: User) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>; | ||
whatsapp: (loginId: string, user?: User) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>; | ||
}; | ||
signUpOrIn: { | ||
email: (loginId: string) => Promise<SdkResponse<{ | ||
maskedEmail: string; | ||
}>>; | ||
sms: (loginId: string) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>; | ||
whatsapp: (loginId: string) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>; | ||
}; | ||
update: { | ||
email: (loginId: string, email: string, token?: string) => Promise<SdkResponse<never>>; | ||
phone: Deliveries<(loginId: string, phone: string) => Promise<SdkResponse<never>>>; | ||
email: (loginId: string, email: string, token?: string) => Promise<SdkResponse<{ | ||
maskedEmail: string; | ||
}>>; | ||
phone: Deliveries<(loginId: string, phone: string) => Promise<SdkResponse<{ | ||
maskedPhone: string; | ||
}>>>; | ||
}; | ||
@@ -358,5 +416,17 @@ }; | ||
verify: (token: string) => Promise<SdkResponse<JWTResponse>>; | ||
signIn: Deliveries<SignInFn>; | ||
signUp: Deliveries<SignUpFn>; | ||
signUpOrIn: Deliveries<SignInFn>; | ||
signIn: { | ||
email: SignInFn<DeliveryMethods.email>; | ||
sms: SignInFn<DeliveryMethods.sms>; | ||
whatsapp: SignInFn<DeliveryMethods.whatsapp>; | ||
}; | ||
signUp: { | ||
email: SignUpFn<DeliveryMethods.email>; | ||
sms: SignUpFn<DeliveryMethods.sms>; | ||
whatsapp: SignUpFn<DeliveryMethods.whatsapp>; | ||
}; | ||
signUpOrIn: { | ||
email: SignInFn<DeliveryMethods.email>; | ||
sms: SignInFn<DeliveryMethods.sms>; | ||
whatsapp: SignInFn<DeliveryMethods.whatsapp>; | ||
}; | ||
update: { | ||
@@ -452,2 +522,10 @@ email: (loginId: string, email: string, URI?: string, token?: string) => Promise<SdkResponse<never>>; | ||
}; | ||
password: { | ||
signUp: (loginId: string, password: string, user?: User) => Promise<SdkResponse<JWTResponse>>; | ||
signIn: (loginId: string, password: string) => Promise<SdkResponse<JWTResponse>>; | ||
sendReset: (loginId: string, redirectUrl?: string) => Promise<SdkResponse<PasswordResetResponse>>; | ||
update: (loginId: string, newPassword: string, token?: string) => Promise<SdkResponse<never>>; | ||
replace: (loginId: string, oldPassword: string, newPassword: string) => Promise<SdkResponse<never>>; | ||
policy: () => Promise<SdkResponse<PasswordPolicyResponse>>; | ||
}; | ||
flow: { | ||
@@ -454,0 +532,0 @@ start: (flowId: string, options?: Options, conditionInteractionId?: string, interactionId?: string, input?: FlowInput) => Promise<SdkResponse<FlowResponse>>; |
@@ -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,fetch:a})=>{const r=f(s,a),u=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:u,body:d,headers:l,queryParams:c,method:p,token:g}=a,h=await r((({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":"1.0.2"},(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}={})=>u({path:e,headers:t,queryParams:n,body:void 0,method:m.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>u({path:e,headers:n,queryParams:s,body:t,method:m.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>u({path:e,headers:n,queryParams:s,body:t,method:m.put,token:o}),delete:(e,t,{headers:n,queryParams:s,token:o}={})=>u({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=N(C("token")),W=N(G),X=N(C("pendingRef")),ee=N(G,_("email")),te=e=>({verify:V((t=>q(e.post(i.verify,{token:t})))),signIn:W(((t,n,s,o)=>q(e.post(P(i.signIn,K.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:W(((t,n)=>q(e.post(P(i.signUpOrIn,K.email),{loginId:t,URI:n})))),signUp:W(((t,n,s)=>q(e.post(P(i.signUp,K.email),{loginId:t,URI:n,user:s})))),waitForSession:X(((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:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(u)}),a)})))),update:{email:ee(((t,n,s,o)=>q(e.post(i.update.email,{loginId:t,email:n,URI:s},{token:o}))))}}),ne=N(C("flowId")),se=N(C("executionId"),C("stepId"),C("interactionId")),oe=e=>({start:ne(((t,n,s,o,i)=>q(e.post(h.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,input:i})))),next:se(((t,n,s,o)=>q(e.post(h.next,{executionId:t,stepId:n,interactionId:s,input:o}))))}),ie=C("loginId"),ae=N(C("token")),re=N(ie),ue=N(ie,D("phone")),de=N(ie,_("email")),le=e=>({verify:ae((t=>q(e.post(o.verify,{token:t})))),signIn:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:re(((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]:re(((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]:re(((t,s)=>q(e.post(P(o.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:de(((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]:ue(((t,s,i,a)=>q(e.post(P(o.update.phone,n),{loginId:t,phone:s,URI:i},{token:a}))))})),{})}});var ce;!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"}(ce||(ce={}));const pe=N(C("code")),ge=e=>({start:Object.keys(ce).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:pe((t=>q(e.post(a.exchange,{code:t}))))});var he;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(he||(he={}));const ve=C("loginId"),fe=N(ve,C("code")),me=N(ve),Ie=N(ve,D("phone")),be=N(ve,_("email")),ke=e=>({verify:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:fe(((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]:me(((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]:me(((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]:me((t=>q(e.post(P(s.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:be(((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]:Ie(((t,o,i)=>q(e.post(P(s.update.phone,n),{loginId:t,phone:o},{token:i}))))})),{})}}),ye=N(C("tenant")),Oe=N(C("code")),we=e=>({start:ye((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:Oe((t=>q(e.post(r.exchange,{code:t}))))}),je=C("loginId"),Ue=N(je,C("code")),Re=N(je),xe=N(je),Pe=e=>({signUp:Re(((t,n)=>q(e.post(u.signUp,{loginId:t,user:n})))),verify:Ue(((t,n,s,o)=>q(e.post(u.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:xe(((t,n)=>q(e.post(u.update,{loginId:t},{token:n}))))}),qe=[J(`"${"loginId"}" must be a string`)];const Ee=C("loginId"),$e=C("origin"),Se=N(Ee,$e,C("name")),Me=N(Ee,$e),Te=N(qe,$e),Ae=N(Ee,$e,C("token")),Le=N(C("transactionId"),C("response")),ze=e=>({signUp:{start:Se(((t,n,s)=>q(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Le(((t,n)=>q(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Te(((t,n,s,o)=>q(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Le(((t,n)=>q(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Me(((t,n)=>q(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:Ae(((t,n,s)=>q(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:Le(((t,n)=>q(e.post(d.update.finish,{transactionId:t,response:n}))))}}),He=N(C("token"));var Je,Ne;var Ce=N([(Je="projectId",Ne=C("projectId"),E(((e,n)=>s=>$(...n).validate(t(s,e)))(Je,Ne))())])((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={},fetch:a})=>{return r=y({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:B(r),otp:ke(r),magicLink:le(r),enchantedLink:te(r),oauth:ge(r),saml:we(r),totp:Pe(r),webauthn:ze(r),flow:oe(r),refresh:e=>q(r.post(l,{},{token:e})),logout:e=>q(r.post(c,{},{token:e})),logoutAll:e=>q(r.post(p,{},{token:e})),me:e=>q(r.get(g,{token:e})),isJwtExpired:He(U),getJwtPermissions:He(R),getJwtRoles:He(x),httpClient:r};var r})));const _e=(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),De=(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 Ze=Object.assign(Ce,{DeliveryMethods:K});export{O as HttpStatusCodes,De as addHooksToConfig,Ze as default,q as transformResponse,_e 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"},d={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},u={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},p="/v1/auth/refresh",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v={start:"/v1/flow/start",next:"/v1/flow/next"};const f=()=>{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")}},m=(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=>f().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)),f().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var I;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(I||(I={}));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}),{})),b=e=>void 0===e?void 0:JSON.stringify(e),k=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},w=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i,fetch:a})=>{const r=m(s,a),d=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:d,body:u,headers:l,queryParams:p,method:c,token:g}=a,h=await r((({path:e,baseUrl:t,queryParams:n})=>{const s=new URL(e,t);return n&&(s.search=new URLSearchParams(n).toString()),s})({path:d,baseUrl:e,queryParams:p}),{headers:y(k(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.3"},(null==n?void 0:n.baseHeaders)||{},l),method:c,body:b(u),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}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:I.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:I.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:I.put,token:o}),delete:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:I.delete,token:o}),hooks:o}};var O={TOO_MANY_REQUESTS:429};function U(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 P(e){const{exp:t}=j(e);return(new Date).getTime()/1e3>t}function R(e,t){return U(e,t,"permissions")}function x(e,t){return U(e,t,"roles")}const q=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function E(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,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)}),M=e=>t=>e.test(t),T=M(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),A=M(/^\+[1-9]{1}[0-9]{3,14}$/),L=$(T,'"{val}" is not a valid email'),z=$(A,'"{val}" is not a valid phone number'),H=$((J=1,e=>e.length>=J),"Minimum length is 1");var J;const N=$((e=>"string"==typeof e),"Input is not a string"),C=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>S(...e).validate(n[t]))),t(...n)),_=e=>[N(`"${e}" must be a string`),H(`"${e}" must not be empty`)],D=e=>[N(`"${e}" must be a string`),L()],Z=e=>[N(`"${e}" must be a string`),z()],B=C(_("accessKey")),F=e=>({exchange:B((t=>E(e.post(n.exchange,{},{token:t}))))});var K,Q,Y,G;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(K||(K={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Q||(Q={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Y||(Y={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(G||(G={}));const V=_("loginId"),W=C(_("token")),X=C(V),ee=C(_("pendingRef")),te=C(V,D("email")),ne=e=>({verify:W((t=>E(e.post(i.verify,{token:t})))),signIn:X(((t,n,s,o)=>E(e.post(q(i.signIn,Q.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:X(((t,n)=>E(e.post(q(i.signUpOrIn,Q.email),{loginId:t,URI:n})))),signUp:X(((t,n,s)=>E(e.post(q(i.signUp,Q.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 d=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(E(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:te(((t,n,s,o)=>E(e.post(i.update.email,{loginId:t,email:n,URI:s},{token:o}))))}}),se=C(_("flowId")),oe=C(_("executionId"),_("stepId"),_("interactionId")),ie=e=>({start:se(((t,n,s,o,i)=>E(e.post(v.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,input:i})))),next:oe(((t,n,s,o)=>E(e.post(v.next,{executionId:t,stepId:n,interactionId:s,input:o}))))}),ae=_("loginId"),re=C(_("token")),de=C(ae),ue=C(ae,Z("phone")),le=C(ae,D("email")),pe=e=>({verify:re((t=>E(e.post(o.verify,{token:t})))),signIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:de(((t,s,i,a)=>E(e.post(q(o.signIn,n),{loginId:t,URI:s,loginOptions:i},{token:a}))))})),{}),signUp:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:de(((t,s,i)=>E(e.post(q(o.signUp,n),{loginId:t,URI:s,user:i}))))})),{}),signUpOrIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:de(((t,s)=>E(e.post(q(o.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:le(((t,n,s,i)=>E(e.post(o.update.email,{loginId:t,email:n,URI:s},{token:i})))),phone:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ue(((t,s,i,a)=>E(e.post(q(o.update.phone,n),{loginId:t,phone:s,URI:i},{token:a}))))})),{})}});var ce;!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"}(ce||(ce={}));const ge=C(_("code")),he=e=>({start:Object.keys(ce).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 E(Promise.resolve(r));const{url:d}=await r.json();window.location.href=d}})),{}),exchange:ge((t=>E(e.post(a.exchange,{code:t}))))});var ve;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(ve||(ve={}));const fe=_("loginId"),me=C(fe,_("code")),Ie=C(fe),ye=C(fe,Z("phone")),be=C(fe,D("email")),ke=e=>({verify:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:me(((t,o)=>E(e.post(q(s.verify,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie(((t,o,i)=>E(e.post(q(s.signIn,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie(((t,o)=>E(e.post(q(s.signUp,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(Q).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie((t=>E(e.post(q(s.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:be(((t,n,o)=>E(e.post(s.update.email,{loginId:t,email:n},{token:o})))),phone:Object.keys(K).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i)=>E(e.post(q(s.update.phone,n),{loginId:t,phone:o},{token:i}))))})),{})}}),we=C(_("tenant")),Oe=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 E(Promise.resolve(a));const{url:d}=await a.json();window.location.href=d})),exchange:Oe((t=>E(e.post(r.exchange,{code:t}))))}),je=_("loginId"),Pe=C(je,_("code")),Re=C(je),xe=C(je),qe=e=>({signUp:Re(((t,n)=>E(e.post(d.signUp,{loginId:t,user:n})))),verify:Pe(((t,n,s,o)=>E(e.post(d.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:xe(((t,n)=>E(e.post(d.update,{loginId:t},{token:n}))))}),Ee=_("loginId"),$e=_("newPassword"),Se=C(Ee,_("password")),Me=C(Ee),Te=C(Ee,$e),Ae=C(Ee,_("oldPassword"),$e),Le=e=>({signUp:Se(((t,n,s)=>E(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Se(((t,n)=>E(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Me(((t,n)=>E(e.post(l.sendReset,{loginId:t,redirectUrl:n})))),update:Te(((t,n,s)=>E(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Ae(((t,n,s)=>E(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>E(e.get(l.policy))}),ze=[N(`"${"loginId"}" must be a string`)];const He=_("loginId"),Je=_("origin"),Ne=C(He,Je,_("name")),Ce=C(He,Je),_e=C(ze,Je),De=C(He,Je,_("token")),Ze=C(_("transactionId"),_("response")),Be=e=>({signUp:{start:Ne(((t,n,s)=>E(e.post(u.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Ze(((t,n)=>E(e.post(u.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:_e(((t,n,s,o)=>E(e.post(u.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Ze(((t,n)=>E(e.post(u.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Ce(((t,n)=>E(e.post(u.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:De(((t,n,s)=>E(e.post(u.update.start,{loginId:t,origin:n},{token:s})))),finish:Ze(((t,n)=>E(e.post(u.update.finish,{transactionId:t,response:n}))))}}),Fe=C(_("token"));var Ke,Qe;var Ye=C([(Ke="projectId",Qe=_("projectId"),$(((e,n)=>s=>S(...n).validate(t(s,e)))(Ke,Qe))())])((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={},fetch:a})=>{return r=w({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:F(r),otp:ke(r),magicLink:pe(r),enchantedLink:ne(r),oauth:he(r),saml:Ue(r),totp:qe(r),webauthn:Be(r),password:Le(r),flow:ie(r),refresh:e=>E(r.post(p,{},{token:e})),logout:e=>E(r.post(c,{},{token:e})),logoutAll:e=>E(r.post(g,{},{token:e})),me:e=>E(r.get(h,{token:e})),isJwtExpired:Fe(P),getJwtPermissions:Fe(R),getJwtRoles:Fe(x),httpClient:r};var r})));const Ge=(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),Ve=(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 We=Object.assign(Ye,{DeliveryMethods:Q});export{O as HttpStatusCodes,Ve as addHooksToConfig,We as default,E as transformResponse,Ge as wrapWith}; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@descope/core-js-sdk", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": "Descope Team <info@descope.com>", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/descope/core-js-sdk", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
212745
644