npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

entitlement-lite

v0.1.0

Published

Tiny RBAC/ABAC permission engine for TypeScript — role-based access with rule-lite-powered attribute conditions.

Readme

entitlement-lite

Tiny, dependency-light RBAC (role-based access control) engine for TypeScript, with an ABAC (attribute-based) escape hatch powered by rule-lite.

Define roles, attach permissions, optionally gate a permission behind a condition evaluated against runtime context — and ask a single question: can(subject, action, resource).

Install

npm install entitlement-lite

Quick start

import { EntitlementEngine } from 'entitlement-lite';

const engine = new EntitlementEngine([
  {
    name: 'admin',
    permissions: [{ action: '*', resource: '*' }],
  },
  {
    name: 'editor',
    permissions: [
      { action: 'view', resource: 'invoice' },
      { action: 'edit', resource: 'invoice' },
    ],
  },
]);

engine.can({ roles: ['editor'] }, 'edit', 'invoice'); // true
engine.can({ roles: ['editor'] }, 'delete', 'invoice'); // false

Attribute-based conditions (ABAC)

Permissions can carry an optional condition — a rule-lite Rule evaluated against merged context ({ subject, resource, ...context }):

const engine = new EntitlementEngine([
  {
    name: 'approver',
    permissions: [
      {
        action: 'approve',
        resource: 'invoice',
        condition: { all: [{ field: 'amount', operator: 'lte', value: 5000 }] },
      },
    ],
  },
]);

engine.can({ roles: ['approver'] }, 'approve', 'invoice', { amount: 4000 }); // true
engine.can({ roles: ['approver'] }, 'approve', 'invoice', { amount: 9000 }); // false

API

| Export | Signature | Description | |---|---|---| | EntitlementEngine | new EntitlementEngine(roles?: Role[]) | Stateful engine; .can() and .registerRole() | | EntitlementEngine#can | (subject, action, resource, context?) => boolean | True if any matching permission grants access | | EntitlementEngine#registerRole | (role: Role) => void | Add or overwrite a role after construction | | can | (roles, subject, action, resource, context?) => boolean | Stateless one-off check |

action and resource support the wildcard '*' on either side of a Permission.

Angular example

@Injectable({ providedIn: 'root' })
export class EntitlementService {
  private engine = new EntitlementEngine(this.roleConfig.roles);

  canEdit(resource: string): boolean {
    return this.engine.can(this.currentUser, 'edit', resource);
  }
}

Use canEdit() behind a structural directive (*ngIf) or a route guard to keep permission logic out of components.

Why a separate package instead of one bigger "auth-lite"?

See CASE_STUDY.md for the RBAC-vs-ABAC design rationale, why this depends on rule-lite rather than reimplementing condition evaluation, and trade-offs against heavier options like OPA or Casbin.

License

MIT