@codespar/api-types

中文文档
0.5.0发布于 2026/05/07MITTypeScriptES Module近 30 天下载 3221

Shared REST wire contract for the CodeSpar managed-tier API (api.codespar.dev) — Zod schemas + inferred TypeScript types

原始使用文档
文档目录8 节
  1. Why
  2. Usage
  3. Coverage
  4. auth_type enum
  5. What's new in 0.4.0
  6. Versioning
  7. Need more?
  8. License

@codespar/api-types

Shared REST wire contract for the CodeSpar managed-tier API at api.codespar.dev.

Every request body and response shape is defined once, as a Zod schema, and the matching TypeScript type is inferred from it. Both the backend (codespar-enterprise) and the dashboard (codespar-web) import from here — no more hand-rolled mirror types.

Why

Two bugs shipped in a 48-hour window because web and backend independently redeclared the same response types:

  • Newly-created API keys rendered as "Revoked" (revoked_at omitted on the create response, web type assumed present, undefined !== null was truthy).
  • API-key list came back empty (backend returns { keys: [...] }, web parsed data.api_keys).

Schemas here are the single source of truth. Parse responses at the fetch boundary and these failures become impossible — missing/renamed fields throw at runtime instead of rendering broken UI.

Usage

import {
  ApiKeyRowSchema,
  ListApiKeysResponseSchema,
  type ListApiKeysResponse,
} from "@codespar/api-types";

const res = await fetch("/v1/api-keys", { headers: { authorization: `Bearer ${token}` } });
const body: ListApiKeysResponse = ListApiKeysResponseSchema.parse(await res.json());
//    ^^^^ throws ZodError if the backend drifts

Every module exports both the schema (FooSchema) and the inferred type (Foo). Import whichever side you need.

Coverage

  • api-keys — create / list / row
  • projects — create / update / list / row
  • connections — create / list / row / webhook-secret rotation
  • servers — list / row / auth-schema
  • sessions — create / list / row / detail / tool-calls / execute

auth_type enum

A connection's auth_type determines how credentials are stored and forwarded to the upstream provider. As of 0.4.0 the enum has six values:

ValueUsed by
api_keyMost providers — Asaas, Mercado Pago, NFe.io, Stripe, etc.
path_secretZ-API-style providers that embed credentials in the URL path with a companion header.
oauthProviders requiring an OAuth flow (e.g. user-authorized integrations).
certmTLS — BR open-banking pilots (BB live; Itaú / Santander / Bradesco / Caixa next).
hmac_signedFoxbit + LATAM crypto exchanges that sign each request with a derived HMAC.
nonePublic APIs / no credentials.

What's new in 0.4.0

Adds the cert and hmac_signed auth_type values to the connection schemas — the contract now covers BR open-banking mTLS pilots and HMAC-signed crypto exchange APIs alongside the original four.

Known limitation. AuthSchemaFieldKindSchema (the kind enum for individual fields inside an auth schema) does NOT yet include hmac — only the connection-level auth_type enum does. The dashboard's ProviderConnectModal works around this by tagging HMAC-signed fields as path_secret kind. Consumers reading auth schemas directly should expect this mismatch until a future minor bump tightens the field-kind enum.

Versioning

  • This package mirrors the /v1/* REST surface of api.codespar.dev.
  • Additive changes (new field, new endpoint schema) → minor bump.
  • Breaking changes (field removed, type narrowed) → major bump, shipped alongside a matching backend release.

Keep TS + Python + backend aligned — drift is the loudest way to break trust.

Need more?

Need governance, budget limits, and audit trails for agent payments? CodeSpar Enterprise adds policy engine, payment routing, and compliance templates on top of these MCP servers.

License

MIT — codespar.dev

版本与发布记录

@codespar/api-types 共发布 5 个版本,首次发布于 2026/04/24;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.5.0latest2026/05/076 个月前
0.4.02026/05/056 个月前
0.3.02026/05/016 个月前
0.2.02026/04/296 个月前
0.1.02026/04/246 个月前

关于 @codespar/api-types 的常见问题

@codespar/api-types 是什么?

Shared REST wire contract for the CodeSpar managed-tier API (api.codespar.dev) — Zod schemas + inferred TypeScript types

如何安装 @codespar/api-types?

在项目目录运行 npm install @codespar/api-types,或使用 pnpm add / yarn add / bun add。

@codespar/api-types 支持 TypeScript 吗?

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

@codespar/api-types 支持 ESM 还是 CommonJS?

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

@codespar/api-types 需要什么版本的 Node.js?

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

@codespar/api-types 可以商用吗?

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

@codespar/api-types 的下载量有多少?

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

@codespar/api-types 还在维护吗?

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