Skip to content

AccessEngine

← Documentation home

Central authorization engine: holds your policy rules and answers can this subject perform this action on this resource? Returns a Decision (or ExplainResult when debugging).

Create one instance per app (or per domain), add rules, then call evaluate() from HTTP middleware, jobs, or UI code. See How evaluation works for the matching pipeline.


Constructor

typescript
new AccessEngine<S>(options: AccessEngineOptions<S>)

AccessEngineOptions

OptionDefaultDescription
schemarequired (type anchor)SchemaDefinition for inference
defaultEffect"deny"Effect when no rule matches
onDecisionListener on every evaluation
onConditionErrorWhen a condition throws
strictTenancyfalseThrow if tenantId omitted when required
roleHierarchyRoleHierarchy<S> instance
cacheSize0 (off)LRU capacity

Methods

MethodDescription
addRule(rule)Add one rule (frozen)
addRules(...rules)Add multiple
removeRule(id)Remove by id
getRules()Readonly frozen rules
clearRules()Remove all
evaluate(subject, action, resource, ctx?, tenantId?)Sync evaluation
evaluateAsync(...)Async evaluation
permitted(subject, resource, actions[], ctx?, tenantId?)Allowed actions as Set
permittedAsync(...)Async variant
explain(...)Evaluation + trace
explainAsync(...)Async variant
can(subject)Fluent check helper
onDecision(listener)Subscribe; returns unsubscribe
allow() / deny()Return a RuleBuilder bound to this engine's schema
clearCache()Clear LRU
cacheStats{ size, maxSize } or null

Released under the MIT License.