UNPKG

@baqhub/sdk-react

Version:

The official React SDK for the BAQ federated app platform.

65 lines (64 loc) 2.36 kB
import { AppRecordContent, AuthenticationState } from "@baqhub/sdk"; import { SecureStorageAdapter, StorageAdapter } from "../helpers/storage.js"; import { StoreIdentity } from "./store/storeIdentity.js"; export declare enum AuthenticationStatus { UNAUTHENTICATED = "unauthenticated", AUTHENTICATED = "authenticated" } export declare enum ConnectStatus { IDLE = "idle", CONNECTING = "connecting", WAITING_ON_FLOW = "waiting_on_flow" } export declare enum ConnectError { ENTITY_NOT_FOUND = "entity_not_found", BAD_APP_RECORD = "bad_app_record", OTHER = "other" } interface UnauthenticatedInitialState { status: AuthenticationStatus.UNAUTHENTICATED; connectStatus: ConnectStatus.IDLE; error?: ConnectError; } interface UnauthenticatedConnectingState { status: AuthenticationStatus.UNAUTHENTICATED; connectStatus: ConnectStatus.CONNECTING; entity: string; } interface UnauthenticatedWaitingOnFlowState { status: AuthenticationStatus.UNAUTHENTICATED; connectStatus: ConnectStatus.WAITING_ON_FLOW; localState: AuthenticationState; flowUrl: string; } export type UnauthenticatedState = UnauthenticatedInitialState | UnauthenticatedConnectingState | UnauthenticatedWaitingOnFlowState; interface InitializingAuthenticatedState { status: AuthenticationStatus.AUTHENTICATED; authorizationId: string | undefined; localState: AuthenticationState; identity: StoreIdentity; } interface InitializedAuthenticatedState { status: AuthenticationStatus.AUTHENTICATED; identity: StoreIdentity; } type AuthenticatedState = InitializingAuthenticatedState | InitializedAuthenticatedState; export type UseAuthenticationState = UnauthenticatedState | AuthenticatedState; export interface BuildAuthenticationOptions { storage: StorageAdapter; secureStorage?: SecureStorageAdapter; app: AppRecordContent; } export interface UseAuthenticationOptions { appIconUrl?: string; authorizationId?: string | null; } export declare function buildAuthentication(options: BuildAuthenticationOptions): { useAuthentication: (options?: UseAuthenticationOptions) => { state: UseAuthenticationState; onConnectRequest: (entity: string) => void; onAuthorizationResult: (authorizationId?: string) => void; onDisconnectRequest: () => void; }; }; export {};