Scans and progress
Start scans, list history, retrieve full latest or specific scan details, and stop execution explicitly.
A scan is a particular execution on a project. Keep the organization, project, and scan IDs separate. The SDK returns current state on request; your application decides when to refresh again.
Start a scan
const beforeStart = await client.scans.list(projectRef);
// Persist beforeStart.map((scan) => scan.id) and a start intent first.
const started = await client.scans.start(projectRef);
if (!started.current_scan_id) {
throw new Error("Start needs reconciliation against the saved history");
}
const scanRef = { ...projectRef, scanId: started.current_scan_id };
// Persist scanRef before returning from your launch handler.start sends a bodyless POST and returns ProjectOut. Its current_scan_id identifies the started execution. Starting orchestrates discovery, test generation and execution; it does not promise to rerun every previously completed task.
There is no automatic POST retry or create-and-start transaction. If the response is lost or the pointer is missing, use the persisted pre-start history for reconciliation.
List all scans
const scans = await client.scans.list(projectRef);The result is the complete history array, newest first, using one GET. Each entry includes its identity, sequence, trigger, status, phase progress, timestamps, task/finding counts and summary when supplied by the API. There are no page, cursor, or incremental filters.
Get the latest scan by default
const scan = await client.scans.get(projectRef);
if (scan === null) {
console.log("This project has no scans yet");
} else {
console.log({
scanId: scan.id,
progress: scan.progress_percent,
status: scan.status,
failed: scan.status === "failed",
});
}Without scanId, get reads the history, selects its newest entry, and fetches that scan's full details. An empty history returns null. This requires two GETs when a scan exists, because the API has no latest-detail endpoint. They share one timeout and cancellation budget. Errors are surfaced; the SDK does not silently select an older scan after a detail failure.
Get one specific scan
const scan = await client.scans.get({ ...projectRef, scanId: savedScanId });
const phases = scan.phases;
const recon = scan.recon_run;
const taskRuns = scan.task_runs;
const findings = scan.findings;
const summary = scan.summary;An explicit ID needs one detail GET and returns ScanDetailOut. A missing scan is an HTTP error. Both lookup forms preserve all API-provided detail fields, including additional properties:
| Fields | Information |
|---|---|
id, sequence_number, trigger, is_current | Execution identity and origin |
status, progress_percent, phases | Current execution state and progression |
started_at, ended_at, duration_seconds | Timing; nullable values stay nullable |
tasks_completed, tasks_total, findings_count | Counts |
recon_run, generation_task_count | Discovery and generation information |
task_runs | Per-run IDs, task IDs, outcomes, timing and usage fields |
findings, summary | Scan-associated finding summaries and aggregate changes |
Fields declared optional by the API remain optional. Missing required identity/status or a mismatched scan ID raises StraylabsProtocolError. Unknown string statuses are retained for caller handling.
Interpret status independently from progress
| Status | Interpretation |
|---|---|
running | Still executing, even if progress is already 100 |
completed | Pipeline ended; inspect individual task outcomes for partial failures |
failed | Provider marked the scan as failed |
abandoned | Scan was stopped |
| Other value | Preserve it and handle as an unrecognized state |
The SDK returns the snapshot immediately. It does not wait for completion or start background polling. A failed refresh request is a synchronization error, not evidence that the remote scan failed.
Use a persisted scan ID when tracking an order. scans.get(projectRef) intentionally follows the latest execution and can return a different scan after someone starts another one. Project idle and a cleared current_scan_id are not proof of successful completion.
Stop explicitly
const project = await client.projects.get(projectRef);
if (project.current_scan_id !== savedScanId) {
throw new Error("The current scan differs from the execution you intend to stop");
}
const stopped = await client.scans.stop(projectRef);Stop targets the project's current scan, not a scan ID. Serialize controls in your application: the check above is not a server-side conditional-stop token. A normal stop makes the scan abandoned; there is no supported pause/resume workflow. If no scan is running, the API can return HTTP 409.
Cancelling or timing out a GET only ends the local request. It never calls stop.
Last updated