<@via-profit/ability>v3.8.3
v3.8.3 · ABAC · DSL · TypeScript · 0 dependencies

Access rules you can actually read

A lightweight ABAC engine: describe policies in a simple DSL, get TypeScript types and check access the same way on the server and in the browser.

<@via-profit/ability>

How it looks

Policies
dsl
@name "Author can update a draft order"
permit permission.order.update if all:
  order.authorId equals user.id
  order.status in ['draft', 'review']

@name "Completed orders are read-only, except for admins"
deny permission.order.update if all:
  order.status equals 'completed'
  except any of:
    user.roles contains 'admin'
Check
ts
import {
  AbilityDSLParser,
  AbilityResolver,
  DenyOverridesStrategy,
} from '@via-profit/ability';

const policies = new AbilityDSLParser(dsl).parse();
const resolver = new AbilityResolver(policies, DenyOverridesStrategy);

// Throws AbilityError if access is denied
resolver.enforce('order.update', { order, user });

// Or check manually and explain the decision
const result = resolver.resolve('order.update', { order, user });
if (result.isDenied()) {
  console.log(result.explainToString());
}

Features

Simple DSL

Policies read like text: all/any groups, except blocks, aliases and annotations.

Types from policies

The generator builds TypeScript types of resources and environment — typos show up in the IDE.

8 strategies

Deny overrides, permit overrides, priorities, first match and more — or your own.

Explain

The check tree shows which rule matched and why access was denied.

Server and browser

Policies are defined on the server and sent to the client as JSON — a single source of truth.

Fast and light

Zero dependencies and about 1.5 µs per check — fine to check on every render.

Found it useful? Leave a star

Ability is an open source project under the MIT license. A star on GitHub is the simplest way to support it: it helps the library grow and lets more developers discover it.

Star on GitHub

Docs