@hivetechs/hive-ai
Version:
Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API
134 lines (133 loc) • 3.38 kB
TypeScript
/**
* Modern License Gate System (2025 Best Practices)
*
* Features:
* - Pure ES Module design
* - Async-first architecture
* - Encrypted local storage
* - Multiple fallback strategies
* - Circuit breaker pattern
* - Comprehensive error handling
*/
export declare enum FeatureTier {
FREE = "free",
PREMIUM = "premium"
}
export interface LicenseStatus {
valid: boolean;
tier: FeatureTier;
userId?: string;
expiresAt?: number;
features: string[];
message?: string;
dailyLimit?: number;
user_id?: string;
email?: string;
subscription_status?: string;
max_devices?: number;
active_devices?: number;
}
export declare class ModernLicenseGate {
private static instance;
private licenseCache;
private readonly CACHE_TTL;
private readonly CONFIG_DIR;
private readonly LICENSE_FILE;
private readonly CIRCUIT_BREAKER_THRESHOLD;
private readonly CIRCUIT_BREAKER_TIMEOUT;
private quietMode;
private circuitBreaker;
private readonly freeFeatures;
private readonly premiumFeatures;
static getInstance(): ModernLicenseGate;
/**
* Enable quiet mode to suppress debug messages during interactive sessions
*/
setQuietMode(quiet: boolean): void;
/**
* Force refresh license cache (useful after plan upgrades)
*/
refreshLicense(): Promise<LicenseStatus>;
/**
* Clear stored license and cache (for logout)
*/
clearLicense(): Promise<void>;
/**
* Primary entry point for feature access validation
*/
checkFeatureAccess(feature: string): Promise<LicenseStatus>;
/**
* Validate license using multiple strategies
*/
private validateLicense;
/**
* Get license key from unified database storage
*/
private getLicenseKey;
/**
* Validate license with API using circuit breaker pattern
*/
private validateWithAPI;
/**
* Make API call with proper error handling
*/
private makeAPICall;
/**
* Store license key securely with encryption
*/
storeLicenseKey(licenseKey: string): Promise<void>;
/**
* Encrypt sensitive data
*/
private encryptData;
/**
* Decrypt sensitive data
*/
private decryptData;
/**
* Derive encryption key from system info
*/
private getDerivedKey;
/**
* Get stable machine identifier
*/
private getMachineId;
/**
* Get device fingerprint for API calls
*/
private getDeviceFingerprint;
/**
* Get version information
*/
private getVersion;
/**
* Get filesystem module with proper error handling
*/
private getFS;
/**
* Check if cache is valid
*/
private isCacheValid;
/**
* Cache license with encryption
*/
private cacheLicense;
/**
* Get cached license
*/
private getCachedLicense;
/**
* Create invalid license response
*/
private createInvalidLicense;
}
export declare class NoLicenseError extends Error {
constructor(feature: string);
}
export declare class PremiumFeatureError extends Error {
constructor(feature: string);
}
/**
* Decorator for protecting premium MCP tools
*/
export declare function requiresPremium(target: any, propertyName: string, descriptor: PropertyDescriptor): PropertyDescriptor;