import { SecurityCard, ReachabilityAnswer, SecurityScanResult, SecurityDiff, SecurityFixAction } from '@neat.is/types'; import { N as NeatGraph } from './graph-CUsxjbKt.js'; import 'graphology'; type ChangeStatus = 'modified' | 'new' | 'removed'; interface ChangedSymbol { symbol: string; file: string; kind: string; status: ChangeStatus; namedInAdvisory: boolean; } interface FixDiff { from: string; to: string; changed: ChangedSymbol[]; } type SeverityLabel = 'critical' | 'high' | 'moderate' | 'low' | 'unknown'; interface AffectedRange { type: 'SEMVER' | 'ECOSYSTEM' | 'GIT'; events: Array<{ introduced?: string; fixed?: string; last_affected?: string; limit?: string; }>; } interface AffectedPackage { ecosystem: string; name: string; ranges: AffectedRange[]; versions?: string[]; symbols?: string[]; } interface Advisory { id: string; aliases: string[]; summary: string; details: string; severity: { cvss?: string; label: SeverityLabel; }; cwe: string[]; published?: string; modified: string; affected: AffectedPackage[]; fixRefs: string[]; fixDiff?: FixDiff; } interface AdvisorySnapshot { asOf: string; advisories: Advisory[]; } interface AdvisoryMatch { advisoryId: string; dependencyId: string; fixedIn: string[]; asOf: string; } /** * The card for one advisory match in one service, or null when the service * doesn't depend on that version or the advisory isn't in the snapshot. */ declare function buildSecurityCard(graph: NeatGraph, match: AdvisoryMatch, snapshot: AdvisorySnapshot, serviceId: string): SecurityCard | null; /** One card per service that depends on the matched version, in service-id order. */ declare function buildSecurityCards(graph: NeatGraph, match: AdvisoryMatch, snapshot: AdvisorySnapshot): SecurityCard[]; /** The highest ladder step among `cards`, or null for none. */ declare function highestLevel(cards: SecurityCard[]): SecurityCard['reachability']['level'] | null; /** * Ranking (security-card.md ยง5): level, then severity, then direct before * transitive, then card id so the order is total. A new array; the input is * untouched. Callers keep `present` cards out of a findings list. */ declare function rankSecurityCards(cards: SecurityCard[]): SecurityCard[]; interface ScanOptions { fetchImpl?: typeof fetch; env?: NodeJS.ProcessEnv; now?: () => number; service?: string; } /** Every matched advisory in the project, findings ranked, `present` as context. */ declare function scanProjectCves(graph: NeatGraph, opts?: ScanOptions): Promise; /** * One package's answer: its cards and the highest level they reach. Matches the * package by name (PyPI names PEP 503-normalized), optionally pinned to a version * and an ecosystem. Only that package's versions are looked up. */ declare function isReachable(graph: NeatGraph, query: { package: string; version?: string; ecosystem?: string; symbol?: string; }, opts?: ScanOptions): Promise; /** * The before/after comparison of two sets of cards. An advisory, package and * service is one entry whatever the version on each side; with several versions * of a package in one service, the most exposed card stands for it. * * - `introduced`: a finding after (`imported` or above) that wasn't one before, * including a package that was only in the lockfile and is now imported. * - `removed`: a finding before that isn't one after, whether the package went, * moved to an unaffected version, or is no longer imported. * - `stillPresent`: a finding on both sides. * - `context`: matches that are only in the lockfile, appearing or going. */ declare function diffSecurityCards(before: SecurityCard[], after: SecurityCard[]): Omit; interface ScanDiffOptions { fetchImpl?: typeof fetch; env?: NodeJS.ProcessEnv; now?: () => number; service?: string; } /** The comparison of two already-extracted graphs, judged against one snapshot. */ declare function scanDiffGraphs(before: NeatGraph, after: NeatGraph, refs: { base: string; head: string; }, opts?: ScanDiffOptions): Promise; /** * A commit for a ref name, a full or short sha, or either followed by `~N` / * `^` (first parents), the forms a PR or an agent writes: `main`, `HEAD~1`, * `abc123^`. isomorphic-git resolves names and shas but not the suffixes. */ declare function resolveRevision(repoRoot: string, rev: string): Promise; /** * Write the tree of `ref` under `subdir` of the repository at `repoRoot` into * `outDir`, from the local object store (no network). Blobs over 2MB are left * out; extraction doesn't read them. */ declare function materializeRef(repoRoot: string, ref: string, subdir: string, outDir: string): Promise; /** * scan_diff on a local checkout: `base` (a ref or commit) against `head` (a ref * or commit, or the working tree when omitted). Each side is extracted into its * own scratch graph, never the project's. The scratch copies take the scan * root's directory name, so a service named after its directory (a nameless * package.json) is the same service on both sides. */ declare function scanDiffLocal(scanPath: string, refs: { base: string; head?: string; }, opts?: ScanDiffOptions & { tmpRoot?: string; }): Promise; interface FileEdit { file: string; change: 'manifest-spec' | 'manifest-override' | 'lockfile-regenerated'; dependency: string; from: string; to: string; } type ApplyOutcome = { applied: true; action: SecurityFixAction; edits: FileEdit[]; } | { applied: false; action?: SecurityFixAction; reason: string; }; interface ApplyOptions { manifestDir?: string; regenerateLock?: (manifestDirAbs: string) => void | Promise; } /** * Apply a card's fix to the working tree. Edits the manifest deterministically * and regenerates the lockfile with npm. Returns applied:false with a reason for * anything it will not fix, so a caller never reads "not handled" as "fixed". */ declare function applyFixAction(scanPath: string, card: SecurityCard, opts?: ApplyOptions): Promise; interface DepApplyResult { dependencyId: string; manifest: string; outcome: ApplyOutcome; } /** * Apply the fixes for a set of cards, once per (dependency, manifest). After the * reconcile step every card of a dependency carries the same fix.action, and * there are several cards per dependency (one per service and advisory), so a * naive per-card loop would apply the same bump many times. This dedups by * (dependency.id, manifest.file) and applies each dependency's bump once, in a * stable order. Each card derives its own manifest location from the card, so a * dependency in two services edits each service's manifest. */ declare function applyFixes(scanPath: string, cards: SecurityCard[], opts?: Pick): Promise; interface ReverifyResult { outcome: ApplyOutcome; reverify?: SecurityDiff; cleared?: boolean; } /** * Apply the card's fix to the working tree, then scan_diff HEAD (the committed, * still-vulnerable state) against the working tree. `cleared` is true when the * card's advisory moved to `removed` and no new finding was introduced. Security * axis only; the project's own tests are the separate 0-regression check. */ declare function applyAndReverify(scanPath: string, card: SecurityCard, opts?: ApplyOptions & ScanDiffOptions): Promise; export { type ApplyOptions, type ApplyOutcome, type DepApplyResult, type FileEdit, type ReverifyResult, type ScanDiffOptions, type ScanOptions, applyAndReverify, applyFixAction, applyFixes, buildSecurityCard, buildSecurityCards, diffSecurityCards, highestLevel, isReachable, materializeRef, rankSecurityCards, resolveRevision, scanDiffGraphs, scanDiffLocal, scanProjectCves };