@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.
- package/README.md +1 -1
- package/dist/package.json +1 -1
- package/dist/src/ai-enrichment/lambda-init-error.d.ts +5 -0
- package/dist/src/ai-enrichment/lambda-init-error.js +38 -0
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +5 -0
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +27 -1
- package/dist/src/analyzers/cpp/cpp-detection-config.d.ts +73 -0
- package/dist/src/analyzers/cpp/cpp-detection-config.js +137 -0
- package/dist/src/analyzers/cpp/dependency-manifests.d.ts +8 -0
- package/dist/src/analyzers/cpp/dependency-manifests.js +130 -0
- package/dist/src/analyzers/cpp/detector.d.ts +3 -0
- package/dist/src/analyzers/cpp/detector.js +21 -0
- package/dist/src/analyzers/cpp/index.d.ts +2 -0
- package/dist/src/analyzers/cpp/index.js +11 -0
- package/dist/src/analyzers/cpp/manifest-parsers.d.ts +13 -0
- package/dist/src/analyzers/cpp/manifest-parsers.js +104 -0
- package/dist/src/analyzers/cpp/parser.d.ts +35 -0
- package/dist/src/analyzers/cpp/parser.js +206 -0
- package/dist/src/analyzers/cpp/patterns.d.ts +3 -0
- package/dist/src/analyzers/cpp/patterns.js +37 -0
- package/dist/src/analyzers/csharp/csharp-detection-config.d.ts +100 -0
- package/dist/src/analyzers/csharp/csharp-detection-config.js +160 -0
- package/dist/src/analyzers/csharp/dependency-manifests.d.ts +13 -0
- package/dist/src/analyzers/csharp/dependency-manifests.js +184 -0
- package/dist/src/analyzers/csharp/detector.d.ts +3 -0
- package/dist/src/analyzers/csharp/detector.js +21 -0
- package/dist/src/analyzers/csharp/index.d.ts +2 -0
- package/dist/src/analyzers/csharp/index.js +11 -0
- package/dist/src/analyzers/csharp/manifest-parsers.d.ts +34 -0
- package/dist/src/analyzers/csharp/manifest-parsers.js +130 -0
- package/dist/src/analyzers/csharp/parser.d.ts +48 -0
- package/dist/src/analyzers/csharp/parser.js +277 -0
- package/dist/src/analyzers/csharp/patterns.d.ts +3 -0
- package/dist/src/analyzers/csharp/patterns.js +57 -0
- package/dist/src/analyzers/go/dependency-manifests.d.ts +10 -0
- package/dist/src/analyzers/go/dependency-manifests.js +117 -0
- package/dist/src/analyzers/go/detector.d.ts +3 -0
- package/dist/src/analyzers/go/detector.js +21 -0
- package/dist/src/analyzers/go/go-detection-config.d.ts +97 -0
- package/dist/src/analyzers/go/go-detection-config.js +164 -0
- package/dist/src/analyzers/go/index.d.ts +2 -0
- package/dist/src/analyzers/go/index.js +11 -0
- package/dist/src/analyzers/go/manifest-parsers.d.ts +20 -0
- package/dist/src/analyzers/go/manifest-parsers.js +104 -0
- package/dist/src/analyzers/go/parser.d.ts +40 -0
- package/dist/src/analyzers/go/parser.js +186 -0
- package/dist/src/analyzers/go/patterns.d.ts +3 -0
- package/dist/src/analyzers/go/patterns.js +50 -0
- package/dist/src/analyzers/jvm/dependency-manifests.d.ts +16 -0
- package/dist/src/analyzers/jvm/dependency-manifests.js +205 -0
- package/dist/src/analyzers/jvm/detector.d.ts +3 -0
- package/dist/src/analyzers/jvm/detector.js +21 -0
- package/dist/src/analyzers/jvm/index.d.ts +9 -0
- package/dist/src/analyzers/jvm/index.js +18 -0
- package/dist/src/analyzers/jvm/jvm-detection-config.d.ts +136 -0
- package/dist/src/analyzers/jvm/jvm-detection-config.js +195 -0
- package/dist/src/analyzers/jvm/manifest-parsers.d.ts +61 -0
- package/dist/src/analyzers/jvm/manifest-parsers.js +246 -0
- package/dist/src/analyzers/jvm/parser.d.ts +54 -0
- package/dist/src/analyzers/jvm/parser.js +419 -0
- package/dist/src/analyzers/jvm/patterns.d.ts +3 -0
- package/dist/src/analyzers/jvm/patterns.js +64 -0
- package/dist/src/analyzers/python/detector.js +1 -1
- package/dist/src/analyzers/python/parser.d.ts +1 -0
- package/dist/src/analyzers/python/parser.js +7 -0
- package/dist/src/analyzers/python/patterns.d.ts +1 -0
- package/dist/src/analyzers/python/patterns.js +22 -77
- package/dist/src/analyzers/python/python-detection-config.d.ts +18 -0
- package/dist/src/analyzers/python/python-detection-config.js +20 -0
- package/dist/src/analyzers/registry.js +15 -0
- package/dist/src/analyzers/shared/c-family-calls.d.ts +26 -0
- package/dist/src/analyzers/shared/c-family-calls.js +118 -0
- package/dist/src/analyzers/shared/strip-comments.d.ts +32 -0
- package/dist/src/analyzers/shared/strip-comments.js +167 -0
- package/dist/src/analyzers/typescript/detector.js +1 -1
- package/dist/src/analyzers/typescript/typescript-detection-config.d.ts +37 -0
- package/dist/src/analyzers/typescript/typescript-detection-config.js +48 -0
- package/dist/src/analyzers/typescript/typescript-detection.d.ts +1 -0
- package/dist/src/analyzers/typescript/typescript-detection.js +27 -29
- package/dist/src/cli.js +28 -1
- package/dist/src/config/file.js +5 -0
- package/dist/src/config/resolve.js +5 -0
- package/dist/src/core/pipeline/graph-mapping.js +3 -0
- package/dist/src/core/pipeline/structural-scan.js +154 -31
- package/dist/src/core/schema/scan-config.schema.d.ts +5 -0
- package/dist/src/core/schema/scan-config.schema.js +5 -0
- package/dist/src/core/schema/scan-result.schema.d.ts +5 -0
- package/dist/src/core/schema/scan-result.schema.js +5 -0
- package/dist/src/core/sectioning/discover-service-sections.js +27 -1
- package/dist/src/core/types/file.d.ts +1 -1
- package/dist/src/ingest/file-system.js +27 -0
- package/dist/src/patterns/config.d.ts +8 -0
- package/dist/src/patterns/config.js +136 -0
- package/dist/src/patterns/detectors/cpp.d.ts +8 -0
- package/dist/src/patterns/detectors/cpp.js +243 -0
- package/dist/src/patterns/detectors/csharp.d.ts +9 -0
- package/dist/src/patterns/detectors/csharp.js +385 -0
- package/dist/src/patterns/detectors/go.d.ts +9 -0
- package/dist/src/patterns/detectors/go.js +298 -0
- package/dist/src/patterns/detectors/helpers.d.ts +3 -0
- package/dist/src/patterns/detectors/helpers.js +5 -0
- package/dist/src/patterns/detectors/jvm.d.ts +15 -0
- package/dist/src/patterns/detectors/jvm.js +537 -0
- package/dist/src/patterns/detectors/python.d.ts +1 -0
- package/dist/src/patterns/detectors/python.js +92 -5
- package/dist/src/patterns/detectors/typescript.d.ts +2 -0
- package/dist/src/patterns/detectors/typescript.js +156 -4
- package/dist/src/patterns/engine.d.ts +18 -0
- package/dist/src/patterns/engine.js +30 -0
- package/dist/src/patterns/scan-exclusions.js +20 -0
- package/dist/src/platform-api/telemetry-client.d.ts +6 -0
- package/dist/src/platform-api/telemetry-client.js +65 -0
- package/dist/src/platform-api/telemetry.types.d.ts +13 -0
- package/dist/src/platform-api/telemetry.types.js +2 -0
- package/dist/src/platform-api/upload-client.d.ts +2 -0
- package/dist/src/platform-api/upload-client.js +4 -0
- package/dist/src/platform-api/upload.types.d.ts +2 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +10 -3
- package/dist/src/upload/run-upload.js +62 -19
- package/dist/src/upload/types.d.ts +2 -0
- package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.d.ts +1 -0
- package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.js +11 -0
- package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +80 -0
- package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.js +66 -0
- package/dist/tests/unit/analyzers/cpp/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/cpp/parser.spec.js +80 -0
- package/dist/tests/unit/analyzers/cpp/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/cpp/patterns.spec.js +141 -0
- package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.js +75 -0
- package/dist/tests/unit/analyzers/csharp/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/csharp/parser.spec.js +118 -0
- package/dist/tests/unit/analyzers/csharp/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/csharp/patterns.spec.js +210 -0
- package/dist/tests/unit/analyzers/go/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/go/dependency-manifests.spec.js +96 -0
- package/dist/tests/unit/analyzers/go/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/go/parser.spec.js +110 -0
- package/dist/tests/unit/analyzers/go/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/go/patterns.spec.js +239 -0
- package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.js +179 -0
- package/dist/tests/unit/analyzers/jvm/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/jvm/parser.spec.js +195 -0
- package/dist/tests/unit/analyzers/jvm/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/jvm/patterns.spec.js +284 -0
- package/dist/tests/unit/analyzers/python/patterns.spec.js +169 -0
- package/dist/tests/unit/analyzers/typescript/detector.spec.js +188 -0
- package/dist/tests/unit/core/cpp-dotnet-scan.spec.d.ts +1 -0
- package/dist/tests/unit/core/cpp-dotnet-scan.spec.js +67 -0
- package/dist/tests/unit/core/cpp-dotnet-sections.spec.d.ts +1 -0
- package/dist/tests/unit/core/cpp-dotnet-sections.spec.js +46 -0
- package/dist/tests/unit/core/go-scan.spec.d.ts +1 -0
- package/dist/tests/unit/core/go-scan.spec.js +78 -0
- package/dist/tests/unit/core/graph-mapping.spec.js +75 -0
- package/dist/tests/unit/core/jvm-scan.spec.d.ts +1 -0
- package/dist/tests/unit/core/jvm-scan.spec.js +94 -0
- package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.d.ts +1 -0
- package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.js +56 -0
- package/dist/tests/unit/ingest/jvm-languages.spec.d.ts +1 -0
- package/dist/tests/unit/ingest/jvm-languages.spec.js +47 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
- package/dist/tests/unit/upload/run-upload.spec.js +18 -0
- package/package.json +1 -1
- package/patterns/cpp.md +176 -0
- package/patterns/cpp.patterns.yaml +314 -0
- package/patterns/csharp.md +211 -0
- package/patterns/csharp.patterns.yaml +375 -0
- package/patterns/go.md +211 -0
- package/patterns/go.patterns.yaml +429 -0
- package/patterns/jvm.md +160 -0
- package/patterns/jvm.patterns.yaml +884 -0
- package/patterns/python.patterns.yaml +177 -0
- package/patterns/third-party.patterns.yaml +5 -0
- package/patterns/typescript.patterns.yaml +222 -0
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const orchestrator_1 = require("../../../src/core/pipeline/orchestrator");
|
|
10
|
+
const discover_service_sections_1 = require("../../../src/core/sectioning/discover-service-sections");
|
|
11
|
+
function fixturePath(name) {
|
|
12
|
+
return path_1.default.join(__dirname, "..", "..", "fixtures", name);
|
|
13
|
+
}
|
|
14
|
+
function write(filePath, content) {
|
|
15
|
+
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
16
|
+
fs_1.default.writeFileSync(filePath, content, "utf8");
|
|
17
|
+
}
|
|
18
|
+
describe("structural scan - JVM repositories", () => {
|
|
19
|
+
it("produces components, flows, and parser stats for a Spring service", async () => {
|
|
20
|
+
const config = (0, orchestrator_1.createDefaultScanConfiguration)({ enableAiInference: false });
|
|
21
|
+
const { scanResult, files, findings } = await (0, orchestrator_1.scan)(fixturePath("java-basic"), config);
|
|
22
|
+
expect(files.some((file) => file.language === "java")).toBe(true);
|
|
23
|
+
const routeNames = findings
|
|
24
|
+
.filter((f) => f.pattern === "express_route")
|
|
25
|
+
.map((f) => f.name);
|
|
26
|
+
expect(routeNames).toEqual(expect.arrayContaining([
|
|
27
|
+
"GET /api/customers/{id}",
|
|
28
|
+
"POST /api/customers",
|
|
29
|
+
"DELETE /api/customers/{id}",
|
|
30
|
+
]));
|
|
31
|
+
const patterns = new Set(findings.map((f) => f.pattern));
|
|
32
|
+
expect(patterns.has("database_connection")).toBe(true);
|
|
33
|
+
expect(patterns.has("external_api_call")).toBe(true);
|
|
34
|
+
expect(patterns.has("auth_middleware")).toBe(true);
|
|
35
|
+
expect(patterns.has("env_variable")).toBe(true);
|
|
36
|
+
expect(scanResult.components.length).toBeGreaterThan(0);
|
|
37
|
+
const stats = (scanResult.languageStats ?? []).find((stat) => stat.language === "java");
|
|
38
|
+
expect(stats).toBeDefined();
|
|
39
|
+
expect(stats?.filesParsed).toBe(3);
|
|
40
|
+
expect(stats?.warnings).toEqual([]);
|
|
41
|
+
const serviceNames = scanResult.components
|
|
42
|
+
.filter((c) => c.type === "third_party")
|
|
43
|
+
.map((c) => c.properties?.serviceName);
|
|
44
|
+
expect(serviceNames).toContain("stripe");
|
|
45
|
+
// The JDBC URL should surface postgres, not a generic SQL node.
|
|
46
|
+
const postgres = findings.filter((f) => f.pattern === "database_connection" &&
|
|
47
|
+
f.properties.databaseType === "postgres");
|
|
48
|
+
expect(postgres.length).toBeGreaterThan(0);
|
|
49
|
+
});
|
|
50
|
+
it("scans a Kotlin service through the same analyzer", async () => {
|
|
51
|
+
const config = (0, orchestrator_1.createDefaultScanConfiguration)({ enableAiInference: false });
|
|
52
|
+
const { scanResult, files, findings } = await (0, orchestrator_1.scan)(fixturePath("kotlin-basic"), config);
|
|
53
|
+
expect(files.some((file) => file.language === "kotlin")).toBe(true);
|
|
54
|
+
const routeNames = findings
|
|
55
|
+
.filter((f) => f.pattern === "express_route")
|
|
56
|
+
.map((f) => f.name);
|
|
57
|
+
expect(routeNames).toEqual(expect.arrayContaining(["GET /health", "POST /api/invoices"]));
|
|
58
|
+
const databases = findings.filter((f) => f.pattern === "database_connection");
|
|
59
|
+
expect(databases.map((f) => f.name)).toContain("exposed");
|
|
60
|
+
const stats = (scanResult.languageStats ?? []).find((stat) => stat.language === "kotlin");
|
|
61
|
+
expect(stats?.filesParsed).toBe(1);
|
|
62
|
+
expect(stats?.warnings).toEqual([]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("section discovery - JVM build files", () => {
|
|
66
|
+
let root;
|
|
67
|
+
beforeAll(() => {
|
|
68
|
+
root = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dp-jvm-sections-"));
|
|
69
|
+
write(path_1.default.join(root, "services", "billing", "pom.xml"), "<project><groupId>com.acme</groupId><artifactId>billing</artifactId></project>");
|
|
70
|
+
write(path_1.default.join(root, "services", "billing", "src", "main", "java", "App.java"), "package com.acme.billing;\n\npublic class App {}\n");
|
|
71
|
+
write(path_1.default.join(root, "services", "ledger", "build.gradle.kts"), 'dependencies {\n implementation("org.postgresql:postgresql:42.7.1")\n}\n');
|
|
72
|
+
write(path_1.default.join(root, "services", "ledger", "src", "main", "kotlin", "App.kt"), "package com.acme.ledger\n\nfun main() {}\n");
|
|
73
|
+
// A settings file marks the root of a multi-project build, not a module.
|
|
74
|
+
write(path_1.default.join(root, "settings.gradle.kts"), 'rootProject.name = "acme"\n');
|
|
75
|
+
});
|
|
76
|
+
afterAll(() => {
|
|
77
|
+
fs_1.default.rmSync(root, { recursive: true, force: true });
|
|
78
|
+
});
|
|
79
|
+
it("treats pom.xml and build.gradle.kts as service boundaries", async () => {
|
|
80
|
+
const { sections } = await (0, discover_service_sections_1.discoverServiceSections)(root);
|
|
81
|
+
const serviceDirs = sections
|
|
82
|
+
.filter((section) => section.role === "service")
|
|
83
|
+
.map((section) => section.sectionDir)
|
|
84
|
+
.sort();
|
|
85
|
+
expect(serviceDirs).toEqual(["services/billing", "services/ledger"]);
|
|
86
|
+
});
|
|
87
|
+
it("does not promote settings.gradle.kts to a service section", async () => {
|
|
88
|
+
const { sections } = await (0, discover_service_sections_1.discoverServiceSections)(root);
|
|
89
|
+
const rootSection = sections.find((section) => section.sectionDir === "");
|
|
90
|
+
// A settings file marks a multi-project build, not a deployable module,
|
|
91
|
+
// so the repository root stays the root section.
|
|
92
|
+
expect(rootSection?.role).toBe("root");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const file_system_1 = require("../../../src/ingest/file-system");
|
|
10
|
+
describe("ingest/file-system - C++ and C# language mapping", () => {
|
|
11
|
+
let root;
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
root = await promises_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "dp-ingest-cpp-dotnet-"));
|
|
14
|
+
const files = {
|
|
15
|
+
"main.cpp": "int main() { return 0; }",
|
|
16
|
+
"helper.cc": "void helper() {}",
|
|
17
|
+
"service.cxx": "void service() {}",
|
|
18
|
+
"types.hpp": "struct T {};",
|
|
19
|
+
"legacy.h": "void legacy();",
|
|
20
|
+
"Program.cs": "class Program {}",
|
|
21
|
+
"View.cshtml": "@page",
|
|
22
|
+
"Component.razor": "<div></div>",
|
|
23
|
+
"notes.md": "# notes",
|
|
24
|
+
};
|
|
25
|
+
for (const [name, content] of Object.entries(files)) {
|
|
26
|
+
await promises_1.default.writeFile(path_1.default.join(root, name), content, "utf8");
|
|
27
|
+
}
|
|
28
|
+
// Generated C# sources and .NET build output are excluded by default.
|
|
29
|
+
await promises_1.default.writeFile(path_1.default.join(root, "Resources.Designer.cs"), "class Resources {}", "utf8");
|
|
30
|
+
await promises_1.default.mkdir(path_1.default.join(root, "obj"), { recursive: true });
|
|
31
|
+
await promises_1.default.writeFile(path_1.default.join(root, "obj", "Generated.cs"), "class Generated {}", "utf8");
|
|
32
|
+
});
|
|
33
|
+
afterAll(async () => {
|
|
34
|
+
await promises_1.default.rm(root, { recursive: true, force: true });
|
|
35
|
+
});
|
|
36
|
+
it("maps C++ and C# extensions to their languages", async () => {
|
|
37
|
+
const files = await (0, file_system_1.ingestFileSystem)(root);
|
|
38
|
+
const byPath = new Map(files.map((file) => [file.path, file.language]));
|
|
39
|
+
expect(byPath.get("main.cpp")).toBe("cpp");
|
|
40
|
+
expect(byPath.get("helper.cc")).toBe("cpp");
|
|
41
|
+
expect(byPath.get("service.cxx")).toBe("cpp");
|
|
42
|
+
expect(byPath.get("types.hpp")).toBe("cpp");
|
|
43
|
+
expect(byPath.get("legacy.h")).toBe("cpp");
|
|
44
|
+
expect(byPath.get("Program.cs")).toBe("csharp");
|
|
45
|
+
expect(byPath.get("View.cshtml")).toBe("csharp");
|
|
46
|
+
expect(byPath.get("Component.razor")).toBe("csharp");
|
|
47
|
+
// Unsupported file types are still skipped.
|
|
48
|
+
expect(byPath.has("notes.md")).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
it("skips generated C# sources and .NET build output", async () => {
|
|
51
|
+
const files = await (0, file_system_1.ingestFileSystem)(root);
|
|
52
|
+
const paths = files.map((file) => file.path);
|
|
53
|
+
expect(paths).not.toContain("Resources.Designer.cs");
|
|
54
|
+
expect(paths.some((p) => p.startsWith("obj/"))).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const file_system_1 = require("../../../src/ingest/file-system");
|
|
10
|
+
describe("ingest/file-system - Java and Kotlin language mapping", () => {
|
|
11
|
+
let root;
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
root = await promises_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "dp-ingest-jvm-"));
|
|
14
|
+
const files = {
|
|
15
|
+
"Application.java": "class Application {}",
|
|
16
|
+
"Routes.kt": "fun routes() {}",
|
|
17
|
+
"build.gradle.kts": "plugins { }",
|
|
18
|
+
"notes.md": "# notes",
|
|
19
|
+
};
|
|
20
|
+
for (const [name, content] of Object.entries(files)) {
|
|
21
|
+
await promises_1.default.writeFile(path_1.default.join(root, name), content, "utf8");
|
|
22
|
+
}
|
|
23
|
+
// Maven and Gradle build output is excluded by default.
|
|
24
|
+
await promises_1.default.mkdir(path_1.default.join(root, "target", "classes"), { recursive: true });
|
|
25
|
+
await promises_1.default.writeFile(path_1.default.join(root, "target", "classes", "Generated.java"), "class Generated {}", "utf8");
|
|
26
|
+
await promises_1.default.mkdir(path_1.default.join(root, ".gradle"), { recursive: true });
|
|
27
|
+
await promises_1.default.writeFile(path_1.default.join(root, ".gradle", "Cached.kt"), "fun cached() {}", "utf8");
|
|
28
|
+
});
|
|
29
|
+
afterAll(async () => {
|
|
30
|
+
await promises_1.default.rm(root, { recursive: true, force: true });
|
|
31
|
+
});
|
|
32
|
+
it("maps .java to java and .kt/.kts to kotlin", async () => {
|
|
33
|
+
const files = await (0, file_system_1.ingestFileSystem)(root);
|
|
34
|
+
const byName = new Map(files.map((file) => [file.name, file.language]));
|
|
35
|
+
expect(byName.get("Application.java")).toBe("java");
|
|
36
|
+
expect(byName.get("Routes.kt")).toBe("kotlin");
|
|
37
|
+
expect(byName.get("build.gradle.kts")).toBe("kotlin");
|
|
38
|
+
expect(byName.has("notes.md")).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it("excludes Maven and Gradle build output", async () => {
|
|
41
|
+
const files = await (0, file_system_1.ingestFileSystem)(root);
|
|
42
|
+
const names = files.map((file) => file.name);
|
|
43
|
+
// `target/` is excluded by name; `.gradle/` as a hidden directory.
|
|
44
|
+
expect(names).not.toContain("Generated.java");
|
|
45
|
+
expect(names).not.toContain("Cached.kt");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
|
|
4
|
+
describe("isCliTelemetryEnabled", () => {
|
|
5
|
+
const originalNodeEnv = process.env.NODE_ENV;
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
delete process.env.DATAPARADE_TELEMETRY;
|
|
8
|
+
delete process.env.SCAN_TELEMETRY_ENABLED;
|
|
9
|
+
process.env.NODE_ENV = originalNodeEnv;
|
|
10
|
+
});
|
|
11
|
+
it("is off in test unless explicitly enabled", () => {
|
|
12
|
+
process.env.NODE_ENV = "test";
|
|
13
|
+
delete process.env.DATAPARADE_TELEMETRY;
|
|
14
|
+
expect((0, telemetry_client_1.isCliTelemetryEnabled)({ NODE_ENV: "test" })).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
it("honors DATAPARADE_TELEMETRY=false", () => {
|
|
17
|
+
expect((0, telemetry_client_1.isCliTelemetryEnabled)({ DATAPARADE_TELEMETRY: "false", NODE_ENV: "production" })).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
it("honors SCAN_TELEMETRY_ENABLED=false", () => {
|
|
20
|
+
expect((0, telemetry_client_1.isCliTelemetryEnabled)({
|
|
21
|
+
SCAN_TELEMETRY_ENABLED: "false",
|
|
22
|
+
NODE_ENV: "production",
|
|
23
|
+
})).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe("reportCliUsageEvent", () => {
|
|
27
|
+
const fetchMock = jest.fn();
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
fetchMock.mockReset();
|
|
30
|
+
global.fetch = fetchMock;
|
|
31
|
+
});
|
|
32
|
+
it("does not throw when the API returns 5xx", async () => {
|
|
33
|
+
fetchMock.mockResolvedValue({ ok: false, status: 500 });
|
|
34
|
+
await expect((0, telemetry_client_1.reportCliUsageEvent)({
|
|
35
|
+
sessionId: "11111111-1111-4111-8111-111111111111",
|
|
36
|
+
event: "scan_started",
|
|
37
|
+
command: "scan",
|
|
38
|
+
}, { DATAPARADE_TELEMETRY: "true", NODE_ENV: "test" })).resolves.toBeUndefined();
|
|
39
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
it("is a no-op when telemetry is disabled", async () => {
|
|
42
|
+
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
43
|
+
sessionId: "11111111-1111-4111-8111-111111111111",
|
|
44
|
+
event: "scan_started",
|
|
45
|
+
}, { DATAPARADE_TELEMETRY: "false" });
|
|
46
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -16,6 +16,11 @@ describe("buildImportPreviewUrl", () => {
|
|
|
16
16
|
const url = (0, build_preview_url_1.buildImportPreviewUrl)("draft-abc");
|
|
17
17
|
expect(url).toBe("http://localhost:3001/dashboard?importDraft=draft-abc");
|
|
18
18
|
});
|
|
19
|
+
it("appends cliSession when provided", () => {
|
|
20
|
+
process.env.DATAPARADE_APP_URL = "http://localhost:3001";
|
|
21
|
+
const url = (0, build_preview_url_1.buildImportPreviewUrl)("draft-abc", "11111111-1111-4111-8111-111111111111");
|
|
22
|
+
expect(url).toContain("cliSession=11111111-1111-4111-8111-111111111111");
|
|
23
|
+
});
|
|
19
24
|
});
|
|
20
25
|
describe("buildAnonymousCliPreviewUrl", () => {
|
|
21
26
|
const original = process.env.DATAPARADE_APP_URL;
|
|
@@ -32,4 +37,9 @@ describe("buildAnonymousCliPreviewUrl", () => {
|
|
|
32
37
|
const url = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)("claim-token-xyz");
|
|
33
38
|
expect(url).toBe("http://localhost:3001/preview/cli/claim-token-xyz");
|
|
34
39
|
});
|
|
40
|
+
it("appends cliSession when provided", () => {
|
|
41
|
+
process.env.DATAPARADE_APP_URL = "http://localhost:3001";
|
|
42
|
+
const url = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)("claim-token-xyz", "11111111-1111-4111-8111-111111111111");
|
|
43
|
+
expect(url).toContain("cliSession=11111111-1111-4111-8111-111111111111");
|
|
44
|
+
});
|
|
35
45
|
});
|
|
@@ -5,11 +5,15 @@ jest.mock("../../../src/platform-api/upload-client", () => ({
|
|
|
5
5
|
cliUploadAnonymousPreview: jest.fn(),
|
|
6
6
|
cliUploadPreview: jest.fn(),
|
|
7
7
|
}));
|
|
8
|
+
jest.mock("../../../src/platform-api/telemetry-client", () => ({
|
|
9
|
+
reportCliUsageEvent: jest.fn().mockResolvedValue(undefined),
|
|
10
|
+
}));
|
|
8
11
|
jest.mock("../../../src/upload/build-preview-url", () => ({
|
|
9
12
|
buildAnonymousCliPreviewUrl: jest.fn((token) => `https://app.example/preview/cli/${token}`),
|
|
10
13
|
buildImportPreviewUrl: jest.fn((draftId) => `https://app.example/dashboard?importDraft=${draftId}`),
|
|
11
14
|
}));
|
|
12
15
|
const upload_client_1 = require("../../../src/platform-api/upload-client");
|
|
16
|
+
const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
|
|
13
17
|
describe("runDataflowUpload anonymous path", () => {
|
|
14
18
|
const logSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);
|
|
15
19
|
afterEach(() => {
|
|
@@ -34,10 +38,24 @@ describe("runDataflowUpload anonymous path", () => {
|
|
|
34
38
|
dataflow: { schemaVersion: "1.0" },
|
|
35
39
|
projectName: "Proj",
|
|
36
40
|
scanJobId: "job-anon-1",
|
|
41
|
+
cliUsageSessionId: undefined,
|
|
42
|
+
command: "scan",
|
|
37
43
|
});
|
|
38
44
|
expect(upload_client_1.cliUploadPreview).not.toHaveBeenCalled();
|
|
39
45
|
expect(result.previewUrl).toContain("claim-1");
|
|
40
46
|
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Claiming this preview after signup uses 1 scan slot"));
|
|
41
47
|
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("platform AI tokens"));
|
|
42
48
|
});
|
|
49
|
+
it("reports upload_failed and rethrows", async () => {
|
|
50
|
+
upload_client_1.cliUploadAnonymousPreview.mockRejectedValue(new Error("network down"));
|
|
51
|
+
await expect((0, run_upload_1.runDataflowUpload)({
|
|
52
|
+
dataflow: { schemaVersion: "1.0" },
|
|
53
|
+
cliUsageSessionId: "11111111-1111-4111-8111-111111111111",
|
|
54
|
+
logPrefix: "[scan]",
|
|
55
|
+
})).rejects.toThrow("network down");
|
|
56
|
+
expect(telemetry_client_1.reportCliUsageEvent).toHaveBeenCalledWith(expect.objectContaining({
|
|
57
|
+
event: "upload_failed",
|
|
58
|
+
errorCode: "upload_failed",
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
43
61
|
});
|
package/package.json
CHANGED
package/patterns/cpp.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# C++ Patterns (CLI Scanner)
|
|
2
|
+
|
|
3
|
+
This document describes the C++ patterns implemented by the CLI codebase
|
|
4
|
+
scanner.
|
|
5
|
+
|
|
6
|
+
The C++ analyzer emits `RawFinding[]` using the **shared pattern IDs** from
|
|
7
|
+
`core/types/detection.ts`:
|
|
8
|
+
|
|
9
|
+
- `express_route`
|
|
10
|
+
- `database_connection`
|
|
11
|
+
- `external_api_call`
|
|
12
|
+
- `auth_middleware`
|
|
13
|
+
- `config_file`
|
|
14
|
+
- `env_variable`
|
|
15
|
+
|
|
16
|
+
These pattern IDs align with the TypeScript/JavaScript, Python, and C#
|
|
17
|
+
analyzers so that the classifier and data-flow detector treat every language
|
|
18
|
+
consistently.
|
|
19
|
+
|
|
20
|
+
## Structure
|
|
21
|
+
|
|
22
|
+
- **YAML configuration** at `cli/patterns/cpp.patterns.yaml` defines pattern
|
|
23
|
+
IDs, headers, package names, call names, route regexes, and confidences.
|
|
24
|
+
- **Config loader** (`cli/src/analyzers/cpp/cpp-detection-config.ts`) validates
|
|
25
|
+
the YAML and compiles its regexes.
|
|
26
|
+
- **Parser** (`cli/src/analyzers/cpp/parser.ts`) produces a lightweight
|
|
27
|
+
translation-unit model: includes, functions, types, namespaces, and call
|
|
28
|
+
sites.
|
|
29
|
+
- **Detectors** (`cli/src/patterns/detectors/cpp.ts`) run inside the shared
|
|
30
|
+
`matchPatterns()` engine.
|
|
31
|
+
|
|
32
|
+
### Comment handling
|
|
33
|
+
|
|
34
|
+
C++ sources are pre-processed by `stripCommentsPreservingLayout()`
|
|
35
|
+
(`cli/src/analyzers/shared/strip-comments.ts`) before any line-based rule runs.
|
|
36
|
+
Comments are replaced with spaces so line numbers stay accurate, and string
|
|
37
|
+
literals are preserved — a URL like `"https://api.example.com"` must not be
|
|
38
|
+
truncated at its `//`. Commented-out routes therefore produce no findings.
|
|
39
|
+
|
|
40
|
+
### Header matching
|
|
41
|
+
|
|
42
|
+
`includeHeaders` values are matched against `#include` paths:
|
|
43
|
+
|
|
44
|
+
- A value **without** a `/` must match a whole path segment. `hiredis` matches
|
|
45
|
+
`<hiredis/hiredis.h>`; `sql.h` does **not** match `<mysql/mysql.h>`.
|
|
46
|
+
- A value **with** a `/` is matched as a substring, e.g. `curl/curl.h`.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Route / Handler Detection (`express_route`)
|
|
51
|
+
|
|
52
|
+
Route detection is regex-driven per framework and gated on the framework's
|
|
53
|
+
headers. Each rule declares a `regex` plus optional `methodGroup` /
|
|
54
|
+
`pathGroup` / `defaultMethod`.
|
|
55
|
+
|
|
56
|
+
| Framework | Detected form |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| Crow | `CROW_ROUTE(app, "/users")`, `CROW_BP_ROUTE(...)` |
|
|
59
|
+
| cpp-httplib | `svr.Get("/health", ...)`, `svr.Post(...)` |
|
|
60
|
+
| Drogon | `registerHandler("/users", ...)`, `ADD_METHOD_TO(...)`, `METHOD_ADD(...)` |
|
|
61
|
+
| Pistache | `Routes::Get(router, "/users", ...)` |
|
|
62
|
+
| oatpp | `ENDPOINT("GET", "/users", name)` |
|
|
63
|
+
|
|
64
|
+
**Example:**
|
|
65
|
+
|
|
66
|
+
```cpp
|
|
67
|
+
#include <crow.h>
|
|
68
|
+
|
|
69
|
+
int main() {
|
|
70
|
+
crow::SimpleApp app;
|
|
71
|
+
CROW_ROUTE(app, "/customers")([]() { return crow::response(200); });
|
|
72
|
+
app.port(8080).run();
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Emitted finding:**
|
|
77
|
+
|
|
78
|
+
- `pattern`: `express_route`
|
|
79
|
+
- `name`: `"<METHOD> <path>"` when the framework encodes a method, otherwise
|
|
80
|
+
`"<FRAMEWORK>_ROUTE <path>"`
|
|
81
|
+
- `properties`: `framework`, `httpMethods`, `path`
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Database Connections (`database_connection`)
|
|
86
|
+
|
|
87
|
+
Detected from a header include, a package-manifest entry, or a call site.
|
|
88
|
+
|
|
89
|
+
| Client | `databaseType` | Signals |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| libpq | `postgres` | `<libpq-fe.h>`, `PQconnectdb` |
|
|
92
|
+
| libpqxx | `postgres` | `<pqxx/pqxx>`, `pqxx::connection` |
|
|
93
|
+
| SQLite3 | `sqlite` | `<sqlite3.h>`, `sqlite3_open` |
|
|
94
|
+
| MySQL Connector/C++ | `mysql` | `<mysql/mysql.h>`, `mysql_real_connect` |
|
|
95
|
+
| mongocxx | `mongodb` | `<mongocxx/client.hpp>`, `mongocxx::client` |
|
|
96
|
+
| hiredis | `redis` | `<hiredis/hiredis.h>`, `redisConnect` |
|
|
97
|
+
| redis-plus-plus | `redis` | `<sw/redis++/redis++.h>` |
|
|
98
|
+
| SOCI | `sql` | `<soci/soci.h>`, `soci::session` |
|
|
99
|
+
| nanodbc | `sql` | `<nanodbc/nanodbc.h>` |
|
|
100
|
+
| DataStax C++ driver | `cassandra` | `<cassandra.h>`, `cass_session_connect` |
|
|
101
|
+
|
|
102
|
+
**Emitted properties:** `client`, `databaseType`.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## External API Calls (`external_api_call`)
|
|
107
|
+
|
|
108
|
+
Matched on call sites whose callee is a configured `callNames` entry or starts
|
|
109
|
+
with a configured `callNamePrefixes` entry, gated on the client's headers. When
|
|
110
|
+
the call arguments contain a literal URL, the service name is resolved from the
|
|
111
|
+
third-party catalog (`third-party.patterns.yaml`).
|
|
112
|
+
|
|
113
|
+
| Client | Signals |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| libcurl | `<curl/curl.h>`, `curl_easy_setopt(..., CURLOPT_URL, "https://...")` |
|
|
116
|
+
| cpr | `<cpr/cpr.h>`, any `cpr::` call |
|
|
117
|
+
| cpp-httplib client | `httplib::Client("https://...")` |
|
|
118
|
+
| POCO | `Poco::Net::HTTPSClientSession`, `Poco::URI` |
|
|
119
|
+
| Boost.Beast | `<boost/beast/http.hpp>` |
|
|
120
|
+
|
|
121
|
+
**Example:**
|
|
122
|
+
|
|
123
|
+
```cpp
|
|
124
|
+
#include <curl/curl.h>
|
|
125
|
+
|
|
126
|
+
CURL* curl = curl_easy_init();
|
|
127
|
+
curl_easy_setopt(curl, CURLOPT_URL, "https://api.stripe.com/v1/charges");
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
→ `external_api_call` with `properties.serviceName = "stripe"`.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Auth (`auth_middleware`)
|
|
135
|
+
|
|
136
|
+
- **jwt-cpp** — `<jwt-cpp/jwt.h>` or `jwt::decode` / `jwt::verify` /
|
|
137
|
+
`jwt::create`; emits `properties.strategy = "jwt"`.
|
|
138
|
+
- **Bearer token headers** — a literal `"Authorization"` header or a
|
|
139
|
+
`Authorization: Bearer` construction; lower confidence (`0.7`), emits
|
|
140
|
+
`properties.strategy = "bearer_token"`.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Config and Environment (`config_file`, `env_variable`)
|
|
145
|
+
|
|
146
|
+
- `env_variable`: `getenv("KEY")` / `std::getenv("KEY")`; the key is captured
|
|
147
|
+
into `properties.key`.
|
|
148
|
+
- `config_file`: files named `config`, `configuration`, or `settings` with a
|
|
149
|
+
C++ extension (`.h`, `.hpp`, `.hxx`, `.cpp`, `.cc`, `.cxx`).
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Dependency Manifests
|
|
154
|
+
|
|
155
|
+
`cli/src/analyzers/cpp/dependency-manifests.ts` walks the repository for:
|
|
156
|
+
|
|
157
|
+
- `vcpkg.json` — `dependencies` (string and object forms)
|
|
158
|
+
- `conanfile.txt` — `[requires]` / `[tool_requires]`
|
|
159
|
+
- `conanfile.py` — `requires = "..."`, `self.requires("...")`
|
|
160
|
+
- `CMakeLists.txt` — `find_package()`, `FetchContent_Declare()`, `CPMAddPackage()`
|
|
161
|
+
|
|
162
|
+
Versions are stripped (`fmt/10.2.1` → `fmt`). Package names feed the shared
|
|
163
|
+
third-party service catalog and the `packageNames` field of the database and
|
|
164
|
+
auth rules, so a `libpqxx` dependency is reported as a Postgres client even
|
|
165
|
+
when no source file was scanned.
|
|
166
|
+
|
|
167
|
+
Manifest walking is bounded by the shared budgets in
|
|
168
|
+
`cli/src/analyzers/shared/manifest-budgets.ts`.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## File Types
|
|
173
|
+
|
|
174
|
+
The ingest layer maps `.cpp`, `.cc`, `.cxx`, `.c++`, `.hpp`, `.hh`, `.hxx`,
|
|
175
|
+
`.ipp`, `.inl`, and `.h` to the `cpp` language. `cmake-build-debug/` and
|
|
176
|
+
`cmake-build-release/` are excluded by default.
|