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

@iushev/rbac

v2.0.0

Published

Role-based access control

Readme

rbac

Role-based access control following the NIST model — Core + Hierarchical RBAC with rules.

The package has no runtime dependencies and works the same on the server and on the client (web, React Native). The store is only an interface — implementations live in a separate project.

Install

npm install @iushev/rbac

The two halves

Building the data (server) — RbacManager over RbacManagerStore:

import { RbacManager, createRole, createPermission } from "@iushev/rbac";

const manager = new RbacManager({ store });

const viewPost = createPermission({ name: "viewPost" });
const updatePost = createPermission({ name: "updatePost", ruleName: "isAuthor" });
const reader = createRole({ name: "reader" });
const author = createRole({ name: "author" });

for (const item of [viewPost, updatePost, reader, author]) {
  await manager.add(item);
}

await manager.addChild(reader, viewPost); // a role contains a permission
await manager.addChild(author, reader); // a role contains a role
await manager.addChild(author, updatePost);

await manager.assign(author, "alice");

The hierarchy is a partial order: addChild rejects a cycle and a role under a permission.

Checking access (server or client) — CheckAccess:

await manager.checkAccess({ username: "alice", itemName: "viewPost" }); // true, via reader

Rules

A rule is code, not data. The store holds only its name and a text payload; the implementations are registered at startup, the same way on both sides:

import { RuleRegistry } from "@iushev/rbac";

const rules = new RuleRegistry({
  isAuthor: ({ username, params }) => (params.post as Post).authorId === username,
});

const manager = new RbacManager({ store, rules });

await manager.checkAccess({
  username: "alice",
  itemName: "updatePost",
  params: { post },
}); // true only if alice is the author

If an item points to an unregistered rule, the check throws UnknownRuleError.

Client side

The server serializes the graph with toSnapshot, the client loads it into InMemoryRbacStore and checks access locally, without the network:

// server
const payload = {
  rbac: await toSnapshot(store),
  assignments: [...(await store.getAssignments(username)).values()],
};

// client (web / React Native)
const store = new InMemoryRbacStore(payload.rbac);
const checker = new CheckAccess({ store, rules });

RbacUser ties an identity to the checker and caches results of checks without params:

const user = new RbacUser(checker, identity);
await user.can({ permissionName: "viewPost" });

matchRole covers the common "this screen is for these roles" case, with "?" for a guest and "@" for a logged-in user.

Store

Two interfaces, defined here and implemented elsewhere:

  • RbacStore — read-only (8 methods). That is all an access check needs, and all a client has to implement.
  • RbacManagerStore extends RbacStore — adds the mutations for building the data; server only.

InMemoryRbacStore is a full implementation of RbacManagerStore — for the client and for tests. Logic that doesn't depend on the backend (cycle detection, the ban on a role under a permission) is in RbacManager, so it isn't repeated in every implementation.

Migrating from @iushev/rbac

The vocabulary is the same; three differences:

| @iushev/rbac | here | | ------------------------------- | --------------------------------- | | new Role({ name }) | createRole({ name }) | | class extends BaseManager | implements RbacManagerStore | | Rule subclass + Rule.init() | RuleRegistry.register(name, fn) |

Role and Permission are now interfaces, not classes: an item that came over the network is a plain object and instanceof on it is always false. Distinguish by item.type (isRole / isPermission).

The Express middleware is not part of this package — it belongs to a server adapter on top of it.

Development

npm run build      # compiles src/ -> dist/
npm run dev        # tsc --watch
npm run typecheck  # type check without emit
npm test           # vitest
npm run lint       # eslint (typed rules)
npm run format     # prettier --write

The package has no runtime dependencies — everything external is in devDependencies.