Node.js SDK reference

LIVE

Constructor options, methods, errors and versions for @cyberspec/sdk, the typed Node.js client for the CyberSpec API.

  • npm install @cyberspec/sdk; Node.js 20 or later, ESM only, TypeScript types included
  • Zero runtime dependencies; uses the platform fetch
  • assets, scans, findings and reports namespaces in 0.1.0 on npm; code and the deps CLI from 0.2.0, not yet on npm
  • findings.all() pages for you and returns known-exploited issues first
  • Failed requests throw CyberSpecError with status, message and the parsed body; nothing is retried for you
CyberSpec dashboard: risk score, open findings by severity, a seven-day trend and recent scans
The CyberSpec portal.

This is the reference. For what you can build with it, such as a CI gate and a dependency check, see the SDK overview at /sdk. The client wraps the same Bearer-key REST API the portal uses. Network assets are read-only through it, because adding one needs ownership verification and a person’s consent to scan, and that happens in the portal.

Install and quick start

An Owner or Admin creates a key under Settings → API and you put it in CYBERSPEC_API_KEY. From CommonJS, load the package with await import('@cyberspec/sdk'). The loop below prints every open finding, known-exploited first (CISA’s KEV catalog), then by severity.

npm install @cyberspec/sdk

import { CyberSpec } from '@cyberspec/sdk';

const cs = new CyberSpec({ apiKey: process.env.CYBERSPEC_API_KEY });

for await (const finding of cs.findings.all({ status: 'open' })) {
  console.log(finding.severity, finding.cve ?? finding.checkType, finding.hostPort);
}

Constructor options

apiKey is required and is a cs_live_ key. baseUrl defaults to https://api.cyberspec.pro. timeoutMs applies to each request and defaults to 30 seconds; a request that runs out rejects with the AbortSignal TimeoutError, not CyberSpecError.

Methods

assets: list(), get(id). scans: list(), get(id), create({ assetIds, type, schedule? }) with type quick, full or custom, cancel(id), wait(id, { intervalMs?, timeoutMs? }), which polls every 10 seconds for up to an hour by default and returns the scan, so check its status. findings: list(filter) for one page (100 by default, limit up to 200, offset), all(filter) to iterate every page, summary(), get(id), setStatus(id, status), setStatusBulk(ids, status), explain(id), triage(id). Filters are severity, status, cve, assetId, checkType and scanId. reports: list(), get(id), create({ type, assetId? }), downloadUrl(id). code: scan({ name, packages, consent: true }), plus readLockfiles(dir), from 0.2.0, not yet on npm.

Errors and timeouts

A non-2xx response throws CyberSpecError. status is the HTTP code, message is the API’s message and body is the parsed response. A 429 from Explain or Triage means the daily AI limit is used up; it resets at 00:00 UTC. The SDK does not retry, so wrap calls yourself if you want that. Keep the key on the server and out of source control.

import { CyberSpec, CyberSpecError } from '@cyberspec/sdk';

const cs = new CyberSpec({ apiKey: process.env.CYBERSPEC_API_KEY, timeoutMs: 60_000 });

try {
  await cs.findings.triage(id);
} catch (err) {
  if (err instanceof CyberSpecError && err.status === 429) {
    // daily AI limit reached, resets at 00:00 UTC
  } else throw err;
}

Versions

npm’s latest is 0.1.0, which has assets, scans, findings and reports. Version 0.2.0 adds the code namespace, readLockfiles, the dependency check type, the repo asset type and the npx @cyberspec/sdk deps CLI. It is in the CyberSpec repository but not yet published to npm, so installing today gives you 0.1.0.

The parts of CyberSpec that do this

For teams in United States

US buyers mostly meet security questions through SOC 2, ISO 27001 or PCI DSS. CyberSpec maps every open CVE finding to the controls in all three, from live scans, so the evidence is current when an auditor or a customer asks.

CyberSpec is $19 per client a month for up to 5 assets, a $129 one-off report, or free for one asset.

See your own exposure in minutes

Free for one asset, no card. Add a domain, prove you own it, and run your first scan.

More in Developers