Skip to content

API reference

Export Purpose
definePolicy(policy) Validate, canonicalize, compile, and freeze a policy. Reuse the returned object.
createAuthorizer(policy, options?) Create an authorizer. options.onInternalError reports evaluator faults.
authorizer.bind({ subject, assignments, context? }) Validate a binding and return a bound authorizer.
bound.check(request) Return a decision. Never throws on malformed input.
bound.enforce(request) Return the decision on allow, throw AuthorizationError on denial.
bound.explain(request) Return a decision with a bounded rule trace.
check(request), enforce(request), explain(request) One-shot forms that take the binding and check fields together.
trustedResource(ref, ancestors?, attributes?) Create an immutable, caller-attested resource snapshot.
prepareAssignments(assignments) Pre-validate and freeze a collection for reuse across many checks.

AuthorizationError is thrown by enforce() and carries decision.

RolebookPolicy, ResourceDefinitions, RoleDefinition, PolicyRule, PolicyCondition, ValueOperator, Subject, ResourceRef, RoleAssignment, TrustedResource, BindInput, CheckRequest, AuthorizationRequest, AuthorizationDecision, DecisionExplanation, DecisionTraceEntry, DecisionCode, MatchedRule, Authorizer, BoundAuthorizer, AuthorizerOptions, InternalErrorReporter, PermissionFromResources, ConcretePermission.

rolebook/middleware/hono exports createRolebookMiddleware(options) and the RolebookEnv<TPolicy> type. See Hono adapter.