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

@pactor-app/permission

v1.20.0

Published

Pactor permission: permission code store, runtime permission adapter, menu/page guards and expression function

Downloads

2,852

Readme

@pactor-app/permission

Pactor 的权限模块:权限码集合存储(PermissionStore)、适配 @pactor-app/runtime 的权限适配器、Menu / Page 守卫纯函数与表达式函数 permission(code)

浏览器只持有 Permission Set,DSL 中不出现 Role;前端权限只控制 UI(隐藏 / 禁用 / 拦截),后端必须再次鉴权。

安装

npm install @pactor-app/permission
# 或
pnpm add @pactor-app/permission

零运行时依赖(仅 @pactor-app/core 类型),不依赖 React 与 @pactor-app/runtime,可纯 Node 使用与测试。

示例

import {
  PermissionStore,
  createPermissionAdapter,
  createPermissionFunction,
  filterMenusByPermission,
  checkPagePermission,
} from '@pactor-app/permission';

// bootstrap 阶段一次性注入权限码集合
const store = new PermissionStore();
store.setPermissions(['customer:view', 'customer:edit']);

// 1. 注入 @pactor-app/runtime(结构化兼容 PermissionAdapter)
const runtime = createPageRuntime(pageDsl, {
  permission: createPermissionAdapter(store),
});
// - 节点 permission: 'customer:edit' 无权限时默认隐藏;
// - permission: { code: 'customer:edit', denied: 'disabled' } 时注入 disabled: true;
// - 动作配置无权限的 permission 时被 Action 引擎拦截({ ok: false })。

// 2. Menu / Page 守卫(纯函数)
const menus = filterMenusByPermission(rawMenus, store);
const canEnter = checkPagePermission(pageMeta, store);

// 3. 表达式函数(注入求值 options.functions 或作用域)
const functions = { permission: createPermissionFunction(store) };
// 支持 `${!permission('customer:edit')}` 形式

// 4. 权限变更通知
const off = store.subscribe(() => {/* 重新过滤菜单等 */});

功能一览

  • PermissionStoresetPermissions(codes)(整体替换)/ clear() / has(code) / hasAny(codes) / hasAll(codes) / subscribe(listener)(返回退订函数)。V1 精确匹配,不做通配符。
  • createPermissionAdapter(store):结构化兼容 @pactor-app/runtime 的 PermissionAdaptercheck 支持 string / string[](hasAny)/ { code, denied } 三种配置形态(对象形式只判定 code)。
  • resolvePermissionCheck(config, checker):三种形态归一为 { allowed, denied }(denied 缺省 'hidden',未配置 permission 视为放行),Renderer 与 Guards 复用同一逻辑。
  • filterMenusByPermission(menus, checker):递归移除无权限菜单项与空目录,不修改原数组,泛型保持菜单项类型。
  • checkPagePermission(page, checker):页面无 permission 字段时放行。
  • createPermissionFunction(store):返回 (code: string) => boolean,作为白名单函数注入表达式求值。

文档

完整文档见 https://github.com/426-330/pactor/tree/main/docspnpm docs:dev 本地启动文档站)。

License

MIT