guardrail-security 1.0.2 → 2.0.0

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 (60) hide show
  1. package/dist/sbom/generator.d.ts +42 -0
  2. package/dist/sbom/generator.d.ts.map +1 -1
  3. package/dist/sbom/generator.js +168 -7
  4. package/dist/secrets/allowlist.d.ts +38 -0
  5. package/dist/secrets/allowlist.d.ts.map +1 -0
  6. package/dist/secrets/allowlist.js +131 -0
  7. package/dist/secrets/config-loader.d.ts +25 -0
  8. package/dist/secrets/config-loader.d.ts.map +1 -0
  9. package/dist/secrets/config-loader.js +103 -0
  10. package/dist/secrets/contextual-risk.d.ts +19 -0
  11. package/dist/secrets/contextual-risk.d.ts.map +1 -0
  12. package/dist/secrets/contextual-risk.js +88 -0
  13. package/dist/secrets/git-scanner.d.ts +29 -0
  14. package/dist/secrets/git-scanner.d.ts.map +1 -0
  15. package/dist/secrets/git-scanner.js +109 -0
  16. package/dist/secrets/guardian.d.ts +70 -57
  17. package/dist/secrets/guardian.d.ts.map +1 -1
  18. package/dist/secrets/guardian.js +531 -258
  19. package/dist/secrets/index.d.ts +4 -0
  20. package/dist/secrets/index.d.ts.map +1 -1
  21. package/dist/secrets/index.js +11 -1
  22. package/dist/secrets/patterns.d.ts +39 -10
  23. package/dist/secrets/patterns.d.ts.map +1 -1
  24. package/dist/secrets/patterns.js +129 -71
  25. package/dist/secrets/pre-commit.d.ts.map +1 -1
  26. package/dist/secrets/pre-commit.js +1 -1
  27. package/dist/secrets/vault-integration.d.ts.map +1 -1
  28. package/dist/secrets/vault-integration.js +1 -0
  29. package/dist/supply-chain/vulnerability-db.d.ts +89 -16
  30. package/dist/supply-chain/vulnerability-db.d.ts.map +1 -1
  31. package/dist/supply-chain/vulnerability-db.js +404 -115
  32. package/dist/utils/semver.d.ts +37 -0
  33. package/dist/utils/semver.d.ts.map +1 -0
  34. package/dist/utils/semver.js +109 -0
  35. package/package.json +17 -3
  36. package/src/__tests__/license/engine.test.ts +0 -250
  37. package/src/__tests__/supply-chain/typosquat.test.ts +0 -191
  38. package/src/attack-surface/analyzer.ts +0 -153
  39. package/src/attack-surface/index.ts +0 -5
  40. package/src/index.ts +0 -21
  41. package/src/languages/index.ts +0 -91
  42. package/src/languages/java-analyzer.ts +0 -490
  43. package/src/languages/python-analyzer.ts +0 -498
  44. package/src/license/compatibility-matrix.ts +0 -366
  45. package/src/license/engine.ts +0 -346
  46. package/src/license/index.ts +0 -6
  47. package/src/sbom/generator.ts +0 -355
  48. package/src/sbom/index.ts +0 -5
  49. package/src/secrets/guardian.ts +0 -468
  50. package/src/secrets/index.ts +0 -10
  51. package/src/secrets/patterns.ts +0 -186
  52. package/src/secrets/pre-commit.ts +0 -158
  53. package/src/secrets/vault-integration.ts +0 -360
  54. package/src/secrets/vault-providers.ts +0 -446
  55. package/src/supply-chain/detector.ts +0 -253
  56. package/src/supply-chain/index.ts +0 -11
  57. package/src/supply-chain/malicious-db.ts +0 -103
  58. package/src/supply-chain/script-analyzer.ts +0 -194
  59. package/src/supply-chain/typosquat.ts +0 -302
  60. package/src/supply-chain/vulnerability-db.ts +0 -386
@@ -1,366 +0,0 @@
1
- /**
2
- * License Compatibility Matrix
3
- *
4
- * Defines which licenses are compatible with each other
5
- */
6
-
7
- export type LicenseType =
8
- | "MIT"
9
- | "Apache-2.0"
10
- | "BSD-2-Clause"
11
- | "BSD-3-Clause"
12
- | "ISC"
13
- | "GPL-2.0"
14
- | "GPL-3.0"
15
- | "LGPL-2.1"
16
- | "LGPL-3.0"
17
- | "AGPL-3.0"
18
- | "MPL-2.0"
19
- | "CDDL-1.0"
20
- | "EPL-2.0"
21
- | "Unlicense"
22
- | "CC0-1.0"
23
- | "Proprietary"
24
- | "Unknown";
25
-
26
- export type LicenseCategory =
27
- | "permissive"
28
- | "weak_copyleft"
29
- | "strong_copyleft"
30
- | "public_domain"
31
- | "proprietary";
32
-
33
- export interface LicenseInfo {
34
- name: string;
35
- category: LicenseCategory;
36
- requiresAttribution: boolean;
37
- requiresSourceDisclosure: boolean;
38
- requiresSameLicense: boolean;
39
- allowsCommercialUse: boolean;
40
- allowsModification: boolean;
41
- allowsDistribution: boolean;
42
- patentGrant: boolean;
43
- }
44
-
45
- /**
46
- * License metadata
47
- */
48
- export const LICENSE_INFO: Record<LicenseType, LicenseInfo> = {
49
- MIT: {
50
- name: "MIT License",
51
- category: "permissive",
52
- requiresAttribution: true,
53
- requiresSourceDisclosure: false,
54
- requiresSameLicense: false,
55
- allowsCommercialUse: true,
56
- allowsModification: true,
57
- allowsDistribution: true,
58
- patentGrant: false,
59
- },
60
- "Apache-2.0": {
61
- name: "Apache License 2.0",
62
- category: "permissive",
63
- requiresAttribution: true,
64
- requiresSourceDisclosure: false,
65
- requiresSameLicense: false,
66
- allowsCommercialUse: true,
67
- allowsModification: true,
68
- allowsDistribution: true,
69
- patentGrant: true,
70
- },
71
- "BSD-2-Clause": {
72
- name: "BSD 2-Clause License",
73
- category: "permissive",
74
- requiresAttribution: true,
75
- requiresSourceDisclosure: false,
76
- requiresSameLicense: false,
77
- allowsCommercialUse: true,
78
- allowsModification: true,
79
- allowsDistribution: true,
80
- patentGrant: false,
81
- },
82
- "BSD-3-Clause": {
83
- name: "BSD 3-Clause License",
84
- category: "permissive",
85
- requiresAttribution: true,
86
- requiresSourceDisclosure: false,
87
- requiresSameLicense: false,
88
- allowsCommercialUse: true,
89
- allowsModification: true,
90
- allowsDistribution: true,
91
- patentGrant: false,
92
- },
93
- ISC: {
94
- name: "ISC License",
95
- category: "permissive",
96
- requiresAttribution: true,
97
- requiresSourceDisclosure: false,
98
- requiresSameLicense: false,
99
- allowsCommercialUse: true,
100
- allowsModification: true,
101
- allowsDistribution: true,
102
- patentGrant: false,
103
- },
104
- "GPL-2.0": {
105
- name: "GNU General Public License v2.0",
106
- category: "strong_copyleft",
107
- requiresAttribution: true,
108
- requiresSourceDisclosure: true,
109
- requiresSameLicense: true,
110
- allowsCommercialUse: true,
111
- allowsModification: true,
112
- allowsDistribution: true,
113
- patentGrant: false,
114
- },
115
- "GPL-3.0": {
116
- name: "GNU General Public License v3.0",
117
- category: "strong_copyleft",
118
- requiresAttribution: true,
119
- requiresSourceDisclosure: true,
120
- requiresSameLicense: true,
121
- allowsCommercialUse: true,
122
- allowsModification: true,
123
- allowsDistribution: true,
124
- patentGrant: true,
125
- },
126
- "LGPL-2.1": {
127
- name: "GNU Lesser General Public License v2.1",
128
- category: "weak_copyleft",
129
- requiresAttribution: true,
130
- requiresSourceDisclosure: true,
131
- requiresSameLicense: false,
132
- allowsCommercialUse: true,
133
- allowsModification: true,
134
- allowsDistribution: true,
135
- patentGrant: false,
136
- },
137
- "LGPL-3.0": {
138
- name: "GNU Lesser General Public License v3.0",
139
- category: "weak_copyleft",
140
- requiresAttribution: true,
141
- requiresSourceDisclosure: true,
142
- requiresSameLicense: false,
143
- allowsCommercialUse: true,
144
- allowsModification: true,
145
- allowsDistribution: true,
146
- patentGrant: true,
147
- },
148
- "AGPL-3.0": {
149
- name: "GNU Affero General Public License v3.0",
150
- category: "strong_copyleft",
151
- requiresAttribution: true,
152
- requiresSourceDisclosure: true,
153
- requiresSameLicense: true,
154
- allowsCommercialUse: true,
155
- allowsModification: true,
156
- allowsDistribution: true,
157
- patentGrant: true,
158
- },
159
- "MPL-2.0": {
160
- name: "Mozilla Public License 2.0",
161
- category: "weak_copyleft",
162
- requiresAttribution: true,
163
- requiresSourceDisclosure: true,
164
- requiresSameLicense: false,
165
- allowsCommercialUse: true,
166
- allowsModification: true,
167
- allowsDistribution: true,
168
- patentGrant: true,
169
- },
170
- "CDDL-1.0": {
171
- name: "Common Development and Distribution License 1.0",
172
- category: "weak_copyleft",
173
- requiresAttribution: true,
174
- requiresSourceDisclosure: true,
175
- requiresSameLicense: false,
176
- allowsCommercialUse: true,
177
- allowsModification: true,
178
- allowsDistribution: true,
179
- patentGrant: true,
180
- },
181
- "EPL-2.0": {
182
- name: "Eclipse Public License 2.0",
183
- category: "weak_copyleft",
184
- requiresAttribution: true,
185
- requiresSourceDisclosure: true,
186
- requiresSameLicense: false,
187
- allowsCommercialUse: true,
188
- allowsModification: true,
189
- allowsDistribution: true,
190
- patentGrant: true,
191
- },
192
- Unlicense: {
193
- name: "The Unlicense",
194
- category: "public_domain",
195
- requiresAttribution: false,
196
- requiresSourceDisclosure: false,
197
- requiresSameLicense: false,
198
- allowsCommercialUse: true,
199
- allowsModification: true,
200
- allowsDistribution: true,
201
- patentGrant: false,
202
- },
203
- "CC0-1.0": {
204
- name: "Creative Commons Zero v1.0 Universal",
205
- category: "public_domain",
206
- requiresAttribution: false,
207
- requiresSourceDisclosure: false,
208
- requiresSameLicense: false,
209
- allowsCommercialUse: true,
210
- allowsModification: true,
211
- allowsDistribution: true,
212
- patentGrant: false,
213
- },
214
- Proprietary: {
215
- name: "Proprietary License",
216
- category: "proprietary",
217
- requiresAttribution: false,
218
- requiresSourceDisclosure: false,
219
- requiresSameLicense: false,
220
- allowsCommercialUse: false,
221
- allowsModification: false,
222
- allowsDistribution: false,
223
- patentGrant: false,
224
- },
225
- Unknown: {
226
- name: "Unknown License",
227
- category: "proprietary",
228
- requiresAttribution: false,
229
- requiresSourceDisclosure: false,
230
- requiresSameLicense: false,
231
- allowsCommercialUse: false,
232
- allowsModification: false,
233
- allowsDistribution: false,
234
- patentGrant: false,
235
- },
236
- };
237
-
238
- /**
239
- * Compatibility matrix
240
- * true = compatible, false = incompatible
241
- */
242
- export const COMPATIBILITY_MATRIX: Record<
243
- LicenseType,
244
- Record<LicenseType, boolean>
245
- > = {
246
- MIT: {
247
- MIT: true,
248
- "Apache-2.0": true,
249
- "BSD-2-Clause": true,
250
- "BSD-3-Clause": true,
251
- ISC: true,
252
- "GPL-2.0": true,
253
- "GPL-3.0": true,
254
- "LGPL-2.1": true,
255
- "LGPL-3.0": true,
256
- "AGPL-3.0": true,
257
- "MPL-2.0": true,
258
- "CDDL-1.0": true,
259
- "EPL-2.0": true,
260
- Unlicense: true,
261
- "CC0-1.0": true,
262
- Proprietary: false,
263
- Unknown: false,
264
- },
265
- "Apache-2.0": {
266
- MIT: true,
267
- "Apache-2.0": true,
268
- "BSD-2-Clause": true,
269
- "BSD-3-Clause": true,
270
- ISC: true,
271
- "GPL-2.0": false, // Apache 2.0 incompatible with GPL 2.0
272
- "GPL-3.0": true,
273
- "LGPL-2.1": true,
274
- "LGPL-3.0": true,
275
- "AGPL-3.0": true,
276
- "MPL-2.0": true,
277
- "CDDL-1.0": true,
278
- "EPL-2.0": true,
279
- Unlicense: true,
280
- "CC0-1.0": true,
281
- Proprietary: false,
282
- Unknown: false,
283
- },
284
- "GPL-3.0": {
285
- MIT: true,
286
- "Apache-2.0": true,
287
- "BSD-2-Clause": true,
288
- "BSD-3-Clause": true,
289
- ISC: true,
290
- "GPL-2.0": false, // GPL 3.0 incompatible with GPL 2.0
291
- "GPL-3.0": true,
292
- "LGPL-2.1": true,
293
- "LGPL-3.0": true,
294
- "AGPL-3.0": true,
295
- "MPL-2.0": false, // Incompatible
296
- "CDDL-1.0": false, // Incompatible
297
- "EPL-2.0": false, // Incompatible
298
- Unlicense: true,
299
- "CC0-1.0": true,
300
- Proprietary: false,
301
- Unknown: false,
302
- },
303
- Proprietary: {
304
- MIT: false,
305
- "Apache-2.0": false,
306
- "BSD-2-Clause": false,
307
- "BSD-3-Clause": false,
308
- ISC: false,
309
- "GPL-2.0": false,
310
- "GPL-3.0": false,
311
- "LGPL-2.1": false,
312
- "LGPL-3.0": false,
313
- "AGPL-3.0": false,
314
- "MPL-2.0": false,
315
- "CDDL-1.0": false,
316
- "EPL-2.0": false,
317
- Unlicense: false,
318
- "CC0-1.0": false,
319
- Proprietary: true,
320
- Unknown: false,
321
- },
322
- Unknown: {
323
- MIT: false,
324
- "Apache-2.0": false,
325
- "BSD-2-Clause": false,
326
- "BSD-3-Clause": false,
327
- ISC: false,
328
- "GPL-2.0": false,
329
- "GPL-3.0": false,
330
- "LGPL-2.1": false,
331
- "LGPL-3.0": false,
332
- "AGPL-3.0": false,
333
- "MPL-2.0": false,
334
- "CDDL-1.0": false,
335
- "EPL-2.0": false,
336
- Unlicense: false,
337
- "CC0-1.0": false,
338
- Proprietary: false,
339
- Unknown: true,
340
- },
341
- // ... other licenses would follow the same pattern
342
- // For brevity, I'll set defaults for remaining licenses
343
- } as any;
344
-
345
- // Fill in remaining licenses with permissive defaults
346
- for (const license of Object.keys(LICENSE_INFO) as LicenseType[]) {
347
- if (!COMPATIBILITY_MATRIX[license]) {
348
- COMPATIBILITY_MATRIX[license] = {} as any;
349
- }
350
- for (const otherLicense of Object.keys(LICENSE_INFO) as LicenseType[]) {
351
- if (COMPATIBILITY_MATRIX[license][otherLicense] === undefined) {
352
- // Default: permissive with permissive = true, others case by case
353
- const licenseInfo = LICENSE_INFO[license];
354
- const otherInfo = LICENSE_INFO[otherLicense];
355
-
356
- if (
357
- licenseInfo.category === "permissive" &&
358
- otherInfo.category === "permissive"
359
- ) {
360
- COMPATIBILITY_MATRIX[license][otherLicense] = true;
361
- } else {
362
- COMPATIBILITY_MATRIX[license][otherLicense] = license === otherLicense;
363
- }
364
- }
365
- }
366
- }
@@ -1,346 +0,0 @@
1
- // Stub prisma for standalone use
2
- const prisma: any = null;
3
- import { LICENSE_INFO, COMPATIBILITY_MATRIX, LicenseType } from './compatibility-matrix';
4
- import { readFileSync, existsSync } from 'fs';
5
- import { join } from 'path';
6
-
7
- /**
8
- * License cache to avoid repeated API calls
9
- */
10
- const licenseCache = new Map<string, { license: string; category: string; fetchedAt: Date }>();
11
- const CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
12
-
13
- export interface LicensedDependency {
14
- name: string;
15
- version: string;
16
- license: string;
17
- category: string;
18
- }
19
-
20
- export interface LicenseConflict {
21
- dependency: string;
22
- dependencyLicense: string;
23
- projectLicense: string;
24
- reason: string;
25
- severity: 'warning' | 'error';
26
- }
27
-
28
- export interface LicenseAnalysisResult {
29
- projectId: string;
30
- projectLicense: string;
31
- summary: {
32
- totalDeps: number;
33
- categories: Record<string, number>;
34
- conflicts: number;
35
- };
36
- dependencies: LicensedDependency[];
37
- conflicts: LicenseConflict[];
38
- aiAttribution: AICodeAttribution[];
39
- overallStatus: 'compliant' | 'warning' | 'violation';
40
- }
41
-
42
- export interface AICodeAttribution {
43
- file: string;
44
- generator: string; // 'copilot', 'chatgpt', 'claude', etc.
45
- percentage: number;
46
- requiresAttribution: boolean;
47
- }
48
-
49
- export interface CompatibilityResult {
50
- compatible: boolean;
51
- reason: string;
52
- }
53
-
54
- export class LicenseComplianceEngine {
55
- async analyzeProject(projectPath: string, projectId: string, projectLicense: string): Promise<LicenseAnalysisResult> {
56
- const dependencies = await this.extractDependencies(projectPath);
57
- const conflicts = this.detectGPLContamination(dependencies, projectLicense);
58
- const aiAttribution = await this.analyzeAICodeAttribution(projectPath);
59
-
60
- const categories: Record<string, number> = {};
61
- for (const dep of dependencies) {
62
- categories[dep.category] = (categories[dep.category] || 0) + 1;
63
- }
64
-
65
- const overallStatus: 'compliant' | 'warning' | 'violation' =
66
- conflicts.some(c => c.severity === 'error') ? 'violation' :
67
- conflicts.length > 0 ? 'warning' : 'compliant';
68
-
69
- const result: LicenseAnalysisResult = {
70
- projectId,
71
- projectLicense,
72
- summary: {
73
- totalDeps: dependencies.length,
74
- categories,
75
- conflicts: conflicts.length,
76
- },
77
- dependencies,
78
- conflicts,
79
- aiAttribution,
80
- overallStatus,
81
- };
82
-
83
- // @ts-ignore - licenseAnalysis may not exist in schema yet
84
- const analysis = await prisma.licenseAnalysis.findUnique({
85
- where: { id: projectId }
86
- });
87
-
88
- return result;
89
- }
90
-
91
- private async extractDependencies(projectPath: string): Promise<LicensedDependency[]> {
92
- try {
93
- const packageJsonPath = join(projectPath, 'package.json');
94
- if (!existsSync(packageJsonPath)) {
95
- return [];
96
- }
97
-
98
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
99
- const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
100
- const entries = Object.entries(deps);
101
-
102
- // Fetch licenses in parallel with concurrency limit
103
- const results: LicensedDependency[] = [];
104
- const batchSize = 10;
105
-
106
- for (let i = 0; i < entries.length; i += batchSize) {
107
- const batch = entries.slice(i, i + batchSize);
108
- const batchResults = await Promise.all(
109
- batch.map(async ([name, version]) => {
110
- const licenseInfo = await this.fetchLicenseFromRegistry(name);
111
- return {
112
- name,
113
- version: version as string,
114
- license: licenseInfo.license,
115
- category: licenseInfo.category,
116
- };
117
- })
118
- );
119
- results.push(...batchResults);
120
- }
121
-
122
- return results;
123
- } catch (error) {
124
- console.error('Failed to extract dependencies:', error);
125
- return [];
126
- }
127
- }
128
-
129
- /**
130
- * Fetch license information from npm registry
131
- */
132
- private async fetchLicenseFromRegistry(packageName: string): Promise<{ license: string; category: string }> {
133
- // Check cache first
134
- const cached = licenseCache.get(packageName);
135
- if (cached && (Date.now() - cached.fetchedAt.getTime()) < CACHE_TTL_MS) {
136
- return { license: cached.license, category: cached.category };
137
- }
138
-
139
- try {
140
- // Fetch from npm registry
141
- const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(packageName)}`, {
142
- headers: {
143
- 'Accept': 'application/json',
144
- 'User-Agent': 'Guardrail-AI/1.0',
145
- },
146
- signal: AbortSignal.timeout(5000), // 5 second timeout
147
- });
148
-
149
- if (!response.ok) {
150
- return this.getDefaultLicense(packageName);
151
- }
152
-
153
- const data = await response.json();
154
- const license = this.extractLicenseFromPackageData(data);
155
- const category = this.categorizeLicense(license);
156
-
157
- // Cache the result
158
- licenseCache.set(packageName, {
159
- license,
160
- category,
161
- fetchedAt: new Date(),
162
- });
163
-
164
- return { license, category };
165
- } catch (error) {
166
- // Fallback for network errors or private packages
167
- return this.getDefaultLicense(packageName);
168
- }
169
- }
170
-
171
- /**
172
- * Extract license from npm package data
173
- */
174
- private extractLicenseFromPackageData(data: any): string {
175
- // Check latest version first
176
- const latestVersion = data['dist-tags']?.latest;
177
- const versionData = latestVersion ? data.versions?.[latestVersion] : null;
178
-
179
- // Try multiple license sources
180
- let license = versionData?.license || data.license;
181
-
182
- // Handle SPDX expressions
183
- if (typeof license === 'object') {
184
- if (license.type) {
185
- license = license.type;
186
- } else if (Array.isArray(license)) {
187
- license = license.map((l: any) => l.type || l).join(' OR ');
188
- }
189
- }
190
-
191
- // Normalize common variations
192
- if (typeof license === 'string') {
193
- license = this.normalizeLicenseName(license);
194
- }
195
-
196
- return license || 'UNKNOWN';
197
- }
198
-
199
- /**
200
- * Normalize license name variations
201
- */
202
- private normalizeLicenseName(license: string): string {
203
- const normalizations: Record<string, string> = {
204
- 'Apache 2.0': 'Apache-2.0',
205
- 'Apache License 2.0': 'Apache-2.0',
206
- 'Apache-2': 'Apache-2.0',
207
- 'BSD': 'BSD-3-Clause',
208
- 'BSD-2': 'BSD-2-Clause',
209
- 'BSD-3': 'BSD-3-Clause',
210
- 'GPL': 'GPL-3.0',
211
- 'GPLv2': 'GPL-2.0',
212
- 'GPLv3': 'GPL-3.0',
213
- 'LGPL': 'LGPL-3.0',
214
- 'LGPLv2': 'LGPL-2.1',
215
- 'LGPLv3': 'LGPL-3.0',
216
- 'MIT License': 'MIT',
217
- 'ISC License': 'ISC',
218
- 'Unlicense': 'Unlicense',
219
- 'WTFPL': 'WTFPL',
220
- 'CC0': 'CC0-1.0',
221
- 'CC-BY-3.0': 'CC-BY-3.0',
222
- 'CC-BY-4.0': 'CC-BY-4.0',
223
- };
224
-
225
- return normalizations[license] || license;
226
- }
227
-
228
- /**
229
- * Categorize license by permissiveness
230
- */
231
- private categorizeLicense(license: string): string {
232
- const categories: Record<string, string[]> = {
233
- 'permissive': ['MIT', 'ISC', 'BSD-2-Clause', 'BSD-3-Clause', 'Apache-2.0', 'Unlicense', 'CC0-1.0', 'WTFPL', '0BSD'],
234
- 'weak-copyleft': ['LGPL-2.1', 'LGPL-3.0', 'MPL-2.0', 'EPL-1.0', 'EPL-2.0'],
235
- 'copyleft': ['GPL-2.0', 'GPL-3.0', 'AGPL-3.0'],
236
- 'proprietary': ['PROPRIETARY', 'COMMERCIAL', 'UNLICENSED'],
237
- 'public-domain': ['CC0-1.0', 'Unlicense', 'WTFPL'],
238
- };
239
-
240
- for (const [category, licenses] of Object.entries(categories)) {
241
- if (licenses.some(l => license.toUpperCase().includes(l.toUpperCase()))) {
242
- return category;
243
- }
244
- }
245
-
246
- return 'unknown';
247
- }
248
-
249
- /**
250
- * Get default license for packages that can't be fetched
251
- */
252
- private getDefaultLicense(_packageName: string): { license: string; category: string } {
253
- // Check node_modules for local license file
254
- // This is a fallback for private packages
255
- return {
256
- license: 'UNKNOWN',
257
- category: 'unknown',
258
- };
259
- }
260
-
261
- /**
262
- * Clear license cache
263
- */
264
- clearCache(): void {
265
- licenseCache.clear();
266
- }
267
-
268
- /**
269
- * Get cache statistics
270
- */
271
- getCacheStats(): { size: number; oldestEntry: Date | null } {
272
- let oldest: Date | null = null;
273
- for (const entry of licenseCache.values()) {
274
- if (!oldest || entry.fetchedAt < oldest) {
275
- oldest = entry.fetchedAt;
276
- }
277
- }
278
- return {
279
- size: licenseCache.size,
280
- oldestEntry: oldest,
281
- };
282
- }
283
-
284
- checkCompatibility(projectLicense: string, depLicense: string): CompatibilityResult {
285
- const projLic = projectLicense as LicenseType;
286
- const depLic = depLicense as LicenseType;
287
-
288
- if (!LICENSE_INFO[projLic] || !LICENSE_INFO[depLic]) {
289
- return { compatible: false, reason: 'Unknown license' };
290
- }
291
-
292
- const compatible = COMPATIBILITY_MATRIX[projLic]?.[depLic] ?? false;
293
-
294
- return {
295
- compatible,
296
- reason: compatible
297
- ? 'Licenses are compatible'
298
- : `${depLicense} is incompatible with ${projectLicense}`,
299
- };
300
- }
301
-
302
- private detectGPLContamination(deps: LicensedDependency[], projectLicense: string): LicenseConflict[] {
303
- const conflicts: LicenseConflict[] = [];
304
-
305
- for (const dep of deps) {
306
- const compat = this.checkCompatibility(projectLicense, dep.license);
307
-
308
- if (!compat.compatible) {
309
- conflicts.push({
310
- dependency: dep.name,
311
- dependencyLicense: dep.license,
312
- projectLicense,
313
- reason: compat.reason,
314
- severity: dep.license.includes('GPL') ? 'error' : 'warning',
315
- });
316
- }
317
- }
318
-
319
- return conflicts;
320
- }
321
-
322
- private async analyzeAICodeAttribution(_projectPath: string): Promise<AICodeAttribution[]> {
323
- // In production, this would scan for AI-generated code markers
324
- return [];
325
- }
326
-
327
- async generateComplianceReport(analysis: LicenseAnalysisResult): Promise<string> {
328
- let report = '# License Compliance Report\n\n';
329
- report += `**Project License:** ${analysis.projectLicense}\n`;
330
- report += `**Status:** ${analysis.overallStatus}\n\n`;
331
- report += `## Summary\n`;
332
- report += `- Total Dependencies: ${analysis.summary.totalDeps}\n`;
333
- report += `- Conflicts: ${analysis.summary.conflicts}\n\n`;
334
-
335
- if (analysis.conflicts.length > 0) {
336
- report += `## Conflicts\n\n`;
337
- for (const conflict of analysis.conflicts) {
338
- report += `- **${conflict.dependency}** (${conflict.dependencyLicense}): ${conflict.reason}\n`;
339
- }
340
- }
341
-
342
- return report;
343
- }
344
- }
345
-
346
- export const licenseComplianceEngine = new LicenseComplianceEngine();
@@ -1,6 +0,0 @@
1
- /**
2
- * License Compliance Engine
3
- */
4
-
5
- export * from './compatibility-matrix';
6
- export * from './engine';