@descope/core-js-sdk 1.3.4 → 1.3.6

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/index.d.ts CHANGED
@@ -1,35 +1,35 @@
1
- declare type JSONSerializable = string | number | boolean | null | Array<JSONSerializable>;
2
- declare type FlowInput = Record<string, JSONSerializable>;
1
+ type JSONSerializable = string | number | boolean | null | Array<JSONSerializable>;
2
+ type FlowInput = Record<string, JSONSerializable>;
3
3
 
4
- declare type DeviceInfo = {
4
+ type DeviceInfo = {
5
5
  webAuthnSupport?: boolean;
6
6
  };
7
- declare type LastAuth = {
7
+ type LastAuth = {
8
8
  authMethod?: AuthMethod;
9
9
  oauthProvider?: string;
10
10
  name?: string;
11
11
  loginId?: string;
12
12
  };
13
- declare type RedirectAuth = {
13
+ type RedirectAuth = {
14
14
  callbackUrl: string;
15
15
  codeChallenge: string;
16
16
  };
17
- declare type AuthMethod = 'magiclink' | 'enchantedlink' | 'otp' | 'totp' | 'oauth' | 'saml' | 'webauthn';
18
- declare type SdkFn$1 = (...args: any[]) => Promise<SdkResponse<ResponseData>>;
19
- declare type MaskedPhone = {
17
+ type AuthMethod = 'magiclink' | 'enchantedlink' | 'otp' | 'totp' | 'oauth' | 'saml' | 'webauthn';
18
+ type SdkFn$1 = (...args: any[]) => Promise<SdkResponse<ResponseData>>;
19
+ type MaskedPhone = {
20
20
  maskedPhone: string;
21
21
  };
22
- declare type MaskedEmail = {
22
+ type MaskedEmail = {
23
23
  maskedEmail: string;
24
24
  };
25
25
  /** User base details from Descope API */
26
- declare type User = {
26
+ type User = {
27
27
  email?: string;
28
28
  name?: string;
29
29
  phone?: string;
30
30
  };
31
31
  /** User extended details from Descope API */
32
- declare type UserResponse = User & {
32
+ type UserResponse = User & {
33
33
  loginIds: string[];
34
34
  userId: string;
35
35
  verifiedEmail?: boolean;
@@ -43,18 +43,18 @@ declare type UserResponse = User & {
43
43
  oauth?: Record<string, boolean>;
44
44
  };
45
45
  /** A tenant association mapping */
46
- declare type UserTenant = {
46
+ type UserTenant = {
47
47
  tenantId: string;
48
48
  roleNames?: string[];
49
49
  };
50
50
  /** Login options to be added to the different authentication methods */
51
- declare type LoginOptions = {
51
+ type LoginOptions = {
52
52
  stepup?: boolean;
53
53
  mfa?: boolean;
54
54
  customClaims?: Record<string, any>;
55
55
  };
56
56
  /** Authentication info result from the various JWT validations */
57
- declare type JWTResponse = {
57
+ type JWTResponse = {
58
58
  sessionJwt: string;
59
59
  refreshJwt?: string;
60
60
  cookieDomain?: string;
@@ -65,19 +65,19 @@ declare type JWTResponse = {
65
65
  firstSeen?: boolean;
66
66
  };
67
67
  /** Authentication info result from exchanging access keys for a session */
68
- declare type ExchangeAccessKeyResponse = {
68
+ type ExchangeAccessKeyResponse = {
69
69
  keyId: string;
70
70
  sessionJwt: string;
71
71
  expiration: number;
72
72
  };
73
73
  /** The response returned from the various start webauthn functions */
74
- declare type WebAuthnStartResponse = {
74
+ type WebAuthnStartResponse = {
75
75
  transactionId: string;
76
76
  options: string;
77
77
  create: boolean;
78
78
  };
79
79
  /** Enchanted link response */
80
- declare type EnchantedLinkResponse = {
80
+ type EnchantedLinkResponse = {
81
81
  /** Pending reference URL to poll while waiting for user to click magic link */
82
82
  pendingRef: string;
83
83
  /** Link id, on which link the user should click */
@@ -86,24 +86,24 @@ declare type EnchantedLinkResponse = {
86
86
  maskedEmail: string;
87
87
  };
88
88
  /** URL response to redirect user in case of OAuth or SSO */
89
- declare type URLResponse = {
89
+ type URLResponse = {
90
90
  url: string;
91
91
  };
92
92
  /** TOTP response with the TOTP details */
93
- declare type TOTPResponse = {
93
+ type TOTPResponse = {
94
94
  provisioningURL: string;
95
95
  image: string;
96
96
  key: string;
97
97
  };
98
98
  /** Password reset response with details according to response method */
99
- declare type PasswordResetResponse = {
99
+ type PasswordResetResponse = {
100
100
  resetMethod: string;
101
101
  pendingRef?: string;
102
102
  linkId?: string;
103
103
  maskedEmail: string;
104
104
  };
105
105
  /** A subset of the password policy that can be checked on the client side for better UX */
106
- declare type PasswordPolicyResponse = {
106
+ type PasswordPolicyResponse = {
107
107
  minLength: number;
108
108
  lowercase: boolean;
109
109
  uppercase: boolean;
@@ -119,7 +119,7 @@ declare enum DeliveryEmail {
119
119
  email = "email"
120
120
  }
121
121
  /** All delivery methods currently supported */
122
- declare type DeliveryMethods = DeliveryPhone | DeliveryEmail;
122
+ type DeliveryMethods = DeliveryPhone | DeliveryEmail;
123
123
  declare const DeliveryMethods: {
124
124
  readonly email: DeliveryEmail.email;
125
125
  readonly sms: DeliveryPhone.sms;
@@ -144,9 +144,9 @@ declare enum FlowStatus {
144
144
  * - webauthnCreate/webauthnGet - next action is to prompt webauthn (details in 'webauthn' attribute)
145
145
  * - none - no next action
146
146
  */
147
- declare type FlowAction = 'screen' | 'poll' | 'redirect' | 'webauthnCreate' | 'webauthnGet' | 'none';
147
+ type FlowAction = 'screen' | 'poll' | 'redirect' | 'webauthnCreate' | 'webauthnGet' | 'none';
148
148
  /** Flow response with flow execution details */
149
- declare type FlowResponse = {
149
+ type FlowResponse = {
150
150
  executionId: string;
151
151
  stepId: string;
152
152
  status: FlowStatus;
@@ -171,19 +171,20 @@ declare type FlowResponse = {
171
171
  authInfo?: JWTResponse;
172
172
  lastAuth?: Pick<LastAuth, 'authMethod' | 'oauthProvider'>;
173
173
  };
174
- declare type Options = {
174
+ type Options = {
175
175
  redirectUrl?: string;
176
176
  tenant?: string;
177
177
  deviceInfo?: DeviceInfo;
178
178
  lastAuth?: LastAuth;
179
179
  redirectAuth?: RedirectAuth;
180
+ oidcIdpStateId?: string;
180
181
  };
181
- declare type ResponseData = Record<string, any>;
182
+ type ResponseData = Record<string, any>;
182
183
  /**
183
184
  * Response from our SDK calls which includes the result (ok, code, error).
184
185
  * The relevant data is provided in the more specific interfaces extending SdkResponse.
185
186
  */
186
- declare type SdkResponse<T extends ResponseData> = {
187
+ type SdkResponse<T extends ResponseData> = {
187
188
  code?: number;
188
189
  ok: boolean;
189
190
  response?: Response;
@@ -196,29 +197,29 @@ declare type SdkResponse<T extends ResponseData> = {
196
197
  data?: T;
197
198
  };
198
199
  /** Different delivery method */
199
- declare type Deliveries<T extends Record<DeliveryMethods, SdkFn$1>> = {
200
+ type Deliveries<T extends Record<DeliveryMethods, SdkFn$1>> = {
200
201
  [S in DeliveryMethods]: T[S];
201
202
  };
202
- declare type DeliveriesPhone<T extends Record<DeliveryPhone, SdkFn$1> | SdkFn$1> = {
203
+ type DeliveriesPhone<T extends Record<DeliveryPhone, SdkFn$1> | SdkFn$1> = {
203
204
  [S in DeliveryPhone]: T extends Record<DeliveryPhone, SdkFn$1> ? T[S] : T;
204
205
  };
205
206
  /** Logger type that supports the given levels (debug, log, error) */
206
- declare type Logger = Pick<Console, 'debug' | 'log' | 'error' | 'warn'>;
207
- declare type UpdateOptions<T extends boolean> = {
207
+ type Logger = Pick<Console, 'debug' | 'log' | 'error' | 'warn'>;
208
+ type UpdateOptions<T extends boolean> = {
208
209
  addToLoginIDs?: T;
209
210
  onMergeUseExisting?: T extends true ? boolean : never;
210
211
  };
211
212
 
212
- declare type EnchantedLinkSignInFn = (loginId: string, uri: string) => Promise<SdkResponse<EnchantedLinkResponse>>;
213
- declare type EnchantedLinkSignUpFn = (loginId: string, uri: string, user?: User) => Promise<SdkResponse<EnchantedLinkResponse>>;
213
+ type EnchantedLinkSignInFn = (loginId: string, uri: string) => Promise<SdkResponse<EnchantedLinkResponse>>;
214
+ type EnchantedLinkSignUpFn = (loginId: string, uri: string, user?: User) => Promise<SdkResponse<EnchantedLinkResponse>>;
214
215
  /** Polling configuration for session waiting */
215
- declare type WaitForSessionConfig = {
216
+ type WaitForSessionConfig = {
216
217
  pollingIntervalMs: number;
217
218
  timeoutMs: number;
218
219
  };
219
220
 
220
221
  /** Request configuration including headers, query params and token */
221
- declare type HttpClientReqConfig = {
222
+ type HttpClientReqConfig = {
222
223
  headers?: HeadersInit;
223
224
  queryParams?: {
224
225
  [key: string]: string;
@@ -233,7 +234,7 @@ declare enum HTTPMethods {
233
234
  put = "PUT"
234
235
  }
235
236
  /** HTTP Client type that implements the HTTP method calls. Descopers can provide their own HTTP client although required only in rare cases. */
236
- declare type HttpClient = {
237
+ type HttpClient = {
237
238
  get: (path: string, config?: HttpClientReqConfig) => Promise<Response>;
238
239
  post: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
239
240
  put: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
@@ -241,7 +242,7 @@ declare type HttpClient = {
241
242
  hooks?: Hooks;
242
243
  };
243
244
  /** For before-request hook allows overriding parts of the request */
244
- declare type RequestConfig = {
245
+ type RequestConfig = {
245
246
  path: string;
246
247
  headers?: HeadersInit;
247
248
  queryParams?: {
@@ -251,10 +252,10 @@ declare type RequestConfig = {
251
252
  method: HTTPMethods;
252
253
  token?: string;
253
254
  };
254
- declare type BeforeRequest = (config: RequestConfig) => RequestConfig;
255
- declare type AfterRequest = (req: RequestConfig, res: Response) => void | Promise<void>;
255
+ type BeforeRequest = (config: RequestConfig) => RequestConfig;
256
+ type AfterRequest = (req: RequestConfig, res: Response) => void | Promise<void>;
256
257
  /** Hooks before and after the request is made */
257
- declare type Hooks = {
258
+ type Hooks = {
258
259
  beforeRequest?: BeforeRequest;
259
260
  afterRequest?: AfterRequest;
260
261
  };
@@ -276,24 +277,24 @@ declare enum OAuthProviders {
276
277
  */
277
278
  declare function transformResponse<T extends ResponseData, S extends ResponseData = T>(response: Promise<Response>, transform?: (data: T) => S): Promise<SdkResponse<S>>;
278
279
 
279
- declare type IsObject<T> = T extends Array<any> ? false : T extends Function ? false : T extends object ? true : false;
280
- declare type Tail<T extends ReadonlyArray<string>> = T extends readonly [
280
+ type IsObject<T> = T extends Array<any> ? false : T extends Function ? false : T extends object ? true : false;
281
+ type Tail<T extends ReadonlyArray<string>> = T extends readonly [
281
282
  head: any,
282
283
  ...tail: infer Tail_
283
284
  ] ? Tail_ : never;
284
- declare type Head<T extends ReadonlyArray<string>> = T extends readonly [] ? never : T[0];
285
- declare type SdkResponseType<F extends SdkFn<ResponseData>> = F extends SdkFn<infer U> ? U : never;
286
- declare type SdkFnWrapperInternal<F extends SdkFn<ResponseData>, R extends ResponseData> = (fn: (...args: Parameters<F>) => ReturnType<F>) => (...args: Parameters<F>) => Promise<SdkResponse<R extends Record<string, never> ? SdkResponseType<F> : SdkResponseType<F> & R>>;
287
- declare type PrependDot<T extends string> = [T] extends [never] ? '' : `.${T}`;
288
- declare type SdkFnsPaths<T extends object> = keyof T extends infer K ? K extends string & keyof T ? IsObject<T> extends false ? never : T[K] extends SdkFn<ResponseData> ? K : IsObject<T[K]> extends false ? never : T[K] extends object ? `${K}${PrependDot<SdkFnsPaths<T[K]>>}` : never : never : never;
289
- declare type ReplacePaths<Obj extends object, Paths extends ReadonlyArray<string>, WrapperData extends Record<string, any>> = Head<Paths> extends never ? Obj : Tail<Paths> extends ReadonlyArray<string> ? ReplacePaths<ReplacePath<Obj, Head<Paths>, WrapperData>, Tail<Paths>, WrapperData> : ReplacePath<Obj, Head<Paths>, WrapperData>;
290
- declare type ReplacePath<Obj, Path extends string, WrapperData extends Record<string, any>> = Path extends `${infer Head}.${infer Tail}` ? {
285
+ type Head<T extends ReadonlyArray<string>> = T extends readonly [] ? never : T[0];
286
+ type SdkResponseType<F extends SdkFn<ResponseData>> = F extends SdkFn<infer U> ? U : never;
287
+ type SdkFnWrapperInternal<F extends SdkFn<ResponseData>, R extends ResponseData> = (fn: (...args: Parameters<F>) => ReturnType<F>) => (...args: Parameters<F>) => Promise<SdkResponse<R extends Record<string, never> ? SdkResponseType<F> : SdkResponseType<F> & R>>;
288
+ type PrependDot<T extends string> = [T] extends [never] ? '' : `.${T}`;
289
+ type SdkFnsPaths<T extends object> = keyof T extends infer K ? K extends string & keyof T ? IsObject<T> extends false ? never : T[K] extends SdkFn<ResponseData> ? K : IsObject<T[K]> extends false ? never : T[K] extends object ? `${K}${PrependDot<SdkFnsPaths<T[K]>>}` : never : never : never;
290
+ type ReplacePaths<Obj extends object, Paths extends ReadonlyArray<string>, WrapperData extends Record<string, any>> = Head<Paths> extends never ? Obj : Tail<Paths> extends ReadonlyArray<string> ? ReplacePaths<ReplacePath<Obj, Head<Paths>, WrapperData>, Tail<Paths>, WrapperData> : ReplacePath<Obj, Head<Paths>, WrapperData>;
291
+ type ReplacePath<Obj, Path extends string, WrapperData extends Record<string, any>> = Path extends `${infer Head}.${infer Tail}` ? {
291
292
  [Key in keyof Obj]: Key extends Head ? ReplacePath<Obj[Key], Tail, WrapperData> : Obj[Key];
292
293
  } : {
293
294
  [Key in keyof Obj]: Key extends Path ? Obj[Key] extends SdkFn<ResponseData> ? ReturnType<SdkFnWrapperInternal<Obj[Key], WrapperData>> : Obj[Key] : Obj[Key];
294
295
  };
295
- declare type SdkFn<T extends ResponseData> = (...args: any) => Promise<SdkResponse<T>>;
296
- declare type SdkFnWrapper<Z extends ResponseData> = <A extends any[], R extends ResponseData>(fn: (...args: A) => Promise<SdkResponse<R>>) => (...args: A) => Promise<SdkResponse<Z extends Record<string, never> ? R : Z & R>>;
296
+ type SdkFn<T extends ResponseData> = (...args: any) => Promise<SdkResponse<T>>;
297
+ type SdkFnWrapper<Z extends ResponseData> = <A extends any[], R extends ResponseData>(fn: (...args: A) => Promise<SdkResponse<R>>) => (...args: A) => Promise<SdkResponse<Z extends Record<string, never> ? R : Z & R>>;
297
298
 
298
299
  /**
299
300
  * A wrapper function that allows to wrap multiple Sdk function
@@ -511,8 +512,8 @@ declare const _default: ((config: Omit<{
511
512
  };
512
513
 
513
514
  /** Type to restrict to valid delivery methods */
514
- declare type DeliveryMethod = keyof typeof DeliveryMethods;
515
+ type DeliveryMethod = keyof typeof DeliveryMethods;
515
516
  /** Type to restrict to valid OAuth providers */
516
- declare type OAuthProvider = keyof typeof OAuthProviders;
517
+ type OAuthProvider = keyof typeof OAuthProviders;
517
518
 
518
519
  export { DeliveryMethod, EnchantedLinkResponse, ExchangeAccessKeyResponse, FlowAction, FlowResponse, FlowStatus, HTTPMethods, _default$1 as HttpStatusCodes, JWTResponse, OAuthProvider, RequestConfig, ResponseData, SdkFnWrapper, SdkResponse, TOTPResponse, URLResponse, UserResponse, _default as default, transformResponse, wrapWith };
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- 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"},d={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},u={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},p="/v1/auth/refresh",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v={start:"/v1/flow/start",next:"/v1/flow/next"};const f=1e3,m=6e5,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")}},b=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>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.text();return I().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var y;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(y||(y={}));const k=(...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,fetch:a})=>{const r=b(s,a),d=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:d,body:u,headers:l,queryParams:p,method:c,token:g}=a,h=await r((({path:e,baseUrl:t,queryParams:n})=>{const s=new URL(e,t);return n&&(s.search=new URLSearchParams(n).toString()),s})({path:d,baseUrl:e,queryParams:p}),{headers:k(w(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.4"},(null==n?void 0:n.baseHeaders)||{},l),method:c,body:O(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:y.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:y.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:y.put,token:o}),delete:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:y.delete,token:s}),hooks:o}};var U={TOO_MANY_REQUESTS:429};function R(e,t,n){var s;let o=P(e);t&&(o=null===(s=null==o?void 0:o.tenants)||void 0===s?void 0:s[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function P(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function x(e){const{exp:t}=P(e);return(new Date).getTime()/1e3>t}function q(e,t){return R(e,t,"permissions")}function E(e,t){return R(e,t,"roles")}const $=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function S(e,t){var n;const s=await e,o={code:s.status,ok:s.ok,response:s},i=await s.clone().json();return s.ok?o.data=t?t(i):i:(o.error=i,s.status===U.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const M=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),T=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),A=e=>t=>e.test(t),L=A(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),z=A(/^\+[1-9]{1}[0-9]{3,14}$/),H=M(L,'"{val}" is not a valid email'),J=M(z,'"{val}" is not a valid phone number'),N=M((C=1,e=>e.length>=C),"Minimum length is 1");var C;const _=M((e=>"string"==typeof e),"Input is not a string"),D=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>T(...e).validate(n[t]))),t(...n)),Z=e=>[_(`"${e}" must be a string`),N(`"${e}" must not be empty`)],B=e=>[_(`"${e}" must be a string`),H()],F=e=>[_(`"${e}" must be a string`),J()],K=D(Z("accessKey")),Q=e=>({exchange:K((t=>S(e.post(n.exchange,{},{token:t}))))});var Y,G;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Y||(Y={})),function(e){e.email="email"}(G||(G={}));const V=Object.assign(Object.assign({},Y),G);var W;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(W||(W={}));const X=Z("loginId"),ee=D(Z("token")),te=D(X),ne=D(Z("pendingRef")),se=D(X,B("email")),oe=e=>({verify:ee((t=>S(e.post(i.verify,{token:t})))),signIn:te(((t,n,s,o)=>S(e.post($(i.signIn,V.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:te(((t,n)=>S(e.post($(i.signUpOrIn,V.email),{loginId:t,URI:n})))),signUp:te(((t,n,s)=>S(e.post($(i.signUp,V.email),{loginId:t,URI:n,user:s})))),waitForSession:ne(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||f,f),timeoutMs:Math.min(t||m,m)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(S(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:se(((t,n,s,o,a)=>S(e.post(i.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:o}))))}}),ie=D(Z("flowId")),ae=D(Z("executionId"),Z("stepId"),Z("interactionId")),re=e=>({start:ie(((t,n,s,o,i,a)=>S(e.post(v.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,input:i,version:a})))),next:ae(((t,n,s,o,i)=>S(e.post(v.next,{executionId:t,stepId:n,interactionId:s,input:o,version:i}))))}),de=Z("loginId"),ue=D(Z("token")),le=D(de),pe=D(de,F("phone")),ce=D(de,B("email")),ge=e=>({verify:ue((t=>S(e.post(o.verify,{token:t})))),signIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:le(((t,s,i,a)=>S(e.post($(o.signIn,n),{loginId:t,URI:s,loginOptions:i},{token:a}))))})),{}),signUp:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:le(((t,s,i)=>S(e.post($(o.signUp,n),{loginId:t,URI:s,user:i}))))})),{}),signUpOrIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:le(((t,s)=>S(e.post($(o.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:ce(((t,n,s,i,a)=>S(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s,i,a,r)=>S(e.post($(o.update.phone,n),Object.assign({loginId:t,phone:s,URI:i},r),{token:a}))))})),{})}});var he;!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"}(he||(he={}));const ve=D(Z("code")),fe=e=>({start:Object.keys(he).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>S(e.post(a.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{}),exchange:ve((t=>S(e.post(a.exchange,{code:t}))))}),me=Z("loginId"),Ie=D(me,Z("code")),be=D(me),ye=D(me,F("phone")),ke=D(me,B("email")),Oe=e=>({verify:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie(((t,o)=>S(e.post($(s.verify,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i)=>S(e.post($(s.signIn,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o)=>S(e.post($(s.signUp,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be((t=>S(e.post($(s.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:ke(((t,n,o,i)=>S(e.post(s.update.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i,a)=>S(e.post($(s.update.phone,n),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),we=D(Z("tenant")),je=D(Z("code")),Ue=e=>({start:we(((t,n,s,o)=>S(e.post(r.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:je((t=>S(e.post(r.exchange,{code:t}))))}),Re=Z("loginId"),Pe=D(Re,Z("code")),xe=D(Re),qe=D(Re),Ee=e=>({signUp:xe(((t,n)=>S(e.post(d.signUp,{loginId:t,user:n})))),verify:Pe(((t,n,s,o)=>S(e.post(d.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:qe(((t,n)=>S(e.post(d.update,{loginId:t},{token:n}))))}),$e=Z("loginId"),Se=Z("newPassword"),Me=D($e,Z("password")),Te=D($e),Ae=D($e,Se),Le=D($e,Z("oldPassword"),Se),ze=e=>({signUp:Me(((t,n,s)=>S(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Me(((t,n)=>S(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Te(((t,n)=>S(e.post(l.sendReset,{loginId:t,redirectUrl:n})))),update:Ae(((t,n,s)=>S(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Le(((t,n,s)=>S(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>S(e.get(l.policy))}),He=[_(`"${"loginId"}" must be a string`)];const Je=Z("loginId"),Ne=Z("origin"),Ce=D(Je,Ne,Z("name")),_e=D(Je,Ne),De=D(He,Ne),Ze=D(Je,Ne,Z("token")),Be=D(Z("transactionId"),Z("response")),Fe=e=>({signUp:{start:Ce(((t,n,s)=>S(e.post(u.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Be(((t,n)=>S(e.post(u.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:De(((t,n,s,o)=>S(e.post(u.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Be(((t,n)=>S(e.post(u.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:_e(((t,n)=>S(e.post(u.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:Ze(((t,n,s)=>S(e.post(u.update.start,{loginId:t,origin:n},{token:s})))),finish:Be(((t,n)=>S(e.post(u.update.finish,{transactionId:t,response:n}))))}}),Ke=D(Z("token"));var Qe,Ye;var Ge=D([(Qe="projectId",Ye=Z("projectId"),M(((e,n)=>s=>T(...n).validate(t(s,e)))(Qe,Ye))())])((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:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))})((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return r=j({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:Q(r),otp:Oe(r),magicLink:ge(r),enchantedLink:oe(r),oauth:fe(r),saml:Ue(r),totp:Ee(r),webauthn:Fe(r),password:ze(r),flow:re(r),refresh:e=>S(r.post(p,{},{token:e})),logout:e=>S(r.post(c,{},{token:e})),logoutAll:e=>S(r.post(g,{},{token:e})),me:e=>S(r.get(h,{token:e})),isJwtExpired:Ke(x),getJwtPermissions:Ke(q),getJwtRoles:Ke(E),httpClient:r};var r})));const Ve=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);var We=Object.assign(Ge,{DeliveryMethods:V});export{U as HttpStatusCodes,We as default,S as transformResponse,Ve as wrapWith};
1
+ 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"},d={verify:"/v1/auth/totp/verify",signUp:"/v1/auth/totp/signup",update:"/v1/auth/totp/update"},u={signUp:{start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},signIn:{start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},signUpOrIn:{start:"/v1/auth/webauthn/signup-in/start"},update:{start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"}},l={signUp:"/v1/auth/password/signup",signIn:"/v1/auth/password/signin",sendReset:"/v1/auth/password/reset",update:"/v1/auth/password/update",replace:"/v1/auth/password/replace",policy:"/v1/auth/password/policy"},p="/v1/auth/refresh",c="/v1/auth/logout",g="/v1/auth/logoutall",h="/v1/auth/me",v={start:"/v1/flow/start",next:"/v1/flow/next"};const f=1e3,m=6e5,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")}},b=(e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),s=await n.text();return n.text=()=>Promise.resolve(s),n.json=()=>Promise.resolve(JSON.parse(s)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>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.text();return I().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(s)),s}:n};var y;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(y||(y={}));const k=(...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,fetch:a})=>{const r=b(s,a),d=async s=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(s):s,{path:d,body:u,headers:l,queryParams:p,method:c,token:g}=a,h=await r((({path:e,baseUrl:t,queryParams:n})=>{const s=new URL(e,t);return n&&(s.search=new URLSearchParams(n).toString()),s})({path:d,baseUrl:e,queryParams:p}),{headers:k(w(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.3.6"},(null==n?void 0:n.baseHeaders)||{},l),method:c,body:O(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&await o.afterRequest(s,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:y.get,token:s}),post:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:y.post,token:o}),put:(e,t,{headers:n,queryParams:s,token:o}={})=>d({path:e,headers:n,queryParams:s,body:t,method:y.put,token:o}),delete:(e,{headers:t,queryParams:n,token:s}={})=>d({path:e,headers:t,queryParams:n,body:void 0,method:y.delete,token:s}),hooks:o}};var U={TOO_MANY_REQUESTS:429};function R(e,t,n){var s;let o=P(e);t&&(o=null===(s=null==o?void 0:o.tenants)||void 0===s?void 0:s[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function P(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return e(t)}function x(e){const{exp:t}=P(e);return(new Date).getTime()/1e3>t}function q(e,t){return R(e,t,"permissions")}function E(e,t){return R(e,t,"roles")}const $=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function S(e,t){var n;const s=await e,o={code:s.status,ok:s.ok,response:s},i=await s.clone().json();return s.ok?o.data=t?t(i):i:(o.error=i,s.status===U.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=s.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const M=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),T=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),A=e=>t=>e.test(t),L=A(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),z=A(/^\+[1-9]{1}[0-9]{3,14}$/),H=M(L,'"{val}" is not a valid email'),J=M(z,'"{val}" is not a valid phone number'),N=M((C=1,e=>e.length>=C),"Minimum length is 1");var C;const _=M((e=>"string"==typeof e),"Input is not a string"),D=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>T(...e).validate(n[t]))),t(...n)),Z=e=>[_(`"${e}" must be a string`),N(`"${e}" must not be empty`)],B=e=>[_(`"${e}" must be a string`),H()],F=e=>[_(`"${e}" must be a string`),J()],K=D(Z("accessKey")),Q=e=>({exchange:K((t=>S(e.post(n.exchange,{},{token:t}))))});var Y,G;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Y||(Y={})),function(e){e.email="email"}(G||(G={}));const V=Object.assign(Object.assign({},Y),G);var W;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(W||(W={}));const X=Z("loginId"),ee=D(Z("token")),te=D(X),ne=D(Z("pendingRef")),se=D(X,B("email")),oe=e=>({verify:ee((t=>S(e.post(i.verify,{token:t})))),signIn:te(((t,n,s,o)=>S(e.post($(i.signIn,V.email),{loginId:t,URI:n,loginOptions:s},{token:o})))),signUpOrIn:te(((t,n)=>S(e.post($(i.signUpOrIn,V.email),{loginId:t,URI:n})))),signUp:te(((t,n,s)=>S(e.post($(i.signUp,V.email),{loginId:t,URI:n,user:s})))),waitForSession:ne(((t,n)=>new Promise((s=>{const{pollingIntervalMs:o,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||f,f),timeoutMs:Math.min(t||m,m)}))(n);let r;const d=setInterval((async()=>{const n=await e.post(i.session,{pendingRef:t});n.ok&&(clearInterval(d),r&&clearTimeout(r),s(S(Promise.resolve(n))))}),o);r=setTimeout((()=>{s({error:{errorDescription:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(d)}),a)})))),update:{email:se(((t,n,s,o,a)=>S(e.post(i.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:o}))))}}),ie=D(Z("flowId")),ae=D(Z("executionId"),Z("stepId"),Z("interactionId")),re=e=>({start:ie(((t,n,s,o,i,a)=>S(e.post(v.start,{flowId:t,options:n,conditionInteractionId:s,interactionId:o,input:i,version:a})))),next:ae(((t,n,s,o,i)=>S(e.post(v.next,{executionId:t,stepId:n,interactionId:s,input:o,version:i}))))}),de=Z("loginId"),ue=D(Z("token")),le=D(de),pe=D(de,F("phone")),ce=D(de,B("email")),ge=e=>({verify:ue((t=>S(e.post(o.verify,{token:t})))),signIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:le(((t,s,i,a)=>S(e.post($(o.signIn,n),{loginId:t,URI:s,loginOptions:i},{token:a}))))})),{}),signUp:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:le(((t,s,i)=>S(e.post($(o.signUp,n),{loginId:t,URI:s,user:i}))))})),{}),signUpOrIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:le(((t,s)=>S(e.post($(o.signUpOrIn,n),{loginId:t,URI:s}))))})),{}),update:{email:ce(((t,n,s,i,a)=>S(e.post(o.update.email,Object.assign({loginId:t,email:n,URI:s},a),{token:i})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:pe(((t,s,i,a,r)=>S(e.post($(o.update.phone,n),Object.assign({loginId:t,phone:s,URI:i},r),{token:a}))))})),{})}});var he;!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"}(he||(he={}));const ve=D(Z("code")),fe=e=>({start:Object.keys(he).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,s,o)=>S(e.post(a.start,s||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:o}))})),{}),exchange:ve((t=>S(e.post(a.exchange,{code:t}))))}),me=Z("loginId"),Ie=D(me,Z("code")),be=D(me),ye=D(me,F("phone")),ke=D(me,B("email")),Oe=e=>({verify:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ie(((t,o)=>S(e.post($(s.verify,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o,i)=>S(e.post($(s.signIn,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be(((t,o)=>S(e.post($(s.signUp,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(V).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:be((t=>S(e.post($(s.signUpOrIn,n),{loginId:t}))))})),{}),update:{email:ke(((t,n,o,i)=>S(e.post(s.update.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(Y).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ye(((t,o,i,a)=>S(e.post($(s.update.phone,n),Object.assign({loginId:t,phone:o},a),{token:i}))))})),{})}}),we=D(Z("tenant")),je=D(Z("code")),Ue=e=>({start:we(((t,n,s,o)=>S(e.post(r.start,s||{},{queryParams:{tenant:t,redirectURL:n},token:o})))),exchange:je((t=>S(e.post(r.exchange,{code:t}))))}),Re=Z("loginId"),Pe=D(Re,Z("code")),xe=D(Re),qe=D(Re),Ee=e=>({signUp:xe(((t,n)=>S(e.post(d.signUp,{loginId:t,user:n})))),verify:Pe(((t,n,s,o)=>S(e.post(d.verify,{loginId:t,code:n,loginOptions:s},{token:o})))),update:qe(((t,n)=>S(e.post(d.update,{loginId:t},{token:n}))))}),$e=Z("loginId"),Se=Z("newPassword"),Me=D($e,Z("password")),Te=D($e),Ae=D($e,Se),Le=D($e,Z("oldPassword"),Se),ze=e=>({signUp:Me(((t,n,s)=>S(e.post(l.signUp,{loginId:t,password:n,user:s})))),signIn:Me(((t,n)=>S(e.post(l.signIn,{loginId:t,password:n})))),sendReset:Te(((t,n)=>S(e.post(l.sendReset,{loginId:t,redirectUrl:n})))),update:Ae(((t,n,s)=>S(e.post(l.update,{loginId:t,newPassword:n},{token:s})))),replace:Le(((t,n,s)=>S(e.post(l.replace,{loginId:t,oldPassword:n,newPassword:s})))),policy:()=>S(e.get(l.policy))}),He=[_(`"${"loginId"}" must be a string`)];const Je=Z("loginId"),Ne=Z("origin"),Ce=D(Je,Ne,Z("name")),_e=D(Je,Ne),De=D(He,Ne),Ze=D(Je,Ne,Z("token")),Be=D(Z("transactionId"),Z("response")),Fe=e=>({signUp:{start:Ce(((t,n,s)=>S(e.post(u.signUp.start,{user:{loginId:t,name:s},origin:n})))),finish:Be(((t,n)=>S(e.post(u.signUp.finish,{transactionId:t,response:n}))))},signIn:{start:De(((t,n,s,o)=>S(e.post(u.signIn.start,{loginId:t,origin:n,loginOptions:s},{token:o})))),finish:Be(((t,n)=>S(e.post(u.signIn.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:_e(((t,n)=>S(e.post(u.signUpOrIn.start,{loginId:t,origin:n}))))},update:{start:Ze(((t,n,s)=>S(e.post(u.update.start,{loginId:t,origin:n},{token:s})))),finish:Be(((t,n)=>S(e.post(u.update.finish,{transactionId:t,response:n}))))}}),Ke=D(Z("token"));var Qe,Ye;var Ge=D([(Qe="projectId",Ye=Z("projectId"),M(((e,n)=>s=>T(...n).validate(t(s,e)))(Qe,Ye))())])((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:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))})((({projectId:e,logger:t,baseUrl:n,hooks:s,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return r=j({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:s,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:Q(r),otp:Oe(r),magicLink:ge(r),enchantedLink:oe(r),oauth:fe(r),saml:Ue(r),totp:Ee(r),webauthn:Fe(r),password:ze(r),flow:re(r),refresh:e=>S(r.post(p,{},{token:e})),logout:e=>S(r.post(c,{},{token:e})),logoutAll:e=>S(r.post(g,{},{token:e})),me:e=>S(r.get(h,{token:e})),isJwtExpired:Ke(x),getJwtPermissions:Ke(q),getJwtRoles:Ke(E),httpClient:r};var r})));const Ve=(e,t,n)=>(t.forEach((t=>{const s=t.split(".");let o=s.shift(),i=e;for(;s.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=s.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);var We=Object.assign(Ge,{DeliveryMethods:V});export{U as HttpStatusCodes,We as default,S as transformResponse,Ve as wrapWith};
2
2
  //# sourceMappingURL=index.esm.js.map