@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.
Files changed (120) hide show
  1. package/README.md +56 -13
  2. package/dist/package.json +7 -7
  3. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +0 -1
  4. package/dist/src/cli.d.ts +3 -0
  5. package/dist/src/cli.js +102 -68
  6. package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +1 -1
  7. package/dist/src/discoveries/load-ocsf-discoveries.d.ts +0 -8
  8. package/dist/src/discoveries/load-ocsf-discoveries.js +0 -31
  9. package/dist/src/discoveries/write-ocsf-discoveries.d.ts +0 -8
  10. package/dist/src/discoveries/write-ocsf-discoveries.js +0 -38
  11. package/dist/src/evals/run-model-matrix.js +0 -1
  12. package/dist/src/export/export-ocsf.d.ts +18 -0
  13. package/dist/src/export/export-ocsf.js +104 -0
  14. package/dist/src/export/register-export-commands.d.ts +2 -0
  15. package/dist/src/export/register-export-commands.js +30 -0
  16. package/dist/src/facts/apply-answers.d.ts +29 -0
  17. package/dist/src/facts/apply-answers.js +202 -0
  18. package/dist/src/facts/build-facts.d.ts +24 -0
  19. package/dist/src/facts/build-facts.js +198 -0
  20. package/dist/src/facts/io.d.ts +17 -0
  21. package/dist/src/facts/io.js +67 -0
  22. package/dist/src/facts/layout.d.ts +29 -0
  23. package/dist/src/facts/layout.js +38 -0
  24. package/dist/src/facts/schema.d.ts +265 -0
  25. package/dist/src/facts/schema.js +122 -0
  26. package/dist/src/facts/slug.d.ts +7 -0
  27. package/dist/src/facts/slug.js +47 -0
  28. package/dist/src/kb/brief.d.ts +1 -2
  29. package/dist/src/kb/brief.js +2 -4
  30. package/dist/src/kb/interview-record.d.ts +18 -0
  31. package/dist/src/kb/interview-record.js +70 -0
  32. package/dist/src/kb/kb-store.d.ts +24 -18
  33. package/dist/src/kb/kb-store.js +89 -28
  34. package/dist/src/kb/land.d.ts +32 -12
  35. package/dist/src/kb/land.js +97 -90
  36. package/dist/src/kb/migrate.d.ts +23 -0
  37. package/dist/src/kb/migrate.js +91 -0
  38. package/dist/src/kb/project-diagram.js +4 -4
  39. package/dist/src/kb/register-kb-commands.js +71 -20
  40. package/dist/src/observability/scan-sentry.js +0 -1
  41. package/dist/src/output/scan-output-excludes.d.ts +1 -1
  42. package/dist/src/output/scan-output-excludes.js +14 -5
  43. package/dist/src/output/write-scan-knowledge.d.ts +33 -0
  44. package/dist/src/output/write-scan-knowledge.js +115 -0
  45. package/dist/src/platform-api/estimate-scan-footprint.d.ts +31 -0
  46. package/dist/src/platform-api/estimate-scan-footprint.js +75 -2
  47. package/dist/src/platform-api/fetch-failure.d.ts +5 -0
  48. package/dist/src/platform-api/fetch-failure.js +13 -0
  49. package/dist/src/platform-api/upload-client.d.ts +5 -0
  50. package/dist/src/platform-api/upload-client.js +11 -1
  51. package/dist/src/ui/scan-progress-renderer.d.ts +16 -0
  52. package/dist/src/ui/scan-progress-renderer.js +29 -3
  53. package/dist/src/ui/teaching-lines.js +18 -6
  54. package/dist/src/upload/collect-scan-sidecars.d.ts +2 -27
  55. package/dist/src/upload/collect-scan-sidecars.js +25 -121
  56. package/dist/src/upload/run-upload.js +0 -3
  57. package/dist/tests/cli/cli.spec.js +30 -13
  58. package/dist/tests/helpers/facts-fixture.d.ts +9 -0
  59. package/dist/tests/helpers/facts-fixture.js +72 -0
  60. package/dist/tests/unit/cli/scan-ai-session-fallback.spec.js +156 -0
  61. package/dist/tests/unit/export/export-ocsf.spec.js +72 -0
  62. package/dist/tests/unit/facts/apply-answers.spec.d.ts +1 -0
  63. package/dist/tests/unit/facts/apply-answers.spec.js +128 -0
  64. package/dist/tests/unit/facts/build-facts.spec.d.ts +1 -0
  65. package/dist/tests/unit/facts/build-facts.spec.js +161 -0
  66. package/dist/tests/unit/facts/slug.spec.d.ts +1 -0
  67. package/dist/tests/unit/facts/slug.spec.js +30 -0
  68. package/dist/tests/unit/kb/kb-interview-loop.spec.js +83 -35
  69. package/dist/tests/unit/kb/migrate.spec.d.ts +1 -0
  70. package/dist/tests/unit/kb/migrate.spec.js +108 -0
  71. package/dist/tests/unit/output/graphify-cache-dir.spec.d.ts +1 -0
  72. package/dist/tests/unit/output/graphify-cache-dir.spec.js +20 -0
  73. package/dist/tests/unit/output/scan-output-excludes.spec.js +4 -2
  74. package/dist/tests/unit/platform-api/estimate-scan-footprint.spec.js +77 -0
  75. package/dist/tests/unit/platform-api/upload-client.spec.js +2 -2
  76. package/dist/tests/unit/ui/scan-progress-renderer.spec.js +21 -0
  77. package/dist/tests/unit/ui/teaching-lines.spec.js +16 -0
  78. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +46 -46
  79. package/dist/tests/unit/upload/pack-scan-upload.spec.js +6 -6
  80. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +6 -14
  81. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +1 -0
  82. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +32 -1
  83. package/dist/vendor/scanner/dist/src/classifier/naming.d.ts +5 -0
  84. package/dist/vendor/scanner/dist/src/classifier/naming.js +8 -4
  85. package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +26 -14
  86. package/dist/vendor/scanner/dist/src/core/pipeline/enrich-personal-data-layers.js +3 -1
  87. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +18 -0
  88. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +125 -66
  89. package/dist/vendor/scanner/dist/src/index.d.ts +2 -0
  90. package/dist/vendor/scanner/dist/src/index.js +7 -2
  91. package/dist/vendor/scanner/dist/src/ingest/file-system.d.ts +5 -0
  92. package/dist/vendor/scanner/dist/src/ingest/file-system.js +5 -0
  93. package/dist/vendor/scanner/dist/src/ingest/gitignore.d.ts +17 -0
  94. package/dist/vendor/scanner/dist/src/ingest/gitignore.js +47 -9
  95. package/dist/vendor/scanner/dist/src/ingest/schema-files.d.ts +10 -2
  96. package/dist/vendor/scanner/dist/src/ingest/schema-files.js +24 -7
  97. package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.d.ts +3 -0
  98. package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.js +45 -0
  99. package/dist/vendor/scanner/dist/src/patterns/scan-exclusions.js +7 -0
  100. package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +24 -0
  101. package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +19 -6
  102. package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +5 -2
  103. package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +5 -2
  104. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +8 -0
  105. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +9 -0
  106. package/package.json +7 -7
  107. package/dist/src/discoveries/project-collected-diagram.d.ts +0 -7
  108. package/dist/src/discoveries/project-collected-diagram.js +0 -182
  109. package/dist/src/discoveries/project-ocsf-to-discoveries-document.d.ts +0 -16
  110. package/dist/src/discoveries/project-ocsf-to-discoveries-document.js +0 -269
  111. package/dist/src/discoveries/scan-result-to-discovery-input.d.ts +0 -13
  112. package/dist/src/discoveries/scan-result-to-discovery-input.js +0 -60
  113. package/dist/src/output/write-knowledge-graph.d.ts +0 -20
  114. package/dist/src/output/write-knowledge-graph.js +0 -53
  115. package/dist/src/output/write-scan-discoveries.d.ts +0 -17
  116. package/dist/src/output/write-scan-discoveries.js +0 -61
  117. package/dist/tests/unit/discoveries/project-collected-diagram.spec.js +0 -97
  118. package/dist/tests/unit/discoveries/rescan-replaces-scan-records.spec.js +0 -89
  119. /package/dist/tests/unit/{discoveries/project-collected-diagram.spec.d.ts → cli/scan-ai-session-fallback.spec.d.ts} +0 -0
  120. /package/dist/tests/unit/{discoveries/rescan-replaces-scan-records.spec.d.ts → export/export-ocsf.spec.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CliUploadError = void 0;
3
4
  exports.cliUploadAnonymousPreview = cliUploadAnonymousPreview;
4
5
  exports.cliUploadPreview = cliUploadPreview;
5
6
  const pack_scan_upload_1 = require("../upload/pack-scan-upload");
@@ -10,6 +11,15 @@ function buildAuthHeaders(apiKey) {
10
11
  'Content-Type': 'application/json',
11
12
  };
12
13
  }
14
+ /** Upload rejected by the API; `status` is the HTTP status (429 = rate limit). */
15
+ class CliUploadError extends Error {
16
+ constructor(message, status) {
17
+ super(message);
18
+ this.status = status;
19
+ this.name = 'CliUploadError';
20
+ }
21
+ }
22
+ exports.CliUploadError = CliUploadError;
13
23
  async function parseUploadError(res) {
14
24
  let message = `Upload failed (${res.status})`;
15
25
  try {
@@ -24,7 +34,7 @@ async function parseUploadError(res) {
24
34
  catch {
25
35
  // ignore
26
36
  }
27
- throw new Error(message);
37
+ throw new CliUploadError(message, res.status);
28
38
  }
29
39
  async function cliUploadAnonymousPreview(input) {
30
40
  const res = await fetch(`${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)()}/api/scans/cli/preview`, {
@@ -12,6 +12,14 @@ export declare function formatAiStepResult(result: ScanAiStepResult): string;
12
12
  export declare function formatOutputPath(outputPath: string): string;
13
13
  /** Prefer a short, human path in the header (home → ~). */
14
14
  export declare function formatProjectLabel(projectPath: string): string;
15
+ export type ScanUploadFailure = {
16
+ /** Why the upload failed, without a trailing period. */
17
+ reason: string;
18
+ /** Exact command to retry the upload. */
19
+ retryCommand: string;
20
+ /** Optional extra advice, e.g. how to avoid the anonymous per-IP cap. */
21
+ hint?: string;
22
+ };
15
23
  /**
16
24
  * Staged scan progress for TTY (Clack) and plain logs for non-TTY / NO_COLOR.
17
25
  */
@@ -34,6 +42,7 @@ export declare class ScanProgressRenderer {
34
42
  private teachingSummaryLines;
35
43
  private previewUrl;
36
44
  private previewNotice;
45
+ private uploadFailure;
37
46
  constructor(options: ScanProgressRendererOptions, clack: ClackPrompts | null);
38
47
  /** Test helper: true when Clack chrome is active. */
39
48
  get usesClackChrome(): boolean;
@@ -45,6 +54,13 @@ export declare class ScanProgressRenderer {
45
54
  onWroteDataflow(outputPath?: string): void;
46
55
  /** Store preview URL for the "What to do next" note. Machine line stays in upload. */
47
56
  onPreviewUrl(previewUrl: string, notice?: string): void;
57
+ /**
58
+ * Auto-upload failed after the local output was written. finish() then
59
+ * says so and prints the retry command instead of the success closing.
60
+ */
61
+ onUploadFailed(failure: ScanUploadFailure): void;
62
+ /** One plain informational line, e.g. how many files the scan walks. */
63
+ info(message: string): void;
48
64
  /**
49
65
  * Non-fatal scan warning. Clack renders it inside the guide rail; plain mode
50
66
  * keeps the `[scan] …` stderr line scripts may grep for.
@@ -228,6 +228,23 @@ class ScanProgressRenderer {
228
228
  this.previewUrl = previewUrl;
229
229
  this.previewNotice = notice;
230
230
  }
231
+ /**
232
+ * Auto-upload failed after the local output was written. finish() then
233
+ * says so and prints the retry command instead of the success closing.
234
+ */
235
+ onUploadFailed(failure) {
236
+ this.uploadFailure = failure;
237
+ }
238
+ /** One plain informational line, e.g. how many files the scan walks. */
239
+ info(message) {
240
+ this.start();
241
+ if (this.useClack) {
242
+ this.prompts().log.info(message);
243
+ }
244
+ else {
245
+ this.writePlain(message);
246
+ }
247
+ }
231
248
  /**
232
249
  * Non-fatal scan warning. Clack renders it inside the guide rail; plain mode
233
250
  * keeps the `[scan] …` stderr line scripts may grep for.
@@ -263,7 +280,16 @@ class ScanProgressRenderer {
263
280
  finish() {
264
281
  this.completeActiveStep();
265
282
  const nextSteps = [];
266
- if (this.previewUrl) {
283
+ let closing = 'All done — nice work.';
284
+ if (this.uploadFailure) {
285
+ const { reason, retryCommand, hint } = this.uploadFailure;
286
+ nextSteps.push(`The upload did not complete: ${reason}.`);
287
+ nextSteps.push(`Your scan is saved locally. To upload it, run:\n ${retryCommand}`);
288
+ if (hint)
289
+ nextSteps.push(hint);
290
+ closing = 'Scan finished. The upload did not complete.';
291
+ }
292
+ else if (this.previewUrl) {
267
293
  nextSteps.push(`Open your diagram:\n${formatPreviewLink(this.previewUrl, this.colorEnabled)}`);
268
294
  // Plain mode already got the notice from the upload's own log line.
269
295
  if (this.useClack && this.previewNotice) {
@@ -278,7 +304,7 @@ class ScanProgressRenderer {
278
304
  // preview URLs and breaks click-to-open.
279
305
  this.prompts().log.step('What to do next');
280
306
  this.prompts().log.message(nextSteps.join('\n\n'));
281
- this.prompts().outro('All done — nice work.');
307
+ this.prompts().outro(closing);
282
308
  }
283
309
  else {
284
310
  this.writePlain('What to do next');
@@ -291,7 +317,7 @@ class ScanProgressRenderer {
291
317
  this.writePlain(` ${line}`);
292
318
  }
293
319
  }
294
- this.writePlain('All done — nice work.');
320
+ this.writePlain(closing);
295
321
  }
296
322
  }
297
323
  transitionTo(step) {
@@ -15,13 +15,23 @@ function titleCaseToken(token) {
15
15
  return token;
16
16
  return token.charAt(0).toUpperCase() + token.slice(1);
17
17
  }
18
+ /** Each `_`- or space-separated word title-cased: `Google_identity` -> `Google Identity`. */
19
+ function titleCaseWords(value) {
20
+ return value
21
+ .split(/[_\s]+/)
22
+ .filter((word) => word.length > 0)
23
+ .map(titleCaseToken)
24
+ .join(' ');
25
+ }
26
+ /** Every spelling the analyzers use for Next.js. */
27
+ const NEXT_JS_SPELLINGS = new Set(['nextjs', 'next', 'next.js', 'next_or_react_route']);
18
28
  function prettyFramework(framework) {
19
29
  const lower = framework.toLowerCase();
20
30
  if (lower === 'express')
21
31
  return 'Express';
22
32
  if (lower === 'nest')
23
33
  return 'Nest';
24
- if (lower === 'next_or_react_route')
34
+ if (NEXT_JS_SPELLINGS.has(lower))
25
35
  return 'Next.js';
26
36
  if (lower === 'fastapi')
27
37
  return 'FastAPI';
@@ -75,7 +85,7 @@ function prettyVendor(serviceName) {
75
85
  };
76
86
  if (known[lower])
77
87
  return known[lower];
78
- return titleCaseToken(serviceName);
88
+ return titleCaseWords(serviceName);
79
89
  }
80
90
  /**
81
91
  * Build teaching lines from deterministic findings/components.
@@ -86,13 +96,15 @@ function buildTeachingLineGroups(findings, components) {
86
96
  for (const finding of findings) {
87
97
  if (finding.pattern !== 'express_route')
88
98
  continue;
89
- const framework = asString(finding.properties?.framework) ?? 'framework';
90
- routeCounts.set(framework, (routeCounts.get(framework) ?? 0) + 1);
99
+ // A package.json dependency on a framework is a hint about the app, not a route.
100
+ if (finding.properties?.sourceContext === 'dependency_manifest')
101
+ continue;
102
+ const name = prettyFramework(asString(finding.properties?.framework) ?? 'framework');
103
+ routeCounts.set(name, (routeCounts.get(name) ?? 0) + 1);
91
104
  }
92
105
  const routes = [...routeCounts.entries()]
93
106
  .sort(([a], [b]) => a.localeCompare(b))
94
- .map(([framework, count]) => {
95
- const name = prettyFramework(framework);
107
+ .map(([name, count]) => {
96
108
  return count === 1
97
109
  ? `Found 1 ${name} route`
98
110
  : `Found ${count} ${name} routes`;
@@ -1,35 +1,10 @@
1
- /**
2
- * Files a scan writes beside dataflow.json. The upload sends these with the
3
- * diagram so the stored preview can keep the full scan.
4
- */
5
- export type ScanUploadSidecars = {
6
- /** graphify-out/graph.json. Omitted when Graphify did not write it. */
7
- graphifyGraph?: unknown;
8
- /** dataparade-graph.json. Joins an occurrence to a Graphify node. */
9
- dataparadeGraph?: unknown;
10
- /**
11
- * Occurrence and data-item Facts from ocsf-discoveries/.
12
- * Component and flow Facts are left out.
13
- * Present (possibly empty) when that directory exists.
14
- */
15
- facts?: unknown[];
16
- };
17
- export declare function entityIdFromAsserts(asserts: string): string | null;
18
- /** True for an occurrence or data-item Fact, including its slot records. */
19
- export declare function isOccurrenceOrDataItemFact(record: unknown): boolean;
20
- /**
21
- * Read the scan files that sit next to dataflow.json.
22
- * graphify-out/graph.json is included only when that file exists.
23
- */
24
- export declare function collectScanSidecars(dataflowFilePath: string): ScanUploadSidecars;
25
1
  /** One scan file, as it was written on disk, ready to upload on its own. */
26
2
  export type ScanUploadFile = {
27
3
  relativePath: string;
28
4
  content: string;
29
5
  };
30
6
  /**
31
- * Raw scan files to upload beside dataflow.json.
32
- * graphify-out/graph.json is included only when that file exists.
33
- * Only occurrence and data-item Facts are included.
7
+ * The scan files to upload after dataflow.json: facts.json, every data-items/*.json,
8
+ * graphify.json, and answers.json. A file that is missing or is not a JSON object is left out.
34
9
  */
35
10
  export declare function collectScanUploadFiles(dataflowFilePath: string): ScanUploadFile[];
@@ -3,18 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.entityIdFromAsserts = entityIdFromAsserts;
7
- exports.isOccurrenceOrDataItemFact = isOccurrenceOrDataItemFact;
8
- exports.collectScanSidecars = collectScanSidecars;
9
6
  exports.collectScanUploadFiles = collectScanUploadFiles;
10
7
  const fs_1 = __importDefault(require("fs"));
11
8
  const path_1 = __importDefault(require("path"));
12
- const PATH_PREFIX = 'dp:scan/path/';
13
- const ENTITY_MARKER = '/entity/';
14
- const LEGACY_PREFIX = 'dp:scan/entity/';
9
+ const layout_1 = require("../facts/layout");
15
10
  function readTextIfPresent(filePath) {
16
- if (!fs_1.default.existsSync(filePath))
17
- return undefined;
18
11
  try {
19
12
  return fs_1.default.readFileSync(filePath, 'utf8');
20
13
  }
@@ -22,132 +15,43 @@ function readTextIfPresent(filePath) {
22
15
  return undefined;
23
16
  }
24
17
  }
25
- function readJsonIfPresent(filePath) {
26
- const text = readTextIfPresent(filePath);
27
- if (text === undefined)
28
- return undefined;
18
+ function isJsonObject(text) {
29
19
  try {
30
- return JSON.parse(text);
20
+ const parsed = JSON.parse(text);
21
+ return Boolean(parsed) && typeof parsed === 'object' && !Array.isArray(parsed);
31
22
  }
32
23
  catch {
33
- return undefined;
34
- }
35
- }
36
- function asObject(value) {
37
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
38
- return undefined;
39
- }
40
- return value;
41
- }
42
- function entityIdFromAsserts(asserts) {
43
- if (asserts.startsWith(PATH_PREFIX)) {
44
- const rest = asserts.slice(PATH_PREFIX.length);
45
- const markerAt = rest.indexOf(ENTITY_MARKER);
46
- if (markerAt === -1)
47
- return null;
48
- const entityId = rest.slice(markerAt + ENTITY_MARKER.length);
49
- return entityId || null;
50
- }
51
- if (asserts.startsWith(LEGACY_PREFIX)) {
52
- const entityId = asserts.slice(LEGACY_PREFIX.length);
53
- return entityId || null;
54
- }
55
- return null;
56
- }
57
- /** True for an occurrence or data-item Fact, including its slot records. */
58
- function isOccurrenceOrDataItemFact(record) {
59
- if (!record || typeof record !== 'object')
60
- return false;
61
- const asserts = record.dataparade
62
- ?.asserts;
63
- if (typeof asserts !== 'string')
64
24
  return false;
65
- const entityId = entityIdFromAsserts(asserts);
66
- if (!entityId)
67
- return false;
68
- return (entityId.startsWith('occurrence:') || entityId.startsWith('data_item:'));
69
- }
70
- function readOccurrenceAndDataItemFacts(discoveriesDir) {
71
- if (!fs_1.default.existsSync(discoveriesDir))
72
- return undefined;
73
- const facts = [];
74
- const names = fs_1.default
75
- .readdirSync(discoveriesDir)
76
- .filter((name) => name.endsWith('.json'));
77
- names.sort((left, right) => left.localeCompare(right));
78
- for (const name of names) {
79
- const parsed = readJsonIfPresent(path_1.default.join(discoveriesDir, name));
80
- if (isOccurrenceOrDataItemFact(parsed)) {
81
- facts.push(parsed);
82
- }
83
25
  }
84
- return facts;
85
26
  }
86
27
  /**
87
- * Read the scan files that sit next to dataflow.json.
88
- * graphify-out/graph.json is included only when that file exists.
89
- */
90
- function collectScanSidecars(dataflowFilePath) {
91
- const outputDir = path_1.default.dirname(path_1.default.resolve(dataflowFilePath));
92
- const sidecars = {};
93
- const graphifyGraph = asObject(readJsonIfPresent(path_1.default.join(outputDir, 'graphify-out', 'graph.json')));
94
- if (graphifyGraph !== undefined) {
95
- sidecars.graphifyGraph = graphifyGraph;
96
- }
97
- const dataparadeGraph = asObject(readJsonIfPresent(path_1.default.join(outputDir, 'dataparade-graph.json')));
98
- if (dataparadeGraph !== undefined) {
99
- sidecars.dataparadeGraph = dataparadeGraph;
100
- }
101
- const facts = readOccurrenceAndDataItemFacts(path_1.default.join(outputDir, 'ocsf-discoveries'));
102
- if (facts !== undefined) {
103
- sidecars.facts = facts;
104
- }
105
- return sidecars;
106
- }
107
- /**
108
- * Raw scan files to upload beside dataflow.json.
109
- * graphify-out/graph.json is included only when that file exists.
110
- * Only occurrence and data-item Facts are included.
28
+ * The scan files to upload after dataflow.json: facts.json, every data-items/*.json,
29
+ * graphify.json, and answers.json. A file that is missing or is not a JSON object is left out.
111
30
  */
112
31
  function collectScanUploadFiles(dataflowFilePath) {
113
- const outputDir = path_1.default.dirname(path_1.default.resolve(dataflowFilePath));
32
+ const layout = (0, layout_1.layoutForDir)(path_1.default.dirname(path_1.default.resolve(dataflowFilePath)));
114
33
  const files = [];
115
- const graphify = readTextIfPresent(path_1.default.join(outputDir, 'graphify-out', 'graph.json'));
116
- if (graphify !== undefined && asObject(parseJson(graphify))) {
117
- files.push({ relativePath: 'graphify-out/graph.json', content: graphify });
118
- }
119
- const dataparadeGraph = readTextIfPresent(path_1.default.join(outputDir, 'dataparade-graph.json'));
120
- if (dataparadeGraph !== undefined && asObject(parseJson(dataparadeGraph))) {
121
- files.push({
122
- relativePath: 'dataparade-graph.json',
123
- content: dataparadeGraph,
124
- });
125
- }
126
- const discoveriesDir = path_1.default.join(outputDir, 'ocsf-discoveries');
127
- if (fs_1.default.existsSync(discoveriesDir)) {
128
- const names = fs_1.default
129
- .readdirSync(discoveriesDir)
130
- .filter((name) => name.endsWith('.json'));
131
- names.sort((left, right) => left.localeCompare(right));
132
- for (const name of names) {
133
- const content = readTextIfPresent(path_1.default.join(discoveriesDir, name));
134
- if (content === undefined)
135
- continue;
136
- if (!isOccurrenceOrDataItemFact(parseJson(content)))
137
- continue;
138
- files.push({
139
- relativePath: `ocsf-discoveries/${name}`,
140
- content,
141
- });
34
+ const add = (relativePath, absolutePath) => {
35
+ const content = readTextIfPresent(absolutePath);
36
+ if (content !== undefined && isJsonObject(content)) {
37
+ files.push({ relativePath, content });
142
38
  }
143
- }
144
- return files;
145
- }
146
- function parseJson(text) {
39
+ };
40
+ add(layout_1.FACTS_BASENAME, layout.factsPath);
41
+ let names = [];
147
42
  try {
148
- return JSON.parse(text);
43
+ names = fs_1.default
44
+ .readdirSync(layout.dataItemsDir)
45
+ .filter((name) => name.endsWith('.json'));
149
46
  }
150
47
  catch {
151
- return undefined;
48
+ names = [];
152
49
  }
50
+ names.sort((left, right) => left.localeCompare(right));
51
+ for (const name of names) {
52
+ add(`${layout_1.DATA_ITEMS_DIRNAME}/${name}`, path_1.default.join(layout.dataItemsDir, name));
53
+ }
54
+ add(layout_1.GRAPHIFY_BASENAME, layout.graphifyPath);
55
+ add(layout_1.ANSWERS_BASENAME, layout.answersPath);
56
+ return files;
153
57
  }
@@ -25,7 +25,6 @@ async function runDataflowUpload(input) {
25
25
  });
26
26
  const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId, sessionId);
27
27
  if (!input.quiet) {
28
- // eslint-disable-next-line no-console
29
28
  console.log(`${prefix} Preview ready: ${previewUrl}`);
30
29
  }
31
30
  if (sessionId) {
@@ -57,9 +56,7 @@ async function runDataflowUpload(input) {
57
56
  ? ' and any platform AI tokens used during the scan.'
58
57
  : '.');
59
58
  if (!input.quiet) {
60
- // eslint-disable-next-line no-console
61
59
  console.log(`${prefix} Preview ready: ${previewUrl}`);
62
- // eslint-disable-next-line no-console
63
60
  console.log(`${prefix} ${notice}`);
64
61
  }
65
62
  if (sessionId) {
@@ -9,19 +9,19 @@ const path_1 = __importDefault(require("path"));
9
9
  const cliDistPath = path_1.default.join(__dirname, '../../dist/bin/cli.js');
10
10
  const cliCwd = path_1.default.join(__dirname, '../../');
11
11
  const scanFixturePath = path_1.default.join(cliCwd, 'tests/fixtures/typescript-basic');
12
- /** Scan outputs the CLI writes next to dataflow.json in the working directory. */
12
+ /** Scan outputs the CLI writes in the working directory (default `.dataparade/`, plus `-o` files in the tests). */
13
13
  const SCAN_OUTPUTS = [
14
+ '.dataparade',
15
+ '.cli-test-out',
14
16
  'dataflow.json',
15
- 'dataparade.json',
16
- 'dataparade-graph.json',
17
- 'discoveries-diagram.json',
18
- 'discoveries-diagram.d2',
19
- 'ocsf-discoveries',
20
- 'graphify-out',
17
+ 'facts.json',
18
+ 'data-items',
19
+ 'graphify.json',
20
+ 'scan-fixture-summary.json',
21
+ 'scan-teaching-progress.json',
21
22
  ];
22
23
  describe('CLI', () => {
23
- // Discovery records refuse to overwrite a same-day record, so each scan test starts
24
- // from a clean working directory.
24
+ // Each scan test starts from a clean working directory.
25
25
  beforeEach(() => {
26
26
  for (const name of SCAN_OUTPUTS)
27
27
  (0, fs_1.rmSync)(path_1.default.join(cliCwd, name), { recursive: true, force: true });
@@ -47,7 +47,7 @@ describe('CLI', () => {
47
47
  cwd: cliCwd,
48
48
  });
49
49
  expect(result.status).toBe(0);
50
- const outputPath = path_1.default.join(cliCwd, 'dataflow.json');
50
+ const outputPath = path_1.default.join(cliCwd, '.dataparade', 'dataflow.json');
51
51
  const exists = (0, fs_1.existsSync)(outputPath);
52
52
  expect(exists).toBe(true);
53
53
  const contents = (0, fs_1.readFileSync)(outputPath, 'utf8').trim();
@@ -56,6 +56,23 @@ describe('CLI', () => {
56
56
  expect(dataflow.graph).toBeDefined();
57
57
  expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
58
58
  expect(Array.isArray(dataflow.graph.edges)).toBe(true);
59
+ // The default folder holds Facts, one file per data item, and nothing from older versions.
60
+ const outputDir = path_1.default.join(cliCwd, '.dataparade');
61
+ const names = (0, fs_1.readdirSync)(outputDir).sort();
62
+ expect(names).toEqual(expect.arrayContaining(['dataflow.json', 'facts.json']));
63
+ for (const legacy of [
64
+ 'dataparade.json',
65
+ 'dataparade-graph.json',
66
+ 'ocsf-discoveries',
67
+ 'discoveries-diagram.json',
68
+ 'graphify-out',
69
+ ]) {
70
+ expect(names).not.toContain(legacy);
71
+ }
72
+ const facts = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(outputDir, 'facts.json'), 'utf8'));
73
+ expect(facts.schemaVersion).toBe(1);
74
+ expect(facts.components.length).toBeGreaterThan(0);
75
+ expect(JSON.stringify(facts)).not.toContain(cliCwd);
59
76
  });
60
77
  it('scan fixture produces a dataflow.json wrapper with at least one node', () => {
61
78
  const result = (0, child_process_1.spawnSync)('node', [
@@ -69,14 +86,14 @@ describe('CLI', () => {
69
86
  cwd: cliCwd,
70
87
  });
71
88
  expect(result.status).toBe(0);
72
- const outputPath = path_1.default.join(cliCwd, 'dataflow.json');
89
+ const outputPath = path_1.default.join(cliCwd, '.dataparade', 'dataflow.json');
73
90
  const contents = (0, fs_1.readFileSync)(outputPath, 'utf8').trim();
74
91
  const dataflow = JSON.parse(contents);
75
92
  expect(Array.isArray(dataflow.graph.nodes)).toBe(true);
76
93
  expect(dataflow.graph.nodes.length).toBeGreaterThan(0);
77
94
  });
78
95
  it('scan fixture --output writes a dataflow.json wrapper to the given file and prints a short message', () => {
79
- const outputFile = 'scan-fixture-summary.json';
96
+ const outputFile = '.cli-test-out/scan-fixture-summary.json';
80
97
  const result = (0, child_process_1.spawnSync)('node', [
81
98
  cliDistPath,
82
99
  'scan',
@@ -98,7 +115,7 @@ describe('CLI', () => {
98
115
  });
99
116
  it('scan mixed-language fixture prints teaching lines before dataflow.json written', () => {
100
117
  const teachingFixture = path_1.default.join(cliCwd, 'tests/fixtures/mixed-language-basic');
101
- const outputFile = 'scan-teaching-progress.json';
118
+ const outputFile = '.cli-test-out/scan-teaching-progress.json';
102
119
  const result = (0, child_process_1.spawnSync)('node', [
103
120
  cliDistPath,
104
121
  'scan',
@@ -0,0 +1,9 @@
1
+ import { type OutputLayout } from "../../src/facts/layout";
2
+ import type { DataItemFile, FactsFile } from "../../src/facts/schema";
3
+ /** A small scan: an API, Sendgrid, a customer, two flows, and an email data item with two groups. */
4
+ export declare function sampleFacts(): {
5
+ facts: FactsFile;
6
+ files: DataItemFile[];
7
+ };
8
+ /** A knowledge base folder holding sampleFacts(). */
9
+ export declare function makeKbDir(): OutputLayout;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sampleFacts = sampleFacts;
7
+ exports.makeKbDir = makeKbDir;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const io_1 = require("../../src/facts/io");
12
+ const layout_1 = require("../../src/facts/layout");
13
+ /** A small scan: an API, Sendgrid, a customer, two flows, and an email data item with two groups. */
14
+ function sampleFacts() {
15
+ const groups = [
16
+ { id: "group:email:customer", label: "customer", basis: "column", occurrenceCount: 2, handledBy: ["cmp_api"] },
17
+ { id: "group:email:staff", label: "staff", basis: "name", occurrenceCount: 1, handledBy: ["cmp_api", "cmp_mail"] },
18
+ ];
19
+ const emailFile = {
20
+ schemaVersion: 1,
21
+ id: "data_item:email",
22
+ name: "email",
23
+ labels: ["contact"],
24
+ groups,
25
+ occurrences: [
26
+ { id: "occurrence:email:src/a.ts:3", groupId: "group:email:customer", filePath: "src/a.ts", startLine: 3, endLine: 3, code: "email", labels: ["contact"], codeRefs: [] },
27
+ { id: "occurrence:email:src/b.ts:9", groupId: "group:email:customer", filePath: "src/b.ts", startLine: 9, endLine: 9, labels: ["contact"], codeRefs: [] },
28
+ { id: "occurrence:email:src/c.ts:1", groupId: "group:email:staff", filePath: "src/c.ts", startLine: 1, endLine: 1, labels: [], codeRefs: [] },
29
+ ],
30
+ };
31
+ const phoneFile = {
32
+ schemaVersion: 1,
33
+ id: "data_item:phone",
34
+ name: "phone",
35
+ labels: [],
36
+ groups: [{ id: "group:phone:customer", label: "customer", occurrenceCount: 1, handledBy: ["cmp_api"] }],
37
+ occurrences: [
38
+ { id: "occurrence:phone:src/a.ts:7", groupId: "group:phone:customer", filePath: "src/a.ts", startLine: 7, endLine: 7, labels: [], codeRefs: [] },
39
+ ],
40
+ };
41
+ const facts = {
42
+ schemaVersion: 1,
43
+ scan: { projectName: "demo", scannedAt: "2026-10-09T00:00:00.000Z", cliVersion: "0.0.27", scannerVersion: "abc123" },
44
+ components: [
45
+ { id: "cmp_api", name: "backend", type: "asset", subType: "service", confidence: 0.9, sourceLocations: [{ filePath: "backend/src/main.ts", startLine: 1, endLine: 1 }], codeRefs: [] },
46
+ { id: "cmp_mail", name: "Sendgrid", type: "third_party", subType: "email", confidence: 0.9, sourceLocations: [], codeRefs: [] },
47
+ { id: "cmp_user", name: "Customer", type: "actor", subType: "", confidence: 0.8, sourceLocations: [], codeRefs: [] },
48
+ ],
49
+ dataFlows: [
50
+ { id: "flow_mail", sourceComponentId: "cmp_api", targetComponentId: "cmp_mail", type: "api_call", confidence: 0.9, sourceLocations: [], codeRefs: [] },
51
+ { id: "flow_login", sourceComponentId: "cmp_user", targetComponentId: "cmp_api", type: "api_call", confidence: 0.9, sourceLocations: [], codeRefs: [] },
52
+ ],
53
+ dataItems: [
54
+ { id: "data_item:email", name: "email", labels: ["contact"], occurrenceCount: 3, file: "data-items/email.json", groups },
55
+ { id: "data_item:phone", name: "phone", labels: [], occurrenceCount: 1, file: "data-items/phone.json", groups: phoneFile.groups },
56
+ ],
57
+ relations: [
58
+ { type: "sends", source: "cmp_api", target: "flow_mail", confidence: "EXTRACTED", basis: null },
59
+ { type: "delivers_to", source: "flow_mail", target: "cmp_mail", confidence: "EXTRACTED", basis: null },
60
+ { type: "handled_by", source: "group:email:staff", target: "cmp_mail", confidence: "INFERRED", basis: "same_file" },
61
+ ],
62
+ };
63
+ return { facts, files: [emailFile, phoneFile] };
64
+ }
65
+ /** A knowledge base folder holding sampleFacts(). */
66
+ function makeKbDir() {
67
+ const layout = (0, layout_1.layoutForDir)(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dp-kb-")));
68
+ const { facts, files } = sampleFacts();
69
+ (0, io_1.writeFactsOutput)(layout, facts, new Map(files.map((file) => [`data-items/${file.name}.json`, file])));
70
+ fs_1.default.writeFileSync(layout.dataflowPath, JSON.stringify({ schemaVersion: "1.0", graph: { nodes: [], edges: [] }, metadata: { projectName: "demo" } }));
71
+ return layout;
72
+ }