UNPKG

adpa-enterprise-framework-automation

Version:

Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe

253 lines 11.4 kB
/** * Adobe Document Generation API Client * * Provides integration with Adobe Document Generation APIs for * template-based document creation with data merge capabilities. */ import { CreativeSuiteAuthenticator } from './authenticator.js'; import { creativeSuiteConfig } from './config.js'; export class DocumentGenerationAPIClient { authenticator; apiEndpoint; accessToken = null; constructor() { this.authenticator = new CreativeSuiteAuthenticator(); this.apiEndpoint = creativeSuiteConfig.getConfig().apis.documentGeneration.endpoint; } /** * Initialize the client and authenticate with Adobe Document Generation API */ async initialize() { const authResult = await this.authenticator.authenticate(); this.accessToken = authResult.accessToken; } /** * List available document templates */ async listTemplates(category) { await this.ensureAuthenticated(); // Phase 2: This would fetch from actual Adobe Document Generation API // For now, return predefined templates const allTemplates = [ { id: 'pmbok-project-charter', name: 'PMBOK Project Charter', description: 'Professional project charter following PMBOK guidelines', category: 'project-management', version: '1.0', templatePath: 'templates/adobe-creative/pmbok-project-charter.docx', variables: [ { name: 'projectName', type: 'text', required: true, description: 'Project name' }, { name: 'projectManager', type: 'text', required: true, description: 'Project manager' }, { name: 'sponsor', type: 'text', required: true, description: 'Project sponsor' }, { name: 'startDate', type: 'date', required: true, description: 'Project start date' }, { name: 'endDate', type: 'date', required: true, description: 'Project end date' }, { name: 'budget', type: 'number', required: false, description: 'Project budget' }, { name: 'stakeholders', type: 'table', required: true, description: 'Stakeholder matrix' } ], sections: [ { id: 'header', name: 'Header', type: 'header', variables: ['projectName', 'projectManager'] }, { id: 'overview', name: 'Project Overview', type: 'body', variables: ['projectName', 'sponsor'] }, { id: 'scope', name: 'Project Scope', type: 'body', variables: [] }, { id: 'timeline', name: 'Timeline', type: 'body', variables: ['startDate', 'endDate'] }, { id: 'stakeholders', name: 'Stakeholders', type: 'body', variables: ['stakeholders'] } ], outputFormats: ['pdf', 'docx'] }, { id: 'technical-requirements-spec', name: 'Technical Requirements Specification', description: 'Comprehensive technical requirements document', category: 'technical', version: '1.0', templatePath: 'templates/adobe-creative/technical-requirements.docx', variables: [ { name: 'systemName', type: 'text', required: true, description: 'System name' }, { name: 'version', type: 'text', required: true, description: 'Document version' }, { name: 'author', type: 'text', required: true, description: 'Document author' }, { name: 'functionalRequirements', type: 'table', required: true, description: 'Functional requirements' }, { name: 'nonFunctionalRequirements', type: 'table', required: true, description: 'Non-functional requirements' } ], sections: [ { id: 'introduction', name: 'Introduction', type: 'body', variables: ['systemName'] }, { id: 'functional', name: 'Functional Requirements', type: 'body', variables: ['functionalRequirements'] }, { id: 'nonfunctional', name: 'Non-Functional Requirements', type: 'body', variables: ['nonFunctionalRequirements'] } ], outputFormats: ['pdf', 'docx'] } ]; return category ? allTemplates.filter(t => t.category === category) : allTemplates; } /** * Generate a document from template and data */ async generateDocument(request) { await this.ensureAuthenticated(); const startTime = Date.now(); try { // Phase 2 Implementation: Call actual Adobe Document Generation API // 1. Validate template and data await this.validateRequest(request); // 2. Process template with data const processedDocument = await this.processTemplate(request); // 3. Apply branding and formatting const brandedDocument = await this.applyDocumentBranding(processedDocument, request.outputOptions.branding); // 4. Generate final output const finalDocument = await this.generateFinalOutput(brandedDocument, request.outputOptions); const processingTime = Date.now() - startTime; return { id: `docgen-${Date.now()}`, templateUsed: request.templateId, outputPath: finalDocument.path, format: request.outputOptions.format, pageCount: finalDocument.pageCount, fileSize: finalDocument.fileSize, variablesUsed: Object.keys(request.data.variables), metadata: { createdAt: new Date(), processingTime, template: request.templateId, version: '1.0', dataHash: this.calculateDataHash(request.data) } }; } catch (error) { console.error('Document generation failed:', error); throw new Error(`Failed to generate document: ${error instanceof Error ? error.message : 'Unknown error'}`); } } /** * Batch generate multiple documents from the same template */ async batchGenerateDocuments(templateId, dataSet, outputOptions) { const documents = []; // Process in parallel with concurrency limit const concurrency = 2; for (let i = 0; i < dataSet.length; i += concurrency) { const batch = dataSet.slice(i, i + concurrency); const batchPromises = batch.map(data => this.generateDocument({ templateId, data, outputOptions })); const batchResults = await Promise.all(batchPromises); documents.push(...batchResults); } return documents; } /** * Generate documents in multiple formats from a single data source */ async generateMultiFormatDocument(templateId, data, formats) { const documents = []; for (const format of formats) { const outputOptions = { format: format, quality: 'high' }; const document = await this.generateDocument({ templateId, data, outputOptions }); documents.push(document); } return documents; } /** * Preview a document without generating the final output */ async previewDocument(templateId, data, previewOptions) { await this.ensureAuthenticated(); // Phase 2: Generate preview using Adobe Document Generation API return { previewUrl: `preview/${templateId}-${Date.now()}.${previewOptions.format}`, pageCount: 5 }; } /** * Validate document data against template requirements */ async validateDocumentData(templateId, data) { const template = await this.getTemplate(templateId); const errors = []; const warnings = []; // Check required variables for (const variable of template.variables) { if (variable.required && !data.variables[variable.name]) { errors.push(`Required variable '${variable.name}' is missing`); } // Validate variable types and constraints if (data.variables[variable.name] && variable.validation) { const value = data.variables[variable.name]; if (variable.validation.pattern) { const regex = new RegExp(variable.validation.pattern); if (!regex.test(String(value))) { errors.push(`Variable '${variable.name}' does not match required pattern`); } } if (variable.validation.minLength && String(value).length < variable.validation.minLength) { errors.push(`Variable '${variable.name}' is too short`); } if (variable.validation.maxLength && String(value).length > variable.validation.maxLength) { warnings.push(`Variable '${variable.name}' is longer than recommended`); } } } return { isValid: errors.length === 0, errors, warnings }; } // Private helper methods async ensureAuthenticated() { if (!this.accessToken) { await this.initialize(); } } async getTemplate(templateId) { const templates = await this.listTemplates(); const template = templates.find(t => t.id === templateId); if (!template) { throw new Error(`Template not found: ${templateId}`); } return template; } async validateRequest(request) { const validation = await this.validateDocumentData(request.templateId, request.data); if (!validation.isValid) { throw new Error(`Invalid document data: ${validation.errors.join(', ')}`); } } async processTemplate(request) { // Phase 2: Process template with Adobe Document Generation API return { processed: true, request }; } async applyDocumentBranding(document, branding) { // Phase 2: Apply branding using Adobe Document Generation API return { document, branding, branded: true }; } async generateFinalOutput(document, options) { // Phase 2: Generate final output using Adobe Document Generation API return { path: `output/generated-document.${options.format}`, pageCount: 8, fileSize: 1536000 // 1.5MB }; } calculateDataHash(data) { // Simple hash calculation for data integrity const dataString = JSON.stringify(data); let hash = 0; for (let i = 0; i < dataString.length; i++) { const char = dataString.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash = hash & hash; // Convert to 32-bit integer } return hash.toString(16); } } export const documentGenerationClient = new DocumentGenerationAPIClient(); //# sourceMappingURL=document-generation-client.js.map