@dataparade/cli 0.0.9 → 0.0.11

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 (179) hide show
  1. package/README.md +1 -1
  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 +28 -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/src/platform-api/telemetry-client.d.ts +6 -0
  112. package/dist/src/platform-api/telemetry-client.js +65 -0
  113. package/dist/src/platform-api/telemetry.types.d.ts +13 -0
  114. package/dist/src/platform-api/telemetry.types.js +2 -0
  115. package/dist/src/platform-api/upload-client.d.ts +2 -0
  116. package/dist/src/platform-api/upload-client.js +4 -0
  117. package/dist/src/platform-api/upload.types.d.ts +2 -0
  118. package/dist/src/upload/build-preview-url.d.ts +2 -2
  119. package/dist/src/upload/build-preview-url.js +10 -3
  120. package/dist/src/upload/run-upload.js +62 -19
  121. package/dist/src/upload/types.d.ts +2 -0
  122. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.d.ts +1 -0
  123. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.js +11 -0
  124. package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +80 -0
  125. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.d.ts +1 -0
  126. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.js +66 -0
  127. package/dist/tests/unit/analyzers/cpp/parser.spec.d.ts +1 -0
  128. package/dist/tests/unit/analyzers/cpp/parser.spec.js +80 -0
  129. package/dist/tests/unit/analyzers/cpp/patterns.spec.d.ts +1 -0
  130. package/dist/tests/unit/analyzers/cpp/patterns.spec.js +141 -0
  131. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.d.ts +1 -0
  132. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.js +75 -0
  133. package/dist/tests/unit/analyzers/csharp/parser.spec.d.ts +1 -0
  134. package/dist/tests/unit/analyzers/csharp/parser.spec.js +118 -0
  135. package/dist/tests/unit/analyzers/csharp/patterns.spec.d.ts +1 -0
  136. package/dist/tests/unit/analyzers/csharp/patterns.spec.js +210 -0
  137. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.d.ts +1 -0
  138. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.js +96 -0
  139. package/dist/tests/unit/analyzers/go/parser.spec.d.ts +1 -0
  140. package/dist/tests/unit/analyzers/go/parser.spec.js +110 -0
  141. package/dist/tests/unit/analyzers/go/patterns.spec.d.ts +1 -0
  142. package/dist/tests/unit/analyzers/go/patterns.spec.js +239 -0
  143. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.d.ts +1 -0
  144. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.js +179 -0
  145. package/dist/tests/unit/analyzers/jvm/parser.spec.d.ts +1 -0
  146. package/dist/tests/unit/analyzers/jvm/parser.spec.js +195 -0
  147. package/dist/tests/unit/analyzers/jvm/patterns.spec.d.ts +1 -0
  148. package/dist/tests/unit/analyzers/jvm/patterns.spec.js +284 -0
  149. package/dist/tests/unit/analyzers/python/patterns.spec.js +169 -0
  150. package/dist/tests/unit/analyzers/typescript/detector.spec.js +188 -0
  151. package/dist/tests/unit/core/cpp-dotnet-scan.spec.d.ts +1 -0
  152. package/dist/tests/unit/core/cpp-dotnet-scan.spec.js +67 -0
  153. package/dist/tests/unit/core/cpp-dotnet-sections.spec.d.ts +1 -0
  154. package/dist/tests/unit/core/cpp-dotnet-sections.spec.js +46 -0
  155. package/dist/tests/unit/core/go-scan.spec.d.ts +1 -0
  156. package/dist/tests/unit/core/go-scan.spec.js +78 -0
  157. package/dist/tests/unit/core/graph-mapping.spec.js +75 -0
  158. package/dist/tests/unit/core/jvm-scan.spec.d.ts +1 -0
  159. package/dist/tests/unit/core/jvm-scan.spec.js +94 -0
  160. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.d.ts +1 -0
  161. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.js +56 -0
  162. package/dist/tests/unit/ingest/jvm-languages.spec.d.ts +1 -0
  163. package/dist/tests/unit/ingest/jvm-languages.spec.js +47 -0
  164. package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
  165. package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
  166. package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
  167. package/dist/tests/unit/upload/run-upload.spec.js +18 -0
  168. package/package.json +1 -1
  169. package/patterns/cpp.md +176 -0
  170. package/patterns/cpp.patterns.yaml +314 -0
  171. package/patterns/csharp.md +211 -0
  172. package/patterns/csharp.patterns.yaml +375 -0
  173. package/patterns/go.md +211 -0
  174. package/patterns/go.patterns.yaml +429 -0
  175. package/patterns/jvm.md +160 -0
  176. package/patterns/jvm.patterns.yaml +884 -0
  177. package/patterns/python.patterns.yaml +177 -0
  178. package/patterns/third-party.patterns.yaml +5 -0
  179. package/patterns/typescript.patterns.yaml +222 -0
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clearGoPatternConfigCache = clearGoPatternConfigCache;
7
+ exports.loadGoPatternConfig = loadGoPatternConfig;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const yaml_1 = __importDefault(require("yaml"));
11
+ const detection_1 = require("../../core/types/detection");
12
+ const DEFAULT_CONFIDENCE = 0.8;
13
+ const DEFAULT_URL_REGEX = '"(https?:\\/\\/[^\\s"]+)"';
14
+ function validatePatternId(raw, context) {
15
+ const id = String(raw);
16
+ if (!detection_1.PATTERN_IDS.includes(id)) {
17
+ throw new Error(`Invalid patternId '${raw}' in ${context}`);
18
+ }
19
+ return id;
20
+ }
21
+ function compileRegex(pattern, context) {
22
+ try {
23
+ return new RegExp(pattern);
24
+ }
25
+ catch (err) {
26
+ const msg = err instanceof Error ? err.message : String(err);
27
+ throw new Error(`Invalid regex in ${context}: ${msg}`);
28
+ }
29
+ }
30
+ function getConfigPath() {
31
+ const parts = __dirname.split(path_1.default.sep);
32
+ const distIndex = parts.lastIndexOf("dist");
33
+ const cliRoot = distIndex !== -1
34
+ ? parts.slice(0, distIndex).join(path_1.default.sep)
35
+ : path_1.default.resolve(__dirname, "../../..");
36
+ return path_1.default.join(cliRoot, "patterns", "go.patterns.yaml");
37
+ }
38
+ function normalizeImportPaths(values) {
39
+ return (values ?? []).map((v) => v.trim()).filter(Boolean);
40
+ }
41
+ function normalizeRouteRegexes(raw, context) {
42
+ return (raw ?? []).map((entry, index) => ({
43
+ regex: compileRegex(entry.regex, `${context}.routeRegexes[${index}]`),
44
+ methodGroup: entry.methodGroup,
45
+ pathGroup: entry.pathGroup,
46
+ defaultMethod: entry.defaultMethod,
47
+ }));
48
+ }
49
+ function normalizeRawConfig(raw) {
50
+ const dbClients = raw.db_clients?.map((c) => ({
51
+ id: c.id,
52
+ patternId: validatePatternId(c.patternId, `go.db_clients entry '${c.id}'`),
53
+ databaseType: c.databaseType,
54
+ importPaths: normalizeImportPaths(c.importPaths),
55
+ callNames: c.callNames ?? [],
56
+ confidence: c.confidence ?? DEFAULT_CONFIDENCE,
57
+ })) ?? [];
58
+ const sqlOpenRaw = raw.sql_open;
59
+ const sqlOpen = sqlOpenRaw && sqlOpenRaw.patternId && sqlOpenRaw.regex
60
+ ? {
61
+ patternId: validatePatternId(sqlOpenRaw.patternId, "go.sql_open.patternId"),
62
+ regex: compileRegex(sqlOpenRaw.regex, "go.sql_open.regex"),
63
+ name: sqlOpenRaw.name ?? "database_sql",
64
+ confidence: sqlOpenRaw.confidence ?? DEFAULT_CONFIDENCE,
65
+ drivers: sqlOpenRaw.drivers ?? {},
66
+ defaultDatabaseType: sqlOpenRaw.defaultDatabaseType ?? "sql",
67
+ }
68
+ : undefined;
69
+ const authLibraries = raw.auth?.libraries?.map((lib) => ({
70
+ id: lib.id,
71
+ patternId: validatePatternId(lib.patternId, `go.auth.libraries['${lib.id}']`),
72
+ importPaths: normalizeImportPaths(lib.importPaths),
73
+ callNames: lib.callNames ?? [],
74
+ contentRegexes: (lib.contentRegexes ?? []).map((p) => compileRegex(p, `go.auth.libraries['${lib.id}'].contentRegexes`)),
75
+ strategy: lib.strategy,
76
+ confidence: lib.confidence ?? DEFAULT_CONFIDENCE,
77
+ })) ?? [];
78
+ const routeFrameworks = raw.routes?.frameworks?.map((fw) => ({
79
+ id: fw.id,
80
+ patternId: validatePatternId(fw.patternId, `go.routes.frameworks['${fw.id}']`),
81
+ importPaths: normalizeImportPaths(fw.importPaths),
82
+ routeRegexes: normalizeRouteRegexes(fw.routeRegexes, `go.routes.frameworks['${fw.id}']`),
83
+ confidence: fw.confidence ?? DEFAULT_CONFIDENCE,
84
+ })) ?? [];
85
+ const serverlessHandlers = raw.serverless?.handlers?.map((handler) => ({
86
+ id: handler.id,
87
+ patternId: validatePatternId(handler.patternId, `go.serverless.handlers['${handler.id}']`),
88
+ importPaths: normalizeImportPaths(handler.importPaths),
89
+ callNames: handler.callNames ?? [],
90
+ confidence: handler.confidence ?? DEFAULT_CONFIDENCE,
91
+ })) ?? [];
92
+ const envVarRaw = raw.env_config?.envVariable;
93
+ const envVariable = envVarRaw && envVarRaw.patternId && envVarRaw.regex
94
+ ? {
95
+ patternId: validatePatternId(envVarRaw.patternId, "go.env_config.envVariable.patternId"),
96
+ regex: compileRegex(envVarRaw.regex, "go.env_config.envVariable.regex"),
97
+ confidence: envVarRaw.confidence ?? DEFAULT_CONFIDENCE,
98
+ }
99
+ : undefined;
100
+ const configLoadersRaw = raw.env_config?.configLoaders;
101
+ const configLoaders = configLoadersRaw && configLoadersRaw.patternId
102
+ ? {
103
+ patternId: validatePatternId(configLoadersRaw.patternId, "go.env_config.configLoaders.patternId"),
104
+ confidence: configLoadersRaw.confidence ?? DEFAULT_CONFIDENCE,
105
+ loaders: (configLoadersRaw.loaders ?? []).map((loader) => ({
106
+ id: loader.id,
107
+ importPaths: normalizeImportPaths(loader.importPaths),
108
+ callNames: loader.callNames ?? [],
109
+ })),
110
+ }
111
+ : undefined;
112
+ const configFileRaw = raw.env_config?.configFile;
113
+ const configFile = configFileRaw && configFileRaw.patternId && configFileRaw.fileNameRegex
114
+ ? {
115
+ patternId: validatePatternId(configFileRaw.patternId, "go.env_config.configFile.patternId"),
116
+ fileNameRegex: compileRegex(configFileRaw.fileNameRegex, "go.env_config.configFile.fileNameRegex"),
117
+ name: configFileRaw.name ?? "go_config",
118
+ confidence: configFileRaw.confidence ?? DEFAULT_CONFIDENCE,
119
+ }
120
+ : undefined;
121
+ const httpClients = raw.external_apis?.httpClients?.map((client) => ({
122
+ id: client.id,
123
+ patternId: validatePatternId(client.patternId, `go.external_apis.httpClients['${client.id}']`),
124
+ clientName: client.clientName,
125
+ importPaths: normalizeImportPaths(client.importPaths),
126
+ callNames: client.callNames ?? [],
127
+ callNameSuffixes: client.callNameSuffixes ?? [],
128
+ urlRegex: compileRegex(client.urlRegex ?? DEFAULT_URL_REGEX, `go.external_apis.httpClients['${client.id}'].urlRegex`),
129
+ confidence: client.confidence ?? DEFAULT_CONFIDENCE,
130
+ })) ?? [];
131
+ return {
132
+ dbClients,
133
+ sqlOpen,
134
+ auth: { libraries: authLibraries },
135
+ routes: { frameworks: routeFrameworks },
136
+ serverless: { handlers: serverlessHandlers },
137
+ envConfig: { envVariable, configLoaders, configFile },
138
+ externalApis: { httpClients },
139
+ };
140
+ }
141
+ let cachedConfig;
142
+ function clearGoPatternConfigCache() {
143
+ cachedConfig = undefined;
144
+ }
145
+ function loadGoPatternConfig() {
146
+ if (cachedConfig)
147
+ return cachedConfig;
148
+ const configPath = getConfigPath();
149
+ let rawYaml;
150
+ try {
151
+ rawYaml = fs_1.default.readFileSync(configPath, "utf8");
152
+ }
153
+ catch (err) {
154
+ const msg = err instanceof Error ? err.message : String(err);
155
+ throw new Error(`Go pattern config is required but could not be read from '${configPath}': ${msg}`);
156
+ }
157
+ const parsed = yaml_1.default.parse(rawYaml);
158
+ if (!parsed || typeof parsed !== "object") {
159
+ throw new Error(`Go pattern config at '${configPath}' did not parse to an object.`);
160
+ }
161
+ const normalized = normalizeRawConfig(parsed);
162
+ cachedConfig = normalized;
163
+ return normalized;
164
+ }
@@ -0,0 +1,2 @@
1
+ import type { Analyzer } from "../types";
2
+ export declare function createGoAnalyzer(): Analyzer;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createGoAnalyzer = createGoAnalyzer;
4
+ const detector_1 = require("./detector");
5
+ function createGoAnalyzer() {
6
+ return {
7
+ detect(file) {
8
+ return (0, detector_1.detectGoPatterns)(file);
9
+ },
10
+ };
11
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Dependency extraction for Go module manifests.
3
+ *
4
+ * `go.mod` is the single source of truth for a Go module's dependencies, and
5
+ * unlike most ecosystems its dependency tokens are already the same strings
6
+ * that appear in `import` statements — so they feed the shared third-party
7
+ * catalog directly.
8
+ */
9
+ export interface GoModuleManifest {
10
+ /** The `module` declaration, e.g. `github.com/acme/billing`. */
11
+ modulePath?: string;
12
+ /** Required module paths, versions stripped. */
13
+ requires: string[];
14
+ }
15
+ export declare function parseGoMod(content: string): GoModuleManifest;
16
+ /**
17
+ * `go.work` — Go workspaces list member module directories, which is how a
18
+ * multi-module Go repository declares its services.
19
+ */
20
+ export declare function parseGoWork(content: string): string[];
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Dependency extraction for Go module manifests.
4
+ *
5
+ * `go.mod` is the single source of truth for a Go module's dependencies, and
6
+ * unlike most ecosystems its dependency tokens are already the same strings
7
+ * that appear in `import` statements — so they feed the shared third-party
8
+ * catalog directly.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.parseGoMod = parseGoMod;
12
+ exports.parseGoWork = parseGoWork;
13
+ const MODULE_REGEX = /^module\s+(\S+)/;
14
+ const REQUIRE_BLOCK_START_REGEX = /^require\s*\(/;
15
+ const REQUIRE_SINGLE_REGEX = /^require\s+(\S+)\s+\S+/;
16
+ const REPLACE_BLOCK_START_REGEX = /^(?:replace|exclude|retract)\s*\(/;
17
+ const REQUIRE_ENTRY_REGEX = /^(\S+)\s+v\S+/;
18
+ function stripLineComment(line) {
19
+ const index = line.indexOf("//");
20
+ return index === -1 ? line : line.slice(0, index);
21
+ }
22
+ function isValidModulePath(token) {
23
+ if (!token || token.startsWith("//"))
24
+ return false;
25
+ // Module paths are domain-like or std-lib-like; reject stray syntax.
26
+ return /^[A-Za-z0-9][A-Za-z0-9._~/-]*$/.test(token);
27
+ }
28
+ function parseGoMod(content) {
29
+ const requires = new Set();
30
+ let modulePath;
31
+ let inRequireBlock = false;
32
+ let inIgnoredBlock = false;
33
+ for (const rawLine of content.split(/\r?\n/)) {
34
+ const line = stripLineComment(rawLine).trim();
35
+ if (!line)
36
+ continue;
37
+ if (inIgnoredBlock) {
38
+ if (line.startsWith(")"))
39
+ inIgnoredBlock = false;
40
+ continue;
41
+ }
42
+ if (inRequireBlock) {
43
+ if (line.startsWith(")")) {
44
+ inRequireBlock = false;
45
+ continue;
46
+ }
47
+ const entry = line.match(REQUIRE_ENTRY_REGEX);
48
+ if (entry && isValidModulePath(entry[1]))
49
+ requires.add(entry[1]);
50
+ continue;
51
+ }
52
+ if (!modulePath) {
53
+ const moduleMatch = line.match(MODULE_REGEX);
54
+ if (moduleMatch && isValidModulePath(moduleMatch[1])) {
55
+ modulePath = moduleMatch[1];
56
+ continue;
57
+ }
58
+ }
59
+ if (REQUIRE_BLOCK_START_REGEX.test(line)) {
60
+ inRequireBlock = true;
61
+ continue;
62
+ }
63
+ // `replace`/`exclude`/`retract` blocks are skipped: they redirect or
64
+ // remove dependencies rather than declare them.
65
+ if (REPLACE_BLOCK_START_REGEX.test(line)) {
66
+ inIgnoredBlock = true;
67
+ continue;
68
+ }
69
+ const single = line.match(REQUIRE_SINGLE_REGEX);
70
+ if (single && isValidModulePath(single[1])) {
71
+ requires.add(single[1]);
72
+ }
73
+ }
74
+ return { modulePath, requires: Array.from(requires) };
75
+ }
76
+ /**
77
+ * `go.work` — Go workspaces list member module directories, which is how a
78
+ * multi-module Go repository declares its services.
79
+ */
80
+ function parseGoWork(content) {
81
+ const members = new Set();
82
+ let inUseBlock = false;
83
+ for (const rawLine of content.split(/\r?\n/)) {
84
+ const line = stripLineComment(rawLine).trim();
85
+ if (!line)
86
+ continue;
87
+ if (inUseBlock) {
88
+ if (line.startsWith(")")) {
89
+ inUseBlock = false;
90
+ continue;
91
+ }
92
+ members.add(line.replace(/^\.\//, ""));
93
+ continue;
94
+ }
95
+ if (/^use\s*\(/.test(line)) {
96
+ inUseBlock = true;
97
+ continue;
98
+ }
99
+ const single = line.match(/^use\s+(\S+)/);
100
+ if (single)
101
+ members.add(single[1].replace(/^\.\//, ""));
102
+ }
103
+ return Array.from(members);
104
+ }
@@ -0,0 +1,40 @@
1
+ import type { FileInfo, SourceLocation } from "../../core/types/file";
2
+ import { type CFamilyCallEntry } from "../shared/c-family-calls";
3
+ export interface GoImportEntry {
4
+ /** Import path as written, e.g. `net/http` or `github.com/lib/pq`. */
5
+ path: string;
6
+ /** Alias for `m "github.com/gorilla/mux"`. */
7
+ alias?: string;
8
+ /**
9
+ * True for `_ "github.com/lib/pq"`. Blank imports exist purely for their
10
+ * side effects — in Go this is how database drivers register themselves,
11
+ * so they are the strongest available signal for driver detection.
12
+ */
13
+ isBlank: boolean;
14
+ location: SourceLocation;
15
+ }
16
+ export interface GoFunctionEntry {
17
+ name: string;
18
+ /** Receiver type for methods: `func (s *Server) Handle()` → `Server`. */
19
+ receiverType?: string;
20
+ location: SourceLocation;
21
+ }
22
+ export interface GoTypeEntry {
23
+ name: string;
24
+ kind: "struct" | "interface";
25
+ location: SourceLocation;
26
+ }
27
+ export type GoCallEntry = CFamilyCallEntry;
28
+ export interface GoSourceFileModel {
29
+ file: FileInfo;
30
+ normalizedPath: string;
31
+ /** Source with comments blanked out; line/column offsets are preserved. */
32
+ strippedContent: string;
33
+ packageName?: string;
34
+ imports: GoImportEntry[];
35
+ functions: GoFunctionEntry[];
36
+ types: GoTypeEntry[];
37
+ calls: GoCallEntry[];
38
+ warnings: string[];
39
+ }
40
+ export declare function parseGoSourceFile(file: FileInfo): GoSourceFileModel;
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseGoSourceFile = parseGoSourceFile;
37
+ const nodePath = __importStar(require("path"));
38
+ const c_family_calls_1 = require("../shared/c-family-calls");
39
+ const strip_comments_1 = require("../shared/strip-comments");
40
+ const PACKAGE_REGEX = /^package\s+([A-Za-z_]\w*)/;
41
+ const SINGLE_IMPORT_REGEX = /^import\s+(?:(_|\.|[A-Za-z_]\w*)\s+)?"([^"]+)"/;
42
+ const IMPORT_BLOCK_START_REGEX = /^import\s*\(/;
43
+ const IMPORT_BLOCK_ENTRY_REGEX = /^(?:(_|\.|[A-Za-z_]\w*)\s+)?"([^"]+)"/;
44
+ const FUNCTION_REGEX = /^func\s+(?:\(\s*(?:[A-Za-z_]\w*\s+)?\*?([A-Za-z_][\w.]*)\s*\)\s*)?([A-Za-z_]\w*)\s*(?:\[[^\]]*\])?\s*\(/;
45
+ const TYPE_REGEX = /^type\s+([A-Za-z_]\w*)(?:\[[^\]]*\])?\s+(struct|interface)\b/;
46
+ function normalizePath(p) {
47
+ if (!p)
48
+ return "";
49
+ const normalized = p.split("\\").join("/");
50
+ return normalizedPathIsRelativeToCwd(normalized)
51
+ ? normalized
52
+ : normalized.replace(nodePath.resolve(), "").replace(/^\/+/, "");
53
+ }
54
+ function normalizedPathIsRelativeToCwd(p) {
55
+ return !p.startsWith("/") && !p.match(/^[A-Za-z]:\//);
56
+ }
57
+ function emptyModel(file, normalizedPath, warnings) {
58
+ return {
59
+ file,
60
+ normalizedPath,
61
+ strippedContent: "",
62
+ imports: [],
63
+ functions: [],
64
+ types: [],
65
+ calls: [],
66
+ warnings,
67
+ };
68
+ }
69
+ function parseGoSourceFile(file) {
70
+ const warnings = [];
71
+ const normalizedPath = normalizePath(file.path);
72
+ if (file.language !== "go") {
73
+ warnings.push(`Unsupported language '${file.language}' for Go parser in file '${file.path}'.`);
74
+ return emptyModel(file, normalizedPath, warnings);
75
+ }
76
+ const content = file.content ?? "";
77
+ if (content.includes("\u0000")) {
78
+ warnings.push(`File '${file.path}' appears unreadable (contains null bytes); parser will continue with best-effort analysis.`);
79
+ }
80
+ const strippedContent = (0, strip_comments_1.stripCommentsPreservingLayout)(content, {
81
+ backtickStrings: true,
82
+ });
83
+ const lines = strippedContent.split(/\r?\n/);
84
+ const imports = [];
85
+ const functions = [];
86
+ const types = [];
87
+ let packageName;
88
+ let inImportBlock = false;
89
+ const toLocation = (startLine, endLine) => ({
90
+ filePath: file.path,
91
+ startLine,
92
+ endLine,
93
+ });
94
+ const pushImport = (prefix, importPath, lineNumber) => {
95
+ imports.push({
96
+ path: importPath,
97
+ alias: prefix && prefix !== "_" && prefix !== "." ? prefix : undefined,
98
+ isBlank: prefix === "_",
99
+ location: toLocation(lineNumber, lineNumber),
100
+ });
101
+ };
102
+ for (let i = 0; i < lines.length; i += 1) {
103
+ const text = (lines[i] ?? "").trim();
104
+ const lineNumber = i + 1;
105
+ if (!text)
106
+ continue;
107
+ if (inImportBlock) {
108
+ if (text.startsWith(")")) {
109
+ inImportBlock = false;
110
+ continue;
111
+ }
112
+ const entry = text.match(IMPORT_BLOCK_ENTRY_REGEX);
113
+ if (entry)
114
+ pushImport(entry[1], entry[2], lineNumber);
115
+ continue;
116
+ }
117
+ if (!packageName) {
118
+ const packageMatch = text.match(PACKAGE_REGEX);
119
+ if (packageMatch) {
120
+ packageName = packageMatch[1];
121
+ continue;
122
+ }
123
+ }
124
+ if (IMPORT_BLOCK_START_REGEX.test(text)) {
125
+ inImportBlock = true;
126
+ continue;
127
+ }
128
+ const singleImport = text.match(SINGLE_IMPORT_REGEX);
129
+ if (singleImport) {
130
+ pushImport(singleImport[1], singleImport[2], lineNumber);
131
+ continue;
132
+ }
133
+ const typeMatch = text.match(TYPE_REGEX);
134
+ if (typeMatch) {
135
+ types.push({
136
+ name: typeMatch[1],
137
+ kind: typeMatch[2] === "interface" ? "interface" : "struct",
138
+ location: toLocation(lineNumber, lineNumber),
139
+ });
140
+ continue;
141
+ }
142
+ const functionMatch = text.match(FUNCTION_REGEX);
143
+ if (functionMatch) {
144
+ functions.push({
145
+ name: functionMatch[2],
146
+ receiverType: functionMatch[1],
147
+ location: toLocation(lineNumber, findFunctionEndLine(lines, i)),
148
+ });
149
+ }
150
+ }
151
+ const calls = (0, c_family_calls_1.extractCFamilyCalls)(lines, { filePath: file.path });
152
+ return {
153
+ file,
154
+ normalizedPath,
155
+ strippedContent,
156
+ packageName,
157
+ imports,
158
+ functions,
159
+ types,
160
+ calls,
161
+ warnings,
162
+ };
163
+ }
164
+ /**
165
+ * Walk braces forward from a function declaration to find its closing line.
166
+ * Go always brace-delimits function bodies, so this is reliable.
167
+ */
168
+ function findFunctionEndLine(lines, startIndex) {
169
+ let depth = 0;
170
+ let seenOpening = false;
171
+ for (let i = startIndex; i < lines.length; i += 1) {
172
+ const line = lines[i] ?? "";
173
+ for (const char of line) {
174
+ if (char === "{") {
175
+ depth += 1;
176
+ seenOpening = true;
177
+ }
178
+ else if (char === "}") {
179
+ depth -= 1;
180
+ }
181
+ }
182
+ if (seenOpening && depth <= 0)
183
+ return i + 1;
184
+ }
185
+ return startIndex + 1;
186
+ }
@@ -0,0 +1,3 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import type { GoSourceFileModel } from "./parser";
3
+ export declare function detectGoPatternsFromModel(model: GoSourceFileModel): RawFinding[];
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectGoPatternsFromModel = detectGoPatternsFromModel;
4
+ const engine_1 = require("../../patterns/engine");
5
+ /**
6
+ * Represent a Go import as a language-agnostic import.
7
+ *
8
+ * Go import paths are already lowercase URLs (`github.com/getsentry/sentry-go`),
9
+ * which is exactly the shape the shared third-party catalog matches its
10
+ * lowercase fragments against — no case juggling needed. The trailing path
11
+ * segments are carried as names so `sentry-go` and `sentry` both resolve.
12
+ */
13
+ function importsForEngine(model) {
14
+ return model.imports.map((entry) => {
15
+ const importPath = entry.path;
16
+ const segments = importPath.split("/").filter(Boolean);
17
+ const names = Array.from(new Set([
18
+ importPath,
19
+ ...segments,
20
+ ...(entry.alias ? [entry.alias] : []),
21
+ ])).filter(Boolean);
22
+ return { module: importPath, names };
23
+ });
24
+ }
25
+ function detectGoPatternsFromModel(model) {
26
+ return (0, engine_1.matchPatterns)({
27
+ language: "go",
28
+ file: model.file,
29
+ normalizedPath: model.normalizedPath,
30
+ strippedContent: model.strippedContent,
31
+ imports: importsForEngine(model),
32
+ functions: model.functions.map((fn) => ({
33
+ name: fn.name,
34
+ decorators: [],
35
+ location: fn.location,
36
+ })),
37
+ types: model.types.map((type) => ({
38
+ name: type.name,
39
+ kind: type.kind,
40
+ baseTypes: [],
41
+ decorators: [],
42
+ location: type.location,
43
+ })),
44
+ moduleLevelCalls: model.calls.map((call) => ({
45
+ callee: call.callee,
46
+ argumentsSnippet: call.argumentsSnippet,
47
+ location: call.location,
48
+ })),
49
+ });
50
+ }
@@ -0,0 +1,16 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import { type ManifestScanBudgetOptions } from "../shared/manifest-budgets";
3
+ export interface JvmManifestPackages {
4
+ manifestRelativePath: string;
5
+ /** Maven coordinates (`groupId:artifactId`), versions dropped. */
6
+ packages: string[];
7
+ }
8
+ export declare function isJvmBuildManifestName(name: string): boolean;
9
+ export declare function isSpringConfigName(name: string): boolean;
10
+ export declare function parseJvmDependencyManifests(rootPath: string, opts?: ManifestScanBudgetOptions): Promise<JvmManifestPackages[]>;
11
+ /**
12
+ * Third-party and dependency detection from JVM build manifests, plus the
13
+ * datasource URIs declared in `application.properties` / `application.yml` —
14
+ * usually the only place a Spring service names the databases it talks to.
15
+ */
16
+ export declare function detectJvmPatternsFromDependencyManifests(rootPath: string, opts?: ManifestScanBudgetOptions): Promise<RawFinding[]>;