@descope/core-js-sdk 2.45.0 → 2.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +31 -13
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -290,6 +290,7 @@ type Options = {
|
|
|
290
290
|
locale?: string;
|
|
291
291
|
oidcPrompt?: string;
|
|
292
292
|
oidcErrorRedirectUri?: string;
|
|
293
|
+
oidcResource?: string;
|
|
293
294
|
nativeOptions?: NativeOptions;
|
|
294
295
|
thirdPartyAppStateId?: string;
|
|
295
296
|
applicationScopes?: string;
|
|
@@ -380,6 +381,20 @@ type HttpClient = {
|
|
|
380
381
|
[key: string]: string;
|
|
381
382
|
}) => string;
|
|
382
383
|
};
|
|
384
|
+
type Fetch = typeof fetch;
|
|
385
|
+
/** Parameters for the HTTP client. Defaults should work for most cases. */
|
|
386
|
+
type CreateHttpClientConfig = {
|
|
387
|
+
baseUrl?: string;
|
|
388
|
+
projectId: string;
|
|
389
|
+
baseConfig?: {
|
|
390
|
+
baseHeaders: HeadersInit;
|
|
391
|
+
};
|
|
392
|
+
logger?: Logger;
|
|
393
|
+
hooks?: Hooks;
|
|
394
|
+
cookiePolicy?: RequestCredentials | null;
|
|
395
|
+
refreshCookieName?: string;
|
|
396
|
+
fetch?: Fetch;
|
|
397
|
+
};
|
|
383
398
|
/** For before-request hook allows overriding parts of the request */
|
|
384
399
|
type RequestConfig = {
|
|
385
400
|
path: string;
|
|
@@ -399,6 +414,19 @@ type Hooks = {
|
|
|
399
414
|
afterRequest?: AfterRequest;
|
|
400
415
|
transformResponse?: (mutableResponse: ExtendedResponse) => Promise<ExtendedResponse>;
|
|
401
416
|
};
|
|
417
|
+
type MultipleHooks = {
|
|
418
|
+
beforeRequest?: BeforeRequest | BeforeRequest[];
|
|
419
|
+
afterRequest?: AfterRequest | AfterRequest[];
|
|
420
|
+
transformResponse?: (mutableResponse: ExtendedResponse) => Promise<ExtendedResponse>;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
declare const _default$2: {
|
|
424
|
+
TOO_MANY_REQUESTS: number;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
declare const _default$1: (config: Omit<CreateHttpClientConfig, "hooks"> & {
|
|
428
|
+
hooks?: MultipleHooks;
|
|
429
|
+
}) => HttpClient;
|
|
402
430
|
|
|
403
431
|
/** Transform the Promise Response to our internal SdkResponse implementation
|
|
404
432
|
* @param response The Response promise from fetch
|
|
@@ -471,10 +499,6 @@ declare const normalizeWaitForSessionConfig: ({ pollingIntervalMs, timeoutMs, }?
|
|
|
471
499
|
timeoutMs: number;
|
|
472
500
|
};
|
|
473
501
|
|
|
474
|
-
declare const _default$1: {
|
|
475
|
-
TOO_MANY_REQUESTS: number;
|
|
476
|
-
};
|
|
477
|
-
|
|
478
502
|
/** Descope SDK client with delivery methods enum.
|
|
479
503
|
*
|
|
480
504
|
* Please see full documentation at {@link https://docs.descope.com/guides Descope Docs}
|
|
@@ -491,21 +515,15 @@ declare const _default$1: {
|
|
|
491
515
|
* const jwtResponse = sdk.otp.verify.email(userIdentifier, codeFromEmail);
|
|
492
516
|
* ```
|
|
493
517
|
*/
|
|
494
|
-
declare const _default: ((config:
|
|
518
|
+
declare const _default: ((config: {
|
|
495
519
|
projectId: string;
|
|
496
520
|
logger?: Logger;
|
|
497
521
|
baseUrl?: string;
|
|
498
|
-
hooks?:
|
|
522
|
+
hooks?: MultipleHooks;
|
|
499
523
|
cookiePolicy?: RequestCredentials;
|
|
500
524
|
baseHeaders?: HeadersInit;
|
|
501
525
|
refreshCookieName?: string;
|
|
502
526
|
fetch?: typeof fetch;
|
|
503
|
-
}, "hooks"> & {
|
|
504
|
-
hooks?: {
|
|
505
|
-
beforeRequest?: BeforeRequest | BeforeRequest[];
|
|
506
|
-
afterRequest?: AfterRequest | AfterRequest[];
|
|
507
|
-
transformResponse?: (mutableResponse: ExtendedResponse) => Promise<ExtendedResponse>;
|
|
508
|
-
};
|
|
509
527
|
}) => {
|
|
510
528
|
accessKey: {
|
|
511
529
|
exchange: (accessKey: string, loginOptions?: AccessKeyLoginOptions) => Promise<SdkResponse<ExchangeAccessKeyResponse>>;
|
|
@@ -660,4 +678,4 @@ type DeliveryMethod = keyof typeof DeliveryMethods;
|
|
|
660
678
|
/** Type to restrict to valid OAuth providers */
|
|
661
679
|
type OAuthProvider = keyof typeof OAuthProviders;
|
|
662
680
|
|
|
663
|
-
export { type AccessKeyLoginOptions, type DeliveryMethod, type EnchantedLinkResponse, type ExchangeAccessKeyResponse, type ExtendedResponse, type FlowAction, type FlowResponse, FlowStatus, HTTPMethods, _default$
|
|
681
|
+
export { type AccessKeyLoginOptions, type CreateHttpClientConfig, type DeliveryMethod, type EnchantedLinkResponse, type ExchangeAccessKeyResponse, type ExtendedResponse, type FlowAction, type FlowResponse, FlowStatus, HTTPMethods, type HttpClient, _default$2 as HttpStatusCodes, type JWTResponse, type LoginOptions, type OAuthProvider, type PasskeyOptions, type RequestConfig, type ResponseData, type SdkFnWrapper, type SdkResponse, type TOTPResponse, type URLResponse, type UserHistoryResponse, type UserResponse, _default$1 as createHttpClient, _default as default, normalizeWaitForSessionConfig, transformResponse, wrapWith };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jwtDecode as e}from"jwt-decode";var t={accessKey:{exchange:"/v1/auth/accesskey/exchange"},otp:{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"},magicLink:{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"},enchantedLink:{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"},oauth:{start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish",oneTap:{getOneTapClientId:"/v1/auth/onetap/clientid/{provider}",exchangeOneTapIDToken:"/v1/auth/onetap/idtoken/exchange",verifyOneTapIDToken:"/v1/auth/onetap/idtoken/verify"}},outbound:{connect:"/v1/outbound/oauth/connect"},saml:{start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},totp:{verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},notp:{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"},webauthn:{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"}},password:{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"},refresh:"/v1/auth/refresh",selectTenant:"/v1/auth/tenant/select",logout:"/v1/auth/logout",logoutAll:"/v1/auth/logoutall",me:"/v1/auth/me",myTenants:"/v1/auth/me/tenants",history:"/v1/auth/me/history",flow:{start:"/v1/flow/start",next:"/v1/flow/next"}};const n="<region>",o=`https://api.${n}descope.com`,s=1e3,i=6e5,a="dct",r=()=>{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},retries(t){return e.Retries=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},p=[521,524],l=e=>async(...t)=>{let n=await e(...t);p.includes(n.status)&&(n=await e(...t),n.retries=1);const o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n},d=(e,t)=>{const n=t||fetch;return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>r().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await l(n)(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return r().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).retries(e.retries).build()})(o)),o}:l(n)};let u;const c=()=>{if(u)return u;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 u=`${t}-${n}`,u};var g;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT",e.patch="PATCH"}(g||(g={}));const h=({path:e,baseUrl:t,queryParams:o,projectId:s})=>{const i=s.slice(1,-27);t=t.replace(n,i?i+".":"");let a=e?`${t.replace(/\/$/,"")}/${null==e?void 0:e.replace(/^\//,"")}`:t;if(o){const e=Object.keys(o);e.forEach(((t,n)=>{a=`${a}${0===n?"?":""}${t}=${encodeURIComponent(o[t])}${n===e.length-1?"":"&"}`}))}return a},v=(...e)=>new Headers(e.reduce(((e,t)=>((e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t).forEach((([t,n])=>{e[t]="function"==typeof n?n():n})),e)),{})),f={"Content-Type":"application/json"},m=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},k=(e,t)=>{const n={"x-descope-sdk-session-id":c(),"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.45.0","x-descope-project-id":e};return t&&(n["x-descope-refresh-cookie-name"]=t),n},I=e=>{try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e},b=({baseUrl:e,projectId:t,baseConfig:n,refreshCookieName:o,logger:s,hooks:i,cookiePolicy:a,fetch:r})=>{const p=d(s,r),l=async s=>{var r;const l=(null==i?void 0:i.beforeRequest)?i.beforeRequest(s):s,{path:d,body:u,headers:c,queryParams:g,method:b,token:y}=l,O=(e=>void 0===e?void 0:JSON.stringify(e))(u),w={headers:v(m(t,y),k(t,o),(null==n?void 0:n.baseHeaders)||{},I(O)?f:{},c),method:b,body:O};null!==a&&(w.credentials=a||"include");const j=await p(h({path:d,baseUrl:e,queryParams:g,projectId:t}),w);if((null==i?void 0:i.afterRequest)&&await i.afterRequest(s,null==j?void 0:j.clone()),null==i?void 0:i.transformResponse){const e=await j.json(),t=((null===(r=j.headers)||void 0===r?void 0:r.get("set-cookie"))||"").split(";").reduce(((e,t)=>{const[n,o]=t.split("=");return Object.assign(Object.assign({},e),{[n.trim()]:o})}),{}),n=Object.assign(Object.assign({},j),{json:()=>Promise.resolve(e),cookies:t});return n.clone=()=>n,i.transformResponse(n)}return j};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:g.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:s}={})=>l({path:e,headers:n,queryParams:o,body:t,method:g.post,token:s}),patch:(e,t,{headers:n,queryParams:o,token:s}={})=>l({path:e,headers:n,queryParams:o,body:t,method:g.patch,token:s}),put:(e,t,{headers:n,queryParams:o,token:s}={})=>l({path:e,headers:n,queryParams:o,body:t,method:g.put,token:s}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:g.delete,token:o}),hooks:i,buildUrl:(n,o)=>h({projectId:t,baseUrl:e,path:n,queryParams:o})}};var y={TOO_MANY_REQUESTS:429};function O(e,t,n){var o;let s=w(e);if(t){if(!(null==s?void 0:s.tenants)&&(null==s?void 0:s[a])===t)return(null==s?void 0:s[n])||[];s=null===(o=null==s?void 0:s.tenants)||void 0===o?void 0:o[t]}const i=null==s?void 0:s[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){let t=w(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function T(e,t){return O(e,t,"permissions")}function R(e,t){return O(e,t,"roles")}const x=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function P(e,t){var n;const o=await e,s={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?s.data=t?t(i):i:(s.error=i,o.status===y.TOO_MANY_REQUESTS&&Object.assign(s.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),s}function $(e){var t;return(null===(t=w(e))||void 0===t?void 0:t[a])||""}const S=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),q=(e,t)=>(n=t)=>t=>{const o=e.filter((e=>e(t)));return!(o.length<e.length)&&(n?n.replace("{val}",t):o.join(" OR "))},C=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),A=e=>t=>e.test(t),E=A(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),M=A(/^\+[1-9]{1}[0-9]{3,14}$/),L=(e,t)=>n=>C(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),s=o.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<s;)a=a[o[i++]];return i&&i===s&&void 0!==a?a:n})(n,e)),N=S(E,'"{val}" is not a valid email'),D=S(M,'"{val}" is not a valid phone number'),H=S((J=1,e=>e.length>=J),"Minimum length is 1");var J;const z=S((e=>"string"==typeof e),"Input is not a string"),_=S((e=>Array.isArray(e)),"Input is not an array"),F=S((e=>"boolean"==typeof e),"Input is not a boolean"),K=S((e=>void 0===e),"Input is defined"),V=q([z(),K()],"Input is not a string or undefined"),Y=q([_(),F()],"Input is not an array or boolean"),Z=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>C(...e).validate(n[t]))),t(...n)),B=e=>[z(`"${e}" must be a string`)],Q=e=>[V(`"${e}" must be string or undefined`)],G=e=>[z(`"${e}" must be a string`),H(`"${e}" must not be empty`)],W=e=>[z(`"${e}" must be a string`),N()],X=e=>[z(`"${e}" must be a string`),D()],ee=Z(G("accessKey")),te=e=>({exchange:ee(((n,o)=>P(e.post(t.accessKey.exchange,{loginOptions:o},{token:n}))))}),ne=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let s=o.shift(),i=e;for(;o.length>0;){if(i=i[s],!s||!i)throw Error(`Invalid path "${t}", "${s}" is missing or has no value`);s=o.shift()}if("function"!=typeof i[s])throw Error(`"${t}" is not a function`);const a=i[s];i[s]=n(a)})),e),oe=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||s,s),timeoutMs:Math.min(t||i,i)});var se,ie;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(se||(se={})),function(e){e.email="email"}(ie||(ie={}));const ae=Object.assign(Object.assign({},se),ie);var re;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(re||(re={}));const pe=G("loginId"),le=Z(G("token")),de=Z(pe),ue=Z(G("pendingRef")),ce=Z(pe,W("email")),ge=e=>({verify:le((n=>P(e.post(t.enchantedLink.verify,{token:n})))),signIn:de(((n,o,s,i)=>P(e.post(x(t.enchantedLink.signIn,ae.email),{loginId:n,URI:o,loginOptions:s},{token:i})))),signUpOrIn:de(((n,o,s)=>P(e.post(x(t.enchantedLink.signUpOrIn,ae.email),{loginId:n,URI:o,loginOptions:s})))),signUp:de(((n,o,s,i)=>P(e.post(x(t.enchantedLink.signUp,ae.email),{loginId:n,URI:o,user:s,loginOptions:i})))),waitForSession:ue(((n,o)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=oe(o);let r;const p=setInterval((async()=>{const o=await e.post(t.enchantedLink.session,{pendingRef:n});o.ok&&(clearInterval(p),r&&clearTimeout(r),s(P(Promise.resolve(o))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)})))),update:{email:ce(((n,o,s,i,a)=>P(e.post(t.enchantedLink.update.email,Object.assign({loginId:n,email:o,URI:s},a),{token:i}))))}}),he=Z(G("flowId")),ve=Z(G("executionId"),G("stepId"),G("interactionId")),fe=e=>({start:he(((n,o,s,i,a,r,p)=>P(e.post(t.flow.start,{flowId:n,options:o,conditionInteractionId:s,interactionId:i,componentsVersion:a,flowVersions:r,input:p})))),next:ve(((n,o,s,i,a,r)=>P(e.post(t.flow.next,{executionId:n,stepId:o,interactionId:s,version:i,componentsVersion:a,input:r}))))}),me=G("loginId"),ke=Z(G("token")),Ie=Z(me),be=Z(me,X("phone")),ye=Z(me,W("email")),Oe=Object.keys(ae).filter((e=>e!==se.voice)),we=e=>({verify:ke((n=>P(e.post(t.magicLink.verify,{token:n})))),signIn:Oe.reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ie(((n,s,i,a)=>P(e.post(x(t.magicLink.signIn,o),{loginId:n,URI:s,loginOptions:i},{token:a}))))})),{}),signUp:Oe.reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ie(((n,s,i,a)=>P(e.post(x(t.magicLink.signUp,o),{loginId:n,URI:s,user:i,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ie(((n,s,i)=>P(e.post(x(t.magicLink.signUpOrIn,o),{loginId:n,URI:s,loginOptions:i}))))})),{}),update:{email:ye(((n,o,s,i,a)=>P(e.post(t.magicLink.update.email,Object.assign({loginId:n,email:o,URI:s},a),{token:i})))),phone:Object.keys(se).filter((e=>e!==se.voice)).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:be(((n,s,i,a,r)=>P(e.post(x(t.magicLink.update.phone,o),Object.assign({loginId:n,phone:s,URI:i},r),{token:a}))))})),{})}});var je;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(je||(je={}));const Ue=Z(G("code")),Te=e=>({start:Object.assign(((n,o,s,i,a)=>P(e.post(t.oauth.start,s||{},{queryParams:Object.assign(Object.assign({provider:n},o&&{redirectURL:o}),a&&{loginHint:a}),token:i}))),Object.keys(je).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:(n,s,i,a)=>P(e.post(t.oauth.start,s||{},{queryParams:Object.assign(Object.assign({provider:o},n&&{redirectURL:n}),a&&{loginHint:a}),token:i}))})),{})),exchange:Ue((n=>P(e.post(t.oauth.exchange,{code:n})))),startNative:(n,o,s)=>P(e.post(t.oauth.startNative,{provider:n,loginOptions:o,implicit:s})),finishNative:(n,o,s,i,a)=>P(e.post(t.oauth.finishNative,{provider:n,stateId:o,user:s,code:i,idToken:a})),getOneTapClientId:n=>P(e.get(t.oauth.oneTap.getOneTapClientId.replace("{provider}",n))),verifyOneTapIDToken:(n,o,s,i)=>P(e.post(t.oauth.oneTap.verifyOneTapIDToken,{provider:n,idToken:o,nonce:s,loginOptions:i})),exchangeOneTapIDToken:(n,o,s,i)=>P(e.post(t.oauth.oneTap.exchangeOneTapIDToken,{provider:n,idToken:o,nonce:s,loginOptions:i}))}),Re=G("appId"),xe=Z(Re),Pe=e=>({connect:xe(((n,o,s)=>P(e.post(t.outbound.connect,{appId:n,options:o},{token:s}))))}),$e=G("loginId"),Se=Z($e,G("code")),qe=Z($e),Ce=Z($e,X("phone")),Ae=Z($e,W("email")),Ee=e=>({verify:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Se(((n,s)=>P(e.post(x(t.otp.verify,o),{code:s,loginId:n}))))})),{}),signIn:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:qe(((n,s,i)=>P(e.post(x(t.otp.signIn,o),{loginId:n,loginOptions:s},{token:i}))))})),{}),signUp:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:qe(((n,s,i)=>P(e.post(x(t.otp.signUp,o),{loginId:n,user:s,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:qe(((n,s)=>P(e.post(x(t.otp.signUpOrIn,o),{loginId:n,loginOptions:s}))))})),{}),update:{email:Ae(((n,o,s,i)=>P(e.post(t.otp.update.email,Object.assign({loginId:n,email:o},i),{token:s})))),phone:Object.keys(se).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ce(((n,s,i,a)=>P(e.post(x(t.otp.update.phone,o),Object.assign({loginId:n,phone:s},a),{token:i}))))})),{})}}),Me=Z(G("tenant")),Le=Z(G("code")),Ne=e=>({start:Me(((n,o,s,i,a)=>P(e.post(t.saml.start,s||{},Object.assign({queryParams:Object.assign(Object.assign({tenant:n},o&&{redirectURL:o}),a&&{ssoId:a})},i&&{token:i}))))),exchange:Le((n=>P(e.post(t.saml.exchange,{code:n}))))}),De=G("loginId"),He=Z(De,G("code")),Je=Z(De),ze=Z(De),_e=e=>({signUp:Je(((n,o)=>P(e.post(t.totp.signUp,{loginId:n,user:o})))),verify:He(((n,o,s,i)=>P(e.post(t.totp.verify,{loginId:n,code:o,loginOptions:s},{token:i})))),update:ze(((n,o)=>P(e.post(t.totp.update,{loginId:n},{token:o}))))}),Fe=G("loginId"),Ke=G("newPassword"),Ve=Z(Fe,G("password")),Ye=Z(Fe),Ze=Z(Fe,Ke),Be=Z(Fe,G("oldPassword"),Ke),Qe=e=>({signUp:Ve(((n,o,s,i)=>P(e.post(t.password.signUp,{loginId:n,password:o,user:s,loginOptions:i})))),signIn:Ve(((n,o,s)=>P(e.post(t.password.signIn,{loginId:n,password:o,loginOptions:s})))),sendReset:Ye(((n,o,s)=>P(e.post(t.password.sendReset,{loginId:n,redirectUrl:o,templateOptions:s})))),update:Ze(((n,o,s)=>P(e.post(t.password.update,{loginId:n,newPassword:o},{token:s})))),replace:Be(((n,o,s)=>P(e.post(t.password.replace,{loginId:n,oldPassword:o,newPassword:s})))),policy:()=>P(e.get(t.password.policy))}),Ge=B("loginId"),We=G("loginId"),Xe=G("origin"),et=Z(We,Xe,G("name")),tt=Z(We,Xe),nt=Z(Ge,Xe),ot=Z(We,Xe,Q("token")),st=Z(G("transactionId"),G("response")),it=e=>({signUp:{start:et(((n,o,s,i)=>P(e.post(t.webauthn.signUp.start,{user:{loginId:n,name:s},origin:o,passkeyOptions:i})))),finish:st(((n,o)=>P(e.post(t.webauthn.signUp.finish,{transactionId:n,response:o}))))},signIn:{start:nt(((n,o,s,i,a)=>P(e.post(t.webauthn.signIn.start,{loginId:n,origin:o,loginOptions:s,passkeyOptions:a},{token:i})))),finish:st(((n,o)=>P(e.post(t.webauthn.signIn.finish,{transactionId:n,response:o}))))},signUpOrIn:{start:tt(((n,o,s)=>P(e.post(t.webauthn.signUpOrIn.start,{loginId:n,origin:o,passkeyOptions:s}))))},update:{start:ot(((n,o,s,i)=>P(e.post(t.webauthn.update.start,{loginId:n,origin:o,passkeyOptions:i},{token:s})))),finish:st(((n,o)=>P(e.post(t.webauthn.update.finish,{transactionId:n,response:o}))))}}),at=B("loginId"),rt=Z(at),pt=Z(G("pendingRef")),lt=e=>({signUpOrIn:rt(((n,o)=>P(e.post(t.notp.signUpOrIn,{loginId:n,loginOptions:o})))),signUp:rt(((n,o,s)=>P(e.post(t.notp.signUp,{loginId:n,user:o,loginOptions:s})))),signIn:rt(((n,o,s)=>P(e.post(t.notp.signIn,{loginId:n,loginOptions:o},{token:s})))),waitForSession:pt(((n,o)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=oe(o);let r;const p=setInterval((async()=>{const o=await e.post(t.notp.session,{pendingRef:n});o.ok&&(clearInterval(p),r&&clearTimeout(r),s(P(Promise.resolve(o))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)}))))}),dt=Z(G("token")),ut=Z(Q("token"));var ct,gt;var ht=Z([(ct="projectId",gt=G("projectId"),S(L(ct,gt))())])((e=>t=>{var n;return e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var o;const s=[].concat((null===(o=t.hooks)||void 0===o?void 0:o.afterRequest)||[]);if(0==s.length)return;(await Promise.allSettled(null==s?void 0:s.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:n,baseUrl:s,hooks:i,cookiePolicy:a,baseHeaders:r={},refreshCookieName:p,fetch:l})=>{return d=b({baseUrl:s||o,projectId:e,logger:n,hooks:i,cookiePolicy:a,baseConfig:{baseHeaders:r},refreshCookieName:p,fetch:l}),{accessKey:te(d),otp:Ee(d),magicLink:we(d),enchantedLink:ge(d),oauth:Te(d),outbound:Pe(d),saml:Ne(d),totp:_e(d),notp:lt(d),webauthn:it(d),password:Qe(d),flow:fe(d),refresh:ut(((e,n,o)=>{const s={};return o&&(s.externalToken=o),P(d.post(t.refresh,s,{token:e,queryParams:n}))})),selectTenant:Z([z("tenantId")],[V('"token" must be string or undefined')])(((e,n)=>P(d.post(t.selectTenant,{tenant:e},{token:n})))),logout:ut((e=>P(d.post(t.logout,{},{token:e})))),logoutAll:ut((e=>P(d.post(t.logoutAll,{},{token:e})))),me:ut((e=>P(d.get(t.me,{token:e})))),myTenants:Z([Y('"tenants" must a string array or a boolean')],[V('"token" must be string or undefined')])(((e,n)=>{const o={};return"boolean"==typeof e?o.dct=e:o.ids=e,P(d.post(t.myTenants,o,{token:n}))})),history:ut((e=>P(d.get(t.history,{token:e})))),isJwtExpired:dt(j),getTenants:dt(U),getJwtPermissions:dt(T),getJwtRoles:dt(R),getCurrentTenant:dt($),httpClient:d};var d}))),vt=Object.assign(ht,{DeliveryMethods:ae});export{y as HttpStatusCodes,vt as default,oe as normalizeWaitForSessionConfig,P as transformResponse,ne as wrapWith};
|
|
1
|
+
import{jwtDecode as e}from"jwt-decode";var t={accessKey:{exchange:"/v1/auth/accesskey/exchange"},otp:{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"},magicLink:{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"},enchantedLink:{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"},oauth:{start:"/v1/auth/oauth/authorize",exchange:"/v1/auth/oauth/exchange",startNative:"v1/auth/oauth/native/start",finishNative:"v1/auth/oauth/native/finish",oneTap:{getOneTapClientId:"/v1/auth/onetap/clientid/{provider}",exchangeOneTapIDToken:"/v1/auth/onetap/idtoken/exchange",verifyOneTapIDToken:"/v1/auth/onetap/idtoken/verify"}},outbound:{connect:"/v1/outbound/oauth/connect"},saml:{start:"/v1/auth/saml/authorize",exchange:"/v1/auth/saml/exchange"},totp:{verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},notp:{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"},webauthn:{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"}},password:{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"},refresh:"/v1/auth/refresh",selectTenant:"/v1/auth/tenant/select",logout:"/v1/auth/logout",logoutAll:"/v1/auth/logoutall",me:"/v1/auth/me",myTenants:"/v1/auth/me/tenants",history:"/v1/auth/me/history",flow:{start:"/v1/flow/start",next:"/v1/flow/next"}};const n="<region>",o=`https://api.${n}descope.com`,s=1e3,i=6e5,a="dct",r=()=>{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},retries(t){return e.Retries=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},p=[521,524],l=e=>async(...t)=>{let n=await e(...t);p.includes(n.status)&&(n=await e(...t),n.retries=1);const o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n},d=(e,t)=>{const n=t||fetch;return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>r().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await l(n)(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return r().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).retries(e.retries).build()})(o)),o}:l(n)};let u;const c=()=>{if(u)return u;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 u=`${t}-${n}`,u};var g;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT",e.patch="PATCH"}(g||(g={}));const h=({path:e,baseUrl:t,queryParams:o,projectId:s})=>{const i=s.slice(1,-27);t=t.replace(n,i?i+".":"");let a=e?`${t.replace(/\/$/,"")}/${null==e?void 0:e.replace(/^\//,"")}`:t;if(o){const e=Object.keys(o);e.forEach(((t,n)=>{a=`${a}${0===n?"?":""}${t}=${encodeURIComponent(o[t])}${n===e.length-1?"":"&"}`}))}return a},v=(...e)=>new Headers(e.reduce(((e,t)=>((e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t).forEach((([t,n])=>{e[t]="function"==typeof n?n():n})),e)),{})),f={"Content-Type":"application/json"},m=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},k=(e,t)=>{const n={"x-descope-sdk-session-id":c(),"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.46.1","x-descope-project-id":e};return t&&(n["x-descope-refresh-cookie-name"]=t),n},I=e=>{try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e};var b=(e=>t=>{var n;return e(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),e)},afterRequest:async(e,n)=>{var o;const s=[].concat((null===(o=t.hooks)||void 0===o?void 0:o.afterRequest)||[]);if(0==s.length)return;(await Promise.allSettled(null==s?void 0:s.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}}))})((({baseUrl:e=o,projectId:t,baseConfig:n,refreshCookieName:s,logger:i,hooks:a,cookiePolicy:r,fetch:p})=>{const l=d(i,p),u=async o=>{var i;const p=(null==a?void 0:a.beforeRequest)?a.beforeRequest(o):o,{path:d,body:u,headers:c,queryParams:g,method:b,token:y}=p,O=(e=>void 0===e?void 0:JSON.stringify(e))(u),w={headers:v(m(t,y),k(t,s),(null==n?void 0:n.baseHeaders)||{},I(O)?f:{},c),method:b,body:O};null!==r&&(w.credentials=r||"include");const j=await l(h({path:d,baseUrl:e,queryParams:g,projectId:t}),w);if((null==a?void 0:a.afterRequest)&&await a.afterRequest(o,null==j?void 0:j.clone()),null==a?void 0:a.transformResponse){const e=await j.json(),t=((null===(i=j.headers)||void 0===i?void 0:i.get("set-cookie"))||"").split(";").reduce(((e,t)=>{const[n,o]=t.split("=");return Object.assign(Object.assign({},e),{[n.trim()]:o})}),{}),n=Object.assign(Object.assign({},j),{json:()=>Promise.resolve(e),cookies:t});return n.clone=()=>n,a.transformResponse(n)}return j};return{get:(e,{headers:t,queryParams:n,token:o}={})=>u({path:e,headers:t,queryParams:n,body:void 0,method:g.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:s}={})=>u({path:e,headers:n,queryParams:o,body:t,method:g.post,token:s}),patch:(e,t,{headers:n,queryParams:o,token:s}={})=>u({path:e,headers:n,queryParams:o,body:t,method:g.patch,token:s}),put:(e,t,{headers:n,queryParams:o,token:s}={})=>u({path:e,headers:n,queryParams:o,body:t,method:g.put,token:s}),delete:(e,{headers:t,queryParams:n,token:o}={})=>u({path:e,headers:t,queryParams:n,body:void 0,method:g.delete,token:o}),hooks:a,buildUrl:(n,o)=>h({projectId:t,baseUrl:e,path:n,queryParams:o})}})),y={TOO_MANY_REQUESTS:429};function O(e,t,n){var o;let s=w(e);if(t){if(!(null==s?void 0:s.tenants)&&(null==s?void 0:s[a])===t)return(null==s?void 0:s[n])||[];s=null===(o=null==s?void 0:s.tenants)||void 0===o?void 0:o[t]}const i=null==s?void 0:s[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){let t=w(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function T(e,t){return O(e,t,"permissions")}function R(e,t){return O(e,t,"roles")}const x=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function P(e,t){var n;const o=await e,s={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?s.data=t?t(i):i:(s.error=i,o.status===y.TOO_MANY_REQUESTS&&Object.assign(s.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),s}function $(e){var t;return(null===(t=w(e))||void 0===t?void 0:t[a])||""}const q=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),S=(e,t)=>(n=t)=>t=>{const o=e.filter((e=>e(t)));return!(o.length<e.length)&&(n?n.replace("{val}",t):o.join(" OR "))},C=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),A=e=>t=>e.test(t),E=A(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),M=A(/^\+[1-9]{1}[0-9]{3,14}$/),L=(e,t)=>n=>C(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),s=o.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<s;)a=a[o[i++]];return i&&i===s&&void 0!==a?a:n})(n,e)),N=q(E,'"{val}" is not a valid email'),D=q(M,'"{val}" is not a valid phone number'),H=q((J=1,e=>e.length>=J),"Minimum length is 1");var J;const z=q((e=>"string"==typeof e),"Input is not a string"),_=q((e=>Array.isArray(e)),"Input is not an array"),F=q((e=>"boolean"==typeof e),"Input is not a boolean"),K=q((e=>void 0===e),"Input is defined"),V=S([z(),K()],"Input is not a string or undefined"),Y=S([_(),F()],"Input is not an array or boolean"),Z=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>C(...e).validate(n[t]))),t(...n)),B=e=>[z(`"${e}" must be a string`)],Q=e=>[V(`"${e}" must be string or undefined`)],G=e=>[z(`"${e}" must be a string`),H(`"${e}" must not be empty`)],W=e=>[z(`"${e}" must be a string`),N()],X=e=>[z(`"${e}" must be a string`),D()],ee=Z(G("accessKey")),te=e=>({exchange:ee(((n,o)=>P(e.post(t.accessKey.exchange,{loginOptions:o},{token:n}))))}),ne=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let s=o.shift(),i=e;for(;o.length>0;){if(i=i[s],!s||!i)throw Error(`Invalid path "${t}", "${s}" is missing or has no value`);s=o.shift()}if("function"!=typeof i[s])throw Error(`"${t}" is not a function`);const a=i[s];i[s]=n(a)})),e),oe=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||s,s),timeoutMs:Math.min(t||i,i)});var se,ie;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(se||(se={})),function(e){e.email="email"}(ie||(ie={}));const ae=Object.assign(Object.assign({},se),ie);var re;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(re||(re={}));const pe=G("loginId"),le=Z(G("token")),de=Z(pe),ue=Z(G("pendingRef")),ce=Z(pe,W("email")),ge=e=>({verify:le((n=>P(e.post(t.enchantedLink.verify,{token:n})))),signIn:de(((n,o,s,i)=>P(e.post(x(t.enchantedLink.signIn,ae.email),{loginId:n,URI:o,loginOptions:s},{token:i})))),signUpOrIn:de(((n,o,s)=>P(e.post(x(t.enchantedLink.signUpOrIn,ae.email),{loginId:n,URI:o,loginOptions:s})))),signUp:de(((n,o,s,i)=>P(e.post(x(t.enchantedLink.signUp,ae.email),{loginId:n,URI:o,user:s,loginOptions:i})))),waitForSession:ue(((n,o)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=oe(o);let r;const p=setInterval((async()=>{const o=await e.post(t.enchantedLink.session,{pendingRef:n});o.ok&&(clearInterval(p),r&&clearTimeout(r),s(P(Promise.resolve(o))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)})))),update:{email:ce(((n,o,s,i,a)=>P(e.post(t.enchantedLink.update.email,Object.assign({loginId:n,email:o,URI:s},a),{token:i}))))}}),he=Z(G("flowId")),ve=Z(G("executionId"),G("stepId"),G("interactionId")),fe=e=>({start:he(((n,o,s,i,a,r,p)=>P(e.post(t.flow.start,{flowId:n,options:o,conditionInteractionId:s,interactionId:i,componentsVersion:a,flowVersions:r,input:p})))),next:ve(((n,o,s,i,a,r)=>P(e.post(t.flow.next,{executionId:n,stepId:o,interactionId:s,version:i,componentsVersion:a,input:r}))))}),me=G("loginId"),ke=Z(G("token")),Ie=Z(me),be=Z(me,X("phone")),ye=Z(me,W("email")),Oe=Object.keys(ae).filter((e=>e!==se.voice)),we=e=>({verify:ke((n=>P(e.post(t.magicLink.verify,{token:n})))),signIn:Oe.reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ie(((n,s,i,a)=>P(e.post(x(t.magicLink.signIn,o),{loginId:n,URI:s,loginOptions:i},{token:a}))))})),{}),signUp:Oe.reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ie(((n,s,i,a)=>P(e.post(x(t.magicLink.signUp,o),{loginId:n,URI:s,user:i,loginOptions:a}))))})),{}),signUpOrIn:Oe.reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ie(((n,s,i)=>P(e.post(x(t.magicLink.signUpOrIn,o),{loginId:n,URI:s,loginOptions:i}))))})),{}),update:{email:ye(((n,o,s,i,a)=>P(e.post(t.magicLink.update.email,Object.assign({loginId:n,email:o,URI:s},a),{token:i})))),phone:Object.keys(se).filter((e=>e!==se.voice)).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:be(((n,s,i,a,r)=>P(e.post(x(t.magicLink.update.phone,o),Object.assign({loginId:n,phone:s,URI:i},r),{token:a}))))})),{})}});var je;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(je||(je={}));const Ue=Z(G("code")),Te=e=>({start:Object.assign(((n,o,s,i,a)=>P(e.post(t.oauth.start,s||{},{queryParams:Object.assign(Object.assign({provider:n},o&&{redirectURL:o}),a&&{loginHint:a}),token:i}))),Object.keys(je).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:(n,s,i,a)=>P(e.post(t.oauth.start,s||{},{queryParams:Object.assign(Object.assign({provider:o},n&&{redirectURL:n}),a&&{loginHint:a}),token:i}))})),{})),exchange:Ue((n=>P(e.post(t.oauth.exchange,{code:n})))),startNative:(n,o,s)=>P(e.post(t.oauth.startNative,{provider:n,loginOptions:o,implicit:s})),finishNative:(n,o,s,i,a)=>P(e.post(t.oauth.finishNative,{provider:n,stateId:o,user:s,code:i,idToken:a})),getOneTapClientId:n=>P(e.get(t.oauth.oneTap.getOneTapClientId.replace("{provider}",n))),verifyOneTapIDToken:(n,o,s,i)=>P(e.post(t.oauth.oneTap.verifyOneTapIDToken,{provider:n,idToken:o,nonce:s,loginOptions:i})),exchangeOneTapIDToken:(n,o,s,i)=>P(e.post(t.oauth.oneTap.exchangeOneTapIDToken,{provider:n,idToken:o,nonce:s,loginOptions:i}))}),Re=G("appId"),xe=Z(Re),Pe=e=>({connect:xe(((n,o,s)=>P(e.post(t.outbound.connect,{appId:n,options:o},{token:s}))))}),$e=G("loginId"),qe=Z($e,G("code")),Se=Z($e),Ce=Z($e,X("phone")),Ae=Z($e,W("email")),Ee=e=>({verify:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:qe(((n,s)=>P(e.post(x(t.otp.verify,o),{code:s,loginId:n}))))})),{}),signIn:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Se(((n,s,i)=>P(e.post(x(t.otp.signIn,o),{loginId:n,loginOptions:s},{token:i}))))})),{}),signUp:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Se(((n,s,i)=>P(e.post(x(t.otp.signUp,o),{loginId:n,user:s,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ae).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Se(((n,s)=>P(e.post(x(t.otp.signUpOrIn,o),{loginId:n,loginOptions:s}))))})),{}),update:{email:Ae(((n,o,s,i)=>P(e.post(t.otp.update.email,Object.assign({loginId:n,email:o},i),{token:s})))),phone:Object.keys(se).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:Ce(((n,s,i,a)=>P(e.post(x(t.otp.update.phone,o),Object.assign({loginId:n,phone:s},a),{token:i}))))})),{})}}),Me=Z(G("tenant")),Le=Z(G("code")),Ne=e=>({start:Me(((n,o,s,i,a)=>P(e.post(t.saml.start,s||{},Object.assign({queryParams:Object.assign(Object.assign({tenant:n},o&&{redirectURL:o}),a&&{ssoId:a})},i&&{token:i}))))),exchange:Le((n=>P(e.post(t.saml.exchange,{code:n}))))}),De=G("loginId"),He=Z(De,G("code")),Je=Z(De),ze=Z(De),_e=e=>({signUp:Je(((n,o)=>P(e.post(t.totp.signUp,{loginId:n,user:o})))),verify:He(((n,o,s,i)=>P(e.post(t.totp.verify,{loginId:n,code:o,loginOptions:s},{token:i})))),update:ze(((n,o)=>P(e.post(t.totp.update,{loginId:n},{token:o}))))}),Fe=G("loginId"),Ke=G("newPassword"),Ve=Z(Fe,G("password")),Ye=Z(Fe),Ze=Z(Fe,Ke),Be=Z(Fe,G("oldPassword"),Ke),Qe=e=>({signUp:Ve(((n,o,s,i)=>P(e.post(t.password.signUp,{loginId:n,password:o,user:s,loginOptions:i})))),signIn:Ve(((n,o,s)=>P(e.post(t.password.signIn,{loginId:n,password:o,loginOptions:s})))),sendReset:Ye(((n,o,s)=>P(e.post(t.password.sendReset,{loginId:n,redirectUrl:o,templateOptions:s})))),update:Ze(((n,o,s)=>P(e.post(t.password.update,{loginId:n,newPassword:o},{token:s})))),replace:Be(((n,o,s)=>P(e.post(t.password.replace,{loginId:n,oldPassword:o,newPassword:s})))),policy:()=>P(e.get(t.password.policy))}),Ge=B("loginId"),We=G("loginId"),Xe=G("origin"),et=Z(We,Xe,G("name")),tt=Z(We,Xe),nt=Z(Ge,Xe),ot=Z(We,Xe,Q("token")),st=Z(G("transactionId"),G("response")),it=e=>({signUp:{start:et(((n,o,s,i)=>P(e.post(t.webauthn.signUp.start,{user:{loginId:n,name:s},origin:o,passkeyOptions:i})))),finish:st(((n,o)=>P(e.post(t.webauthn.signUp.finish,{transactionId:n,response:o}))))},signIn:{start:nt(((n,o,s,i,a)=>P(e.post(t.webauthn.signIn.start,{loginId:n,origin:o,loginOptions:s,passkeyOptions:a},{token:i})))),finish:st(((n,o)=>P(e.post(t.webauthn.signIn.finish,{transactionId:n,response:o}))))},signUpOrIn:{start:tt(((n,o,s)=>P(e.post(t.webauthn.signUpOrIn.start,{loginId:n,origin:o,passkeyOptions:s}))))},update:{start:ot(((n,o,s,i)=>P(e.post(t.webauthn.update.start,{loginId:n,origin:o,passkeyOptions:i},{token:s})))),finish:st(((n,o)=>P(e.post(t.webauthn.update.finish,{transactionId:n,response:o}))))}}),at=B("loginId"),rt=Z(at),pt=Z(G("pendingRef")),lt=e=>({signUpOrIn:rt(((n,o)=>P(e.post(t.notp.signUpOrIn,{loginId:n,loginOptions:o})))),signUp:rt(((n,o,s)=>P(e.post(t.notp.signUp,{loginId:n,user:o,loginOptions:s})))),signIn:rt(((n,o,s)=>P(e.post(t.notp.signIn,{loginId:n,loginOptions:o},{token:s})))),waitForSession:pt(((n,o)=>new Promise((s=>{const{pollingIntervalMs:i,timeoutMs:a}=oe(o);let r;const p=setInterval((async()=>{const o=await e.post(t.notp.session,{pendingRef:n});o.ok&&(clearInterval(p),r&&clearTimeout(r),s(P(Promise.resolve(o))))}),i);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(p)}),a)}))))}),dt=Z(G("token")),ut=Z(Q("token"));var ct,gt,ht=Z([(ct="projectId",gt=G("projectId"),q(L(ct,gt))())])((e=>{const{projectId:n,logger:o,baseUrl:s,cookiePolicy:i,baseHeaders:a={},refreshCookieName:r,fetch:p}=e;return l=b({baseUrl:s,projectId:n,logger:o,hooks:{get beforeRequest(){var t;return null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest},get afterRequest(){var t;return null===(t=e.hooks)||void 0===t?void 0:t.afterRequest},get transformResponse(){var t;return null===(t=e.hooks)||void 0===t?void 0:t.transformResponse}},cookiePolicy:i,baseConfig:{baseHeaders:a},refreshCookieName:r,fetch:p}),{accessKey:te(l),otp:Ee(l),magicLink:we(l),enchantedLink:ge(l),oauth:Te(l),outbound:Pe(l),saml:Ne(l),totp:_e(l),notp:lt(l),webauthn:it(l),password:Qe(l),flow:fe(l),refresh:ut(((e,n,o)=>{const s={};return o&&(s.externalToken=o),P(l.post(t.refresh,s,{token:e,queryParams:n}))})),selectTenant:Z([z("tenantId")],[V('"token" must be string or undefined')])(((e,n)=>P(l.post(t.selectTenant,{tenant:e},{token:n})))),logout:ut((e=>P(l.post(t.logout,{},{token:e})))),logoutAll:ut((e=>P(l.post(t.logoutAll,{},{token:e})))),me:ut((e=>P(l.get(t.me,{token:e})))),myTenants:Z([Y('"tenants" must a string array or a boolean')],[V('"token" must be string or undefined')])(((e,n)=>{const o={};return"boolean"==typeof e?o.dct=e:o.ids=e,P(l.post(t.myTenants,o,{token:n}))})),history:ut((e=>P(l.get(t.history,{token:e})))),isJwtExpired:dt(j),getTenants:dt(U),getJwtPermissions:dt(T),getJwtRoles:dt(R),getCurrentTenant:dt($),httpClient:l};var l})),vt=Object.assign(ht,{DeliveryMethods:ae});export{y as HttpStatusCodes,b as createHttpClient,vt as default,oe as normalizeWaitForSessionConfig,P as transformResponse,ne as wrapWith};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|