editia-core
Version:
Core services and utilities for Editia applications - Authentication, Monetization, Video Generation Types, and Database Management
71 lines • 3.98 kB
JavaScript
;
/**
* Database types for Editia Core
*
* This file imports and re-exports the actual Supabase generated types
* and provides utility functions for type safety and developer experience.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidUsageField = exports.isValidAction = exports.isValidFeatureId = exports.getUsageFieldForFeature = exports.getUsageFieldForAction = exports.getActionForFeature = exports.FEATURE_TO_USAGE_FIELD_MAP = exports.ACTION_TO_USAGE_FIELD_MAP = exports.FEATURE_TO_ACTION_MAP = exports.USAGE_FIELDS = exports.ACTIONS = exports.FEATURES = exports.getUsagePercentage = exports.hasReachedLimit = exports.calculateRemainingUsage = exports.hasPlanAccess = exports.getPlanLevel = exports.isValidPlanIdentifier = void 0;
// ============================================================================
// UTILITY FUNCTIONS
// ============================================================================
/**
* Check if a plan identifier is valid
*/
const isValidPlanIdentifier = (plan) => {
return ['free', 'creator', 'pro'].includes(plan);
};
exports.isValidPlanIdentifier = isValidPlanIdentifier;
/**
* Get plan hierarchy level (for access control)
*/
const getPlanLevel = (plan) => {
const levels = { free: 0, creator: 1, pro: 2 };
return levels[plan];
};
exports.getPlanLevel = getPlanLevel;
/**
* Check if user has access to a required plan
*/
const hasPlanAccess = (userPlan, requiredPlan) => {
return (0, exports.getPlanLevel)(userPlan) >= (0, exports.getPlanLevel)(requiredPlan);
};
exports.hasPlanAccess = hasPlanAccess;
/**
* Calculate remaining usage for a resource
*/
const calculateRemainingUsage = (used, limit) => {
return Math.max(0, limit - used);
};
exports.calculateRemainingUsage = calculateRemainingUsage;
/**
* Check if user has reached their limit for a resource
*/
const hasReachedLimit = (used, limit) => {
return used >= limit;
};
exports.hasReachedLimit = hasReachedLimit;
/**
* Get usage percentage for a resource
*/
const getUsagePercentage = (used, limit) => {
if (limit === 0)
return 0;
return Math.min(100, (used / limit) * 100);
};
exports.getUsagePercentage = getUsagePercentage;
var monetization_1 = require("./monetization");
Object.defineProperty(exports, "FEATURES", { enumerable: true, get: function () { return monetization_1.FEATURES; } });
Object.defineProperty(exports, "ACTIONS", { enumerable: true, get: function () { return monetization_1.ACTIONS; } });
Object.defineProperty(exports, "USAGE_FIELDS", { enumerable: true, get: function () { return monetization_1.USAGE_FIELDS; } });
Object.defineProperty(exports, "FEATURE_TO_ACTION_MAP", { enumerable: true, get: function () { return monetization_1.FEATURE_TO_ACTION_MAP; } });
Object.defineProperty(exports, "ACTION_TO_USAGE_FIELD_MAP", { enumerable: true, get: function () { return monetization_1.ACTION_TO_USAGE_FIELD_MAP; } });
Object.defineProperty(exports, "FEATURE_TO_USAGE_FIELD_MAP", { enumerable: true, get: function () { return monetization_1.FEATURE_TO_USAGE_FIELD_MAP; } });
Object.defineProperty(exports, "getActionForFeature", { enumerable: true, get: function () { return monetization_1.getActionForFeature; } });
Object.defineProperty(exports, "getUsageFieldForAction", { enumerable: true, get: function () { return monetization_1.getUsageFieldForAction; } });
Object.defineProperty(exports, "getUsageFieldForFeature", { enumerable: true, get: function () { return monetization_1.getUsageFieldForFeature; } });
Object.defineProperty(exports, "isValidFeatureId", { enumerable: true, get: function () { return monetization_1.isValidFeatureId; } });
Object.defineProperty(exports, "isValidAction", { enumerable: true, get: function () { return monetization_1.isValidAction; } });
Object.defineProperty(exports, "isValidUsageField", { enumerable: true, get: function () { return monetization_1.isValidUsageField; } });
//# sourceMappingURL=database.js.map