@haneinfo/m2m-api-key

中文文档
8.1.38发布于 2026/11/17UNLICENSEDTypeScriptCommonJS近 30 天下载 6597
原始使用文档

Machine-to-machine API keys

Scope catalog

The grantable catalog comes from mounted REST @Scopes() declarations and App-provided M2M_SCOPE_SOURCES (ScopeSource[]). Concrete scopes use <resource>:<action>, split at the last colon. Each resource segment and the action must contain only [a-z0-9_-], with at least one character per segment. For example, users:read, haneinfo-reports:definition:read and haneinfo-reports:reports:data:read are valid when declared. Empty segments, whitespace, uppercase characters and embedded wildcards are rejected. Actions are not limited to read/write.

New grants must be declared concrete scopes, * (the existing global grant), or <resource>:* for a resource with at least one concrete catalog entry. A wildcard declaration alone does not establish a resource. Resource matching is exact: haneinfo-reports:definition:* matches haneinfo-reports:definition:read, whereas haneinfo-reports:* does not. The latter cannot be issued unless a concrete scope with resource exactly haneinfo-reports is declared.

list() returns sorted concrete scopes; describe() and groupOf() use the entire resource for App M2M_SCOPE_GROUPS display grouping. Key creation validates all grants; updates validate only newly added grants, preserving existing legacy scopes through unrelated edits. ScopeGuard and the SCOPE_MATCHER capability used by MCP delegate matching to plugin-api matchScope.

See the agent guide for App wiring and verification.

Authentication observation

Successful API key authentication records lastUsedAt asynchronously. Writes are throttled per key across processes using a conditional database update. The default interval is 60 seconds; set M2M_API_KEY_LAST_USED_INTERVAL_SECONDS to an integer from 0 to 86400 to change it (0 disables throttling). Invalid or absent values use 60 seconds. The timestamp can lag the latest successful authentication by up to the configured interval, plus asynchronous database delay; write failures are logged and retried on a later request. This timestamp is observational and does not determine authentication or authorization.

版本与发布记录

@haneinfo/m2m-api-key 共发布 42 个版本,首次发布于 2026/10/02;过去 12 个月发布了 42 个版本。

版本发布日期距今
8.1.38latest2026/11/17今天
8.1.372026/11/161 天前
8.1.362026/11/0412 天前
8.1.352026/11/0214 天前
8.1.342026/11/0115 天前
8.1.332026/10/3017 天前

关于 @haneinfo/m2m-api-key 的常见问题

如何安装 @haneinfo/m2m-api-key?

在项目目录运行 npm install @haneinfo/m2m-api-key,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^4.4.0)、@nestjs/core(^11.0.0 || ^12.0.0)、@nestjs/common(^11.0.0 || ^12.0.0)、@prisma/client(^6.19.0 || ^7.10.1)、@haneinfo/common(^0.6.1 || ^0.7.0)、@haneinfo/plugin-host-nest(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@haneinfo/m2m-api-key 支持 TypeScript 吗?

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

@haneinfo/m2m-api-key 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@haneinfo/m2m-api-key 可以商用吗?

@haneinfo/m2m-api-key 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@haneinfo/m2m-api-key 的下载量有多少?

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

@haneinfo/m2m-api-key 还在维护吗?

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