@dataparade/cli 0.0.8 → 0.0.10

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 (164) hide show
  1. package/README.md +10 -10
  2. package/dist/package.json +1 -1
  3. package/dist/src/ai-enrichment/lambda-init-error.d.ts +5 -0
  4. package/dist/src/ai-enrichment/lambda-init-error.js +38 -0
  5. package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +5 -0
  6. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +27 -1
  7. package/dist/src/analyzers/cpp/cpp-detection-config.d.ts +73 -0
  8. package/dist/src/analyzers/cpp/cpp-detection-config.js +137 -0
  9. package/dist/src/analyzers/cpp/dependency-manifests.d.ts +8 -0
  10. package/dist/src/analyzers/cpp/dependency-manifests.js +130 -0
  11. package/dist/src/analyzers/cpp/detector.d.ts +3 -0
  12. package/dist/src/analyzers/cpp/detector.js +21 -0
  13. package/dist/src/analyzers/cpp/index.d.ts +2 -0
  14. package/dist/src/analyzers/cpp/index.js +11 -0
  15. package/dist/src/analyzers/cpp/manifest-parsers.d.ts +13 -0
  16. package/dist/src/analyzers/cpp/manifest-parsers.js +104 -0
  17. package/dist/src/analyzers/cpp/parser.d.ts +35 -0
  18. package/dist/src/analyzers/cpp/parser.js +206 -0
  19. package/dist/src/analyzers/cpp/patterns.d.ts +3 -0
  20. package/dist/src/analyzers/cpp/patterns.js +37 -0
  21. package/dist/src/analyzers/csharp/csharp-detection-config.d.ts +100 -0
  22. package/dist/src/analyzers/csharp/csharp-detection-config.js +160 -0
  23. package/dist/src/analyzers/csharp/dependency-manifests.d.ts +13 -0
  24. package/dist/src/analyzers/csharp/dependency-manifests.js +184 -0
  25. package/dist/src/analyzers/csharp/detector.d.ts +3 -0
  26. package/dist/src/analyzers/csharp/detector.js +21 -0
  27. package/dist/src/analyzers/csharp/index.d.ts +2 -0
  28. package/dist/src/analyzers/csharp/index.js +11 -0
  29. package/dist/src/analyzers/csharp/manifest-parsers.d.ts +34 -0
  30. package/dist/src/analyzers/csharp/manifest-parsers.js +130 -0
  31. package/dist/src/analyzers/csharp/parser.d.ts +48 -0
  32. package/dist/src/analyzers/csharp/parser.js +277 -0
  33. package/dist/src/analyzers/csharp/patterns.d.ts +3 -0
  34. package/dist/src/analyzers/csharp/patterns.js +57 -0
  35. package/dist/src/analyzers/go/dependency-manifests.d.ts +10 -0
  36. package/dist/src/analyzers/go/dependency-manifests.js +117 -0
  37. package/dist/src/analyzers/go/detector.d.ts +3 -0
  38. package/dist/src/analyzers/go/detector.js +21 -0
  39. package/dist/src/analyzers/go/go-detection-config.d.ts +97 -0
  40. package/dist/src/analyzers/go/go-detection-config.js +164 -0
  41. package/dist/src/analyzers/go/index.d.ts +2 -0
  42. package/dist/src/analyzers/go/index.js +11 -0
  43. package/dist/src/analyzers/go/manifest-parsers.d.ts +20 -0
  44. package/dist/src/analyzers/go/manifest-parsers.js +104 -0
  45. package/dist/src/analyzers/go/parser.d.ts +40 -0
  46. package/dist/src/analyzers/go/parser.js +186 -0
  47. package/dist/src/analyzers/go/patterns.d.ts +3 -0
  48. package/dist/src/analyzers/go/patterns.js +50 -0
  49. package/dist/src/analyzers/jvm/dependency-manifests.d.ts +16 -0
  50. package/dist/src/analyzers/jvm/dependency-manifests.js +205 -0
  51. package/dist/src/analyzers/jvm/detector.d.ts +3 -0
  52. package/dist/src/analyzers/jvm/detector.js +21 -0
  53. package/dist/src/analyzers/jvm/index.d.ts +9 -0
  54. package/dist/src/analyzers/jvm/index.js +18 -0
  55. package/dist/src/analyzers/jvm/jvm-detection-config.d.ts +136 -0
  56. package/dist/src/analyzers/jvm/jvm-detection-config.js +195 -0
  57. package/dist/src/analyzers/jvm/manifest-parsers.d.ts +61 -0
  58. package/dist/src/analyzers/jvm/manifest-parsers.js +246 -0
  59. package/dist/src/analyzers/jvm/parser.d.ts +54 -0
  60. package/dist/src/analyzers/jvm/parser.js +419 -0
  61. package/dist/src/analyzers/jvm/patterns.d.ts +3 -0
  62. package/dist/src/analyzers/jvm/patterns.js +64 -0
  63. package/dist/src/analyzers/python/detector.js +1 -1
  64. package/dist/src/analyzers/python/parser.d.ts +1 -0
  65. package/dist/src/analyzers/python/parser.js +7 -0
  66. package/dist/src/analyzers/python/patterns.d.ts +1 -0
  67. package/dist/src/analyzers/python/patterns.js +22 -77
  68. package/dist/src/analyzers/python/python-detection-config.d.ts +18 -0
  69. package/dist/src/analyzers/python/python-detection-config.js +20 -0
  70. package/dist/src/analyzers/registry.js +15 -0
  71. package/dist/src/analyzers/shared/c-family-calls.d.ts +26 -0
  72. package/dist/src/analyzers/shared/c-family-calls.js +118 -0
  73. package/dist/src/analyzers/shared/strip-comments.d.ts +32 -0
  74. package/dist/src/analyzers/shared/strip-comments.js +167 -0
  75. package/dist/src/analyzers/typescript/detector.js +1 -1
  76. package/dist/src/analyzers/typescript/typescript-detection-config.d.ts +37 -0
  77. package/dist/src/analyzers/typescript/typescript-detection-config.js +48 -0
  78. package/dist/src/analyzers/typescript/typescript-detection.d.ts +1 -0
  79. package/dist/src/analyzers/typescript/typescript-detection.js +27 -29
  80. package/dist/src/cli.js +1 -1
  81. package/dist/src/config/file.js +5 -0
  82. package/dist/src/config/resolve.js +5 -0
  83. package/dist/src/core/pipeline/graph-mapping.js +3 -0
  84. package/dist/src/core/pipeline/structural-scan.js +154 -31
  85. package/dist/src/core/schema/scan-config.schema.d.ts +5 -0
  86. package/dist/src/core/schema/scan-config.schema.js +5 -0
  87. package/dist/src/core/schema/scan-result.schema.d.ts +5 -0
  88. package/dist/src/core/schema/scan-result.schema.js +5 -0
  89. package/dist/src/core/sectioning/discover-service-sections.js +27 -1
  90. package/dist/src/core/types/file.d.ts +1 -1
  91. package/dist/src/ingest/file-system.js +27 -0
  92. package/dist/src/patterns/config.d.ts +8 -0
  93. package/dist/src/patterns/config.js +136 -0
  94. package/dist/src/patterns/detectors/cpp.d.ts +8 -0
  95. package/dist/src/patterns/detectors/cpp.js +243 -0
  96. package/dist/src/patterns/detectors/csharp.d.ts +9 -0
  97. package/dist/src/patterns/detectors/csharp.js +385 -0
  98. package/dist/src/patterns/detectors/go.d.ts +9 -0
  99. package/dist/src/patterns/detectors/go.js +298 -0
  100. package/dist/src/patterns/detectors/helpers.d.ts +3 -0
  101. package/dist/src/patterns/detectors/helpers.js +5 -0
  102. package/dist/src/patterns/detectors/jvm.d.ts +15 -0
  103. package/dist/src/patterns/detectors/jvm.js +537 -0
  104. package/dist/src/patterns/detectors/python.d.ts +1 -0
  105. package/dist/src/patterns/detectors/python.js +92 -5
  106. package/dist/src/patterns/detectors/typescript.d.ts +2 -0
  107. package/dist/src/patterns/detectors/typescript.js +156 -4
  108. package/dist/src/patterns/engine.d.ts +18 -0
  109. package/dist/src/patterns/engine.js +30 -0
  110. package/dist/src/patterns/scan-exclusions.js +20 -0
  111. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.d.ts +1 -0
  112. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.js +11 -0
  113. package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +80 -0
  114. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.d.ts +1 -0
  115. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.js +66 -0
  116. package/dist/tests/unit/analyzers/cpp/parser.spec.d.ts +1 -0
  117. package/dist/tests/unit/analyzers/cpp/parser.spec.js +80 -0
  118. package/dist/tests/unit/analyzers/cpp/patterns.spec.d.ts +1 -0
  119. package/dist/tests/unit/analyzers/cpp/patterns.spec.js +141 -0
  120. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.d.ts +1 -0
  121. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.js +75 -0
  122. package/dist/tests/unit/analyzers/csharp/parser.spec.d.ts +1 -0
  123. package/dist/tests/unit/analyzers/csharp/parser.spec.js +118 -0
  124. package/dist/tests/unit/analyzers/csharp/patterns.spec.d.ts +1 -0
  125. package/dist/tests/unit/analyzers/csharp/patterns.spec.js +210 -0
  126. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.d.ts +1 -0
  127. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.js +96 -0
  128. package/dist/tests/unit/analyzers/go/parser.spec.d.ts +1 -0
  129. package/dist/tests/unit/analyzers/go/parser.spec.js +110 -0
  130. package/dist/tests/unit/analyzers/go/patterns.spec.d.ts +1 -0
  131. package/dist/tests/unit/analyzers/go/patterns.spec.js +239 -0
  132. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.d.ts +1 -0
  133. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.js +179 -0
  134. package/dist/tests/unit/analyzers/jvm/parser.spec.d.ts +1 -0
  135. package/dist/tests/unit/analyzers/jvm/parser.spec.js +195 -0
  136. package/dist/tests/unit/analyzers/jvm/patterns.spec.d.ts +1 -0
  137. package/dist/tests/unit/analyzers/jvm/patterns.spec.js +284 -0
  138. package/dist/tests/unit/analyzers/python/patterns.spec.js +169 -0
  139. package/dist/tests/unit/analyzers/typescript/detector.spec.js +188 -0
  140. package/dist/tests/unit/core/cpp-dotnet-scan.spec.d.ts +1 -0
  141. package/dist/tests/unit/core/cpp-dotnet-scan.spec.js +67 -0
  142. package/dist/tests/unit/core/cpp-dotnet-sections.spec.d.ts +1 -0
  143. package/dist/tests/unit/core/cpp-dotnet-sections.spec.js +46 -0
  144. package/dist/tests/unit/core/go-scan.spec.d.ts +1 -0
  145. package/dist/tests/unit/core/go-scan.spec.js +78 -0
  146. package/dist/tests/unit/core/graph-mapping.spec.js +75 -0
  147. package/dist/tests/unit/core/jvm-scan.spec.d.ts +1 -0
  148. package/dist/tests/unit/core/jvm-scan.spec.js +94 -0
  149. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.d.ts +1 -0
  150. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.js +56 -0
  151. package/dist/tests/unit/ingest/jvm-languages.spec.d.ts +1 -0
  152. package/dist/tests/unit/ingest/jvm-languages.spec.js +47 -0
  153. package/package.json +1 -1
  154. package/patterns/cpp.md +176 -0
  155. package/patterns/cpp.patterns.yaml +314 -0
  156. package/patterns/csharp.md +211 -0
  157. package/patterns/csharp.patterns.yaml +375 -0
  158. package/patterns/go.md +211 -0
  159. package/patterns/go.patterns.yaml +429 -0
  160. package/patterns/jvm.md +160 -0
  161. package/patterns/jvm.patterns.yaml +884 -0
  162. package/patterns/python.patterns.yaml +177 -0
  163. package/patterns/third-party.patterns.yaml +5 -0
  164. package/patterns/typescript.patterns.yaml +222 -0
@@ -26,6 +26,24 @@ export interface PythonPatternConfig {
26
26
  callNames: string[];
27
27
  confidence: number;
28
28
  }>;
29
+ libraries: Array<{
30
+ id: string;
31
+ patternId: PatternId;
32
+ importModules: string[];
33
+ contentRegexes: RegExp[];
34
+ strategy?: string;
35
+ confidence: number;
36
+ }>;
37
+ };
38
+ serverless: {
39
+ handlers: Array<{
40
+ id: string;
41
+ patternId: PatternId;
42
+ importModules: string[];
43
+ functionNameRegexes: RegExp[];
44
+ decoratorNames: string[];
45
+ confidence: number;
46
+ }>;
29
47
  };
30
48
  routes: {
31
49
  frameworks: Array<{
@@ -56,6 +56,22 @@ function normalizeRawConfig(raw) {
56
56
  callNames: d.callNames ?? [],
57
57
  confidence: d.confidence ?? DEFAULT_CONFIDENCE,
58
58
  })) ?? [];
59
+ const authLibraries = raw.auth?.libraries?.map((lib) => ({
60
+ id: lib.id,
61
+ patternId: validatePatternId(lib.patternId, `python.auth.libraries['${lib.id}']`),
62
+ contentRegexes: (lib.contentRegexes ?? []).map((p) => new RegExp(p)),
63
+ importModules: lib.importModules ?? [],
64
+ strategy: lib.strategy,
65
+ confidence: lib.confidence ?? DEFAULT_CONFIDENCE,
66
+ })) ?? [];
67
+ const serverlessHandlers = raw.serverless?.handlers?.map((handler) => ({
68
+ id: handler.id,
69
+ patternId: validatePatternId(handler.patternId, `python.serverless.handlers['${handler.id}']`),
70
+ importModules: handler.importModules ?? [],
71
+ functionNameRegexes: (handler.functionNameRegexes ?? []).map((p) => new RegExp(p)),
72
+ decoratorNames: handler.decoratorNames ?? [],
73
+ confidence: handler.confidence ?? DEFAULT_CONFIDENCE,
74
+ })) ?? [];
59
75
  const routeFrameworks = raw.routes?.frameworks?.map((fw) => ({
60
76
  id: fw.id,
61
77
  patternId: validatePatternId(fw.patternId, `python.routes.frameworks['${fw.id}']`),
@@ -108,6 +124,10 @@ function normalizeRawConfig(raw) {
108
124
  auth: {
109
125
  jwt: authJwt,
110
126
  decorators: authDecorators,
127
+ libraries: authLibraries,
128
+ },
129
+ serverless: {
130
+ handlers: serverlessHandlers,
111
131
  },
112
132
  routes: {
113
133
  frameworks: routeFrameworks,
@@ -6,6 +6,10 @@ exports.runAnalyzers = runAnalyzers;
6
6
  exports.runAnalyzersForRootPath = runAnalyzersForRootPath;
7
7
  exports.__clearAnalyzersForTest = __clearAnalyzersForTest;
8
8
  const file_system_1 = require("../ingest/file-system");
9
+ const cpp_1 = require("./cpp");
10
+ const go_1 = require("./go");
11
+ const jvm_1 = require("./jvm");
12
+ const csharp_1 = require("./csharp");
9
13
  const python_1 = require("./python");
10
14
  const terraform_1 = require("./terraform");
11
15
  const typescript_1 = require("./typescript");
@@ -13,9 +17,20 @@ const terraform_detection_config_1 = require("./terraform/terraform-detection-co
13
17
  const detector_1 = require("./terraform/detector");
14
18
  const typeScriptAnalyzer = (0, typescript_1.createTypeScriptAnalyzer)();
15
19
  const pythonAnalyzer = (0, python_1.createPythonAnalyzer)();
20
+ const cppAnalyzer = (0, cpp_1.createCppAnalyzer)();
21
+ const goAnalyzer = (0, go_1.createGoAnalyzer)();
22
+ const jvmAnalyzer = (0, jvm_1.createJvmAnalyzer)();
23
+ const cSharpAnalyzer = (0, csharp_1.createCSharpAnalyzer)();
16
24
  const terraformAnalyzer = (0, terraform_1.createTerraformAnalyzer)();
17
25
  const registry = new Map([
18
26
  ["python", pythonAnalyzer],
27
+ ["go", goAnalyzer],
28
+ // Java and Kotlin share one analyzer: same package namespace, same
29
+ // Maven/Gradle coordinates, same Spring/Jakarta annotations, same JDBC.
30
+ ["java", jvmAnalyzer],
31
+ ["kotlin", jvmAnalyzer],
32
+ ["cpp", cppAnalyzer],
33
+ ["csharp", cSharpAnalyzer],
19
34
  ["terraform", terraformAnalyzer],
20
35
  ["typescript", typeScriptAnalyzer],
21
36
  ["javascript", typeScriptAnalyzer],
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Call-site extraction shared by the C-family parsers (C++, C#).
3
+ *
4
+ * Both languages express external I/O as call expressions on qualified names
5
+ * (`curl_easy_setopt(...)`, `httpClient.GetAsync(...)`, `cpr::Get(...)`), so
6
+ * the same line scanner serves both. Callers pass comment-stripped lines.
7
+ */
8
+ import type { SourceLocation } from "../../core/types/file";
9
+ export interface CFamilyCallEntry {
10
+ /** Fully qualified callee as written, e.g. `cpr::Get` or `client.GetAsync`. */
11
+ callee: string;
12
+ argumentsSnippet: string;
13
+ location: SourceLocation;
14
+ }
15
+ export interface ExtractCallsOptions {
16
+ filePath: string;
17
+ /** Guard against pathological files; callers keep the default. */
18
+ maxCalls?: number;
19
+ }
20
+ /**
21
+ * Extract call sites from comment-stripped source lines.
22
+ *
23
+ * Stripping blanks comments only, so string literals (including URLs) are
24
+ * still intact in the arguments snippet.
25
+ */
26
+ export declare function extractCFamilyCalls(strippedLines: string[], options: ExtractCallsOptions): CFamilyCallEntry[];
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * Call-site extraction shared by the C-family parsers (C++, C#).
4
+ *
5
+ * Both languages express external I/O as call expressions on qualified names
6
+ * (`curl_easy_setopt(...)`, `httpClient.GetAsync(...)`, `cpr::Get(...)`), so
7
+ * the same line scanner serves both. Callers pass comment-stripped lines.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.extractCFamilyCalls = extractCFamilyCalls;
11
+ /** Keywords that look like calls but are control flow, not invocations. */
12
+ const CONTROL_KEYWORDS = new Set([
13
+ "if",
14
+ "for",
15
+ "while",
16
+ "switch",
17
+ "catch",
18
+ "return",
19
+ "sizeof",
20
+ "throw",
21
+ "lock",
22
+ "using",
23
+ "fixed",
24
+ "foreach",
25
+ "do",
26
+ "else",
27
+ "case",
28
+ "new",
29
+ "typeof",
30
+ "nameof",
31
+ "alignof",
32
+ "decltype",
33
+ "static_assert",
34
+ "defined",
35
+ // Go keywords and builtins that read as calls but are not invocations.
36
+ "func",
37
+ "make",
38
+ "len",
39
+ "cap",
40
+ "append",
41
+ "copy",
42
+ "panic",
43
+ "recover",
44
+ "delete",
45
+ "print",
46
+ "println",
47
+ "range",
48
+ "select",
49
+ "go",
50
+ "defer",
51
+ // Java and Kotlin: declarations, control flow, and constructor delegation
52
+ // that read as calls but are not invocations.
53
+ "assert",
54
+ "synchronized",
55
+ "instanceof",
56
+ "super",
57
+ "this",
58
+ "when",
59
+ "try",
60
+ "finally",
61
+ "class",
62
+ "object",
63
+ "init",
64
+ "constructor",
65
+ "val",
66
+ "var",
67
+ "is",
68
+ "as",
69
+ "in",
70
+ "yield",
71
+ "record",
72
+ ]);
73
+ const CALL_REGEX = /\b([A-Za-z_][A-Za-z0-9_]*(?:(?:::|\.|->)[A-Za-z_][A-Za-z0-9_]*)*)\s*\(/g;
74
+ const MAX_ARGUMENTS_SNIPPET_LENGTH = 200;
75
+ const DEFAULT_MAX_CALLS = 5_000;
76
+ /**
77
+ * Extract call sites from comment-stripped source lines.
78
+ *
79
+ * Stripping blanks comments only, so string literals (including URLs) are
80
+ * still intact in the arguments snippet.
81
+ */
82
+ function extractCFamilyCalls(strippedLines, options) {
83
+ const maxCalls = options.maxCalls ?? DEFAULT_MAX_CALLS;
84
+ const calls = [];
85
+ for (let i = 0; i < strippedLines.length; i += 1) {
86
+ if (calls.length >= maxCalls)
87
+ break;
88
+ const line = strippedLines[i] ?? "";
89
+ if (!line.includes("("))
90
+ continue;
91
+ CALL_REGEX.lastIndex = 0;
92
+ let match;
93
+ while ((match = CALL_REGEX.exec(line)) !== null) {
94
+ if (calls.length >= maxCalls)
95
+ break;
96
+ const callee = match[1];
97
+ const lastSegment = callee.split(/::|\.|->/).pop() ?? callee;
98
+ if (CONTROL_KEYWORDS.has(callee) || CONTROL_KEYWORDS.has(lastSegment)) {
99
+ continue;
100
+ }
101
+ const openParenIndex = match.index + match[0].length - 1;
102
+ const argumentsSnippet = line
103
+ .slice(openParenIndex + 1)
104
+ .slice(0, MAX_ARGUMENTS_SNIPPET_LENGTH);
105
+ calls.push({
106
+ callee,
107
+ argumentsSnippet,
108
+ location: {
109
+ filePath: options.filePath,
110
+ startLine: i + 1,
111
+ endLine: i + 1,
112
+ code: line.trim().slice(0, MAX_ARGUMENTS_SNIPPET_LENGTH),
113
+ },
114
+ });
115
+ }
116
+ }
117
+ return calls;
118
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Comment stripping for source files (C++, C#, TypeScript/JavaScript, Python, Go, Java, Kotlin).
3
+ *
4
+ * Comments are replaced with spaces rather than removed so line and column
5
+ * offsets stay identical to the original file. That keeps `SourceLocation`
6
+ * line numbers accurate for findings produced from the stripped text.
7
+ *
8
+ * String literals are preserved verbatim: a URL such as `"https://api.x/v1"`
9
+ * must survive stripping, so the scanner tracks string state instead of
10
+ * blindly cutting at the first `//`.
11
+ */
12
+ export interface StripCommentsOptions {
13
+ /** C++ raw string literals: `R"delim( ... )delim"`. */
14
+ rawStrings?: boolean;
15
+ /** C# verbatim string literals: `@"..."`, where `""` is an escaped quote. */
16
+ verbatimStrings?: boolean;
17
+ /** Python `#` line comments. */
18
+ hashComments?: boolean;
19
+ /** Python `"""..."""` and `'''...'''` string literals. */
20
+ tripleQuoteStrings?: boolean;
21
+ /** Go raw string literals: backtick-delimited, no escapes, may span lines. */
22
+ backtickStrings?: boolean;
23
+ /** Java text blocks and Kotlin raw strings: `"""..."""`, may span lines. */
24
+ tripleQuotedStrings?: boolean;
25
+ /**
26
+ * Kotlin permits nested block comments: an inner open delimiter must be
27
+ * matched by its own close delimiter, so the comment ends at the last one
28
+ * rather than the first. Java and the rest of the C family do not nest.
29
+ */
30
+ nestedBlockComments?: boolean;
31
+ }
32
+ export declare function stripCommentsPreservingLayout(source: string, options?: StripCommentsOptions): string;
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ /**
3
+ * Comment stripping for source files (C++, C#, TypeScript/JavaScript, Python, Go, Java, Kotlin).
4
+ *
5
+ * Comments are replaced with spaces rather than removed so line and column
6
+ * offsets stay identical to the original file. That keeps `SourceLocation`
7
+ * line numbers accurate for findings produced from the stripped text.
8
+ *
9
+ * String literals are preserved verbatim: a URL such as `"https://api.x/v1"`
10
+ * must survive stripping, so the scanner tracks string state instead of
11
+ * blindly cutting at the first `//`.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.stripCommentsPreservingLayout = stripCommentsPreservingLayout;
15
+ function blankOut(chars, from, to) {
16
+ for (let i = from; i < to; i += 1) {
17
+ if (chars[i] !== "\n" && chars[i] !== "\r")
18
+ chars[i] = " ";
19
+ }
20
+ }
21
+ function stripCommentsPreservingLayout(source, options = {}) {
22
+ const chars = source.split("");
23
+ const length = chars.length;
24
+ let i = 0;
25
+ while (i < length) {
26
+ const ch = chars[i];
27
+ const next = i + 1 < length ? chars[i + 1] : "";
28
+ // Line comment.
29
+ if (ch === "/" && next === "/") {
30
+ let end = i;
31
+ while (end < length && chars[end] !== "\n")
32
+ end += 1;
33
+ blankOut(chars, i, end);
34
+ i = end;
35
+ continue;
36
+ }
37
+ // Block comment.
38
+ if (ch === "/" && next === "*") {
39
+ let end = i + 2;
40
+ if (options.nestedBlockComments) {
41
+ let depth = 1;
42
+ while (end < length && depth > 0) {
43
+ if (chars[end] === "/" && chars[end + 1] === "*") {
44
+ depth += 1;
45
+ end += 2;
46
+ continue;
47
+ }
48
+ if (chars[end] === "*" && chars[end + 1] === "/") {
49
+ depth -= 1;
50
+ end += 2;
51
+ continue;
52
+ }
53
+ end += 1;
54
+ }
55
+ }
56
+ else {
57
+ while (end < length && !(chars[end] === "*" && chars[end + 1] === "/")) {
58
+ end += 1;
59
+ }
60
+ end += 2;
61
+ }
62
+ end = Math.min(end, length);
63
+ blankOut(chars, i, end);
64
+ i = end;
65
+ continue;
66
+ }
67
+ // Java text block / Kotlin raw string: """...""" (may span lines).
68
+ if (options.tripleQuotedStrings &&
69
+ ch === '"' &&
70
+ next === '"' &&
71
+ chars[i + 2] === '"') {
72
+ const close = source.indexOf('"""', i + 3);
73
+ i = close === -1 ? length : close + 3;
74
+ continue;
75
+ }
76
+ // C++ raw string: R"delim( ... )delim"
77
+ if (options.rawStrings && ch === "R" && next === '"') {
78
+ let cursor = i + 2;
79
+ let delimiter = "";
80
+ while (cursor < length && chars[cursor] !== "(" && delimiter.length < 16) {
81
+ delimiter += chars[cursor];
82
+ cursor += 1;
83
+ }
84
+ if (chars[cursor] === "(") {
85
+ const terminator = `)${delimiter}"`;
86
+ const rest = source.indexOf(terminator, cursor + 1);
87
+ i = rest === -1 ? length : rest + terminator.length;
88
+ continue;
89
+ }
90
+ }
91
+ // C# verbatim string: @"..." (doubled quotes escape).
92
+ if (options.verbatimStrings && ch === "@" && next === '"') {
93
+ let cursor = i + 2;
94
+ while (cursor < length) {
95
+ if (chars[cursor] === '"') {
96
+ if (chars[cursor + 1] === '"') {
97
+ cursor += 2;
98
+ continue;
99
+ }
100
+ cursor += 1;
101
+ break;
102
+ }
103
+ cursor += 1;
104
+ }
105
+ i = cursor;
106
+ continue;
107
+ }
108
+ // Python triple-quoted string.
109
+ if (options.tripleQuoteStrings &&
110
+ (ch === '"' || ch === "'") &&
111
+ next === ch &&
112
+ i + 2 < length &&
113
+ chars[i + 2] === ch) {
114
+ const quote = ch;
115
+ let cursor = i + 3;
116
+ while (cursor < length) {
117
+ if (chars[cursor] === quote &&
118
+ chars[cursor + 1] === quote &&
119
+ chars[cursor + 2] === quote) {
120
+ cursor += 3;
121
+ break;
122
+ }
123
+ cursor += 1;
124
+ }
125
+ i = cursor;
126
+ continue;
127
+ }
128
+ // Python / shell line comment.
129
+ if (options.hashComments && ch === "#") {
130
+ let end = i;
131
+ while (end < length && chars[end] !== "\n")
132
+ end += 1;
133
+ blankOut(chars, i, end);
134
+ i = end;
135
+ continue;
136
+ }
137
+ // Go raw string: `...` (no escapes, may span lines).
138
+ if (options.backtickStrings && ch === "`") {
139
+ const close = source.indexOf("`", i + 1);
140
+ i = close === -1 ? length : close + 1;
141
+ continue;
142
+ }
143
+ // Regular string / char literal (backslash escapes).
144
+ if (ch === '"' || ch === "'") {
145
+ const quote = ch;
146
+ let cursor = i + 1;
147
+ while (cursor < length) {
148
+ if (chars[cursor] === "\\") {
149
+ cursor += 2;
150
+ continue;
151
+ }
152
+ if (chars[cursor] === quote) {
153
+ cursor += 1;
154
+ break;
155
+ }
156
+ // An unterminated literal should not swallow the rest of the file.
157
+ if (chars[cursor] === "\n")
158
+ break;
159
+ cursor += 1;
160
+ }
161
+ i = cursor;
162
+ continue;
163
+ }
164
+ i += 1;
165
+ }
166
+ return chars.join("");
167
+ }
@@ -11,7 +11,7 @@ function detectPatterns(file) {
11
11
  return [];
12
12
  }
13
13
  const findings = [];
14
- findings.push(...(0, typescript_detection_1.detectRoutePatterns)(file, model), ...(0, typescript_detection_1.detectDatabaseConnections)(file, model), ...(0, typescript_detection_1.detectExternalApiCalls)(file, model), ...(0, typescript_detection_1.detectAuthMiddleware)(file, model), ...(0, typescript_detection_1.detectConfigAndEnvUsage)(file, model), ...(0, actor_detection_1.detectActorsFromFile)(file, model));
14
+ findings.push(...(0, typescript_detection_1.detectRoutePatterns)(file, model), ...(0, typescript_detection_1.detectDatabaseConnections)(file, model), ...(0, typescript_detection_1.detectExternalApiCalls)(file, model), ...(0, typescript_detection_1.detectAuthMiddleware)(file, model), ...(0, typescript_detection_1.detectConfigAndEnvUsage)(file, model), ...(0, typescript_detection_1.detectServerlessHandlers)(file, model), ...(0, actor_detection_1.detectActorsFromFile)(file, model));
15
15
  // Merge pattern-matched component properties into each finding so classifier/enhancer get them
16
16
  for (const finding of findings) {
17
17
  const detected = (0, property_inference_1.getPropertiesFromFinding)(finding, file.content);
@@ -3,12 +3,19 @@ import { type PatternId } from "../../core/types/detection";
3
3
  export interface WithPatternId {
4
4
  patternId: PatternId;
5
5
  }
6
+ export interface RouteRegexConfig {
7
+ regex: RegExp;
8
+ methodGroup?: number;
9
+ pathGroup?: number;
10
+ defaultMethod?: string;
11
+ }
6
12
  export interface RouteFrameworkConfig extends WithPatternId {
7
13
  id: string;
8
14
  imports: string[];
9
15
  routeCallRegexes: RegExp[];
10
16
  controllerDecoratorRegexes: RegExp[];
11
17
  routeDecoratorRegexes: RegExp[];
18
+ routeRegexes: RouteRegexConfig[];
12
19
  confidence: number;
13
20
  }
14
21
  export interface DbClientConfig extends WithPatternId {
@@ -23,6 +30,29 @@ export interface AuthLibraryConfig extends WithPatternId {
23
30
  id: string;
24
31
  importFragments: string[];
25
32
  callRegexes: RegExp[];
33
+ contentRegexes: RegExp[];
34
+ strategy?: string;
35
+ confidence: number;
36
+ }
37
+ export interface ServerlessHandlerConfig extends WithPatternId {
38
+ id: string;
39
+ importModules: string[];
40
+ handlerRegexes: RegExp[];
41
+ typeNames: string[];
42
+ confidence: number;
43
+ }
44
+ export interface ExternalApiClientConfig extends WithPatternId {
45
+ id: string;
46
+ clientName: string;
47
+ importFragments: string[];
48
+ callRegexes: RegExp[];
49
+ confidence: number;
50
+ }
51
+ export interface ConfigLoaderConfig extends WithPatternId {
52
+ id: string;
53
+ importFragments: string[];
54
+ callRegexes: RegExp[];
55
+ name: string;
26
56
  confidence: number;
27
57
  }
28
58
  export interface ConfigKeyConfig extends WithPatternId {
@@ -55,6 +85,13 @@ export interface TypeScriptPatternConfig {
55
85
  auth: {
56
86
  libraries: AuthLibraryConfig[];
57
87
  };
88
+ serverless: {
89
+ handlers: ServerlessHandlerConfig[];
90
+ };
91
+ externalApis: {
92
+ httpClients: ExternalApiClientConfig[];
93
+ };
94
+ configLoaders: ConfigLoaderConfig[];
58
95
  heuristics: HeuristicsConfig;
59
96
  envVariables: {
60
97
  importantKeys: string[];
@@ -43,6 +43,12 @@ function normalizeRawConfig(raw) {
43
43
  routeCallRegexes: compileRegexList(fw.routeCallRegexes),
44
44
  controllerDecoratorRegexes: compileRegexList(fw.controllerDecoratorRegexes),
45
45
  routeDecoratorRegexes: compileRegexList(fw.routeDecoratorRegexes),
46
+ routeRegexes: fw.routeRegexes?.map((entry) => ({
47
+ regex: compileRegex(entry.regex),
48
+ methodGroup: entry.methodGroup,
49
+ pathGroup: entry.pathGroup,
50
+ defaultMethod: entry.defaultMethod,
51
+ })) ?? [],
46
52
  confidence: fw.confidence ?? DEFAULT_CONFIDENCE,
47
53
  };
48
54
  }) ?? [];
@@ -64,9 +70,44 @@ function normalizeRawConfig(raw) {
64
70
  patternId,
65
71
  importFragments: lib.importFragments ?? [],
66
72
  callRegexes: compileRegexList(lib.regexes),
73
+ contentRegexes: compileRegexList(lib.contentRegexes),
74
+ strategy: lib.strategy,
67
75
  confidence: lib.confidence ?? DEFAULT_CONFIDENCE,
68
76
  };
69
77
  }) ?? [];
78
+ const serverlessHandlers = raw.serverless?.handlers?.map((handler) => {
79
+ const patternId = validatePatternId(handler.patternId, `serverless.handlers entry '${handler.id}'`);
80
+ return {
81
+ id: handler.id,
82
+ patternId,
83
+ importModules: handler.importModules ?? [],
84
+ handlerRegexes: compileRegexList(handler.handlerRegexes),
85
+ typeNames: handler.typeNames ?? [],
86
+ confidence: handler.confidence ?? DEFAULT_CONFIDENCE,
87
+ };
88
+ }) ?? [];
89
+ const externalHttpClients = raw.external_apis?.httpClients?.map((client) => {
90
+ const patternId = validatePatternId(client.patternId, `external_apis.httpClients entry '${client.id}'`);
91
+ return {
92
+ id: client.id,
93
+ patternId,
94
+ clientName: client.clientName,
95
+ importFragments: client.importFragments ?? [],
96
+ callRegexes: compileRegexList(client.regexes),
97
+ confidence: client.confidence ?? DEFAULT_CONFIDENCE,
98
+ };
99
+ }) ?? [];
100
+ const configLoaders = raw.config_loaders?.map((loader) => {
101
+ const patternId = validatePatternId(loader.patternId, `config_loaders entry '${loader.id}'`);
102
+ return {
103
+ id: loader.id,
104
+ patternId,
105
+ importFragments: loader.importFragments ?? [],
106
+ callRegexes: compileRegexList(loader.regexes),
107
+ name: loader.name ?? loader.id,
108
+ confidence: loader.confidence ?? DEFAULT_CONFIDENCE,
109
+ };
110
+ }) ?? [];
70
111
  const configKeys = raw.config_keys?.keys?.map((k) => {
71
112
  const patternId = validatePatternId(k.patternId, `config_keys.keys entry '${k.name}'`);
72
113
  return {
@@ -111,6 +152,13 @@ function normalizeRawConfig(raw) {
111
152
  auth: {
112
153
  libraries: authLibraries,
113
154
  },
155
+ serverless: {
156
+ handlers: serverlessHandlers,
157
+ },
158
+ externalApis: {
159
+ httpClients: externalHttpClients,
160
+ },
161
+ configLoaders,
114
162
  heuristics,
115
163
  envVariables: {
116
164
  importantKeys,
@@ -7,4 +7,5 @@ export declare const detectDatabaseConnections: TsPatternDetector;
7
7
  export declare const detectExternalApiCalls: TsPatternDetector;
8
8
  export declare const detectAuthMiddleware: TsPatternDetector;
9
9
  export declare const detectConfigAndEnvUsage: TsPatternDetector;
10
+ export declare const detectServerlessHandlers: TsPatternDetector;
10
11
  export {};
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectConfigAndEnvUsage = exports.detectAuthMiddleware = exports.detectExternalApiCalls = exports.detectDatabaseConnections = exports.detectRoutePatterns = void 0;
4
- const third_party_detection_1 = require("./third-party-detection");
3
+ exports.detectServerlessHandlers = exports.detectConfigAndEnvUsage = exports.detectAuthMiddleware = exports.detectExternalApiCalls = exports.detectDatabaseConnections = exports.detectRoutePatterns = void 0;
4
+ const strip_comments_1 = require("../shared/strip-comments");
5
5
  const engine_1 = require("../../patterns/engine");
6
6
  function toImportLikes(model) {
7
7
  return model.imports.map((imp) => ({
@@ -9,49 +9,47 @@ function toImportLikes(model) {
9
9
  names: imp.importedNames,
10
10
  }));
11
11
  }
12
- const detectRoutePatterns = (file, model) => {
13
- const importsForEngine = toImportLikes(model);
14
- const allFindings = (0, engine_1.matchPatterns)({
12
+ function buildPatternContext(file, model) {
13
+ return {
15
14
  language: model.language,
16
15
  file,
17
- imports: importsForEngine,
16
+ imports: toImportLikes(model),
18
17
  normalizedPath: model.normalizedPath,
19
- });
18
+ strippedContent: (0, strip_comments_1.stripCommentsPreservingLayout)(file.content ?? "", {
19
+ backtickStrings: true,
20
+ }),
21
+ };
22
+ }
23
+ const detectRoutePatterns = (file, model) => {
24
+ const allFindings = (0, engine_1.matchPatterns)(buildPatternContext(file, model));
20
25
  return allFindings.filter((f) => f.pattern === "express_route");
21
26
  };
22
27
  exports.detectRoutePatterns = detectRoutePatterns;
23
28
  const detectDatabaseConnections = (file, model) => {
24
- const importsForEngine = toImportLikes(model);
25
- const allFindings = (0, engine_1.matchPatterns)({
26
- language: model.language,
27
- file,
28
- imports: importsForEngine,
29
- normalizedPath: model.normalizedPath,
30
- });
29
+ const allFindings = (0, engine_1.matchPatterns)(buildPatternContext(file, model));
31
30
  return allFindings.filter((f) => f.pattern === "database_connection");
32
31
  };
33
32
  exports.detectDatabaseConnections = detectDatabaseConnections;
34
- const detectExternalApiCalls = (file, model) => (0, third_party_detection_1.detectExternalApiCalls)(file, model);
35
- exports.detectExternalApiCalls = detectExternalApiCalls;
36
- const detectAuthMiddleware = (file, model) => {
37
- const importsForEngine = toImportLikes(model);
33
+ const detectExternalApiCalls = (file, model) => {
38
34
  const allFindings = (0, engine_1.matchPatterns)({
39
- language: model.language,
40
- file,
41
- imports: importsForEngine,
42
- normalizedPath: model.normalizedPath,
35
+ ...buildPatternContext(file, model),
36
+ includeThirdPartyHttpLinePatterns: true,
43
37
  });
38
+ return allFindings.filter((f) => f.pattern === "external_api_call");
39
+ };
40
+ exports.detectExternalApiCalls = detectExternalApiCalls;
41
+ const detectAuthMiddleware = (file, model) => {
42
+ const allFindings = (0, engine_1.matchPatterns)(buildPatternContext(file, model));
44
43
  return allFindings.filter((f) => f.pattern === "auth_middleware");
45
44
  };
46
45
  exports.detectAuthMiddleware = detectAuthMiddleware;
47
46
  const detectConfigAndEnvUsage = (file, model) => {
48
- const importsForEngine = toImportLikes(model);
49
- const allFindings = (0, engine_1.matchPatterns)({
50
- language: model.language,
51
- file,
52
- imports: importsForEngine,
53
- normalizedPath: model.normalizedPath,
54
- });
47
+ const allFindings = (0, engine_1.matchPatterns)(buildPatternContext(file, model));
55
48
  return allFindings.filter((f) => f.pattern === "env_variable" || f.pattern === "config_file");
56
49
  };
57
50
  exports.detectConfigAndEnvUsage = detectConfigAndEnvUsage;
51
+ const detectServerlessHandlers = (file, model) => {
52
+ const allFindings = (0, engine_1.matchPatterns)(buildPatternContext(file, model));
53
+ return allFindings.filter((f) => f.pattern === "lambda_handler");
54
+ };
55
+ exports.detectServerlessHandlers = detectServerlessHandlers;