--- title: SBOM --- ```js import {API} from "./components/config.js"; ``` ```js // Fetch SBOM data on load let _entries = [], _report = {groups: [], copyleft_direct_count: 0}, _repos = [], _domains = [], _snapshots = []; try { [_entries, _report, _repos, _domains, _snapshots] = await Promise.all([ fetch(`${API}/sbom/`).then(r => r.ok ? r.json() : []), fetch(`${API}/sbom/report/licences/`).then(r => r.ok ? r.json() : {groups:[], copyleft_direct_count: 0}), fetch(`${API}/repos/`).then(r => r.ok ? r.json() : []), fetch(`${API}/domains/`).then(r => r.ok ? r.json() : []), fetch(`${API}/sbom/snapshots/`).then(r => r.ok ? r.json() : []), ]); } catch {} ``` ```js const entries = _entries ?? []; const report = _report ?? {groups: [], copyleft_direct_count: 0}; const repos = _repos ?? []; const domains = _domains ?? []; const snapshots = _snapshots ?? []; const groups = report.groups ?? []; const riskCount = report.copyleft_direct_count ?? 0; // Domain + repo lookups const domainById = Object.fromEntries(domains.map(d => [d.id, d])); const repoById = Object.fromEntries(repos.map(r => [r.id, r])); const repoDomain = Object.fromEntries(repos.map(r => [r.id, domainById[r.domain_id]?.slug ?? "—"])); const domainSlugs = [...new Set(repos.map(r => repoDomain[r.id]).filter(s => s !== "—"))].sort(); // Copyleft detector (mirrors server-side logic) const COPYLEFT_KW = ["GPL", "AGPL", "LGPL", "EUPL", "CDDL", "MPL"]; const isCopyleft = spdx => spdx && COPYLEFT_KW.some(k => spdx.toUpperCase().includes(k)); ``` # SBOM ```js import {withDocHelp} from "./components/doc-overlay.js"; const _h1 = document.querySelector("#observablehq-main h1"); if (_h1) { _h1.style.position = "relative"; withDocHelp(_h1, "/docs/sbom"); } ``` ## Overview ```js const riskBadge = riskCount === 0 ? html`✓ No copyleft in direct prod deps` : html`⚠ ${riskCount} direct prod dep(s) with copyleft licence`; display(html`
${entries.length}
${new Set(entries.map(e => e.repo_id)).size}
${domainSlugs.length || new Set(Object.values(repoDomain).filter(s => s !== "—")).size}
${riskCount}
${riskBadge}${groups.length}
No SBOM data ingested yet. Run make ingest-sbom REPO=<slug> SCAN=1 REPO_PATH=<path>.
No SBOM data ingested yet.
`); } else { const plotData = groups.slice(0, 15).map(g => ({ licence: g.license_spdx ?? "(unknown)", count: g.count, copyleft: g.is_copyleft, })); display(Plot.plot({ x: {label: "Packages"}, y: {label: null, domain: plotData.map(d => d.licence)}, color: {domain: [false, true], range: ["steelblue", "#e53935"], legend: true, tickFormat: d => d ? "Copyleft" : "Permissive"}, marks: [ Plot.barX(plotData, {y: "licence", x: "count", fill: "copyleft", tip: true}), Plot.ruleX([0]), ], marginLeft: 130, height: Math.max(80, plotData.length * 30 + 50), width: 600, })); } ``` ## Copyleft Risk Detail ```js const copyleftGroups = groups.filter(g => g.is_copyleft); if (copyleftGroups.length === 0) { display(html`✓ No copyleft packages found.
`); } else { display(html`Note: dual-licensed packages (e.g. "MIT OR GPL-3.0") are flagged conservatively. Review if the non-copyleft variant is used.
`); } ``` ## By Repo ```js // Group entries by repo, sorted by domain then repo name const byRepo = {}; for (const e of entries) { (byRepo[e.repo_id] = byRepo[e.repo_id] ?? []).push(e); } const repoSections = Object.entries(byRepo) .map(([repoId, es]) => { const repo = repoById[repoId]; const domSlug = repoDomain[repoId] ?? "—"; const dom = domains.find(d => d.slug === domSlug); const directProd = es.filter(e => e.is_direct && !e.is_dev); const copyleftRisk = directProd.filter(e => isCopyleft(e.license_spdx)).length; const ecosystems = [...new Set(es.map(e => e.ecosystem))].sort(); return { repoId, repo, dom, domSlug, es, directProd, copyleftRisk, ecosystems }; }) .sort((a, b) => (a.domSlug + a.repo?.slug).localeCompare(b.domSlug + b.repo?.slug)); if (repoSections.length === 0) { display(html`No repo data.
`); } else { display(html`Showing first 200 of ${es.length}
` : ""}No snapshots recorded yet.
`); } else { // Group by repo, sort newest first within each group const snapByRepo = {}; for (const s of snapshots) { (snapByRepo[s.repo_id] = snapByRepo[s.repo_id] ?? []).push(s); } const repoOrder = Object.keys(snapByRepo).sort((a, b) => { const ra = repos.find(r => r.id === a); const rb = repos.find(r => r.id === b); return (ra?.slug ?? a).localeCompare(rb?.slug ?? b); }); display(html`