@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
@@ -0,0 +1,575 @@
1
+ "use strict";
2
+ /**
3
+ * TypeScript/JavaScript outbound HTTP destinations (DATAP-818), the counterpart of
4
+ * `python-outbound-http.ts`.
5
+ *
6
+ * It parses the file with the TypeScript compiler API (the TS analyzer's parser already
7
+ * depends on it) and finds request calls: the global `fetch`, and the raw HTTP libraries
8
+ * marked `rawHttp` in `typescript.patterns.yaml` (axios, got, ky, node-fetch ...), including
9
+ * instances made with `axios.create({ baseURL })` / `got.extend({ prefixUrl })`. The URL is
10
+ * resolved from literals and template literals, `const` bindings, parameter defaults,
11
+ * `??` / `||` defaults on `process.env`, object-literal constants, and `const` exports of
12
+ * same-repo modules imported with a relative path. A known host names the vendor; a URL that
13
+ * only comes from the environment (`import.meta.env.VITE_*`, `process.env.X` with no default)
14
+ * gives an outbound call with no vendor. A library is never the destination. Relative URLs
15
+ * with no base are same-origin calls and are not reported.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.detectTsOutboundHttp = detectTsOutboundHttp;
52
+ const ts = __importStar(require("typescript"));
53
+ const python_outbound_http_1 = require("./python-outbound-http");
54
+ const source_module_index_1 = require("./source-module-index");
55
+ const REQUEST_VERBS = new Set(["get", "post", "put", "patch", "delete", "head", "options", "request"]);
56
+ const MAX_DEPTH = 10;
57
+ const MAX_VALUES = 8;
58
+ const ENV_PREFIX = "{env:";
59
+ function scriptKind(path) {
60
+ if (/\.tsx$/.test(path))
61
+ return ts.ScriptKind.TSX;
62
+ if (/\.jsx$/.test(path))
63
+ return ts.ScriptKind.JSX;
64
+ if (/\.[cm]?js$/.test(path))
65
+ return ts.ScriptKind.JS;
66
+ return ts.ScriptKind.TS;
67
+ }
68
+ const sourceCache = new Map();
69
+ function parse(path, content) {
70
+ const key = `${path}\u0000${content.length}\u0000${content.slice(0, 64)}`;
71
+ const cached = sourceCache.get(key);
72
+ if (cached && cached.text === content)
73
+ return cached;
74
+ const sf = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true, scriptKind(path));
75
+ if (sourceCache.size > 64)
76
+ sourceCache.clear();
77
+ sourceCache.set(key, sf);
78
+ return sf;
79
+ }
80
+ function unwrap(node) {
81
+ let current = node;
82
+ while (ts.isParenthesizedExpression(current) ||
83
+ ts.isAsExpression(current) ||
84
+ ts.isNonNullExpression(current) ||
85
+ ts.isTypeAssertionExpression(current) ||
86
+ ts.isSatisfiesExpression(current)) {
87
+ current = current.expression;
88
+ }
89
+ return current;
90
+ }
91
+ function isEnvAccess(node) {
92
+ // process.env.X, process.env["X"], import.meta.env.X
93
+ const n = unwrap(node);
94
+ const target = ts.isPropertyAccessExpression(n) ? n.expression : ts.isElementAccessExpression(n) ? n.expression : undefined;
95
+ if (!target)
96
+ return undefined;
97
+ const text = target.getText();
98
+ if (text !== "process.env" && text !== "import.meta.env")
99
+ return undefined;
100
+ return ts.isPropertyAccessExpression(n) ? n.name.text : n.getText();
101
+ }
102
+ function product(left, right) {
103
+ const out = [];
104
+ for (const l of left)
105
+ for (const r of right) {
106
+ out.push({ text: l.text + r.text });
107
+ if (out.length >= MAX_VALUES)
108
+ return out;
109
+ }
110
+ return out;
111
+ }
112
+ function dedupe(values) {
113
+ const seen = new Set();
114
+ return values.filter((v) => (seen.has(v.text) ? false : (seen.add(v.text), true))).slice(0, MAX_VALUES);
115
+ }
116
+ /** Drop environment-only values when a concrete default exists (`process.env.X ?? "https://..."`). */
117
+ function preferConcrete(values) {
118
+ const concrete = values.filter((v) => !v.text.startsWith(ENV_PREFIX));
119
+ return concrete.length > 0 ? concrete : values;
120
+ }
121
+ class TsResolver {
122
+ constructor(path) {
123
+ this.path = path;
124
+ }
125
+ eval(node, depth = 0) {
126
+ if (depth > MAX_DEPTH)
127
+ return [];
128
+ const n = unwrap(node);
129
+ const next = depth + 1;
130
+ if (ts.isStringLiteral(n) || ts.isNoSubstitutionTemplateLiteral(n))
131
+ return [{ text: n.text }];
132
+ if (ts.isTemplateExpression(n)) {
133
+ let acc = [{ text: n.head.text }];
134
+ for (const span of n.templateSpans) {
135
+ const values = this.eval(span.expression, next);
136
+ const piece = values.length > 0 ? values : [{ text: `{${span.expression.getText()}}` }];
137
+ acc = product(product(acc, piece), [{ text: span.literal.text }]);
138
+ }
139
+ return acc;
140
+ }
141
+ const env = isEnvAccess(n);
142
+ if (env)
143
+ return [{ text: `${ENV_PREFIX}${env}}` }];
144
+ if (ts.isBinaryExpression(n)) {
145
+ const op = n.operatorToken.kind;
146
+ if (op === ts.SyntaxKind.QuestionQuestionToken || op === ts.SyntaxKind.BarBarToken) {
147
+ return preferConcrete(dedupe([...this.eval(n.left, next), ...this.eval(n.right, next)]));
148
+ }
149
+ if (op === ts.SyntaxKind.PlusToken) {
150
+ const l = this.eval(n.left, next);
151
+ const r = this.eval(n.right, next);
152
+ if (l.length === 0 && r.length === 0)
153
+ return [];
154
+ return product(l.length ? l : [{ text: `{${n.left.getText()}}` }], r.length ? r : [{ text: `{${n.right.getText()}}` }]);
155
+ }
156
+ return [];
157
+ }
158
+ if (ts.isConditionalExpression(n))
159
+ return dedupe([...this.eval(n.whenTrue, next), ...this.eval(n.whenFalse, next)]);
160
+ if (ts.isIdentifier(n))
161
+ return this.resolveIdentifier(n, next);
162
+ if (ts.isPropertyAccessExpression(n)) {
163
+ // CONFIG.apiBase where CONFIG is a const object literal.
164
+ const obj = this.objectLiteralOf(n.expression, next);
165
+ const prop = obj?.properties.find((p) => ts.isPropertyAssignment(p) && propertyName(p) === n.name.text);
166
+ return prop ? this.eval(prop.initializer, next) : [];
167
+ }
168
+ if (ts.isCallExpression(n) && ts.isIdentifier(n.expression) && n.expression.text === "String" && n.arguments[0]) {
169
+ return this.eval(n.arguments[0], next);
170
+ }
171
+ return [];
172
+ }
173
+ /** Object literal a name or expression refers to (for property reads and instance options). */
174
+ objectLiteralOf(node, depth) {
175
+ const n = unwrap(node);
176
+ if (ts.isObjectLiteralExpression(n))
177
+ return n;
178
+ if (ts.isIdentifier(n) && depth <= MAX_DEPTH) {
179
+ const decl = this.declarationOf(n);
180
+ if (decl?.initializer)
181
+ return this.objectLiteralOf(decl.initializer, depth + 1);
182
+ }
183
+ return undefined;
184
+ }
185
+ resolveIdentifier(id, depth) {
186
+ const name = id.text;
187
+ // Parameters: use the default value (`apiBase = DEFAULT_API_BASE`).
188
+ for (let node = id.parent; node; node = node.parent) {
189
+ if (ts.isFunctionLike(node)) {
190
+ const param = node.parameters.find((p) => ts.isIdentifier(p.name) && p.name.text === name);
191
+ if (param)
192
+ return param.initializer ? this.eval(param.initializer, depth) : [];
193
+ }
194
+ }
195
+ const decl = this.declarationOf(id);
196
+ if (decl)
197
+ return decl.initializer ? this.eval(decl.initializer, depth) : [];
198
+ return this.importedConst(id, depth);
199
+ }
200
+ /** Nearest `const/let/var name = ...` visible from `id` (block, function or file level). */
201
+ declarationOf(id) {
202
+ const name = id.text;
203
+ for (let node = id.parent; node; node = node.parent) {
204
+ if (!(ts.isBlock(node) || ts.isSourceFile(node) || ts.isModuleBlock(node)))
205
+ continue;
206
+ for (const stmt of node.statements) {
207
+ if (!ts.isVariableStatement(stmt))
208
+ continue;
209
+ for (const d of stmt.declarationList.declarations) {
210
+ if (ts.isIdentifier(d.name) && d.name.text === name)
211
+ return d;
212
+ }
213
+ }
214
+ }
215
+ return undefined;
216
+ }
217
+ /** `import { NAME } from "./settings"` -> the exported const in that same-repo module. */
218
+ importedConst(id, depth) {
219
+ const sf = id.getSourceFile();
220
+ for (const stmt of sf.statements) {
221
+ if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
222
+ continue;
223
+ const bindings = stmt.importClause?.namedBindings;
224
+ if (!bindings || !ts.isNamedImports(bindings))
225
+ continue;
226
+ const el = bindings.elements.find((e) => e.name.text === id.text);
227
+ if (!el)
228
+ continue;
229
+ const exported = (el.propertyName ?? el.name).text;
230
+ const path = (0, source_module_index_1.resolveTsModulePath)(sf.fileName || this.path, stmt.moduleSpecifier.text);
231
+ const source = path ? (0, source_module_index_1.sourceModule)(path) : undefined;
232
+ if (!path || source === undefined)
233
+ return [];
234
+ const target = parse(path, source);
235
+ for (const s of target.statements) {
236
+ if (!ts.isVariableStatement(s))
237
+ continue;
238
+ for (const d of s.declarationList.declarations) {
239
+ if (ts.isIdentifier(d.name) && d.name.text === exported && d.initializer) {
240
+ return new TsResolver(path).eval(d.initializer, depth + 1);
241
+ }
242
+ }
243
+ }
244
+ return [];
245
+ }
246
+ return [];
247
+ }
248
+ }
249
+ function propertyName(p) {
250
+ const n = p.name;
251
+ if (!n)
252
+ return undefined;
253
+ if (ts.isIdentifier(n) || ts.isStringLiteral(n))
254
+ return n.text;
255
+ return undefined;
256
+ }
257
+ /** Local names bound to a library (default/namespace import or require) and to its request functions. */
258
+ function libraryBindings(sf, libs) {
259
+ const libByName = new Map();
260
+ const fnByName = new Map();
261
+ const libForModule = (spec) => libs.find((l) => l.config.modules.includes(spec));
262
+ for (const stmt of sf.statements) {
263
+ if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
264
+ continue;
265
+ const lib = libForModule(stmt.moduleSpecifier.text);
266
+ const clause = stmt.importClause;
267
+ if (!lib || !clause)
268
+ continue;
269
+ if (clause.name)
270
+ libByName.set(clause.name.text, lib);
271
+ const nb = clause.namedBindings;
272
+ if (nb && ts.isNamespaceImport(nb))
273
+ libByName.set(nb.name.text, lib);
274
+ if (nb && ts.isNamedImports(nb)) {
275
+ for (const el of nb.elements) {
276
+ const imported = (el.propertyName ?? el.name).text;
277
+ if (imported === "default")
278
+ libByName.set(el.name.text, lib);
279
+ else if (lib.config.namedFunctions.includes(imported))
280
+ fnByName.set(el.name.text, lib);
281
+ }
282
+ }
283
+ }
284
+ const visitRequires = (node) => {
285
+ if (ts.isVariableDeclaration(node) && node.initializer) {
286
+ const init = unwrap(node.initializer);
287
+ if (ts.isCallExpression(init) && ts.isIdentifier(init.expression) && init.expression.text === "require") {
288
+ const arg = init.arguments[0];
289
+ const lib = arg && ts.isStringLiteral(arg) ? libForModule(arg.text) : undefined;
290
+ if (lib && ts.isIdentifier(node.name))
291
+ libByName.set(node.name.text, lib);
292
+ if (lib && ts.isObjectBindingPattern(node.name)) {
293
+ for (const el of node.name.elements) {
294
+ const imported = (el.propertyName && ts.isIdentifier(el.propertyName) ? el.propertyName : el.name);
295
+ if (ts.isIdentifier(el.name) && lib.config.namedFunctions.includes(imported.text))
296
+ fnByName.set(el.name.text, lib);
297
+ }
298
+ }
299
+ }
300
+ }
301
+ ts.forEachChild(node, visitRequires);
302
+ };
303
+ visitRequires(sf);
304
+ return { libByName, fnByName };
305
+ }
306
+ const bindingsCache = new WeakMap();
307
+ function bindingsOf(sf, libs) {
308
+ let cached = bindingsCache.get(sf);
309
+ if (!cached) {
310
+ cached = libraryBindings(sf, libs);
311
+ bindingsCache.set(sf, cached);
312
+ }
313
+ return cached;
314
+ }
315
+ /** Top-level `const NAME = ...` in a file. */
316
+ function topLevelConst(sf, name) {
317
+ for (const stmt of sf.statements) {
318
+ if (!ts.isVariableStatement(stmt))
319
+ continue;
320
+ for (const d of stmt.declarationList.declarations)
321
+ if (ts.isIdentifier(d.name) && d.name.text === name)
322
+ return d;
323
+ }
324
+ return undefined;
325
+ }
326
+ /**
327
+ * The expression a same-repo module exports under `exported` ("default" for the default
328
+ * export): `export const X = ...`, `export { local as X }`, `export default local`, or
329
+ * `export default <expression>`.
330
+ */
331
+ function exportedExpression(sf, exported) {
332
+ for (const stmt of sf.statements) {
333
+ if (exported === "default" && ts.isExportAssignment(stmt) && !stmt.isExportEquals)
334
+ return stmt.expression;
335
+ if (ts.isExportDeclaration(stmt) && !stmt.moduleSpecifier && stmt.exportClause && ts.isNamedExports(stmt.exportClause)) {
336
+ const el = stmt.exportClause.elements.find((e) => e.name.text === exported);
337
+ if (el)
338
+ return ts.factory.createIdentifier((el.propertyName ?? el.name).text);
339
+ }
340
+ }
341
+ const decl = exported !== "default" ? topLevelConst(sf, exported) : undefined;
342
+ return decl?.initializer;
343
+ }
344
+ function instanceFor(expr, sf, libs, depth) {
345
+ if (depth > 4)
346
+ return undefined;
347
+ const n = unwrap(expr);
348
+ let init;
349
+ let home = sf;
350
+ if (ts.isIdentifier(n)) {
351
+ // Local binding first (synthesized identifiers from re-exports have no parent).
352
+ const local = n.parent ? new TsResolver(sf.fileName).declarationOf(n) : topLevelConst(sf, n.text);
353
+ if (local?.initializer)
354
+ init = local.initializer;
355
+ else {
356
+ const imported = importedBinding(sf, n.text);
357
+ if (!imported)
358
+ return undefined;
359
+ const path = (0, source_module_index_1.resolveTsModulePath)(sf.fileName, imported.spec);
360
+ const source = path ? (0, source_module_index_1.sourceModule)(path) : undefined;
361
+ if (!path || source === undefined)
362
+ return undefined;
363
+ home = parse(path, source);
364
+ const target = exportedExpression(home, imported.exported);
365
+ if (!target)
366
+ return undefined;
367
+ if (ts.isIdentifier(target))
368
+ return instanceFor(target, home, libs, depth + 1);
369
+ init = target;
370
+ }
371
+ }
372
+ else {
373
+ init = n;
374
+ }
375
+ const call = unwrap(init);
376
+ if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression)) {
377
+ return ts.isIdentifier(call) && call !== n ? instanceFor(call, home, libs, depth + 1) : undefined;
378
+ }
379
+ const owner = unwrap(call.expression.expression);
380
+ const lib = ts.isIdentifier(owner) ? bindingsOf(home, libs).libByName.get(owner.text) : undefined;
381
+ if (!lib || !lib.config.instanceFactories.includes(call.expression.name.text))
382
+ return undefined;
383
+ const resolver = new TsResolver(home.fileName);
384
+ const options = call.arguments[0] ? resolver.objectLiteralOf(call.arguments[0], 0) : undefined;
385
+ const baseProp = options?.properties.find((p) => ts.isPropertyAssignment(p) && lib.config.baseUrlKeys.includes(propertyName(p) ?? ""));
386
+ return { lib, ...(baseProp ? { base: baseProp.initializer } : {}) };
387
+ }
388
+ /** `import X from "./m"` / `import { Y as X } from "./m"` -> where X comes from. */
389
+ function importedBinding(sf, local) {
390
+ for (const stmt of sf.statements) {
391
+ if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
392
+ continue;
393
+ const clause = stmt.importClause;
394
+ if (!clause)
395
+ continue;
396
+ if (clause.name?.text === local)
397
+ return { spec: stmt.moduleSpecifier.text, exported: "default" };
398
+ const nb = clause.namedBindings;
399
+ if (nb && ts.isNamedImports(nb)) {
400
+ const el = nb.elements.find((e) => e.name.text === local);
401
+ if (el)
402
+ return { spec: stmt.moduleSpecifier.text, exported: (el.propertyName ?? el.name).text };
403
+ }
404
+ }
405
+ return undefined;
406
+ }
407
+ function detectTsOutboundHttp(input) {
408
+ const { filePath, content, config } = input;
409
+ const empty = { findings: [], coveredSpans: [] };
410
+ const libs = config.typescript.externalApis.httpClients
411
+ .filter((c) => c.rawHttp)
412
+ .map((c) => ({ name: c.clientName, config: c.rawHttp }));
413
+ // A file may also call an instance created in another module (`import { backend } from "../lib/http"`).
414
+ const mentionsHttp = /\bfetch\s*\(/.test(content) || libs.some((l) => l.config.modules.some((m) => content.includes(m)));
415
+ const relativeImport = /\bfrom\s+["']\.{1,2}\//.test(content);
416
+ if (!mentionsHttp && !relativeImport)
417
+ return empty;
418
+ let sf;
419
+ try {
420
+ sf = parse(filePath, content);
421
+ }
422
+ catch {
423
+ return empty;
424
+ }
425
+ const resolver = new TsResolver(filePath);
426
+ const router = new python_outbound_http_1.DestinationRouter(config, [...libs.map((l) => l.name), ...libs.flatMap((l) => l.config.modules), "fetch"]);
427
+ const { libByName, fnByName } = libraryBindings(sf, libs);
428
+ // Instances: `const api = axios.create({ baseURL })`, here or exported by a same-repo module.
429
+ const instanceOf = (expr) => instanceFor(expr, sf, libs, 0);
430
+ const findings = [];
431
+ const coveredSpans = [];
432
+ const lineOf = (pos) => sf.getLineAndCharacterOfPosition(pos).line + 1;
433
+ const lines = content.split(/\r?\n/);
434
+ const urlFromArg = (arg) => {
435
+ if (!arg)
436
+ return undefined;
437
+ const obj = ts.isObjectLiteralExpression(unwrap(arg)) ? unwrap(arg) : undefined;
438
+ if (!obj)
439
+ return arg;
440
+ const urlProp = obj.properties.find((p) => ts.isPropertyAssignment(p) && propertyName(p) === "url");
441
+ return urlProp?.initializer;
442
+ };
443
+ const hintFor = (node) => {
444
+ const names = [filePath];
445
+ for (let n = node.parent; n; n = n.parent) {
446
+ if ((ts.isFunctionDeclaration(n) || ts.isClassDeclaration(n) || ts.isMethodDeclaration(n)) && n.name && ts.isIdentifier(n.name)) {
447
+ names.push(n.name.text);
448
+ }
449
+ }
450
+ return names.join(" ").toLowerCase();
451
+ };
452
+ const handle = (call, lib, urlExpr, base) => {
453
+ const startLine = lineOf(call.getStart());
454
+ const endLine = lineOf(call.getEnd());
455
+ coveredSpans.push({ startLine, endLine });
456
+ const urlValues = urlExpr ? resolver.eval(urlExpr) : [];
457
+ const absolute = urlValues.filter((v) => /^(https?|wss?):\/\//i.test(v.text));
458
+ let candidates = absolute;
459
+ let envOnly = urlValues.length > 0 && urlValues.every((v) => v.text.startsWith(ENV_PREFIX));
460
+ const envNames = new Set();
461
+ const noteEnv = (values) => {
462
+ for (const v of values) {
463
+ const m = /^\{env:([^}]+)\}/.exec(v.text);
464
+ if (m)
465
+ envNames.add(m[1]);
466
+ }
467
+ };
468
+ noteEnv(urlValues);
469
+ if (candidates.length === 0 && base) {
470
+ const bases = new TsResolver(base.getSourceFile().fileName).eval(base);
471
+ noteEnv(bases);
472
+ const absoluteBases = bases.filter((v) => /^(https?|wss?):\/\//i.test(v.text));
473
+ if (absoluteBases.length > 0) {
474
+ const rel = urlValues.length > 0 ? urlValues : [{ text: urlExpr ? `{${urlExpr.getText()}}` : "" }];
475
+ candidates = absoluteBases.flatMap((b) => rel.map((r) => ({ text: `${b.text.replace(/\/+$/, "")}/${r.text.replace(/^\/+/, "")}` })));
476
+ }
477
+ else if (bases.length > 0 && bases.every((v) => v.text.startsWith(ENV_PREFIX))) {
478
+ envOnly = true;
479
+ }
480
+ }
481
+ const location = { filePath, startLine, endLine, code: lines[startLine - 1]?.trim() ?? "" };
482
+ const seen = new Set();
483
+ let reported = false;
484
+ for (const v of candidates) {
485
+ const routed = router.route(v.text, hintFor(call), true);
486
+ if (routed === "unknown")
487
+ continue;
488
+ if ("remote" in routed) {
489
+ const host = routed.remote.host;
490
+ if (seen.has(`remote:${host}`))
491
+ continue;
492
+ seen.add(`remote:${host}`);
493
+ reported = true;
494
+ findings.push({
495
+ pattern: "external_api_call",
496
+ name: (0, python_outbound_http_1.remoteServiceName)(routed.remote),
497
+ confidence: 0.85,
498
+ location,
499
+ properties: (0, python_outbound_http_1.remoteServiceProperties)(routed.remote, v.text, { client: lib, httpClientLibrary: lib }),
500
+ });
501
+ continue;
502
+ }
503
+ const name = routed.subType ? `${routed.serviceName} ${routed.subType}` : routed.serviceName;
504
+ if (seen.has(name))
505
+ continue;
506
+ seen.add(name);
507
+ reported = true;
508
+ findings.push({
509
+ pattern: "external_api_call",
510
+ name,
511
+ confidence: 0.85,
512
+ location,
513
+ properties: {
514
+ serviceName: routed.serviceName,
515
+ url: v.text,
516
+ ...(routed.subType ? { thirdPartySubType: routed.subType } : {}),
517
+ client: lib, httpClientLibrary: lib,
518
+ },
519
+ });
520
+ }
521
+ // Outbound with no vendor: the URL or base exists only in the environment, or the URL is
522
+ // absolute with a host the router cannot name. Same-origin relative calls stay silent.
523
+ if (!reported && (envOnly || candidates.length > 0)) {
524
+ // Name the remote service after the setting that holds its URL, so two env-configured
525
+ // backends stay two API assets.
526
+ const envVar = [...envNames].sort()[0];
527
+ findings.push({
528
+ pattern: "external_api_call",
529
+ name: envVar && envOnly ? envVar : python_outbound_http_1.OUTBOUND_HTTP_UNKNOWN_FINDING_NAME,
530
+ confidence: 0.8,
531
+ location,
532
+ properties: { client: lib, httpClientLibrary: lib, destination: "unknown", ...(envVar && envOnly ? { envVar } : {}) },
533
+ });
534
+ }
535
+ };
536
+ const visit = (node) => {
537
+ if (ts.isCallExpression(node)) {
538
+ const callee = unwrap(node.expression);
539
+ if (ts.isIdentifier(callee)) {
540
+ const lib = libByName.get(callee.text);
541
+ const fn = fnByName.get(callee.text);
542
+ if (callee.text === "fetch" && !lib && !fn)
543
+ handle(node, "fetch", urlFromArg(node.arguments[0]), undefined);
544
+ else if (fn)
545
+ handle(node, fn.name, urlFromArg(node.arguments[0]), undefined);
546
+ else if (lib?.config.callable)
547
+ handle(node, lib.name, urlFromArg(node.arguments[0]), undefined);
548
+ else {
549
+ const inst = instanceOf(callee);
550
+ if (inst)
551
+ handle(node, inst.lib.name, urlFromArg(node.arguments[0]), inst.base);
552
+ }
553
+ }
554
+ else if (ts.isPropertyAccessExpression(callee) && REQUEST_VERBS.has(callee.name.text)) {
555
+ const owner = unwrap(callee.expression);
556
+ const lib = ts.isIdentifier(owner) ? libByName.get(owner.text) : undefined;
557
+ if (lib)
558
+ handle(node, lib.name, urlFromArg(node.arguments[0]), undefined);
559
+ else {
560
+ const inst = instanceOf(owner);
561
+ if (inst)
562
+ handle(node, inst.lib.name, urlFromArg(node.arguments[0]), inst.base);
563
+ }
564
+ }
565
+ }
566
+ ts.forEachChild(node, visit);
567
+ };
568
+ try {
569
+ visit(sf);
570
+ }
571
+ catch {
572
+ return empty;
573
+ }
574
+ return { findings, coveredSpans };
575
+ }
@@ -13,6 +13,7 @@ exports.detectTypeScriptServerlessHandlersFromConfig = detectTypeScriptServerles
13
13
  exports.detectTypeScriptExternalApisFromConfig = detectTypeScriptExternalApisFromConfig;
14
14
  const fs_1 = __importDefault(require("fs"));
15
15
  const path_1 = __importDefault(require("path"));
16
+ const typescript_outbound_http_1 = require("./typescript-outbound-http");
16
17
  const external_url_third_party_1 = require("../../classifier/external-url-third-party");
17
18
  const helpers_1 = require("./helpers");
18
19
  function importMatchesFragment(imp, fragment) {
@@ -33,10 +34,17 @@ function detectTypeScriptJavaScriptExternalApisFromHttpClients(ctx, config) {
33
34
  const content = ctx.file.content ?? "";
34
35
  const findings = [];
35
36
  const urlHostPatterns = (0, helpers_1.buildThirdPartyUrlHostPatterns)(config);
37
+ // Request calls resolved on the AST (fetch, axios, got, ky ...; DATAP-818). The line
38
+ // regexes below only fill in lines the AST detector did not handle.
39
+ const resolved = (0, typescript_outbound_http_1.detectTsOutboundHttp)({ filePath: ctx.file.path, content, config });
40
+ findings.push(...resolved.findings);
41
+ const covered = (line) => resolved.coveredSpans.some((span) => line >= span.startLine && line <= span.endLine);
36
42
  for (const client of config.thirdParty.httpClients) {
37
43
  for (const regex of client.callRegexes) {
38
44
  const httpMatches = (0, helpers_1.findLineMatches)(content, regex);
39
45
  for (const { line, match } of httpMatches) {
46
+ if (covered(line))
47
+ continue;
40
48
  const [, clientName, methodMaybe, url] = match;
41
49
  if ((0, external_url_third_party_1.shouldIgnoreExternalHttpUrl)(url)) {
42
50
  continue;
@@ -590,6 +598,10 @@ function detectTypeScriptExternalApisFromConfig(ctx, config) {
590
598
  const content = (0, helpers_1.sourceOf)(ctx);
591
599
  const findings = [];
592
600
  for (const client of config.typescript.externalApis.httpClients) {
601
+ // Raw HTTP libraries are resolved per request call by the AST detector when line
602
+ // patterns run; a library-named `axios_call` would read as a destination (DATAP-818).
603
+ if (client.rawHttp && ctx.includeThirdPartyHttpLinePatterns)
604
+ continue;
593
605
  const hasClientImport = client.importFragments.length === 0 ||
594
606
  client.importFragments.some((frag) => (ctx.imports ?? []).some((imp) => imp.module === frag ||
595
607
  imp.module.includes(frag) ||
@@ -24,6 +24,7 @@ function findFirstLineMatch(content, regex) {
24
24
  }
25
25
  return undefined;
26
26
  }
27
+ const INSTRUMENTATION_PACKAGE = /(^|[./@-])instrumentation([./-]|$)/i;
27
28
  function importMatchesFragment(imp, fragment) {
28
29
  return (imp.module.includes(fragment) ||
29
30
  imp.names.some((name) => name.includes(fragment)));
@@ -36,6 +37,10 @@ function detectThirdPartyServicesFromImportsWithConfig(ctx, config) {
36
37
  for (const svc of config.thirdParty.services) {
37
38
  const seenSpans = new Set();
38
39
  for (const imp of imports) {
40
+ // Instrumentation packages for a vendor SDK (`openinference.instrumentation.openai`,
41
+ // `@opentelemetry/instrumentation-aws-sdk`) trace calls; they do not call the vendor.
42
+ if (INSTRUMENTATION_PACKAGE.test(imp.module))
43
+ continue;
39
44
  const matches = svc.importFragments.some((frag) => importMatchesFragment(imp, frag));
40
45
  if (!matches)
41
46
  continue;
@@ -174,5 +179,5 @@ function matchPatterns(ctx) {
174
179
  findings.push(...(0, typescript_1.detectTypeScriptEnvAndConfigFromConfig)(ctx, config));
175
180
  findings.push(...(0, typescript_1.detectTypeScriptServerlessHandlersFromConfig)(ctx, config));
176
181
  findings.push(...(0, typescript_1.detectTypeScriptExternalApisFromConfig)(ctx, config));
177
- return findings;
182
+ return (0, python_1.dropRedirectedOpenAiImportFindings)(ctx, config, findings);
178
183
  }