/** Mirrors the server's `ResourceAccessState`. */ export type ResourceAccessGateState = "allowed" | "trashed" | "denied" | "missing" | "signed-out"; export type ResourceAccessGateRole = "owner" | "admin" | "editor" | "commenter" | "viewer"; /** The viewer's own open request for access. */ export interface ResourceAccessGateRequest { state: "pending"; requestedAt: string; } export interface ResourceAccessGateStatus { state: ResourceAccessGateState; /** The viewer's role, only when they can open the resource. */ role?: ResourceAccessGateRole; /** Whether the viewer can ask for access now. Only for `denied`. */ canRequest?: boolean; /** The viewer's open request. Only for `denied`. */ request?: ResourceAccessGateRequest; } /** Why asking for access failed, for the screen to explain. */ export interface ResourceAccessRequestFailure { /** The server's error code, such as `access_request_rate_limited`. */ errorCode: string | null; /** When the viewer can try again, if the server said. */ retryAt: string | null; } export interface ResourceAccessGateOptions { resourceType: string; resourceId: string; enabled?: boolean; /** * Called once when the status says the viewer can open the resource: either * the read that failed should be tried again, or the owner shared it while * this screen was open. The status is checked again whenever the window * regains focus, including switching back from another browser window, * every half minute while the viewer's request is open, and every 12 seconds * while the resource is in Trash. */ onAccessGranted?: () => void; } export interface ResourceAccessGateController { status: ResourceAccessGateStatus | undefined; isLoading: boolean; isError: boolean; refetch: () => Promise; /** * Asks the owner for access, with an optional note. Resolves once the * request is stored and the status shows it; rejects when it fails, with * the reason in `requestError`. */ requestAccess: (note?: string) => Promise; isRequesting: boolean; requestError: ResourceAccessRequestFailure | null; } /** * Asks the server what a link the viewer couldn't open should say. Use it * after a resource read fails with 403 or 404, then render the matching * access screen. */ export declare function useResourceAccessGate({ resourceType, resourceId, enabled, onAccessGranted, }: ResourceAccessGateOptions): ResourceAccessGateController;