import { t as IamClient } from "../../client-0N6XNM6z.js"; import { ReactNode } from "react"; //#region src/client/react/index.d.ts /** Minimal React context type. */ interface ReactContext<_T> { Provider: unknown; } /** Minimal React API surface for dependency injection. */ interface ReactLike { createContext(defaultValue: T): ReactContext; useContext(context: ReactContext): T; useMemo(factory: () => T, deps: readonly unknown[]): T; useCallback(callback: T, deps: readonly unknown[]): T; createElement(type: unknown, props: Record | null, ...children: ReactNode[]): ReactNode; useState(initialState: T | (() => T)): [T, (value: T | ((prev: T) => T)) => void]; useEffect(effect: () => undefined | (() => void), deps?: readonly unknown[]): void; } /** * React client integration types. Type-only namespace - zero bundle cost. * * Named `IamReactClient` (rather than `React`) to avoid clashing with the React * package namespace when consumers import this module alongside React. */ declare namespace IamReactClient { /** * Describes the value exposed by the {@link createIamAccessControl} React context. * * @template TAction - Constrains valid action strings. * @template TResource - Constrains valid resource strings. * @template TScope - Constrains valid scope strings. */ interface IContextValue { /** The resolved permission map. */ permissions: IamClient.PermissionMap; /** Returns `true` if the action/resource combination is allowed. */ can: (action: TAction, resource: TResource, resourceId?: string, scope?: TScope) => boolean; /** Returns `true` if the action/resource combination is denied. */ cannot: (action: TAction, resource: TResource, resourceId?: string, scope?: TScope) => boolean; } } /** * Builds the React access control surface (Provider, hook, components). * * Call once at app init and export the result so the entire app shares a * single context. * * @template TAction - Constrains valid action strings. * @template TResource - Constrains valid resource strings. * @template TScope - Constrains valid scope strings. * @param React - Provides the host React module so we never bundle our own copy. * @returns `{ AccessContext, AccessProvider, useAccess, usePermissions, Can, Cannot }`. * @example * ```ts * import React from 'react' * import { createIamAccessControl } from 'duck-iam/client/react' * * export const { AccessProvider, useAccess, Can, Cannot } = createIamAccessControl(React) * ``` */ declare function createIamAccessControl(React: ReactLike): { AccessContext: ReactContext>; AccessProvider: ({ permissions, children }: { permissions: IamClient.PermissionMap; children: ReactNode; }) => ReactNode; useAccess: () => IamReactClient.IContextValue; usePermissions: (fetchFn: () => Promise>, deps?: readonly unknown[]) => { permissions: IamClient.PermissionMap; can: (action: TAction, resource: TResource, resourceId?: string, scope?: TScope) => boolean; loading: boolean; error: Error | null; }; Can: ({ action, resource, resourceId, scope, children, fallback }: { action: TAction; resource: TResource; resourceId?: string; scope?: TScope; children: ReactNode; fallback?: ReactNode; }) => ReactNode; Cannot: ({ action, resource, resourceId, scope, children }: { action: TAction; resource: TResource; resourceId?: string; scope?: TScope; children: ReactNode; }) => ReactNode; }; /** * Builds a standalone permission checker that does not require React. * * Useful for one-off checks, hooks outside the provider, or non-React paths. * * @template TAction - Constrains valid action strings. * @template TResource - Constrains valid resource strings. * @template TScope - Constrains valid scope strings. * @param permissions - Provides the permission map (typically from `engine.permissions(...)`). * @returns `{ can, cannot, permissions }`. */ declare function createIamPermissionChecker(permissions: IamClient.PermissionMap): { can: (action: TAction, resource: TResource, resourceId?: string, scope?: TScope) => boolean; cannot: (action: TAction, resource: TResource, resourceId?: string, scope?: TScope) => boolean; permissions: IamClient.PermissionMap; }; //#endregion export { IamReactClient, createIamAccessControl, createIamPermissionChecker }; //# sourceMappingURL=index.d.ts.map