@formbricks/hub

中文文档
0.14.3发布于 2026/11/11Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.4万

The official TypeScript library for the Formbricks Hub API

原始使用文档
文档目录6 节
  1. Usage
  2. Retries and timeouts
  3. Runtime validation
  4. Repeated query parameters
  5. How this package is built
  6. License

@formbricks/hub

The official TypeScript client for the Formbricks Hub API — feedback-record storage, search, enrichment and webhooks.

npm install @formbricks/hub

On Node.js, 22 or later. The client is built on the standard fetch, so it also runs in browsers and Bun. Deno is not supported yet: the generated client passes its client option through to new Request(), which Deno rejects.

Usage

import { createHubClient, listFeedbackRecords } from "@formbricks/hub";

const client = createHubClient({
  apiKey: process.env.HUB_API_KEY!,
  baseUrl: "https://app.formbricks.com", // or your self-hosted Hub
});

const { data } = await listFeedbackRecords({
  client,
  query: {
    tenant_id: "org-123",
    source_type: ["survey", "review"],
    sentiment: ["negative", "very_negative"],
    limit: 50,
  },
});

baseUrl is required rather than defaulted: the Hub is self-hostable, so there is no single correct origin.

Every operation is a standalone function, so bundlers can tree-shake what you don't call. If you need interceptors or extra headers, use the generated client directly — and pass it createHubFetch() to keep the retries described below:

import { createClient, createConfig, createHubFetch } from "@formbricks/hub";

const client = createClient(
  createConfig({ baseUrl, auth: () => apiKey, fetch: createHubFetch() }),
);

Calls return { data, error, response } rather than throwing on an error status; pass throwOnError: true to throw the parsed error body instead. Network failures and timeouts come back in error the same way.

Retries and timeouts

Requests are retried and timed out by default: up to 2 retries, 60 seconds per attempt, exponential backoff with jitter, and a server's Retry-After honoured. A request is only sent again when that cannot apply it twice — with one exception, below the table:

RetriedOn
Any request429; a 408 or 503 with Retry-After; a 409 whose problem code is tenant_write_conflict
GET, HEAD, OPTIONS, PUT, DELETE also500, 502, 504, any other 408 or 503, network errors, timed-out attempts

POST and PATCH are not retried after a 500, 502 or 504, a 408 or 503 without Retry-After, a network error or a timeout, because the Hub may already have applied them. A proxy such as Envoy or Istio answers 503 when its connection to the Hub drops and 408 when its idle timeout fires, either of which can follow a committed write. A create the Hub already applied would come back as a 409 conflict, or — for a webhook — be created twice. Retry those deliberately if your call is safe to repeat, such as a semantic search. Other 4xx responses are never retried, nor is a request you abort, nor a response whose Retry-After asks for more than 60 seconds: that response is returned for you to act on.

A DELETE retried after its response was lost can answer 404: the first attempt already deleted it. The exception is the tenant purge, DELETE /v1/tenants/{tenant_id}/feedback-records: a purge requested after an earlier one finished starts a new run, so if the first purge's response is lost and that purge completes before the retry, the retry also deletes feedback ingested in between. If that matters, call it with maxRetries: 0 and check its progress instead.

If you run the Hub behind your own proxy, don't have it turn upstream errors into 503 with Retry-After — that marks a request the Hub never saw, so POSTs would be re-sent.

const client = createHubClient({
  apiKey,
  baseUrl,
  maxRetries: 4, // 0 turns retries off
  timeout: 10_000, // per attempt, in ms; 0 turns it off
});

The timeout covers each attempt until its body has been read, so a response that stalls mid-body can't hang a call; set timeout: 0 for a long-lived stream. For GET, OPTIONS, PUT and DELETE, while a retry is still possible, a JSON body is read inside the attempt, so one that drops or stalls mid-response is retried like any other failure. A retried response's body is discarded unread, except a 409's, of which up to 64 KB is read for its code. The timeout applies to each attempt separately; to bound a call as a whole, pass a signal, e.g. AbortSignal.timeout(30_000).

Retries live in the client's fetch. A fetch passed per call, or set later with client.setConfig({ fetch }), replaces them unless it is a createHubFetch() itself.

Runtime validation

Zod schemas for every request and response shape — carrying the spec's own minLength, maxLength, pattern and enum constraints — are available from a separate entry point, so importing the client itself pulls in no dependencies:

import { zFeedbackRecordData } from "@formbricks/hub/schemas";

zod is an optional peer dependency; install it only if you use this entry point.

Repeated query parameters

Array filters are sent as repeated parameters (?source_type=survey&source_type=review), which is what the Hub expects — it does not split comma-separated values. Pass arrays and the client does the right thing.

How this package is built

It is generated from openapi.yaml in the Hub repository by @hey-api/openapi-ts, and published from that repository on every stable Hub release with npm provenance. Its version is the Hub release's: @formbricks/[email protected] is the client for Hub 0.14.0, so pin the SDK to the Hub version you run. The generated source is not committed — this tarball ships it under src/, and the provenance attestation names the exact commit it came from, so you can regenerate and compare.

To report a problem or request a change to the API surface, open an issue in formbricks/hub.

License

Apache-2.0

版本与发布记录

@formbricks/hub 共发布 21 个版本,首次发布于 2026/02/18;过去 12 个月发布了 21 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.14.3latest2026/11/114 天前
0.14.22026/11/069 天前
0.14.12026/10/2125 天前
0.14.02026/10/121 个月前
0.13.02026/08/272 个月前
0.12.02026/08/123 个月前

关于 @formbricks/hub 的常见问题

@formbricks/hub 是什么?

The official TypeScript library for the Formbricks Hub API

如何安装 @formbricks/hub?

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

@formbricks/hub 支持 TypeScript 吗?

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

@formbricks/hub 支持 ESM 还是 CommonJS?

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

@formbricks/hub 需要什么版本的 Node.js?

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

@formbricks/hub 可以商用吗?

@formbricks/hub 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@formbricks/hub 的下载量有多少?

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

@formbricks/hub 还在维护吗?

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