editia-core
Version: 
Core services and utilities for Editia applications - Authentication, Monetization, Video Generation Types, and Database Management
134 lines • 5.72 kB
JavaScript
;
/**
 * Compatibility Layer for Editia Core Types
 *
 * This file provides backward compatibility for existing code while
 * encouraging migration to the new strongly-typed system.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.LEGACY_ACTIONS = exports.LEGACY_FEATURES = exports.showDeprecationWarning = exports.toLegacyUserUsage = exports.toUsageField = exports.toAction = exports.toFeatureId = void 0;
const monetization_1 = require("./monetization");
// ============================================================================
// COMPATIBILITY FUNCTIONS
// ============================================================================
/**
 * Convert legacy string to FeatureId with validation
 * @deprecated Use FEATURES constants directly
 */
function toFeatureId(legacyFeature) {
    if (Object.values(monetization_1.FEATURES).includes(legacyFeature)) {
        return legacyFeature;
    }
    // Fallback mappings for common legacy values
    const fallbackMap = {
        'video_generation': monetization_1.FEATURES.VIDEO_GENERATION,
        'source_videos': monetization_1.FEATURES.SOURCE_VIDEOS,
        'voice_clone': monetization_1.FEATURES.VOICE_CLONE,
        'account_analysis': monetization_1.FEATURES.ACCOUNT_ANALYSIS,
        'script_conversations': monetization_1.FEATURES.SCRIPT_CONVERSATIONS,
        'script_generation': monetization_1.FEATURES.SCRIPT_GENERATION,
        'chat_ai': monetization_1.FEATURES.CHAT_AI,
    };
    return fallbackMap[legacyFeature] || monetization_1.FEATURES.VIDEO_GENERATION;
}
exports.toFeatureId = toFeatureId;
/**
 * Convert legacy string to Action with validation
 * @deprecated Use ACTIONS constants directly
 */
function toAction(legacyAction) {
    if (Object.values(monetization_1.ACTIONS).includes(legacyAction)) {
        return legacyAction;
    }
    // Fallback mappings for common legacy values
    const fallbackMap = {
        'video_generation': monetization_1.ACTIONS.VIDEO_GENERATION,
        'source_video_upload': monetization_1.ACTIONS.SOURCE_VIDEO_UPLOAD,
        'voice_clone': monetization_1.ACTIONS.VOICE_CLONE,
        'account_analysis': monetization_1.ACTIONS.ACCOUNT_ANALYSIS,
        'script_conversations': monetization_1.ACTIONS.SCRIPT_CONVERSATIONS,
    };
    return fallbackMap[legacyAction] || monetization_1.ACTIONS.VIDEO_GENERATION;
}
exports.toAction = toAction;
/**
 * Convert legacy string to UsageField with validation
 * @deprecated Use USAGE_FIELDS constants directly
 */
function toUsageField(legacyField) {
    if (Object.values(monetization_1.USAGE_FIELDS).includes(legacyField)) {
        return legacyField;
    }
    // Fallback mappings for common legacy values
    const fallbackMap = {
        'videos_generated': monetization_1.USAGE_FIELDS.VIDEOS_GENERATED,
        'source_videos_used': monetization_1.USAGE_FIELDS.SOURCE_VIDEOS_USED,
        'voice_clones_used': monetization_1.USAGE_FIELDS.VOICE_CLONES_USED,
        'account_analysis_used': monetization_1.USAGE_FIELDS.ACCOUNT_ANALYSIS_USED,
        'script_conversations_used': monetization_1.USAGE_FIELDS.SCRIPT_CONVERSATIONS_USED,
    };
    return fallbackMap[legacyField] || monetization_1.USAGE_FIELDS.VIDEOS_GENERATED;
}
exports.toUsageField = toUsageField;
/**
 * Convert new UserUsage to legacy format
 * @deprecated Use new UserUsage type directly
 */
function toLegacyUserUsage(newUsage) {
    return {
        user_id: newUsage.user_id,
        current_plan_id: newUsage.current_plan_id,
        videos_generated: newUsage.videos_generated,
        videos_generated_limit: newUsage.videos_generated_limit,
        source_videos_used: newUsage.source_videos_used,
        source_videos_limit: newUsage.source_videos_limit,
        voice_clones_used: newUsage.voice_clones_used,
        voice_clones_limit: newUsage.voice_clones_limit,
        account_analysis_used: newUsage.account_analysis_used,
        account_analysis_limit: newUsage.account_analysis_limit,
        script_conversations_used: newUsage.script_conversations_used,
        script_conversations_limit: newUsage.script_conversations_limit,
        next_reset_date: newUsage.next_reset_date,
        created_at: newUsage.created_at,
        updated_at: newUsage.updated_at,
    };
}
exports.toLegacyUserUsage = toLegacyUserUsage;
// ============================================================================
// DEPRECATION WARNINGS
// ============================================================================
/**
 * Show deprecation warning in development
 */
function showDeprecationWarning(oldUsage, newUsage) {
    if (process.env.NODE_ENV === 'development') {
        console.warn(`⚠️  DEPRECATION WARNING: ${oldUsage} is deprecated. Use ${newUsage} instead.`);
    }
}
exports.showDeprecationWarning = showDeprecationWarning;
// ============================================================================
// LEGACY CONSTANTS (for backward compatibility)
// ============================================================================
/**
 * @deprecated Use FEATURES constants instead
 */
exports.LEGACY_FEATURES = {
    VIDEO_GENERATION: 'video_generation',
    SOURCE_VIDEOS: 'source_videos',
    VOICE_CLONE: 'voice_clone',
    ACCOUNT_ANALYSIS: 'account_analysis',
    SCRIPT_CONVERSATIONS: 'script_conversations',
    SCRIPT_GENERATION: 'script_generation',
    CHAT_AI: 'chat_ai',
};
/**
 * @deprecated Use ACTIONS constants instead
 */
exports.LEGACY_ACTIONS = {
    VIDEO_GENERATION: 'video_generation',
    SOURCE_VIDEO_UPLOAD: 'source_video_upload',
    VOICE_CLONE: 'voice_clone',
    ACCOUNT_ANALYSIS: 'account_analysis',
    SCRIPT_CONVERSATIONS: 'script_conversations',
};
//# sourceMappingURL=compatibility.js.map