import type { AccessControlError } from '../core/AccessControlError.js'; import type { UnknownObject } from './UnknownObject.js'; /** Event names (the {@link AccessControlEvent} enum values). */ export type AccessControlEventName = 'access' | 'change' | 'error'; /** * Why a check was denied — makes denials debuggable in the audit log. * `undefined` when granted. * * `'out_of_schedule'` is the special one: the check failed *only* because of a * `during` schedule — it would have been granted at a covered instant * ("granted, but not now"). When a value predicate also failed, the reason * stays `'condition_failed'` / `'require_failed'`. */ export type DenyReason = 'no_grant' | 'condition_failed' | 'out_of_schedule' | 'require_failed' | 'ownership_failed' | 'strict'; /** * @deprecated Renamed to {@link DenyReason} (the value only exists on denial); * this alias remains for backward compatibility and will be removed in v4. */ export type AccessReason = DenyReason; /** Discriminator for a {@link ChangeEvent} (what kind of mutation occurred). */ export type ChangeType = 'grant' | 'deny' | 'extend' | 'remove' | 'set_grants' | 'reset' | 'setup' | 'require' | 'lock'; /** Fields shared by every emitted event. */ export interface BaseEvent { /** The event name (`access` | `change` | `error`). */ name: AccessControlEventName; /** Epoch milliseconds when the event was emitted. */ timestamp: number; } /** * Emitted for every resolved check — granted and denied. This **is** the access * audit record. ⚠️ `context` may contain PII; handle accordingly. */ export interface AccessEvent extends BaseEvent { name: 'access'; roles: string[]; resource: string; /** The resource's category, when it is a `category/resource`. */ category?: string; action: string; possession?: 'own' | 'any'; granted: boolean; attributes: string[]; /** Why it was denied (omitted when granted). */ reason?: DenyReason; /** The merged check context (may contain PII). */ context?: UnknownObject; } /** Emitted when the grants model or vocabulary mutates (policy-edit audit). */ export interface ChangeEvent extends BaseEvent { name: 'change'; type: ChangeType; /** Mutation-specific details (e.g. `{ roles, resource, action }`). */ detail?: UnknownObject; } /** Emitted when a check throws (also under `tryCan()`, which then denies). */ export interface ErrorEvent extends BaseEvent { name: 'error'; error: AccessControlError; /** The operation that threw: always `'check'`, the only one that emits `error`. */ operation: string; roles?: string[]; resource?: string; action?: string; } /** Any event emitted by `AccessControl`. */ export type AccessControlEventPayload = AccessEvent | ChangeEvent | ErrorEvent; /** An event listener callback. */ export type EventListener = (event: AccessControlEventPayload) => void; //# sourceMappingURL=IEvent.d.ts.map