Package Exports
- @appthreat/cdx-proto
- @appthreat/cdx-proto/v1.5
- @appthreat/cdx-proto/v1.6
- @appthreat/cdx-proto/v1.7
Readme
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, andv1.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 matchingBomSchemafor CycloneDX1.5,1.6, or1.7.createBom(specVersion, init)creates a BOM message and automatically setsspecVersion.parseBomJson(json)andparseBomJsonString(json)auto-detect the schema fromspecVersion/spec_version.decodeBomBinary(specVersion, bytes)decodes a protobuf BOM when the schema version is known.encodeBomBinary(bom),encodeBomJson(bom), andencodeBomJsonString(bom)choose the correct schema from the BOM itself.
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