import { type AppContextValue, type PendingSlackLink } from "./app-context.js"; import { type OpenGeniBrowserClient } from "@opengeni/sdk/browser"; import type { BrowserAccountTransition } from "../accounts.js"; import { type Dispatch, type SetStateAction } from "react"; import type { AnalyticsEventName, AnalyticsProperties } from "./lib/analytics-types.js"; import type { CreditRequired } from "./components/credit-required-gate.js"; import type { AccessContext, AuthSession, ClientConfig, SlackUserLinkAccessRequest, Workspace } from "./types.js"; /** * Transport and sign-in functions the app state calls. Pass one stable object * (a module constant): its functions are read once per render. */ export type AppStateHost = Readonly<{ /** * "app": the app owns sign-in (deployment key, configured token or managed * session, as the server's client configuration says). "host": the * embedding page already authenticated `createOpenGeniClient`'s client, so * no sign-in step or access-key gate runs. */ authority: "app" | "host"; createOpenGeniClient: (beginSharedRead?: () => number) => OpenGeniBrowserClient; fetchClientConfig: (signal?: AbortSignal, workspaceId?: string) => Promise; /** Product analytics for sign-in and sign-up outcomes. */ captureProductEvent: (name: AnalyticsEventName, properties?: AnalyticsProperties) => void; /** Re-checks the deployed revision on focus and on an interval; absent: never. */ checkDeploymentRevision?: ((signal: AbortSignal) => Promise) | undefined; fetchAuthSession: () => Promise; signInEmail: (input: { email: string; password: string; rememberMe?: boolean; }) => Promise; signUpEmail: (input: { name: string; email: string; password: string; signupChallengeToken?: string; }) => Promise; signOutManaged: () => Promise; startManagedSocialSignIn: (provider: "google" | "github", signupChallengeToken?: string) => Promise; /** * Passkey sign-in and passkey-only sign-up. Both run the browser's WebAuthn * ceremony and leave the managed session cookie set; absent: the app offers * no passkeys even where the server would. */ signInPasskey?: () => Promise; signUpPasskey?: (input: { name: string; signupChallengeToken?: string; }) => Promise; configureManagedActorEpoch: (epoch: string | null) => void; getStoredAccessKey: () => string | null; setStoredAccessKey: (value: string) => void; clearStoredAccessKey: () => void; /** A signed Slack link the page opened with, exchanged once after sign-in. */ slackLink: SlackLinkPrepareController; initialInvalidSlackLinkQueryWorkspaceId: string | null; }>; export type AppStateOptions = Readonly<{ /** Skip the client-configuration bootstrap (public pages that need no session). */ bootstrapSuspended: boolean; }>; export type AppState = ReturnType; /** The one "GitHub status unavailable" toast; a newer failure replaces it. */ export declare const GITHUB_STATUS_TOAST_ID = "opengeni-github-status"; /** The one "Your GitHub account is unavailable" toast. */ export declare const PERSONAL_GITHUB_STATUS_TOAST_ID = "opengeni-personal-github-status"; /** The one lasting "Reconnect your GitHub" toast. */ export declare const PERSONAL_GITHUB_RECONNECT_TOAST_ID = "opengeni-personal-github-reconnect"; /** The lasting "Reconnect your GitHub" toast with its one action. */ export declare function showPersonalGitHubReconnectToast(githubLogin: string | null, onReconnect: () => void): void; export type SlackLinkPrepareController = ReturnType>; export type SlackLinkPreparePhase = "none" | "raw" | "in_flight" | "prepared" | "failed"; /** * A signed-out Slack deep link has already been scrubbed from browser history, * so its raw in-memory bearer may cross exactly the sign-in that authenticates * its exchange. Every other principal transition clears it. */ export declare function preserveSlackLinkForManagedAuth(mode: "signin" | "signup", phase: SlackLinkPreparePhase): boolean; export declare function createSlackLinkPrepareController(value: PendingSlackLink | null): { workspaceId: () => string | null; phase: () => SlackLinkPreparePhase; prepare: (requestedWorkspaceId: string, exchange: (token: string) => Promise) => Promise; clear: () => void; }; export declare function useAppState(host: AppStateHost, appStateOptions: AppStateOptions): { appContext: AppContextValue | null; client: OpenGeniBrowserClient; clientConfig: ClientConfig | null; configError: Readonly<{ title: string; description: string; recovering?: true | undefined; }> | null; retryClientConfig: () => void; authSession: AuthSession | null | undefined; accessContext: AccessContext | null; accessError: Readonly<{ title: string; description: string; recovering?: true | undefined; }> | null; accessLoading: boolean; accessKeyVersion: number; retryAccess: () => void; keyAuthRequired: boolean; hasAccessKey: boolean; accessKeyDraft: string; setAccessKeyDraft: Dispatch>; saveAccessKey: () => void; managedAuthRequired: boolean; managedEmailVerificationRequired: boolean; managedNewSignupsEnabled: boolean; managedSocialProviders: ("github" | "google")[]; managedPasskeySignIn: boolean; managedPasskeySignUp: boolean; browserAccountsConfigured: boolean; browserAccountsEnabled: boolean; handleManagedAuth: (mode: "signin" | "signup", input: { name: string; email: string; password: string; signupChallengeToken?: string; }) => Promise; handleManagedSessionSetSignup: (input: { signupChallengeToken?: string; name: string; email: string; password: string; }) => Promise; handleManagedSocialAuth: (provider: "google" | "github", signupChallengeToken?: string) => Promise; handleManagedPasskeyAuth: (mode: "signin" | "signup", input?: { name: string; signupChallengeToken?: string; }) => Promise; handleManagedSignOut: () => Promise; handleBrowserActorTransition: (transition: BrowserAccountTransition) => Promise; completeOrganizationOnboarding: (destination?: { workspaceId: string; sessionId?: string; }) => Promise; revalidatePrincipalAccess: () => void; defaultWorkspaceId: string | null; slackLinkContinuationWorkspaceId: string | null; routedWorkspace: Workspace | null; creditRequired: CreditRequired | null; setCreditRequired: Dispatch>; mutationBusy: boolean; };