/** * Template element class implementing IElement interface. * Represents reusable content structures with variable substitution and dynamic content. * * SECURITY FIXES IMPLEMENTED (Following PR #319 patterns): * 1. CRITICAL: Template injection prevention - no eval() or Function() constructor * 2. CRITICAL: Path traversal prevention for template includes * 3. HIGH: Input validation and sanitization for all template variables * 4. MEDIUM: Memory limits to prevent resource exhaustion (100KB templates, 100 variables) * 5. MEDIUM: Audit logging for all security operations via SecurityMonitor * 6. MEDIUM: Unicode normalization to prevent homograph attacks */ import { BaseElement } from '../BaseElement.js'; import { IElement, IElementMetadata, ElementValidationResult } from '../../types/elements/index.js'; import { ElementType } from '../../portfolio/types.js'; import { MetadataService } from '../../services/MetadataService.js'; export interface TemplateMetadata extends IElementMetadata { type?: ElementType.TEMPLATE; category?: string; output_format?: string; variables?: TemplateVariable[]; includes?: string[]; tags?: string[]; usage_count?: number; last_used?: string; examples?: TemplateExample[]; /** * Action verbs that trigger this template (e.g., "create", "generate", "draft") * Used by Enhanced Capability Index for intelligent template suggestions * @since v1.9.10 */ triggers?: string[]; } export interface TemplateVariable { name: string; type: 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object'; description?: string; required?: boolean; default?: unknown; validation?: string; options?: string[]; format?: string; } export interface TemplateExample { title: string; description?: string; variables: Record; output?: string; } /** Parsed result of a section-format template (issue #705). */ export interface TemplateSections { /** True when the content contains at least one bare section tag. */ isSectionMode: boolean; /** Content of the