@forteplatforms/sdk

中文文档
1.0.536发布于 2026/11/16MITTypeScriptCommonJS零依赖近 30 天下载 4624

Official TypeScript SDK for Forte Platforms

原始使用文档
文档目录13 节
  1. Installation
  2. Authentication
  3. Inside a Forte-hosted service (no config)
  4. Client-side (browser / mobile)
  5. Server-side BFF calling client.users.* (no token, per-call …
  6. External server-side calling client.projects.* (explicit to…
  7. Quick Start
  8. Error Handling
  9. User Custom Attributes
  10. Merge with existing attributes
  11. API Reference
  12. client.projects
  13. client.users

Forte Platforms TypeScript SDK

Official TypeScript SDK for interacting with the Forte Platforms API.

Installation

npm install @forteplatforms/sdk

Authentication

The SDK supports three auth modes depending on where it runs.

Inside a Forte-hosted service (no config)

FORTE_API_TOKEN is set automatically and scoped to the service's project:

const client = new ForteClient();

Client-side (browser / mobile)

For calls to client.users.*, construct with no arguments. The browser sends the Forte-User-Session-Token cookie automatically after the user logs in. The SDK sets credentials: 'include' so the cookie reaches the API cross-origin.

const client = new ForteClient();
await client.users.renewSessionToken({ projectId });

Do not pass apiToken from browser code — it's a server-side secret.

Server-side BFF calling client.users.* (no token, per-call authorization)

In a BFF that proxies user-scoped calls, omit the token and forward each user's session token as the authorization parameter on each call:

const client = new ForteClient();
await client.users.renewSessionToken({
  projectId,
  authorization: `Bearer ${userSessionToken}`,
});

External server-side calling client.projects.* (explicit token)

const client = new ForteClient({ apiToken: 'your_api_token_here' });

Or set FORTE_API_TOKEN in the environment (Node.js only) and call new ForteClient().

You can generate an API token from the Forte Platforms dashboard.

Quick Start

import { ForteClient } from '@forteplatforms/sdk';

const client = new ForteClient();

// List your projects
const projects = await client.projects.listProjects();

// Get a specific project
const project = await client.projects.getProject({ projectId: 'your-project-id' });

Error Handling

API errors are thrown as exceptions with HTTP status information:

try {
  const project = await client.projects.getProject({ projectId: 'invalid-id' });
} catch (error) {
  console.error('API error:', error);
}

User Custom Attributes

Store arbitrary key-value metadata on your users. Useful for tracking subscription tiers, feature flags, preferences, or any application-specific data.

// Set custom attributes on a user
const user = await client.projects.putUserCustomAttributes({
  projectId: 'your-project-id',
  userId: 'user-id',
  requestBody: {
    plan: 'pro',
    referral_source: 'google',
    onboarding_completed: 'true',
  },
});

console.log(user.customMetadataAttributes);
// { plan: 'pro', referral_source: 'google', onboarding_completed: 'true' }

Key constraints:

  • Keys must be 1-64 characters: letters, numbers, underscores, and hyphens only
  • Values are strings
  • Each call replaces all existing attributes — include any you want to keep

Merge with existing attributes

// Read current attributes, then merge
const user = await client.projects.getProjectUser({
  projectId: 'your-project-id',
  userId: 'user-id',
});

await client.projects.putUserCustomAttributes({
  projectId: 'your-project-id',
  userId: 'user-id',
  requestBody: {
    ...user.customMetadataAttributes,
    plan: 'enterprise', // update one field
  },
});

API Reference

client.projects

Manage projects and services on Forte Platforms.

client.users

Manage end-users within your projects.

版本与发布记录

@forteplatforms/sdk 共发布 112 个版本,首次发布于 2026/03/19;过去 12 个月发布了 112 个版本。

版本发布日期距今
1.0.536latest2026/11/16今天
1.0.5352026/11/132 天前
1.0.5282026/11/0511 天前
1.0.5272026/11/0511 天前
1.0.5262026/11/0312 天前
1.0.5252026/11/0312 天前

关于 @forteplatforms/sdk 的常见问题

@forteplatforms/sdk 是什么?

Official TypeScript SDK for Forte Platforms

如何安装 @forteplatforms/sdk?

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

@forteplatforms/sdk 支持 TypeScript 吗?

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

@forteplatforms/sdk 支持 ESM 还是 CommonJS?

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

@forteplatforms/sdk 可以商用吗?

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

@forteplatforms/sdk 的下载量有多少?

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

@forteplatforms/sdk 还在维护吗?

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