@abxy/foil-server

中文文档
0.4.0发布于 2026/10/28MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4188

官方 Foil 节点服务器 SDK

中文使用文档
文档目录12 节
  1. 文档
  2. 安装
  3. 所需资源
  4. 使用量
  5. 封存符号验证
  6. 倾斜
  7. 指纹
  8. 组织
  9. 组织 API 密钥
  10. 网络呼号
  11. 处理错误
  12. 支助

Foil节点库

Preview Node 18+ License: MIT

Foil节点库从在Node.js运行的应用程序中为Foil API提供方便访问. 它包括一个为会话,指印,组织,组织API密钥管理,webhook端点,以及被封号的验证而输入的客户端.

图书馆还提供:

  • 使用快速配置路径 FOIL_SECRET_KEY
  • 基于光标的页形帮助
  • 结构化的 API 错误和内置封装符号验证
  • webhook 端点管理、测试发送、事件发送历史和webhook 签名验证

文档

见 Foil 文档 财务报告和审定财务报表 API 参考。 。 。 .

安装

除非你想要修改软件包,否则不需要这个源代码. 如果你想使用软件包,请运行:

npm install @abxy/foil-server

所需资源

  • 节点18+

使用量

使用 FOIL_SECRET_KEY 或明示 secretKey数字 :

import { Foil } from "@abxy/foil-server";

const client = new Foil({
  secretKey: process.env.FOIL_SECRET_KEY,
});

const page = await client.sessions.list({ verdict: "bot", limit: 25 });
const session = await client.sessions.get("sid_123");
await client.sessions.attachClientUser("sid_123", "user_123");
await client.sessions.clearClientUser("sid_123");
await client.sessions.attachClientApplication("sid_123", "app_123");
await client.sessions.clearClientApplication("sid_123");
const userSessions = await client.sessions.list({ client_user_id: "user_123" });

console.log(page.has_more, page.next_cursor);
console.log(session.decision.risk_score, session.highlights[0]?.summary);

封存符号验证

import { safeVerifyFoilToken } from "@abxy/foil-server";

const result = safeVerifyFoilToken(
  sealedToken,
  process.env.FOIL_SECRET_KEY,
);

if (!result.ok) {
  console.error(result.error);
  return;
}

console.log(result.data.decision.verdict, result.data.decision.risk_score);

倾斜

for await (const session of client.sessions.iter({ search: "signup" })) {
  console.log(session.id, session.latest_decision.verdict);
}

指纹

const page = await client.fingerprints.list({ sort: "seen_count" });
const fingerprint = await client.fingerprints.get("vid_123");

console.log(fingerprint.lifecycle.last_seen_at);

组织

const organization = await client.organizations.get("org_123");
const updated = await client.organizations.update("org_123", { name: "New Name" });

组织 API 密钥

const created = await client.organizations.apiKeys.create("org_123", {
  name: "Production",
  type: "secret",
  environment: "live",
  scopes: ["sessions:list", "sessions:read"],
});

await client.organizations.apiKeys.revoke("org_123", created.id);

网络呼号

const endpoint = await client.webhooks.createEndpoint("org_123", {
  name: "Production alerts",
  url: "https://example.com/foil/webhook",
  event_types: ["session.result.persisted"],
});

const events = await client.webhooks.listEvents("org_123", {
  endpoint_id: endpoint.id,
  type: "session.result.persisted",
});

console.log(events.items[0]?.webhook_deliveries[0]?.status);

正在验证webhook交付

每封网络邮递都签有你的端点签名的秘密 校验 X-Foil-Timestamp 财务报告和审定财务报表 X-Foil-Signature 在信任有效载荷之前,用头指向原始请求体:

import { parseWebhookEvent, verifyAndParseWebhookEvent, verifyWebhookSignature } from "@abxy/foil-server";

const valid = verifyWebhookSignature({
  secret: process.env.FOIL_WEBHOOK_SECRET!,
  timestamp: request.headers["x-foil-timestamp"],
  rawBody,
  signature: request.headers["x-foil-signature"],
});

// Verify and parse in one step. Throws if the signature is invalid or expired.
const event = verifyAndParseWebhookEvent({
  secret: process.env.FOIL_WEBHOOK_SECRET!,
  timestamp: request.headers["x-foil-timestamp"],
  rawBody,
  signature: request.headers["x-foil-signature"],
});

if (event.type === "session.result.persisted") {
  console.log(event.data);
}

// Parse a payload you have already verified.
const parsed = parseWebhookEvent(rawBody);

签署时间超过5分钟的,默认不予签署。 过 maxAgeSeconds 以改变宽容.

处理错误

import { FoilApiError } from "@abxy/foil-server";

try {
  await client.sessions.list({ limit: 999 });
} catch (error) {
  if (error instanceof FoilApiError) {
    console.error(error.status, error.code, error.message);
  }
}

支助

如果您需要帮助整合 Foil, 请从 使用foil.com/docs。 。 。 .

版本与发布记录

@abxy/foil-server 共发布 6 个版本,首次发布于 2026/05/23;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/10/2810 天前
0.3.12026/10/2612 天前
0.3.02026/10/061 个月前
0.2.62026/07/213 个月前
0.2.52026/07/213 个月前
0.2.42026/05/235 个月前

关于 @abxy/foil-server 的常见问题

@abxy/foil-server 是什么?

官方 Foil 节点服务器 SDK

如何安装 @abxy/foil-server?

在项目目录运行 npm install @abxy/foil-server,或使用 pnpm add / yarn add / bun add。

@abxy/foil-server 支持 TypeScript 吗?

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

@abxy/foil-server 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@abxy/foil-server 需要什么版本的 Node.js?

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

@abxy/foil-server 可以商用吗?

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

@abxy/foil-server 的下载量有多少?

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

@abxy/foil-server 还在维护吗?

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