@dataparade/cli 0.0.10 → 0.0.12

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 (64) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/analyzers/php/dependency-manifests.d.ts +10 -0
  3. package/dist/src/analyzers/php/dependency-manifests.js +117 -0
  4. package/dist/src/analyzers/php/detector.d.ts +3 -0
  5. package/dist/src/analyzers/php/detector.js +20 -0
  6. package/dist/src/analyzers/php/index.d.ts +2 -0
  7. package/dist/src/analyzers/php/index.js +11 -0
  8. package/dist/src/analyzers/php/manifest-parsers.d.ts +14 -0
  9. package/dist/src/analyzers/php/manifest-parsers.js +40 -0
  10. package/dist/src/analyzers/php/parser.d.ts +42 -0
  11. package/dist/src/analyzers/php/parser.js +297 -0
  12. package/dist/src/analyzers/php/patterns.d.ts +3 -0
  13. package/dist/src/analyzers/php/patterns.js +49 -0
  14. package/dist/src/analyzers/php/php-detection-config.d.ts +104 -0
  15. package/dist/src/analyzers/php/php-detection-config.js +192 -0
  16. package/dist/src/analyzers/registry.js +3 -0
  17. package/dist/src/analyzers/shared/strip-comments.js +3 -2
  18. package/dist/src/classifier/postprocessing.d.ts +6 -0
  19. package/dist/src/classifier/postprocessing.js +61 -6
  20. package/dist/src/cli.js +27 -0
  21. package/dist/src/config/file.js +1 -0
  22. package/dist/src/config/resolve.js +1 -0
  23. package/dist/src/core/pipeline/classifier-phase.js +3 -3
  24. package/dist/src/core/pipeline/structural-scan.js +39 -14
  25. package/dist/src/core/schema/scan-config.schema.d.ts +1 -0
  26. package/dist/src/core/schema/scan-config.schema.js +1 -0
  27. package/dist/src/core/schema/scan-result.schema.d.ts +1 -0
  28. package/dist/src/core/schema/scan-result.schema.js +1 -0
  29. package/dist/src/core/sectioning/discover-service-sections.js +3 -0
  30. package/dist/src/core/types/file.d.ts +1 -1
  31. package/dist/src/ingest/file-system.js +3 -0
  32. package/dist/src/patterns/config.d.ts +2 -0
  33. package/dist/src/patterns/config.js +31 -0
  34. package/dist/src/patterns/detectors/php.d.ts +9 -0
  35. package/dist/src/patterns/detectors/php.js +466 -0
  36. package/dist/src/patterns/engine.js +7 -0
  37. package/dist/src/platform-api/telemetry-client.d.ts +6 -0
  38. package/dist/src/platform-api/telemetry-client.js +65 -0
  39. package/dist/src/platform-api/telemetry.types.d.ts +13 -0
  40. package/dist/src/platform-api/telemetry.types.js +2 -0
  41. package/dist/src/platform-api/upload-client.d.ts +2 -0
  42. package/dist/src/platform-api/upload-client.js +4 -0
  43. package/dist/src/platform-api/upload.types.d.ts +2 -0
  44. package/dist/src/upload/build-preview-url.d.ts +2 -2
  45. package/dist/src/upload/build-preview-url.js +10 -3
  46. package/dist/src/upload/run-upload.js +62 -19
  47. package/dist/src/upload/types.d.ts +2 -0
  48. package/dist/tests/unit/analyzers/php/dependency-manifests.spec.d.ts +1 -0
  49. package/dist/tests/unit/analyzers/php/dependency-manifests.spec.js +54 -0
  50. package/dist/tests/unit/analyzers/php/parser.spec.d.ts +1 -0
  51. package/dist/tests/unit/analyzers/php/parser.spec.js +128 -0
  52. package/dist/tests/unit/analyzers/php/patterns.spec.d.ts +1 -0
  53. package/dist/tests/unit/analyzers/php/patterns.spec.js +334 -0
  54. package/dist/tests/unit/classifier/classify.spec.js +68 -0
  55. package/dist/tests/unit/ingest/php-languages.spec.d.ts +1 -0
  56. package/dist/tests/unit/ingest/php-languages.spec.js +40 -0
  57. package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
  58. package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
  59. package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
  60. package/dist/tests/unit/upload/run-upload.spec.js +18 -0
  61. package/package.json +1 -1
  62. package/patterns/php.md +74 -0
  63. package/patterns/php.patterns.yaml +311 -0
  64. package/patterns/third-party.patterns.yaml +10 -0
@@ -0,0 +1,104 @@
1
+ import { type PatternId } from "../../core/types/detection";
2
+ export interface PhpRouteRegex {
3
+ regex: RegExp;
4
+ methodGroup?: number;
5
+ pathGroup?: number;
6
+ defaultMethod?: string;
7
+ }
8
+ export interface PhpDbClientConfig {
9
+ id: string;
10
+ patternId: PatternId;
11
+ databaseType: string;
12
+ importNamespaces: string[];
13
+ packageNames: string[];
14
+ callNames: string[];
15
+ confidence: number;
16
+ }
17
+ export interface PhpAuthLibraryConfig {
18
+ id: string;
19
+ patternId: PatternId;
20
+ importNamespaces: string[];
21
+ packageNames: string[];
22
+ callNames: string[];
23
+ contentRegexes: RegExp[];
24
+ strategy?: string;
25
+ confidence: number;
26
+ }
27
+ export interface PhpRouteFrameworkConfig {
28
+ id: string;
29
+ patternId: PatternId;
30
+ importNamespaces: string[];
31
+ packageNames: string[];
32
+ routeRegexes: PhpRouteRegex[];
33
+ confidence: number;
34
+ }
35
+ export interface PhpServerlessHandlerConfig {
36
+ id: string;
37
+ patternId: PatternId;
38
+ importNamespaces: string[];
39
+ packageNames: string[];
40
+ callNames: string[];
41
+ confidence: number;
42
+ }
43
+ export interface PhpConfigLoader {
44
+ id: string;
45
+ importNamespaces: string[];
46
+ packageNames: string[];
47
+ callNames: string[];
48
+ }
49
+ export interface PhpHttpClientConfig {
50
+ id: string;
51
+ patternId: PatternId;
52
+ clientName: string;
53
+ importNamespaces: string[];
54
+ packageNames: string[];
55
+ callNames: string[];
56
+ callNameSuffixes: string[];
57
+ urlRegex: RegExp;
58
+ confidence: number;
59
+ /** When true, gated import/package alone emits a finding (SDK presence). */
60
+ emitOnPresence: boolean;
61
+ }
62
+ export interface PhpPatternConfig {
63
+ dbClients: PhpDbClientConfig[];
64
+ pdoDsn?: {
65
+ patternId: PatternId;
66
+ regex: RegExp;
67
+ name: string;
68
+ confidence: number;
69
+ drivers: Record<string, string>;
70
+ defaultDatabaseType: string;
71
+ };
72
+ auth: {
73
+ libraries: PhpAuthLibraryConfig[];
74
+ };
75
+ routes: {
76
+ frameworks: PhpRouteFrameworkConfig[];
77
+ };
78
+ serverless: {
79
+ handlers: PhpServerlessHandlerConfig[];
80
+ };
81
+ envConfig: {
82
+ envVariable?: {
83
+ patternId: PatternId;
84
+ regex: RegExp;
85
+ confidence: number;
86
+ };
87
+ configLoaders?: {
88
+ patternId: PatternId;
89
+ confidence: number;
90
+ loaders: PhpConfigLoader[];
91
+ };
92
+ configFile?: {
93
+ patternId: PatternId;
94
+ fileNameRegex: RegExp;
95
+ name: string;
96
+ confidence: number;
97
+ };
98
+ };
99
+ externalApis: {
100
+ httpClients: PhpHttpClientConfig[];
101
+ };
102
+ }
103
+ export declare function clearPhpPatternConfigCache(): void;
104
+ export declare function loadPhpPatternConfig(): PhpPatternConfig;
@@ -0,0 +1,192 @@
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.clearPhpPatternConfigCache = clearPhpPatternConfigCache;
7
+ exports.loadPhpPatternConfig = loadPhpPatternConfig;
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?:\\/\\/[^"\']+)["\']';
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", "php.patterns.yaml");
37
+ }
38
+ function normalizeList(values) {
39
+ return (values ?? [])
40
+ .map((v) => (typeof v === "string" ? v.trim() : String(v ?? "").trim()))
41
+ .filter(Boolean);
42
+ }
43
+ /** Coerce YAML call-name entries to strings (trailing `::` can parse as maps). */
44
+ function normalizeCallNames(values) {
45
+ if (!values)
46
+ return [];
47
+ const out = [];
48
+ for (const v of values) {
49
+ if (typeof v === "string" && v.trim()) {
50
+ out.push(v.trim());
51
+ continue;
52
+ }
53
+ if (v && typeof v === "object") {
54
+ for (const key of Object.keys(v)) {
55
+ if (key.trim())
56
+ out.push(key.trim());
57
+ }
58
+ }
59
+ }
60
+ return out;
61
+ }
62
+ function normalizeRouteRegexes(raw, context) {
63
+ return (raw ?? []).map((entry, index) => ({
64
+ regex: compileRegex(entry.regex, `${context}.routeRegexes[${index}]`),
65
+ methodGroup: entry.methodGroup,
66
+ pathGroup: entry.pathGroup,
67
+ defaultMethod: entry.defaultMethod,
68
+ }));
69
+ }
70
+ function normalizeRawConfig(raw) {
71
+ const dbClients = raw.db_clients?.map((c) => ({
72
+ id: c.id,
73
+ patternId: validatePatternId(c.patternId, `php.db_clients entry '${c.id}'`),
74
+ databaseType: c.databaseType,
75
+ importNamespaces: normalizeList(c.importNamespaces),
76
+ packageNames: normalizeList(c.packageNames),
77
+ callNames: normalizeCallNames(c.callNames),
78
+ confidence: c.confidence ?? DEFAULT_CONFIDENCE,
79
+ })) ?? [];
80
+ const pdoDsnRaw = raw.pdo_dsn;
81
+ const pdoDsn = pdoDsnRaw && pdoDsnRaw.patternId && pdoDsnRaw.regex
82
+ ? {
83
+ patternId: validatePatternId(pdoDsnRaw.patternId, "php.pdo_dsn.patternId"),
84
+ regex: compileRegex(pdoDsnRaw.regex, "php.pdo_dsn.regex"),
85
+ name: pdoDsnRaw.name ?? "pdo_dsn",
86
+ confidence: pdoDsnRaw.confidence ?? DEFAULT_CONFIDENCE,
87
+ drivers: pdoDsnRaw.drivers ?? {},
88
+ defaultDatabaseType: pdoDsnRaw.defaultDatabaseType ?? "sql",
89
+ }
90
+ : undefined;
91
+ const authLibraries = raw.auth?.libraries?.map((lib) => ({
92
+ id: lib.id,
93
+ patternId: validatePatternId(lib.patternId, `php.auth.libraries['${lib.id}']`),
94
+ importNamespaces: normalizeList(lib.importNamespaces),
95
+ packageNames: normalizeList(lib.packageNames),
96
+ callNames: normalizeCallNames(lib.callNames),
97
+ contentRegexes: (lib.contentRegexes ?? []).map((p) => compileRegex(p, `php.auth.libraries['${lib.id}'].contentRegexes`)),
98
+ strategy: lib.strategy,
99
+ confidence: lib.confidence ?? DEFAULT_CONFIDENCE,
100
+ })) ?? [];
101
+ const routeFrameworks = raw.routes?.frameworks?.map((fw) => ({
102
+ id: fw.id,
103
+ patternId: validatePatternId(fw.patternId, `php.routes.frameworks['${fw.id}']`),
104
+ importNamespaces: normalizeList(fw.importNamespaces),
105
+ packageNames: normalizeList(fw.packageNames),
106
+ routeRegexes: normalizeRouteRegexes(fw.routeRegexes, `php.routes.frameworks['${fw.id}']`),
107
+ confidence: fw.confidence ?? DEFAULT_CONFIDENCE,
108
+ })) ?? [];
109
+ const serverlessHandlers = raw.serverless?.handlers?.map((handler) => ({
110
+ id: handler.id,
111
+ patternId: validatePatternId(handler.patternId, `php.serverless.handlers['${handler.id}']`),
112
+ importNamespaces: normalizeList(handler.importNamespaces),
113
+ packageNames: normalizeList(handler.packageNames),
114
+ callNames: normalizeCallNames(handler.callNames),
115
+ confidence: handler.confidence ?? DEFAULT_CONFIDENCE,
116
+ })) ?? [];
117
+ const envVarRaw = raw.env_config?.envVariable;
118
+ const envVariable = envVarRaw && envVarRaw.patternId && envVarRaw.regex
119
+ ? {
120
+ patternId: validatePatternId(envVarRaw.patternId, "php.env_config.envVariable.patternId"),
121
+ regex: compileRegex(envVarRaw.regex, "php.env_config.envVariable.regex"),
122
+ confidence: envVarRaw.confidence ?? DEFAULT_CONFIDENCE,
123
+ }
124
+ : undefined;
125
+ const configLoadersRaw = raw.env_config?.configLoaders;
126
+ const configLoaders = configLoadersRaw && configLoadersRaw.patternId
127
+ ? {
128
+ patternId: validatePatternId(configLoadersRaw.patternId, "php.env_config.configLoaders.patternId"),
129
+ confidence: configLoadersRaw.confidence ?? DEFAULT_CONFIDENCE,
130
+ loaders: (configLoadersRaw.loaders ?? []).map((loader) => ({
131
+ id: loader.id,
132
+ importNamespaces: normalizeList(loader.importNamespaces),
133
+ packageNames: normalizeList(loader.packageNames),
134
+ callNames: normalizeCallNames(loader.callNames),
135
+ })),
136
+ }
137
+ : undefined;
138
+ const configFileRaw = raw.env_config?.configFile;
139
+ const configFile = configFileRaw && configFileRaw.patternId && configFileRaw.fileNameRegex
140
+ ? {
141
+ patternId: validatePatternId(configFileRaw.patternId, "php.env_config.configFile.patternId"),
142
+ fileNameRegex: compileRegex(configFileRaw.fileNameRegex, "php.env_config.configFile.fileNameRegex"),
143
+ name: configFileRaw.name ?? "php_config",
144
+ confidence: configFileRaw.confidence ?? DEFAULT_CONFIDENCE,
145
+ }
146
+ : undefined;
147
+ const httpClients = raw.external_apis?.httpClients?.map((client) => ({
148
+ id: client.id,
149
+ patternId: validatePatternId(client.patternId, `php.external_apis.httpClients['${client.id}']`),
150
+ clientName: client.clientName,
151
+ importNamespaces: normalizeList(client.importNamespaces),
152
+ packageNames: normalizeList(client.packageNames),
153
+ callNames: normalizeCallNames(client.callNames),
154
+ callNameSuffixes: normalizeCallNames(client.callNameSuffixes),
155
+ urlRegex: compileRegex(client.urlRegex ?? DEFAULT_URL_REGEX, `php.external_apis.httpClients['${client.id}'].urlRegex`),
156
+ confidence: client.confidence ?? DEFAULT_CONFIDENCE,
157
+ emitOnPresence: client.emitOnPresence === true,
158
+ })) ?? [];
159
+ return {
160
+ dbClients,
161
+ pdoDsn,
162
+ auth: { libraries: authLibraries },
163
+ routes: { frameworks: routeFrameworks },
164
+ serverless: { handlers: serverlessHandlers },
165
+ envConfig: { envVariable, configLoaders, configFile },
166
+ externalApis: { httpClients },
167
+ };
168
+ }
169
+ let cachedConfig;
170
+ function clearPhpPatternConfigCache() {
171
+ cachedConfig = undefined;
172
+ }
173
+ function loadPhpPatternConfig() {
174
+ if (cachedConfig)
175
+ return cachedConfig;
176
+ const configPath = getConfigPath();
177
+ let rawYaml;
178
+ try {
179
+ rawYaml = fs_1.default.readFileSync(configPath, "utf8");
180
+ }
181
+ catch (err) {
182
+ const msg = err instanceof Error ? err.message : String(err);
183
+ throw new Error(`PHP pattern config is required but could not be read from '${configPath}': ${msg}`);
184
+ }
185
+ const parsed = yaml_1.default.parse(rawYaml);
186
+ if (!parsed || typeof parsed !== "object") {
187
+ throw new Error(`PHP pattern config at '${configPath}' did not parse to an object.`);
188
+ }
189
+ const normalized = normalizeRawConfig(parsed);
190
+ cachedConfig = normalized;
191
+ return normalized;
192
+ }
@@ -8,6 +8,7 @@ exports.__clearAnalyzersForTest = __clearAnalyzersForTest;
8
8
  const file_system_1 = require("../ingest/file-system");
9
9
  const cpp_1 = require("./cpp");
10
10
  const go_1 = require("./go");
11
+ const php_1 = require("./php");
11
12
  const jvm_1 = require("./jvm");
12
13
  const csharp_1 = require("./csharp");
13
14
  const python_1 = require("./python");
@@ -19,12 +20,14 @@ const typeScriptAnalyzer = (0, typescript_1.createTypeScriptAnalyzer)();
19
20
  const pythonAnalyzer = (0, python_1.createPythonAnalyzer)();
20
21
  const cppAnalyzer = (0, cpp_1.createCppAnalyzer)();
21
22
  const goAnalyzer = (0, go_1.createGoAnalyzer)();
23
+ const phpAnalyzer = (0, php_1.createPhpAnalyzer)();
22
24
  const jvmAnalyzer = (0, jvm_1.createJvmAnalyzer)();
23
25
  const cSharpAnalyzer = (0, csharp_1.createCSharpAnalyzer)();
24
26
  const terraformAnalyzer = (0, terraform_1.createTerraformAnalyzer)();
25
27
  const registry = new Map([
26
28
  ["python", pythonAnalyzer],
27
29
  ["go", goAnalyzer],
30
+ ["php", phpAnalyzer],
28
31
  // Java and Kotlin share one analyzer: same package namespace, same
29
32
  // Maven/Gradle coordinates, same Spring/Jakarta annotations, same JDBC.
30
33
  ["java", jvmAnalyzer],
@@ -125,8 +125,9 @@ function stripCommentsPreservingLayout(source, options = {}) {
125
125
  i = cursor;
126
126
  continue;
127
127
  }
128
- // Python / shell line comment.
129
- if (options.hashComments && ch === "#") {
128
+ // Python / shell / PHP `#` line comment.
129
+ // PHP 8 attributes use `#[...]`; do not treat that as a comment.
130
+ if (options.hashComments && ch === "#" && next !== "[") {
130
131
  let end = i;
131
132
  while (end < length && chars[end] !== "\n")
132
133
  end += 1;
@@ -9,4 +9,10 @@ export declare function getDatabaseCanonicalKey(component: DetectedComponent): s
9
9
  export declare function dedupeComponents(components: DetectedComponent[]): DetectedComponent[];
10
10
  export declare function mergeGlobalIdentityProviderThirdParties(components: DetectedComponent[]): DetectedComponent[];
11
11
  export declare function mergeDatabaseAssetsByType(components: DetectedComponent[]): DetectedComponent[];
12
+ /**
13
+ * Pick where in-app auth middleware should fold when compacting auth_service nodes.
14
+ * Prefer IdP third parties and HTTP API surfaces; never database/storage/config.
15
+ * Returns undefined when no safe target exists (auth_service nodes stay standalone).
16
+ */
17
+ export declare function findAuthCompactionTarget(sectionComponents: DetectedComponent[]): DetectedComponent | undefined;
12
18
  export declare function compactAuthServiceComponents(components: DetectedComponent[]): DetectedComponent[];
@@ -8,6 +8,7 @@ exports.getDatabaseCanonicalKey = getDatabaseCanonicalKey;
8
8
  exports.dedupeComponents = dedupeComponents;
9
9
  exports.mergeGlobalIdentityProviderThirdParties = mergeGlobalIdentityProviderThirdParties;
10
10
  exports.mergeDatabaseAssetsByType = mergeDatabaseAssetsByType;
11
+ exports.findAuthCompactionTarget = findAuthCompactionTarget;
11
12
  exports.compactAuthServiceComponents = compactAuthServiceComponents;
12
13
  const config_1 = require("./config");
13
14
  const naming_1 = require("./naming");
@@ -433,6 +434,65 @@ function isAuthProviderThirdParty(component) {
433
434
  const normalizedName = (component.name || "").trim().toLowerCase();
434
435
  return normalizedService.includes("auth0") || normalizedName.includes("auth0");
435
436
  }
437
+ const AUTH_MERGE_EXCLUDED_SUBTYPES = new Set([
438
+ "database",
439
+ "file_storage",
440
+ "config",
441
+ ]);
442
+ function isBadAuthMergeTarget(component) {
443
+ if (component.type !== "asset")
444
+ return true;
445
+ const subType = component.subType ?? "";
446
+ if (AUTH_MERGE_EXCLUDED_SUBTYPES.has(subType))
447
+ return true;
448
+ if (typeof component.properties?.managed_by_provider === "string")
449
+ return true;
450
+ return false;
451
+ }
452
+ function isMainApplicationAsset(component) {
453
+ return (component.type === "asset" &&
454
+ (component.properties?.isMainApplication === true ||
455
+ component.properties?.isMainApplication === "true"));
456
+ }
457
+ function httpApiAssetRank(component) {
458
+ let score = 0;
459
+ if (component.properties?.isSectionApiNode === true ||
460
+ component.properties?.isSectionApiNode === "true") {
461
+ score += 4;
462
+ }
463
+ if (component.detectedFrom.some((ref) => ref.pattern === "express_route")) {
464
+ score += 2;
465
+ }
466
+ const name = (component.name || "").trim();
467
+ if (name === "API" || name.endsWith(" API"))
468
+ score += 1;
469
+ return score;
470
+ }
471
+ /**
472
+ * Pick where in-app auth middleware should fold when compacting auth_service nodes.
473
+ * Prefer IdP third parties and HTTP API surfaces; never database/storage/config.
474
+ * Returns undefined when no safe target exists (auth_service nodes stay standalone).
475
+ */
476
+ function findAuthCompactionTarget(sectionComponents) {
477
+ const authThirdParty = sectionComponents.find(isAuthProviderThirdParty);
478
+ if (authThirdParty)
479
+ return authThirdParty;
480
+ const mainApp = sectionComponents.find(isMainApplicationAsset);
481
+ if (mainApp && !isBadAuthMergeTarget(mainApp))
482
+ return mainApp;
483
+ const apiCandidates = sectionComponents
484
+ .filter((c) => c.type === "asset" && c.subType === "api" && !isBadAuthMergeTarget(c))
485
+ .sort((a, b) => httpApiAssetRank(b) - httpApiAssetRank(a) ||
486
+ a.name.localeCompare(b.name));
487
+ if (apiCandidates[0])
488
+ return apiCandidates[0];
489
+ const serviceOrApp = sectionComponents.find((c) => c.type === "asset" &&
490
+ (c.subType === "service" || c.subType === "application") &&
491
+ !isBadAuthMergeTarget(c));
492
+ if (serviceOrApp)
493
+ return serviceOrApp;
494
+ return undefined;
495
+ }
436
496
  function mergeAuthServiceIntoTarget(authService, target) {
437
497
  const mergedProperties = {};
438
498
  mergeProperties(mergedProperties, target.properties);
@@ -485,12 +545,7 @@ function compactAuthServiceComponents(components) {
485
545
  !isTerraformScannedResourceAsset(c));
486
546
  if (authServices.length === 0)
487
547
  continue;
488
- const authThirdParty = sectionComponents.find(isAuthProviderThirdParty);
489
- const mainApp = sectionComponents.find((c) => c.type === "asset" &&
490
- (c.properties?.isMainApplication === true ||
491
- c.properties?.isMainApplication === "true"));
492
- const fallbackAsset = sectionComponents.find((c) => c.type === "asset");
493
- const mergeTarget = authThirdParty ?? mainApp ?? fallbackAsset;
548
+ const mergeTarget = findAuthCompactionTarget(sectionComponents);
494
549
  if (!mergeTarget)
495
550
  continue;
496
551
  let nextTarget = replacementById.get(mergeTarget.id) ?? mergeTarget;
package/dist/src/cli.js CHANGED
@@ -40,6 +40,7 @@ exports.run = run;
40
40
  require("./config/load-cli-env");
41
41
  const path_1 = __importDefault(require("path"));
42
42
  const commander_1 = require("commander");
43
+ const crypto_1 = require("crypto");
43
44
  const package_json_1 = __importDefault(require("../package.json"));
44
45
  const json_1 = require("./output/json");
45
46
  const upload_env_1 = require("./config/upload-env");
@@ -50,6 +51,7 @@ const resolve_1 = require("./config/resolve");
50
51
  const scan_env_1 = require("./config/scan-env");
51
52
  const validate_scan_ai_1 = require("./config/validate-scan-ai");
52
53
  const scan_sentry_1 = require("./observability/scan-sentry");
54
+ const telemetry_client_1 = require("./platform-api/telemetry-client");
53
55
  const scan_config_schema_1 = require("./core/schema/scan-config.schema");
54
56
  const file_system_1 = require("./ingest/file-system");
55
57
  function formatEvidence(detail) {
@@ -159,6 +161,15 @@ function createProgram() {
159
161
  const workspaceApiKey = options.workspaceApiKey?.trim() ||
160
162
  options.apiKey?.trim() ||
161
163
  (0, scan_env_1.resolveWorkspaceApiKey)(process.env);
164
+ const usageSessionId = (0, crypto_1.randomUUID)();
165
+ await (0, telemetry_client_1.reportCliUsageEvent)({
166
+ sessionId: usageSessionId,
167
+ event: "scan_started",
168
+ command: "scan",
169
+ hasApiKey: Boolean(workspaceApiKey),
170
+ apiKey: workspaceApiKey,
171
+ cliVersion: package_json_1.default.version,
172
+ });
162
173
  try {
163
174
  const rootPathArg = path || ".";
164
175
  // Load dataparade.config.json from the directory being scanned, not
@@ -438,6 +449,8 @@ function createProgram() {
438
449
  projectName: resolvedProjectName,
439
450
  scanJobId: cliQuotaJobId,
440
451
  logPrefix: "[scan]",
452
+ cliUsageSessionId: usageSessionId,
453
+ command: "scan",
441
454
  });
442
455
  }
443
456
  catch (uploadError) {
@@ -516,6 +529,17 @@ function createProgram() {
516
529
  process.exitCode = 1;
517
530
  }
518
531
  finally {
532
+ const scanFailed = (process.exitCode ?? 0) !== 0;
533
+ await (0, telemetry_client_1.reportCliUsageEvent)({
534
+ sessionId: usageSessionId,
535
+ event: scanFailed ? "scan_failed" : "scan_succeeded",
536
+ command: "scan",
537
+ hasApiKey: Boolean(workspaceApiKey),
538
+ apiKey: workspaceApiKey,
539
+ cliVersion: package_json_1.default.version,
540
+ errorCode: scanFailed ? "scan_failed" : undefined,
541
+ errorMessage: scanFailed ? fallbackFailureMessage : undefined,
542
+ });
519
543
  if (platformQuotaApiKey && cliQuotaJobId && !quotaCompletionReported) {
520
544
  try {
521
545
  const { cliScanComplete } = await Promise.resolve().then(() => __importStar(require("./platform-api/scan-quota-client")));
@@ -548,6 +572,7 @@ function createProgram() {
548
572
  const apiKey = options.workspaceApiKey?.trim() ||
549
573
  options.apiKey?.trim() ||
550
574
  (0, scan_env_1.resolveWorkspaceApiKey)(process.env);
575
+ const usageSessionId = (0, crypto_1.randomUUID)();
551
576
  const filePath = path_1.default.resolve(process.cwd(), file || "dataflow.json");
552
577
  let dataflow;
553
578
  try {
@@ -575,6 +600,8 @@ function createProgram() {
575
600
  apiKey,
576
601
  dataflow,
577
602
  projectName,
603
+ cliUsageSessionId: usageSessionId,
604
+ command: "upload",
578
605
  });
579
606
  }
580
607
  catch (err) {
@@ -18,6 +18,7 @@ const fileLanguageEnum = zod_1.z.enum([
18
18
  "cpp",
19
19
  "csharp",
20
20
  "go",
21
+ "php",
21
22
  "java",
22
23
  "kotlin",
23
24
  "terraform",
@@ -26,6 +26,7 @@ function normalizeLanguages(values) {
26
26
  "cpp",
27
27
  "csharp",
28
28
  "go",
29
+ "php",
29
30
  "java",
30
31
  "kotlin",
31
32
  "terraform",
@@ -67,12 +67,12 @@ function collapseManifestFrontendFrameworkAssets(components) {
67
67
  function runClassifierPhase(findings, sections, options) {
68
68
  const classified = (0, classify_1.classifyRawFindings)(findings);
69
69
  const dedupedComponents = (0, classify_1.dedupeComponents)(classified);
70
- const compactedAuthComponents = (0, classify_1.compactAuthServiceComponents)(dedupedComponents);
71
- const mergedDbComponents = (0, classify_1.mergeDatabaseAssetsByType)(compactedAuthComponents);
70
+ const mergedDbComponents = (0, classify_1.mergeDatabaseAssetsByType)(dedupedComponents);
72
71
  const withPerSectionApplication = (0, classify_1.injectApplicationAssetsPerSectionIfMissing)(mergedDbComponents, sections, { projectName: options.projectName });
73
72
  const withApplication = (0, classify_1.injectApplicationAssetIfMissing)(withPerSectionApplication, { projectName: options.projectName });
74
73
  const enhanced = (0, enhance_1.enhanceComponents)(withApplication);
75
74
  const mergedFrameworkHelpers = collapseManifestFrontendFrameworkAssets(enhanced);
76
75
  const withSectionApiNodes = (0, classify_1.synthesizeSectionApiNodes)(mergedFrameworkHelpers);
77
- return (0, classify_1.injectActorIfMissing)(withSectionApiNodes).filter((component) => component.confidence >= options.minimumConfidence);
76
+ const compactedAuthComponents = (0, classify_1.compactAuthServiceComponents)(withSectionApiNodes);
77
+ return (0, classify_1.injectActorIfMissing)(compactedAuthComponents).filter((component) => component.confidence >= options.minimumConfidence);
78
78
  }
@@ -14,15 +14,17 @@ const terraform_show_json_1 = require("../../analyzers/terraform/terraform-show-
14
14
  const terraform_exec_1 = require("../../analyzers/terraform/terraform-exec");
15
15
  const parser_1 = require("../../analyzers/python/parser");
16
16
  const parser_2 = require("../../analyzers/go/parser");
17
- const parser_3 = require("../../analyzers/jvm/parser");
18
- const parser_4 = require("../../analyzers/cpp/parser");
19
- const parser_5 = require("../../analyzers/csharp/parser");
17
+ const parser_3 = require("../../analyzers/php/parser");
18
+ const parser_4 = require("../../analyzers/jvm/parser");
19
+ const parser_5 = require("../../analyzers/cpp/parser");
20
+ const parser_6 = require("../../analyzers/csharp/parser");
20
21
  const dependency_manifests_1 = require("../../analyzers/python/dependency-manifests");
21
22
  const dependency_manifests_2 = require("../../analyzers/go/dependency-manifests");
22
- const dependency_manifests_3 = require("../../analyzers/jvm/dependency-manifests");
23
- const dependency_manifests_4 = require("../../analyzers/cpp/dependency-manifests");
24
- const dependency_manifests_5 = require("../../analyzers/csharp/dependency-manifests");
25
- const dependency_manifests_6 = require("../../analyzers/typescript/dependency-manifests");
23
+ const dependency_manifests_3 = require("../../analyzers/php/dependency-manifests");
24
+ const dependency_manifests_4 = require("../../analyzers/jvm/dependency-manifests");
25
+ const dependency_manifests_5 = require("../../analyzers/cpp/dependency-manifests");
26
+ const dependency_manifests_6 = require("../../analyzers/csharp/dependency-manifests");
27
+ const dependency_manifests_7 = require("../../analyzers/typescript/dependency-manifests");
26
28
  const discover_service_sections_1 = require("../sectioning/discover-service-sections");
27
29
  const classifier_phase_1 = require("./classifier-phase");
28
30
  const dataflow_phase_1 = require("./dataflow-phase");
@@ -124,10 +126,20 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
124
126
  }, warn);
125
127
  if (goStats)
126
128
  languageStats.push(goStats);
129
+ const phpStats = collectLanguageParserStats(files, "php", (file) => {
130
+ const unit = (0, parser_3.parsePhpSourceFile)(file);
131
+ return {
132
+ functionsIndexed: unit.functions.length,
133
+ callsIndexed: unit.calls.length,
134
+ warnings: unit.warnings,
135
+ };
136
+ }, warn);
137
+ if (phpStats)
138
+ languageStats.push(phpStats);
127
139
  // One parser, reported per language so the stats stay attributable.
128
140
  for (const jvmLanguage of ["java", "kotlin"]) {
129
141
  const jvmStats = collectLanguageParserStats(files, jvmLanguage, (file) => {
130
- const unit = (0, parser_3.parseJvmSourceFile)(file);
142
+ const unit = (0, parser_4.parseJvmSourceFile)(file);
131
143
  return {
132
144
  functionsIndexed: unit.methods.length,
133
145
  callsIndexed: unit.calls.length,
@@ -138,7 +150,7 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
138
150
  languageStats.push(jvmStats);
139
151
  }
140
152
  const cppStats = collectLanguageParserStats(files, "cpp", (file) => {
141
- const unit = (0, parser_4.parseCppTranslationUnit)(file);
153
+ const unit = (0, parser_5.parseCppTranslationUnit)(file);
142
154
  return {
143
155
  functionsIndexed: unit.functions.length,
144
156
  callsIndexed: unit.calls.length,
@@ -148,7 +160,7 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
148
160
  if (cppStats)
149
161
  languageStats.push(cppStats);
150
162
  const cSharpStats = collectLanguageParserStats(files, "csharp", (file) => {
151
- const unit = (0, parser_5.parseCSharpCompilationUnit)(file);
163
+ const unit = (0, parser_6.parseCSharpCompilationUnit)(file);
152
164
  return {
153
165
  functionsIndexed: unit.methods.length,
154
166
  callsIndexed: unit.calls.length,
@@ -240,13 +252,26 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
240
252
  warn(`go-manifests: ${message}`);
241
253
  }
242
254
  }
255
+ // Third-party service and dependency detection from Composer manifests.
256
+ if (!config.languages || config.languages.includes("php")) {
257
+ try {
258
+ findings.push(...(await (0, dependency_manifests_3.detectPhpPatternsFromDependencyManifests)(scanRootDir, {
259
+ onWarning: warn,
260
+ excludePaths: config.excludePaths,
261
+ })));
262
+ }
263
+ catch (err) {
264
+ const message = err instanceof Error ? err.message : "Unknown error parsing manifests.";
265
+ warn(`php-manifests: ${message}`);
266
+ }
267
+ }
243
268
  // Third-party service and dependency detection from JVM build manifests
244
269
  // (Maven / Gradle), plus Spring datasource configuration.
245
270
  if (!config.languages ||
246
271
  config.languages.includes("java") ||
247
272
  config.languages.includes("kotlin")) {
248
273
  try {
249
- findings.push(...(await (0, dependency_manifests_3.detectJvmPatternsFromDependencyManifests)(scanRootDir, {
274
+ findings.push(...(await (0, dependency_manifests_4.detectJvmPatternsFromDependencyManifests)(scanRootDir, {
250
275
  onWarning: warn,
251
276
  excludePaths: config.excludePaths,
252
277
  })));
@@ -260,7 +285,7 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
260
285
  // (vcpkg / Conan / CMake).
261
286
  if (!config.languages || config.languages.includes("cpp")) {
262
287
  try {
263
- findings.push(...(await (0, dependency_manifests_4.detectCppPatternsFromDependencyManifests)(scanRootDir, {
288
+ findings.push(...(await (0, dependency_manifests_5.detectCppPatternsFromDependencyManifests)(scanRootDir, {
264
289
  onWarning: warn,
265
290
  excludePaths: config.excludePaths,
266
291
  })));
@@ -273,7 +298,7 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
273
298
  // .NET project manifests (PackageReference) and appsettings connection strings.
274
299
  if (!config.languages || config.languages.includes("csharp")) {
275
300
  try {
276
- findings.push(...(await (0, dependency_manifests_5.detectDotnetPatternsFromManifests)(scanRootDir, {
301
+ findings.push(...(await (0, dependency_manifests_6.detectDotnetPatternsFromManifests)(scanRootDir, {
277
302
  onWarning: warn,
278
303
  excludePaths: config.excludePaths,
279
304
  })));
@@ -288,7 +313,7 @@ async function runStructuralScanPhase(rootPath, config, onWarning) {
288
313
  config.languages.some((l) => l === "typescript" || l === "javascript");
289
314
  if (wantsTsOrJs) {
290
315
  try {
291
- findings.push(...(await (0, dependency_manifests_6.detectTypeScriptPatternsFromDependencyManifests)(scanRootDir, {
316
+ findings.push(...(await (0, dependency_manifests_7.detectTypeScriptPatternsFromDependencyManifests)(scanRootDir, {
292
317
  onWarning: warn,
293
318
  excludePaths: config.excludePaths,
294
319
  })));
@@ -16,6 +16,7 @@ export declare const scanConfigurationSchema: z.ZodObject<{
16
16
  cpp: "cpp";
17
17
  csharp: "csharp";
18
18
  go: "go";
19
+ php: "php";
19
20
  java: "java";
20
21
  kotlin: "kotlin";
21
22
  terraform: "terraform";