@descope/core-js-sdk
Version:
Descope JavaScript core SDK
684 lines (669 loc) • 29.9 kB
TypeScript
type JSONSerializable = string | number | boolean | null | Array<JSONSerializable>;
type FlowInput = Record<string, JSONSerializable>;
type NOTPResponse = {
pendingRef: string;
redirectUrl: string;
image: string;
};
type ConnectOptions = {
redirectUrl?: string;
scopes?: string[];
tenantId?: string;
tenantLevel?: boolean;
};
type DeviceInfo = {
webAuthnSupport?: boolean;
};
type LastAuth = {
authMethod?: AuthMethod;
oauthProvider?: string;
name?: string;
loginId?: string;
};
type RedirectAuth = {
callbackUrl: string;
codeChallenge: string;
};
/** Sent in a flow start request when running as a native flow component via a mobile SDK */
type NativeOptions = {
/** What mobile platform we're running on, used to decide between different behaviors on the backend */
platform: 'ios' | 'android';
/** The name of an OAuth provider that will use native OAuth (Sign in with Apple/Google) instead of web OAuth when running in a mobile app */
oauthProvider?: string;
/** An override for web OAuth that sets the address to redirect to after authentication succeeds at the OAuth provider website */
oauthRedirect?: string;
};
type AuthMethod = 'magiclink' | 'enchantedlink' | 'otp' | 'totp' | 'oauth' | 'saml' | 'webauthn';
type SdkFn$1 = (...args: any[]) => Promise<SdkResponse<ResponseData>>;
type MaskedPhone = {
maskedPhone: string;
};
type MaskedEmail = {
maskedEmail: string;
};
/** User base details from Descope API */
type User = {
email?: string;
name?: string;
givenName?: string;
middleName?: string;
familyName?: string;
phone?: string;
};
/** User extended details from Descope API */
type UserResponse = User & {
loginIds: string[];
userId: string;
verifiedEmail?: boolean;
verifiedPhone?: boolean;
picture?: string;
roleNames?: string[];
userTenants?: UserTenant[];
createdTime: number;
TOTP: boolean;
SAML: boolean;
SCIM: boolean;
password: boolean;
OAuth?: Record<string, boolean>;
customAttributes?: Record<string, any>;
status: string;
};
type Tenant = {
id: string;
name: string;
customAttributes?: Record<string, any>;
};
type TenantsResponse = {
tenants: Tenant[];
};
type UserHistoryResponse = {
userId: string;
loginTime: number;
city: string;
country: string;
ip: string;
};
/** A tenant association mapping */
type UserTenant = {
tenantId: string;
roleNames?: string[];
tenantName: string;
};
type TemplateOptions = Record<string, string>;
/** Login options to be added to the different authentication methods */
type LoginOptions = {
stepup?: boolean;
mfa?: boolean;
revokeOtherSessions?: boolean;
customClaims?: Record<string, any>;
templateId?: string;
templateOptions?: TemplateOptions;
};
/** Access key login options to be added to the different authentication methods */
type AccessKeyLoginOptions = {
customClaims?: Record<string, any>;
};
/** Sign Up options to be added to the different authentication methods */
type SignUpOptions = {
customClaims?: Record<string, any>;
templateId?: string;
templateOptions?: TemplateOptions;
};
/** Authentication info result from the various JWT validations */
type JWTResponse = {
sessionJwt: string;
refreshJwt?: string;
cookieDomain?: string;
cookiePath?: string;
cookieMaxAge?: number;
cookieExpiration?: number;
user?: UserResponse;
firstSeen?: boolean;
sessionExpiration: number;
};
/** Authentication info result from exchanging access keys for a session */
type ExchangeAccessKeyResponse = {
keyId: string;
sessionJwt: string;
expiration: number;
};
/** Options for fine-grained passkey (WebAuthn) control */
type PasskeyOptions = {
authenticatorSelection?: WebauthnAuthenticatorSelectionCriteria;
attestation?: 'none' | 'indirect' | 'direct';
userVerification?: 'preferred' | 'required' | 'discouraged';
extensionsJSON?: string;
};
/** Part of the passkey options that apply when performing attestation (sign up) */
type WebauthnAuthenticatorSelectionCriteria = {
authenticatorAttachment?: 'any' | 'platform' | 'crossplatform';
residentKey?: 'discouraged' | 'preferred' | 'required';
userVerification?: 'preferred' | 'required' | 'discouraged';
};
/** The response returned from the various start webauthn functions */
type WebAuthnStartResponse = {
transactionId: string;
options: string;
create: boolean;
};
/** Enchanted link response */
type EnchantedLinkResponse = {
/** Pending reference URL to poll while waiting for user to click magic link */
pendingRef: string;
/** Link id, on which link the user should click */
linkId: string;
/** Email to which the link was sent to */
maskedEmail: string;
};
/** URL response to redirect user in case of OAuth or SSO */
type URLResponse = {
url: string;
};
/** TOTP response with the TOTP details */
type TOTPResponse = {
provisioningURL: string;
image: string;
key: string;
};
/** Password reset response with details according to response method */
type PasswordResetResponse = {
resetMethod: string;
pendingRef?: string;
linkId?: string;
maskedEmail: string;
};
/** A subset of the password policy that can be checked on the client side for better UX */
type PasswordPolicyResponse = {
minLength: number;
lowercase: boolean;
uppercase: boolean;
number: boolean;
nonAlphanumeric: boolean;
};
type ClientIdResponse = {
clientId: string;
};
type VerifyOneTapIDTokenResponse = {
code: string;
};
/** Phone delivery methods which are currently supported */
declare enum DeliveryPhone {
sms = "sms",
voice = "voice",
whatsapp = "whatsapp"
}
declare enum DeliveryEmail {
email = "email"
}
/** All delivery methods currently supported */
type DeliveryMethods = DeliveryPhone | DeliveryEmail;
declare const DeliveryMethods: {
readonly email: DeliveryEmail.email;
readonly sms: DeliveryPhone.sms;
readonly voice: DeliveryPhone.voice;
readonly whatsapp: DeliveryPhone.whatsapp;
};
/** All flow execution statuses
* - waiting - flow execution is waiting for user interaction
* - running - flow execution is currently running
* - completed - flow execution completed successfully
* - failed - flow execution failed
*/
declare enum FlowStatus {
waiting = "waiting",
running = "running",
completed = "completed",
failed = "failed"
}
/** All flow response action
* - screen - next action is to render screen
* - poll - next action is poll for next after timeout
* - redirect - next action is to redirect (redirection details in 'redirect' attribute)
* - webauthnCreate/webauthnGet - next action is to prompt webauthn (details in 'webauthn' attribute)
* - nativeBridge - the next action needs to be sent via the native bridge to the native layer
* - none - no next action
*/
type FlowAction = 'screen' | 'poll' | 'redirect' | 'webauthnCreate' | 'webauthnGet' | 'nativeBridge' | 'none';
type ComponentsConfig = Record<string, any>;
/** Flow response with flow execution details */
type FlowResponse = {
executionId: string;
stepId: string;
stepName: string;
status: FlowStatus;
action: FlowAction;
screen?: {
id: string;
state: Record<string, any>;
componentsConfig: ComponentsConfig;
};
redirect?: {
url: string;
isPopup?: boolean;
};
samlIdpResponse?: {
url: string;
samlResponse: string;
relayState: string;
};
openInNewTabUrl?: string;
webauthn?: {
transactionId: string;
options: string;
create: boolean;
};
nativeResponse?: {
type: 'oauthNative' | 'oauthWeb' | 'webauthnGet' | 'webauthnCreate';
payload: Record<string, any>;
};
error?: {
code: string;
description: string;
message: string;
};
authInfo?: JWTResponse;
lastAuth?: Pick<LastAuth, 'authMethod' | 'oauthProvider'>;
runnerLogs?: {
title?: string;
log: string;
level?: 'info' | 'debug' | 'warn' | 'error';
}[];
};
type Options = {
redirectUrl?: string;
location?: string;
tenant?: string;
deviceInfo?: DeviceInfo;
lastAuth?: LastAuth;
redirectAuth?: RedirectAuth;
oidcIdpStateId?: string;
preview?: boolean;
samlIdpStateId?: string;
samlIdpUsername?: string;
ssoAppId?: string;
thirdPartyAppId?: string;
oidcLoginHint?: string;
abTestingKey?: number;
startOptionsVersion?: number;
client?: Record<string, any>;
locale?: string;
oidcPrompt?: string;
oidcErrorRedirectUri?: string;
oidcResource?: string;
nativeOptions?: NativeOptions;
thirdPartyAppStateId?: string;
applicationScopes?: string;
outboundAppId?: string;
outboundAppScopes?: string[];
};
type ResponseData = Record<string, any>;
/**
* Response from our SDK calls which includes the result (ok, code, error).
* The relevant data is provided in the more specific interfaces extending SdkResponse.
*/
type SdkResponse<T extends ResponseData> = {
code?: number;
ok: boolean;
response?: Response;
error?: {
errorCode: string;
errorDescription: string;
errorMessage?: string;
retryAfter?: string;
};
data?: T;
};
/** Different delivery method */
type Deliveries<T extends Record<DeliveryMethods, SdkFn$1>> = {
[S in DeliveryMethods]: T[S];
};
type DeliveriesPhone<T extends Record<DeliveryPhone, SdkFn$1> | SdkFn$1> = {
[S in DeliveryPhone]: T extends Record<DeliveryPhone, SdkFn$1> ? T[S] : T;
};
/** Logger type that supports the given levels (debug, log, error) */
type Logger = Pick<Console, 'debug' | 'log' | 'error' | 'warn'>;
/** Polling configuration for session waiting */
type WaitForSessionConfig = {
pollingIntervalMs: number;
timeoutMs: number;
};
type UpdateOptions<T extends boolean> = {
addToLoginIDs?: T;
onMergeUseExisting?: T extends true ? boolean : never;
templateOptions?: TemplateOptions;
templateId?: string;
providerId?: string;
};
declare enum OAuthProviders {
facebook = "facebook",
github = "github",
google = "google",
microsoft = "microsoft",
gitlab = "gitlab",
apple = "apple",
discord = "discord",
linkedin = "linkedin",
slack = "slack"
}
type StartFn = (redirectURL?: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<URLResponse>>;
type Providers<T> = Record<keyof typeof OAuthProviders, T>;
/** Request configuration including headers, query params and token */
type HttpClientReqConfig = {
headers?: HeadersInit;
queryParams?: {
[key: string]: string;
};
token?: string;
};
type ExtendedResponse = Response & {
cookies: Record<string, string>;
};
/** HTTP methods we use in the client */
declare enum HTTPMethods {
get = "GET",
delete = "DELETE",
post = "POST",
put = "PUT",
patch = "PATCH"
}
/** HTTP Client type that implements the HTTP method calls. Descopers can provide their own HTTP client although required only in rare cases. */
type HttpClient = {
get: (path: string, config?: HttpClientReqConfig) => Promise<Response>;
post: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
patch: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
put: (path: string, body?: any, config?: HttpClientReqConfig) => Promise<Response>;
delete: (path: string, config?: HttpClientReqConfig) => Promise<Response>;
hooks?: Hooks;
buildUrl: (path: string, queryParams?: {
[key: string]: string;
}) => string;
};
type Fetch = typeof fetch;
/** Parameters for the HTTP client. Defaults should work for most cases. */
type CreateHttpClientConfig = {
baseUrl?: string;
projectId: string;
baseConfig?: {
baseHeaders: HeadersInit;
};
logger?: Logger;
hooks?: Hooks;
cookiePolicy?: RequestCredentials | null;
refreshCookieName?: string;
fetch?: Fetch;
};
/** For before-request hook allows overriding parts of the request */
type RequestConfig = {
path: string;
headers?: HeadersInit;
queryParams?: {
[key: string]: string;
};
body?: any;
method: HTTPMethods;
token?: string;
};
type BeforeRequest = (config: RequestConfig) => RequestConfig;
type AfterRequest = (req: RequestConfig, res: Response) => void | Promise<void>;
/** Hooks before and after the request is made */
type Hooks = {
beforeRequest?: BeforeRequest;
afterRequest?: AfterRequest;
transformResponse?: (mutableResponse: ExtendedResponse) => Promise<ExtendedResponse>;
};
type MultipleHooks = {
beforeRequest?: BeforeRequest | BeforeRequest[];
afterRequest?: AfterRequest | AfterRequest[];
transformResponse?: (mutableResponse: ExtendedResponse) => Promise<ExtendedResponse>;
};
declare const _default$2: {
TOO_MANY_REQUESTS: number;
};
declare const _default$1: (config: Omit<CreateHttpClientConfig, "hooks"> & {
hooks?: MultipleHooks;
}) => HttpClient;
/** Transform the Promise Response to our internal SdkResponse implementation
* @param response The Response promise from fetch
* @param transform Optionally transform the response JSON to another type
*/
declare function transformResponse<T extends ResponseData, S extends ResponseData = T>(response: Promise<Response>, transform?: (data: T) => S): Promise<SdkResponse<S>>;
type IsObject<T> = T extends Array<any> ? false : T extends Function ? false : T extends object ? true : false;
type Tail<T extends ReadonlyArray<string>> = T extends readonly [
head: any,
...tail: infer Tail_
] ? Tail_ : never;
type Head<T extends ReadonlyArray<string>> = T extends readonly [] ? never : T[0];
type SdkResponseType<F extends SdkFn<ResponseData>> = F extends SdkFn<infer U> ? U : never;
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>>;
type PrependDot<T extends string> = [T] extends [never] ? '' : `.${T}`;
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;
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>;
type ReplacePath<Obj, Path extends string, WrapperData extends Record<string, any>> = Path extends `${infer Head}.${infer Tail}` ? {
[Key in keyof Obj]: Key extends Head ? ReplacePath<Obj[Key], Tail, WrapperData> : Obj[Key];
} : {
[Key in keyof Obj]: Key extends Path ? Obj[Key] extends SdkFn<ResponseData> ? ReturnType<SdkFnWrapperInternal<Obj[Key], WrapperData>> : Obj[Key] : Obj[Key];
};
type SdkFn<T extends ResponseData> = (...args: any) => Promise<SdkResponse<T>>;
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>>;
/**
* A wrapper function that allows to wrap multiple Sdk function
* @param obj: The Sdk instance you want to wrap
* @param paths: A readonly list of paths of the functions you want to wrap
* @param wrapper: Your wrapper function, it should gets an Sdk function and return a new Sdk function
* @returns a mutated instance of the Sdk with updated type definitions based on your wrapper return type
*
* Usage example:
*
* // Assuming this is our SDK instance
* const sdk = {
* me: (token) => {...}
* flow: {
* start: (...params) => {...}
* next: (...params) => {...}
* }
* ...
* }
*
* // This is our wrapper
* const wrapper = (sdkFn) => async (...args) => {
* const sdkResponse = await sdkFn(...args)
*
* // Modify return value
* return {...sdkResponse, data: {...sdkResponse.data, myCustomAttribute: 'hello'}}
* }
*
* // And those are the paths we want to wrap
* const paths = ['flow.start', 'flow.next'] as const // You MUST add as const!
*
* // We can wrap our SDK functions with the wrapper we created in this way
* const newlyTypedSdk = wrapWith(sdk, paths, wrapper)
*
* Now the 2 wrapped functions will have the updated type based on the wrapper return value
*/
declare const wrapWith: <Obj extends object, Paths extends readonly SdkFnsPaths<Obj>[], WrapperData extends ResponseData>(obj: Obj, paths: Paths, wrapper: SdkFnWrapper<WrapperData>) => ReplacePaths<Obj, Paths, WrapperData>;
/** Polling configuration with defaults and normalizing checks */
declare const normalizeWaitForSessionConfig: ({ pollingIntervalMs, timeoutMs, }?: {
pollingIntervalMs?: number;
timeoutMs?: number;
}) => {
pollingIntervalMs: number;
timeoutMs: number;
};
/** Descope SDK client with delivery methods enum.
*
* Please see full documentation at {@link https://docs.descope.com/guides Descope Docs}
* @example Usage
*
* ```js
* import descopeSdk from '@descope/core-js-sdk';
*
* const myProjectId = 'xxx';
* const sdk = descopeSdk({ projectId: myProjectId });
*
* const userLoginId = 'loginId';
* sdk.otp.signIn.email(userLoginId);
* const jwtResponse = sdk.otp.verify.email(userIdentifier, codeFromEmail);
* ```
*/
declare const _default: ((config: {
projectId: string;
logger?: Logger;
baseUrl?: string;
hooks?: MultipleHooks;
cookiePolicy?: RequestCredentials;
baseHeaders?: HeadersInit;
refreshCookieName?: string;
fetch?: typeof fetch;
}) => {
accessKey: {
exchange: (accessKey: string, loginOptions?: AccessKeyLoginOptions) => Promise<SdkResponse<ExchangeAccessKeyResponse>>;
};
otp: {
verify: {
sms: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
voice: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
whatsapp: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
email: (loginId: string, code: string) => Promise<SdkResponse<JWTResponse>>;
};
signIn: Deliveries<{
sms: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedEmail>>;
}>;
signUp: Deliveries<{
sms: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedEmail>>;
}>;
signUpOrIn: Deliveries<{
sms: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedEmail>>;
}>;
update: {
email: <T extends boolean>(loginId: string, email: string, token?: string, updateOptions?: UpdateOptions<T>) => Promise<SdkResponse<MaskedEmail>>;
phone: DeliveriesPhone<(<T_1 extends boolean>(loginId: string, phone: string, token?: string, updateOptions?: UpdateOptions<T_1>) => Promise<SdkResponse<MaskedPhone>>)>;
};
};
magicLink: {
verify: (token: string) => Promise<SdkResponse<JWTResponse>>;
signIn: Deliveries<{
sms: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, URI: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<MaskedEmail>>;
}>;
signUp: Deliveries<{
sms: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, URI: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedEmail>>;
}>;
signUpOrIn: Deliveries<{
sms: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
voice: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
whatsapp: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedPhone>>;
email: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<MaskedEmail>>;
}>;
update: {
email: <T_2 extends boolean>(loginId: string, email: string, URI?: string, token?: string, updateOptions?: UpdateOptions<T_2>) => Promise<SdkResponse<MaskedEmail>>;
phone: DeliveriesPhone<(<T_3 extends boolean>(loginId: string, phone: string, URI?: string, token?: string, updateOptions?: UpdateOptions<T_3>) => Promise<SdkResponse<MaskedPhone>>)>;
};
};
enchantedLink: {
verify: (token: string) => Promise<SdkResponse<never>>;
signIn: (loginId: string, URI?: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<EnchantedLinkResponse>>;
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<EnchantedLinkResponse>>;
signUp: (loginId: string, URI?: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<EnchantedLinkResponse>>;
waitForSession: (pendingRef: string, config?: WaitForSessionConfig) => Promise<SdkResponse<JWTResponse>>;
update: {
email: <T_4 extends boolean>(loginId: string, email: string, URI?: string, token?: string, updateOptions?: UpdateOptions<T_4>) => Promise<SdkResponse<EnchantedLinkResponse>>;
};
};
oauth: {
start: ((provider: string, redirectUrl?: string, loginOptions?: LoginOptions, token?: string, loginHint?: string) => Promise<SdkResponse<ResponseData>>) & Providers<StartFn>;
exchange: (code: string) => Promise<SdkResponse<JWTResponse>>;
startNative: (provider: string, loginOptions?: LoginOptions, implicit?: boolean) => Promise<SdkResponse<ResponseData>>;
finishNative: (provider: string, stateId: string, user?: string, code?: string, idToken?: string) => Promise<SdkResponse<ResponseData>>;
getOneTapClientId: (provider: string) => Promise<SdkResponse<ClientIdResponse>>;
verifyOneTapIDToken: (provider: string, idToken: string, nonce: string, loginOptions?: LoginOptions) => Promise<SdkResponse<VerifyOneTapIDTokenResponse>>;
exchangeOneTapIDToken: (provider: string, idToken: string, nonce: string, loginOptions?: LoginOptions) => Promise<SdkResponse<JWTResponse>>;
};
outbound: {
connect: (appId: string, options?: ConnectOptions, token?: string) => Promise<SdkResponse<URLResponse>>;
};
saml: {
start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: LoginOptions, token?: string, ssoId?: string) => Promise<SdkResponse<URLResponse>>;
exchange: (code: string) => Promise<SdkResponse<JWTResponse>>;
};
totp: {
signUp: (loginId: string, user?: User) => Promise<SdkResponse<TOTPResponse>>;
verify: (loginId: string, code: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<JWTResponse>>;
update: (loginId: string, token?: string) => Promise<SdkResponse<TOTPResponse>>;
};
notp: {
signUpOrIn: (loginId?: string, signUpOptions?: SignUpOptions) => Promise<SdkResponse<NOTPResponse>>;
signUp: (loginId?: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<NOTPResponse>>;
signIn: (loginId?: string, loginOptions?: LoginOptions, token?: string) => Promise<SdkResponse<NOTPResponse>>;
waitForSession: (pendingRef: string, config?: WaitForSessionConfig) => Promise<SdkResponse<JWTResponse>>;
};
webauthn: {
signUp: {
start: (loginId: string, origin: string, name: string, passkeyOptions?: PasskeyOptions) => Promise<SdkResponse<WebAuthnStartResponse>>;
finish: (transactionId: string, response: string) => Promise<SdkResponse<JWTResponse>>;
};
signIn: {
start: (loginId: string, origin: string, loginOptions?: LoginOptions, token?: string, passkeyOptions?: PasskeyOptions) => Promise<SdkResponse<WebAuthnStartResponse>>;
finish: (transactionId: string, response: string) => Promise<SdkResponse<JWTResponse>>;
};
signUpOrIn: {
start: (loginId: string, origin: string, passkeyOptions?: PasskeyOptions) => Promise<SdkResponse<WebAuthnStartResponse>>;
};
update: {
start: (loginId: string, origin: string, token?: string, passkeyOptions?: PasskeyOptions) => Promise<SdkResponse<WebAuthnStartResponse>>;
finish: (transactionId: string, response: string) => Promise<SdkResponse<ResponseData>>;
};
};
password: {
signUp: (loginId: string, password: string, user?: User, signUpOptions?: SignUpOptions) => Promise<SdkResponse<JWTResponse>>;
signIn: (loginId: string, password: string, loginOptions?: LoginOptions) => Promise<SdkResponse<JWTResponse>>;
sendReset: (loginId: string, redirectUrl?: string, templateOptions?: TemplateOptions) => Promise<SdkResponse<PasswordResetResponse>>;
update: (loginId: string, newPassword: string, token?: string) => Promise<SdkResponse<never>>;
replace: (loginId: string, oldPassword: string, newPassword: string) => Promise<SdkResponse<JWTResponse>>;
policy: () => Promise<SdkResponse<PasswordPolicyResponse>>;
};
flow: {
start: (flowId: string, options?: Options, conditionInteractionId?: string, interactionId?: string, componentsVersion?: string, flowVersions?: Record<string, number>, input?: FlowInput) => Promise<SdkResponse<FlowResponse>>;
next: (executionId: string, stepId: string, interactionId: string, version?: number, componentsVersion?: string, input?: FlowInput) => Promise<SdkResponse<FlowResponse>>;
};
refresh: (token?: string, queryParams?: {
[key: string]: string;
}, externalToken?: string, tryRefresh?: boolean) => Promise<SdkResponse<JWTResponse>>;
selectTenant: (tenantId: string, token?: string) => Promise<SdkResponse<JWTResponse>>;
logout: (token?: string) => Promise<SdkResponse<never>>;
logoutAll: (token?: string) => Promise<SdkResponse<never>>;
me: (token?: string) => Promise<SdkResponse<UserResponse>>;
myTenants: (tenants: true | string[], token?: string) => Promise<SdkResponse<TenantsResponse>>;
history: (token?: string) => Promise<SdkResponse<UserHistoryResponse>>;
isJwtExpired: (token: string) => boolean;
getTenants: (token: string) => string[];
getJwtPermissions: (token: string, tenant?: string) => string[];
getJwtRoles: (token: string, tenant?: string) => string[];
getCurrentTenant: (token: string) => string;
httpClient: HttpClient;
}) & {
DeliveryMethods: {
readonly email: DeliveryEmail.email;
readonly sms: DeliveryPhone.sms;
readonly voice: DeliveryPhone.voice;
readonly whatsapp: DeliveryPhone.whatsapp;
};
};
/** Type to restrict to valid delivery methods */
type DeliveryMethod = keyof typeof DeliveryMethods;
/** Type to restrict to valid OAuth providers */
type OAuthProvider = keyof typeof OAuthProviders;
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 };