@moontra/moonui-pro 3.1.1 → 3.2.1
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 +124 -124
- package/dist/cdn/index.global.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.mjs +25 -158
- package/package.json +1 -1
- package/scripts/postinstall.cjs +41 -2
package/dist/index.d.ts
CHANGED
|
@@ -147,15 +147,16 @@ interface AuthContextType extends AuthState {
|
|
|
147
147
|
clearAuth: () => void;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* MoonUI Auth Provider -
|
|
151
|
-
*
|
|
150
|
+
* MoonUI Auth Provider - Simplified Authentication
|
|
151
|
+
* 1. Check embedded license token (from PostInstall)
|
|
152
|
+
* 2. Check localhost CLI auth server (development only)
|
|
153
|
+
* 3. No production API calls from browser
|
|
152
154
|
*/
|
|
153
155
|
declare function MoonUIAuthProvider({ children }: {
|
|
154
156
|
children: ReactNode;
|
|
155
157
|
}): react_jsx_runtime.JSX.Element;
|
|
156
158
|
/**
|
|
157
159
|
* Hook to use auth context
|
|
158
|
-
* Falls back to direct API call if context is not available
|
|
159
160
|
*/
|
|
160
161
|
declare function useMoonUIAuth(): AuthContextType;
|
|
161
162
|
|
package/dist/index.mjs
CHANGED
|
@@ -2165,24 +2165,6 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2165
2165
|
isAdmin: false
|
|
2166
2166
|
});
|
|
2167
2167
|
const isMounted = useRef(true);
|
|
2168
|
-
const readValidationFromCookie = () => {
|
|
2169
|
-
if (typeof document === "undefined")
|
|
2170
|
-
return null;
|
|
2171
|
-
try {
|
|
2172
|
-
const cookies = document.cookie.split(";");
|
|
2173
|
-
const statusCookie = cookies.find(
|
|
2174
|
-
(c2) => c2.trim().startsWith("moonui_pro_status=")
|
|
2175
|
-
);
|
|
2176
|
-
if (statusCookie) {
|
|
2177
|
-
const value2 = statusCookie.split("=")[1];
|
|
2178
|
-
const decoded = decodeURIComponent(value2);
|
|
2179
|
-
return JSON.parse(decoded);
|
|
2180
|
-
}
|
|
2181
|
-
} catch (error) {
|
|
2182
|
-
console.error("[MoonUI Auth] Error reading cookie:", error);
|
|
2183
|
-
}
|
|
2184
|
-
return null;
|
|
2185
|
-
};
|
|
2186
2168
|
const validateAuth = async (forceRefresh2 = false) => {
|
|
2187
2169
|
const now = Date.now();
|
|
2188
2170
|
if (!forceRefresh2 && now - lastFetchTime < FETCH_COOLDOWN) {
|
|
@@ -2193,79 +2175,34 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2193
2175
|
console.log("[MoonUI Auth] Using ongoing request");
|
|
2194
2176
|
return authPromise;
|
|
2195
2177
|
}
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
subscriptionPlan: licenseToken.plan === "lifetime" ? "lifetime" : "free",
|
|
2204
|
-
subscription: {
|
|
2205
|
-
status: "active",
|
|
2206
|
-
plan: licenseToken.plan === "lifetime" ? "lifetime" : "free"
|
|
2207
|
-
},
|
|
2208
|
-
isAdmin: false
|
|
2209
|
-
};
|
|
2210
|
-
setState(tokenState);
|
|
2211
|
-
return tokenState;
|
|
2212
|
-
}
|
|
2213
|
-
if (!forceRefresh2) {
|
|
2214
|
-
const cached = readValidationFromCookie();
|
|
2215
|
-
if (cached && cached.valid) {
|
|
2216
|
-
const age = now - cached.timestamp;
|
|
2217
|
-
const maxAge = AUTH_CONFIG.cache.serverCacheDuration;
|
|
2218
|
-
if (age < maxAge) {
|
|
2219
|
-
console.log("[MoonUI Auth] Using cookie cache");
|
|
2220
|
-
const cachedState2 = {
|
|
2178
|
+
authPromise = (async () => {
|
|
2179
|
+
try {
|
|
2180
|
+
lastFetchTime = now;
|
|
2181
|
+
const licenseToken = readLicenseTokenClient();
|
|
2182
|
+
if (licenseToken && licenseToken.hasProAccess) {
|
|
2183
|
+
console.log("[MoonUI Auth] Using embedded license token - Pro access granted");
|
|
2184
|
+
const tokenState = {
|
|
2221
2185
|
isLoading: false,
|
|
2222
|
-
hasProAccess:
|
|
2223
|
-
isAuthenticated:
|
|
2224
|
-
subscriptionPlan:
|
|
2186
|
+
hasProAccess: true,
|
|
2187
|
+
isAuthenticated: true,
|
|
2188
|
+
subscriptionPlan: licenseToken.plan === "lifetime" ? "lifetime" : "free",
|
|
2225
2189
|
subscription: {
|
|
2226
|
-
status:
|
|
2227
|
-
plan:
|
|
2190
|
+
status: "active",
|
|
2191
|
+
plan: licenseToken.plan === "lifetime" ? "lifetime" : "free"
|
|
2228
2192
|
},
|
|
2229
2193
|
isAdmin: false
|
|
2230
2194
|
};
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
authPromise = (async () => {
|
|
2237
|
-
try {
|
|
2238
|
-
lastFetchTime = now;
|
|
2239
|
-
let isProduction = false;
|
|
2240
|
-
let isDevelopment = true;
|
|
2241
|
-
let environmentInfo = {};
|
|
2242
|
-
try {
|
|
2243
|
-
const envResponse = await fetch("/api/environment", {
|
|
2244
|
-
method: "GET",
|
|
2245
|
-
cache: "no-store"
|
|
2246
|
-
});
|
|
2247
|
-
if (envResponse.ok) {
|
|
2248
|
-
environmentInfo = await envResponse.json();
|
|
2249
|
-
isProduction = environmentInfo.isProduction;
|
|
2250
|
-
isDevelopment = environmentInfo.isDevelopment;
|
|
2251
|
-
console.log("[MoonUI Auth] Runtime Environment Detection:", {
|
|
2252
|
-
...environmentInfo.debug,
|
|
2253
|
-
environment: environmentInfo.environment,
|
|
2254
|
-
isProduction,
|
|
2255
|
-
isDevelopment
|
|
2256
|
-
});
|
|
2257
|
-
} else {
|
|
2258
|
-
console.warn("[MoonUI Auth] Failed to fetch environment info, falling back to development mode");
|
|
2195
|
+
if (isMounted.current) {
|
|
2196
|
+
setState(tokenState);
|
|
2259
2197
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2198
|
+
authPromise = null;
|
|
2199
|
+
return tokenState;
|
|
2262
2200
|
}
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
const authServerUrl = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_MOONUI_AUTH_SERVER || "http://localhost:7878" : "http://localhost:7878";
|
|
2201
|
+
const isLocalhost = typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1");
|
|
2202
|
+
if (isLocalhost) {
|
|
2266
2203
|
try {
|
|
2267
|
-
console.log("[MoonUI Auth] Development mode - checking CLI auth server
|
|
2268
|
-
response = await fetch(
|
|
2204
|
+
console.log("[MoonUI Auth] Development mode - checking CLI auth server");
|
|
2205
|
+
const response = await fetch("http://localhost:7878/validate", {
|
|
2269
2206
|
method: "GET",
|
|
2270
2207
|
headers: {
|
|
2271
2208
|
"X-Component": "MoonUIAuthProvider",
|
|
@@ -2274,7 +2211,7 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2274
2211
|
credentials: "include"
|
|
2275
2212
|
});
|
|
2276
2213
|
if (response && response.ok) {
|
|
2277
|
-
console.log("[MoonUI Auth]
|
|
2214
|
+
console.log("[MoonUI Auth] CLI auth server available");
|
|
2278
2215
|
const data = await response.json();
|
|
2279
2216
|
if (data.valid && data.hasProAccess) {
|
|
2280
2217
|
saveLicenseTokenClient({
|
|
@@ -2302,79 +2239,12 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2302
2239
|
}
|
|
2303
2240
|
authPromise = null;
|
|
2304
2241
|
return newState;
|
|
2305
|
-
} else {
|
|
2306
|
-
throw new Error("Auth server not available");
|
|
2307
2242
|
}
|
|
2308
2243
|
} catch (error) {
|
|
2309
|
-
console.log('[MoonUI Auth]
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
if (isProduction) {
|
|
2313
|
-
const licenseKey = environmentInfo.hasLicenseKey ? process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || process.env.MOONUI_LICENSE_KEY || process.env.VITE_MOONUI_LICENSE_KEY || process.env.REACT_APP_MOONUI_LICENSE_KEY || "check-server" : null;
|
|
2314
|
-
if (licenseKey) {
|
|
2315
|
-
console.log("[MoonUI Auth] Production mode - validating license key...");
|
|
2316
|
-
try {
|
|
2317
|
-
const currentDomain = typeof window !== "undefined" ? window.location.hostname : process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || "";
|
|
2318
|
-
const apiUrl = "https://moonui.dev/api/v1/license/validate";
|
|
2319
|
-
const validationResponse = await fetch(apiUrl, {
|
|
2320
|
-
method: "POST",
|
|
2321
|
-
headers: {
|
|
2322
|
-
"Content-Type": "application/json"
|
|
2323
|
-
},
|
|
2324
|
-
body: JSON.stringify({
|
|
2325
|
-
licenseKey,
|
|
2326
|
-
domain: currentDomain
|
|
2327
|
-
})
|
|
2328
|
-
});
|
|
2329
|
-
if (validationResponse.ok) {
|
|
2330
|
-
const validationData = await validationResponse.json();
|
|
2331
|
-
if (validationData.valid && validationData.hasProAccess) {
|
|
2332
|
-
console.log("[MoonUI Auth] License key validated successfully");
|
|
2333
|
-
saveLicenseTokenClient({
|
|
2334
|
-
valid: true,
|
|
2335
|
-
hasProAccess: validationData.hasProAccess,
|
|
2336
|
-
plan: validationData.plan || "lifetime",
|
|
2337
|
-
expiresAt: validationData.expiresAt || Date.now() + 30 * 24 * 60 * 60 * 1e3,
|
|
2338
|
-
domain: currentDomain || "production",
|
|
2339
|
-
timestamp: Date.now()
|
|
2340
|
-
});
|
|
2341
|
-
const newState = {
|
|
2342
|
-
isLoading: false,
|
|
2343
|
-
hasProAccess: validationData.hasProAccess,
|
|
2344
|
-
isAuthenticated: true,
|
|
2345
|
-
subscriptionPlan: validationData.plan === "lifetime" ? "lifetime" : "free",
|
|
2346
|
-
subscription: {
|
|
2347
|
-
status: validationData.hasProAccess ? "active" : "inactive",
|
|
2348
|
-
plan: validationData.plan === "lifetime" ? "lifetime" : "free"
|
|
2349
|
-
},
|
|
2350
|
-
isAdmin: false
|
|
2351
|
-
};
|
|
2352
|
-
if (typeof document !== "undefined" && validationData.cacheDuration) {
|
|
2353
|
-
const cacheData = {
|
|
2354
|
-
valid: true,
|
|
2355
|
-
hasProAccess: validationData.hasProAccess,
|
|
2356
|
-
timestamp: Date.now()
|
|
2357
|
-
};
|
|
2358
|
-
document.cookie = `moonui_pro_status=${encodeURIComponent(
|
|
2359
|
-
JSON.stringify(cacheData)
|
|
2360
|
-
)}; max-age=${Math.floor(validationData.cacheDuration / 1e3)}; path=/; SameSite=Strict`;
|
|
2361
|
-
}
|
|
2362
|
-
if (isMounted.current) {
|
|
2363
|
-
setState(newState);
|
|
2364
|
-
}
|
|
2365
|
-
authPromise = null;
|
|
2366
|
-
return newState;
|
|
2367
|
-
} else {
|
|
2368
|
-
console.warn("[MoonUI Auth] License key validation failed:", validationData.error || "Invalid license");
|
|
2369
|
-
}
|
|
2370
|
-
} else {
|
|
2371
|
-
console.error("[MoonUI Auth] License validation request failed:", validationResponse.status);
|
|
2372
|
-
}
|
|
2373
|
-
} catch (error) {
|
|
2374
|
-
console.error("[MoonUI Auth] License validation error:", error);
|
|
2375
|
-
}
|
|
2244
|
+
console.log('[MoonUI Auth] CLI auth server not available. Run "moonui dev" to enable Pro features.');
|
|
2376
2245
|
}
|
|
2377
2246
|
}
|
|
2247
|
+
console.log("[MoonUI Auth] No authentication available - using free plan");
|
|
2378
2248
|
const freeState = {
|
|
2379
2249
|
isLoading: false,
|
|
2380
2250
|
hasProAccess: false,
|
|
@@ -2407,9 +2277,8 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2407
2277
|
if (isMounted.current) {
|
|
2408
2278
|
setState(errorState);
|
|
2409
2279
|
}
|
|
2410
|
-
return errorState;
|
|
2411
|
-
} finally {
|
|
2412
2280
|
authPromise = null;
|
|
2281
|
+
return errorState;
|
|
2413
2282
|
}
|
|
2414
2283
|
})();
|
|
2415
2284
|
return authPromise;
|
|
@@ -2427,8 +2296,6 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2427
2296
|
};
|
|
2428
2297
|
const clearAuth2 = () => {
|
|
2429
2298
|
console.log("[MoonUI Auth] Clearing auth");
|
|
2430
|
-
document.cookie = "moonui_pro_status=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
2431
|
-
document.cookie = "moonui_auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
2432
2299
|
setState({
|
|
2433
2300
|
isLoading: false,
|
|
2434
2301
|
hasProAccess: false,
|
|
@@ -2453,7 +2320,7 @@ function MoonUIAuthProvider({ children }) {
|
|
|
2453
2320
|
function useMoonUIAuth() {
|
|
2454
2321
|
const context = useContext(AuthContext);
|
|
2455
2322
|
if (!context) {
|
|
2456
|
-
console.warn("[MoonUI Auth] No AuthProvider found,
|
|
2323
|
+
console.warn("[MoonUI Auth] No AuthProvider found, using free plan");
|
|
2457
2324
|
return {
|
|
2458
2325
|
isLoading: false,
|
|
2459
2326
|
hasProAccess: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moontra/moonui-pro",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
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",
|
package/scripts/postinstall.cjs
CHANGED
|
@@ -50,10 +50,31 @@ function encryptToken(token, key) {
|
|
|
50
50
|
// Validate license with MoonUI API
|
|
51
51
|
async function validateLicense(licenseKey) {
|
|
52
52
|
return new Promise((resolve, reject) => {
|
|
53
|
+
// Determine the domain
|
|
54
|
+
let domain = 'unknown';
|
|
55
|
+
|
|
56
|
+
// Check for Vercel deployment
|
|
57
|
+
if (process.env.VERCEL_URL) {
|
|
58
|
+
domain = process.env.VERCEL_URL.replace(/^https?:\/\//, '');
|
|
59
|
+
} else if (process.env.VERCEL_PROJECT_PRODUCTION_URL) {
|
|
60
|
+
domain = process.env.VERCEL_PROJECT_PRODUCTION_URL.replace(/^https?:\/\//, '');
|
|
61
|
+
} else if (process.env.NEXT_PUBLIC_VERCEL_URL) {
|
|
62
|
+
domain = process.env.NEXT_PUBLIC_VERCEL_URL.replace(/^https?:\/\//, '');
|
|
63
|
+
} else if (process.env.DEPLOY_URL) {
|
|
64
|
+
domain = process.env.DEPLOY_URL.replace(/^https?:\/\//, '');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// For moonui.dev site, use special validation
|
|
68
|
+
const isMoonUISite = domain.includes('moonui.dev') ||
|
|
69
|
+
domain.includes('moonui-git') ||
|
|
70
|
+
domain.includes('moonui-') ||
|
|
71
|
+
process.env.MOONUI_SITE === 'true';
|
|
72
|
+
|
|
53
73
|
const postData = JSON.stringify({
|
|
54
74
|
licenseKey,
|
|
55
|
-
domain:
|
|
56
|
-
environment: 'production'
|
|
75
|
+
domain: isMoonUISite ? 'moonui.dev' : domain,
|
|
76
|
+
environment: 'production',
|
|
77
|
+
isMoonUISite
|
|
57
78
|
});
|
|
58
79
|
|
|
59
80
|
const options = {
|
|
@@ -142,6 +163,24 @@ async function main() {
|
|
|
142
163
|
|
|
143
164
|
console.log('[MoonUI Pro] Production environment detected, checking license...');
|
|
144
165
|
|
|
166
|
+
// Special case: moonui.dev site itself always has Pro access
|
|
167
|
+
const vercelUrl = process.env.VERCEL_URL || process.env.VERCEL_PROJECT_PRODUCTION_URL || '';
|
|
168
|
+
if (vercelUrl.includes('moonui.dev') || vercelUrl.includes('moonui-git') ||
|
|
169
|
+
process.env.MOONUI_SITE === 'true') {
|
|
170
|
+
console.log('[MoonUI Pro] MoonUI site detected - granting Pro access');
|
|
171
|
+
const token = {
|
|
172
|
+
valid: true,
|
|
173
|
+
hasProAccess: true,
|
|
174
|
+
plan: 'lifetime',
|
|
175
|
+
expiresAt: Date.now() + CACHE_DURATION,
|
|
176
|
+
domain: 'moonui.dev',
|
|
177
|
+
timestamp: Date.now()
|
|
178
|
+
};
|
|
179
|
+
saveLicenseToken(token);
|
|
180
|
+
console.log('[MoonUI Pro] ✓ Pro features enabled for moonui.dev');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
145
184
|
// Check for license key in environment variables
|
|
146
185
|
const licenseKey = process.env.MOONUI_LICENSE_KEY ||
|
|
147
186
|
process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY ||
|