@forwardpath/node

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

Server-side client that mints ForwardPath intake sessions.

原始使用文档
文档目录5 节
  1. Install
  2. Verify users with createUserHash
  3. Keep your API key on the server
  4. Next.js route
  5. Minting a session yourself

@forwardpath/node

Server-side helpers for the ForwardPath intake API. Use it to sign users for publishable-key sessions with createUserHash, or to mint short-lived intake sessions with your secret API key, so the key never reaches the browser. It ships a ready-made route handler for Next.js App Router (or any runtime with web Request/Response).

Install

npm install @forwardpath/node

Verify users with createUserHash

With a publishable key, the browser mints its own sessions and names the user. Without proof, ForwardPath marks that user claimed, i.e. unverified. To mark them verified, sign the user on your server with the key's identity secret (fpiv_…, shown once when you create the key) and pass the hash to the browser.

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}>

The hash is lowercase hex HMAC-SHA256 of JSON.stringify([id, email]), with the id trimmed and the email trimmed and lowercased (null when absent). It signs the id and email, not the name. The browser must send the same id and email, or the session fails with a 401. createUserHash throws in a browser or if the secret doesn't start with fpiv_. Keep the secret in a server-only env var.

Keep your API key on the server

Your API key (fp_<keyId>.<secret>) can mint sessions for any user. Store it in a server-only env var. createForwardPathClient throws if it runs in a browser or if the key is malformed. The route handler responds with only the session token and its expiry, never the key.

Next.js route

// 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,
    };
  },
});

The browser calls it with POST /api/forwardpath/session and gets back { token, expiresAt }. Pass the token to @forwardpath/js or @forwardpath/react. The body may carry { clientContext } (e.g. from collectClientContext()); the handler forwards it to ForwardPath.

Handler responses:

StatusWhen
200{ token, expiresAt }
400Body isn't a JSON object, or ForwardPath rejected the payload
401getUser returned null
502ForwardPath failed for another reason (e.g. bad API key)

Minting a session yourself

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 }

A non-2xx response rejects with ForwardPathApiError (re-exported from @forwardpath/js), which has status, code and 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 是什么?

Server-side client that mints ForwardPath intake sessions.

如何安装 @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 和提交记录判断。