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

@zhin.js/permission

v1.0.2

Published

Unified PermissionHost for command permit, tool permit, and platform-level auth in Zhin Plugin Runtime

Downloads

1,243

Readme

@zhin.js/permission

统一鉴权面(PermissionHost),供命令 permit、工具 permissions、平台级权限校验使用。

核心概念

  • PermissionHost — 解析 permit 字符串并校验是否通过。解析顺序:builtin → platform(adapter,perm) → 自定义 register → deny。
  • PermissionSubject — 鸭式鉴权主体(与 CommandSession / Message 同构:adapter / endpoint / scene / sender)。
  • permissionHostToken — Plugin Runtime Scope Token,ImRuntime 在根 Scope provide

使用

import {
  createPermissionHost,
  permissionHostToken,
  toPermissionSubject,
  assertPermitSyntax,
  type PermissionHost,
  type PermissionSubject,
} from '@zhin.js/permission';

命令 permit 校验

defineCommandpermit 字段支持 builtin DSL 和 platform(adapter,perm) 两种形态。构建期通过 assertPermitSyntax 做语法校验。

适配器注册平台 checker

// adapter plugin.ts
import { permissionHostToken, createSceneRolePlatformChecker } from '@zhin.js/permission';

export default definePlugin({
  name: 'my-adapter',
  setup(context) {
    if (context.resources.has(permissionHostToken)) {
      const host = context.resources.use(permissionHostToken);
      return host.registerPlatform('my-adapter', createSceneRolePlatformChecker());
    }
  },
});

自定义 permission

import { definePermission, definePlatformPermission } from '@zhin.js/permission';

// 名称匹配
export default definePermission({
  name: 'can_deploy',
  check: (name, subject) => subject.sender?.role?.includes('admin') ?? false,
});

// 正则匹配
export default definePermission({
  name: /^feature\./,
  check: (name, subject) => true,
});

层级

@zhin.js/plugin-runtime
  ↓
@zhin.js/permission  ← 本包
  ↓
@zhin.js/command / @zhin.js/core / @zhin.js/agent(消费者)

不依赖 @zhin.js/core——通过 PermissionSubject 鸭式接口解耦。