@dataparade/cli 0.0.26 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -13
- package/dist/package.json +7 -7
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +0 -1
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +102 -68
- package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +1 -1
- package/dist/src/discoveries/load-ocsf-discoveries.d.ts +0 -8
- package/dist/src/discoveries/load-ocsf-discoveries.js +0 -31
- package/dist/src/discoveries/write-ocsf-discoveries.d.ts +0 -8
- package/dist/src/discoveries/write-ocsf-discoveries.js +0 -38
- package/dist/src/evals/run-model-matrix.js +0 -1
- package/dist/src/export/export-ocsf.d.ts +18 -0
- package/dist/src/export/export-ocsf.js +104 -0
- package/dist/src/export/register-export-commands.d.ts +2 -0
- package/dist/src/export/register-export-commands.js +30 -0
- package/dist/src/facts/apply-answers.d.ts +29 -0
- package/dist/src/facts/apply-answers.js +202 -0
- package/dist/src/facts/build-facts.d.ts +24 -0
- package/dist/src/facts/build-facts.js +198 -0
- package/dist/src/facts/io.d.ts +17 -0
- package/dist/src/facts/io.js +67 -0
- package/dist/src/facts/layout.d.ts +29 -0
- package/dist/src/facts/layout.js +38 -0
- package/dist/src/facts/schema.d.ts +265 -0
- package/dist/src/facts/schema.js +122 -0
- package/dist/src/facts/slug.d.ts +7 -0
- package/dist/src/facts/slug.js +47 -0
- package/dist/src/kb/brief.d.ts +1 -2
- package/dist/src/kb/brief.js +2 -4
- package/dist/src/kb/interview-record.d.ts +18 -0
- package/dist/src/kb/interview-record.js +70 -0
- package/dist/src/kb/kb-store.d.ts +24 -18
- package/dist/src/kb/kb-store.js +89 -28
- package/dist/src/kb/land.d.ts +32 -12
- package/dist/src/kb/land.js +97 -90
- package/dist/src/kb/migrate.d.ts +23 -0
- package/dist/src/kb/migrate.js +91 -0
- package/dist/src/kb/project-diagram.js +4 -4
- package/dist/src/kb/register-kb-commands.js +71 -20
- package/dist/src/observability/scan-sentry.js +0 -1
- package/dist/src/output/scan-output-excludes.d.ts +1 -1
- package/dist/src/output/scan-output-excludes.js +14 -5
- package/dist/src/output/write-scan-knowledge.d.ts +33 -0
- package/dist/src/output/write-scan-knowledge.js +115 -0
- package/dist/src/platform-api/estimate-scan-footprint.d.ts +31 -0
- package/dist/src/platform-api/estimate-scan-footprint.js +75 -2
- package/dist/src/platform-api/fetch-failure.d.ts +5 -0
- package/dist/src/platform-api/fetch-failure.js +13 -0
- package/dist/src/platform-api/upload-client.d.ts +5 -0
- package/dist/src/platform-api/upload-client.js +11 -1
- package/dist/src/ui/scan-progress-renderer.d.ts +16 -0
- package/dist/src/ui/scan-progress-renderer.js +29 -3
- package/dist/src/ui/teaching-lines.js +18 -6
- package/dist/src/upload/collect-scan-sidecars.d.ts +2 -27
- package/dist/src/upload/collect-scan-sidecars.js +25 -121
- package/dist/src/upload/run-upload.js +0 -3
- package/dist/tests/cli/cli.spec.js +30 -13
- package/dist/tests/helpers/facts-fixture.d.ts +9 -0
- package/dist/tests/helpers/facts-fixture.js +72 -0
- package/dist/tests/unit/cli/scan-ai-session-fallback.spec.js +156 -0
- package/dist/tests/unit/export/export-ocsf.spec.js +72 -0
- package/dist/tests/unit/facts/apply-answers.spec.d.ts +1 -0
- package/dist/tests/unit/facts/apply-answers.spec.js +128 -0
- package/dist/tests/unit/facts/build-facts.spec.d.ts +1 -0
- package/dist/tests/unit/facts/build-facts.spec.js +161 -0
- package/dist/tests/unit/facts/slug.spec.d.ts +1 -0
- package/dist/tests/unit/facts/slug.spec.js +30 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +83 -35
- package/dist/tests/unit/kb/migrate.spec.d.ts +1 -0
- package/dist/tests/unit/kb/migrate.spec.js +108 -0
- package/dist/tests/unit/output/graphify-cache-dir.spec.d.ts +1 -0
- package/dist/tests/unit/output/graphify-cache-dir.spec.js +20 -0
- package/dist/tests/unit/output/scan-output-excludes.spec.js +4 -2
- package/dist/tests/unit/platform-api/estimate-scan-footprint.spec.js +77 -0
- package/dist/tests/unit/platform-api/upload-client.spec.js +2 -2
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +21 -0
- package/dist/tests/unit/ui/teaching-lines.spec.js +16 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +46 -46
- package/dist/tests/unit/upload/pack-scan-upload.spec.js +6 -6
- package/dist/vendor/scanner/dist/src/classifier/component-factory.js +6 -14
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +1 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +32 -1
- package/dist/vendor/scanner/dist/src/classifier/naming.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/classifier/naming.js +8 -4
- package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +26 -14
- package/dist/vendor/scanner/dist/src/core/pipeline/enrich-personal-data-layers.js +3 -1
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +18 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +125 -66
- package/dist/vendor/scanner/dist/src/index.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/index.js +7 -2
- package/dist/vendor/scanner/dist/src/ingest/file-system.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/ingest/file-system.js +5 -0
- package/dist/vendor/scanner/dist/src/ingest/gitignore.d.ts +17 -0
- package/dist/vendor/scanner/dist/src/ingest/gitignore.js +47 -9
- package/dist/vendor/scanner/dist/src/ingest/schema-files.d.ts +10 -2
- package/dist/vendor/scanner/dist/src/ingest/schema-files.js +24 -7
- package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.d.ts +3 -0
- package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.js +45 -0
- package/dist/vendor/scanner/dist/src/patterns/scan-exclusions.js +7 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +24 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +19 -6
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +5 -2
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +5 -2
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +8 -0
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +9 -0
- package/package.json +7 -7
- package/dist/src/discoveries/project-collected-diagram.d.ts +0 -7
- package/dist/src/discoveries/project-collected-diagram.js +0 -182
- package/dist/src/discoveries/project-ocsf-to-discoveries-document.d.ts +0 -16
- package/dist/src/discoveries/project-ocsf-to-discoveries-document.js +0 -269
- package/dist/src/discoveries/scan-result-to-discovery-input.d.ts +0 -13
- package/dist/src/discoveries/scan-result-to-discovery-input.js +0 -60
- package/dist/src/output/write-knowledge-graph.d.ts +0 -20
- package/dist/src/output/write-knowledge-graph.js +0 -53
- package/dist/src/output/write-scan-discoveries.d.ts +0 -17
- package/dist/src/output/write-scan-discoveries.js +0 -61
- package/dist/tests/unit/discoveries/project-collected-diagram.spec.js +0 -97
- package/dist/tests/unit/discoveries/rescan-replaces-scan-records.spec.js +0 -89
- /package/dist/tests/unit/{discoveries/project-collected-diagram.spec.d.ts → cli/scan-ai-session-fallback.spec.d.ts} +0 -0
- /package/dist/tests/unit/{discoveries/rescan-replaces-scan-records.spec.d.ts → export/export-ocsf.spec.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -12,61 +12,104 @@ The **dataPARADE CLI** (`@dataparade/cli`) scans a codebase and produces a **`da
|
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
14
14
|
|
|
15
|
+
Install the CLI and check that it runs:
|
|
16
|
+
|
|
15
17
|
```bash
|
|
16
|
-
|
|
18
|
+
npm install -g @dataparade/cli
|
|
19
|
+
dataparade --help
|
|
17
20
|
```
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
Then scan your project from its root folder:
|
|
20
23
|
|
|
21
24
|
```bash
|
|
22
|
-
|
|
25
|
+
dataparade scan .
|
|
23
26
|
```
|
|
24
27
|
|
|
28
|
+
A scan reads the source and config files under the folder (skipping dependencies, build output and anything in `.gitignore`) and uploads the result to the dataPARADE web app unless you pass `--skip-auto-upload`.
|
|
29
|
+
|
|
25
30
|
**What to expect:**
|
|
26
31
|
|
|
27
32
|
- In a TTY: brand header, staged progress (spinner → checkmarks), a short **What we found** summary (routes, databases, outbound services), and a clear next-step note.
|
|
28
33
|
- In CI / non-TTY (or with `NO_COLOR`): the same content as plain logs — no spinners or ANSI.
|
|
29
34
|
- On success: `[scan] dataflow.json written to /absolute/path/to/dataflow.json` (always printed for scripts/tests).
|
|
35
|
+
- If AI enrichment cannot start (no network, anonymous per-IP limit, server error), the CLI prints `AI enrichment unavailable (<reason>); continuing with a structural scan.` and still writes the output. Use `--no-ai-inference` to skip AI.
|
|
30
36
|
- When auto-upload runs: `[scan] Preview ready: <URL>` (plus a friendly next-step note with the same URL).
|
|
31
|
-
- By default,
|
|
37
|
+
- By default, the output goes to a **`.dataparade/`** folder in the current working directory (override the path of `dataflow.json` with `-o` / `--output`; the other files sit next to it).
|
|
32
38
|
|
|
33
39
|
```bash
|
|
34
|
-
|
|
40
|
+
dataparade scan path/to/your/project --output scan-my-project-dataflow.json
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
List commands and options: `
|
|
43
|
+
List commands and options: `dataparade --help` and `dataparade scan --help`.
|
|
38
44
|
|
|
39
45
|
---
|
|
40
46
|
|
|
41
47
|
## Upload to dashboard
|
|
42
48
|
|
|
43
|
-
After a scan, the CLI **auto-uploads** `dataflow.json` by default (unless you opt out). This creates an **import preview draft** in the web app — not a finished assessment.
|
|
49
|
+
After a scan, the CLI **auto-uploads** `dataflow.json` and the Facts next to it by default (unless you opt out). This creates an **import preview draft** in the web app — not a finished assessment.
|
|
44
50
|
|
|
45
51
|
- **With a workspace API key** (`DATAPARADE_WORKSPACE_API_KEY` from **Workspace → Access keys**): prints a dashboard link (`?importDraft=`) for that workspace.
|
|
46
52
|
- **Without a workspace key**: prints a sign-up link (`/preview/cli/<token>`). Create an account to open **Preview & Edit** on your dashboard.
|
|
47
53
|
- Opt out: `--skip-auto-upload` or `DATAPARADE_SKIP_AUTO_UPLOAD=true`
|
|
48
|
-
-
|
|
54
|
+
- With a workspace API key, an upload does **not** use scan quota.
|
|
55
|
+
- Without a key, uploads count toward a small per-IP limit on anonymous scans. A default scan (AI on) counts once, when its AI session starts, and its auto-upload does not count again. A scan with `--no-ai-inference`, or a separate `dataparade upload`, counts once when it uploads. When the limit is reached, the scan still writes `.dataparade/`; set `DATAPARADE_WORKSPACE_API_KEY` and run `dataparade upload .dataparade/dataflow.json`.
|
|
56
|
+
- If the upload fails, the scan output stays on disk and the CLI prints the `dataparade upload` command to retry.
|
|
49
57
|
|
|
50
58
|
```bash
|
|
51
|
-
npx @dataparade/cli upload
|
|
59
|
+
npx @dataparade/cli upload .dataparade/dataflow.json --project-name "My service"
|
|
52
60
|
```
|
|
53
61
|
|
|
54
62
|
**Full guide:** [Upload to dashboard](https://app.dataparade.io/docs/cli-import-and-zip/upload)
|
|
55
63
|
|
|
56
64
|
---
|
|
57
65
|
|
|
58
|
-
## Output:
|
|
66
|
+
## Output: `.dataparade/`
|
|
67
|
+
|
|
68
|
+
By default, a scan writes these files to `./.dataparade/`:
|
|
69
|
+
|
|
70
|
+
| File | What it is |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `dataflow.json` | The diagram the web app imports: a wrapper with `schemaVersion`, `graph` (`DiagramGraphJson`: nodes, edges, viewport) and `metadata` (files scanned, duration, C4 `hierarchy`, etc.). |
|
|
73
|
+
| `facts.json` | What the latest scan found: components, data flows, data items (with groups) and the links between them. Replaced on every scan. |
|
|
74
|
+
| `data-items/<name>.json` | One file per data item, with every place it occurs in the code. |
|
|
75
|
+
| `graphify.json` | The code-structure graph from [Graphify](https://github.com/Graphify-Labs/graphify), when it is installed. |
|
|
76
|
+
| `answers.json` | People's decisions (interview answers, reviews). A scan never writes or changes it. |
|
|
77
|
+
|
|
78
|
+
`-o` / `--output` is the path of `dataflow.json`; the other files go in the same folder. Scans skip this folder, so rescanning does not read old output. Commit `answers.json` with your code; the rest can be regenerated.
|
|
79
|
+
|
|
80
|
+
Graphify's cache lives outside the output, in `~/.cache/dataparade/graphify/` (set `DATAPARADE_CACHE_DIR` to move it).
|
|
81
|
+
|
|
82
|
+
Interview and review commands work on this folder:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx @dataparade/cli kb brief # open interview questions
|
|
86
|
+
npx @dataparade/cli kb land ... # save a confirmed answer to answers.json
|
|
87
|
+
npx @dataparade/cli kb migrate # import answers from an old ocsf-discoveries/ folder
|
|
88
|
+
npx @dataparade/cli export ocsf --out ocsf # write OCSF records from facts + answers
|
|
89
|
+
```
|
|
59
90
|
|
|
60
|
-
|
|
91
|
+
Formats, and how answers apply: [docs/cli/scan-output.md](../docs/cli/scan-output.md).
|
|
61
92
|
|
|
62
|
-
-
|
|
63
|
-
- The `graph` section is compatible with the DataParade import flow
|
|
93
|
+
- The `graph` section of `dataflow.json` is compatible with the DataParade import flow
|
|
64
94
|
- Most node properties are emitted with `null` defaults; only a subset are filled from code patterns — complete the rest in Preview & Edit
|
|
65
95
|
|
|
66
96
|
**Full guide:** [Output and results](https://app.dataparade.io/docs/cli-import-and-zip/output)
|
|
67
97
|
|
|
68
98
|
---
|
|
69
99
|
|
|
100
|
+
## Troubleshooting
|
|
101
|
+
|
|
102
|
+
**The scan stops with `FATAL ERROR: ... JavaScript heap out of memory`.** Node ran out of memory on a very large tree. At the start of each scan the CLI prints how many files it will read and, for a large tree, names the biggest folders. Skip folders that hold no application code, and if needed give Node more memory:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
dataparade scan . --exclude 'public/**' 'generated/**'
|
|
106
|
+
NODE_OPTIONS=--max-old-space-size=8192 dataparade scan .
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Dependencies, build output and anything in `.gitignore` are skipped already.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
70
113
|
## Documentation
|
|
71
114
|
|
|
72
115
|
| Topic | Link |
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@clack/prompts": "^1.8.1",
|
|
58
58
|
"@sentry/node": "^10.38.0",
|
|
59
|
-
"commander": "^
|
|
59
|
+
"commander": "^14.0.3",
|
|
60
60
|
"dotenv": "^16.4.7",
|
|
61
|
-
"langsmith": "^0.
|
|
61
|
+
"langsmith": "^0.10.13",
|
|
62
62
|
"tree-sitter-wasms": "^0.1.13",
|
|
63
63
|
"typescript": "^5.7.3",
|
|
64
64
|
"web-tree-sitter": "0.25.10",
|
|
@@ -66,14 +66,14 @@
|
|
|
66
66
|
"zod": "^4.3.5"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@dataparade/scanner": "github:DataParade-io/scanner#
|
|
69
|
+
"@dataparade/scanner": "github:DataParade-io/scanner#6a5a95897fe9ccd60230b0636f3a91b2e21a1ab1",
|
|
70
70
|
"@eslint/js": "^9.18.0",
|
|
71
|
-
"@types/jest": "^
|
|
71
|
+
"@types/jest": "^30.0.0",
|
|
72
72
|
"@types/node": "^22.0.0",
|
|
73
73
|
"eslint": "^9.18.0",
|
|
74
74
|
"globals": "^15.14.0",
|
|
75
|
-
"jest": "^
|
|
76
|
-
"ts-jest": "^29.
|
|
75
|
+
"jest": "^30.5.2",
|
|
76
|
+
"ts-jest": "^29.4.6",
|
|
77
77
|
"typescript-eslint": "^8.20.0"
|
|
78
78
|
},
|
|
79
79
|
"files": [
|
|
@@ -95,7 +95,6 @@ class PlatformProxyProvider {
|
|
|
95
95
|
if (attempt >= delays.length || !(0, fetch_failure_1.isTransientFetchError)(err)) {
|
|
96
96
|
throw (0, fetch_failure_1.toApiReachabilityError)(err, url, method, attempt + 1);
|
|
97
97
|
}
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
98
|
console.warn(`[dataparade-ai] ${(0, fetch_failure_1.describeRequestTarget)(url, method)} failed (${(0, fetch_failure_1.fetchFailureDetail)(err)}). Retrying (${attempt + 1}/${delays.length}).`);
|
|
100
99
|
await this.wait(delays[attempt] ?? 0);
|
|
101
100
|
}
|
package/dist/src/cli.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import './config/load-cli-env';
|
|
2
|
+
import { type ScanUploadFailure } from './ui/scan-progress-renderer';
|
|
3
|
+
/** Retry command and advice shown when the scan's auto-upload fails. */
|
|
4
|
+
export declare function describeAutoUploadFailure(uploadError: unknown, dataflowOutputPath: string, hasWorkspaceApiKey: boolean): ScanUploadFailure;
|
|
2
5
|
export declare function run(argv?: string[]): Promise<void>;
|
package/dist/src/cli.js
CHANGED
|
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.describeAutoUploadFailure = describeAutoUploadFailure;
|
|
39
40
|
exports.run = run;
|
|
40
41
|
require("./config/load-cli-env");
|
|
41
42
|
const path_1 = __importDefault(require("path"));
|
|
@@ -43,9 +44,10 @@ const commander_1 = require("commander");
|
|
|
43
44
|
const crypto_1 = require("crypto");
|
|
44
45
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
45
46
|
const json_1 = require("./output/json");
|
|
46
|
-
const
|
|
47
|
-
const
|
|
47
|
+
const write_scan_knowledge_1 = require("./output/write-scan-knowledge");
|
|
48
|
+
const layout_1 = require("./facts/layout");
|
|
48
49
|
const register_kb_commands_1 = require("./kb/register-kb-commands");
|
|
50
|
+
const register_export_commands_1 = require("./export/register-export-commands");
|
|
49
51
|
const scan_output_excludes_1 = require("./output/scan-output-excludes");
|
|
50
52
|
const dataflow_wrapper_schema_1 = require("./core/schema/dataflow-wrapper.schema");
|
|
51
53
|
const upload_env_1 = require("./config/upload-env");
|
|
@@ -63,6 +65,16 @@ const cli_scan_failure_report_1 = require("./platform-api/cli-scan-failure-repor
|
|
|
63
65
|
const scan_config_schema_1 = require("./core/schema/scan-config.schema");
|
|
64
66
|
const scanner_1 = require("../vendor/scanner/dist/src/index.js");
|
|
65
67
|
const scan_progress_renderer_1 = require("./ui/scan-progress-renderer");
|
|
68
|
+
/** The scanner is vendored into the CLI; its version is the commit the CLI depends on. */
|
|
69
|
+
function scannerVersionFromPackage() {
|
|
70
|
+
// Built from parts: the vendor step rewrites the scanner's package name in string literals.
|
|
71
|
+
const scannerPackage = ['@dataparade', 'scanner'].join('/');
|
|
72
|
+
const spec = package_json_1.default.devDependencies?.[scannerPackage];
|
|
73
|
+
if (!spec)
|
|
74
|
+
return 'unknown';
|
|
75
|
+
const ref = spec.split('#')[1];
|
|
76
|
+
return ref ? ref.slice(0, 12) : spec;
|
|
77
|
+
}
|
|
66
78
|
function formatEvidence(detail) {
|
|
67
79
|
const evidence = detail.evidence;
|
|
68
80
|
if (!evidence || evidence.length === 0) {
|
|
@@ -113,6 +125,24 @@ function formatAiInferenceVerbose(details) {
|
|
|
113
125
|
}
|
|
114
126
|
return lines;
|
|
115
127
|
}
|
|
128
|
+
/** Retry command and advice shown when the scan's auto-upload fails. */
|
|
129
|
+
function describeAutoUploadFailure(uploadError, dataflowOutputPath, hasWorkspaceApiKey) {
|
|
130
|
+
const relative = path_1.default.relative(process.cwd(), dataflowOutputPath);
|
|
131
|
+
const target = relative && !relative.startsWith('..') ? relative : dataflowOutputPath;
|
|
132
|
+
const quoted = /\s/.test(target) ? `"${target}"` : target;
|
|
133
|
+
const status = uploadError && typeof uploadError === 'object' && 'status' in uploadError
|
|
134
|
+
? uploadError.status
|
|
135
|
+
: undefined;
|
|
136
|
+
const message = uploadError instanceof Error ? uploadError.message : '';
|
|
137
|
+
const rateLimited = status === 429 || /too many anonymous cli scans/i.test(message);
|
|
138
|
+
return {
|
|
139
|
+
reason: (0, fetch_failure_1.describeUnavailableReason)(uploadError),
|
|
140
|
+
retryCommand: `dataparade upload ${quoted}`,
|
|
141
|
+
hint: rateLimited && !hasWorkspaceApiKey
|
|
142
|
+
? 'Anonymous uploads are limited per IP address. To avoid the limit, set DATAPARADE_WORKSPACE_API_KEY (from Workspace → Access keys in DataParade) and run the upload again.'
|
|
143
|
+
: undefined,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
116
146
|
function formatUsd(value) {
|
|
117
147
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
118
148
|
return 'n/a';
|
|
@@ -127,7 +157,7 @@ function createProgram() {
|
|
|
127
157
|
program
|
|
128
158
|
.command('scan <path>')
|
|
129
159
|
.description('Scan a directory (or a single supported source file) for data flow components')
|
|
130
|
-
.option('-o, --output <file>',
|
|
160
|
+
.option('-o, --output <file>', `Write dataflow.json to the given file; facts.json, data-items/ and graphify.json go next to it (default: ./${layout_1.DEFAULT_DATAFLOW_OUTPUT})`)
|
|
131
161
|
.option('--exclude <pattern...>', 'One or more glob patterns to exclude from scanning')
|
|
132
162
|
.option('--minimum-confidence <number>', 'Minimum confidence (0-1) for including detections')
|
|
133
163
|
.option('--language <language...>', 'Limit scanning to specific languages (e.g. typescript, javascript, python, go, java, kotlin, cpp, csharp, terraform)')
|
|
@@ -157,7 +187,7 @@ function createProgram() {
|
|
|
157
187
|
.option('--byok-model <model>', 'BYOK model name (env: SCAN_BYOK_MODEL)')
|
|
158
188
|
.option('--skip-auto-upload', 'Do not upload dataflow.json to the dashboard after scan (env: DATAPARADE_SKIP_AUTO_UPLOAD)')
|
|
159
189
|
.option('--git-context <json>', 'Git repository context for evidence linking (JSON: {"provider":"github"|"gitlab","repository":"owner/repo","commitSha":"...","baseUrl?":"..."})')
|
|
160
|
-
.option('--no-structure-graph', 'Do not
|
|
190
|
+
.option('--no-structure-graph', 'Do not run graphify (graphify.json is not written, and Facts have no code references)')
|
|
161
191
|
.action(async (path, options) => {
|
|
162
192
|
let cliQuotaJobId;
|
|
163
193
|
let platformQuotaApiKey;
|
|
@@ -181,7 +211,6 @@ function createProgram() {
|
|
|
181
211
|
const errors = validated.error.issues
|
|
182
212
|
.map((i) => `${i.path.join('.') || '<root>'}: ${i.message}`)
|
|
183
213
|
.join('; ');
|
|
184
|
-
// eslint-disable-next-line no-console
|
|
185
214
|
console.error(`[scan] invalid --git-context: ${errors}`);
|
|
186
215
|
process.exitCode = 2;
|
|
187
216
|
return;
|
|
@@ -190,7 +219,6 @@ function createProgram() {
|
|
|
190
219
|
}
|
|
191
220
|
catch (parseErr) {
|
|
192
221
|
const message = parseErr instanceof Error ? parseErr.message : 'Invalid JSON';
|
|
193
|
-
// eslint-disable-next-line no-console
|
|
194
222
|
console.error(`[scan] failed to parse --git-context: ${message}`);
|
|
195
223
|
process.exitCode = 2;
|
|
196
224
|
return;
|
|
@@ -231,7 +259,6 @@ function createProgram() {
|
|
|
231
259
|
failurePhase: 'resolve_path',
|
|
232
260
|
failureCode: 'path_not_found',
|
|
233
261
|
});
|
|
234
|
-
// eslint-disable-next-line no-console
|
|
235
262
|
console.error(`[scan] error: ${message}`);
|
|
236
263
|
process.exitCode = 2;
|
|
237
264
|
return;
|
|
@@ -257,7 +284,7 @@ function createProgram() {
|
|
|
257
284
|
const flags = {
|
|
258
285
|
exclude: [
|
|
259
286
|
...(options.exclude ?? []),
|
|
260
|
-
...(0, scan_output_excludes_1.scanOutputExcludes)(resolvedScanRoot, path_1.default.resolve(process.cwd(), options.output ??
|
|
287
|
+
...(0, scan_output_excludes_1.scanOutputExcludes)(resolvedScanRoot, path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT)),
|
|
261
288
|
],
|
|
262
289
|
minimumConfidence: typeof options.minimumConfidence === 'string'
|
|
263
290
|
? Number(options.minimumConfidence)
|
|
@@ -313,6 +340,16 @@ function createProgram() {
|
|
|
313
340
|
sentryScanRoot = scanEntry.scanRootDir;
|
|
314
341
|
sentryAiMode = aiMode;
|
|
315
342
|
sentryAiProvider = config.aiProvider;
|
|
343
|
+
// AI enrichment is optional. When its platform setup fails (no
|
|
344
|
+
// network, anonymous per-IP cap, server error), say so once and
|
|
345
|
+
// run the structural scan so the local output is still written.
|
|
346
|
+
const continueWithoutAi = (setupError) => {
|
|
347
|
+
config.enableAiInference = false;
|
|
348
|
+
config.cliQuotaJobId = undefined;
|
|
349
|
+
config.anonSessionToken = undefined;
|
|
350
|
+
sentryAiMode = 'none';
|
|
351
|
+
progressUi.warn(`AI enrichment unavailable (${(0, fetch_failure_1.describeUnavailableReason)(setupError)}); continuing with a structural scan. Use --no-ai-inference to skip this step.`);
|
|
352
|
+
};
|
|
316
353
|
// Quota preflight for platform billing. Structural-only scans (AI off) do not use quota API.
|
|
317
354
|
if (workspaceApiKey && !usesByok && config.enableAiInference) {
|
|
318
355
|
const [{ cliScanPreflight }, { estimateScanFootprint }] = await Promise.all([
|
|
@@ -326,28 +363,38 @@ function createProgram() {
|
|
|
326
363
|
projectName: config.projectName,
|
|
327
364
|
fileCount: footprint.fileCount,
|
|
328
365
|
bytesIngested: footprint.bytesIngested,
|
|
366
|
+
}).catch(async (preflightError) => {
|
|
367
|
+
const { CliScanQuotaExceededError, CliScanAlreadyRunningError } = await Promise.resolve().then(() => __importStar(require('./platform-api/scan-quota-client')));
|
|
368
|
+
// Workspace quota and concurrency answers stay blocking.
|
|
369
|
+
if (preflightError instanceof CliScanQuotaExceededError ||
|
|
370
|
+
preflightError instanceof CliScanAlreadyRunningError) {
|
|
371
|
+
throw preflightError;
|
|
372
|
+
}
|
|
373
|
+
continueWithoutAi(preflightError);
|
|
374
|
+
return undefined;
|
|
329
375
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (preflight.aiDelivery === 'platform_proxy') {
|
|
341
|
-
config.aiMode = 'platform';
|
|
342
|
-
}
|
|
343
|
-
if (isInteractive) {
|
|
344
|
-
const quotaLine = `[scan] quota: scans_remaining=${preflight.scansRemaining} ai_tokens_remaining=${preflight.aiTokensRemaining} job_id=${preflight.jobId} working_budget=${config.aiBudgetTokens ?? 0}`;
|
|
345
|
-
if (friendlyTty) {
|
|
346
|
-
technicalLines.push(quotaLine);
|
|
376
|
+
if (preflight) {
|
|
377
|
+
cliQuotaJobId = preflight.jobId;
|
|
378
|
+
platformQuotaApiKey = workspaceApiKey;
|
|
379
|
+
config.cliQuotaJobId = preflight.jobId;
|
|
380
|
+
if (config.enableAiInference &&
|
|
381
|
+
preflight.suggestedAiBudgetTokens > 0) {
|
|
382
|
+
// suggestedAiBudgetTokens is a server ceiling (remaining quota /
|
|
383
|
+
// per-job cap), not a spend target. Never raise the CLI working
|
|
384
|
+
// budget above the configured default (or user override).
|
|
385
|
+
config.aiBudgetTokens = Math.min(config.aiBudgetTokens ?? 12_000, preflight.suggestedAiBudgetTokens);
|
|
347
386
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
387
|
+
if (preflight.aiDelivery === 'platform_proxy') {
|
|
388
|
+
config.aiMode = 'platform';
|
|
389
|
+
}
|
|
390
|
+
if (isInteractive) {
|
|
391
|
+
const quotaLine = `[scan] quota: scans_remaining=${preflight.scansRemaining} ai_tokens_remaining=${preflight.aiTokensRemaining} job_id=${preflight.jobId} working_budget=${config.aiBudgetTokens ?? 0}`;
|
|
392
|
+
if (friendlyTty) {
|
|
393
|
+
technicalLines.push(quotaLine);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
console.log(quotaLine);
|
|
397
|
+
}
|
|
351
398
|
}
|
|
352
399
|
}
|
|
353
400
|
}
|
|
@@ -377,25 +424,14 @@ function createProgram() {
|
|
|
377
424
|
technicalLines.push(sessionLine);
|
|
378
425
|
}
|
|
379
426
|
else {
|
|
380
|
-
// eslint-disable-next-line no-console
|
|
381
427
|
console.log(sessionLine);
|
|
382
428
|
}
|
|
383
429
|
}
|
|
384
430
|
}
|
|
385
431
|
catch (anonSessionError) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
: 'Anonymous AI session failed.';
|
|
390
|
-
reportedFailure = {
|
|
391
|
-
code: 'anonymous_ai_session_failed',
|
|
392
|
-
message: (0, cli_scan_failure_report_1.truncateFailureMessage)(message),
|
|
393
|
-
};
|
|
394
|
-
// eslint-disable-next-line no-console
|
|
395
|
-
console.error(`[scan] ${message}`);
|
|
396
|
-
process.exitCode =
|
|
397
|
-
anonSessionError instanceof CliAnonymousIpLimitError ? 2 : 1;
|
|
398
|
-
return;
|
|
432
|
+
// AI is optional: keep scanning without it so the user still
|
|
433
|
+
// gets the local .dataparade/ output.
|
|
434
|
+
continueWithoutAi(anonSessionError);
|
|
399
435
|
}
|
|
400
436
|
}
|
|
401
437
|
const configValidation = (0, scan_config_schema_1.validateScanConfiguration)(config);
|
|
@@ -413,7 +449,6 @@ function createProgram() {
|
|
|
413
449
|
failurePhase: 'config_validation',
|
|
414
450
|
failureCode: 'invalid_configuration',
|
|
415
451
|
});
|
|
416
|
-
// eslint-disable-next-line no-console
|
|
417
452
|
console.error(`[scan] invalid configuration:\n${configValidation.errors.map((e) => ` - ${e}`).join('\n')}`);
|
|
418
453
|
process.exitCode = 2;
|
|
419
454
|
return;
|
|
@@ -424,10 +459,16 @@ function createProgram() {
|
|
|
424
459
|
progressUi.warn(w);
|
|
425
460
|
}
|
|
426
461
|
else {
|
|
427
|
-
// eslint-disable-next-line no-console
|
|
428
462
|
console.warn(`[scan] warnings:\n${warnings.map((w) => ` - ${w}`).join('\n')}`);
|
|
429
463
|
}
|
|
430
464
|
}
|
|
465
|
+
{
|
|
466
|
+
const { summarizeScanTree, describeScanTree } = await Promise.resolve().then(() => __importStar(require('./platform-api/estimate-scan-footprint')));
|
|
467
|
+
const tree = describeScanTree(await summarizeScanTree(scanEntry.scanRootDir, config.excludePaths ?? []));
|
|
468
|
+
progressUi.info(tree.line);
|
|
469
|
+
if (tree.warning)
|
|
470
|
+
progressUi.warn(tree.warning);
|
|
471
|
+
}
|
|
431
472
|
const orchestratorResult = await runScanPipeline(resolvedScanRoot, config, (progress) => {
|
|
432
473
|
progressUi.onProgress(progress);
|
|
433
474
|
}, (recognition) => {
|
|
@@ -523,16 +564,17 @@ function createProgram() {
|
|
|
523
564
|
const message = graphError instanceof Error
|
|
524
565
|
? graphError.message
|
|
525
566
|
: 'Unknown error while building diagram graph.';
|
|
526
|
-
// eslint-disable-next-line no-console
|
|
527
567
|
console.error(`[scan] warning: unable to build diagram graph: ${message}`);
|
|
528
568
|
}
|
|
529
569
|
process.exitCode = 1;
|
|
530
570
|
}
|
|
531
571
|
if (diagramGraph) {
|
|
532
|
-
const dataflowOutputPath = path_1.default.resolve(process.cwd(), options.output ??
|
|
572
|
+
const dataflowOutputPath = path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT);
|
|
533
573
|
const resolvedProjectName = config.projectName?.trim() ||
|
|
534
574
|
path_1.default.basename(scanEntry.scanRootDir);
|
|
535
|
-
const
|
|
575
|
+
const layout = (0, layout_1.resolveOutputLayout)(dataflowOutputPath);
|
|
576
|
+
const knowledge = await (0, write_scan_knowledge_1.prepareScanKnowledge)(orchestratorResult, resolvedScanRoot, layout, { structureGraph: options.structureGraph !== false });
|
|
577
|
+
const hierarchy = (0, write_scan_knowledge_1.buildScanHierarchy)(knowledge.graph, diagramGraph.nodes.map((node) => node.id));
|
|
536
578
|
try {
|
|
537
579
|
(0, json_1.writeDataflowJson)({
|
|
538
580
|
scanResult,
|
|
@@ -543,24 +585,21 @@ function createProgram() {
|
|
|
543
585
|
gitContext: parsedGitContext,
|
|
544
586
|
hierarchy,
|
|
545
587
|
});
|
|
546
|
-
|
|
588
|
+
(0, write_scan_knowledge_1.writeScanFacts)(layout, {
|
|
589
|
+
knowledge,
|
|
590
|
+
scanRoot: scanEntry.scanRootDir,
|
|
591
|
+
projectName: resolvedProjectName,
|
|
592
|
+
cliVersion: package_json_1.default.version,
|
|
593
|
+
scannerVersion: scannerVersionFromPackage(),
|
|
594
|
+
});
|
|
547
595
|
// Friendly TTY/plain progress line (additive).
|
|
548
596
|
progressUi.onWroteDataflow(dataflowOutputPath);
|
|
549
597
|
// Machine line for scripts / CI (non-TTY). The friendly TTY UI
|
|
550
598
|
// shows the path in its own success line instead.
|
|
551
599
|
if (!friendlyTty) {
|
|
552
|
-
// eslint-disable-next-line no-console
|
|
553
600
|
console.log(`[scan] dataflow.json written to ${dataflowOutputPath}`);
|
|
554
601
|
}
|
|
555
|
-
|
|
556
|
-
console.log(`[scan] OCSF discoveries written to ${scanDiscoveriesPaths.ocsfDiscoveriesDir}`);
|
|
557
|
-
// eslint-disable-next-line no-console
|
|
558
|
-
console.log(`[scan] dataparade.json written to ${scanDiscoveriesPaths.dataparadeJsonPath}`);
|
|
559
|
-
// eslint-disable-next-line no-console
|
|
560
|
-
console.log(`[scan] discoveries diagram written to ${scanDiscoveriesPaths.collectedDiagramJsonPath}`);
|
|
561
|
-
if (options.structureGraph !== false) {
|
|
562
|
-
await (0, write_knowledge_graph_1.writeScanKnowledgeGraph)(orchestratorResult, resolvedScanRoot, path_1.default.dirname(dataflowOutputPath));
|
|
563
|
-
}
|
|
602
|
+
console.log(`[scan] facts.json and data-items/ written to ${layout.dir}`);
|
|
564
603
|
const skipAutoUpload = Boolean(options.skipAutoUpload) ||
|
|
565
604
|
(0, upload_env_1.resolveSkipAutoUpload)(process.env);
|
|
566
605
|
if (!skipAutoUpload) {
|
|
@@ -596,9 +635,11 @@ function createProgram() {
|
|
|
596
635
|
progressUi.warn(`Auto-upload failed: ${uploadMessage}`);
|
|
597
636
|
}
|
|
598
637
|
else {
|
|
599
|
-
// eslint-disable-next-line no-console
|
|
600
638
|
console.error(`[scan] Auto-upload failed: ${uploadMessage}`);
|
|
601
639
|
}
|
|
640
|
+
// The scan itself succeeded (exit 0), but do not close with
|
|
641
|
+
// the success line: say the upload failed and how to retry.
|
|
642
|
+
progressUi.onUploadFailed(describeAutoUploadFailure(uploadError, dataflowOutputPath, Boolean(workspaceApiKey)));
|
|
602
643
|
}
|
|
603
644
|
}
|
|
604
645
|
progressUi.finish();
|
|
@@ -622,7 +663,6 @@ function createProgram() {
|
|
|
622
663
|
const message = dataflowError instanceof Error
|
|
623
664
|
? dataflowError.message
|
|
624
665
|
: 'Unknown error while writing dataflow.json.';
|
|
625
|
-
// eslint-disable-next-line no-console
|
|
626
666
|
console.error(`[scan] error: failed to write dataflow.json: ${message}`);
|
|
627
667
|
process.exitCode = 1;
|
|
628
668
|
}
|
|
@@ -648,7 +688,6 @@ function createProgram() {
|
|
|
648
688
|
quotaCompletionReported = true;
|
|
649
689
|
// The Clack outro already closes the run in friendly TTY.
|
|
650
690
|
if (isInteractive && !friendlyTty) {
|
|
651
|
-
// eslint-disable-next-line no-console
|
|
652
691
|
console.log('[scan] Scan finished — you can start a new scan now.');
|
|
653
692
|
}
|
|
654
693
|
}
|
|
@@ -680,7 +719,6 @@ function createProgram() {
|
|
|
680
719
|
? 'scan_already_running'
|
|
681
720
|
: 'scan_exception',
|
|
682
721
|
});
|
|
683
|
-
// eslint-disable-next-line no-console
|
|
684
722
|
console.error(quotaBlocked
|
|
685
723
|
? `[scan] workspace quota: ${message}`
|
|
686
724
|
: scanInProgress
|
|
@@ -718,7 +756,6 @@ function createProgram() {
|
|
|
718
756
|
});
|
|
719
757
|
quotaCompletionReported = true;
|
|
720
758
|
if (isInteractive) {
|
|
721
|
-
// eslint-disable-next-line no-console
|
|
722
759
|
console.log('[scan] Scan finished — you can start a new scan now.');
|
|
723
760
|
}
|
|
724
761
|
}
|
|
@@ -739,7 +776,7 @@ function createProgram() {
|
|
|
739
776
|
options.apiKey?.trim() ||
|
|
740
777
|
(0, scan_env_1.resolveWorkspaceApiKey)(process.env);
|
|
741
778
|
const usageSessionId = (0, crypto_1.randomUUID)();
|
|
742
|
-
const filePath = path_1.default.resolve(process.cwd(), file ||
|
|
779
|
+
const filePath = path_1.default.resolve(process.cwd(), file || layout_1.DEFAULT_DATAFLOW_OUTPUT);
|
|
743
780
|
let dataflow;
|
|
744
781
|
try {
|
|
745
782
|
const { readFileSync } = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
@@ -747,7 +784,6 @@ function createProgram() {
|
|
|
747
784
|
}
|
|
748
785
|
catch (err) {
|
|
749
786
|
const message = err instanceof Error ? err.message : 'Failed to read dataflow.json';
|
|
750
|
-
// eslint-disable-next-line no-console
|
|
751
787
|
console.error(`[upload] error: ${message}`);
|
|
752
788
|
process.exitCode = 1;
|
|
753
789
|
return;
|
|
@@ -775,7 +811,6 @@ function createProgram() {
|
|
|
775
811
|
}
|
|
776
812
|
catch (err) {
|
|
777
813
|
const message = err instanceof Error ? err.message : 'Upload failed.';
|
|
778
|
-
// eslint-disable-next-line no-console
|
|
779
814
|
console.error(`[upload] error: ${message}`);
|
|
780
815
|
process.exitCode = 1;
|
|
781
816
|
}
|
|
@@ -805,19 +840,18 @@ function createProgram() {
|
|
|
805
840
|
});
|
|
806
841
|
const config = createDefaultScanConfiguration(overrides);
|
|
807
842
|
const displayConfig = (0, redact_1.redactScanConfigurationForDisplay)(config);
|
|
808
|
-
// eslint-disable-next-line no-console
|
|
809
843
|
console.log(JSON.stringify(displayConfig, null, 2));
|
|
810
844
|
}
|
|
811
845
|
catch (err) {
|
|
812
846
|
const message = err instanceof Error
|
|
813
847
|
? err.message
|
|
814
848
|
: 'Unknown error while loading configuration.';
|
|
815
|
-
// eslint-disable-next-line no-console
|
|
816
849
|
console.error('Failed to read configuration:', message);
|
|
817
850
|
process.exitCode = 1;
|
|
818
851
|
}
|
|
819
852
|
});
|
|
820
853
|
(0, register_kb_commands_1.registerKbCommands)(program);
|
|
854
|
+
(0, register_export_commands_1.registerExportCommands)(program);
|
|
821
855
|
return program;
|
|
822
856
|
}
|
|
823
857
|
async function run(argv) {
|
|
@@ -31,8 +31,8 @@ export declare const ocsfDiscoveryRecordSchema: z.ZodObject<{
|
|
|
31
31
|
ontology_version: z.ZodLiteral<"0.3.0">;
|
|
32
32
|
source: z.ZodEnum<{
|
|
33
33
|
scan: "scan";
|
|
34
|
-
cloud: "cloud";
|
|
35
34
|
interview: "interview";
|
|
35
|
+
cloud: "cloud";
|
|
36
36
|
}>;
|
|
37
37
|
asserted_at: z.ZodString;
|
|
38
38
|
asserts: z.ZodString;
|
|
@@ -16,11 +16,3 @@ export interface LoadOcsfDiscoveriesOptions {
|
|
|
16
16
|
requiredBriefSha?: string;
|
|
17
17
|
}
|
|
18
18
|
export declare function loadOcsfDiscoveriesFromDir(directory: string, options?: LoadOcsfDiscoveriesOptions): LoadedOcsfDiscoveries;
|
|
19
|
-
export type DiscoverySlotIndex = Map<string, Map<string, string>>;
|
|
20
|
-
/**
|
|
21
|
-
* Latest value per (asserts, slot). A record named in another record's
|
|
22
|
-
* `supersedes` is a corrected answer and drops out; the rest apply in
|
|
23
|
-
* `asserted_at` order (stable, so same-instant records keep load order).
|
|
24
|
-
*/
|
|
25
|
-
export declare function indexDiscoverySlots(records: OcsfDiscoveryRecord[]): DiscoverySlotIndex;
|
|
26
|
-
export declare function discoveryValue(index: DiscoverySlotIndex, asserts: string, slot: string): string | undefined;
|
|
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OcsfDiscoveryLoadError = void 0;
|
|
7
7
|
exports.loadOcsfDiscoveriesFromDir = loadOcsfDiscoveriesFromDir;
|
|
8
|
-
exports.indexDiscoverySlots = indexDiscoverySlots;
|
|
9
|
-
exports.discoveryValue = discoveryValue;
|
|
10
8
|
const fs_1 = __importDefault(require("fs"));
|
|
11
9
|
const path_1 = __importDefault(require("path"));
|
|
12
10
|
const ocsf_discovery_record_1 = require("./contract/ocsf-discovery-record");
|
|
@@ -44,32 +42,3 @@ function loadOcsfDiscoveriesFromDir(directory, options = {}) {
|
|
|
44
42
|
}
|
|
45
43
|
return { directory: resolved, records };
|
|
46
44
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Latest value per (asserts, slot). A record named in another record's
|
|
49
|
-
* `supersedes` is a corrected answer and drops out; the rest apply in
|
|
50
|
-
* `asserted_at` order (stable, so same-instant records keep load order).
|
|
51
|
-
*/
|
|
52
|
-
function indexDiscoverySlots(records) {
|
|
53
|
-
const superseded = new Set(records.map((record) => record.dataparade.supersedes).filter((uid) => Boolean(uid)));
|
|
54
|
-
const ordered = records
|
|
55
|
-
.filter((record) => !superseded.has(record.metadata.uid))
|
|
56
|
-
.map((record, position) => ({ record, position }))
|
|
57
|
-
.sort((a, b) => Date.parse(a.record.dataparade.asserted_at) - Date.parse(b.record.dataparade.asserted_at) ||
|
|
58
|
-
a.position - b.position)
|
|
59
|
-
.map(({ record }) => record);
|
|
60
|
-
const index = new Map();
|
|
61
|
-
for (const record of ordered) {
|
|
62
|
-
const slot = record.dataparade.asserted_slot;
|
|
63
|
-
if (!slot) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
const asserts = record.dataparade.asserts;
|
|
67
|
-
const bySlot = index.get(asserts) ?? new Map();
|
|
68
|
-
bySlot.set(slot, record.dataparade.asserted_value ?? "");
|
|
69
|
-
index.set(asserts, bySlot);
|
|
70
|
-
}
|
|
71
|
-
return index;
|
|
72
|
-
}
|
|
73
|
-
function discoveryValue(index, asserts, slot) {
|
|
74
|
-
return index.get(asserts)?.get(slot);
|
|
75
|
-
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import type { OcsfDiscoveryRecord } from "./contract/ocsf-discovery-record";
|
|
2
2
|
export declare function slugifyDiscoveryId(id: string): string;
|
|
3
3
|
export declare function writeOcsfDiscoveryRecordsToDir(records: OcsfDiscoveryRecord[], outputDir: string): string[];
|
|
4
|
-
/**
|
|
5
|
-
* A re-scan replaces that scan path's earlier scan records: the scan is the
|
|
6
|
-
* source of truth for what it found, and its records carry the land date in
|
|
7
|
-
* their ids, so an append would collide on the same day and pile up across days.
|
|
8
|
-
* Interview and cloud records, and scan records for other scan paths, are kept.
|
|
9
|
-
* Returns the paths it removed.
|
|
10
|
-
*/
|
|
11
|
-
export declare function removeScanRecordsForScanPath(outputDir: string, scanPath: string): string[];
|