@dataparade/cli 0.0.22 → 0.0.24

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -0,0 +1,34 @@
1
+ /**
2
+ * NestJS `services/*.service.ts` classes and bare HTTP clients (Axios, HttpClient)
3
+ * are implementation details. Directus collection services (`extends ItemsService`)
4
+ * and calls that name a real third party stay on the diagram.
5
+ */
6
+ export interface OmittableLocation {
7
+ filePath: string;
8
+ code?: string;
9
+ startLine?: number;
10
+ }
11
+ export interface OmittableComponent {
12
+ id: string;
13
+ name: string;
14
+ type: string;
15
+ subType?: string;
16
+ detectedFrom?: Array<{
17
+ pattern: string;
18
+ sourceLocation?: OmittableLocation;
19
+ }>;
20
+ sourceLocations?: OmittableLocation[];
21
+ properties?: Record<string, unknown>;
22
+ }
23
+ export interface OmittableFlow {
24
+ sourceComponentId: string;
25
+ targetComponentId: string;
26
+ type: string;
27
+ }
28
+ export interface OmitInternalImplementationOptions {
29
+ readSource?: (filePath: string) => string | undefined;
30
+ }
31
+ export declare function omitInternalImplementationNodes<C extends OmittableComponent, F extends OmittableFlow>(components: C[], flows: F[], options?: OmitInternalImplementationOptions): {
32
+ components: C[];
33
+ dataFlows: F[];
34
+ };
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ /**
3
+ * NestJS `services/*.service.ts` classes and bare HTTP clients (Axios, HttpClient)
4
+ * are implementation details. Directus collection services (`extends ItemsService`)
5
+ * and calls that name a real third party stay on the diagram.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.omitInternalImplementationNodes = omitInternalImplementationNodes;
9
+ const HTTP_TRANSPORT_NAMES = new Set([
10
+ 'axios',
11
+ 'fetch',
12
+ 'got',
13
+ 'ky',
14
+ 'httpclient',
15
+ 'httpclientfactory',
16
+ 'restsharp',
17
+ 'flurl',
18
+ 'undici',
19
+ 'nodefetch',
20
+ 'crossfetch',
21
+ ]);
22
+ function compactName(value) {
23
+ return value
24
+ .trim()
25
+ .toLowerCase()
26
+ .replace(/[\s_-]+/g, '');
27
+ }
28
+ function isMainApplication(component) {
29
+ const flag = component.properties?.isMainApplication;
30
+ return flag === true || flag === 'true';
31
+ }
32
+ function sectionId(component) {
33
+ const raw = component.properties?.section_id;
34
+ return typeof raw === 'string' ? raw.trim() : '';
35
+ }
36
+ function serviceFileLocations(component) {
37
+ return (component.sourceLocations ?? []).filter((location) => /(?:^|\/)services\/.+\.tsx?$/i.test(location.filePath.replace(/\\/g, '/')));
38
+ }
39
+ function declarationWindow(source, startLine) {
40
+ const lines = source.split(/\r?\n/);
41
+ const start = Math.max(0, (startLine ?? 1) - 1);
42
+ return lines.slice(start, start + 4).join('\n');
43
+ }
44
+ function isDirectusItemsService(component, readSource) {
45
+ for (const location of serviceFileLocations(component)) {
46
+ const fromSnippet = location.code ?? '';
47
+ if (/extends\s+(?:\w+\.)?ItemsService\b/.test(fromSnippet))
48
+ return true;
49
+ const source = readSource(location.filePath);
50
+ if (!source)
51
+ continue;
52
+ if (/extends\s+(?:\w+\.)?ItemsService\b/.test(declarationWindow(source, location.startLine))) {
53
+ return true;
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+ function isNestServiceClassNode(component, readSource) {
59
+ if (component.type !== 'asset' || component.subType !== 'service')
60
+ return false;
61
+ const locations = serviceFileLocations(component);
62
+ if (locations.length === 0)
63
+ return false;
64
+ const patterns = (component.detectedFrom ?? []).map((ref) => ref.pattern);
65
+ if (patterns.length === 0 ||
66
+ patterns.some((pattern) => pattern !== 'auth_middleware')) {
67
+ return false;
68
+ }
69
+ if (isDirectusItemsService(component, readSource))
70
+ return false;
71
+ for (const location of locations) {
72
+ const snippet = location.code ?? '';
73
+ if (/export\s+class\s+\w+Service\b/.test(snippet))
74
+ return true;
75
+ const source = readSource(location.filePath);
76
+ if (!source)
77
+ continue;
78
+ if (/export\s+class\s+\w+Service\b/.test(declarationWindow(source, location.startLine))) {
79
+ return true;
80
+ }
81
+ }
82
+ return false;
83
+ }
84
+ function stringProp(component, key) {
85
+ const value = component.properties?.[key];
86
+ return typeof value === 'string' ? value : '';
87
+ }
88
+ function hasPublicUrl(component) {
89
+ const url = stringProp(component, 'url') ||
90
+ (/^https?:\/\//i.test(component.name) ? component.name : '');
91
+ if (!/^https?:\/\//i.test(url))
92
+ return false;
93
+ if (/\$\{|process\.env|localhost|127\.0\.0\.1/i.test(url))
94
+ return false;
95
+ return true;
96
+ }
97
+ function isBareHttpTransportNode(component) {
98
+ if (component.properties?.sourceContext === 'dependency_manifest')
99
+ return false;
100
+ if (hasPublicUrl(component))
101
+ return false;
102
+ const serviceName = compactName(stringProp(component, 'serviceName'));
103
+ if (serviceName && !HTTP_TRANSPORT_NAMES.has(serviceName))
104
+ return false;
105
+ const client = compactName(stringProp(component, 'client'));
106
+ const fromName = compactName(component.name).replace(/call$/, '');
107
+ const namedAsClientCall = /\bcall$/i.test(component.name.trim()) &&
108
+ HTTP_TRANSPORT_NAMES.has(fromName);
109
+ return (HTTP_TRANSPORT_NAMES.has(client) ||
110
+ HTTP_TRANSPORT_NAMES.has(serviceName) ||
111
+ namedAsClientCall);
112
+ }
113
+ function hubIdFor(components, dropped, dropIds) {
114
+ const hubs = components.filter((component) => isMainApplication(component) && !dropIds.has(component.id));
115
+ const section = sectionId(dropped);
116
+ const sameSection = hubs.find((hub) => sectionId(hub) === section);
117
+ return (sameSection ?? hubs[0])?.id;
118
+ }
119
+ function omitInternalImplementationNodes(components, flows, options = {}) {
120
+ const readSource = options.readSource ?? (() => undefined);
121
+ const dropIds = new Set(components
122
+ .filter((component) => !isMainApplication(component) &&
123
+ (isNestServiceClassNode(component, readSource) ||
124
+ isBareHttpTransportNode(component)))
125
+ .map((component) => component.id));
126
+ if (dropIds.size === 0) {
127
+ return { components, dataFlows: flows };
128
+ }
129
+ const kept = components.filter((component) => !dropIds.has(component.id));
130
+ const seen = new Set();
131
+ const dataFlows = [];
132
+ for (const flow of flows) {
133
+ if (dropIds.has(flow.targetComponentId))
134
+ continue;
135
+ let sourceId = flow.sourceComponentId;
136
+ if (dropIds.has(sourceId)) {
137
+ const dropped = components.find((component) => component.id === sourceId);
138
+ const hub = dropped ? hubIdFor(components, dropped, dropIds) : undefined;
139
+ if (!hub || hub === flow.targetComponentId)
140
+ continue;
141
+ sourceId = hub;
142
+ }
143
+ const key = `${sourceId}\t${flow.targetComponentId}\t${flow.type}`;
144
+ if (seen.has(key))
145
+ continue;
146
+ seen.add(key);
147
+ dataFlows.push(sourceId === flow.sourceComponentId
148
+ ? flow
149
+ : { ...flow, sourceComponentId: sourceId });
150
+ }
151
+ return { components: kept, dataFlows };
152
+ }
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.runScanPipeline = runScanPipeline;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
4
9
  const ai_orchestrator_options_1 = require("./ai-orchestrator-options");
10
+ const omit_internal_implementation_1 = require("./omit-internal-implementation");
5
11
  const scanner_1 = require("@dataparade/scanner");
6
12
  const pipeline_1 = require("../../ai-enrichment/pipeline");
7
13
  const fallbacks_1 = require("../../ai-enrichment/fallbacks");
@@ -267,6 +273,21 @@ async function runScanPipelineInner(rootPath, config, onProgress, onRecognition)
267
273
  const fallbackResult = (0, fallbacks_1.applyDeterministicInferenceFallbacks)(components, dataFlows);
268
274
  components.splice(0, components.length, ...fallbackResult.components);
269
275
  let finalizedFlows = fallbackResult.dataFlows;
276
+ const omitted = (0, omit_internal_implementation_1.omitInternalImplementationNodes)(components, finalizedFlows, {
277
+ readSource: (filePath) => {
278
+ const absolute = path_1.default.isAbsolute(filePath)
279
+ ? filePath
280
+ : path_1.default.join(rootPath, filePath);
281
+ try {
282
+ return fs_1.default.readFileSync(absolute, 'utf8');
283
+ }
284
+ catch {
285
+ return undefined;
286
+ }
287
+ },
288
+ });
289
+ components.splice(0, components.length, ...omitted.components);
290
+ finalizedFlows = omitted.dataFlows;
270
291
  const redFlagPass = (0, red_flags_1.applyConnectivityRedFlagPass)(components, finalizedFlows);
271
292
  components.splice(0, components.length, ...redFlagPass.components);
272
293
  finalizedFlows = redFlagPass.dataFlows;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const omit_internal_implementation_1 = require("../../../src/core/pipeline/omit-internal-implementation");
4
+ const nestSource = `
5
+ import { Injectable } from "@nestjs/common";
6
+
7
+ @Injectable()
8
+ export class AssetContextService {
9
+ findAll() {}
10
+ }
11
+ `;
12
+ const directusSource = `
13
+ export class UsersService extends ItemsService {
14
+ constructor() {
15
+ super("directus_users", {});
16
+ }
17
+ }
18
+ `;
19
+ describe('omitInternalImplementationNodes', () => {
20
+ const readSource = (filePath) => {
21
+ if (filePath.endsWith('asset-context.service.ts'))
22
+ return nestSource;
23
+ if (filePath.endsWith('users.ts'))
24
+ return directusSource;
25
+ return undefined;
26
+ };
27
+ it('drops NestJS service classes and bare HTTP clients, and keeps named services', () => {
28
+ const result = (0, omit_internal_implementation_1.omitInternalImplementationNodes)([
29
+ {
30
+ id: 'hub',
31
+ name: 'backend',
32
+ type: 'asset',
33
+ subType: 'application',
34
+ properties: { isMainApplication: true, section_id: 'backend' },
35
+ },
36
+ {
37
+ id: 'asset-context',
38
+ name: 'Assetcontext',
39
+ type: 'asset',
40
+ subType: 'service',
41
+ detectedFrom: [{ pattern: 'auth_middleware' }],
42
+ sourceLocations: [
43
+ {
44
+ filePath: 'backend/src/diagrams/services/asset-context.service.ts',
45
+ startLine: 5,
46
+ },
47
+ ],
48
+ properties: { section_id: 'backend' },
49
+ },
50
+ {
51
+ id: 'users',
52
+ name: 'Users',
53
+ type: 'asset',
54
+ subType: 'service',
55
+ detectedFrom: [{ pattern: 'auth_middleware' }],
56
+ sourceLocations: [
57
+ { filePath: 'api/src/services/users.ts', startLine: 2 },
58
+ ],
59
+ properties: { section_id: 'backend' },
60
+ },
61
+ {
62
+ id: 'axios',
63
+ name: 'Axios Call',
64
+ type: 'asset',
65
+ subType: 'api',
66
+ properties: { client: 'axios', section_id: 'backend' },
67
+ },
68
+ {
69
+ id: 'sendgrid',
70
+ name: 'Sendgrid',
71
+ type: 'third_party',
72
+ properties: {
73
+ serviceName: 'sendgrid',
74
+ client: 'axios',
75
+ section_id: 'backend',
76
+ },
77
+ },
78
+ ], [
79
+ {
80
+ id: 'flow-service',
81
+ sourceComponentId: 'hub',
82
+ targetComponentId: 'asset-context',
83
+ type: 'api_call',
84
+ },
85
+ {
86
+ id: 'flow-users',
87
+ sourceComponentId: 'hub',
88
+ targetComponentId: 'users',
89
+ type: 'api_call',
90
+ },
91
+ {
92
+ id: 'flow-axios',
93
+ sourceComponentId: 'hub',
94
+ targetComponentId: 'axios',
95
+ type: 'api_call',
96
+ },
97
+ {
98
+ id: 'flow-sendgrid',
99
+ sourceComponentId: 'axios',
100
+ targetComponentId: 'sendgrid',
101
+ type: 'api_call',
102
+ },
103
+ ], { readSource });
104
+ expect(result.components.map((component) => component.name).sort()).toEqual(['Sendgrid', 'Users', 'backend']);
105
+ expect(result.dataFlows.map((flow) => [
106
+ flow.sourceComponentId,
107
+ flow.targetComponentId,
108
+ ])).toEqual([
109
+ ['hub', 'users'],
110
+ ['hub', 'sendgrid'],
111
+ ]);
112
+ });
113
+ it('keeps section hubs that were promoted from a service class or an HTTP call', () => {
114
+ const result = (0, omit_internal_implementation_1.omitInternalImplementationNodes)([
115
+ {
116
+ id: 'backend',
117
+ name: 'backend',
118
+ type: 'asset',
119
+ subType: 'service',
120
+ detectedFrom: [{ pattern: 'auth_middleware' }],
121
+ sourceLocations: [
122
+ {
123
+ filePath: 'backend/src/diagrams/services/asset-context.service.ts',
124
+ startLine: 5,
125
+ },
126
+ ],
127
+ properties: { isMainApplication: true, section_id: 'backend' },
128
+ },
129
+ {
130
+ id: 'lambdas',
131
+ name: 'lambdas',
132
+ type: 'asset',
133
+ subType: 'api',
134
+ properties: {
135
+ isMainApplication: 'true',
136
+ client: 'axios',
137
+ section_id: 'backend/lambdas',
138
+ },
139
+ },
140
+ {
141
+ id: 'customer',
142
+ name: 'Customer',
143
+ type: 'actor',
144
+ properties: { section_id: 'backend' },
145
+ },
146
+ ], [
147
+ {
148
+ sourceComponentId: 'customer',
149
+ targetComponentId: 'backend',
150
+ type: 'user_interaction',
151
+ },
152
+ ], { readSource });
153
+ expect(result.components.map((component) => component.id)).toEqual([
154
+ 'backend',
155
+ 'lambdas',
156
+ 'customer',
157
+ ]);
158
+ expect(result.dataFlows).toHaveLength(1);
159
+ });
160
+ it('keeps a service class when its source file cannot be read', () => {
161
+ const result = (0, omit_internal_implementation_1.omitInternalImplementationNodes)([
162
+ {
163
+ id: 'svc',
164
+ name: 'Assetcontext',
165
+ type: 'asset',
166
+ subType: 'service',
167
+ detectedFrom: [{ pattern: 'auth_middleware' }],
168
+ sourceLocations: [
169
+ { filePath: 'src/services/asset-context.service.ts', startLine: 1 },
170
+ ],
171
+ },
172
+ ], [], { readSource: () => undefined });
173
+ expect(result.components).toHaveLength(1);
174
+ });
175
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",