@adonis-agora/authz

中文文档
0.20.1发布于 2026/10/28MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 6173

Bouncer-integrated, DB-backed RBAC for AdonisJS — roles, permissions, wildcard matching and multi-tenancy on top of @adonisjs/bouncer, with pluggable stores (Lucid / in-memory). Part of the Agora ecosystem.

原始使用文档
文档目录4 节
  1. Install
  2. Use
  3. Dashboards
  4. License

@adonis-agora/authz

npm version npm downloads CI license

Bouncer-integrated, DB-backed RBAC for AdonisJS — roles, permissions, wildcard matching and multi-tenancy on top of @adonisjs/bouncer, with pluggable stores. Part of the Agora ecosystem.

It does not replace Bouncer — it registers a small set of static Bouncer abilities (can, hasRole) whose body consults a database-backed permission store. You keep using ctx.bouncer.allows(...) and @can(...) exactly as you do today.

Install

npm i @adonis-agora/authz
node ace configure @adonis-agora/authz
node ace migration:run   # if you use the Lucid store

Use

// app/abilities/authz.ts was published for you:
import { can, hasRole } from '#abilities/authz'

// In a controller / route:
await ctx.bouncer.allows('can', 'posts.edit', post)   // wildcard: posts.* ⊇ posts.edit
await ctx.bouncer.authorize('hasRole', 'admin')
@can('can', 'posts.edit')
  <a href="/posts/{{ post.id }}/edit">Edit</a>
@end

Grant from the CLI or programmatically:

node ace authz:grant editor posts.edit
node ace authz:assign editor 42

Need resource-aware allow and deny from an external policy engine? Plug a decisionProvider into config/authz.ts — a Cerbos adapter ships at @adonis-agora/authz/cerbos (no extra runtime dependency; bring your own @cerbos/http client). It runs right after the super-admin check, batches authz.canMany, and maps Cerbos query plans onto accessibleBy scopes.

See the docs for concepts (wildcards, tenancy), config drivers, the Lucid mixin, ace commands and testing.

Dashboards

authorizeByRoles({ roles: ['ADMIN'] }) is the authorize hook for the @adonis-agora dashboards (telescope, durable, media, payments, agent). It returns an AuthorizeResult: true, or { allowed: false, reason: 'unauthenticated' | 'forbidden' } so the dashboard can answer 401 vs 403.

Requires the dashboard lib versions that accept AuthorizeDecision. The denial is an object (truthy); an older dashboard that treats the result as a boolean would let it through. See the minimum versions in docs/middleware.mdx.

License

MIT

版本与发布记录

@adonis-agora/authz 共发布 41 个版本,首次发布于 2026/06/23;过去 12 个月发布了 41 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.20.1latest2026/10/289 天前
0.20.02026/10/289 天前
0.19.12026/10/2710 天前
0.19.02026/10/1719 天前
0.18.12026/10/1720 天前
0.18.02026/09/291 个月前

关于 @adonis-agora/authz 的常见问题

@adonis-agora/authz 是什么?

Bouncer-integrated, DB-backed RBAC for AdonisJS — roles, permissions, wildcard matching and multi-tenancy on top of @adonisjs/bouncer, with pluggable stores (Lucid / in-memory). Part of the Agora ecosystem.

如何安装 @adonis-agora/authz?

在项目目录运行 npm install @adonis-agora/authz,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@adonisjs/core(^7.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adonis-agora/authz 支持 TypeScript 吗?

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

@adonis-agora/authz 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adonis-agora/authz 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adonis-agora/authz 可以商用吗?

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

@adonis-agora/authz 的下载量有多少?

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

@adonis-agora/authz 还在维护吗?

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