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