@forwardpath/node

中文文档
0.2.0发布于 2026/10/23UNLICENSEDTypeScriptES Module近 30 天下载 3864

服务器侧客户端 : 薄荷FrontPath 接收会话 .

中文使用文档
文档目录5 节
  1. 安装
  2. 验证用户为 createUserHash
  3. 在服务器上保留您的 API 密钥
  4. 下一个.js路线
  5. 自己去打一场

@ forwardpath/节点

FrontPath 收录 API 的服务器端助手. 用于签名用户 可出版关键会话 createUserHash或薄荷短寿命摄入量 带有您的 API 密钥的会话, 因此密钥永远不会到达浏览器 。 这个 next.js App路由器(或任何运行时间)的现成路线处理器 网络 Request编号 :Response) (中文(简体) ).

安装

npm install @forwardpath/node

验证用户为 createUserHash

使用可公布的密钥,浏览器会自定会话并命名为 用户。 没有证据, ForwardPath 标记该用户 claimed,即未经核实. 来标记他们 verified,用密钥在服务器上签名 身份秘密(fpiv_…,在创建密钥时显示一次)并传递 散列到浏览器 .

import { createUserHash } from "@forwardpath/node";

const userHash = createUserHash({
  identitySecret: process.env.FORWARDPATH_IDENTITY_SECRET!,
  user: { id: user.id, email: user.email },
});
// Render it into the page:
// <ForwardPathProvider publishableKey="fppk_…" user={user} userHash={userHash}>

散列是小写 HMAC-SHA256的 JSON.stringify([id, email]),与 id被剪切,电子邮件被剪切和小写(null (在缺席时)。 这个 签名 ID 和电子邮件, 而不是名称 。 浏览器必须发送相同的 ID 和 电子邮件,或会话失败为 401 . createUserHash 丢入浏览器 如果秘密不是从 fpiv_保持一个秘密 (原始内容存档于2017-03-21). only server-env var.

在服务器上保留您的 API 密钥

您的 API 密钥( E)fp_<keyId>.<secret>)可以为任何用户提供薄荷会话. 收起来 在只使用服务器的env var. createForwardPathClient 如果运行在一个 浏览器, 或者如果密钥形状不当 。 路由处理器只用 语句符号及其过期,绝不是密钥.

下一个.js路线

// app/api/forwardpath/session/route.ts
import {
  createForwardPathClient,
  createIntakeSessionHandler,
} from "@forwardpath/node";

import { auth } from "@/auth"; // your own auth

const client = createForwardPathClient({
  apiKey: process.env.FORWARDPATH_API_KEY!,
  baseUrl: "https://app.forwardpath.ai",
});

export const POST = createIntakeSessionHandler({
  client,
  projectSlug: "acme-app",
  getUser: async () => {
    const session = await auth();
    if (!session?.user) return null; // responds 401
    return {
      externalId: session.user.id,
      email: session.user.email,
      name: session.user.name ?? undefined,
    };
  },
});

浏览器调用它 POST /api/forwardpath/session 回来 { token, expiresAt }。将符号传递给 @forwardpath/js 或者说 @forwardpath/react尸体可以携带 { clientContext } (例如来自 collectClientContext());处理器将其转发到前方Path.

处理器响应 :

状态何时
200个{ token, expiresAt }
400个身体不是JSON物体, 或者ForwardPath拒绝了有效载荷
401 (中文(简体) )getUser 已返回 null
502 (中文(简体) )FrontPath 失败的另一个原因( 如不良的 API 密钥)

自己去打一场

const session = await client.createIntakeSession({
  projectSlug: "acme-app",
  user: { externalId: "u_123", email: "[email protected]", name: "Ada" },
  clientContext: { appName: "Acme", appVersion: "2.4.0" }, // optional
  metadata: { plan: "pro" }, // optional, stored on the reporter
});
// { token, expiresAt, projectSlug, reporter }

非-2xx回复拒绝使用 ForwardPathApiError (从 @forwardpath/js)),已经 status, (中文(简体) ), code 财务报告和审定财务报表 title。 。 。 .

版本与发布记录

@forwardpath/node 共发布 4 个版本,首次发布于 2026/10/22;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.2.0latest2026/10/2324 天前
0.1.12026/10/2224 天前
0.1.02026/10/2224 天前
0.0.0-stage2026/10/2224 天前

关于 @forwardpath/node 的常见问题

@forwardpath/node 是什么?

服务器侧客户端 : 薄荷FrontPath 接收会话 .

如何安装 @forwardpath/node?

在项目目录运行 npm install @forwardpath/node,或使用 pnpm add / yarn add / bun add。

@forwardpath/node 支持 TypeScript 吗?

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

@forwardpath/node 支持 ESM 还是 CommonJS?

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

@forwardpath/node 可以商用吗?

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

@forwardpath/node 的下载量有多少?

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

@forwardpath/node 还在维护吗?

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