@cat-factory/sdk

中文文档
0.68.0发布于 2026/11/04MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 4100

TypeScript/JavaScript client for the cat-factory public API (/api/v1): typed models and resource clients generated from the published OpenAPI spec, over a hand-written fetch transport with bearer auth, bounded retries, keyset auto-pagination and an SSE re

原始使用文档
文档目录7 节
  1. Resource clients
  2. Watching a run
  3. Paging
  4. Errors
  5. Options
  6. Local development and mocks
  7. Notes

@cat-factory/sdk

TypeScript / JavaScript client for the cat-factory public API (/api/v1).

npm install @cat-factory/sdk

Node 20+. No dependencies: the transport is fetch.

import { CatFactoryClient, CatFactoryNotFoundError } from '@cat-factory/sdk'

const client = new CatFactoryClient({
  baseUrl: 'https://cat-factory.example.com',
  apiKey: process.env.CAT_FACTORY_API_KEY!,
})

const { services } = await client.services.list()
const task = await client.tasks.create(services[0].serviceId, {
  title: 'Add a health check endpoint',
  taskType: 'feature',
})
await client.tasks.start(task.taskId, {})

Resource clients

jobs, services, tasks, pipelines, notifications, webhook, usage, decisions, debug: one per tag of the published OpenAPI surface. A workspace-scoped call acts on the key's only workspace, or on workspaceId for a key that reaches several.

Watching a run

const stream = await client.tasks.stream(task.taskId)
try {
  for await (const event of stream) {
    if (event.event === 'decision') {
      // The run PARKED on a human decision and waits indefinitely. Answer it through
      // `client.decisions` (needs a `decide`-scope key) or free it with `tasks.stop`.
      const { decisions } = await client.decisions.list(runId)
    }
    if (event.event === 'done' || event.event === 'error') break
    // `timeout` means the deployment's connection cap was reached, NOT that the run finished.
  }
} finally {
  await stream.close()
}

Paging

Every bounded list has an auto-paging companion that follows nextCursor for you:

for await (const task of client.tasks.listByServiceAll(serviceId)) {
  console.log(task.taskId)
}

Errors

The exception CLASS comes from the HTTP status; code carries the specific cause and is a plain string, because this surface adds new codes without a major version.

try {
  await client.tasks.get(taskId)
} catch (error) {
  if (error instanceof CatFactoryNotFoundError) return null
  if (error instanceof CatFactoryForbiddenError && error.code === 'insufficient_scope') {
    throw new Error('this key needs a higher scope')
  }
  throw error
}

Classes: CatFactoryValidationError (400/422), …Unauthorized (401), …Forbidden (403), …NotFound (404), …Conflict (409), …CredentialRequired (428), …RateLimited (429), …ServerError (5xx), plus …ConnectionError, …TimeoutError and …DecodeError. All extend CatFactoryError. Every API error carries status, code, details, issues and the requestId to quote when reporting a fault.

A CatFactoryConnectionError states what actually failed rather than asserting the deployment was unreachable, and says what this client had already seen from the origin:

cat-factory SDK: POST /api/v1/tasks failed: https://cat-factory.example.com reset the connection
before answering. This client had answered 9 calls against https://cat-factory.example.com, the
last 0.2s ago. (read ECONNRESET)

A reset after nine answered calls is a deployment that restarted; a refusal with nothing answered yet is an address with nothing behind it, and the two send you to completely different places. The runtime's own cause chain is kept verbatim at the end of the message and on cause.

Options

new CatFactoryClient({
  baseUrl,
  apiKey,
  timeoutMs: 30_000, // 0 disables
  maxRetries: 2, // idempotent requests only - a POST is never auto-retried
  headers: {},
  userAgent: 'my-integration/1.2.3',
  fetch: myFetch, // a proxy agent, or a test double
})

Local development and mocks

The base URL takes any origin (http://localhost:8787, a fixture server, a mock) and no scheme validation is applied. Each client also accepts a custom transport, so you can intercept in-process instead. See the SDK guide.

Notes

  • src/*.generated.ts are generated from docs/openapi.json; see ../README.md.
  • The sources are erasable-only TypeScript (no enums, namespaces or parameter properties), so they run under Node's type stripping and erasableSyntaxOnly builds.
  • API reference: backend/docs/public-api.md.

版本与发布记录

@cat-factory/sdk 共发布 82 个版本,首次发布于 2026/08/04;过去 12 个月发布了 82 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.68.0latest2026/11/045 天前
0.67.02026/11/045 天前
0.66.02026/11/045 天前
0.65.02026/11/045 天前
0.64.02026/11/045 天前
0.63.12026/10/1722 天前

关于 @cat-factory/sdk 的常见问题

@cat-factory/sdk 是什么?

TypeScript/JavaScript client for the cat-factory public API (/api/v1): typed models and resource clients generated from the published OpenAPI spec, over a hand-written fetch transport with bearer auth, bounded retries, keyset auto-pagination and an SSE re

如何安装 @cat-factory/sdk?

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

@cat-factory/sdk 支持 TypeScript 吗?

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

@cat-factory/sdk 支持 ESM 还是 CommonJS?

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

@cat-factory/sdk 需要什么版本的 Node.js?

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

@cat-factory/sdk 可以商用吗?

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

@cat-factory/sdk 的下载量有多少?

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

@cat-factory/sdk 还在维护吗?

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