@belvador/api

中文文档
0.8.7发布于 2026/10/30MITTypeScriptES Module零依赖近 30 天下载 3644

Typed client for the Belvador API (api.belvador.dev, OpenAPI 3.1): every operation by operationId, problem+json errors, retries, and node reads straight from the edge with short-lived tickets.

原始使用文档

@belvador/api

Typed client for the Belvador API (https://api.belvador.dev, OpenAPI 3.1). Every operation is called by its OpenAPI operationId with parameters in the API's wire names (snake_case); the operation table and parameter types are generated from the same registry as the OpenAPI document.

npm install @belvador/api
import { BelvadorApiError, createClient } from "@belvador/api";

const belvador = createClient({ token: process.env.BELVADOR_TOKEN! });

const { data } = await belvador.call("issues.list", { status: "unresolved", period: "24h", limit: 20 });

for await (const rows of belvador.pages("monitors.list", { limit: 100 })) console.log(rows.length);

try {
  await belvador.call(
    "monitors.create",
    {
      project_id: 1,
      slug: "nightly-backup",
      name: "Nightly backup",
      kind: "crontab",
      schedule: { type: "crontab", value: "0 2 * * *" },
      timezone: "UTC",
      checkin_margin_min: 5,
      max_runtime_min: 30,
      failure_threshold: 1,
      recovery_threshold: 1,
      expected_environments: ["production"],
    },
    { idempotencyKey: crypto.randomUUID() },
  );
} catch (e) {
  if (e instanceof BelvadorApiError && e.code === "API_SCOPE_INSUFFICIENT") console.log("needs", e.scope);
}
  • Tokens: a personal token (blv_pat_), service token (blv_svc_) or OAuth access token (blv_oat_). Create one in Settings → API tokens. The client never puts the token in an error message.
  • Errors are RFC 9457 problem+json, surfaced as BelvadorApiError with a stable code, status, scope (for API_SCOPE_INSUFFICIENT), retryAfter and requestId.
  • Approvals: sensitive operations (keys, members, tokens, alert destinations, node changes) throw APPROVAL_REQUIRED with e.approval = { id, url, expiresAt, state }. A person opens url on belvador.dev and approves with their authenticator code; call again with the same idempotencyKey (or call("approvals.get", { approval_id })) to read the outcome. Only https /approve/<id> links are kept.
  • Retries: reads, and writes sent with an idempotencyKey, are retried on 429 / 502–504 and network errors (retries, default 2), honouring Retry-After up to 10 s. NODE_OFFLINE is not retried.
  • Scopes: await belvador.scopes() returns the token's effective scopes (the Belvador-Scopes header).
  • Node data (issues, events, spans, traces, logs) lives on your workspace's own node. With nodeReads: "edge" the client asks POST /v1/tickets for a short-lived read ticket and reads edge.belvador.dev directly, so the data never passes the API gateway; it falls back to the gateway when the token may not hold a ticket.

Command line

belvador-api privacy pull writes a project's privacy policy as the JSON the Belvador SDKs accept (privacyPolicy(), SDK 0.6.0+), so a build can ship the same rules your node applies:

BELVADOR_TOKEN=blv_svc_… npx -p @belvador/api belvador-api privacy pull --project 42 --out belvador-privacy.json

--project is the project's number (the end of its DSN). The token needs projects:read; it is read only from BELVADOR_TOKEN and never printed. Exit codes: 0 written, 1 refused by the API (the code is printed), 2 wrong usage.

Node ≥ 20.10, Bun, Deno and modern browsers (any runtime with fetch and AbortSignal.any). MIT licensed.

版本与发布记录

@belvador/api 共发布 18 个版本,首次发布于 2026/10/27;过去 12 个月发布了 18 个版本。

版本发布日期距今
0.8.7latest2026/10/308 天前
0.8.62026/10/308 天前
0.8.52026/10/308 天前
0.8.42026/10/308 天前
0.8.32026/10/308 天前
0.8.22026/10/308 天前

关于 @belvador/api 的常见问题

@belvador/api 是什么?

Typed client for the Belvador API (api.belvador.dev, OpenAPI 3.1): every operation by operationId, problem+json errors, retries, and node reads straight from the edge with short-lived tickets.

如何安装 @belvador/api?

在项目目录运行 npm install @belvador/api,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 belvador-api,可以用 npx belvador-api 直接运行。

@belvador/api 支持 TypeScript 吗?

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

@belvador/api 支持 ESM 还是 CommonJS?

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

@belvador/api 需要什么版本的 Node.js?

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

@belvador/api 可以商用吗?

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

@belvador/api 的下载量有多少?

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

@belvador/api 还在维护吗?

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