import { AxiosRequestConfig, AxiosRequestHeaders } from 'axios'; /** * HTTP method type for permission check requests. * - 'GET': Traditional permission check without attributes in the body * - 'POST': ABAC-enabled permission check with user and resource attributes in the request body */ export declare type HttpMethod = 'GET' | 'POST'; export interface PermitCheckSchema { loggedInUser: string; userAttributes: Record; backendUrl: string; defaultAnswerIfNotExist: boolean; state: PermitStateSchema; check: (action: string, resource: string | ReBACResourceSchema, userAttributes: Record, resourceAttributes?: Record) => boolean; addKeyToState: (action: string, resource: string | ReBACResourceSchema, resourceAttributes?: Record, userAttributes?: Record, method?: HttpMethod) => Promise; loadLocalState: (actionsResourcesList: ActionResourceSchema[], method?: HttpMethod) => Promise; getCaslJson: () => CaslPermissionSchema[]; loadLocalStateBulk: (actionsResourcesList: ActionResourceSchema[]) => Promise; reset: () => void; } export interface CaslPermissionSchema { action: string; subject: string; inverted: boolean; } export interface PermitStateSchema { [key: string]: boolean; } export interface ActionResourceSchema { action: string; resource: string | ReBACResourceSchema; userAttributes?: Record; resourceAttributes?: Record; } export interface ReBACResourceSchema { type: string; key: string; } export declare let permitState: PermitCheckSchema; export declare let permitCaslState: CaslPermissionSchema[]; export declare type PermitProps = { /** The unique identifier of the logged-in user for permission checks */ loggedInUser: string; /** Optional attributes associated with the user for ABAC policies */ userAttributes?: Record; /** The URL of your backend permission check endpoint */ backendUrl: string; /** Default permission value when a check is not found in local state (default: false) */ defaultAnswerIfNotExist?: boolean; /** * Custom headers to include in permission check requests. * @deprecated This option will be replaced by `axiosConfig.headers` in the next major version. * For now, headers must still be provided via `customRequestHeaders`; `axiosConfig.headers` is * currently ignored. */ customRequestHeaders?: AxiosRequestHeaders; /** * Axios request configuration for advanced use cases like CORS credentials or timeouts. * Note: any `axiosConfig.headers` you pass here will be overridden by `customRequestHeaders`. * For now, configure headers via `customRequestHeaders`; * in the next major version, headers will instead be read from `axiosConfig.headers`. */ axiosConfig?: AxiosRequestConfig; }; /** * Initialize the Permit SDK for frontend permission checks. * * @param props - Configuration options for the Permit SDK * @param props.loggedInUser - The unique identifier of the logged-in user * @param props.userAttributes - Optional attributes associated with the user for ABAC policies * @param props.backendUrl - The URL of your backend permission check endpoint * @param props.defaultAnswerIfNotExist - Default permission value when not found in state (default: false) * @param props.customRequestHeaders - Custom headers for requests (deprecated: use axiosConfig.headers in next version) * @param props.axiosConfig - Axios config for CORS credentials, timeouts, etc. (headers currently ignored) * @returns The Permit state object with permission check methods. * * @example * ```typescript * const permit = Permit({ * loggedInUser: 'user-123', * backendUrl: '/api/permit-check', * axiosConfig: { withCredentials: true, timeout: 10000 }, * }); * * await permit.loadLocalStateBulk([ * { action: 'read', resource: 'document' }, * { action: 'write', resource: 'document' }, * ]); * * if (permit.check('read', 'document')) { * // User has permission * } * ``` */ export declare const Permit: ({ loggedInUser, userAttributes, backendUrl, defaultAnswerIfNotExist, customRequestHeaders, axiosConfig }: PermitProps) => PermitCheckSchema;