dazn-commerce-contracts

中文文档
2.108.0发布于 2026/11/03UNLICENSEDTypeScriptCommonJS

Single source of truth for the DAZN commerce /v1 wire format: Zod schemas → types → OpenAPI 3.1 → typed client. Published to a private registry.

原始使用文档
文档目录6 节
  1. Install
  2. Use the schemas and types
  3. Use the typed client
  4. OpenAPI
  5. Golden rules
  6. Scripts

dazn-commerce-contracts

The single source of truth for the DAZN commerce /v1 wire format.

Zod schemas → inferred TypeScript types → generated OpenAPI 3.1 and a typed client. Published (semver) to a private registry and consumed by dazn-commerce-engine and dazn-storefront. If it goes over the wire, it is defined here.

Install

Configure the @dazn scope to the private registry (see .npmrc), then:

pnpm add dazn-commerce-contracts

Use the schemas and types

import { Money, Cart, OrderDetail, OrderStatus, parseOr } from 'dazn-commerce-contracts';

const price: Money = { amount: 2500, currency: 'GBP' }; // £25.00
const cart = Cart.parse(await res.json()); // validated at the boundary

Every schema is exported alongside its inferred type under the same name — Cart is both the Zod schema (a value) and the Cart type.

Use the typed client

import { createClient } from 'dazn-commerce-contracts/client';

const api = createClient({
  baseUrl: 'https://storefront.example.com/v1',
  getToken: () => session.token,
});

const { data } = await api.catalog.listProducts({ limit: 20 });
const order = await api.orders.get('ord_01H9Z...'); // OrderDetail, validated

The client validates every response with the schemas and throws a typed DaznApiError (carrying the standard error code) on a non-2xx response.

OpenAPI

The generated OpenAPI 3.1 document is published at dazn-commerce-contracts/openapi.json and served by the engine at /v1/openapi.json.

Golden rules

  • Money is always integer minor units + ISO-4217 — never a float, never a bare number.
  • /v1 is additive-only. A breaking change is a new major version and a new API version namespace.

Scripts

pnpm build      # dist/ + client/ + openapi/openapi.json
pnpm test       # schema round-trip tests
pnpm lint       # ESLint
pnpm typecheck  # tsc --noEmit (strict)

版本与发布记录

dazn-commerce-contracts 共发布 41 个版本,首次发布于 2026/09/01;过去 12 个月发布了 41 个版本。

版本发布日期距今
2.108.0latest2026/11/03今天
2.107.02026/11/021 天前
2.106.02026/10/313 天前
2.105.02026/10/286 天前
2.104.02026/10/286 天前
2.101.02026/10/2212 天前

关于 dazn-commerce-contracts 的常见问题

dazn-commerce-contracts 是什么?

DAZN commerce /v1连接格式的单一事实来源:Zod模式→类型→OpenAPI 3.1→类型化客户端。发布到私有注册中心。

如何安装 dazn-commerce-contracts?

在项目目录运行 npm install dazn-commerce-contracts,或使用 pnpm add / yarn add / bun add。

dazn-commerce-contracts 支持 TypeScript 吗?

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

dazn-commerce-contracts 支持 ESM 还是 CommonJS?

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

dazn-commerce-contracts 需要什么版本的 Node.js?

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

dazn-commerce-contracts 可以商用吗?

dazn-commerce-contracts 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

dazn-commerce-contracts 还在维护吗?

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