@moontra/moonui-pro 2.37.18 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/index.global.js +126 -126
- package/dist/cdn/index.global.js.map +1 -1
- package/dist/index.mjs +40 -0
- package/dist/server.d.ts +26 -1
- package/dist/server.mjs +74 -5
- package/package.json +2 -1
- package/scripts/postinstall.cjs +199 -0
package/dist/index.mjs
CHANGED
|
@@ -2114,6 +2114,29 @@ var AUTH_CONFIG = {
|
|
|
2114
2114
|
session: "x-moonui-session-id"
|
|
2115
2115
|
}
|
|
2116
2116
|
};
|
|
2117
|
+
|
|
2118
|
+
// src/lib/license-token-client.ts
|
|
2119
|
+
function readLicenseTokenClient() {
|
|
2120
|
+
try {
|
|
2121
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
2122
|
+
return null;
|
|
2123
|
+
}
|
|
2124
|
+
const storedToken = localStorage.getItem("moonui_license_token");
|
|
2125
|
+
if (!storedToken) {
|
|
2126
|
+
return null;
|
|
2127
|
+
}
|
|
2128
|
+
const token = JSON.parse(storedToken);
|
|
2129
|
+
if (token.expiresAt < Date.now()) {
|
|
2130
|
+
console.log("[MoonUI] Client license token expired");
|
|
2131
|
+
localStorage.removeItem("moonui_license_token");
|
|
2132
|
+
return null;
|
|
2133
|
+
}
|
|
2134
|
+
return token;
|
|
2135
|
+
} catch (error) {
|
|
2136
|
+
console.error("[MoonUI] Error reading client license token:", error);
|
|
2137
|
+
return null;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2117
2140
|
var AuthContext = createContext(void 0);
|
|
2118
2141
|
var authPromise = null;
|
|
2119
2142
|
var lastFetchTime = 0;
|
|
@@ -2159,6 +2182,23 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2159
2182
|
console.log("[MoonUI Auth] Using ongoing request");
|
|
2160
2183
|
return authPromise;
|
|
2161
2184
|
}
|
|
2185
|
+
const licenseToken = readLicenseTokenClient();
|
|
2186
|
+
if (licenseToken && licenseToken.hasProAccess) {
|
|
2187
|
+
console.log("[MoonUI Auth] Using embedded license token - Pro access granted");
|
|
2188
|
+
const tokenState = {
|
|
2189
|
+
isLoading: false,
|
|
2190
|
+
hasProAccess: true,
|
|
2191
|
+
isAuthenticated: true,
|
|
2192
|
+
subscriptionPlan: licenseToken.plan === "lifetime" ? "lifetime" : "free",
|
|
2193
|
+
subscription: {
|
|
2194
|
+
status: "active",
|
|
2195
|
+
plan: licenseToken.plan === "lifetime" ? "lifetime" : "free"
|
|
2196
|
+
},
|
|
2197
|
+
isAdmin: false
|
|
2198
|
+
};
|
|
2199
|
+
setState(tokenState);
|
|
2200
|
+
return tokenState;
|
|
2201
|
+
}
|
|
2162
2202
|
if (!forceRefresh2) {
|
|
2163
2203
|
const cached = readValidationFromCookie();
|
|
2164
2204
|
if (cached && cached.valid) {
|
package/dist/server.d.ts
CHANGED
|
@@ -100,4 +100,29 @@ type AuthConfig = typeof AUTH_CONFIG;
|
|
|
100
100
|
type CacheConfig = typeof AUTH_CONFIG.cache;
|
|
101
101
|
type SecurityConfig = typeof AUTH_CONFIG.security;
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
/**
|
|
104
|
+
* License Token Reader
|
|
105
|
+
* Reads and decrypts the license token created by postinstall script
|
|
106
|
+
*/
|
|
107
|
+
interface LicenseToken {
|
|
108
|
+
valid: boolean;
|
|
109
|
+
hasProAccess: boolean;
|
|
110
|
+
plan: string;
|
|
111
|
+
expiresAt: number;
|
|
112
|
+
domain: string;
|
|
113
|
+
timestamp: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Read license token from file system (for server-side)
|
|
117
|
+
*/
|
|
118
|
+
declare function readLicenseTokenServer(): LicenseToken | null;
|
|
119
|
+
/**
|
|
120
|
+
* Read license token (server-side only)
|
|
121
|
+
*/
|
|
122
|
+
declare function readLicenseToken(): LicenseToken | null;
|
|
123
|
+
/**
|
|
124
|
+
* Check if Pro features are enabled from license token
|
|
125
|
+
*/
|
|
126
|
+
declare function hasProAccessFromToken(): boolean;
|
|
127
|
+
|
|
128
|
+
export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, hasProAccessFromToken, performServerValidation, readLicenseToken, readLicenseTokenServer, setValidationInCookies, validateWithMoonUIServer };
|
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
import crypto__default from 'crypto';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @moontra/moonui-pro v2.0.9
|
|
@@ -3026,14 +3027,14 @@ var AUTH_CONFIG = {
|
|
|
3026
3027
|
};
|
|
3027
3028
|
var ENCRYPTION_KEY = process.env.MOONUI_ENCRYPTION_KEY || "moonui-pro-default-key-change-in-production";
|
|
3028
3029
|
function encryptData(data) {
|
|
3029
|
-
const cipher =
|
|
3030
|
+
const cipher = crypto__default.createCipher("aes-256-cbc", ENCRYPTION_KEY);
|
|
3030
3031
|
let encrypted = cipher.update(JSON.stringify(data), "utf8", "hex");
|
|
3031
3032
|
encrypted += cipher.final("hex");
|
|
3032
3033
|
return encrypted;
|
|
3033
3034
|
}
|
|
3034
3035
|
function decryptData(encryptedData) {
|
|
3035
3036
|
try {
|
|
3036
|
-
const decipher =
|
|
3037
|
+
const decipher = crypto__default.createDecipher("aes-256-cbc", ENCRYPTION_KEY);
|
|
3037
3038
|
let decrypted = decipher.update(encryptedData, "hex", "utf8");
|
|
3038
3039
|
decrypted += decipher.final("utf8");
|
|
3039
3040
|
return JSON.parse(decrypted);
|
|
@@ -3050,7 +3051,7 @@ async function generateServerDeviceFingerprint() {
|
|
|
3050
3051
|
headersList.get("accept-encoding") || "unknown",
|
|
3051
3052
|
headersList.get("x-forwarded-for") || headersList.get("x-real-ip") || "unknown"
|
|
3052
3053
|
];
|
|
3053
|
-
const fingerprint =
|
|
3054
|
+
const fingerprint = crypto__default.createHash("sha256").update(components.join("|")).digest("hex");
|
|
3054
3055
|
return fingerprint;
|
|
3055
3056
|
}
|
|
3056
3057
|
async function validateWithMoonUIServer(token, deviceId) {
|
|
@@ -3147,6 +3148,74 @@ async function performServerValidation() {
|
|
|
3147
3148
|
}
|
|
3148
3149
|
return { ...result, cached: false };
|
|
3149
3150
|
}
|
|
3151
|
+
function decryptToken(encryptedData, key) {
|
|
3152
|
+
try {
|
|
3153
|
+
const algorithm = "aes-256-gcm";
|
|
3154
|
+
const salt = Buffer.from(encryptedData.salt, "hex");
|
|
3155
|
+
const derivedKey = crypto.pbkdf2Sync(key, salt, 1e5, 32, "sha256");
|
|
3156
|
+
const iv = Buffer.from(encryptedData.iv, "hex");
|
|
3157
|
+
const authTag = Buffer.from(encryptedData.authTag, "hex");
|
|
3158
|
+
const decipher = crypto.createDecipheriv(algorithm, derivedKey, iv);
|
|
3159
|
+
decipher.setAuthTag(authTag);
|
|
3160
|
+
let decrypted = decipher.update(encryptedData.encrypted, "hex", "utf8");
|
|
3161
|
+
decrypted += decipher.final("utf8");
|
|
3162
|
+
return JSON.parse(decrypted);
|
|
3163
|
+
} catch (error) {
|
|
3164
|
+
console.error("[MoonUI] Failed to decrypt license token:", error);
|
|
3165
|
+
return null;
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
function readLicenseTokenServer() {
|
|
3169
|
+
try {
|
|
3170
|
+
if (typeof window !== "undefined") {
|
|
3171
|
+
return null;
|
|
3172
|
+
}
|
|
3173
|
+
const fs = __require("fs");
|
|
3174
|
+
const path = __require("path");
|
|
3175
|
+
const possiblePaths = [
|
|
3176
|
+
path.join(process.cwd(), ".moonui-license"),
|
|
3177
|
+
path.join(process.cwd(), "..", ".moonui-license"),
|
|
3178
|
+
path.join(process.cwd(), "..", "..", ".moonui-license"),
|
|
3179
|
+
path.join(__dirname, "..", "..", "..", "..", ".moonui-license")
|
|
3180
|
+
];
|
|
3181
|
+
let encryptedData = null;
|
|
3182
|
+
let foundPath = null;
|
|
3183
|
+
for (const filePath of possiblePaths) {
|
|
3184
|
+
if (fs.existsSync(filePath)) {
|
|
3185
|
+
foundPath = filePath;
|
|
3186
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
3187
|
+
encryptedData = JSON.parse(fileContent);
|
|
3188
|
+
break;
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
if (!encryptedData || !foundPath) {
|
|
3192
|
+
console.log("[MoonUI] No license file found");
|
|
3193
|
+
return null;
|
|
3194
|
+
}
|
|
3195
|
+
const decryptionKey = process.env.MOONUI_LICENSE_KEY || process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || "default-key";
|
|
3196
|
+
const token = decryptToken(encryptedData, decryptionKey);
|
|
3197
|
+
if (!token) {
|
|
3198
|
+
console.log("[MoonUI] Failed to decrypt license token");
|
|
3199
|
+
return null;
|
|
3200
|
+
}
|
|
3201
|
+
if (token.expiresAt < Date.now()) {
|
|
3202
|
+
console.log("[MoonUI] License token expired, re-validation required");
|
|
3203
|
+
return null;
|
|
3204
|
+
}
|
|
3205
|
+
console.log("[MoonUI] License token loaded successfully from:", foundPath);
|
|
3206
|
+
return token;
|
|
3207
|
+
} catch (error) {
|
|
3208
|
+
console.error("[MoonUI] Error reading license token:", error);
|
|
3209
|
+
return null;
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
function readLicenseToken() {
|
|
3213
|
+
return readLicenseTokenServer();
|
|
3214
|
+
}
|
|
3215
|
+
function hasProAccessFromToken() {
|
|
3216
|
+
const token = readLicenseToken();
|
|
3217
|
+
return token ? token.hasProAccess : false;
|
|
3218
|
+
}
|
|
3150
3219
|
|
|
3151
3220
|
// src/server.ts
|
|
3152
3221
|
if (typeof window !== "undefined") {
|
|
@@ -3155,4 +3224,4 @@ if (typeof window !== "undefined") {
|
|
|
3155
3224
|
);
|
|
3156
3225
|
}
|
|
3157
3226
|
|
|
3158
|
-
export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
|
|
3227
|
+
export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, hasProAccessFromToken, performServerValidation, readLicenseToken, readLicenseTokenServer, setValidationInCookies, validateWithMoonUIServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moontra/moonui-pro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Premium React components for MoonUI - Advanced UI library with 50+ pro components including performance, interactive, and gesture components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"test:watch": "jest --watch",
|
|
52
52
|
"test:coverage": "jest --coverage",
|
|
53
53
|
"prepublishOnly": "npm run clean && npm run build",
|
|
54
|
+
"postinstall": "node scripts/postinstall.cjs",
|
|
54
55
|
"pub": "npm version patch && npm run build && npm publish",
|
|
55
56
|
"pub:minor": "npm version minor && npm run build && npm publish",
|
|
56
57
|
"pub:major": "npm version major && npm run build && npm publish"
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MoonUI Pro PostInstall Script
|
|
5
|
+
* Automatically validates license in production environments during npm install
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const crypto = require('crypto');
|
|
11
|
+
const https = require('https');
|
|
12
|
+
|
|
13
|
+
// Configuration
|
|
14
|
+
const LICENSE_FILE = '.moonui-license';
|
|
15
|
+
const API_URL = 'https://moonui.dev/api/v1/license/validate';
|
|
16
|
+
const CACHE_DURATION = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
|
|
17
|
+
|
|
18
|
+
// Detect if we're in production environment
|
|
19
|
+
function isProduction() {
|
|
20
|
+
return (
|
|
21
|
+
process.env.NODE_ENV === 'production' ||
|
|
22
|
+
process.env.VERCEL === '1' ||
|
|
23
|
+
process.env.NETLIFY === 'true' ||
|
|
24
|
+
process.env.CI === 'true' ||
|
|
25
|
+
process.env.MOONUI_AUTH_TOKEN // Special token for CI/CD
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Encrypt token for storage
|
|
30
|
+
function encryptToken(token, key) {
|
|
31
|
+
const algorithm = 'aes-256-gcm';
|
|
32
|
+
const salt = crypto.randomBytes(16);
|
|
33
|
+
const derivedKey = crypto.pbkdf2Sync(key, salt, 100000, 32, 'sha256');
|
|
34
|
+
const iv = crypto.randomBytes(16);
|
|
35
|
+
const cipher = crypto.createCipheriv(algorithm, derivedKey, iv);
|
|
36
|
+
|
|
37
|
+
let encrypted = cipher.update(JSON.stringify(token), 'utf8', 'hex');
|
|
38
|
+
encrypted += cipher.final('hex');
|
|
39
|
+
|
|
40
|
+
const authTag = cipher.getAuthTag();
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
encrypted,
|
|
44
|
+
salt: salt.toString('hex'),
|
|
45
|
+
iv: iv.toString('hex'),
|
|
46
|
+
authTag: authTag.toString('hex')
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Validate license with MoonUI API
|
|
51
|
+
async function validateLicense(licenseKey) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const postData = JSON.stringify({
|
|
54
|
+
licenseKey,
|
|
55
|
+
domain: process.env.VERCEL_URL || process.env.DEPLOY_URL || 'unknown',
|
|
56
|
+
environment: 'production'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const options = {
|
|
60
|
+
hostname: 'moonui.dev',
|
|
61
|
+
port: 443,
|
|
62
|
+
path: '/api/v1/license/validate',
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type': 'application/json',
|
|
66
|
+
'Content-Length': Buffer.byteLength(postData),
|
|
67
|
+
'X-PostInstall': 'true',
|
|
68
|
+
'X-Environment': process.env.VERCEL ? 'vercel' : process.env.NETLIFY ? 'netlify' : 'unknown'
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const req = https.request(options, (res) => {
|
|
73
|
+
let data = '';
|
|
74
|
+
|
|
75
|
+
res.on('data', (chunk) => {
|
|
76
|
+
data += chunk;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
res.on('end', () => {
|
|
80
|
+
try {
|
|
81
|
+
const result = JSON.parse(data);
|
|
82
|
+
if (res.statusCode === 200 && result.valid) {
|
|
83
|
+
resolve(result);
|
|
84
|
+
} else {
|
|
85
|
+
reject(new Error(result.error || 'License validation failed'));
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
reject(error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
req.on('error', (error) => {
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
req.write(postData);
|
|
98
|
+
req.end();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Save license token to file
|
|
103
|
+
function saveLicenseToken(token) {
|
|
104
|
+
try {
|
|
105
|
+
// Find the project root (where package.json is)
|
|
106
|
+
let projectRoot = process.cwd();
|
|
107
|
+
let attempts = 0;
|
|
108
|
+
|
|
109
|
+
while (attempts < 10) {
|
|
110
|
+
if (fs.existsSync(path.join(projectRoot, 'package.json'))) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
projectRoot = path.dirname(projectRoot);
|
|
114
|
+
attempts++;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const licenseFilePath = path.join(projectRoot, LICENSE_FILE);
|
|
118
|
+
|
|
119
|
+
// Encrypt token with a deterministic key based on environment
|
|
120
|
+
const encryptionKey = process.env.MOONUI_LICENSE_KEY || 'default-key';
|
|
121
|
+
const encryptedData = encryptToken(token, encryptionKey);
|
|
122
|
+
|
|
123
|
+
// Save to file
|
|
124
|
+
fs.writeFileSync(licenseFilePath, JSON.stringify(encryptedData, null, 2));
|
|
125
|
+
|
|
126
|
+
console.log('[MoonUI Pro] ✓ License token saved successfully');
|
|
127
|
+
return true;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error('[MoonUI Pro] Failed to save license token:', error.message);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Main postinstall logic
|
|
135
|
+
async function main() {
|
|
136
|
+
try {
|
|
137
|
+
// Only run in production environments
|
|
138
|
+
if (!isProduction()) {
|
|
139
|
+
console.log('[MoonUI Pro] Development environment detected, skipping license validation');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log('[MoonUI Pro] Production environment detected, checking license...');
|
|
144
|
+
|
|
145
|
+
// Check for license key in environment variables
|
|
146
|
+
const licenseKey = process.env.MOONUI_LICENSE_KEY ||
|
|
147
|
+
process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY ||
|
|
148
|
+
process.env.VITE_MOONUI_LICENSE_KEY ||
|
|
149
|
+
process.env.REACT_APP_MOONUI_LICENSE_KEY;
|
|
150
|
+
|
|
151
|
+
if (!licenseKey) {
|
|
152
|
+
console.log('[MoonUI Pro] No license key found in environment variables');
|
|
153
|
+
console.log('[MoonUI Pro] Set MOONUI_LICENSE_KEY to enable Pro features');
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
console.log('[MoonUI Pro] Validating license key...');
|
|
158
|
+
|
|
159
|
+
// Validate license with API
|
|
160
|
+
const validationResult = await validateLicense(licenseKey);
|
|
161
|
+
|
|
162
|
+
if (validationResult.valid && validationResult.hasProAccess) {
|
|
163
|
+
// Create token with validation result and expiry
|
|
164
|
+
const token = {
|
|
165
|
+
valid: true,
|
|
166
|
+
hasProAccess: validationResult.hasProAccess,
|
|
167
|
+
plan: validationResult.plan,
|
|
168
|
+
expiresAt: Date.now() + CACHE_DURATION,
|
|
169
|
+
domain: validationResult.domain,
|
|
170
|
+
timestamp: Date.now()
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// Save encrypted token
|
|
174
|
+
saveLicenseToken(token);
|
|
175
|
+
|
|
176
|
+
console.log('[MoonUI Pro] ✓ License validated successfully');
|
|
177
|
+
console.log('[MoonUI Pro] ✓ Pro features enabled');
|
|
178
|
+
} else {
|
|
179
|
+
console.log('[MoonUI Pro] License validation failed');
|
|
180
|
+
console.log('[MoonUI Pro] Pro features will be disabled');
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error('[MoonUI Pro] Error during postinstall:', error.message);
|
|
184
|
+
console.log('[MoonUI Pro] Continuing with Free plan');
|
|
185
|
+
|
|
186
|
+
// Don't fail the install process
|
|
187
|
+
process.exit(0);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Run if called directly (not imported)
|
|
192
|
+
if (require.main === module) {
|
|
193
|
+
main().catch(error => {
|
|
194
|
+
console.error('[MoonUI Pro] Unexpected error:', error);
|
|
195
|
+
process.exit(0); // Don't fail npm install
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = { validateLicense, saveLicenseToken, isProduction };
|