@tracepass/dpp-types

中文文档
0.19.0发布于 2026/11/03Apache-2.0TypeScriptES Module零依赖构建来源已验证

TypeScript types for EU Digital Product Passports (ESPR) — templates, passports, parties, and traceability events. Types only, zero runtime, zero dependencies.

原始使用文档
文档目录5 节
  1. Identifiers are opaque
  2. Product and operator identifiers (EN 18219)
  3. Types model the file, not the database
  4. Related
  5. License
TracePass

@tracepass/dpp-types

TypeScript types for EU Digital Product Passports. Types only — compiles to nothing.

License Dependencies

Part of tracepass-open · Maintained by TracePass


Shared types for a Digital Product Passport under the EU's Ecodesign for Sustainable Products Regulation, (EU) 2024/1781: the category Template (its field spec), the filled-in Passport, the economic-operator Party, and traceability events.

npm install --save-dev @tracepass/dpp-types
import type { Template, Passport, TemplateField } from "@tracepass/dpp-types";

Identifiers are opaque

Id is a string. Nothing in these packages parses it, so a passport that came from any database or a JSON file works unchanged. Storage engines disagree about what an id is; the passport logic doesn't need to care.

Product and operator identifiers (EN 18219)

Passport.identifier carries a ProductIdentifier — a discriminated union over the five schemes EN 18219 defines for Digital Product Passports:

import type { ProductIdentifier, OperatorIdentifier, FacilityIdentifier } from "@tracepass/dpp-types";

// GS1 Digital Link (scheme 1)
const gs1: ProductIdentifier = { scheme: "gs1", gtin: "05449000000996", serialNumber: "SN-001" };

// ISO/IEC 15459 — any issuing agency (scheme 1)
const iso: ProductIdentifier = { scheme: "iso15459", issuingAgencyCode: "MH", primaryId: "BAT-001", raw: "MHBAT-001" };

// IEC 61406 digital nameplate URL (scheme 2)
const iec: ProductIdentifier = { scheme: "iec61406", uri: "https://id.example.com/asset/42" };

// W3C Decentralised Identifier (scheme 3)
const did: ProductIdentifier = { scheme: "did", method: "web", did: "did:web:example.com" };

// DOI (scheme 5)
const doi: ProductIdentifier = { scheme: "doi", doi: "10.1234/my-passport", granularity: "model" };

Party.operatorIdentifier carries a single OperatorIdentifier — ISO 6523 (LEI, GLN via icd 0088, DUNS), standalone GLN (scheme "gln"), DID, or DOI. Party.facilityIdentifier carries a FacilityIdentifier with the same four schemes (6–9) plus an optional GLN extension component for sub-locations. Both are optional; the legacy gln and legacyOperatorId fields remain for backward compatibility.

The legacy Passport.gs1 field is still present but @deprecated — use identifier: { scheme: "gs1", ... } instead.

Validation is in @tracepass/dpp-identifiers.

Types model the file, not the database

Template describes the shape of a published template JSON file. It deliberately has no _id, no createdAt, and its regulation.effectiveDate is an ISO date string, not a Date — because that is what's actually in the file. JSON.parse(readFileSync(...)) type-checks without a cast.

Optional values are T | null, not omitted. A field with no unit carries unit: null; a bound that doesn't apply carries max: null. Treat null as no constraint — and take care not to coerce it to 0.

License

Apache-2.0

版本与发布记录

@tracepass/dpp-types 共发布 28 个版本,首次发布于 2026/07/20;过去 12 个月发布了 28 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.0latest2026/11/03今天
0.18.42026/10/303 天前
0.18.32026/10/304 天前
0.18.22026/10/304 天前
0.18.12026/10/304 天前
0.18.02026/10/295 天前

关于 @tracepass/dpp-types 的常见问题

@tracepass/dpp-types 是什么?

欧盟数字产品护照(ESPR)的TypeScript类型——模板、护照、当事人和可追溯性事件。只有类型,零运行时,零依赖。

如何安装 @tracepass/dpp-types?

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

@tracepass/dpp-types 支持 TypeScript 吗?

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

@tracepass/dpp-types 支持 ESM 还是 CommonJS?

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

@tracepass/dpp-types 需要什么版本的 Node.js?

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

@tracepass/dpp-types 可以商用吗?

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

@tracepass/dpp-types 还在维护吗?

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