@cat-factory/sdk
用于 Cat- 构件的 TypeScript / JavaScript 客户端 公开 API (单位:千美元)/api/v1) (中文(简体) ).
npm install @cat-factory/sdk
节点20+. 无依赖关系:运输是 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, {})
资源客户
jobs, (中文(简体) ), services, (中文(简体) ), tasks, (中文(简体) ), pipelines, (中文(简体) ), notifications, (中文(简体) ), webhook, (中文(简体) ), usage, (中文(简体) ), decisions, (中文(简体) ),
debug数字 :
已公布的 OpenAPI 表面的每个标签 。 工作空间范围呼叫在键唯一的工作空间上,或者在 workspaceId 对于一个键 达到数.
看着跑步
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()
}
拨号
每个被绑定的列表都有一个自动显示的伴奏 nextCursor 为你:
for await (const task of client.tasks.listByServiceAll(serviceId)) {
console.log(task.taskId)
}
错误
例外的CLAS来自HTTP状态; code 带着具体事业,是平地
字符串,因为这个表面添加了没有主要版本的新代码.
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
}
类 : CatFactoryValidationError (400/422) (中文(简体) ), …Unauthorized (401个), …Forbidden (403个),
…NotFound (404个), …Conflict (409个), …CredentialRequired (428个), …RateLimited (429个),
…ServerError (5xx),加上: …ConnectionError, (中文(简体) ), …TimeoutError 财务报告和审定财务报表 …DecodeError全部扩展
CatFactoryError。每个 API 错误都包含 status, (中文(简体) ), code, (中文(简体) ), details, (中文(简体) ), issues 编辑
requestId 在报告过失时引用.
A 类 CatFactoryConnectionError 说明实际失败,而不是声称部署
无法接触,并说出这个客户已经从来源看到的东西:
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)
在九次接通电话后重设是重新启动的部署;拒绝无一答复
却是一个没有背后的地址 两个人把你送到完全不同的地方 这个
运行时间本身的起因链在消息的结尾和运行时保持逐字记录 cause。 。 。 .
选项
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
})
地方发展和嘲笑
基础 URL 具有任何来源( Namehttp://localhost:8787,固定服务器,模拟器),没有方案
进行验证。 每个客户端也接受自定义运输,这样您就可以在进程内拦截
换句话说 见 sDK 指南。 。 。 .
页:1
src/*.generated.ts从docs/openapi.json; 见../README.md。 。 。 .- 来源是 仅可删除 TypeScript (没有enum, 命名空间或参数属性), 所以
他们运行在节点的类型剥离和
erasableSyntaxOnly建设. - API 参考 :
backend/docs/public-api.md。 。 。 .