@dataparade/cli 0.0.31 → 0.0.32

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 (49) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/ai-enrichment/fallbacks.js +12 -1
  3. package/dist/src/cli.js +3 -0
  4. package/dist/src/core/pipeline/omit-internal-implementation.js +13 -6
  5. package/dist/src/output/git-context.d.ts +17 -0
  6. package/dist/src/output/git-context.js +104 -0
  7. package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +30 -0
  8. package/dist/tests/unit/core/omit-internal-implementation.spec.js +21 -0
  9. package/dist/tests/unit/output/git-context.spec.d.ts +1 -0
  10. package/dist/tests/unit/output/git-context.spec.js +79 -0
  11. package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.d.ts +11 -0
  12. package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.js +2 -0
  13. package/dist/vendor/scanner/dist/src/analyzers/registry.d.ts +2 -0
  14. package/dist/vendor/scanner/dist/src/analyzers/registry.js +3 -2
  15. package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.d.ts +17 -0
  16. package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.js +11 -0
  17. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +33 -3
  18. package/dist/vendor/scanner/dist/src/classifier/enhance.js +14 -0
  19. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +8 -0
  20. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +43 -2
  21. package/dist/vendor/scanner/dist/src/classifier/postprocessing.js +4 -1
  22. package/dist/vendor/scanner/dist/src/config/third-party-detection-config.d.ts +41 -0
  23. package/dist/vendor/scanner/dist/src/config/third-party-detection-config.js +65 -1
  24. package/dist/vendor/scanner/dist/src/core/pipeline/structural-scan.js +2 -0
  25. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.d.ts +5 -0
  26. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.js +10 -2
  27. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/data-flows.js +4 -4
  28. package/dist/vendor/scanner/dist/src/patterns/config.js +7 -1
  29. package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.d.ts +14 -0
  30. package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.js +108 -0
  31. package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.d.ts +93 -0
  32. package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.js +1206 -0
  33. package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.d.ts +180 -0
  34. package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.js +1022 -0
  35. package/dist/vendor/scanner/dist/src/patterns/detectors/python.d.ts +6 -0
  36. package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +49 -1
  37. package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.d.ts +2 -0
  38. package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.js +80 -0
  39. package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.d.ts +23 -0
  40. package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.js +145 -0
  41. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.d.ts +30 -0
  42. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.js +575 -0
  43. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript.js +12 -0
  44. package/dist/vendor/scanner/dist/src/patterns/engine.js +6 -1
  45. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +188 -0
  46. package/dist/vendor/scanner/patterns/python.patterns.yaml +10 -0
  47. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +246 -0
  48. package/dist/vendor/scanner/patterns/typescript.patterns.yaml +21 -0
  49. package/package.json +2 -2
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -66,7 +66,7 @@
66
66
  "zod": "^4.3.5"
67
67
  },
68
68
  "devDependencies": {
69
- "@dataparade/scanner": "github:DataParade-io/scanner#dc6104f9108cbb3647eb595861e73090f3cc257a",
69
+ "@dataparade/scanner": "github:DataParade-io/scanner#753bae46a97f90d52539694afb8e0bd9d0569d09",
70
70
  "@eslint/js": "^9.18.0",
71
71
  "@types/jest": "^30.0.0",
72
72
  "@types/node": "^22.0.0",
@@ -213,6 +213,16 @@ function componentMatchesProvider(component, keys) {
213
213
  const corpus = new Set([name, ...serviceNameValues]);
214
214
  return keys.some((k) => corpus.has(k) || name.includes(k));
215
215
  }
216
+ /**
217
+ * A product of the provider (Google Docs, Google Analytics) has its own
218
+ * serviceName that is not a provider key. It keeps its name and stays out of
219
+ * the provider topology, although its name contains the provider key.
220
+ */
221
+ function isProviderProduct(component, keys) {
222
+ const serviceNameValues = getStringValues(component.properties?.serviceName);
223
+ return (serviceNameValues.length > 0 &&
224
+ !serviceNameValues.some((value) => keys.includes(value)));
225
+ }
216
226
  function isManagedResourceComponent(component, managedResource, fallbackPolicy) {
217
227
  if (!(component.type === 'asset' && component.subType === 'database'))
218
228
  return false;
@@ -633,7 +643,8 @@ function applyDeterministicInferenceFallbacks(components, flows) {
633
643
  const providerRules = (0, provider_topology_rules_1.loadProviderTopologyRules)();
634
644
  for (const rule of providerRules) {
635
645
  const providers = nextComponents.filter((component) => component.type === 'third_party' &&
636
- componentMatchesProvider(component, rule.providerMatchKeys));
646
+ componentMatchesProvider(component, rule.providerMatchKeys) &&
647
+ !isProviderProduct(component, rule.providerMatchKeys));
637
648
  if (providers.length === 0)
638
649
  continue;
639
650
  for (const provider of providers) {
package/dist/src/cli.js CHANGED
@@ -44,6 +44,7 @@ const commander_1 = require("commander");
44
44
  const crypto_1 = require("crypto");
45
45
  const package_json_1 = __importDefault(require("../package.json"));
46
46
  const json_1 = require("./output/json");
47
+ const git_context_1 = require("./output/git-context");
47
48
  const write_scan_knowledge_1 = require("./output/write-scan-knowledge");
48
49
  const layout_1 = require("./facts/layout");
49
50
  const register_kb_commands_1 = require("./kb/register-kb-commands");
@@ -304,6 +305,8 @@ function createProgram() {
304
305
  process.exitCode = 2;
305
306
  return;
306
307
  }
308
+ parsedGitContext ??=
309
+ (0, git_context_1.detectGitContext)(scanEntry.scanRootDir) ?? undefined;
307
310
  const [{ createDefaultScanConfiguration }, { runScanPipeline }, { buildDiagramGraphFromScanResult },] = await Promise.all([
308
311
  Promise.resolve().then(() => __importStar(require('./core/pipeline/orchestrator'))),
309
312
  Promise.resolve().then(() => __importStar(require('./core/pipeline/scan-pipeline'))),
@@ -85,14 +85,21 @@ function stringProp(component, key) {
85
85
  const value = component.properties?.[key];
86
86
  return typeof value === 'string' ? value : '';
87
87
  }
88
- function hasPublicUrl(component) {
89
- const url = stringProp(component, 'url') ||
90
- (/^https?:\/\//i.test(component.name) ? component.name : '');
88
+ function isPublicUrl(url) {
91
89
  if (!/^https?:\/\//i.test(url))
92
90
  return false;
93
- if (/\$\{|process\.env|localhost|127\.0\.0\.1/i.test(url))
94
- return false;
95
- return true;
91
+ return !/\$\{|process\.env|localhost|127\.0\.0\.1/i.test(url);
92
+ }
93
+ /** A literal URL or a resolved `host` (e.g. a Cloud Run service) names a real destination. */
94
+ function hasPublicUrl(component) {
95
+ const raw = component.properties?.url;
96
+ const urls = (Array.isArray(raw) ? raw : [raw]).filter((value) => typeof value === 'string');
97
+ if (/^https?:\/\//i.test(component.name))
98
+ urls.push(component.name);
99
+ const host = stringProp(component, 'host');
100
+ if (host)
101
+ urls.push(`https://${host}`);
102
+ return urls.some(isPublicUrl);
96
103
  }
97
104
  function isBareHttpTransportNode(component) {
98
105
  if (component.properties?.sourceContext === 'dependency_manifest')
@@ -0,0 +1,17 @@
1
+ import { type GitContextSchema } from '../core/schema/dataflow-wrapper.schema';
2
+ type ParsedRemote = {
3
+ host: string;
4
+ repository: string;
5
+ protocol: string;
6
+ };
7
+ /** Accepts `git@host:owner/repo.git`, `ssh://git@host[:port]/owner/repo` and http(s) remotes. */
8
+ export declare function parseGitRemote(remote: string): ParsedRemote | null;
9
+ /** Maps a remote to the dataflow git context; null for hosts other than GitHub and GitLab. */
10
+ export declare function gitContextFromRemote(remote: string, commitSha: string): GitContextSchema | null;
11
+ /**
12
+ * Reads the origin remote and HEAD of the repository containing `dir`, so
13
+ * uploads can be matched to their repository. Never throws: no git, no repo
14
+ * or no origin all return null.
15
+ */
16
+ export declare function detectGitContext(dir: string): GitContextSchema | null;
17
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseGitRemote = parseGitRemote;
4
+ exports.gitContextFromRemote = gitContextFromRemote;
5
+ exports.detectGitContext = detectGitContext;
6
+ const node_child_process_1 = require("node:child_process");
7
+ const dataflow_wrapper_schema_1 = require("../core/schema/dataflow-wrapper.schema");
8
+ const GIT_TIMEOUT_MS = 5000;
9
+ /** Accepts `git@host:owner/repo.git`, `ssh://git@host[:port]/owner/repo` and http(s) remotes. */
10
+ function parseGitRemote(remote) {
11
+ const trimmed = remote.trim();
12
+ const scp = /^[^@/\s]+@([^:/\s]+):(.+)$/.exec(trimmed);
13
+ let host;
14
+ let path;
15
+ let protocol = 'https:';
16
+ if (scp && !trimmed.includes('://')) {
17
+ host = scp[1];
18
+ path = scp[2];
19
+ }
20
+ else {
21
+ let url;
22
+ try {
23
+ url = new URL(trimmed);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ if (!['http:', 'https:', 'ssh:', 'git:'].includes(url.protocol)) {
29
+ return null;
30
+ }
31
+ host = url.hostname;
32
+ path = url.pathname;
33
+ if (url.protocol === 'http:')
34
+ protocol = 'http:';
35
+ }
36
+ const repository = path
37
+ .replace(/^\/+/, '')
38
+ .replace(/\/+$/, '')
39
+ .replace(/\.git$/, '');
40
+ if (!host || !repository.includes('/'))
41
+ return null;
42
+ return { host: host.toLowerCase(), repository, protocol };
43
+ }
44
+ /** Maps a remote to the dataflow git context; null for hosts other than GitHub and GitLab. */
45
+ function gitContextFromRemote(remote, commitSha) {
46
+ const parsed = parseGitRemote(remote);
47
+ if (!parsed)
48
+ return null;
49
+ let candidate;
50
+ if (parsed.host === 'github.com') {
51
+ candidate = {
52
+ provider: 'github',
53
+ repository: parsed.repository,
54
+ commitSha,
55
+ };
56
+ }
57
+ else if (parsed.host === 'gitlab.com') {
58
+ candidate = {
59
+ provider: 'gitlab',
60
+ repository: parsed.repository,
61
+ commitSha,
62
+ };
63
+ }
64
+ else if (parsed.host.includes('gitlab')) {
65
+ candidate = {
66
+ provider: 'gitlab',
67
+ repository: parsed.repository,
68
+ commitSha,
69
+ baseUrl: `${parsed.protocol}//${parsed.host}`,
70
+ };
71
+ }
72
+ else {
73
+ return null;
74
+ }
75
+ const validated = dataflow_wrapper_schema_1.gitContextSchema.safeParse(candidate);
76
+ return validated.success ? validated.data : null;
77
+ }
78
+ function git(cwd, args) {
79
+ try {
80
+ return (0, node_child_process_1.execFileSync)('git', args, {
81
+ cwd,
82
+ encoding: 'utf8',
83
+ stdio: ['ignore', 'pipe', 'ignore'],
84
+ timeout: GIT_TIMEOUT_MS,
85
+ }).trim();
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
91
+ /**
92
+ * Reads the origin remote and HEAD of the repository containing `dir`, so
93
+ * uploads can be matched to their repository. Never throws: no git, no repo
94
+ * or no origin all return null.
95
+ */
96
+ function detectGitContext(dir) {
97
+ const remote = git(dir, ['remote', 'get-url', 'origin']);
98
+ if (!remote)
99
+ return null;
100
+ const commitSha = git(dir, ['rev-parse', 'HEAD']);
101
+ if (!commitSha)
102
+ return null;
103
+ return gitContextFromRemote(remote, commitSha);
104
+ }
@@ -1379,4 +1379,34 @@ describe("ai-enrichment deterministic fallbacks", () => {
1379
1379
  expect(result.dataFlows.some((f) => f.sourceComponentId === "asset_scripts" &&
1380
1380
  f.targetComponentId === "tp_stripe")).toBe(true);
1381
1381
  });
1382
+ it("keeps the names of provider products such as Google Docs and Google Analytics", () => {
1383
+ const component = (id, name, serviceName) => ({
1384
+ id,
1385
+ name,
1386
+ type: "third_party",
1387
+ confidence: 1,
1388
+ detectedFrom: [],
1389
+ sourceLocations: [],
1390
+ properties: { serviceName, section_id: "backend" },
1391
+ });
1392
+ const components = [
1393
+ {
1394
+ id: "app_1",
1395
+ name: "Backend",
1396
+ type: "asset",
1397
+ confidence: 1,
1398
+ detectedFrom: [],
1399
+ sourceLocations: [],
1400
+ properties: { section_id: "backend" },
1401
+ },
1402
+ component("docs", "Google Docs", "google_docs"),
1403
+ component("ga", "Google Analytics", "google_analytics"),
1404
+ component("gai", "Google Ai", "google_ai"),
1405
+ ];
1406
+ const result = (0, fallbacks_1.applyDeterministicInferenceFallbacks)(components, []);
1407
+ const names = Object.fromEntries(result.components.map((c) => [c.id, c.name]));
1408
+ expect(names.docs).toBe("Google Docs");
1409
+ expect(names.ga).toBe("Google Analytics");
1410
+ expect(names.gai).toBe("Google");
1411
+ });
1382
1412
  });
@@ -172,4 +172,25 @@ describe('omitInternalImplementationNodes', () => {
172
172
  ], [], { readSource: () => undefined });
173
173
  expect(result.components).toHaveLength(1);
174
174
  });
175
+ it('keeps an HTTP client call whose host is known, such as a Cloud Run service', () => {
176
+ const result = (0, omit_internal_implementation_1.omitInternalImplementationNodes)([
177
+ {
178
+ id: 'cloud-run',
179
+ name: 'orders (Cloud Run)',
180
+ type: 'asset',
181
+ subType: 'api',
182
+ detectedFrom: [{ pattern: 'external_api_call' }],
183
+ properties: {
184
+ client: 'axios',
185
+ host: 'orders-123.us-central1.run.app',
186
+ url: [
187
+ 'https://orders-123.us-central1.run.app/health',
188
+ 'https://orders-123.us-central1.run.app/v1/chat',
189
+ ],
190
+ platform: 'gcp/cloud_run',
191
+ },
192
+ },
193
+ ], []);
194
+ expect(result.components.map((c) => c.id)).toEqual(['cloud-run']);
195
+ });
175
196
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_child_process_1 = require("node:child_process");
4
+ const node_fs_1 = require("node:fs");
5
+ const node_os_1 = require("node:os");
6
+ const node_path_1 = require("node:path");
7
+ const git_context_1 = require("../../../src/output/git-context");
8
+ const SHA = 'a'.repeat(40);
9
+ describe('parseGitRemote', () => {
10
+ it.each([
11
+ ['git@github.com:org/repo.git', 'github.com', 'org/repo'],
12
+ ['https://github.com/org/repo', 'github.com', 'org/repo'],
13
+ ['https://github.com/org/repo.git/', 'github.com', 'org/repo'],
14
+ ['ssh://git@github.com:22/org/repo.git', 'github.com', 'org/repo'],
15
+ ['https://user:pw@GitLab.com/group/sub/repo.git', 'gitlab.com', 'group/sub/repo'],
16
+ ])('parses %s', (remote, host, repository) => {
17
+ expect((0, git_context_1.parseGitRemote)(remote)).toMatchObject({ host, repository });
18
+ });
19
+ it.each(['', 'not a url', '/local/path/repo', 'file:///tmp/repo', 'https://github.com/repo'])('rejects %s', (remote) => {
20
+ expect((0, git_context_1.parseGitRemote)(remote)).toBeNull();
21
+ });
22
+ });
23
+ describe('gitContextFromRemote', () => {
24
+ it('maps GitHub and gitlab.com without a base URL', () => {
25
+ expect((0, git_context_1.gitContextFromRemote)('git@github.com:org/repo.git', SHA)).toEqual({
26
+ provider: 'github',
27
+ repository: 'org/repo',
28
+ commitSha: SHA,
29
+ });
30
+ expect((0, git_context_1.gitContextFromRemote)('https://gitlab.com/g/r.git', SHA)).toEqual({
31
+ provider: 'gitlab',
32
+ repository: 'g/r',
33
+ commitSha: SHA,
34
+ });
35
+ });
36
+ it('keeps the base URL for self-hosted GitLab', () => {
37
+ expect((0, git_context_1.gitContextFromRemote)('git@gitlab.acme.io:team/app.git', SHA)).toEqual({
38
+ provider: 'gitlab',
39
+ repository: 'team/app',
40
+ commitSha: SHA,
41
+ baseUrl: 'https://gitlab.acme.io',
42
+ });
43
+ });
44
+ it('returns null for other hosts and bad SHAs', () => {
45
+ expect((0, git_context_1.gitContextFromRemote)('git@bitbucket.org:org/repo.git', SHA)).toBeNull();
46
+ expect((0, git_context_1.gitContextFromRemote)('git@github.com:org/repo.git', 'abc')).toBeNull();
47
+ });
48
+ });
49
+ describe('detectGitContext', () => {
50
+ let dir;
51
+ const git = (...args) => (0, node_child_process_1.execFileSync)('git', args, { cwd: dir, stdio: 'ignore' });
52
+ beforeEach(() => {
53
+ dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'dp-git-context-'));
54
+ });
55
+ afterEach(() => {
56
+ (0, node_fs_1.rmSync)(dir, { recursive: true, force: true });
57
+ });
58
+ it('returns null outside a repository', () => {
59
+ expect((0, git_context_1.detectGitContext)(dir)).toBeNull();
60
+ });
61
+ it('returns null for a repository without an origin', () => {
62
+ git('init', '-q');
63
+ expect((0, git_context_1.detectGitContext)(dir)).toBeNull();
64
+ });
65
+ it('reads origin and HEAD', () => {
66
+ git('init', '-q');
67
+ git('remote', 'add', 'origin', 'git@github.com:org/repo.git');
68
+ git('-c', 'user.name=t', '-c', 'user.email=t@example.com', 'commit', '-q', '--allow-empty', '-m', 'init');
69
+ const head = (0, node_child_process_1.execFileSync)('git', ['rev-parse', 'HEAD'], {
70
+ cwd: dir,
71
+ encoding: 'utf8',
72
+ }).trim();
73
+ expect((0, git_context_1.detectGitContext)(dir)).toEqual({
74
+ provider: 'github',
75
+ repository: 'org/repo',
76
+ commitSha: head,
77
+ });
78
+ });
79
+ });
@@ -32,6 +32,12 @@ export interface PythonPatternConfig {
32
32
  importModules: string[];
33
33
  contentRegexes: RegExp[];
34
34
  strategy?: string;
35
+ /**
36
+ * The match is a request header (`Authorization: Bearer ...`). When the header is sent
37
+ * on an outbound request it is a credential for that API, not an auth service of this
38
+ * code, so it is not reported (DATAP-818).
39
+ */
40
+ outgoingHeader: boolean;
35
41
  confidence: number;
36
42
  }>;
37
43
  };
@@ -84,6 +90,11 @@ export interface PythonPatternConfig {
84
90
  clientName: string;
85
91
  importModules: string[];
86
92
  callNames: string[];
93
+ /**
94
+ * Session/client classes of a raw HTTP library (`AsyncClient`, `Session`). When set,
95
+ * request calls are resolved to their destination host in the same file (DATAP-818).
96
+ */
97
+ clientConstructors: string[];
87
98
  urlRegex: RegExp;
88
99
  confidence: number;
89
100
  }>;
@@ -62,6 +62,7 @@ function normalizeRawConfig(raw) {
62
62
  contentRegexes: (lib.contentRegexes ?? []).map((p) => new RegExp(p)),
63
63
  importModules: lib.importModules ?? [],
64
64
  strategy: lib.strategy,
65
+ outgoingHeader: lib.outgoingHeader ?? false,
65
66
  confidence: lib.confidence ?? DEFAULT_CONFIDENCE,
66
67
  })) ?? [];
67
68
  const serverlessHandlers = raw.serverless?.handlers?.map((handler) => ({
@@ -115,6 +116,7 @@ function normalizeRawConfig(raw) {
115
116
  clientName: client.clientName,
116
117
  importModules: client.importModules ?? [],
117
118
  callNames: client.callNames ?? [],
119
+ clientConstructors: client.clientConstructors ?? [],
118
120
  urlRegex: new RegExp(client.urlRegex ??
119
121
  "['\\\"](https?:\\/\\/[^\\s'\\\"]+)['\\\"]"),
120
122
  confidence: client.confidence ?? DEFAULT_CONFIDENCE,
@@ -6,6 +6,8 @@ export interface RunAnalyzersOptions {
6
6
  terraformModuleManifest?: TerraformModuleCallManifest;
7
7
  terraformScanRootPath?: string;
8
8
  organizationDomains?: readonly string[];
9
+ /** Owner of the scanned repository's git `origin` remote, a first-party signal. */
10
+ gitRemoteOwner?: string;
9
11
  }
10
12
  export declare function registerAnalyzer(language: FileLanguage, analyzer: Analyzer): void;
11
13
  export declare function getAnalyzerForFile(file: FileInfo): Analyzer | undefined;
@@ -23,6 +23,7 @@ const ruby_2 = require("../patterns/detectors/ruby");
23
23
  const config_1 = require("../patterns/config");
24
24
  const parser_1 = require("./ruby/parser");
25
25
  const organization_domains_scan_scope_1 = require("../classifier/organization-domains-scan-scope");
26
+ const source_module_index_1 = require("../patterns/detectors/source-module-index");
26
27
  const typeScriptAnalyzer = (0, typescript_1.createTypeScriptAnalyzer)();
27
28
  const pythonAnalyzer = (0, python_1.createPythonAnalyzer)();
28
29
  const cppAnalyzer = (0, cpp_1.createCppAnalyzer)();
@@ -63,7 +64,7 @@ function runAnalyzers(files, opts) {
63
64
  scanRootPath: opts.terraformScanRootPath,
64
65
  }
65
66
  : undefined;
66
- return (0, organization_domains_scan_scope_1.runWithOrganizationDomainsScope)(opts?.organizationDomains, () => {
67
+ return (0, organization_domains_scan_scope_1.runWithOrganizationDomainsScope)(opts?.organizationDomains, () => (0, source_module_index_1.runWithPythonModuleIndex)(files, () => {
67
68
  for (const file of files) {
68
69
  if (file.language === "terraform") {
69
70
  findings.push(...(0, detector_2.detectTerraformPatterns)(file, tfConfig, tfOpts));
@@ -94,7 +95,7 @@ function runAnalyzers(files, opts) {
94
95
  }
95
96
  }
96
97
  return findings;
97
- });
98
+ }, { gitRemoteOwner: opts?.gitRemoteOwner }));
98
99
  }
99
100
  async function runAnalyzersForRootPath(rootPath) {
100
101
  const files = await (0, file_system_1.ingestFileSystem)(rootPath);
@@ -43,12 +43,29 @@ export interface ServerlessHandlerConfig extends WithPatternId {
43
43
  typeNames: string[];
44
44
  confidence: number;
45
45
  }
46
+ /**
47
+ * A raw HTTP library whose request URLs the TS/JS AST detector resolves (DATAP-818). Its
48
+ * line regexes then stay off, so the library is never reported as a destination.
49
+ */
50
+ export interface RawHttpClientConfig {
51
+ /** Import specifiers that load it (`axios`, `node-fetch`). */
52
+ modules: string[];
53
+ /** The default import is itself a request function (`axios(url)`, `got(url)`). */
54
+ callable: boolean;
55
+ /** Named exports that are request functions (`fetch` from undici). */
56
+ namedFunctions: string[];
57
+ /** Factory methods returning a configured instance (`axios.create`, `got.extend`). */
58
+ instanceFactories: string[];
59
+ /** Option keys that hold the instance base URL (`baseURL`, `prefixUrl`). */
60
+ baseUrlKeys: string[];
61
+ }
46
62
  export interface ExternalApiClientConfig extends WithPatternId {
47
63
  id: string;
48
64
  clientName: string;
49
65
  importFragments: string[];
50
66
  callRegexes: RegExp[];
51
67
  confidence: number;
68
+ rawHttp?: RawHttpClientConfig;
52
69
  }
53
70
  export interface ConfigLoaderConfig extends WithPatternId {
54
71
  id: string;
@@ -99,6 +99,17 @@ function normalizeRawConfig(raw) {
99
99
  importFragments: client.importFragments ?? [],
100
100
  callRegexes: compileRegexList(client.regexes),
101
101
  confidence: client.confidence ?? DEFAULT_CONFIDENCE,
102
+ ...(client.rawHttp
103
+ ? {
104
+ rawHttp: {
105
+ modules: client.rawHttp.modules,
106
+ callable: client.rawHttp.callable ?? false,
107
+ namedFunctions: client.rawHttp.namedFunctions ?? [],
108
+ instanceFactories: client.rawHttp.instanceFactories ?? [],
109
+ baseUrlKeys: client.rawHttp.baseUrlKeys ?? [],
110
+ },
111
+ }
112
+ : {}),
102
113
  };
103
114
  }) ?? [];
104
115
  const configLoaders = raw.config_loaders?.map((loader) => {
@@ -231,6 +231,9 @@ function findThirdPartyMatch(finding, config, urlOptions, organizationDomains) {
231
231
  if ((0, external_url_third_party_1.isOrganizationOwnedExternalApiFinding)(finding, organizationDomains)) {
232
232
  return undefined;
233
233
  }
234
+ if (finding.properties?.remoteService === true || finding.properties?.firstParty === true) {
235
+ return undefined;
236
+ }
234
237
  const props = finding.properties ?? {};
235
238
  const candidates = [];
236
239
  const serviceName = props.serviceName;
@@ -247,6 +250,14 @@ function findThirdPartyMatch(finding, config, urlOptions, organizationDomains) {
247
250
  /^https?:\/\//i.test(finding.name.trim())) {
248
251
  candidates.push(finding.name.toLowerCase());
249
252
  }
253
+ // A detector that already named the service (e.g. from a resolved URL host) wins over
254
+ // substring keys of earlier catalog entries matching the URL (DATAP-818).
255
+ if (typeof serviceName === "string" && serviceName.trim()) {
256
+ const exact = serviceName.trim().toLowerCase();
257
+ const named = config.thirdParties.find((tp) => tp.serviceName.toLowerCase() === exact);
258
+ if (named)
259
+ return named;
260
+ }
250
261
  for (const tp of config.thirdParties) {
251
262
  for (const key of tp.matchKeys) {
252
263
  if (candidates.some((c) => c.includes(key)))
@@ -378,9 +389,13 @@ function decideComponentTypeAndSubType(group, config, patternDefaultsById, urlOp
378
389
  matchedThirdParty = tp;
379
390
  }
380
391
  if (matchedThirdParty && config.resolution.preferThirdPartyOverAsset) {
392
+ // A route can give one service a different subtype per endpoint (DATAP-818).
393
+ const routed = group.findings
394
+ .map((f) => f.properties?.thirdPartySubType)
395
+ .find((v) => typeof v === "string" && v.trim().length > 0);
381
396
  return {
382
397
  type: "third_party",
383
- subType: matchedThirdParty.subType,
398
+ subType: routed?.trim() ?? matchedThirdParty.subType,
384
399
  thirdParty: matchedThirdParty,
385
400
  };
386
401
  }
@@ -454,7 +469,10 @@ function classifyRawFindings(rawFindings, options) {
454
469
  }
455
470
  const { type, subType, thirdParty } = decideComponentTypeAndSubType(group, config, patternDefaultsById, urlOptions, organizationDomains);
456
471
  if (group.findings.length > 0 &&
457
- group.findings.every((f) => (0, external_url_third_party_1.isOrganizationOwnedExternalApiFinding)(f, organizationDomains))) {
472
+ group.findings.every((f) => (0, external_url_third_party_1.isOrganizationOwnedExternalApiFinding)(f, organizationDomains)) &&
473
+ // Detectors that keep a call to the organization's own host mark it first-party:
474
+ // it stays as an API asset for the remote service (DATAP-818).
475
+ !group.findings.some((f) => f.properties?.firstParty === true)) {
458
476
  continue;
459
477
  }
460
478
  if (type === "third_party" &&
@@ -518,12 +536,24 @@ function classifyRawFindings(rawFindings, options) {
518
536
  if (component.type === "third_party") {
519
537
  const svc = mergedProperties.serviceName;
520
538
  if (typeof svc === "string" && svc.trim()) {
521
- const normalizedService = normalizeComponentName(svc, config.nameNormalization);
539
+ // A catalog service name is already canonical: keep suffixes such as `_api`
540
+ // (meta_conversions_api) that name normalization would strip.
541
+ const catalogName = thirdParty?.serviceName.toLowerCase() === svc.trim().toLowerCase();
542
+ const normalizedService = catalogName
543
+ ? svc.trim().toLowerCase()
544
+ : normalizeComponentName(svc, config.nameNormalization);
522
545
  component.name = (0, naming_1.toDisplayName)(normalizedService, svc);
523
546
  }
524
547
  }
525
548
  if (component.type === "asset" && component.subType === "api") {
526
549
  component.name = normalizeApiDisplayName(component.name, mergedProperties);
550
+ // A remote service on a hosting platform carries its own display name
551
+ // ("mom-skipify (Cloud Run)"); keep it as written (DATAP-818).
552
+ const displayName = group.findings
553
+ .map((f) => f.properties?.displayName)
554
+ .find((v) => typeof v === "string" && v.trim().length > 0);
555
+ if (displayName)
556
+ component.name = displayName;
527
557
  }
528
558
  components.push(component);
529
559
  }
@@ -236,6 +236,11 @@ function enhanceComponents(components) {
236
236
  if ((0, main_application_selection_1.isTerraformModuleCallShellAsset)(c)) {
237
237
  continue;
238
238
  }
239
+ // Outbound calls to another service (DATAP-818) describe that remote service, never
240
+ // this section's application: do not pick or rename them as the main application.
241
+ if (isRemoteOutboundApiAsset(c)) {
242
+ continue;
243
+ }
239
244
  const sid = sectionIdFor(c);
240
245
  const priority = getFrameworkPriority(c);
241
246
  if (isSingleRouteApiAsset(c)) {
@@ -309,3 +314,12 @@ function enhanceComponents(components) {
309
314
  return component;
310
315
  });
311
316
  }
317
+ function propertyIs(value, expected) {
318
+ return Array.isArray(value) ? value.includes(expected) : value === expected;
319
+ }
320
+ /** API asset made from outbound calls (remote service or unknown destination), not an own API. */
321
+ function isRemoteOutboundApiAsset(component) {
322
+ return (component.subType === "api" &&
323
+ (propertyIs(component.properties?.remoteService, true) ||
324
+ propertyIs(component.properties?.destination, "unknown")));
325
+ }
@@ -15,6 +15,14 @@ export declare function shouldIgnoreExternalHttpUrl(url: string | undefined, opt
15
15
  * api.openai.com → openai.com, clipdrop-api.co → clipdrop-api.co.
16
16
  */
17
17
  export declare function deriveServiceKeyFromHostname(host: string): string;
18
+ /** Registrable domain of a host (`www.shop.example.co.uk` -> `example.co.uk`). */
19
+ export declare function registrableDomainOf(host: string): string;
20
+ /**
21
+ * Vendor key for a host the catalog does not know: the registrable domain without its
22
+ * public suffix (`api.dramaboxdb.com` -> `dramaboxdb`, `shop.example.co.uk` -> `example`),
23
+ * so components are named after a vendor, not a domain (DATAP-818).
24
+ */
25
+ export declare function vendorNameFromHostname(host: string): string;
18
26
  /**
19
27
  * Hostname + registrable domain keys from an absolute http(s) URL (for matching
20
28
  * external_api_call findings to third_party nodes by endpoint.