UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

155 lines 5.78 kB
/** * Template Processor Utility * @description Handles processing of entity creation templates including placeholder validation, * type checking, and data transformation for Optimizely API calls. * * Core Functions: * - Validate template completion (all {FILL:} placeholders replaced) * - Type validation against expected data types * - Extract placeholder guidance for AI agents * - Transform filled templates into API-ready payloads * * @author Optimizely MCP Server * @version 1.0.0 */ export interface TemplateValidationResult { isValid: boolean; errors: string[]; warnings: string[]; missingRequired: string[]; completionStatus: { totalPlaceholders: number; filledPlaceholders: number; completionPercentage: number; }; } export interface PlaceholderInfo { path: string; type: "FILL" | "OPTIONAL" | "EXISTING" | "FIND_OR_CREATE" | "CREATE_NEW"; description: string; currentValue?: any; expectedType?: string; entityType?: string; entityIdentifier?: string; } export interface ProcessedTemplate { processedData: any; metadata: { originalTemplate: any; placeholdersFound: PlaceholderInfo[]; validationResult: TemplateValidationResult; }; } /** * Template Processor Class * Handles all template processing operations including validation and transformation */ export declare class TemplateProcessor { private static readonly FILL_PATTERN; private static readonly OPTIONAL_PATTERN; private static readonly EXISTING_PATTERN; private static readonly FIND_OR_CREATE_PATTERN; private static readonly CREATE_NEW_PATTERN; private static readonly PLACEHOLDER_PATTERN; /** * Process a filled template and validate its completion * @param filledTemplate - Template with user-provided values * @param originalTemplate - Original template structure for reference * @returns Processed template with validation results */ static processTemplate(filledTemplate: any, originalTemplate?: any): ProcessedTemplate; /** * Extract all placeholders from a template structure * @param template - Template object to analyze * @returns Array of placeholder information */ static extractPlaceholderInfo(template: any): PlaceholderInfo[]; /** * Validate that all required placeholders have been filled * @param template - Template to validate * @param placeholders - Extracted placeholder information * @returns Validation result with detailed feedback */ static validateTemplate(template: any, placeholders: PlaceholderInfo[]): TemplateValidationResult; /** * Check if a value still contains placeholder syntax * @param value - Value to check * @returns True if placeholder syntax found */ private static hasPlaceholderSyntax; /** * Parse entity reference from placeholder content * Examples: "event:purchase_completed", "page:12345", "audience:mobile_users" * @param reference - Entity reference string * @returns Parsed entity type and identifier */ private static parseEntityReference; /** * Infer expected data type from placeholder description * @param description - Placeholder description * @returns Expected data type */ private static inferTypeFromDescription; /** * Validate data type against expected type * @param value - Value to validate * @param expectedType - Expected data type * @returns Validation result */ private static validateDataType; /** * Transform filled template into API-ready payload * @param template - Filled template * @returns API-ready data structure */ private static transformToAPIPayload; /** * Remove sections that still contain unfilled placeholders * @param obj - Object to clean */ private static cleanUnfilledSections; /** * Check if a value contains placeholder syntax (recursively) * @param value - Value to check * @returns True if placeholder syntax is found */ private static containsPlaceholderSyntax; /** * Transform fields to match API expectations * @param payload - Payload to transform */ private static transformAPIFields; /** * Get guidance for AI agents on what information to collect * @param template - Original template structure * @returns Array of guidance instructions for collecting user input */ static getCollectionGuidance(template: any): string[]; /** * Generate example filled template for AI agent reference * @param template - Original template * @param entityType - Type of entity being created * @returns Example with realistic values */ static generateExampleTemplate(template: any, entityType: string): any; /** * Process entity reference placeholders in template * This transforms entity references into their resolved IDs/keys * @param template - Template with entity references * @param entityResolver - Function to resolve entity references * @returns Template with resolved references */ static resolveEntityReferences(template: any, entityResolver: (entityType: string, identifier: string, strategy: "existing" | "find_or_create" | "create_new") => Promise<string | null>): Promise<{ resolved: any; errors: string[]; }>; /** * Generate example values for placeholders * @param description - Placeholder description * @param path - Field path * @param entityType - Entity type for context * @returns Example value */ private static getExampleValue; } //# sourceMappingURL=TemplateProcessor.d.ts.map