Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/bom/validation.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { SPDX23 } from '../types/bom/spdx-2.3.schema.ts';
import type { CdxBom, SupportedBom } from '../types/index.mjs';

function parseBomOrString(bomOrString: string | object): SupportedBom | null {
if (typeof bomOrString === 'string') {
try {
return JSON.parse(bomOrString);
} catch (e) {
return null;
}
}
return bomOrString as SupportedBom;
}

export function isCdxBom(bomOrString: string | object): bomOrString is CdxBom {
const bom = parseBomOrString(bomOrString);
return (
bom !== null &&
'components' in bom &&
'bomFormat' in bom &&
bom.bomFormat === 'CycloneDX'
);
}

export function isSpdxBom(bomOrString: string | object): bomOrString is SPDX23 {
const bom = parseBomOrString(bomOrString);
return bom !== null && 'SPDXID' in bom && bom.SPDXID === 'SPDXRef-Document';
}

export function isSupportedBom(
bomOrString: string | object,
): bomOrString is SupportedBom {
return isCdxBom(bomOrString) || isSpdxBom(bomOrString);
}
3 changes: 3 additions & 0 deletions src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export type {
ExternalReference,
Hash,
License,
SPDX23,
SupportedBom,
} from './types/index.mjs';

export { ComponentScope } from './types/index.mjs';
export { isCdxBom, isSpdxBom, isSupportedBom } from './bom/validation.mjs';
2 changes: 1 addition & 1 deletion src/types/eol-scan.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface EolReport {
}

export interface EolReportQueryResponse {
eol: { report: { result: EolReport | null } };
eol: { report: { report: EolReport | null } };
}

export interface EolReportMutationResponse {
Expand Down
4 changes: 4 additions & 0 deletions src/types/index.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as CDX from '@cyclonedx/cyclonedx-library';
import type { SPDX23 } from './bom/spdx-2.3.schema.ts';

export type CdxBom = CDX.Serialize.JSON.Types.Normalized.Bom;
export type Component = CDX.Serialize.JSON.Types.Normalized.Component;
Expand All @@ -8,4 +9,7 @@ export type License = CDX.Serialize.JSON.Types.Normalized.License;
export type ExternalReference =
CDX.Serialize.JSON.Types.Normalized.ExternalReference;

export type { SPDX23 };
export type SupportedBom = CdxBom | SPDX23;

export const ComponentScope = CDX.Enums.ComponentScope;