@appthreat/cdx-proto

中文文档
2.0.1发布于 2026/05/14Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 69.5万

Library to serialize/deserialize CycloneDX BOM with protocol buffers

原始使用文档
文档目录6 节
  1. 2.0.0 highlights
  2. Sample usage
  3. Helper API
  4. Canonical JSON guarantees
  5. Version-specific imports
  6. License

cdx-proto

Runtime library to serialize/deserialize CycloneDX BOM with protocol buffers. The project was generated using protoc-gen-es from the official proto specification.

2.0.0 highlights

  • version-specific subpath exports: @appthreat/cdx-proto/v1.5, v1.6, and v1.7
  • helper APIs for schema selection and BOM encode/decode workflows
  • leaner npm package contents that no longer publish generated docs/

Sample usage

import {
  createBom,
  decodeBomBinary,
  encodeBomBinary,
  encodeBomJson,
  getBomSchema,
  parseBomJson,
} from "@appthreat/cdx-proto";
import { BomSchema as BomSchema16 } from "@appthreat/cdx-proto/v1.6";
import { fromJson } from "@bufbuild/protobuf";

// Use version-specific entrypoints when you only need one schema version.
const bom16 = fromJson(BomSchema16, {
  specVersion: "1.6",
  version: 1,
});

// Or use the helper API to auto-select schemas and encode/decode BOMs.
const bom = createBom("1.7", {
  version: 1,
  serialNumber: "urn:uuid:11111111-1111-1111-1111-111111111111",
});

const binary = encodeBomBinary(bom, {
  writeUnknownFields: true,
});

const decoded = decodeBomBinary("1.7", binary, {
  readUnknownFields: true,
});

const json = encodeBomJson(decoded, {
  alwaysEmitImplicit: true,
});

const parsed = parseBomJson({
  specVersion: "1.6",
  version: 1,
});

const schema = getBomSchema(parsed.specVersion);

Helper API

  • getBomSchema(specVersion) returns the matching BomSchema for CycloneDX 1.5, 1.6, or 1.7.
  • createBom(specVersion, init) creates a BOM message and automatically sets specVersion.
  • parseBomJson(json) and parseBomJsonString(json) auto-detect the schema from specVersion / spec_version.
  • decodeBomBinary(specVersion, bytes) decodes a protobuf BOM when the schema version is known.
  • encodeBomBinary(bom), encodeBomJson(bom), and encodeBomJsonString(bom) choose the correct schema from the BOM itself.

Canonical JSON guarantees

The helper layer is designed to work with canonical CycloneDX JSON rather than protobuf-flavored JSON.

  • parseBomJson() and decodeBomJson() accept canonical CycloneDX input such as:
    • root fields like bomFormat and specVersion
    • dashed aliases such as bom-ref, mime-type, and x-trust-boundary
    • canonical hash content fields like hashes[].content
    • canonical standards/declarations objects instead of protobuf list wrappers
  • Undefined object properties and undefined array entries are sanitized before protobuf parsing so callers can pass ordinary JavaScript objects without manually stripping undefined values first.
  • encodeBomJson() and encodeBomJsonString() restore canonical CycloneDX JSON on output, including:
    • bomFormat: "CycloneDX"
    • the BOM specVersion
    • canonical enum values instead of protobuf enum names such as CLASSIFICATION_*, HASH_ALG_*, or EXTERNAL_REFERENCE_TYPE_*
    • canonical object shapes for definitions and declarations
  • parseBomBinary() auto-detects the embedded supported schema version (1.5, 1.6, or 1.7) and can be paired with encodeBomJson() to read protobuf BOMs back as canonical CycloneDX JSON.

In short: if you provide canonical CycloneDX JSON to the helper API, you should get canonical CycloneDX JSON back after binary or message round-trips.

Version-specific imports

Use subpath exports to avoid loading schema versions you do not need:

import { BomSchema as BomSchema15 } from "@appthreat/cdx-proto/v1.5";
import { BomSchema as BomSchema16 } from "@appthreat/cdx-proto/v1.6";
import { BomSchema as BomSchema17 } from "@appthreat/cdx-proto/v1.7";

License

Apache-2.0

版本与发布记录

@appthreat/cdx-proto 共发布 15 个版本,首次发布于 2023/12/24;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.1latest2026/05/145 个月前
2.0.02026/05/145 个月前
1.3.02026/04/176 个月前
1.2.12026/01/289 个月前
1.2.02025/11/1911 个月前
1.1.42025/08/071.2 年前

关于 @appthreat/cdx-proto 的常见问题

@appthreat/cdx-proto 是什么?

Library to serialize/deserialize CycloneDX BOM with protocol buffers

如何安装 @appthreat/cdx-proto?

在项目目录运行 npm install @appthreat/cdx-proto,或使用 pnpm add / yarn add / bun add。

@appthreat/cdx-proto 支持 TypeScript 吗?

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

@appthreat/cdx-proto 支持 ESM 还是 CommonJS?

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

@appthreat/cdx-proto 需要什么版本的 Node.js?

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

@appthreat/cdx-proto 可以商用吗?

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

@appthreat/cdx-proto 的下载量有多少?

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

@appthreat/cdx-proto 还在维护吗?

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