@slashid/react
Version:
React SDK for the /id platform
120 lines • 4.53 kB
TypeScript
import { User } from "@slashid/slashid";
import { Cancel, LogIn, LoginConfiguration, Retry, MFA, LoginOptions, Recover, RetryPolicy } from "../../../domain/types";
import { StoreRecoveryCodesState } from "../store-recovery-codes";
import { Handle } from "../../../domain/types";
export type AuthnContext = {
config: LoginConfiguration;
options?: LoginOptions;
attempt: number;
};
export interface InitialState {
status: "initial";
logIn: (config: LoginConfiguration, options?: LoginOptions) => void;
cancel: Cancel;
}
export interface AuthenticatingState {
status: "authenticating";
context: AuthnContext;
retry: Retry;
cancel: Cancel;
updateContext: (context: AuthnContext) => void;
recover: () => void;
logIn: () => void;
setRecoveryCodes: (codes: string[]) => void;
}
export interface SuccessState {
status: "success";
}
export interface ErrorState {
status: "error";
context: AuthenticatingState["context"] & {
error: Error;
};
retry: Retry;
cancel: Cancel;
}
export interface LoginEvent {
type: "sid_login";
config: LoginConfiguration;
options?: LoginOptions;
}
export interface UpdateAuthnContextEvent {
type: "sid_login.update_context";
context: AuthnContext;
}
export interface LoginSuccessEvent {
type: "sid_login.success";
user: User;
}
export interface LoginErrorEvent {
type: "sid_login.error";
error: Error;
}
export interface CancelEvent {
type: "sid_cancel";
}
export interface RetryEvent {
type: "sid_retry";
context: AuthenticatingState["context"];
policy: RetryPolicy;
}
export interface InitEvent {
type: "sid_init";
}
export interface StoreRecoveryCodesEvent {
type: "sid_storeRecoveryCodes";
user: User;
}
export type Event = InitEvent | LoginEvent | UpdateAuthnContextEvent | LoginSuccessEvent | LoginErrorEvent | RetryEvent | CancelEvent | StoreRecoveryCodesEvent;
type FlowActions = {
entry?: () => void;
};
export type FlowState = FlowActions & (InitialState | AuthenticatingState | SuccessState | ErrorState | StoreRecoveryCodesState);
export type Observer = (state: FlowState, event: Event) => void;
export type Send = (e: Event) => void;
export declare const createInitialState: (send: Send) => InitialState;
export declare const createAuthenticatingState: (send: Send, context: AuthenticatingState["context"], logInFn: LogIn | MFA, recoverFn: Recover, setRecoveryCodes: (codes: string[]) => void, propagateFlowCancelled: boolean) => AuthenticatingState;
export declare const createSuccessState: () => SuccessState;
export declare const createErrorState: (send: Send, context: ErrorState["context"]) => ErrorState;
export declare const createStoreRecoveryCodesState: (send: Send, recoveryCodes: string[], user: User) => StoreRecoveryCodesState;
export type HistoryEntry = {
state: FlowState;
event: Event;
};
export type CreateFlowOptions = {
oid?: string;
onSuccess?: (user: User) => void;
onError?: (error: Error, context: ErrorState["context"]) => void;
logInFn?: LogIn | MFA;
recover?: Recover;
cancelFn?: Cancel;
lastUserHandle?: Handle;
};
type AsyncDependencies = {
getLogInFn: () => LogIn | MFA | undefined;
getRecoverFn: () => Recover | undefined;
getCancelFn: () => Cancel | undefined;
};
type StaticDependencies = {
send: (event: Event) => void;
setState: (state: FlowState, event: Event) => void;
onSuccess?: (user: User) => void;
onError?: (error: Error, context: AuthenticatingState["context"] & {
error: Error;
}) => void;
getRecoveryCodes: () => string[] | undefined;
setRecoveryCodes: (codes: string[]) => void;
propagateFlowCancelledError: boolean;
};
type FlowDependencies = AsyncDependencies & StaticDependencies;
type TransitionHandler = (event: Event, state: FlowState, deps: FlowDependencies) => void;
export declare const loginHandler: TransitionHandler;
export declare const storeRecoveryCodesHandler: TransitionHandler;
export declare const loginUpdateContextHandler: TransitionHandler;
export declare const loginSuccessHandler: TransitionHandler;
export declare const loginErrorHandler: TransitionHandler;
export declare const retryHandler: TransitionHandler;
export type FlowHandlers = Partial<Record<Event["type"], TransitionHandler>>;
export declare function createTransitionFunction(deps: FlowDependencies, handlers: FlowHandlers): (event: Event, state: FlowState) => void;
export {};
//# sourceMappingURL=flow.common.d.ts.map