@dataparade/cli 0.0.31 → 0.0.33

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 (141) hide show
  1. package/README.md +56 -1
  2. package/dist/package.json +4 -3
  3. package/dist/src/ai-enrichment/fallbacks.js +12 -1
  4. package/dist/src/cli.js +50 -4
  5. package/dist/src/core/pipeline/omit-internal-implementation.js +13 -6
  6. package/dist/src/diff/register-diff-command.d.ts +4 -0
  7. package/dist/src/diff/register-diff-command.js +79 -0
  8. package/dist/src/diff/run-diff.d.ts +80 -0
  9. package/dist/src/diff/run-diff.js +206 -0
  10. package/dist/src/diff/upload-diff.d.ts +26 -0
  11. package/dist/src/diff/upload-diff.js +69 -0
  12. package/dist/src/facts/apply-answers.js +1 -1
  13. package/dist/src/facts/build-facts.d.ts +3 -1
  14. package/dist/src/facts/build-facts.js +10 -1
  15. package/dist/src/facts/identity.d.ts +27 -0
  16. package/dist/src/facts/identity.js +203 -0
  17. package/dist/src/facts/io.d.ts +2 -0
  18. package/dist/src/facts/io.js +7 -0
  19. package/dist/src/facts/scan-stamps.d.ts +55 -0
  20. package/dist/src/facts/scan-stamps.js +165 -0
  21. package/dist/src/facts/schema.d.ts +243 -7
  22. package/dist/src/facts/schema.js +71 -1
  23. package/dist/src/kb/answer-fingerprint.d.ts +44 -0
  24. package/dist/src/kb/answer-fingerprint.js +173 -0
  25. package/dist/src/kb/brief.d.ts +8 -1
  26. package/dist/src/kb/brief.js +18 -2
  27. package/dist/src/kb/land.js +3 -0
  28. package/dist/src/kb/register-kb-commands.js +7 -1
  29. package/dist/src/output/git-context.d.ts +25 -0
  30. package/dist/src/output/git-context.js +122 -0
  31. package/dist/src/output/scan-output-excludes.js +5 -1
  32. package/dist/src/output/write-scan-knowledge.d.ts +2 -0
  33. package/dist/src/output/write-scan-knowledge.js +1 -0
  34. package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
  35. package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
  36. package/dist/src/platform-api/upload-client.d.ts +1 -1
  37. package/dist/src/platform-api/upload-client.js +32 -1
  38. package/dist/src/platform-api/upload.types.d.ts +55 -0
  39. package/dist/src/sensitive-scan/process.d.ts +5 -0
  40. package/dist/src/sensitive-scan/process.js +48 -0
  41. package/dist/src/sensitive-scan/project.d.ts +12 -0
  42. package/dist/src/sensitive-scan/project.js +177 -0
  43. package/dist/src/sensitive-scan/report.d.ts +50 -0
  44. package/dist/src/sensitive-scan/report.js +32 -0
  45. package/dist/src/sensitive-scan/sessions.d.ts +2 -0
  46. package/dist/src/sensitive-scan/sessions.js +120 -0
  47. package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
  48. package/dist/src/ui/scan-progress-renderer.js +8 -0
  49. package/dist/src/upload/build-preview-url.d.ts +2 -2
  50. package/dist/src/upload/build-preview-url.js +4 -4
  51. package/dist/src/upload/run-upload.js +6 -2
  52. package/dist/src/upload/types.d.ts +2 -0
  53. package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +30 -0
  54. package/dist/tests/unit/core/omit-internal-implementation.spec.js +21 -0
  55. package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
  56. package/dist/tests/unit/diff/run-diff.spec.js +189 -0
  57. package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
  58. package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
  59. package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
  60. package/dist/tests/unit/facts/build-facts.spec.js +67 -1
  61. package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
  62. package/dist/tests/unit/facts/identity.spec.js +148 -0
  63. package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
  64. package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
  65. package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
  66. package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
  67. package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
  68. package/dist/tests/unit/output/git-context.spec.d.ts +1 -0
  69. package/dist/tests/unit/output/git-context.spec.js +98 -0
  70. package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
  71. package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
  72. package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
  73. package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
  74. package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
  75. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
  76. package/dist/tests/unit/upload/run-upload.spec.js +32 -0
  77. package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
  78. package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
  79. package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
  80. package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
  81. package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
  82. package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
  83. package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
  84. package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
  85. package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
  86. package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
  87. package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
  88. package/dist/vendor/kb-compare/dist/src/index.js +34 -0
  89. package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
  90. package/dist/vendor/kb-compare/dist/src/input.js +75 -0
  91. package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
  92. package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
  93. package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
  94. package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
  95. package/dist/vendor/kb-compare/package.json +6 -0
  96. package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.d.ts +11 -0
  97. package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.js +2 -0
  98. package/dist/vendor/scanner/dist/src/analyzers/registry.d.ts +2 -0
  99. package/dist/vendor/scanner/dist/src/analyzers/registry.js +3 -2
  100. package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.d.ts +17 -0
  101. package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.js +11 -0
  102. package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
  103. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +33 -3
  104. package/dist/vendor/scanner/dist/src/classifier/enhance.js +14 -0
  105. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +8 -0
  106. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +43 -2
  107. package/dist/vendor/scanner/dist/src/classifier/postprocessing.js +4 -1
  108. package/dist/vendor/scanner/dist/src/config/third-party-detection-config.d.ts +41 -0
  109. package/dist/vendor/scanner/dist/src/config/third-party-detection-config.js +65 -1
  110. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
  111. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
  112. package/dist/vendor/scanner/dist/src/core/pipeline/structural-scan.js +2 -0
  113. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.d.ts +5 -0
  114. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.js +10 -2
  115. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/data-flows.js +4 -4
  116. package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
  117. package/dist/vendor/scanner/dist/src/index.js +4 -2
  118. package/dist/vendor/scanner/dist/src/patterns/config.js +7 -1
  119. package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.d.ts +14 -0
  120. package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.js +108 -0
  121. package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.d.ts +93 -0
  122. package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.js +1206 -0
  123. package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.d.ts +180 -0
  124. package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.js +1022 -0
  125. package/dist/vendor/scanner/dist/src/patterns/detectors/python.d.ts +6 -0
  126. package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +49 -1
  127. package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.d.ts +2 -0
  128. package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.js +80 -0
  129. package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.d.ts +23 -0
  130. package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.js +145 -0
  131. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.d.ts +30 -0
  132. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.js +575 -0
  133. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript.js +12 -0
  134. package/dist/vendor/scanner/dist/src/patterns/engine.js +6 -1
  135. package/dist/vendor/scanner/package.json +3 -1
  136. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +198 -0
  137. package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
  138. package/dist/vendor/scanner/patterns/python.patterns.yaml +10 -0
  139. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +271 -0
  140. package/dist/vendor/scanner/patterns/typescript.patterns.yaml +21 -0
  141. package/package.json +4 -3
@@ -5,5 +5,11 @@ export declare function detectPythonDatabaseConnectionsFromImportsAndContent(ctx
5
5
  export declare function detectPythonAuthFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
6
6
  export declare function detectPythonEnvAndConfigFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
7
7
  export declare function detectPythonRoutesFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
8
+ /**
9
+ * Drop the `openai` import finding when every OpenAI client in the file is built with a
10
+ * `base_url` on another provider's host (OpenRouter, Cerebras ...): the code imports the
11
+ * OpenAI SDK but does not call OpenAI (DATAP-818).
12
+ */
13
+ export declare function dropRedirectedOpenAiImportFindings(ctx: PatternContext, config: UnifiedPatternConfig, findings: RawFinding[]): RawFinding[];
8
14
  export declare function detectPythonExternalApisFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
9
15
  export declare function detectPythonServerlessHandlersFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
@@ -4,11 +4,13 @@ exports.detectPythonDatabaseConnectionsFromImportsAndContent = detectPythonDatab
4
4
  exports.detectPythonAuthFromConfig = detectPythonAuthFromConfig;
5
5
  exports.detectPythonEnvAndConfigFromConfig = detectPythonEnvAndConfigFromConfig;
6
6
  exports.detectPythonRoutesFromConfig = detectPythonRoutesFromConfig;
7
+ exports.dropRedirectedOpenAiImportFindings = dropRedirectedOpenAiImportFindings;
7
8
  exports.detectPythonExternalApisFromConfig = detectPythonExternalApisFromConfig;
8
9
  exports.detectPythonServerlessHandlersFromConfig = detectPythonServerlessHandlersFromConfig;
9
10
  const external_url_third_party_1 = require("../../classifier/external-url-third-party");
10
11
  const organization_domains_scan_scope_1 = require("../../classifier/organization-domains-scan-scope");
11
12
  const helpers_1 = require("./helpers");
13
+ const python_outbound_http_1 = require("./python-outbound-http");
12
14
  function pythonImportLocations(ctx, modules) {
13
15
  if (modules.length === 0)
14
16
  return [];
@@ -105,9 +107,19 @@ function detectPythonAuthFromConfig(ctx, config) {
105
107
  });
106
108
  }
107
109
  }
110
+ const outgoing = authConfig.libraries.some((lib) => lib.outgoingHeader)
111
+ ? new Set(outboundHttpFor(ctx, config).outgoingRequestLines)
112
+ : new Set();
108
113
  for (const lib of authConfig.libraries) {
109
114
  const importLocations = pythonImportLocations(ctx, lib.importModules);
110
- const contentLocations = (0, helpers_1.locationsForContentRegexes)(ctx.file, content, lib.contentRegexes);
115
+ let contentLocations = (0, helpers_1.locationsForContentRegexes)(ctx.file, content, lib.contentRegexes);
116
+ if (lib.outgoingHeader) {
117
+ const before = contentLocations.length;
118
+ contentLocations = contentLocations.filter((loc) => !outgoing.has(loc.startLine));
119
+ // Every match is a header sent on an outbound request: nothing to report.
120
+ if (before > 0 && contentLocations.length === 0 && importLocations.length === 0)
121
+ continue;
122
+ }
111
123
  const hasImport = importLocations.length > 0;
112
124
  const matchesContent = lib.contentRegexes.some((re) => re.test(content));
113
125
  if (!hasImport && !matchesContent)
@@ -432,16 +444,52 @@ function detectPythonRoutesFromConfig(ctx, config) {
432
444
  }
433
445
  return findings;
434
446
  }
447
+ function outboundHttpFor(ctx, config) {
448
+ const libraries = config.python.externalApis.httpClients
449
+ .filter((client) => client.clientConstructors.length > 0)
450
+ .map((client) => ({
451
+ name: client.clientName,
452
+ importModules: client.importModules,
453
+ constructors: client.clientConstructors,
454
+ patternId: client.patternId,
455
+ confidence: client.confidence,
456
+ }));
457
+ return (0, python_outbound_http_1.detectPythonOutboundHttp)({
458
+ filePath: ctx.file.path,
459
+ content: ctx.file.content ?? "",
460
+ libraries,
461
+ config,
462
+ });
463
+ }
464
+ /**
465
+ * Drop the `openai` import finding when every OpenAI client in the file is built with a
466
+ * `base_url` on another provider's host (OpenRouter, Cerebras ...): the code imports the
467
+ * OpenAI SDK but does not call OpenAI (DATAP-818).
468
+ */
469
+ function dropRedirectedOpenAiImportFindings(ctx, config, findings) {
470
+ if (ctx.language !== "python")
471
+ return findings;
472
+ if (!outboundHttpFor(ctx, config).openAiClientsRedirected)
473
+ return findings;
474
+ return findings.filter((f) => !(f.pattern === "external_api_call" &&
475
+ f.properties?.client === "openai" &&
476
+ f.properties?.serviceName === "openai"));
477
+ }
435
478
  function detectPythonExternalApisFromConfig(ctx, config) {
436
479
  if (ctx.language !== "python")
437
480
  return [];
438
481
  const imports = ctx.imports ?? [];
439
482
  const calls = ctx.moduleLevelCalls ?? [];
440
483
  const findings = [];
484
+ // Raw HTTP libraries (httpx, requests, aiohttp): resolve each request call's destination
485
+ // in the same file; the library itself is never the destination (DATAP-818).
486
+ findings.push(...outboundHttpFor(ctx, config).findings);
441
487
  if (calls.length === 0)
442
488
  return findings;
443
489
  const urlHostPatterns = (0, helpers_1.buildThirdPartyUrlHostPatterns)(config);
444
490
  for (const client of config.python.externalApis.httpClients) {
491
+ if (client.clientConstructors.length > 0)
492
+ continue;
445
493
  const hasImport = client.importModules.length === 0
446
494
  ? true
447
495
  : client.importModules.some((mod) => imports.some((imp) => imp.module.includes(mod) || imp.names.includes(mod)));
@@ -0,0 +1,2 @@
1
+ import type { FileInfo } from "../../core/types/file";
2
+ export declare function collectRepoDeclaredDomains(files: readonly FileInfo[]): string[];
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectRepoDeclaredDomains = collectRepoDeclaredDomains;
4
+ const external_url_third_party_1 = require("../../classifier/external-url-third-party");
5
+ const third_party_detection_config_1 = require("../../config/third-party-detection-config");
6
+ /**
7
+ * Domains a repository declares as its own (DATAP-818), used as organization domains when
8
+ * none are configured, so a website calling its company's API on another subdomain is a
9
+ * first-party call and not a vendor named after the company.
10
+ *
11
+ * Conservative on purpose. Sources:
12
+ * - `homepage` in a package.json;
13
+ * - site URL settings in env example files and source code: `SITE_URL`, `APP_URL`,
14
+ * `WEBSITE_URL`, `PUBLIC_URL`, `CANONICAL_URL`, `FRONTEND_URL` (with `NEXT_PUBLIC_`,
15
+ * `VITE_`, `REACT_APP_`, `PUBLIC_` prefixes), assigned a literal https URL.
16
+ * Never: code and package hosts (github.com ...), shared hosting platforms (*.run.app ...),
17
+ * placeholder and local hosts, and hosts of catalog vendors. `BASE_URL`/`API_URL` are not
18
+ * read: they usually hold a vendor's API. README links and CNAME files are not ingested.
19
+ */
20
+ const SITE_URL_SETTING = /\b(?:NEXT_PUBLIC_|VITE_|REACT_APP_|PUBLIC_)?(?:SITE|APP|WEBSITE|PUBLIC|CANONICAL|FRONTEND)_URL\b["']?\s*[:=]\s*["'`]?(https:\/\/[^"'`\s/]+)/g;
21
+ const NEVER_OWN = new Set([
22
+ "github.com", "githubusercontent.com", "gitlab.com", "bitbucket.org", "npmjs.com", "npmjs.org",
23
+ "pypi.org", "readthedocs.io", "google.com", "medium.com", "notion.site", "localhost",
24
+ ]);
25
+ function hostOf(url) {
26
+ try {
27
+ return new URL(url).hostname.toLowerCase();
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ }
33
+ function isCatalogVendorHost(host) {
34
+ return (0, third_party_detection_config_1.loadThirdPartyDetectionConfig)().services.some((svc) => svc.urlHostPatterns.some((p) => {
35
+ const pattern = p.toLowerCase().replace(/^\./, "");
36
+ return host === pattern || host.endsWith(`.${pattern}`);
37
+ }));
38
+ }
39
+ function collectRepoDeclaredDomains(files) {
40
+ const hosts = new Set();
41
+ for (const file of files) {
42
+ const base = file.path.split("/").pop() ?? "";
43
+ const content = file.content ?? "";
44
+ if (base === "package.json") {
45
+ try {
46
+ const homepage = JSON.parse(content).homepage;
47
+ if (typeof homepage === "string") {
48
+ const host = hostOf(homepage);
49
+ if (host)
50
+ hosts.add(host);
51
+ }
52
+ }
53
+ catch {
54
+ // Not JSON: ignore.
55
+ }
56
+ continue;
57
+ }
58
+ const isEnvExample = file.language === "env" || /^\.env\./.test(base);
59
+ const isSource = file.language === "typescript" || file.language === "javascript" || file.language === "python";
60
+ if (!isEnvExample && !isSource)
61
+ continue;
62
+ if (!/_URL/.test(content))
63
+ continue;
64
+ for (const m of content.matchAll(SITE_URL_SETTING)) {
65
+ const host = hostOf(m[1]);
66
+ if (host)
67
+ hosts.add(host);
68
+ }
69
+ }
70
+ const domains = new Set();
71
+ for (const host of hosts) {
72
+ if (!host.includes(".") || (0, external_url_third_party_1.isReservedPlaceholderHost)(host) || (0, third_party_detection_config_1.platformOfHost)(host) || isCatalogVendorHost(host))
73
+ continue;
74
+ const domain = (0, external_url_third_party_1.registrableDomainOf)(host);
75
+ if (NEVER_OWN.has(domain))
76
+ continue;
77
+ domains.add(domain);
78
+ }
79
+ return [...domains].sort();
80
+ }
@@ -0,0 +1,23 @@
1
+ import type { FileInfo } from "../../core/types/file";
2
+ export interface SourceScopeOptions {
3
+ /** Owner of the repository's git `origin` remote (see git-remote-owner.ts). */
4
+ gitRemoteOwner?: string;
5
+ }
6
+ export declare function runWithPythonModuleIndex<T>(files: readonly FileInfo[], fn: () => T, options?: SourceScopeOptions): T;
7
+ /** Normalized owner name of the repository's git remote, when known. */
8
+ export declare function repoOwnerKey(): string | undefined;
9
+ /** Domains the scanned repository declares as its own (see repo-declared-domains.ts). */
10
+ export declare function repoDeclaredDomains(): readonly string[];
11
+ /** Changes whenever the active index changes, for cache keys. */
12
+ export declare function pythonModuleIndexGeneration(): number;
13
+ export declare function pythonModuleIndexSize(): number;
14
+ /** Repo-relative file of a relative TS/JS import (`./settings`, `../lib/http`), seen from `fromFile`. */
15
+ export declare function resolveTsModulePath(fromFile: string, spec: string): string | undefined;
16
+ export declare function sourceModule(filePath: string): string | undefined;
17
+ export declare function pythonModuleSource(filePath: string): string | undefined;
18
+ /**
19
+ * Repo-relative file of an imported module, seen from `fromFile`: relative imports
20
+ * (`.settings`, `..pkg.mod`) resolve from the importing file's package; absolute imports
21
+ * (`app.settings`) match a path suffix, preferring the file nearest to the importer.
22
+ */
23
+ export declare function resolvePythonModulePath(fromFile: string, moduleSpec: string): string | undefined;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWithPythonModuleIndex = runWithPythonModuleIndex;
4
+ exports.repoOwnerKey = repoOwnerKey;
5
+ exports.repoDeclaredDomains = repoDeclaredDomains;
6
+ exports.pythonModuleIndexGeneration = pythonModuleIndexGeneration;
7
+ exports.pythonModuleIndexSize = pythonModuleIndexSize;
8
+ exports.resolveTsModulePath = resolveTsModulePath;
9
+ exports.sourceModule = sourceModule;
10
+ exports.pythonModuleSource = pythonModuleSource;
11
+ exports.resolvePythonModulePath = resolvePythonModulePath;
12
+ const git_remote_owner_1 = require("./git-remote-owner");
13
+ const repo_declared_domains_1 = require("./repo-declared-domains");
14
+ /**
15
+ * The Python, TypeScript and JavaScript files of the scan, by repo-relative path, while
16
+ * analyzers run. Detectors use it to follow same-repo imports (`from .settings import
17
+ * settings`, `import { X } from "./settings"`) when they resolve a value (DATAP-818).
18
+ * Outside a scan the index is empty and resolution stays in one file.
19
+ */
20
+ let activeIndex;
21
+ let activeDeclaredDomains = [];
22
+ let activeOwnerKey;
23
+ let generation = 0;
24
+ function normalize(filePath) {
25
+ return filePath.replace(/\\/g, "/").replace(/^\.\/+/, "");
26
+ }
27
+ function runWithPythonModuleIndex(files, fn, options = {}) {
28
+ const prev = activeIndex;
29
+ const index = new Map();
30
+ for (const file of files) {
31
+ if (file.language === "python" || file.language === "typescript" || file.language === "javascript" || /\.(py|[cm]?[jt]sx?)$/.test(file.path)) {
32
+ index.set(normalize(file.path), file.content);
33
+ }
34
+ }
35
+ const prevDomains = activeDeclaredDomains;
36
+ const prevOwner = activeOwnerKey;
37
+ activeIndex = index;
38
+ activeDeclaredDomains = (0, repo_declared_domains_1.collectRepoDeclaredDomains)(files);
39
+ activeOwnerKey = options.gitRemoteOwner ? (0, git_remote_owner_1.normalizeOrganizationName)(options.gitRemoteOwner) || undefined : undefined;
40
+ generation += 1;
41
+ try {
42
+ return fn();
43
+ }
44
+ finally {
45
+ activeIndex = prev;
46
+ activeDeclaredDomains = prevDomains;
47
+ activeOwnerKey = prevOwner;
48
+ generation += 1;
49
+ }
50
+ }
51
+ /** Normalized owner name of the repository's git remote, when known. */
52
+ function repoOwnerKey() {
53
+ return activeOwnerKey;
54
+ }
55
+ /** Domains the scanned repository declares as its own (see repo-declared-domains.ts). */
56
+ function repoDeclaredDomains() {
57
+ return activeDeclaredDomains;
58
+ }
59
+ /** Changes whenever the active index changes, for cache keys. */
60
+ function pythonModuleIndexGeneration() {
61
+ return generation;
62
+ }
63
+ function pythonModuleIndexSize() {
64
+ if (!activeIndex)
65
+ return 0;
66
+ let n = 0;
67
+ for (const key of activeIndex.keys())
68
+ if (key.endsWith(".py"))
69
+ n += 1;
70
+ return n;
71
+ }
72
+ const TS_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"];
73
+ /** Repo-relative file of a relative TS/JS import (`./settings`, `../lib/http`), seen from `fromFile`. */
74
+ function resolveTsModulePath(fromFile, spec) {
75
+ if (!activeIndex || !spec.startsWith("."))
76
+ return undefined;
77
+ const parts = dirname(normalize(fromFile)).split("/").filter(Boolean);
78
+ for (const segment of spec.split("/")) {
79
+ if (segment === "." || segment === "")
80
+ continue;
81
+ if (segment === "..")
82
+ parts.pop();
83
+ else
84
+ parts.push(segment);
85
+ }
86
+ const base = parts.join("/");
87
+ const stem = base.replace(/\.(?:[cm]?js|jsx)$/, "");
88
+ const candidates = [base, ...TS_EXTENSIONS.map((e) => `${stem}${e}`), ...TS_EXTENSIONS.map((e) => `${base}/index${e}`)];
89
+ return candidates.find((p) => activeIndex.has(p));
90
+ }
91
+ function sourceModule(filePath) {
92
+ return activeIndex?.get(normalize(filePath));
93
+ }
94
+ function pythonModuleSource(filePath) {
95
+ return activeIndex?.get(normalize(filePath));
96
+ }
97
+ function dirname(filePath) {
98
+ const i = filePath.lastIndexOf("/");
99
+ return i === -1 ? "" : filePath.slice(0, i);
100
+ }
101
+ function join(dir, rel) {
102
+ return dir ? `${dir}/${rel}` : rel;
103
+ }
104
+ /**
105
+ * Repo-relative file of an imported module, seen from `fromFile`: relative imports
106
+ * (`.settings`, `..pkg.mod`) resolve from the importing file's package; absolute imports
107
+ * (`app.settings`) match a path suffix, preferring the file nearest to the importer.
108
+ */
109
+ function resolvePythonModulePath(fromFile, moduleSpec) {
110
+ if (!activeIndex)
111
+ return undefined;
112
+ const from = normalize(fromFile);
113
+ const dots = /^\.*/.exec(moduleSpec)?.[0].length ?? 0;
114
+ const parts = moduleSpec.slice(dots).split(".").filter(Boolean);
115
+ const candidates = (base) => {
116
+ const rel = parts.join("/");
117
+ return rel ? [join(base, `${rel}.py`), join(base, `${rel}/__init__.py`)] : [join(base, "__init__.py")];
118
+ };
119
+ if (dots > 0) {
120
+ let dir = dirname(from);
121
+ for (let i = 1; i < dots; i += 1)
122
+ dir = dirname(dir);
123
+ return candidates(dir).find((p) => activeIndex.has(p));
124
+ }
125
+ if (parts.length === 0)
126
+ return undefined;
127
+ const suffixes = candidates("");
128
+ let best;
129
+ for (const path of activeIndex.keys()) {
130
+ if (!suffixes.some((s) => path === s || path.endsWith(`/${s}`)))
131
+ continue;
132
+ const shared = sharedPrefix(path, from);
133
+ if (!best || shared > best.shared)
134
+ best = { path, shared };
135
+ }
136
+ return best?.path;
137
+ }
138
+ function sharedPrefix(a, b) {
139
+ const x = a.split("/");
140
+ const y = b.split("/");
141
+ let n = 0;
142
+ while (n < x.length && n < y.length && x[n] === y[n])
143
+ n += 1;
144
+ return n;
145
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * TypeScript/JavaScript outbound HTTP destinations (DATAP-818), the counterpart of
3
+ * `python-outbound-http.ts`.
4
+ *
5
+ * It parses the file with the TypeScript compiler API (the TS analyzer's parser already
6
+ * depends on it) and finds request calls: the global `fetch`, and the raw HTTP libraries
7
+ * marked `rawHttp` in `typescript.patterns.yaml` (axios, got, ky, node-fetch ...), including
8
+ * instances made with `axios.create({ baseURL })` / `got.extend({ prefixUrl })`. The URL is
9
+ * resolved from literals and template literals, `const` bindings, parameter defaults,
10
+ * `??` / `||` defaults on `process.env`, object-literal constants, and `const` exports of
11
+ * same-repo modules imported with a relative path. A known host names the vendor; a URL that
12
+ * only comes from the environment (`import.meta.env.VITE_*`, `process.env.X` with no default)
13
+ * gives an outbound call with no vendor. A library is never the destination. Relative URLs
14
+ * with no base are same-origin calls and are not reported.
15
+ */
16
+ import type { RawFinding } from "../../core/types/detection";
17
+ import type { UnifiedPatternConfig } from "../config";
18
+ export interface TsOutboundHttpResult {
19
+ findings: RawFinding[];
20
+ /** 1-based line spans of the request calls the detector handled (resolved or not). */
21
+ coveredSpans: Array<{
22
+ startLine: number;
23
+ endLine: number;
24
+ }>;
25
+ }
26
+ export declare function detectTsOutboundHttp(input: {
27
+ filePath: string;
28
+ content: string;
29
+ config: UnifiedPatternConfig;
30
+ }): TsOutboundHttpResult;