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