vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
    • Overview
    • Reference
  • Usage
  1. Client
  2. /
  3. API Reference
  4. /
  5. @vltpkg/audit

@vltpkg/audit

@vltpkg/audit

The security audit behind vlt audit: which security alerts a package is reported for and how severe they are, the search for a version that fixes them, the remediation lines, the audit result, its human and JSON views, and the audit of an installed project.

Usage

Usage

Audit a project vlt installed, as vlt audit does:

JavaScript
import {
  auditFails,
  auditProject,
  formatAuditSummary,
} from '@vltpkg/audit'

// `options` are the config options vlt loads: `projectRoot`,
// `packageJson`, `scurry`, `monorepo`, the registries, …
const result = await auditProject({
  ...options,
  auditLevel: 'low',
  signal: new AbortController().signal,
  warn: message => console.error(message),
})
console.log(formatAuditSummary(result))
if (auditFails(result)) process.exitCode = 1

auditGraph audits packages of a graph you have already loaded. With remediation: true, either one looks fixes up in the registry and the security feed for the remediation lines.

The building blocks work on a graph and security data of your own:

JavaScript
import { baseDepID } from '@vltpkg/dep-id'
import { Query } from '@vltpkg/query'
import { SecurityArchive } from '@vltpkg/security-archive'
import {
  auditFails,
  auditQuery,
  buildAuditResult,
  formatAuditSummary,
} from '@vltpkg/audit'

// `graph` is a graph loaded with @vltpkg/graph, e.g. `actual.load()`
const nodes = [...graph.nodes.values()]
const archive = await SecurityArchive.start({ nodes })
const query = new Query({
  nodes: new Set(nodes),
  edges: graph.edges,
  importers: graph.importers,
  securityArchive: archive,
})
const { nodes: matched } = await query.search(auditQuery, {
  signal: new AbortController().signal,
})
const result = buildAuditResult({
  auditLevel: 'low',
  importers: graph.importers,
  nodes,
  flagged: new Set(matched.map(node => baseDepID(node.id))),
  archive,
})
console.log(formatAuditSummary(result))
if (auditFails(result)) process.exitCode = 1

For remediation lines there, pass targets: await findFixTargets({ ...sameOptions, lookup }), where lookup is a FixLookup that answers from the registry and the security feed.


Previous: API ReferencePrevious pageNext: ReferenceNext page

On this page

  • Usage

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now