UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

179 lines 6.47 kB
/** * Dynamic Analytics Query Engine - Constants and Patterns */ export const QUERY_PATTERNS = { // Action patterns grouping: /group(ed)?\s+by\s+(\w+)/i, counting: /how\s+many|count|number\s+of|total/i, trending: /trend|over\s+time|by\s+(day|week|month)|timeline|history/i, comparison: /compare|versus|vs\.?|between|difference/i, finding: /find|show|list|get|which|what/i, analyzing: /analyze|analysis|breakdown|distribution/i, summarizing: /summary|summarize|overview|report/i, // Entity patterns experiments: /experiments?|tests?|a\/b\s+tests?/i, flags: /flags?|feature\s+flags?/i, audiences: /audiences?|segments?|targeting/i, variations: /variations?|variants?|treatments?/i, rules: /rules?|targeting\s+rules?/i, events: /events?|conversions?|goals?/i, attributes: /attributes?|properties/i, pages: /pages?|urls?/i, projects: /projects?/i, environments: /environments?|env/i, rulesets: /rulesets?|rule\s+sets?/i, // Metric patterns traffic: /traffic(\s+allocation)?|allocation/i, conversion: /conversion|performance|results/i, complexity: /complex(ity)?|variations?\s+count/i, usage: /usage|used|utilized/i, // Time patterns lastN: /last\s+(\d+)\s+(days?|weeks?|months?|hours?)/i, between: /between\s+(.+?)\s+and\s+(.+?)(?:\s|$)/i, since: /since\s+(.+?)(?:\s|$)/i, before: /before\s+(.+?)(?:\s|$)/i, after: /after\s+(.+?)(?:\s|$)/i, // Filter patterns hasProperty: /has\s+(\w+)|with\s+(\w+)/gi, notHasProperty: /without\s+(\w+)|no\s+(\w+)/gi, moreThan: /more\s+than\s+(\d+)|>\s*(\d+)|greater\s+than\s+(\d+)/i, lessThan: /less\s+than\s+(\d+)|<\s*(\d+)|fewer\s+than\s+(\d+)/i, equals: /equals?\s+(.+?)|=\s*(.+?)|is\s+(.+?)(?:\s|$)/i, contains: /contains?\s+(.+?)|includes?\s+(.+?)/i, // Grouping patterns byField: /by\s+(\w+)/gi, groupedBy: /grouped\s+by\s+(\w+)/gi, perField: /per\s+(\w+)/gi, // Ordering patterns orderBy: /order(ed)?\s+by\s+(\w+)(\s+(asc|desc)(ending)?)?/i, sortBy: /sort(ed)?\s+by\s+(\w+)(\s+(asc|desc)(ending)?)?/i, topN: /top\s+(\d+)/i, bottomN: /bottom\s+(\d+)/i, // JSON-specific patterns jsonPath: /(\w+)\.(\w+)(?:\.(\w+))*/g, arrayIndex: /\[(\d+)\]/g, nestedProperty: /(\w+)\[(\w+)=([^\]]+)\]/g }; export const COMMON_METRICS = { count: { name: 'count', description: 'Total number of items', aggregation: 'count', type: 'number' }, distinct_count: { name: 'distinct_count', description: 'Number of unique items', aggregation: 'distinct', type: 'number' }, average: { name: 'average', description: 'Average value', aggregation: 'avg', type: 'number' }, sum: { name: 'sum', description: 'Total sum', aggregation: 'sum', type: 'number' }, percentage: { name: 'percentage', description: 'Percentage of total', aggregation: 'percent', type: 'number' } }; export const JSON_PATH_MAPPINGS = { // Flag-specific paths 'flag.variables': 'data_json.variable_definitions', 'flag.environments': 'data_json.environments', 'flag.variations': 'data_json.variations', 'flag.rules': 'data_json.rules', // Experiment-specific paths 'experiment.audiences': 'data_json.audience_conditions', 'experiment.metrics': 'data_json.metrics', 'experiment.pages': 'data_json.page_ids', 'experiment.traffic': 'data_json.traffic_allocation', // Variation-specific paths 'variation.variables': 'data_json.variable_values', 'variation.actions': 'data_json.actions', 'variation.weight': 'data_json.weight', // Audience-specific paths 'audience.conditions': 'conditions', 'audience.segments': 'data_json.segments', // Common paths 'cdnVariationSettings': 'data_json.variable_values.cdnVariationSettings', 'customCode': 'data_json.actions[type="custom_code"]', 'urlTargeting': 'data_json.url_targeting' }; export const QUERY_LIMITS = { defaultLimit: parseInt(process.env.ANALYTICS_DEFAULT_PAGE_SIZE || '10'), maxLimit: 10000, maxGroupByFields: 5, maxFilterConditions: 20, maxJoins: 10, maxJsonataComplexity: 1000, queryTimeout: 30000, // 30 seconds interactiveTimeout: 300000 // 5 minutes }; export const ERROR_CODES = { INVALID_QUERY: 'INVALID_QUERY', PARSE_ERROR: 'PARSE_ERROR', VALIDATION_ERROR: 'VALIDATION_ERROR', EXECUTION_ERROR: 'EXECUTION_ERROR', TIMEOUT_ERROR: 'TIMEOUT_ERROR', PERMISSION_ERROR: 'PERMISSION_ERROR', COMPLEXITY_ERROR: 'COMPLEXITY_ERROR', JSONATA_ERROR: 'JSONATA_ERROR' }; export const INSIGHT_PATTERNS = { highVariationCount: { condition: (data) => data.variation_count > 5, type: 'pattern', title: 'High variation count detected', template: 'Found {count} items with more than 5 variations' }, unusedAudiences: { condition: (data) => data.experiment_count === 0, type: 'pattern', title: 'Unused audiences found', template: '{count} audiences are not used in any experiments' }, complexTargeting: { condition: (data) => data.rule_count > 3 || data.condition_count > 5, type: 'pattern', title: 'Complex targeting rules', template: 'Found items with complex targeting (>3 rules or >5 conditions)' }, trafficImbalance: { condition: (data) => Math.abs(data.traffic_allocation - 50) > 30, type: 'anomaly', title: 'Traffic allocation imbalance', template: 'Significant traffic imbalance detected ({allocation}% allocation)' } }; export const RESERVED_KEYWORDS = [ 'SELECT', 'FROM', 'WHERE', 'GROUP', 'BY', 'ORDER', 'LIMIT', 'JOIN', 'LEFT', 'RIGHT', 'INNER', 'OUTER', 'ON', 'AND', 'OR', 'NOT', 'IN', 'EXISTS', 'LIKE', 'COUNT', 'SUM', 'AVG', 'MIN', 'MAX', 'DISTINCT' ]; export const SAFE_JSON_FUNCTIONS = [ 'JSON_EXTRACT', 'JSON_ARRAY_LENGTH', 'JSON_TYPE', 'JSON_VALID', 'JSON_QUOTE' ]; export const TEMPLATE_CATEGORIES = { VARIABLE_ANALYSIS: 'variable_analysis', COMPLEXITY_ANALYSIS: 'complexity_analysis', PERFORMANCE_TRENDS: 'performance_trends', AUDIENCE_USAGE: 'audience_usage', CHANGE_TRACKING: 'change_tracking', CROSS_ENTITY: 'cross_entity' }; //# sourceMappingURL=constants.js.map