| 1 | import { analyzeComplianceFiles } from './ai/AIAnalyzer.js'; |
| 2 | |
| 3 | export async function generateComplianceReport({ |
| 4 | verifiablePresentation, |
| 5 | selfDescription, |
| 6 | outputFiles, |
| 7 | apiSpec |
| 8 | }) { |
| 9 | // Obtener análisis de IA |
| 10 | const aiAnalysis = await analyzeComplianceFiles(outputFiles, selfDescription); |
| 11 | |
| 12 | const report = { |
| 13 | files: [ |
| 14 | { |
| 15 | path: outputFiles.vp, |
| 16 | description: "Main Verifiable Presentation containing all credentials" |
| 17 | }, |
| 18 | { |
| 19 | path: outputFiles.serviceOffering, |
| 20 | description: "Service Offering description with detailed service metadata" |
| 21 | }, |
| 22 | { |
| 23 | path: outputFiles.virtualResource, |
| 24 | description: "Virtual Resource definition mapping API endpoints" |
| 25 | }, |
| 26 | { |
| 27 | path: outputFiles.instantiatedResource, |
| 28 | description: "Instantiated Resource with concrete service implementation details" |
| 29 | } |
| 30 | ], |
| 31 | |
| 32 | service: { |
| 33 | name: selfDescription.credentialSubject.name, |
| 34 | version: selfDescription.credentialSubject.version, |
| 35 | endpoints: extractEndpoints(apiSpec) |
| 36 | }, |
| 37 | |
| 38 | extendedAttributes: [ |
| 39 | { |
| 40 | name: "serviceQualityLevel", |
| 41 | value: selfDescription.credentialSubject.serviceQualityLevel || "standard", |
| 42 | description: "Defines the quality level guarantees for this service" |
| 43 | }, |
| 44 | { |
| 45 | name: "dataProtectionRegime", |
| 46 | value: selfDescription.credentialSubject.dataProtectionRegime || ["GDPR"], |
| 47 | description: "Applicable data protection regulations" |
| 48 | }, |
| 49 | { |
| 50 | name: "dataAccountExport", |
| 51 | value: selfDescription.credentialSubject.dataAccountExport || true, |
| 52 | description: "Indicates if data can be exported by the account owner" |
| 53 | } |
| 54 | ], |
| 55 | |
| 56 | nextSteps: [ |
| 57 | "Deploy the generated files to your web server at the specified URLs", |
| 58 | "Register your service in the GAIA-X Federation Services", |
| 59 | "Update your service documentation to include the GAIA-X compliance information", |
| 60 | "Monitor the service endpoints for continued compliance", |
| 61 | "Set up automated renewal of credentials before expiration" |
| 62 | ], |
| 63 | |
| 64 | aiAnalysis: { |
| 65 | summary: aiAnalysis.summary, |
| 66 | recommendations: aiAnalysis.recommendations, |
| 67 | compatibility: aiAnalysis.detailedAnalysis.gaiaXCompatibility, |
| 68 | rawAnalysis: aiAnalysis.aiResponse |
| 69 | }, |
| 70 | |
| 71 | toMarkdown() { |
| 72 | return `# GAIA-X Compliance Report |
| 73 | |
| 74 | ## AI Analysis |
| 75 | ${this.aiAnalysis.summary} |
| 76 | |
| 77 | ### Detailed AI Analysis |
| 78 | ${this.aiAnalysis.rawAnalysis} |
| 79 | |
| 80 | ### AI Recommendations |
| 81 | ${this.aiAnalysis.recommendations.map(rec => |
| 82 | `- [${rec.priority}] ${rec.area}: ${rec.recommendation}\n Impact: ${rec.impact}` |
| 83 | ).join('\n')} |
| 84 | |
| 85 | ### GAIA-X Compatibility Status |
| 86 | - Level: ${this.aiAnalysis.compatibility.level} |
| 87 | - Status: ${this.aiAnalysis.compatibility.certificationStatus} |
| 88 | - Next Steps: |
| 89 | ${this.aiAnalysis.compatibility.nextSteps.map(step => ` - ${step}`).join('\n')} |
| 90 | |
| 91 | ## Generated Files |
| 92 | ${this.files.map(f => `- **${f.path}**: ${f.description}`).join('\n')} |
| 93 | |
| 94 | ## Service Details |
| 95 | - **Name**: ${this.service.name} |
| 96 | - **Version**: ${this.service.version} |
| 97 | - **Number of Endpoints**: ${this.service.endpoints.length} |
| 98 | |
| 99 | ## Extended GAIA-X Attributes |
| 100 | ${this.extendedAttributes.map(attr => |
| 101 | `### ${attr.name}\n- Value: ${attr.value}\n- ${attr.description}` |
| 102 | ).join('\n\n')} |
| 103 | |
| 104 | ## Next Steps |
| 105 | ${this.nextSteps.map((step, i) => `${i + 1}. ${step}`).join('\n')} |
| 106 | `; |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | return report; |
| 111 | } |
| 112 | |
| 113 | function extractEndpoints(apiSpec) { |
| 114 | // Extraer endpoints del OpenAPI spec |
| 115 | const endpoints = []; |
| 116 | for (const path in apiSpec.paths) { |
| 117 | for (const method in apiSpec.paths[path]) { |
| 118 | endpoints.push({ |
| 119 | path, |
| 120 | method: method.toUpperCase(), |
| 121 | description: apiSpec.paths[path][method].description |
| 122 | }); |
| 123 | } |
| 124 | } |
| 125 | return endpoints; |
| 126 | } |