UNPKG

@tamyla/ui-components-react

Version:

React-based UI component library with Factory Bridge pattern - integrates seamlessly with @tamyla/ui-components. Enhanced AI agent discoverability with structured component registry, comprehensive Storybook (8 components), and detailed guides.

198 lines (172 loc) โ€ข 5.61 kB
#!/usr/bin/env node /** * @fileoverview Simple license validation test * @description Tests license validation logic without full component imports */ // Mock localStorage for Node.js environment global.localStorage = { getItem: (key) => process.env[key] || null, setItem: (key, value) => { process.env[key] = value; }, removeItem: (key) => { delete process.env[key]; } }; // Mock process.env for license key process.env.TAMYLA_LICENSE_KEY = 'mock-license-key-12345'; console.log('๐Ÿงช Testing Tamyla UI Components License Validation (Standalone)\n'); // Test license validation logic directly function validateLicense(licenseKey) { // Mock validation - replace with actual license server validation if (!licenseKey || licenseKey.length < 10) { return { valid: false, error: 'Invalid license key format' }; } // Mock license data const mockLicense = { type: 'developer', expiry: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), // 1 year from now features: [ 'premium-components', 'advanced-theming', 'email-support', 'basic-analytics' ], restrictions: { maxUsers: 5, whiteLabel: false }, metadata: { issued: new Date(), licensee: 'Mock Licensee', licenseKey: licenseKey } }; const warnings = []; if (mockLicense.expiry < new Date()) { return { valid: false, error: 'License has expired', license: mockLicense }; } // Check if expiry is within 30 days const thirtyDaysFromNow = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000); if (mockLicense.expiry < thirtyDaysFromNow) { warnings.push(`License expires on ${mockLicense.expiry.toDateString()}`); } return { valid: true, license: mockLicense, warnings: warnings.length > 0 ? warnings : undefined }; } function checkFeatureAccess(feature, license) { if (!license) { // Free features that don't require a license const freeFeatures = [ 'button', 'card', 'input', 'typography', 'layout', 'design-tokens' ]; return freeFeatures.includes(feature.toLowerCase()); } return license.features.includes(feature.toLowerCase()); } function requireFeature(feature, license) { if (!checkFeatureAccess(feature, license)) { const upgradeUrl = 'https://tamyla.com/pricing'; throw new Error( `Feature '${feature}' requires a commercial license. ` + `Please upgrade at ${upgradeUrl}` ); } } function getLicenseStatus() { const license = getCurrentLicense(); if (!license) { return { hasLicense: false, features: [ 'button', 'card', 'input', 'typography', 'layout', 'design-tokens' ] }; } const validation = validateLicense(license.metadata?.licenseKey || ''); return { hasLicense: true, licenseType: license.type, expiryDate: license.expiry, features: license.features, warnings: validation.warnings }; } function getCurrentLicense() { // Check environment variable const envLicense = process.env.TAMYLA_LICENSE_KEY; if (envLicense) { const validation = validateLicense(envLicense); return validation.valid ? validation.license : undefined; } return undefined; } try { console.log('โœ… License validation functions defined\n'); // Test 1: Validate license console.log('๐Ÿ“‹ Test 1: License Validation'); const validation = validateLicense('mock-license-key-12345'); console.log('License valid:', validation.valid); if (validation.license) { console.log('License type:', validation.license.type); console.log('Expiry date:', validation.license.expiry.toDateString()); console.log('Features:', validation.license.features.join(', ')); } if (validation.warnings) { console.log('Warnings:', validation.warnings); } console.log(''); // Test 2: Check feature access console.log('๐Ÿ” Test 2: Feature Access Check'); console.log('Free feature (button):', checkFeatureAccess('button')); console.log('Premium feature (advanced-dashboard):', checkFeatureAccess('advanced-dashboard', validation.license)); console.log(''); // Test 3: Require feature (should not throw) console.log('โšก Test 3: Require Feature (Free)'); try { requireFeature('button'); console.log('โœ… Free feature access granted'); } catch (error) { console.log('โŒ Free feature access denied:', error.message); } console.log(''); // Test 4: Require premium feature (should throw) console.log('๐Ÿ’Ž Test 4: Require Premium Feature'); try { requireFeature('advanced-dashboard'); console.log('โœ… Premium feature access granted'); } catch (error) { console.log('โŒ Premium feature access denied:', error.message); } console.log(''); // Test 5: Get license status console.log('๐Ÿ“Š Test 5: License Status'); const status = getLicenseStatus(); console.log('Has license:', status.hasLicense); console.log('License type:', status.licenseType || 'None'); console.log('Available features:', status.features.join(', ')); if (status.warnings) { console.log('Warnings:', status.warnings); } console.log(''); console.log('๐ŸŽ‰ All license validation tests completed successfully!'); } catch (error) { console.error('โŒ License validation test failed:', error.message); process.exit(1); }