UNPKG

editia-core

Version:

Core services and utilities for Editia applications - Authentication, Monetization, Video Generation Types, and Database Management

89 lines 3.02 kB
/** * Editia Monetization Service - Backend * * This service centralizes all monetization logic for backend operations. * It provides methods to check feature access, validate usage limits, * and manage subscription-based restrictions. */ import { SupabaseClient } from '@supabase/supabase-js'; import { Database, UserUsage, MonetizationErrorCode } from '../../types'; import { FeatureId, Action, FeatureAccessResult, UsageValidationResult, MonetizationCheckResult } from '../../types/monetization'; export interface MonetizationConfig { supabaseClient: SupabaseClient<Database>; environment?: 'development' | 'production' | 'test'; } export declare class MonetizationError extends Error { code: string; constructor(message: string, code: MonetizationErrorCode); } export declare function parseMonetizationError(error: MonetizationError): string; export declare function isMonetizationError(error: Error): error is MonetizationError; export declare class MonetizationService { private static instance; private supabaseClient; private environment; private cache; private cacheTimeout; private constructor(); /** * Get singleton instance */ static getInstance(config?: MonetizationConfig): MonetizationService; /** * Initialize the service (call once at startup) */ static initialize(config: MonetizationConfig): void; /** * Check if user has access to a specific feature */ checkFeatureAccess(userId: string, featureId: FeatureId): Promise<FeatureAccessResult>; /** * Validate if user can perform an action (e.g., generate video, upload file) */ validateUsage(userId: string, action: Action): Promise<UsageValidationResult>; /** * Comprehensive check for feature access and usage validation */ checkMonetization(userId: string, featureId: FeatureId): Promise<MonetizationCheckResult>; /** * Increment usage for a specific action */ incrementUsage(userId: string, action: Action): Promise<boolean>; /** * Decrement usage for a specific action */ decrementUsage(userId: string, action: Action): Promise<boolean>; /** * Get current usage for a user */ getUserUsage(userId: string): Promise<UserUsage | null>; /** * Get feature requirements from database */ private getFeatureRequirements; /** * Get usage information for a specific feature */ private getUsageInfoForFeature; /** * Get usage information for a specific action */ private getUsageInfoForAction; /** * Get usage information for a specific field */ private getUsageInfoForField; /** * Clear cache for a specific user */ private clearUserCache; /** * Clear all cache */ clearCache(): void; /** * Get debug information for a user (development only) */ getDebugInfo(userId: string): Promise<any>; } //# sourceMappingURL=monetization-service.d.ts.map