@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,182 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projectCollectedDiscoveriesDiagram = projectCollectedDiscoveriesDiagram;
4
- function layout(ids) {
5
- const positions = new Map();
6
- const cols = Math.max(1, Math.ceil(Math.sqrt(ids.length)));
7
- ids.forEach((id, index) => {
8
- positions.set(id, {
9
- x: 80 + (index % cols) * 240,
10
- y: 80 + Math.floor(index / cols) * 140,
11
- });
12
- });
13
- return positions;
14
- }
15
- function d2Id(id) {
16
- const safe = id.replace(/[^A-Za-z0-9_]/g, "_").replace(/^_+/, "");
17
- return safe.length > 0 ? safe : "node";
18
- }
19
- function localId(id) {
20
- const marker = "::";
21
- const at = id.lastIndexOf(marker);
22
- return at === -1 ? id : id.slice(at + marker.length);
23
- }
24
- function pathLabel(scanPath) {
25
- if (!scanPath) {
26
- return undefined;
27
- }
28
- const parts = scanPath.split("/").filter((part) => part.length > 0);
29
- return parts[parts.length - 1] ?? scanPath;
30
- }
31
- function componentLabel(component) {
32
- const where = pathLabel(component.scanPath);
33
- return where ? `${component.name} (${where})` : component.name;
34
- }
35
- function projectCollectedDiscoveriesDiagram(document) {
36
- const occurrenceById = new Map(document.occurrences.map((occurrence) => [occurrence.id, occurrence]));
37
- const dataItemById = new Map(document.dataItems.map((item) => [item.id, item]));
38
- const componentIds = new Set(document.components.map((component) => component.id));
39
- const dataItemIdsOnComponents = new Set();
40
- for (const component of document.components) {
41
- for (const dataItemId of component.dataItemIds) {
42
- dataItemIdsOnComponents.add(dataItemId);
43
- }
44
- }
45
- const nodeIds = [
46
- ...document.components.map((component) => component.id),
47
- ...document.dataItems
48
- .filter((item) => !dataItemIdsOnComponents.has(item.id))
49
- .map((item) => item.id),
50
- ];
51
- for (const flow of document.dataFlows) {
52
- if (!componentIds.has(flow.sourceComponentId)) {
53
- nodeIds.push(flow.sourceComponentId);
54
- }
55
- if (!componentIds.has(flow.targetComponentId)) {
56
- nodeIds.push(flow.targetComponentId);
57
- }
58
- }
59
- const uniqueNodeIds = [...new Set(nodeIds)];
60
- const positions = layout(uniqueNodeIds);
61
- const nodes = uniqueNodeIds.map((id) => {
62
- const component = document.components.find((row) => row.id === id);
63
- if (component) {
64
- const dataItems = component.dataItemIds
65
- .map((dataItemId) => dataItemById.get(dataItemId))
66
- .filter((item) => item !== undefined)
67
- .map((item) => ({
68
- id: item.id,
69
- occurrences: item.occurrenceIds
70
- .map((occurrenceId) => occurrenceById.get(occurrenceId))
71
- .filter((occurrence) => occurrence !== undefined)
72
- .map((occurrence) => ({
73
- id: occurrence.id,
74
- filePath: occurrence.filePath,
75
- startLine: occurrence.startLine,
76
- endLine: occurrence.endLine,
77
- ...(occurrence.code !== undefined ? { code: occurrence.code } : {}),
78
- })),
79
- }));
80
- return {
81
- id,
82
- type: component.type || "component",
83
- position: positions.get(id) ?? { x: 0, y: 0 },
84
- data: {
85
- label: componentLabel(component),
86
- description: component.subType,
87
- privacy: { slotStatus: "known", source: "ocsf" },
88
- collected: {
89
- scanPath: component.scanPath,
90
- dataItems,
91
- },
92
- },
93
- };
94
- }
95
- const dataItem = dataItemById.get(id);
96
- if (dataItem) {
97
- const where = pathLabel(dataItem.scanPath);
98
- const occurrences = dataItem.occurrenceIds
99
- .map((occurrenceId) => occurrenceById.get(occurrenceId))
100
- .filter((occurrence) => occurrence !== undefined);
101
- return {
102
- id,
103
- type: "data_item",
104
- position: positions.get(id) ?? { x: 0, y: 0 },
105
- data: {
106
- label: where ? `${localId(dataItem.id)} (${where})` : localId(dataItem.id),
107
- privacy: { slotStatus: "known", source: "ocsf" },
108
- collected: {
109
- scanPath: dataItem.scanPath,
110
- occurrences: occurrences.map((occurrence) => ({
111
- id: occurrence.id,
112
- filePath: occurrence.filePath,
113
- startLine: occurrence.startLine,
114
- endLine: occurrence.endLine,
115
- })),
116
- },
117
- },
118
- };
119
- }
120
- return {
121
- id,
122
- type: "component",
123
- position: positions.get(id) ?? { x: 0, y: 0 },
124
- data: {
125
- label: id,
126
- privacy: { slotStatus: "known", source: "ocsf" },
127
- },
128
- };
129
- });
130
- const edges = document.dataFlows.map((flow) => {
131
- const knownBits = [
132
- flow.type,
133
- ...(flow.data_categories ?? []),
134
- ...(flow.purpose ? [flow.purpose] : []),
135
- ];
136
- return {
137
- id: flow.id,
138
- source: flow.sourceComponentId,
139
- target: flow.targetComponentId,
140
- type: "data_flow",
141
- data: {
142
- label: knownBits.join(" | "),
143
- narrative: `${flow.sourceComponentId} → ${flow.targetComponentId}`,
144
- privacy: { slotStatus: "known", source: "ocsf" },
145
- },
146
- };
147
- });
148
- const graph = {
149
- nodes,
150
- edges,
151
- viewport: { x: 0, y: 0, zoom: 0.75 },
152
- };
153
- return { graph, d2: renderCollectedD2(graph) };
154
- }
155
- function renderCollectedD2(graph) {
156
- const lines = ["direction: right", ""];
157
- const used = new Map();
158
- function uniqueD2Id(id) {
159
- const base = d2Id(id);
160
- let candidate = base;
161
- let n = 2;
162
- while ([...used.values()].includes(candidate)) {
163
- candidate = `${base}_${n}`;
164
- n += 1;
165
- }
166
- used.set(id, candidate);
167
- return candidate;
168
- }
169
- for (const node of graph.nodes) {
170
- const id = uniqueD2Id(node.id);
171
- const label = String(node.data.label ?? node.id).replace(/\n/g, " ");
172
- lines.push(`${id}: ${JSON.stringify(label)}`);
173
- }
174
- lines.push("");
175
- for (const edge of graph.edges) {
176
- const source = used.get(edge.source) ?? d2Id(edge.source);
177
- const target = used.get(edge.target) ?? d2Id(edge.target);
178
- const label = edge.data?.label ?? "";
179
- lines.push(label ? `${source} -> ${target}: ${JSON.stringify(label)}` : `${source} -> ${target}`);
180
- }
181
- return `${lines.join("\n")}\n`;
182
- }
@@ -1,16 +0,0 @@
1
- import type { OcsfDiscoveryRecord } from "./contract/ocsf-discovery-record";
2
- import { type A0DiscoveriesDocument } from "./contract/discoveries-document.schema";
3
- /** `mention:email:a.ts:3` -> `occurrence:email:a.ts:3`; other ids unchanged. */
4
- export declare function normalizeOccurrenceId(entityId: string): string;
5
- export interface ProjectOcsfToDiscoveriesDocumentInput {
6
- records: OcsfDiscoveryRecord[];
7
- /**
8
- * What to do with an interview answer about an entity the scan no longer has
9
- * (renamed or removed code). `error` (default, the A0 eval's contract) throws;
10
- * `skip` leaves it out of the document and reports it, so one stale answer
11
- * doesn't block a live session. The record itself stays in the KB.
12
- */
13
- orphanInterviewRecords?: "error" | "skip";
14
- onOrphanInterviewRecord?: (record: OcsfDiscoveryRecord) => void;
15
- }
16
- export declare function projectOcsfToDiscoveriesDocument(input: ProjectOcsfToDiscoveriesDocumentInput): A0DiscoveriesDocument;
@@ -1,269 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeOccurrenceId = normalizeOccurrenceId;
4
- exports.projectOcsfToDiscoveriesDocument = projectOcsfToDiscoveriesDocument;
5
- const discoveries_document_schema_1 = require("./contract/discoveries-document.schema");
6
- const load_ocsf_discoveries_1 = require("./load-ocsf-discoveries");
7
- const scan_entity_uri_1 = require("./scan-entity-uri");
8
- const SYSTEM_ASSERTS_URI = "dp:a0/system";
9
- function parseScanEntityId(asserts) {
10
- return (0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)?.entityId ?? null;
11
- }
12
- /** Discoveries written before the mention -> occurrence rename (ontology < 0.4.0). */
13
- const LEGACY_OCCURRENCE_PREFIX = "mention:";
14
- /** `mention:email:a.ts:3` -> `occurrence:email:a.ts:3`; other ids unchanged. */
15
- function normalizeOccurrenceId(entityId) {
16
- return entityId.startsWith(LEGACY_OCCURRENCE_PREFIX)
17
- ? `occurrence:${entityId.slice(LEGACY_OCCURRENCE_PREFIX.length)}`
18
- : entityId;
19
- }
20
- /** A projected id (`<scanPath>::<entityId>` or a bare entity id) with a legacy `mention:` entity renamed. */
21
- function normalizeProjectedOccurrenceId(projectedId) {
22
- const at = projectedId.lastIndexOf("::");
23
- return at === -1
24
- ? normalizeOccurrenceId(projectedId)
25
- : `${projectedId.slice(0, at + 2)}${normalizeOccurrenceId(projectedId.slice(at + 2))}`;
26
- }
27
- function entityKind(entityId) {
28
- if (entityId.startsWith("occurrence:") || entityId.startsWith(LEGACY_OCCURRENCE_PREFIX)) {
29
- return "occurrence";
30
- }
31
- if (entityId.startsWith("data_item:")) {
32
- return "data_item";
33
- }
34
- if (entityId.startsWith("cmp_")) {
35
- return "component";
36
- }
37
- if (entityId.startsWith("flow_")) {
38
- return "flow";
39
- }
40
- return null;
41
- }
42
- function parseJsonArray(raw) {
43
- if (!raw) {
44
- return [];
45
- }
46
- try {
47
- const parsed = JSON.parse(raw);
48
- if (Array.isArray(parsed)) {
49
- return parsed.map(String);
50
- }
51
- }
52
- catch {
53
- return [];
54
- }
55
- return [];
56
- }
57
- function parseCategoriesValue(raw) {
58
- const values = parseJsonArray(raw);
59
- return values.length > 0 ? values : undefined;
60
- }
61
- function parseSourceLocations(raw) {
62
- if (!raw) {
63
- return [];
64
- }
65
- try {
66
- const parsed = JSON.parse(raw);
67
- if (Array.isArray(parsed)) {
68
- return parsed;
69
- }
70
- }
71
- catch {
72
- return [];
73
- }
74
- return [];
75
- }
76
- function parseNumber(raw, fallback = 0) {
77
- if (raw === undefined) {
78
- return fallback;
79
- }
80
- const value = Number(raw);
81
- return Number.isFinite(value) ? value : fallback;
82
- }
83
- function assertsForProjectedId(scanUris, projectedId) {
84
- for (const uri of scanUris) {
85
- const parsed = (0, scan_entity_uri_1.parseScanEntityAsserts)(uri);
86
- if (parsed && (0, scan_entity_uri_1.projectedEntityId)(parsed.scanPath, parsed.entityId) === projectedId) {
87
- return uri;
88
- }
89
- }
90
- throw new Error(`Missing scan entity URI for ${projectedId}`);
91
- }
92
- function scanEntityUrisFromRecords(records) {
93
- const uris = new Set();
94
- for (const record of records) {
95
- if (record.dataparade.source !== "scan") {
96
- continue;
97
- }
98
- const asserts = record.dataparade.asserts;
99
- if ((0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)) {
100
- uris.add(asserts);
101
- }
102
- }
103
- return uris;
104
- }
105
- function projectOcsfToDiscoveriesDocument(input) {
106
- const scanUris = scanEntityUrisFromRecords(input.records);
107
- const slotIndex = (0, load_ocsf_discoveries_1.indexDiscoverySlots)(input.records);
108
- const componentIds = [];
109
- const flowIds = [];
110
- const occurrenceIds = [];
111
- const dataItemIds = [];
112
- for (const uri of scanUris) {
113
- const parsed = (0, scan_entity_uri_1.parseScanEntityAsserts)(uri);
114
- if (!parsed) {
115
- continue;
116
- }
117
- const entityId = (0, scan_entity_uri_1.projectedEntityId)(parsed.scanPath, parsed.entityId);
118
- const kind = entityKind(parsed.entityId);
119
- switch (kind) {
120
- case "component":
121
- componentIds.push(entityId);
122
- break;
123
- case "flow":
124
- flowIds.push(entityId);
125
- break;
126
- case "occurrence":
127
- occurrenceIds.push(entityId);
128
- break;
129
- case "data_item":
130
- dataItemIds.push(entityId);
131
- break;
132
- default:
133
- break;
134
- }
135
- }
136
- componentIds.sort((left, right) => left.localeCompare(right, undefined, { numeric: true }));
137
- flowIds.sort((left, right) => left.localeCompare(right, undefined, { numeric: true }));
138
- occurrenceIds.sort((left, right) => left.localeCompare(right, undefined, { numeric: true }));
139
- dataItemIds.sort((left, right) => left.localeCompare(right, undefined, { numeric: true }));
140
- const components = componentIds.map((id) => {
141
- const asserts = assertsForProjectedId(scanUris, id);
142
- const parsed = (0, scan_entity_uri_1.parseScanEntityAsserts)(asserts);
143
- const scanPath = parsed?.scanPath ?? "";
144
- const actorKind = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "actor_kind");
145
- const dataItemIdsForComponent = parseJsonArray((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "data_item_ids")).map((dataItemId) => (0, scan_entity_uri_1.projectedEntityId)(scanPath, dataItemId));
146
- return {
147
- id,
148
- ...(scanPath ? { scanPath } : {}),
149
- name: (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "name") ?? id,
150
- type: (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "type") ?? "asset",
151
- subType: (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "sub_type") ?? "",
152
- confidence: parseNumber((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "confidence")),
153
- sourceLocations: parseSourceLocations((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "source_locations")),
154
- dataItemIds: dataItemIdsForComponent,
155
- ...(actorKind ? { actor_kind: actorKind } : {}),
156
- };
157
- });
158
- const dataFlows = flowIds.map((id) => {
159
- const asserts = assertsForProjectedId(scanUris, id);
160
- const scanPath = (0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)?.scanPath ?? "";
161
- const categoriesRaw = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "data_categories");
162
- const purpose = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "purpose");
163
- const dataCategories = parseCategoriesValue(categoriesRaw);
164
- const targetScope = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "target_scope");
165
- const sourceComponentId = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "source_component");
166
- const targetComponentId = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "target_component");
167
- if (!sourceComponentId) {
168
- throw new Error(`Flow ${id} missing source_component in scan OCSF`);
169
- }
170
- if (!targetComponentId) {
171
- throw new Error(`Flow ${id} missing target_component in scan OCSF`);
172
- }
173
- return {
174
- id,
175
- ...(scanPath ? { scanPath } : {}),
176
- sourceComponentId: (0, scan_entity_uri_1.projectedEntityId)(scanPath, sourceComponentId),
177
- targetComponentId: (0, scan_entity_uri_1.projectedEntityId)(scanPath, targetComponentId),
178
- type: (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "type") ?? "data_transfer",
179
- confidence: parseNumber((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "confidence")),
180
- ...(targetScope ? { targetScope } : {}),
181
- ...(dataCategories && dataCategories.length > 0 ? { data_categories: dataCategories } : {}),
182
- ...(purpose ? { purpose } : {}),
183
- };
184
- });
185
- const occurrences = occurrenceIds.map((id) => {
186
- const asserts = assertsForProjectedId(scanUris, id);
187
- const scanPath = (0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)?.scanPath ?? "";
188
- const code = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "code");
189
- return {
190
- id: normalizeProjectedOccurrenceId(id),
191
- ...(scanPath ? { scanPath } : {}),
192
- filePath: (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "file_path") ??
193
- (() => {
194
- throw new Error(`Occurrence ${id} missing file_path in scan OCSF`);
195
- })(),
196
- startLine: parseNumber((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "start_line")),
197
- endLine: parseNumber((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "end_line")),
198
- ...(code !== undefined ? { code } : {}),
199
- };
200
- });
201
- const dataItems = dataItemIds.map((id) => {
202
- const asserts = assertsForProjectedId(scanUris, id);
203
- const scanPath = (0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)?.scanPath ?? "";
204
- const projectOccurrence = (occurrenceId) => (0, scan_entity_uri_1.projectedEntityId)(scanPath, normalizeOccurrenceId(occurrenceId));
205
- const occurrenceIdsFromSlot = parseJsonArray((0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "occurrence_ids") ??
206
- (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "mention_ids")).map(projectOccurrence);
207
- const singleOccurrenceId = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "occurrence") ?? (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, asserts, "mention");
208
- const legacyOccurrenceId = singleOccurrenceId ? projectOccurrence(singleOccurrenceId) : undefined;
209
- const occurrenceIds = occurrenceIdsFromSlot.length > 0
210
- ? occurrenceIdsFromSlot
211
- : legacyOccurrenceId
212
- ? [legacyOccurrenceId]
213
- : (() => {
214
- throw new Error(`Data item ${id} missing occurrence_ids in scan OCSF`);
215
- })();
216
- return {
217
- id,
218
- ...(scanPath ? { scanPath } : {}),
219
- occurrenceIds,
220
- };
221
- });
222
- const inScope = (0, load_ocsf_discoveries_1.discoveryValue)(slotIndex, SYSTEM_ASSERTS_URI, "in_scope");
223
- const document = {
224
- components,
225
- dataFlows,
226
- dataItems,
227
- occurrences,
228
- ...(inScope ? { system: { in_scope: inScope } } : {}),
229
- };
230
- for (const record of input.records) {
231
- if (record.dataparade.source !== "interview") {
232
- continue;
233
- }
234
- const asserts = record.dataparade.asserts;
235
- if (asserts === SYSTEM_ASSERTS_URI) {
236
- const slot = record.dataparade.asserted_slot;
237
- if (slot && slot !== "in_scope") {
238
- throw new Error(`Interview system overlay ${record.metadata.uid} only allows in_scope; got ${slot}`);
239
- }
240
- continue;
241
- }
242
- if (!(0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)) {
243
- throw new Error(`Interview record ${record.metadata.uid} asserts unsupported URI ${asserts}`);
244
- }
245
- if (!record.dataparade.asserted_slot) {
246
- throw new Error(`Interview record ${record.metadata.uid} must not assert scan entity existence`);
247
- }
248
- if (!scanUris.has(asserts)) {
249
- if (input.orphanInterviewRecords === "skip") {
250
- input.onOrphanInterviewRecord?.(record);
251
- continue;
252
- }
253
- throw new Error(`Interview record ${record.metadata.uid} must not create ${asserts}`);
254
- }
255
- const entityId = parseScanEntityId(asserts);
256
- const kind = entityId ? entityKind(entityId) : null;
257
- const slot = record.dataparade.asserted_slot;
258
- const allowed = (kind === "component" && slot === "actor_kind") ||
259
- (kind === "flow" && (slot === "data_categories" || slot === "purpose"));
260
- if (!allowed) {
261
- throw new Error(`Interview overlay ${record.metadata.uid} slot '${slot}' is not allowed on ${asserts}`);
262
- }
263
- }
264
- const validation = (0, discoveries_document_schema_1.validateA0DiscoveriesDocument)(document);
265
- if (!validation.ok) {
266
- throw new Error(`Invalid A0 discoveries document: ${validation.errors.join("; ")}`);
267
- }
268
- return validation.value;
269
- }
@@ -1,13 +0,0 @@
1
- import type { OrchestratorScanResult } from "../core/pipeline/orchestrator-result";
2
- import type { ScanResult } from "../core/types/result";
3
- import type { ScanDiscoveryInput } from "./scan-discovery-input";
4
- export interface DiscoverySeedLike {
5
- components: ScanDiscoveryInput["components"];
6
- dataFlows: Array<ScanDiscoveryInput["dataFlows"][number] & {
7
- sourceLocation?: ScanDiscoveryInput["components"][number]["sourceLocations"][number];
8
- sourceLocations?: ScanDiscoveryInput["components"][number]["sourceLocations"];
9
- }>;
10
- }
11
- export declare function discoverySeedToDiscoveryInput(seed: DiscoverySeedLike): ScanDiscoveryInput;
12
- export declare function scanResultToDiscoveryInput(scanResult: ScanResult, personalData?: Pick<OrchestratorScanResult, "occurrences" | "dataItems">): ScanDiscoveryInput;
13
- export declare function orchestratorScanResultToDiscoveryInput(result: OrchestratorScanResult): ScanDiscoveryInput;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.discoverySeedToDiscoveryInput = discoverySeedToDiscoveryInput;
4
- exports.scanResultToDiscoveryInput = scanResultToDiscoveryInput;
5
- exports.orchestratorScanResultToDiscoveryInput = orchestratorScanResultToDiscoveryInput;
6
- function discoverySeedToDiscoveryInput(seed) {
7
- return {
8
- components: seed.components,
9
- dataFlows: seed.dataFlows.map(({ sourceLocation: _sourceLocation, sourceLocations: _sourceLocations, ...flow }) => flow),
10
- occurrences: [],
11
- dataItems: [],
12
- };
13
- }
14
- function scanResultToDiscoveryInput(scanResult, personalData = {
15
- occurrences: [],
16
- dataItems: [],
17
- }) {
18
- return {
19
- components: scanResult.components.map((component) => ({
20
- id: component.id,
21
- name: component.name,
22
- type: component.type,
23
- subType: component.subType ?? "",
24
- confidence: component.confidence,
25
- sourceLocations: component.sourceLocations.map((location) => ({
26
- filePath: location.filePath,
27
- startLine: location.startLine,
28
- endLine: location.endLine,
29
- ...(location.code !== undefined ? { code: location.code } : {}),
30
- })),
31
- })),
32
- dataFlows: scanResult.dataFlows.map((flow) => ({
33
- id: flow.id,
34
- sourceComponentId: flow.sourceComponentId,
35
- targetComponentId: flow.targetComponentId,
36
- type: flow.type,
37
- confidence: flow.confidence,
38
- ...(flow.targetScope !== undefined ? { targetScope: flow.targetScope } : {}),
39
- })),
40
- occurrences: personalData.occurrences.map((occurrence) => ({
41
- id: occurrence.id,
42
- filePath: occurrence.filePath,
43
- startLine: occurrence.startLine,
44
- endLine: occurrence.endLine,
45
- labels: [...occurrence.labels],
46
- ...(occurrence.code !== undefined ? { code: occurrence.code } : {}),
47
- })),
48
- dataItems: personalData.dataItems.map((dataItem) => ({
49
- id: dataItem.id,
50
- occurrenceIds: [...dataItem.occurrenceIds],
51
- labels: [...dataItem.labels],
52
- })),
53
- };
54
- }
55
- function orchestratorScanResultToDiscoveryInput(result) {
56
- return scanResultToDiscoveryInput(result.scanResult, {
57
- occurrences: result.occurrences ?? [],
58
- dataItems: result.dataItems ?? [],
59
- });
60
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Knowledge graph next to dataflow.json (scanner KDATAP-a528cd, KDATAP-d3e0bc).
3
- *
4
- * graphify maps the code structure (graphify-out/graph.json); the scanner adds
5
- * DataParade's privacy and security layer in the same NetworkX node-link format
6
- * (dataparade-graph.json), with edges that point at graphify's nodes. Loaded
7
- * together, they are one connected graph from data flows down to the functions and
8
- * lines that handle each data item. graphify is optional: without it, only
9
- * dataparade-graph.json is written. Problems here are warnings; they never fail the
10
- * scan or block dataflow.json.
11
- */
12
- import { type OrchestratorScanResult } from '../../vendor/scanner/dist/src/index.js';
13
- import { type DataflowHierarchy } from './c4-hierarchy';
14
- /**
15
- * C4 hierarchy for `dataflow.json` metadata, from the knowledge graph built in
16
- * memory (it does not need graphify or the file on disk). Never throws: on any
17
- * problem it warns and returns undefined, and the scan continues without it.
18
- */
19
- export declare function buildScanHierarchy(result: OrchestratorScanResult, graphNodeIds: Iterable<string>): Promise<DataflowHierarchy | undefined>;
20
- export declare function writeScanKnowledgeGraph(result: OrchestratorScanResult, scanRoot: string, outDir: string): Promise<void>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildScanHierarchy = buildScanHierarchy;
4
- exports.writeScanKnowledgeGraph = writeScanKnowledgeGraph;
5
- /**
6
- * Knowledge graph next to dataflow.json (scanner KDATAP-a528cd, KDATAP-d3e0bc).
7
- *
8
- * graphify maps the code structure (graphify-out/graph.json); the scanner adds
9
- * DataParade's privacy and security layer in the same NetworkX node-link format
10
- * (dataparade-graph.json), with edges that point at graphify's nodes. Loaded
11
- * together, they are one connected graph from data flows down to the functions and
12
- * lines that handle each data item. graphify is optional: without it, only
13
- * dataparade-graph.json is written. Problems here are warnings; they never fail the
14
- * scan or block dataflow.json.
15
- */
16
- const scanner_1 = require("../../vendor/scanner/dist/src/index.js");
17
- const c4_hierarchy_1 = require("./c4-hierarchy");
18
- /**
19
- * C4 hierarchy for `dataflow.json` metadata, from the knowledge graph built in
20
- * memory (it does not need graphify or the file on disk). Never throws: on any
21
- * problem it warns and returns undefined, and the scan continues without it.
22
- */
23
- async function buildScanHierarchy(result, graphNodeIds) {
24
- try {
25
- const knowledgeGraph = await (0, scanner_1.buildDataParadeGraph)(result);
26
- return (0, c4_hierarchy_1.buildDataflowHierarchy)(knowledgeGraph, graphNodeIds);
27
- }
28
- catch (error) {
29
- // eslint-disable-next-line no-console
30
- console.warn(`[scan] warning: C4 hierarchy not computed: ${error instanceof Error ? error.message : String(error)}`);
31
- return undefined;
32
- }
33
- }
34
- async function writeScanKnowledgeGraph(result, scanRoot, outDir) {
35
- try {
36
- const structure = await (0, scanner_1.runGraphify)(scanRoot, { outDir });
37
- for (const warning of structure.warnings) {
38
- // eslint-disable-next-line no-console
39
- console.warn(`[scan] ${warning}`);
40
- }
41
- const written = await (0, scanner_1.writeKnowledgeGraph)(structure.info ? { ...result, structureGraph: structure.info } : result, outDir);
42
- if (written.structureGraph) {
43
- // eslint-disable-next-line no-console
44
- console.log(`[scan] code-structure graph (graphify ${structure.info?.version}) written to ${written.structureGraph}`);
45
- }
46
- // eslint-disable-next-line no-console
47
- console.log(`[scan] knowledge graph written to ${written.dataparadeGraph}`);
48
- }
49
- catch (error) {
50
- // eslint-disable-next-line no-console
51
- console.warn(`[scan] warning: knowledge graph not written: ${error instanceof Error ? error.message : String(error)}`);
52
- }
53
- }
@@ -1,17 +0,0 @@
1
- import type { OrchestratorScanResult } from "../core/pipeline/orchestrator-result";
2
- export declare const SCAN_OCSF_DISCOVERIES_DIRNAME = "ocsf-discoveries";
3
- export declare const SCAN_DATAPARADE_JSON_BASENAME = "dataparade.json";
4
- export declare const SCAN_COLLECTED_DIAGRAM_JSON_BASENAME = "discoveries-diagram.json";
5
- export declare const SCAN_COLLECTED_DIAGRAM_D2_BASENAME = "discoveries-diagram.d2";
6
- export interface ScanDiscoveriesOutputPaths {
7
- ocsfDiscoveriesDir: string;
8
- dataparadeJsonPath: string;
9
- collectedDiagramJsonPath: string;
10
- collectedDiagramD2Path: string;
11
- }
12
- export declare function resolveScanDiscoveriesOutputPaths(dataflowOutputPath: string): ScanDiscoveriesOutputPaths;
13
- export interface WriteScanDiscoveriesOptions {
14
- assertedAt?: string;
15
- scanRootDir: string;
16
- }
17
- export declare function writeScanDiscoveriesArtifacts(scanResult: OrchestratorScanResult, dataflowOutputPath: string, options: WriteScanDiscoveriesOptions): ScanDiscoveriesOutputPaths;