@moontra/moonui-pro 2.37.16 → 2.37.17

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/index.mjs CHANGED
@@ -2239,62 +2239,47 @@ function MoonUIAuthProvider({
2239
2239
  console.log('[MoonUI Auth] Auth server not available in development. Run "moonui dev" to enable Pro features.');
2240
2240
  }
2241
2241
  }
2242
- if (isProduction) {
2243
- if (licenseKey) {
2244
- console.log("[MoonUI Auth] Production mode - validating license key...");
2245
- try {
2246
- const currentDomain = typeof window !== "undefined" ? window.location.hostname : process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || "";
2247
- const apiUrl = "https://moonui.dev/api/v1/license/validate";
2248
- const validationResponse = await fetch(apiUrl, {
2249
- method: "POST",
2250
- headers: {
2251
- "Content-Type": "application/json"
2252
- },
2253
- body: JSON.stringify({
2254
- licenseKey,
2255
- domain: currentDomain
2256
- })
2257
- });
2258
- if (validationResponse.ok) {
2259
- const validationData = await validationResponse.json();
2260
- if (validationData.valid && validationData.hasProAccess) {
2261
- console.log("[MoonUI Auth] License key validated successfully");
2262
- const newState = {
2263
- isLoading: false,
2264
- hasProAccess: validationData.hasProAccess,
2265
- isAuthenticated: true,
2266
- subscriptionPlan: validationData.plan === "lifetime" ? "lifetime" : "free",
2267
- subscription: {
2268
- status: validationData.hasProAccess ? "active" : "inactive",
2269
- plan: validationData.plan === "lifetime" ? "lifetime" : "free"
2270
- },
2271
- isAdmin: false
2272
- };
2273
- if (typeof document !== "undefined" && validationData.cacheDuration) {
2274
- const cacheData = {
2275
- valid: true,
2276
- hasProAccess: validationData.hasProAccess,
2277
- timestamp: Date.now()
2278
- };
2279
- document.cookie = `moonui_pro_status=${encodeURIComponent(
2280
- JSON.stringify(cacheData)
2281
- )}; max-age=${Math.floor(validationData.cacheDuration / 1e3)}; path=/; SameSite=Strict`;
2282
- }
2283
- if (isMounted.current) {
2284
- setState(newState);
2285
- }
2286
- authPromise = null;
2287
- return newState;
2288
- } else {
2289
- console.warn("[MoonUI Auth] License key validation failed:", validationData.error || "Invalid license");
2290
- }
2291
- } else {
2292
- console.error("[MoonUI Auth] License validation request failed:", validationResponse.status);
2293
- }
2294
- } catch (error) {
2295
- console.error("[MoonUI Auth] License validation error:", error);
2242
+ if (isProduction && licenseKey) {
2243
+ console.log("[MoonUI Auth] Production mode - License key provided");
2244
+ const cachedValidation = readValidationFromCookie();
2245
+ if (cachedValidation && cachedValidation.valid && cachedValidation.hasProAccess) {
2246
+ console.log("[MoonUI Auth] Using cached server validation");
2247
+ const newState2 = {
2248
+ isLoading: false,
2249
+ hasProAccess: cachedValidation.hasProAccess,
2250
+ isAuthenticated: true,
2251
+ subscriptionPlan: "lifetime",
2252
+ subscription: {
2253
+ status: "active",
2254
+ plan: "lifetime"
2255
+ },
2256
+ isAdmin: false
2257
+ };
2258
+ if (isMounted.current) {
2259
+ setState(newState2);
2296
2260
  }
2261
+ authPromise = null;
2262
+ return newState2;
2263
+ }
2264
+ console.log("[MoonUI Auth] License key detected - granting Pro access");
2265
+ console.log("[MoonUI Auth] Note: Actual license validation should be done server-side");
2266
+ const newState = {
2267
+ isLoading: false,
2268
+ hasProAccess: true,
2269
+ // Grant access since license key is provided
2270
+ isAuthenticated: true,
2271
+ subscriptionPlan: "lifetime",
2272
+ subscription: {
2273
+ status: "active",
2274
+ plan: "lifetime"
2275
+ },
2276
+ isAdmin: false
2277
+ };
2278
+ if (isMounted.current) {
2279
+ setState(newState);
2297
2280
  }
2281
+ authPromise = null;
2282
+ return newState;
2298
2283
  }
2299
2284
  const freeState = {
2300
2285
  isLoading: false,
package/dist/server.d.ts CHANGED
@@ -53,6 +53,66 @@ declare function performServerValidation(): Promise<{
53
53
  cached?: boolean;
54
54
  }>;
55
55
 
56
+ /**
57
+ * Server-side license validation helper
58
+ * This should be used in API routes or server components to validate license keys
59
+ * and set appropriate cookies for client-side caching
60
+ */
61
+ interface ValidateLicenseOptions {
62
+ licenseKey: string;
63
+ domain: string;
64
+ }
65
+ interface ValidationResponse {
66
+ valid: boolean;
67
+ hasProAccess: boolean;
68
+ plan?: 'lifetime' | 'monthly' | 'annual' | 'free';
69
+ error?: string;
70
+ cacheDuration?: number;
71
+ }
72
+ /**
73
+ * Validate a MoonUI license key on the server
74
+ * This function should be called from your API routes or server components
75
+ *
76
+ * @example Next.js API Route
77
+ * ```typescript
78
+ * // app/api/validate-license/route.ts
79
+ * import { validateLicense } from '@moontra/moonui-pro/server';
80
+ * import { NextResponse } from 'next/server';
81
+ *
82
+ * export async function POST(request: Request) {
83
+ * const { licenseKey } = await request.json();
84
+ * const domain = request.headers.get('host') || '';
85
+ *
86
+ * const result = await validateLicense({ licenseKey, domain });
87
+ *
88
+ * const response = NextResponse.json(result);
89
+ *
90
+ * // Set cookie if validation successful
91
+ * if (result.valid && result.hasProAccess) {
92
+ * response.cookies.set('moonui_pro_status', JSON.stringify({
93
+ * valid: true,
94
+ * hasProAccess: result.hasProAccess,
95
+ * timestamp: Date.now()
96
+ * }), {
97
+ * httpOnly: false, // Must be accessible by client
98
+ * secure: process.env.NODE_ENV === 'production',
99
+ * sameSite: 'strict',
100
+ * maxAge: result.cacheDuration || 86400 // 24 hours default
101
+ * });
102
+ * }
103
+ *
104
+ * return response;
105
+ * }
106
+ * ```
107
+ */
108
+ declare function validateLicense({ licenseKey, domain }: ValidateLicenseOptions): Promise<ValidationResponse>;
109
+ /**
110
+ * Helper to set MoonUI auth cookies
111
+ * Use this after successful validation
112
+ */
113
+ declare function setAuthCookie(response: any, // Response object from your framework
114
+ validationResult: ValidationResponse): void;
115
+
56
116
  /**
57
117
  * MoonUI Pro Authentication Configuration
58
118
  *
@@ -100,4 +160,4 @@ type AuthConfig = typeof AUTH_CONFIG;
100
160
  type CacheConfig = typeof AUTH_CONFIG.cache;
101
161
  type SecurityConfig = typeof AUTH_CONFIG.security;
102
162
 
103
- export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
163
+ export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setAuthCookie, setValidationInCookies, validateLicense, validateWithMoonUIServer };
package/dist/server.mjs CHANGED
@@ -3148,6 +3148,67 @@ async function performServerValidation() {
3148
3148
  return { ...result, cached: false };
3149
3149
  }
3150
3150
 
3151
+ // src/lib/server-validate.ts
3152
+ async function validateLicense({
3153
+ licenseKey,
3154
+ domain
3155
+ }) {
3156
+ try {
3157
+ const response = await fetch("https://moonui.dev/api/v1/license/validate", {
3158
+ method: "POST",
3159
+ headers: {
3160
+ "Content-Type": "application/json",
3161
+ // Add server-side headers to bypass CORS
3162
+ "X-Server-Request": "true",
3163
+ "X-Request-Domain": domain
3164
+ },
3165
+ body: JSON.stringify({
3166
+ licenseKey,
3167
+ domain
3168
+ })
3169
+ });
3170
+ if (!response.ok) {
3171
+ return {
3172
+ valid: false,
3173
+ hasProAccess: false,
3174
+ error: `Validation failed: ${response.status}`
3175
+ };
3176
+ }
3177
+ const data = await response.json();
3178
+ return data;
3179
+ } catch (error) {
3180
+ console.error("[MoonUI Server Validate] Error:", error);
3181
+ return {
3182
+ valid: false,
3183
+ hasProAccess: false,
3184
+ error: error instanceof Error ? error.message : "Validation error"
3185
+ };
3186
+ }
3187
+ }
3188
+ function setAuthCookie(response, validationResult) {
3189
+ if (validationResult.valid && validationResult.hasProAccess) {
3190
+ const cookieData = {
3191
+ valid: true,
3192
+ hasProAccess: validationResult.hasProAccess,
3193
+ timestamp: Date.now()
3194
+ };
3195
+ const maxAge = validationResult.cacheDuration || 86400;
3196
+ if (typeof response.setHeader === "function") {
3197
+ response.setHeader(
3198
+ "Set-Cookie",
3199
+ `moonui_pro_status=${encodeURIComponent(JSON.stringify(cookieData))}; Max-Age=${maxAge}; Path=/; SameSite=Strict; ${""}`
3200
+ );
3201
+ } else if (response.cookies && typeof response.cookies.set === "function") {
3202
+ response.cookies.set("moonui_pro_status", JSON.stringify(cookieData), {
3203
+ maxAge,
3204
+ path: "/",
3205
+ sameSite: "strict",
3206
+ secure: false
3207
+ });
3208
+ }
3209
+ }
3210
+ }
3211
+
3151
3212
  // src/server.ts
3152
3213
  if (typeof window !== "undefined") {
3153
3214
  console.warn(
@@ -3155,4 +3216,4 @@ if (typeof window !== "undefined") {
3155
3216
  );
3156
3217
  }
3157
3218
 
3158
- export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
3219
+ export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setAuthCookie, setValidationInCookies, validateLicense, validateWithMoonUIServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moontra/moonui-pro",
3
- "version": "2.37.16",
3
+ "version": "2.37.17",
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",