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

@anycms/oauth-client

v0.1.1

Published

OAuth2 认证 + 组织架构 API 客户端,面向 AnyCMS BFF 代理层。

Readme

@anycms/oauth-client

OAuth2 认证 + 组织架构 API 客户端,面向 AnyCMS BFF 代理层。

安装

pnpm add @anycms/oauth-client

快速开始

默认实例(推荐)

开箱即用,使用相对路径 + credentials: "include" 自动携带 cookie:

import { authApi, companyApi, departmentApi, orgUserApi, permissionApi } from "@anycms/oauth-client";

// 获取当前登录用户
const res = await authApi.me();
console.log(res.data); // { sub, name, nickname, email, ... }

自定义配置

import { createOAuthClient } from "@anycms/oauth-client";

const client = createOAuthClient({
  baseUrl: "https://api.example.com",  // 可选,默认 ""
  credentials: "include",              // 可选,默认 "include"
});

client.auth.me();
client.org.companyApi.list({ page: 1, pageSize: 20 });

也可以单独创建 Auth 或 Org API:

import { createAuthApi, createOrgApis } from "@anycms/oauth-client";

const auth = createAuthApi({ baseUrl: "https://api.example.com" });
const { companyApi, departmentApi, orgUserApi, permissionApi } = createOrgApis({ baseUrl: "https://api.example.com" });

API 参考

AuthApi — 认证

| 方法 | 说明 | 返回类型 | |------|------|----------| | getLoginUrl() | 获取登录跳转 URL(/api/auth/login) | string | | me() | 获取当前登录用户信息 | Promise<PaginatedResponse<OAuthUser>> | | refresh() | 刷新 token | Promise<PaginatedResponse<{ expiresIn: number }>> | | logout() | 退出登录 | Promise<PaginatedResponse<{ message: string }>> |

OrgApis — 组织架构

companyApi

| 方法 | 说明 | |------|------| | list(params?) | 公司列表,支持 { page, pageSize } | | get(id) | 按 ID 获取公司 | | getByCode(code) | 按编码获取公司 |

departmentApi

| 方法 | 说明 | |------|------| | get(id) | 获取部门详情 | | tree(companyId) | 获取部门树形结构 | | ancestors(id) | 获取祖先部门链 | | descendants(id) | 获取后代部门 | | users(id, params?) | 获取部门下用户,支持分页 | | permissions(id) | 获取部门权限规则 |

orgUserApi

| 方法 | 说明 | |------|------| | departments(userId) | 获取用户所属部门 | | list(params?) | 用户列表(含部门信息) | | registeredUsers(params?) | 注册用户列表 | | permissions(userId, resourceType) | 获取用户权限 | | roles(userId, params?) | 获取用户角色 | | rbacPermissions(userId, params?) | 获取用户 RBAC 权限 |

permissionApi

| 方法 | 说明 | |------|------| | check(req) | 权限检查 | | definitions(params?) | 权限定义列表 |

权限检查请求

const result = await permissionApi.check({
  userId: "user-123",
  resourceType: "agent",
  resourceId: "agent-456",       // 可选
  requiredPermission: "edit",    // "read" | "use" | "edit" | "manage" | "owner"
});
// result.data: { hasPermission, matchedScope, matchedDepartmentId }

类型

import type {
  OAuthUser,
  Company,
  Department,
  DepartmentTreeNode,
  UserDepartment,
  RegisteredUser,
  PermissionCheckRequest,
  PermissionCheckResult,
  DepartmentPermission,
  UserRole,
  PermissionDefinition,
  ApiResponse,
  PaginatedResponse,
  ClientConfig,
  AuthApi,
  OrgApis,
  OAuthClient,
} from "@anycms/oauth-client";

认证方式

浏览器场景推荐 cookie 方式(默认 credentials: "include"),也支持:

  1. Cookie(推荐)— 浏览器自动携带 oauth2_sid
  2. Authorization HeaderBearer <session_id>
  3. Query 参数?token=<session_id>(适用于 iframe、WebSocket)

License

MIT