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 { 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; }) => Promise; signOutManaged: () => Promise; startManagedSocialSignIn: (provider: "google" | "github") => 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; 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; }> | null; retryClientConfig: () => void; authSession: AuthSession | null | undefined; accessContext: AccessContext | null; accessError: Readonly<{ title: string; description: string; }> | 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")[]; browserAccountsConfigured: boolean; browserAccountsEnabled: boolean; handleManagedAuth: (mode: "signin" | "signup", input: { name: string; email: string; password: string; }) => Promise; handleManagedSessionSetSignup: (input: { name: string; email: string; password: string; }) => Promise; handleManagedSocialAuth: (provider: "google" | "github") => 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: { workspaceId: string; accountId: string | null; } | null; setCreditRequired: Dispatch>; mutationBusy: boolean; };