@descope/core-js-sdk
Advanced tools
Comparing version 2.12.1 to 2.12.2
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},o={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},i={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},u={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},l="/v1/auth/refresh",p="/v1/auth/tenant/select",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v="/v1/auth/me/history",f={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",I=`https://api.${m}descope.com`,b=1e3,y=6e5,k=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},O=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>k().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return k().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var w;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(w||(w={}));var j={TOO_MANY_REQUESTS:429};function U(e,t,n){var s;let o=R(e);t&&(o=null===(s=null==o?void 0:o.tenants)||void 0===s?void 0:s[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function R(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function x(e){const{exp:t}=R(e);return(new Date).getTime()/1e3>t}function P(e){let t=R(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function q(e,t){return U(e,t,"permissions")}function $(e,t){return U(e,t,"roles")}const E=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function S(e,t){var n;const s=await e,o={code:s.status,ok:s.ok,response:s},i=await s.clone().json();return s.ok?o.data=t?t(i):i:(o.error=i,s.status===j.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 A=(...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}),{})),T=e=>void 0===e?void 0:JSON.stringify(e),M=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},N=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i,fetch:a})=>{const r=O(s,a),d=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:d,body:u,headers:l,queryParams:p,method:c,token:g}=a,h={headers:A(M(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.12.1"},(null==n?void 0:n.baseHeaders)||{},l),method:c,body:T(u)};null!==i&&(h.credentials=i||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const o=s.slice(1,-27);t=t.replace(m,o?o+".":"");const i=new URL(t);return i.pathname=E(i.pathname,e),n&&(i.search=new URLSearchParams(n).toString()),i})({path:d,baseUrl:e,queryParams:p,projectId:t}),h);return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.put,token:o}),delete:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.delete,token:s}),hooks:o}},L=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),H=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),_=e=>t=>e.test(t),z=_(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=_(/^\+[1-9]{1}[0-9]{3,14}$/),J=(e,t)=>n=>H(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),o=s.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<o;)a=a[s[i++]];return i&&i===o&&void 0!==a?a:n})(n,e)),D=L(z,'"{val}" is not a valid email'),Z=L(C,'"{val}" is not a valid phone number'),B=L((F=1,e=>e.length>=F),"Minimum length is 1");var F;const K=L((e=>"string"==typeof e),"Input is not a string"),Q=L((e=>void 0===e),"Input is defined"),V=(Y=[K(),Q()],G="Input is not a string or undefined",(e=G)=>t=>{const n=Y.filter((e=>e(t)));return!(n.length<Y.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Y,G;const W=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>H(...e).validate(n[t]))),t(...n)),X=e=>[K(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ee=e=>[K(`"${e}" must be a string`),D()],te=e=>[K(`"${e}" must be a string`),Z()],ne=W(X("accessKey")),se=e=>({exchange:ne(((n,s)=>S(e.post(t.exchange,{loginOptions:s},{token:n}))))});var oe,ie;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(oe||(oe={})),function(e){e.email="email"}(ie||(ie={}));const ae=Object.assign(Object.assign({},oe),ie);var re;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(re||(re={}));const de=X("loginId"),ue=W(X("token")),le=W(de),pe=W(X("pendingRef")),ce=W(de,ee("email")),ge=e=>({verify:ue((t=>S(e.post(o.verify,{token:t})))),signIn:le(((t,n,s,i)=>S(e.post(E(o.signIn,ae.email),{loginId:t,URI:n,loginOptions:s},{token:i})))),signUpOrIn:le(((t,n,s)=>S(e.post(E(o.signUpOrIn,ae.email),{loginId:t,URI:n,loginOptions:s})))),signUp:le(((t,n,s,i)=>S(e.post(E(o.signUp,ae.email),{loginId:t,URI:n,user:s,loginOptions:i})))),waitForSession:pe(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||b,b),timeoutMs:Math.min(t||y,y)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(o.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(S(Promise.resolve(n))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:ce(((t,n,s,i,a)=>S(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i}))))}}),he=W(X("flowId")),ve=W(X("executionId"),X("stepId"),X("interactionId")),fe=e=>({start:he(((t,n,s,o,i,a,r)=>S(e.post(f.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,version:i,componentsVersion:a,input:r})))),next:ve(((t,n,s,o,i,a)=>S(e.post(f.next,{executionId:t,stepId:n,interactionId:s,version:o,componentsVersion:i,input:a}))))}),me=X("loginId"),Ie=W(X("token")),be=W(me),ye=W(me,te("phone")),ke=W(me,ee("email")),Oe=Object.keys(ae).filter((e=>e!==oe.voice)),we=e=>({verify:Ie((t=>S(e.post(s.verify,{token:t})))),signIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>S(e.post(E(s.signIn,n),{loginId:t,URI:o,loginOptions:i},{token:a}))))})),{}),signUp:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>S(e.post(E(s.signUp,n),{loginId:t,URI:o,user:i,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i)=>S(e.post(E(s.signUpOrIn,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:ke(((t,n,o,i,a)=>S(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:o},a),{token:i})))),phone:Object.keys(oe).filter((e=>e!==oe.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i,a,r)=>S(e.post(E(s.update.phone,n),Object.assign({loginId:t,phone:o,URI:i},r),{token:a}))))})),{})}});var je;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(je||(je={}));const Ue=W(X("code")),Re=e=>({start:Object.assign(((t,n,s,o)=>S(e.post(i.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:o}))),Object.keys(je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>S(e.post(i.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{})),exchange:Ue((t=>S(e.post(i.exchange,{code:t})))),startNative:(t,n)=>S(e.post(i.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,o,a)=>S(e.post(i.finishNative,{provider:t,stateId:n,user:s,code:o,idToken:a}))}),xe=X("loginId"),Pe=W(xe,X("code")),qe=W(xe),$e=W(xe,te("phone")),Ee=W(xe,ee("email")),Se=e=>({verify:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Pe(((t,o)=>S(e.post(E(n.verify,s),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i)=>S(e.post(E(n.signIn,s),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i)=>S(e.post(E(n.signUp,s),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o)=>S(e.post(E(n.signUpOrIn,s),{loginId:t,loginOptions:o}))))})),{}),update:{email:Ee(((t,s,o,i)=>S(e.post(n.update.email,Object.assign({loginId:t,email:s},i),{token:o})))),phone:Object.keys(oe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,o,i,a)=>S(e.post(E(n.update.phone,s),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),Ae=W(X("tenant")),Te=W(X("code")),Me=e=>({start:Ae(((t,n,s,o)=>S(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:Te((t=>S(e.post(a.exchange,{code:t}))))}),Ne=X("loginId"),Le=W(Ne,X("code")),He=W(Ne),_e=W(Ne),ze=e=>({signUp:He(((t,n)=>S(e.post(r.signUp,{loginId:t,user:n})))),verify:Le(((t,n,s,o)=>S(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:_e(((t,n)=>S(e.post(r.update,{loginId:t},{token:n}))))}),Ce=X("loginId"),Je=X("newPassword"),De=W(Ce,X("password")),Ze=W(Ce),Be=W(Ce,Je),Fe=W(Ce,X("oldPassword"),Je),Ke=e=>({signUp:De(((t,n,s)=>S(e.post(u.signUp,{loginId:t,password:n,user:s})))),signIn:De(((t,n)=>S(e.post(u.signIn,{loginId:t,password:n})))),sendReset:Ze(((t,n,s)=>S(e.post(u.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Be(((t,n,s)=>S(e.post(u.update,{loginId:t,newPassword:n},{token:s})))),replace:Fe(((t,n,s)=>S(e.post(u.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>S(e.get(u.policy))}),Qe=[K(`"${"loginId"}" must be a string`)];const Ve=X("loginId"),Ye=X("origin"),Ge=W(Ve,Ye,X("name")),We=W(Ve,Ye),Xe=W(Qe,Ye),et=W(Ve,Ye,X("token")),tt=W(X("transactionId"),X("response")),nt=e=>({signUp:{start:Ge(((t,n,s)=>S(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:tt(((t,n)=>S(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Xe(((t,n,s,o)=>S(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:tt(((t,n)=>S(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:We(((t,n)=>S(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:et(((t,n,s)=>S(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:tt(((t,n)=>S(e.post(d.update.finish,{transactionId:t,response:n}))))}}),st=W(X("token")),ot=W((e=>[V(`"${e}" must be string or undefined`)])("token"));var it,at;var rt=W([(it="projectId",at=X("projectId"),L(J(it,at))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const o=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(await Promise.allSettled(null==o?void 0:o.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}})))((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return r=N({baseUrl:n||I,projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:se(r),otp:Se(r),magicLink:we(r),enchantedLink:ge(r),oauth:Re(r),saml:Me(r),totp:ze(r),webauthn:nt(r),password:Ke(r),flow:fe(r),refresh:ot((e=>S(r.post(l,{},{token:e})))),selectTenant:W([K("tenantId")],[V('"token" must be string or undefined')])(((e,t)=>S(r.post(p,{tenant:e},{token:t})))),logout:ot((e=>S(r.post(c,{},{token:e})))),logoutAll:ot((e=>S(r.post(g,{},{token:e})))),me:ot((e=>S(r.get(h,{token:e})))),history:ot((e=>S(r.get(v,{token:e})))),isJwtExpired:st(x),getTenants:st(P),getJwtPermissions:st(q),getJwtRoles:st($),httpClient:r};var r})));var dt=Object.assign(rt,{DeliveryMethods:ae});exports.HttpStatusCodes=j,exports.default=dt,exports.transformResponse=S,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("jwt-decode"),t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},o={verify:"/v1/auth/enchantedlink/verify",signIn:"/v1/auth/enchantedlink/signin",signUp:"/v1/auth/enchantedlink/signup",session:"/v1/auth/enchantedlink/pending-session",update:{email:"/v1/auth/enchantedlink/update/email"},signUpOrIn:"/v1/auth/enchantedlink/signup-in"},i={start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},u={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},l="/v1/auth/refresh",p="/v1/auth/tenant/select",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v="/v1/auth/me/history",f={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",I=`https://api.${m}descope.com`,b=1e3,y=6e5,k=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},O=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>k().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return k().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var w;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(w||(w={}));var j={TOO_MANY_REQUESTS:429};function U(e,t,n){var s;let o=R(e);t&&(o=null===(s=null==o?void 0:o.tenants)||void 0===s?void 0:s[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function R(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function x(e){const{exp:t}=R(e);return(new Date).getTime()/1e3>t}function P(e){let t=R(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function q(e,t){return U(e,t,"permissions")}function $(e,t){return U(e,t,"roles")}const E=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function S(e,t){var n;const s=await e,o={code:s.status,ok:s.ok,response:s},i=await s.clone().json();return s.ok?o.data=t?t(i):i:(o.error=i,s.status===j.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 A=(...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}),{})),T=e=>void 0===e?void 0:JSON.stringify(e),M=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},N=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:o,cookiePolicy:i,fetch:a})=>{const r=O(s,a),d=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:d,body:u,headers:l,queryParams:p,method:c,token:g}=a,h={headers:A(M(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.12.2"},(null==n?void 0:n.baseHeaders)||{},l),method:c,body:T(u)};null!==i&&(h.credentials=i||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const o=s.slice(1,-27);t=t.replace(m,o?o+".":"");const i=new URL(t);return i.pathname=E(i.pathname,e),n&&(i.search=new URLSearchParams(n).toString()),i})({path:d,baseUrl:e,queryParams:p,projectId:t}),h);return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.put,token:o}),delete:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.delete,token:s}),hooks:o}},L=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),H=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),_=e=>t=>e.test(t),z=_(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=_(/^\+[1-9]{1}[0-9]{3,14}$/),J=(e,t)=>n=>H(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),o=s.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<o;)a=a[s[i++]];return i&&i===o&&void 0!==a?a:n})(n,e)),D=L(z,'"{val}" is not a valid email'),Z=L(C,'"{val}" is not a valid phone number'),B=L((F=1,e=>e.length>=F),"Minimum length is 1");var F;const K=L((e=>"string"==typeof e),"Input is not a string"),Q=L((e=>void 0===e),"Input is defined"),V=(Y=[K(),Q()],G="Input is not a string or undefined",(e=G)=>t=>{const n=Y.filter((e=>e(t)));return!(n.length<Y.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Y,G;const W=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>H(...e).validate(n[t]))),t(...n)),X=e=>[K(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ee=e=>[K(`"${e}" must be a string`),D()],te=e=>[K(`"${e}" must be a string`),Z()],ne=W(X("accessKey")),se=e=>({exchange:ne(((n,s)=>S(e.post(t.exchange,{loginOptions:s},{token:n}))))});var oe,ie;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(oe||(oe={})),function(e){e.email="email"}(ie||(ie={}));const ae=Object.assign(Object.assign({},oe),ie);var re;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(re||(re={}));const de=X("loginId"),ue=W(X("token")),le=W(de),pe=W(X("pendingRef")),ce=W(de,ee("email")),ge=e=>({verify:ue((t=>S(e.post(o.verify,{token:t})))),signIn:le(((t,n,s,i)=>S(e.post(E(o.signIn,ae.email),{loginId:t,URI:n,loginOptions:s},{token:i})))),signUpOrIn:le(((t,n,s)=>S(e.post(E(o.signUpOrIn,ae.email),{loginId:t,URI:n,loginOptions:s})))),signUp:le(((t,n,s,i)=>S(e.post(E(o.signUp,ae.email),{loginId:t,URI:n,user:s,loginOptions:i})))),waitForSession:pe(((t,n)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||b,b),timeoutMs:Math.min(t||y,y)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(o.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(S(Promise.resolve(n))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:ce(((t,n,s,i,a)=>S(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i}))))}}),he=W(X("flowId")),ve=W(X("executionId"),X("stepId"),X("interactionId")),fe=e=>({start:he(((t,n,s,o,i,a,r)=>S(e.post(f.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,version:i,componentsVersion:a,input:r})))),next:ve(((t,n,s,o,i,a)=>S(e.post(f.next,{executionId:t,stepId:n,interactionId:s,version:o,componentsVersion:i,input:a}))))}),me=X("loginId"),Ie=W(X("token")),be=W(me),ye=W(me,te("phone")),ke=W(me,ee("email")),Oe=Object.keys(ae).filter((e=>e!==oe.voice)),we=e=>({verify:Ie((t=>S(e.post(s.verify,{token:t})))),signIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>S(e.post(E(s.signIn,n),{loginId:t,URI:o,loginOptions:i},{token:a}))))})),{}),signUp:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i,a)=>S(e.post(E(s.signUp,n),{loginId:t,URI:o,user:i,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i)=>S(e.post(E(s.signUpOrIn,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:ke(((t,n,o,i,a)=>S(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:o},a),{token:i})))),phone:Object.keys(oe).filter((e=>e!==oe.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i,a,r)=>S(e.post(E(s.update.phone,n),Object.assign({loginId:t,phone:o,URI:i},r),{token:a}))))})),{})}});var je;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(je||(je={}));const Ue=W(X("code")),Re=e=>({start:Object.assign(((t,n,s,o)=>S(e.post(i.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:o}))),Object.keys(je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>S(e.post(i.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{})),exchange:Ue((t=>S(e.post(i.exchange,{code:t})))),startNative:(t,n)=>S(e.post(i.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,o,a)=>S(e.post(i.finishNative,{provider:t,stateId:n,user:s,code:o,idToken:a}))}),xe=X("loginId"),Pe=W(xe,X("code")),qe=W(xe),$e=W(xe,te("phone")),Ee=W(xe,ee("email")),Se=e=>({verify:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:Pe(((t,o)=>S(e.post(E(n.verify,s),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i)=>S(e.post(E(n.signIn,s),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o,i)=>S(e.post(E(n.signUp,s),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,o)=>S(e.post(E(n.signUpOrIn,s),{loginId:t,loginOptions:o}))))})),{}),update:{email:Ee(((t,s,o,i)=>S(e.post(n.update.email,Object.assign({loginId:t,email:s},i),{token:o})))),phone:Object.keys(oe).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,o,i,a)=>S(e.post(E(n.update.phone,s),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),Ae=W(X("tenant")),Te=W(X("code")),Me=e=>({start:Ae(((t,n,s,o)=>S(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:Te((t=>S(e.post(a.exchange,{code:t}))))}),Ne=X("loginId"),Le=W(Ne,X("code")),He=W(Ne),_e=W(Ne),ze=e=>({signUp:He(((t,n)=>S(e.post(r.signUp,{loginId:t,user:n})))),verify:Le(((t,n,s,o)=>S(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:_e(((t,n)=>S(e.post(r.update,{loginId:t},{token:n}))))}),Ce=X("loginId"),Je=X("newPassword"),De=W(Ce,X("password")),Ze=W(Ce),Be=W(Ce,Je),Fe=W(Ce,X("oldPassword"),Je),Ke=e=>({signUp:De(((t,n,s)=>S(e.post(u.signUp,{loginId:t,password:n,user:s})))),signIn:De(((t,n)=>S(e.post(u.signIn,{loginId:t,password:n})))),sendReset:Ze(((t,n,s)=>S(e.post(u.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Be(((t,n,s)=>S(e.post(u.update,{loginId:t,newPassword:n},{token:s})))),replace:Fe(((t,n,s)=>S(e.post(u.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>S(e.get(u.policy))}),Qe=[K(`"${"loginId"}" must be a string`)];const Ve=X("loginId"),Ye=X("origin"),Ge=W(Ve,Ye,X("name")),We=W(Ve,Ye),Xe=W(Qe,Ye),et=W(Ve,Ye,X("token")),tt=W(X("transactionId"),X("response")),nt=e=>({signUp:{start:Ge(((t,n,s)=>S(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:tt(((t,n)=>S(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Xe(((t,n,s,o)=>S(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:tt(((t,n)=>S(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:We(((t,n)=>S(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:et(((t,n,s)=>S(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:tt(((t,n)=>S(e.post(d.update.finish,{transactionId:t,response:n}))))}}),st=W(X("token")),ot=W((e=>[V(`"${e}" must be string or undefined`)])("token"));var it,at;var rt=W([(it="projectId",at=X("projectId"),L(J(it,at))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const o=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(await Promise.allSettled(null==o?void 0:o.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}})))((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return r=N({baseUrl:n||I,projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:se(r),otp:Se(r),magicLink:we(r),enchantedLink:ge(r),oauth:Re(r),saml:Me(r),totp:ze(r),webauthn:nt(r),password:Ke(r),flow:fe(r),refresh:ot((e=>S(r.post(l,{},{token:e})))),selectTenant:W([K("tenantId")],[V('"token" must be string or undefined')])(((e,t)=>S(r.post(p,{tenant:e},{token:t})))),logout:ot((e=>S(r.post(c,{},{token:e})))),logoutAll:ot((e=>S(r.post(g,{},{token:e})))),me:ot((e=>S(r.get(h,{token:e})))),history:ot((e=>S(r.get(v,{token:e})))),isJwtExpired:st(x),getTenants:st(P),getJwtPermissions:st(q),getJwtRoles:st($),httpClient:r};var r})));var dt=Object.assign(rt,{DeliveryMethods:ae});exports.HttpStatusCodes=j,exports.default=dt,exports.transformResponse=S,exports.wrapWith=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e); | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import e from"jwt-decode";var t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},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",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},u="/v1/auth/refresh",p="/v1/auth/tenant/select",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v="/v1/auth/me/history",f={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",I=`https://api.${m}descope.com`,b=1e3,y=6e5,k=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},O=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>k().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return k().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var w;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(w||(w={}));var j={TOO_MANY_REQUESTS:429};function U(e,t,n){var s;let i=R(e);t&&(i=null===(s=null==i?void 0:i.tenants)||void 0===s?void 0:s[t]);const o=null==i?void 0:i[n];return Array.isArray(o)?o:[]}function R(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function P(e){const{exp:t}=R(e);return(new Date).getTime()/1e3>t}function x(e){let t=R(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function q(e,t){return U(e,t,"permissions")}function $(e,t){return U(e,t,"roles")}const E=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function A(e,t){var n;const s=await e,i={code:s.status,ok:s.ok,response:s},o=await s.clone().json();return s.ok?i.data=t?t(o):o:(i.error=o,s.status===j.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const S=(...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}),{})),T=e=>void 0===e?void 0:JSON.stringify(e),M=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},N=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:i,cookiePolicy:o,fetch:a})=>{const r=O(s,a),d=async s=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(s):s,{path:d,body:l,headers:u,queryParams:p,method:c,token:g}=a,h={headers:S(M(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.12.1"},(null==n?void 0:n.baseHeaders)||{},u),method:c,body:T(l)};null!==o&&(h.credentials=o||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const i=s.slice(1,-27);t=t.replace(m,i?i+".":"");const o=new URL(t);return o.pathname=E(o.pathname,e),n&&(o.search=new URLSearchParams(n).toString()),o})({path:d,baseUrl:e,queryParams:p,projectId:t}),h);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:i}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.post,token:i}),put:(e,t,{headers:n,queryParams:s,token:i}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.put,token:i}),delete:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.delete,token:s}),hooks:i}},L=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),z=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),H=e=>t=>e.test(t),J=H(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=H(/^\+[1-9]{1}[0-9]{3,14}$/),_=(e,t)=>n=>z(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=s.length;let o=0,a=e===Object(e)?e:void 0;for(;null!=a&&o<i;)a=a[s[o++]];return o&&o===i&&void 0!==a?a:n})(n,e)),D=L(J,'"{val}" is not a valid email'),Z=L(C,'"{val}" is not a valid phone number'),B=L((F=1,e=>e.length>=F),"Minimum length is 1");var F;const K=L((e=>"string"==typeof e),"Input is not a string"),Q=L((e=>void 0===e),"Input is defined"),V=(Y=[K(),Q()],G="Input is not a string or undefined",(e=G)=>t=>{const n=Y.filter((e=>e(t)));return!(n.length<Y.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Y,G;const W=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>z(...e).validate(n[t]))),t(...n)),X=e=>[K(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ee=e=>[K(`"${e}" must be a string`),D()],te=e=>[K(`"${e}" must be a string`),Z()],ne=W(X("accessKey")),se=e=>({exchange:ne(((n,s)=>A(e.post(t.exchange,{loginOptions:s},{token:n}))))});var ie,oe;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(ie||(ie={})),function(e){e.email="email"}(oe||(oe={}));const ae=Object.assign(Object.assign({},ie),oe);var re;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(re||(re={}));const de=X("loginId"),le=W(X("token")),ue=W(de),pe=W(X("pendingRef")),ce=W(de,ee("email")),ge=e=>({verify:le((t=>A(e.post(i.verify,{token:t})))),signIn:ue(((t,n,s,o)=>A(e.post(E(i.signIn,ae.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:ue(((t,n,s)=>A(e.post(E(i.signUpOrIn,ae.email),{loginId:t,URI:n,loginOptions:s})))),signUp:ue(((t,n,s,o)=>A(e.post(E(i.signUp,ae.email),{loginId:t,URI:n,user:s,loginOptions:o})))),waitForSession:pe(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||b,b),timeoutMs:Math.min(t||y,y)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(A(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:ce(((t,n,s,o,a)=>A(e.post(i.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:o}))))}}),he=W(X("flowId")),ve=W(X("executionId"),X("stepId"),X("interactionId")),fe=e=>({start:he(((t,n,s,i,o,a,r)=>A(e.post(f.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:i,version:o,componentsVersion:a,input:r})))),next:ve(((t,n,s,i,o,a)=>A(e.post(f.next,{executionId:t,stepId:n,interactionId:s,version:i,componentsVersion:o,input:a}))))}),me=X("loginId"),Ie=W(X("token")),be=W(me),ye=W(me,te("phone")),ke=W(me,ee("email")),Oe=Object.keys(ae).filter((e=>e!==ie.voice)),we=e=>({verify:Ie((t=>A(e.post(s.verify,{token:t})))),signIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,i,o,a)=>A(e.post(E(s.signIn,n),{loginId:t,URI:i,loginOptions:o},{token:a}))))})),{}),signUp:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,i,o,a)=>A(e.post(E(s.signUp,n),{loginId:t,URI:i,user:o,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,i,o)=>A(e.post(E(s.signUpOrIn,n),{loginId:t,URI:i,loginOptions:o}))))})),{}),update:{email:ke(((t,n,i,o,a)=>A(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:i},a),{token:o})))),phone:Object.keys(ie).filter((e=>e!==ie.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,i,o,a,r)=>A(e.post(E(s.update.phone,n),Object.assign({loginId:t,phone:i,URI:o},r),{token:a}))))})),{})}});var je;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(je||(je={}));const Ue=W(X("code")),Re=e=>({start:Object.assign(((t,n,s,i)=>A(e.post(o.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,i)=>A(e.post(o.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:Ue((t=>A(e.post(o.exchange,{code:t})))),startNative:(t,n)=>A(e.post(o.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,i,a)=>A(e.post(o.finishNative,{provider:t,stateId:n,user:s,code:i,idToken:a}))}),Pe=X("loginId"),xe=W(Pe,X("code")),qe=W(Pe),$e=W(Pe,te("phone")),Ee=W(Pe,ee("email")),Ae=e=>({verify:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:xe(((t,i)=>A(e.post(E(n.verify,s),{code:i,loginId:t}))))})),{}),signIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,i,o)=>A(e.post(E(n.signIn,s),{loginId:t,loginOptions:i},{token:o}))))})),{}),signUp:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,i,o)=>A(e.post(E(n.signUp,s),{loginId:t,user:i,loginOptions:o}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,i)=>A(e.post(E(n.signUpOrIn,s),{loginId:t,loginOptions:i}))))})),{}),update:{email:Ee(((t,s,i,o)=>A(e.post(n.update.email,Object.assign({loginId:t,email:s},o),{token:i})))),phone:Object.keys(ie).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,i,o,a)=>A(e.post(E(n.update.phone,s),Object.assign({loginId:t,phone:i},a),{token:o}))))})),{})}}),Se=W(X("tenant")),Te=W(X("code")),Me=e=>({start:Se(((t,n,s,i)=>A(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:Te((t=>A(e.post(a.exchange,{code:t}))))}),Ne=X("loginId"),Le=W(Ne,X("code")),ze=W(Ne),He=W(Ne),Je=e=>({signUp:ze(((t,n)=>A(e.post(r.signUp,{loginId:t,user:n})))),verify:Le(((t,n,s,i)=>A(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:i})))),update:He(((t,n)=>A(e.post(r.update,{loginId:t},{token:n}))))}),Ce=X("loginId"),_e=X("newPassword"),De=W(Ce,X("password")),Ze=W(Ce),Be=W(Ce,_e),Fe=W(Ce,X("oldPassword"),_e),Ke=e=>({signUp:De(((t,n,s)=>A(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:De(((t,n)=>A(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Ze(((t,n,s)=>A(e.post(l.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Be(((t,n,s)=>A(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Fe(((t,n,s)=>A(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>A(e.get(l.policy))}),Qe=[K(`"${"loginId"}" must be a string`)];const Ve=X("loginId"),Ye=X("origin"),Ge=W(Ve,Ye,X("name")),We=W(Ve,Ye),Xe=W(Qe,Ye),et=W(Ve,Ye,X("token")),tt=W(X("transactionId"),X("response")),nt=e=>({signUp:{start:Ge(((t,n,s)=>A(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:tt(((t,n)=>A(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Xe(((t,n,s,i)=>A(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:i})))),finish:tt(((t,n)=>A(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:We(((t,n)=>A(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:et(((t,n,s)=>A(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:tt(((t,n)=>A(e.post(d.update.finish,{transactionId:t,response:n}))))}}),st=W(X("token")),it=W((e=>[V(`"${e}" must be string or undefined`)])("token"));var ot,at;var rt=W([(ot="projectId",at=X("projectId"),L(_(ot,at))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const i=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(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:i,baseHeaders:o={},fetch:a})=>{return r=N({baseUrl:n||I,projectId:e,logger:t,hooks:s,cookiePolicy:i,baseConfig:{baseHeaders:o},fetch:a}),{accessKey:se(r),otp:Ae(r),magicLink:we(r),enchantedLink:ge(r),oauth:Re(r),saml:Me(r),totp:Je(r),webauthn:nt(r),password:Ke(r),flow:fe(r),refresh:it((e=>A(r.post(u,{},{token:e})))),selectTenant:W([K("tenantId")],[V('"token" must be string or undefined')])(((e,t)=>A(r.post(p,{tenant:e},{token:t})))),logout:it((e=>A(r.post(c,{},{token:e})))),logoutAll:it((e=>A(r.post(g,{},{token:e})))),me:it((e=>A(r.get(h,{token:e})))),history:it((e=>A(r.get(v,{token:e})))),isJwtExpired:st(P),getTenants:st(x),getJwtPermissions:st(q),getJwtRoles:st($),httpClient:r};var r})));const dt=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let i=s.shift(),o=e;for(;s.length>0;){if(o=o[i],!i||!o)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=s.shift()}if("function"!=typeof o[i])throw Error(`"${t}" is not a function`);const a=o[i];o[i]=n(a)})),e);var lt=Object.assign(rt,{DeliveryMethods:ae});export{j as HttpStatusCodes,lt as default,A as transformResponse,dt as wrapWith}; | ||
import e from"jwt-decode";var t={exchange:"/v1/auth/accesskey/exchange"},n={verify:"/v1/auth/otp/verify",signIn:"/v1/auth/otp/signin",signUp:"/v1/auth/otp/signup",update:{email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},signUpOrIn:"/v1/auth/otp/signup-in"},s={verify:"/v1/auth/magiclink/verify",signIn:"/v1/auth/magiclink/signin",signUp:"/v1/auth/magiclink/signup",update:{email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},signUpOrIn:"/v1/auth/magiclink/signup-in"},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",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish"},a={start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},r={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},d={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},u="/v1/auth/refresh",p="/v1/auth/tenant/select",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v="/v1/auth/me/history",f={start:"/v1/flow/start",next:"/v1/flow/next"};const m="<region>",I=`https://api.${m}descope.com`,b=1e3,y=6e5,k=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},O=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>k().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const s=await n(...t);return e[s.ok?"log":"error"](await(async e=>{const t=await e.text();return k().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var w;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(w||(w={}));var j={TOO_MANY_REQUESTS:429};function U(e,t,n){var s;let i=R(e);t&&(i=null===(s=null==i?void 0:i.tenants)||void 0===s?void 0:s[t]);const o=null==i?void 0:i[n];return Array.isArray(o)?o:[]}function R(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function P(e){const{exp:t}=R(e);return(new Date).getTime()/1e3>t}function x(e){let t=R(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function q(e,t){return U(e,t,"permissions")}function $(e,t){return U(e,t,"roles")}const E=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function A(e,t){var n;const s=await e,i={code:s.status,ok:s.ok,response:s},o=await s.clone().json();return s.ok?i.data=t?t(o):o:(i.error=o,s.status===j.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const S=(...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}),{})),T=e=>void 0===e?void 0:JSON.stringify(e),M=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},N=({baseUrl:e,projectId:t,baseConfig:n,logger:s,hooks:i,cookiePolicy:o,fetch:a})=>{const r=O(s,a),d=async s=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(s):s,{path:d,body:l,headers:u,queryParams:p,method:c,token:g}=a,h={headers:S(M(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.12.2"},(null==n?void 0:n.baseHeaders)||{},u),method:c,body:T(l)};null!==o&&(h.credentials=o||"include");const v=await r((({path:e,baseUrl:t,queryParams:n,projectId:s})=>{const i=s.slice(1,-27);t=t.replace(m,i?i+".":"");const o=new URL(t);return o.pathname=E(o.pathname,e),n&&(o.search=new URLSearchParams(n).toString()),o})({path:d,baseUrl:e,queryParams:p,projectId:t}),h);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(s,null==v?void 0:v.clone()),v};return{get:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:i}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.post,token:i}),put:(e,t,{headers:n,queryParams:s,token:i}={})=>d({path:e,headers:n,queryParams:s,body:t,method:w.put,token:i}),delete:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:w.delete,token:s}),hooks:i}},L=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),z=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),H=e=>t=>e.test(t),J=H(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),C=H(/^\+[1-9]{1}[0-9]{3,14}$/),_=(e,t)=>n=>z(...t).validate(((e,t,n)=>{const s=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=s.length;let o=0,a=e===Object(e)?e:void 0;for(;null!=a&&o<i;)a=a[s[o++]];return o&&o===i&&void 0!==a?a:n})(n,e)),D=L(J,'"{val}" is not a valid email'),Z=L(C,'"{val}" is not a valid phone number'),B=L((F=1,e=>e.length>=F),"Minimum length is 1");var F;const K=L((e=>"string"==typeof e),"Input is not a string"),Q=L((e=>void 0===e),"Input is defined"),V=(Y=[K(),Q()],G="Input is not a string or undefined",(e=G)=>t=>{const n=Y.filter((e=>e(t)));return!(n.length<Y.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Y,G;const W=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>z(...e).validate(n[t]))),t(...n)),X=e=>[K(`"${e}" must be a string`),B(`"${e}" must not be empty`)],ee=e=>[K(`"${e}" must be a string`),D()],te=e=>[K(`"${e}" must be a string`),Z()],ne=W(X("accessKey")),se=e=>({exchange:ne(((n,s)=>A(e.post(t.exchange,{loginOptions:s},{token:n}))))});var ie,oe;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(ie||(ie={})),function(e){e.email="email"}(oe||(oe={}));const ae=Object.assign(Object.assign({},ie),oe);var re;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(re||(re={}));const de=X("loginId"),le=W(X("token")),ue=W(de),pe=W(X("pendingRef")),ce=W(de,ee("email")),ge=e=>({verify:le((t=>A(e.post(i.verify,{token:t})))),signIn:ue(((t,n,s,o)=>A(e.post(E(i.signIn,ae.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:ue(((t,n,s)=>A(e.post(E(i.signUpOrIn,ae.email),{loginId:t,URI:n,loginOptions:s})))),signUp:ue(((t,n,s,o)=>A(e.post(E(i.signUp,ae.email),{loginId:t,URI:n,user:s,loginOptions:o})))),waitForSession:pe(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||b,b),timeoutMs:Math.min(t||y,y)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(A(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:ce(((t,n,s,o,a)=>A(e.post(i.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:o}))))}}),he=W(X("flowId")),ve=W(X("executionId"),X("stepId"),X("interactionId")),fe=e=>({start:he(((t,n,s,i,o,a,r)=>A(e.post(f.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:i,version:o,componentsVersion:a,input:r})))),next:ve(((t,n,s,i,o,a)=>A(e.post(f.next,{executionId:t,stepId:n,interactionId:s,version:i,componentsVersion:o,input:a}))))}),me=X("loginId"),Ie=W(X("token")),be=W(me),ye=W(me,te("phone")),ke=W(me,ee("email")),Oe=Object.keys(ae).filter((e=>e!==ie.voice)),we=e=>({verify:Ie((t=>A(e.post(s.verify,{token:t})))),signIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,i,o,a)=>A(e.post(E(s.signIn,n),{loginId:t,URI:i,loginOptions:o},{token:a}))))})),{}),signUp:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,i,o,a)=>A(e.post(E(s.signUp,n),{loginId:t,URI:i,user:o,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,i,o)=>A(e.post(E(s.signUpOrIn,n),{loginId:t,URI:i,loginOptions:o}))))})),{}),update:{email:ke(((t,n,i,o,a)=>A(e.post(s.update.email,Object.assign({loginId:t,email:n,URI:i},a),{token:o})))),phone:Object.keys(ie).filter((e=>e!==ie.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,i,o,a,r)=>A(e.post(E(s.update.phone,n),Object.assign({loginId:t,phone:i,URI:o},r),{token:a}))))})),{})}});var je;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(je||(je={}));const Ue=W(X("code")),Re=e=>({start:Object.assign(((t,n,s,i)=>A(e.post(o.start,s||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,i)=>A(e.post(o.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:Ue((t=>A(e.post(o.exchange,{code:t})))),startNative:(t,n)=>A(e.post(o.startNative,{provider:t,loginOptions:n})),finishNative:(t,n,s,i,a)=>A(e.post(o.finishNative,{provider:t,stateId:n,user:s,code:i,idToken:a}))}),Pe=X("loginId"),xe=W(Pe,X("code")),qe=W(Pe),$e=W(Pe,te("phone")),Ee=W(Pe,ee("email")),Ae=e=>({verify:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:xe(((t,i)=>A(e.post(E(n.verify,s),{code:i,loginId:t}))))})),{}),signIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,i,o)=>A(e.post(E(n.signIn,s),{loginId:t,loginOptions:i},{token:o}))))})),{}),signUp:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,i,o)=>A(e.post(E(n.signUp,s),{loginId:t,user:i,loginOptions:o}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:qe(((t,i)=>A(e.post(E(n.signUpOrIn,s),{loginId:t,loginOptions:i}))))})),{}),update:{email:Ee(((t,s,i,o)=>A(e.post(n.update.email,Object.assign({loginId:t,email:s},o),{token:i})))),phone:Object.keys(ie).reduce(((t,s)=>Object.assign(Object.assign({},t),{[s]:$e(((t,i,o,a)=>A(e.post(E(n.update.phone,s),Object.assign({loginId:t,phone:i},a),{token:o}))))})),{})}}),Se=W(X("tenant")),Te=W(X("code")),Me=e=>({start:Se(((t,n,s,i)=>A(e.post(a.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:Te((t=>A(e.post(a.exchange,{code:t}))))}),Ne=X("loginId"),Le=W(Ne,X("code")),ze=W(Ne),He=W(Ne),Je=e=>({signUp:ze(((t,n)=>A(e.post(r.signUp,{loginId:t,user:n})))),verify:Le(((t,n,s,i)=>A(e.post(r.verify,{loginId:t,code:n,loginOptions:s},{token:i})))),update:He(((t,n)=>A(e.post(r.update,{loginId:t},{token:n}))))}),Ce=X("loginId"),_e=X("newPassword"),De=W(Ce,X("password")),Ze=W(Ce),Be=W(Ce,_e),Fe=W(Ce,X("oldPassword"),_e),Ke=e=>({signUp:De(((t,n,s)=>A(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:De(((t,n)=>A(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Ze(((t,n,s)=>A(e.post(l.sendReset,{loginId:t,redirectUrl:n,templateOptions:s})))),update:Be(((t,n,s)=>A(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Fe(((t,n,s)=>A(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>A(e.get(l.policy))}),Qe=[K(`"${"loginId"}" must be a string`)];const Ve=X("loginId"),Ye=X("origin"),Ge=W(Ve,Ye,X("name")),We=W(Ve,Ye),Xe=W(Qe,Ye),et=W(Ve,Ye,X("token")),tt=W(X("transactionId"),X("response")),nt=e=>({signUp:{start:Ge(((t,n,s)=>A(e.post(d.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:tt(((t,n)=>A(e.post(d.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:Xe(((t,n,s,i)=>A(e.post(d.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:i})))),finish:tt(((t,n)=>A(e.post(d.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:We(((t,n)=>A(e.post(d.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:et(((t,n,s)=>A(e.post(d.update.start,{loginId:t,origin:n},{token:s})))),finish:tt(((t,n)=>A(e.post(d.update.finish,{transactionId:t,response:n}))))}}),st=W(X("token")),it=W((e=>[V(`"${e}" must be string or undefined`)])("token"));var ot,at;var rt=W([(ot="projectId",at=X("projectId"),L(_(ot,at))())])((e=>t=>e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const s=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==s?void 0:s.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var s;const i=[].concat((null===(s=t.hooks)||void 0===s?void 0:s.afterRequest)||[]);(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:i,baseHeaders:o={},fetch:a})=>{return r=N({baseUrl:n||I,projectId:e,logger:t,hooks:s,cookiePolicy:i,baseConfig:{baseHeaders:o},fetch:a}),{accessKey:se(r),otp:Ae(r),magicLink:we(r),enchantedLink:ge(r),oauth:Re(r),saml:Me(r),totp:Je(r),webauthn:nt(r),password:Ke(r),flow:fe(r),refresh:it((e=>A(r.post(u,{},{token:e})))),selectTenant:W([K("tenantId")],[V('"token" must be string or undefined')])(((e,t)=>A(r.post(p,{tenant:e},{token:t})))),logout:it((e=>A(r.post(c,{},{token:e})))),logoutAll:it((e=>A(r.post(g,{},{token:e})))),me:it((e=>A(r.get(h,{token:e})))),history:it((e=>A(r.get(v,{token:e})))),isJwtExpired:st(P),getTenants:st(x),getJwtPermissions:st(q),getJwtRoles:st($),httpClient:r};var r})));const dt=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let i=s.shift(),o=e;for(;s.length>0;){if(o=o[i],!i||!o)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=s.shift()}if("function"!=typeof o[i])throw Error(`"${t}" is not a function`);const a=o[i];o[i]=n(a)})),e);var lt=Object.assign(rt,{DeliveryMethods:ae});export{j as HttpStatusCodes,lt as default,A as transformResponse,dt as wrapWith}; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@descope/core-js-sdk", | ||
"version": "2.12.1", | ||
"version": "2.12.2", | ||
"author": "Descope Team <info@descope.com>", | ||
@@ -54,3 +54,3 @@ "homepage": "https://github.com/descope/core-js-sdk", | ||
"eslint-plugin-jest": "27.9.0", | ||
"eslint-plugin-jest-dom": "5.1.0", | ||
"eslint-plugin-jest-dom": "5.2.0", | ||
"eslint-plugin-jest-formatting": "3.1.0", | ||
@@ -57,0 +57,0 @@ "eslint-plugin-n": "16.6.2", |
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