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