@aooth/arbac

中文文档
0.2.6发布于 2026/11/07MITTypeScriptESM + CJS近 30 天下载 2335

Batteries-included RBAC: builder API, privilege factories, scope merge utilities

原始使用文档
文档目录5 节
  1. Install
  2. Documentation
  3. Deny is binary on (resource, action)
  4. Scopes from multiple roles union via $or — permissive wins
  5. License

aoothjs

@aooth/arbac

Batteries-included RBAC — re-exports @aooth/arbac-core and adds a fluent role builder, reusable privilege factories, scope-merge utilities, and a codegen CLI for typed resource/action unions.

Documentation →


Install

pnpm add @aooth/arbac

Documentation

Full docs, API reference, and recipes: https://aooth.moost.org/arbac/**

Deny is binary on (resource, action)

.deny(resource, action) short-circuits the entire (resource, action) tuple — there is no scope or filter parameter. Once a deny rule's action regex matches, evaluate() returns { allowed: false } immediately, before any other role's allow scopes are even constructed (see arbac-core/src/arbac.ts:126-131).

If you need "hide rows where condition X", express it as an allow with a filter that excludes X, not as a partial deny:

// ✗ Not supported — no row-level deny.
// .deny("tasks", "query", { scope: { filter: { status: "secret" } } })

// ✓ Use a filtered allow instead.
allowTableRead<UserAttrs, Scope>("tasks", {
  scope: (attrs) => ({
    filter: { tenantId: attrs.tenantId, status: { $ne: "secret" } },
  }),
});

Pinned by UNION-03 and UNION-05 in packages/e2e-demo/test/arbac-union.spec.ts — unscoped deny short-circuits sibling allows, and wildcard .deny("tasks", "*") 403s both row-allow (markDone) and set-allow (new) tuples.

Scopes from multiple roles union via $or — permissive wins

When a user has multiple roles that each allow the same (resource, action), their scopes are merged disjunctively via mergeScopeFilters (see packages/arbac/src/scope/filter.ts). A row matches if ANY scope's filter matches. Consequence: if one scope has no filter (rule registered without scope, or with filter: undefined / filter: {}), the union widens to universe and the more restrictive filters in sibling scopes are silently dropped.

// Role "viewer" — tenant-scoped read on tasks.
.use(allowTableRead("tasks", {
  scope: (attrs) => ({ filter: { tenantId: attrs.tenantId } }),
}))

// Role "tasks-everywhere" — unscoped read on tasks (e.g., for an audit role).
.allow("tasks", "query")  // no scope ← contributes universe to the union

// A user with both roles sees ALL tasks (universe wins), not just their tenant.

This is the natural $or semantic: union of "tenant rows" and "all rows" is "all rows". The takeaway: don't grant an unscoped allow on a resource that other roles are trying to filter. Pinned by the arbacRowFilter empty-vs-undefined coercion tests in packages/arbac-moost/src/db/shared-read-helpers.spec.ts.

License

MIT

版本与发布记录

@aooth/arbac 共发布 92 个版本,首次发布于 2026/05/18;过去 12 个月发布了 92 个版本。

版本发布日期距今
0.2.6latest2026/11/07今天
0.2.52026/11/061 天前
0.2.42026/11/043 天前
0.2.32026/11/043 天前
0.2.22026/11/034 天前
0.2.12026/11/034 天前

关于 @aooth/arbac 的常见问题

@aooth/arbac 是什么?

Batteries-included RBAC: builder API, privilege factories, scope merge utilities

如何安装 @aooth/arbac?

在项目目录运行 npm install @aooth/arbac,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 aoothjs-arbac-codegen,可以用 npx aoothjs-arbac-codegen 直接运行。

@aooth/arbac 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aooth/arbac 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aooth/arbac 可以商用吗?

@aooth/arbac 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aooth/arbac 的下载量有多少?

根据 npm 官方下载统计,@aooth/arbac 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,335 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aooth/arbac 还在维护吗?

最新版本 0.2.6 发布于 2026/11/07(今天);至今共发布 92 个版本,其中过去 12 个月发布了 92 个;首次发布于 2026/05/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。