@dataparade/cli 0.0.25 → 0.0.28

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 (113) hide show
  1. package/LICENSE +202 -674
  2. package/NOTICE +5 -0
  3. package/README.md +54 -14
  4. package/dist/package.json +9 -8
  5. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +0 -1
  6. package/dist/src/cli.js +37 -37
  7. package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +1 -1
  8. package/dist/src/discoveries/load-ocsf-discoveries.d.ts +0 -8
  9. package/dist/src/discoveries/load-ocsf-discoveries.js +0 -31
  10. package/dist/src/discoveries/write-ocsf-discoveries.d.ts +0 -8
  11. package/dist/src/discoveries/write-ocsf-discoveries.js +0 -38
  12. package/dist/src/evals/run-model-matrix.js +0 -1
  13. package/dist/src/export/export-ocsf.d.ts +18 -0
  14. package/dist/src/export/export-ocsf.js +104 -0
  15. package/dist/src/export/register-export-commands.d.ts +2 -0
  16. package/dist/src/export/register-export-commands.js +30 -0
  17. package/dist/src/facts/apply-answers.d.ts +29 -0
  18. package/dist/src/facts/apply-answers.js +202 -0
  19. package/dist/src/facts/build-facts.d.ts +24 -0
  20. package/dist/src/facts/build-facts.js +198 -0
  21. package/dist/src/facts/io.d.ts +17 -0
  22. package/dist/src/facts/io.js +67 -0
  23. package/dist/src/facts/layout.d.ts +29 -0
  24. package/dist/src/facts/layout.js +38 -0
  25. package/dist/src/facts/schema.d.ts +265 -0
  26. package/dist/src/facts/schema.js +122 -0
  27. package/dist/src/facts/slug.d.ts +7 -0
  28. package/dist/src/facts/slug.js +47 -0
  29. package/dist/src/kb/brief.d.ts +1 -2
  30. package/dist/src/kb/brief.js +2 -4
  31. package/dist/src/kb/interview-record.d.ts +18 -0
  32. package/dist/src/kb/interview-record.js +70 -0
  33. package/dist/src/kb/kb-store.d.ts +24 -18
  34. package/dist/src/kb/kb-store.js +89 -28
  35. package/dist/src/kb/land.d.ts +32 -12
  36. package/dist/src/kb/land.js +97 -90
  37. package/dist/src/kb/migrate.d.ts +23 -0
  38. package/dist/src/kb/migrate.js +91 -0
  39. package/dist/src/kb/project-diagram.js +4 -4
  40. package/dist/src/kb/register-kb-commands.js +71 -20
  41. package/dist/src/observability/scan-sentry.js +0 -1
  42. package/dist/src/output/scan-output-excludes.d.ts +1 -1
  43. package/dist/src/output/scan-output-excludes.js +14 -5
  44. package/dist/src/output/write-scan-knowledge.d.ts +33 -0
  45. package/dist/src/output/write-scan-knowledge.js +115 -0
  46. package/dist/src/platform-api/estimate-scan-footprint.d.ts +31 -0
  47. package/dist/src/platform-api/estimate-scan-footprint.js +75 -2
  48. package/dist/src/ui/scan-progress-renderer.d.ts +2 -0
  49. package/dist/src/ui/scan-progress-renderer.js +10 -0
  50. package/dist/src/ui/teaching-lines.js +18 -6
  51. package/dist/src/upload/collect-scan-sidecars.d.ts +2 -27
  52. package/dist/src/upload/collect-scan-sidecars.js +25 -121
  53. package/dist/src/upload/run-upload.js +0 -3
  54. package/dist/tests/cli/cli.spec.js +30 -13
  55. package/dist/tests/helpers/facts-fixture.d.ts +9 -0
  56. package/dist/tests/helpers/facts-fixture.js +72 -0
  57. package/dist/tests/unit/export/export-ocsf.spec.js +72 -0
  58. package/dist/tests/unit/facts/apply-answers.spec.js +128 -0
  59. package/dist/tests/unit/facts/build-facts.spec.d.ts +1 -0
  60. package/dist/tests/unit/facts/build-facts.spec.js +161 -0
  61. package/dist/tests/unit/facts/slug.spec.d.ts +1 -0
  62. package/dist/tests/unit/facts/slug.spec.js +30 -0
  63. package/dist/tests/unit/kb/kb-interview-loop.spec.js +83 -35
  64. package/dist/tests/unit/kb/migrate.spec.d.ts +1 -0
  65. package/dist/tests/unit/kb/migrate.spec.js +108 -0
  66. package/dist/tests/unit/output/graphify-cache-dir.spec.d.ts +1 -0
  67. package/dist/tests/unit/output/graphify-cache-dir.spec.js +20 -0
  68. package/dist/tests/unit/output/scan-output-excludes.spec.js +4 -2
  69. package/dist/tests/unit/platform-api/estimate-scan-footprint.spec.js +77 -0
  70. package/dist/tests/unit/platform-api/upload-client.spec.js +2 -2
  71. package/dist/tests/unit/ui/teaching-lines.spec.js +16 -0
  72. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +46 -46
  73. package/dist/tests/unit/upload/pack-scan-upload.spec.js +6 -6
  74. package/dist/vendor/scanner/LICENSE +202 -674
  75. package/dist/vendor/scanner/NOTICE +4 -0
  76. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +6 -14
  77. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +1 -0
  78. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +32 -1
  79. package/dist/vendor/scanner/dist/src/classifier/naming.d.ts +5 -0
  80. package/dist/vendor/scanner/dist/src/classifier/naming.js +8 -4
  81. package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +26 -14
  82. package/dist/vendor/scanner/dist/src/core/pipeline/enrich-personal-data-layers.js +3 -1
  83. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +18 -0
  84. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +125 -66
  85. package/dist/vendor/scanner/dist/src/index.d.ts +2 -0
  86. package/dist/vendor/scanner/dist/src/index.js +7 -2
  87. package/dist/vendor/scanner/dist/src/ingest/file-system.d.ts +5 -0
  88. package/dist/vendor/scanner/dist/src/ingest/file-system.js +5 -0
  89. package/dist/vendor/scanner/dist/src/ingest/gitignore.d.ts +17 -0
  90. package/dist/vendor/scanner/dist/src/ingest/gitignore.js +47 -9
  91. package/dist/vendor/scanner/dist/src/ingest/schema-files.d.ts +10 -2
  92. package/dist/vendor/scanner/dist/src/ingest/schema-files.js +24 -7
  93. package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.d.ts +3 -0
  94. package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.js +45 -0
  95. package/dist/vendor/scanner/dist/src/patterns/scan-exclusions.js +7 -0
  96. package/dist/vendor/scanner/package.json +1 -1
  97. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +8 -0
  98. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +9 -0
  99. package/package.json +9 -8
  100. package/dist/src/discoveries/project-collected-diagram.d.ts +0 -7
  101. package/dist/src/discoveries/project-collected-diagram.js +0 -182
  102. package/dist/src/discoveries/project-ocsf-to-discoveries-document.d.ts +0 -16
  103. package/dist/src/discoveries/project-ocsf-to-discoveries-document.js +0 -269
  104. package/dist/src/discoveries/scan-result-to-discovery-input.d.ts +0 -13
  105. package/dist/src/discoveries/scan-result-to-discovery-input.js +0 -60
  106. package/dist/src/output/write-knowledge-graph.d.ts +0 -20
  107. package/dist/src/output/write-knowledge-graph.js +0 -53
  108. package/dist/src/output/write-scan-discoveries.d.ts +0 -17
  109. package/dist/src/output/write-scan-discoveries.js +0 -61
  110. package/dist/tests/unit/discoveries/project-collected-diagram.spec.js +0 -97
  111. package/dist/tests/unit/discoveries/rescan-replaces-scan-records.spec.js +0 -89
  112. /package/dist/tests/unit/{discoveries/project-collected-diagram.spec.d.ts → export/export-ocsf.spec.d.ts} +0 -0
  113. /package/dist/tests/unit/{discoveries/rescan-replaces-scan-records.spec.d.ts → facts/apply-answers.spec.d.ts} +0 -0
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.toPosixPath = toPosixPath;
37
37
  exports.gitignorePatternToRegex = gitignorePatternToRegex;
38
+ exports.gitignoreLineToRegex = gitignoreLineToRegex;
38
39
  exports.readGitignore = readGitignore;
39
40
  exports.gitignoreRulesForDir = gitignoreRulesForDir;
40
41
  exports.isPathIgnored = isPathIgnored;
@@ -43,20 +44,55 @@ const path = __importStar(require("path"));
43
44
  function toPosixPath(p) {
44
45
  return p.split(path.sep).join("/");
45
46
  }
46
- function gitignorePatternToRegex(pattern, dirOnly) {
47
- // Very small subset of .gitignore-style patterns:
48
- // - * matches any chars except path separator
49
- // - ** matches across directories
50
- // - ? matches a single non-separator
51
- // - pattern without leading slash matches anywhere under baseDir
47
+ function globToRegexBody(pattern) {
52
48
  let escaped = pattern.replace(/[-\\^$+?.()|[\]{}*?]/g, "\\$&");
53
49
  // Restore globs
54
50
  escaped = escaped.replace(/\\\*\\\*/g, ".*"); // **
55
51
  escaped = escaped.replace(/\\\*/g, "[^/]*"); // *
56
52
  escaped = escaped.replace(/\\\?/g, "[^/]"); // ?
53
+ return escaped;
54
+ }
55
+ /**
56
+ * Glob to regex for user exclude patterns, matched against the path relative to the
57
+ * scan root:
58
+ * - * matches any chars except path separator
59
+ * - ** matches across directories
60
+ * - ? matches a single non-separator
61
+ */
62
+ function gitignorePatternToRegex(pattern, dirOnly) {
57
63
  const suffix = dirOnly ? "(?:/.*)?$" : "$";
58
64
  // Match from start of the relative path
59
- return new RegExp(`^${escaped}${suffix}`);
65
+ return new RegExp(`^${globToRegexBody(pattern)}${suffix}`);
66
+ }
67
+ /**
68
+ * Regex for one `.gitignore` line, matched against the path relative to the
69
+ * `.gitignore`'s directory, following git's rules:
70
+ * - a leading `/` anchors the pattern to that directory;
71
+ * - a pattern with no other `/` matches a name at any depth (`build`, `*.log`);
72
+ * - a pattern with a `/` in the middle is anchored (`src/gen`);
73
+ * - a leading or inner `**` segment matches zero or more directories.
74
+ * A match on a directory also ignores everything under it.
75
+ */
76
+ function gitignoreLineToRegex(line) {
77
+ let pattern = toPosixPath(line);
78
+ let anchored = false;
79
+ if (pattern.startsWith("/")) {
80
+ anchored = true;
81
+ pattern = pattern.replace(/^\/+/, "");
82
+ }
83
+ else if (pattern.startsWith("**/")) {
84
+ pattern = pattern.slice(3);
85
+ }
86
+ else if (pattern.includes("/")) {
87
+ anchored = true;
88
+ }
89
+ let body = globToRegexBody(pattern);
90
+ // `a/**/b` also matches `a/b`.
91
+ body = body.replace(/\/\.\*\//g, "/(?:.*/)?");
92
+ const prefix = anchored ? "" : "(?:.*/)?";
93
+ // `dirOnly` rules are only applied to directories (see isPathIgnored); either kind
94
+ // also covers what lies under the matched path.
95
+ return new RegExp(`^${prefix}${body}(?:/.*)?$`);
60
96
  }
61
97
  async function readGitignore(dir) {
62
98
  const gitignorePath = path.join(dir, ".gitignore");
@@ -82,7 +118,7 @@ async function readGitignore(dir) {
82
118
  if (!line)
83
119
  continue;
84
120
  }
85
- const regex = gitignorePatternToRegex(toPosixPath(line), dirOnly);
121
+ const regex = gitignoreLineToRegex(line);
86
122
  rules.push({
87
123
  baseDir: dir,
88
124
  pattern: line,
@@ -103,7 +139,9 @@ async function readGitignore(dir) {
103
139
  }
104
140
  async function gitignoreRulesForDir(currentDir, accumulatedRules) {
105
141
  const localRules = await readGitignore(currentDir);
106
- return accumulatedRules.concat(localRules);
142
+ // Most directories have no .gitignore: share the parent's array instead of copying it
143
+ // once per directory.
144
+ return localRules.length === 0 ? accumulatedRules : accumulatedRules.concat(localRules);
107
145
  }
108
146
  function isPathIgnored(absolutePath, isDirectory, rules) {
109
147
  const normalizedPath = toPosixPath(absolutePath);
@@ -12,5 +12,13 @@ export interface SchemaFile {
12
12
  kind: "prisma" | "sql" | "rails" | "laravel";
13
13
  }
14
14
  export declare function schemaFileKind(filePath: string): SchemaFile["kind"] | undefined;
15
- /** Every `*.prisma` and `*.sql` file under the root, outside excluded, test and fixture directories. */
16
- export declare function readSchemaFiles(rootPath: string): Promise<SchemaFile[]>;
15
+ export interface ReadSchemaFilesOptions {
16
+ /** The scan's exclude patterns (`--exclude`); the default file globs are always added. */
17
+ excludePaths?: readonly string[];
18
+ }
19
+ /**
20
+ * Every `*.prisma` and `*.sql` file under the root, outside excluded, test and fixture
21
+ * directories. Uses the same pruning as ingest: default excluded directories, the exclude
22
+ * patterns and `.gitignore` are applied to each directory before it is entered.
23
+ */
24
+ export declare function readSchemaFiles(rootPath: string, options?: ReadSchemaFilesOptions): Promise<SchemaFile[]>;
@@ -38,6 +38,7 @@ exports.readSchemaFiles = readSchemaFiles;
38
38
  const fs_1 = require("fs");
39
39
  const path = __importStar(require("path"));
40
40
  const scan_exclusions_1 = require("../patterns/scan-exclusions");
41
+ const file_system_1 = require("./file-system");
41
42
  const gitignore_1 = require("./gitignore");
42
43
  const MAX_SCHEMA_FILE_BYTES = 2 * 1024 * 1024;
43
44
  const MAX_SCHEMA_FILES = 5_000;
@@ -61,15 +62,22 @@ function schemaFileKind(filePath) {
61
62
  return "laravel";
62
63
  return undefined;
63
64
  }
64
- /** Every `*.prisma` and `*.sql` file under the root, outside excluded, test and fixture directories. */
65
- async function readSchemaFiles(rootPath) {
65
+ /**
66
+ * Every `*.prisma` and `*.sql` file under the root, outside excluded, test and fixture
67
+ * directories. Uses the same pruning as ingest: default excluded directories, the exclude
68
+ * patterns and `.gitignore` are applied to each directory before it is entered.
69
+ */
70
+ async function readSchemaFiles(rootPath, options = {}) {
66
71
  const root = path.resolve(rootPath);
72
+ const excludePaths = [...scan_exclusions_1.DEFAULT_EXCLUDED_FILE_GLOBS, ...(options.excludePaths ?? [])];
67
73
  const out = [];
68
- const walk = async (dir) => {
74
+ const walk = async (dir, parentRules) => {
69
75
  if (out.length >= MAX_SCHEMA_FILES)
70
76
  return;
71
77
  let entries;
78
+ let rules;
72
79
  try {
80
+ rules = await (0, gitignore_1.gitignoreRulesForDir)(dir, parentRules);
73
81
  entries = await fs_1.promises.readdir(dir, { withFileTypes: true });
74
82
  }
75
83
  catch {
@@ -78,20 +86,29 @@ async function readSchemaFiles(rootPath) {
78
86
  entries.sort((a, b) => a.name.localeCompare(b.name));
79
87
  for (const entry of entries) {
80
88
  const full = path.join(dir, entry.name);
89
+ const rel = (0, gitignore_1.toPosixPath)(path.relative(root, full));
81
90
  if (entry.isDirectory()) {
82
91
  if ((0, scan_exclusions_1.shouldSkipDirectoryName)(entry.name) || NON_APP_DIR.test(entry.name))
83
92
  continue;
84
- await walk(full);
93
+ if ((0, file_system_1.isExcludedByUserPatterns)(rel, true, excludePaths))
94
+ continue;
95
+ if ((0, gitignore_1.isPathIgnored)(full, true, rules))
96
+ continue;
97
+ await walk(full, rules);
85
98
  }
86
99
  else if (entry.isFile()) {
87
- const kind = schemaFileKind(path.relative(root, full));
100
+ const kind = schemaFileKind(rel);
88
101
  if (!kind)
89
102
  continue;
103
+ if ((0, file_system_1.isExcludedByUserPatterns)(rel, false, excludePaths))
104
+ continue;
105
+ if ((0, gitignore_1.isPathIgnored)(full, false, rules))
106
+ continue;
90
107
  try {
91
108
  const stat = await fs_1.promises.stat(full);
92
109
  if (stat.size > MAX_SCHEMA_FILE_BYTES)
93
110
  continue;
94
- out.push({ path: (0, gitignore_1.toPosixPath)(path.relative(root, full)), content: await fs_1.promises.readFile(full, "utf8"), kind });
111
+ out.push({ path: rel, content: await fs_1.promises.readFile(full, "utf8"), kind });
95
112
  }
96
113
  catch {
97
114
  /* unreadable files are skipped */
@@ -101,6 +118,6 @@ async function readSchemaFiles(rootPath) {
101
118
  }
102
119
  }
103
120
  };
104
- await walk(root);
121
+ await walk(root, []);
105
122
  return out;
106
123
  }
@@ -2,3 +2,6 @@ export declare const FRONTEND_FRAMEWORK_HINTS: readonly ["next_or_react_route",
2
2
  export declare const FRONTEND_FRAMEWORK_HINTS_SET: Set<string>;
3
3
  export declare const PREFERRED_WEB_APP_FRAMEWORKS: Set<string>;
4
4
  export declare const SERVER_FRAMEWORK_HINTS: Set<string>;
5
+ export declare function canonicalFrameworkId(framework: string): string;
6
+ /** Human-readable framework label, identical for every alias of one framework. */
7
+ export declare function frameworkDisplayName(framework: string): string;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SERVER_FRAMEWORK_HINTS = exports.PREFERRED_WEB_APP_FRAMEWORKS = exports.FRONTEND_FRAMEWORK_HINTS_SET = exports.FRONTEND_FRAMEWORK_HINTS = void 0;
4
+ exports.canonicalFrameworkId = canonicalFrameworkId;
5
+ exports.frameworkDisplayName = frameworkDisplayName;
4
6
  exports.FRONTEND_FRAMEWORK_HINTS = [
5
7
  "next_or_react_route",
6
8
  "nextjs",
@@ -23,3 +25,46 @@ exports.SERVER_FRAMEWORK_HINTS = new Set([
23
25
  "express",
24
26
  "serverless",
25
27
  ]);
28
+ /**
29
+ * Canonical framework ids. Detectors emit different spellings for the same
30
+ * framework (`next_or_react_route` from route-handler files, `nextjs` from the
31
+ * `next` dependency); both resolve to one id here.
32
+ */
33
+ const FRAMEWORK_ALIASES = {
34
+ next_or_react_route: "nextjs",
35
+ next: "nextjs",
36
+ "next.js": "nextjs",
37
+ nextjs: "nextjs",
38
+ };
39
+ const FRAMEWORK_DISPLAY_NAMES = {
40
+ nextjs: "Next.js",
41
+ react: "React",
42
+ vue: "Vue",
43
+ angular: "Angular",
44
+ ionic: "Ionic",
45
+ electron: "Electron",
46
+ svelte: "Svelte",
47
+ solid: "Solid",
48
+ qwik: "Qwik",
49
+ express: "Express",
50
+ nest: "Nest",
51
+ fastapi: "FastAPI",
52
+ flask: "Flask",
53
+ django: "Django",
54
+ };
55
+ function canonicalFrameworkId(framework) {
56
+ const key = framework.trim().toLowerCase();
57
+ return FRAMEWORK_ALIASES[key] ?? key;
58
+ }
59
+ /** Human-readable framework label, identical for every alias of one framework. */
60
+ function frameworkDisplayName(framework) {
61
+ const id = canonicalFrameworkId(framework);
62
+ const known = FRAMEWORK_DISPLAY_NAMES[id];
63
+ if (known)
64
+ return known;
65
+ return id
66
+ .split(/[\s_-]+/)
67
+ .filter(Boolean)
68
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
69
+ .join(" ");
70
+ }
@@ -17,7 +17,14 @@ exports.DEFAULT_EXCLUDED_DIRS = new Set([
17
17
  ".git",
18
18
  "dist",
19
19
  "build",
20
+ // Framework build output and tool caches. Hidden directories are skipped anyway (see
21
+ // shouldSkipDirectoryName); they are listed so the default stays explicit.
20
22
  ".next",
23
+ ".nuxt",
24
+ ".svelte-kit",
25
+ ".turbo",
26
+ ".vercel",
27
+ ".cache",
21
28
  "out",
22
29
  "coverage",
23
30
  ".vscode",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dataparade/scanner",
3
3
  "version": "0.0.1",
4
- "license": "GPL-3.0-or-later",
4
+ "license": "Apache-2.0",
5
5
  "description": "Vendored build of @dataparade/scanner bundled into @dataparade/cli",
6
6
  "main": "dist/src/index.js"
7
7
  }
@@ -53,6 +53,14 @@ third_parties:
53
53
  type: third_party
54
54
  subType: saas_service
55
55
 
56
+ - serviceName: notion
57
+ matchKeys:
58
+ - "@notionhq/client"
59
+ - "notion.so"
60
+ - "notion.com"
61
+ type: third_party
62
+ subType: saas_service
63
+
56
64
  - serviceName: google_identity
57
65
  matchKeys:
58
66
  - google_identity
@@ -57,6 +57,15 @@ services:
57
57
  - api.twitter.com
58
58
  - x.com
59
59
  - api.x.com
60
+ - serviceName: notion
61
+ patternId: external_api_call
62
+ importFragments:
63
+ - "@notionhq/client"
64
+ confidence: 0.85
65
+ url_host_patterns:
66
+ - notion.so
67
+ - notion.com
68
+ - api.notion.com
60
69
  - serviceName: google_identity
61
70
  patternId: external_api_call
62
71
  importFragments:
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.25",
3
+ "version": "0.0.28",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/"
8
8
  },
9
- "license": "GPL-3.0-or-later",
9
+ "license": "Apache-2.0",
10
10
  "author": "DataParade",
11
11
  "homepage": "https://dataparade.io",
12
12
  "repository": {
@@ -56,9 +56,9 @@
56
56
  "dependencies": {
57
57
  "@clack/prompts": "^1.8.1",
58
58
  "@sentry/node": "^10.38.0",
59
- "commander": "^12.1.0",
59
+ "commander": "^14.0.3",
60
60
  "dotenv": "^16.4.7",
61
- "langsmith": "^0.3.14",
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,19 +66,20 @@
66
66
  "zod": "^4.3.5"
67
67
  },
68
68
  "devDependencies": {
69
- "@dataparade/scanner": "github:DataParade-io/scanner#8133cd81f377d5a6a80a84fa0eb41b0c85d26087",
69
+ "@dataparade/scanner": "github:DataParade-io/scanner#a08a57b046b7b6be0afd84b7866432e6242d216a",
70
70
  "@eslint/js": "^9.18.0",
71
- "@types/jest": "^29.5.14",
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": "^29.7.0",
76
- "ts-jest": "^29.2.5",
75
+ "jest": "^30.5.2",
76
+ "ts-jest": "^29.4.6",
77
77
  "typescript-eslint": "^8.20.0"
78
78
  },
79
79
  "files": [
80
80
  "dist",
81
81
  "LICENSE",
82
+ "NOTICE",
82
83
  "README.md",
83
84
  "package.json"
84
85
  ]
@@ -1,7 +0,0 @@
1
- import type { DiagramGraphJsonSchema } from "../core/schema/diagram-graph.schema";
2
- import type { A0DiscoveriesDocument } from "./contract/discoveries-document.schema";
3
- export interface CollectedDiagram {
4
- graph: DiagramGraphJsonSchema;
5
- d2: string;
6
- }
7
- export declare function projectCollectedDiscoveriesDiagram(document: A0DiscoveriesDocument): CollectedDiagram;
@@ -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;