@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
54 lines • 2.18 kB
JavaScript
/**
* EntityMatcher - Utility for matching entities across different types
*
* This utility provides intelligent matching logic for different Optimizely entity types,
* supporting the smart entity adoption feature that allows reusing existing entities
* instead of creating duplicates.
*/
export class EntityMatcher {
/**
* Determines if an entity matches the given criteria (ID or key only)
* @param entityType - The type of entity being matched (not used anymore)
* @param entity - The entity to check
* @param criteria - The matching criteria
* @returns Match result with details
*/
static matchEntity(entityType, entity, criteria) {
// All entities use the same ID/key matching logic
return this.exactMatch(entity, criteria);
}
/**
* Exact match by ID or key only
*/
static exactMatch(entity, criteria) {
// Check ID first (most specific)
// Convert both to string for comparison to handle number vs string IDs
if (criteria.id && entity.id && String(entity.id) === String(criteria.id)) {
return { matched: true, entity, matchType: 'exact_id' };
}
// Then check key
if (criteria.key && entity.key && entity.key === criteria.key) {
return { matched: true, entity, matchType: 'exact_key' };
}
// No match
return { matched: false };
}
/**
* Find first match from a list of entities (ID or key match only)
* @param entityType - Type of entities being matched (not used anymore)
* @param entities - List of entities to search through
* @param criteria - Matching criteria (ID or key)
* @returns First matching entity or null
*/
static findBestMatch(entityType, entities, criteria) {
for (const entity of entities) {
const matchResult = this.matchEntity(entityType, entity, criteria);
if (matchResult.matched) {
// Return first match found (ID or key matches are always exact)
return matchResult.entity;
}
}
return null;
}
}
//# sourceMappingURL=EntityMatcher.js.map