@evanion/acl

中文文档
0.2.0发布于 2026/11/06MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 4766

A declarative, serializable access-control matrix authored once and evaluated locally on whatever JS runtime is running: a Node backend, a frontend SSR graph, a browser SPA, or a hybrid JS platform.

原始使用文档
文档目录5 节
  1. Capability Map
  2. Installation
  3. Security Contract
  4. Documentation
  5. License

@evanion/acl

Consistent, local authorization across your entire stack.

Most apps suffer from an "Authorization Bottleneck": you either make a slow network round-trip for every UI button and API endpoint, or you risk fragile bugs by duplicating the same logic in both the frontend and backend. @evanion/acl solves this by letting you define your authorization logic once as a serializable matrix and evaluate it locally—on your Node backend, in your Next.js server components, or directly in the browser.

import { hydratePolicy, policy } from '@evanion/acl';

type Shopper = { id: string; roles: string[] };
type Question = { id: string; askedBy: string };

const access = policy<Shopper, { question: Question }>()
  .for('question', (p) =>
    p.allow('delete', p.contains('subject.roles', 'bookseller')),
  )
  .build();

const bookseller = { id: 'staff-3', roles: ['bookseller'] };
const customer = { id: 'customer-41', roles: ['customer'] };
const question = { id: 'q7', askedBy: 'customer-41' };
// ---cut---
// The server sends the matrix as JSON text, and the browser rebuilds from it.
const json = JSON.stringify(access.matrix);
const inBrowser = hydratePolicy(JSON.parse(json));

inBrowser.can(bookseller, 'question', 'delete', question).allowed; // -> true
inBrowser.can(customer, 'question', 'delete', question).allowed; // -> false

Capability Map

The @evanion/acl package provides the following capabilities:

  • Local Decisions: Decisions are synchronous function calls with no await and no network requests.
  • Single Source of Truth: The frontend and backend answer from the same matrix shipped as JSON.
  • Fail-Closed Security: Nothing is granted by default; malformed documents throw at construction and uncarried actions are refused.
  • Field-Level Control: Use canFields to decide exactly which fields a user can change.
  • Environment Agnostic: Runs in the browser and Node 20+; it is ESM only with no runtime or peer dependencies.

Installation

npm install @evanion/acl

Security Contract

A decision is authoritative only where it runs in a trusted environment such as your server; in the browser the same can call is advisory and only changes what the user sees. Every layer decides for itself and trusts no earlier one. Because the matrix ships to the client in full, its names and structure are a public document; resolving the subject, covering every access path, and re-checking at write time remain your application's job. The full security contract is in SECURITY.md and on the security page.

Documentation

For deep dives into the security model, field-level permissions, and integration guides for Next.js and Express, visit our documentation site:

👉 libs.evanion.com/docs/acl

License

MIT

版本与发布记录

@evanion/acl 共发布 4 个版本,首次发布于 2026/09/28;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/11/067 天前
0.1.22026/11/068 天前
0.1.12026/10/1826 天前
0.1.02026/09/281 个月前

关于 @evanion/acl 的常见问题

@evanion/acl 是什么?

A declarative, serializable access-control matrix authored once and evaluated locally on whatever JS runtime is running: a Node backend, a frontend SSR graph, a browser SPA, or a hybrid JS platform.

如何安装 @evanion/acl?

在项目目录运行 npm install @evanion/acl,或使用 pnpm add / yarn add / bun add。

@evanion/acl 支持 TypeScript 吗?

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

@evanion/acl 支持 ESM 还是 CommonJS?

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

@evanion/acl 需要什么版本的 Node.js?

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

@evanion/acl 可以商用吗?

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

@evanion/acl 的下载量有多少?

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

@evanion/acl 还在维护吗?

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