@moontra/moonui-pro 2.37.15 → 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.d.ts CHANGED
@@ -146,13 +146,32 @@ interface AuthContextType extends AuthState {
146
146
  refreshAuth: () => Promise<void>;
147
147
  clearAuth: () => void;
148
148
  }
149
+ interface MoonUIAuthProviderProps {
150
+ children: ReactNode;
151
+ /**
152
+ * Environment mode - defaults to 'development' if not provided
153
+ * In Next.js: environment={process.env.NODE_ENV}
154
+ * In Vite: environment={import.meta.env.MODE}
155
+ * In CRA: environment={process.env.NODE_ENV}
156
+ */
157
+ environment?: 'development' | 'production' | 'test';
158
+ /**
159
+ * License key for production environments
160
+ * In Next.js: licenseKey={process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY}
161
+ * In Vite: licenseKey={import.meta.env.VITE_MOONUI_LICENSE_KEY}
162
+ * In CRA: licenseKey={process.env.REACT_APP_MOONUI_LICENSE_KEY}
163
+ */
164
+ licenseKey?: string;
165
+ /**
166
+ * Force production mode (useful for testing)
167
+ */
168
+ forceProduction?: boolean;
169
+ }
149
170
  /**
150
171
  * MoonUI Auth Provider - Centralized authentication state
151
172
  * This provider ensures only ONE API call is made for all components
152
173
  */
153
- declare function MoonUIAuthProvider({ children }: {
154
- children: ReactNode;
155
- }): react_jsx_runtime.JSX.Element;
174
+ declare function MoonUIAuthProvider({ children, environment, licenseKey, forceProduction }: MoonUIAuthProviderProps): react_jsx_runtime.JSX.Element;
156
175
  /**
157
176
  * Hook to use auth context
158
177
  * Falls back to direct API call if context is not available
package/dist/index.mjs CHANGED
@@ -2118,7 +2118,12 @@ var AuthContext = createContext(void 0);
2118
2118
  var authPromise = null;
2119
2119
  var lastFetchTime = 0;
2120
2120
  var FETCH_COOLDOWN = 5e3;
2121
- function MoonUIAuthProvider({ children }) {
2121
+ function MoonUIAuthProvider({
2122
+ children,
2123
+ environment = "development",
2124
+ licenseKey,
2125
+ forceProduction = false
2126
+ }) {
2122
2127
  const [state, setState] = useState({
2123
2128
  isLoading: true,
2124
2129
  hasProAccess: false,
@@ -2185,30 +2190,16 @@ function MoonUIAuthProvider({ children }) {
2185
2190
  authPromise = (async () => {
2186
2191
  try {
2187
2192
  lastFetchTime = now;
2188
- let isProduction = false;
2189
- let isDevelopment = true;
2190
- let environmentInfo = {};
2191
- try {
2192
- const envResponse = await fetch("/api/environment", {
2193
- method: "GET",
2194
- cache: "no-store"
2195
- });
2196
- if (envResponse.ok) {
2197
- environmentInfo = await envResponse.json();
2198
- isProduction = environmentInfo.isProduction;
2199
- isDevelopment = environmentInfo.isDevelopment;
2200
- console.log("[MoonUI Auth] Runtime Environment Detection:", {
2201
- ...environmentInfo.debug,
2202
- environment: environmentInfo.environment,
2203
- isProduction,
2204
- isDevelopment
2205
- });
2206
- } else {
2207
- console.warn("[MoonUI Auth] Failed to fetch environment info, falling back to development mode");
2208
- }
2209
- } catch (error) {
2210
- console.warn("[MoonUI Auth] Error fetching environment info:", error);
2211
- }
2193
+ const isProduction = forceProduction || environment === "production";
2194
+ const isDevelopment = !isProduction;
2195
+ const hasLicenseKey = !!licenseKey;
2196
+ console.log("[MoonUI Auth] Environment Detection:", {
2197
+ environment,
2198
+ forceProduction,
2199
+ hasLicenseKey,
2200
+ isProduction,
2201
+ isDevelopment
2202
+ });
2212
2203
  if (isDevelopment) {
2213
2204
  let response;
2214
2205
  const authServerUrl = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_MOONUI_AUTH_SERVER || "http://localhost:7878" : "http://localhost:7878";
@@ -2248,63 +2239,47 @@ function MoonUIAuthProvider({ children }) {
2248
2239
  console.log('[MoonUI Auth] Auth server not available in development. Run "moonui dev" to enable Pro features.');
2249
2240
  }
2250
2241
  }
2251
- if (isProduction) {
2252
- 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;
2253
- if (licenseKey) {
2254
- console.log("[MoonUI Auth] Production mode - validating license key...");
2255
- try {
2256
- const currentDomain = typeof window !== "undefined" ? window.location.hostname : process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || "";
2257
- const apiUrl = "https://moonui.dev/api/v1/license/validate";
2258
- const validationResponse = await fetch(apiUrl, {
2259
- method: "POST",
2260
- headers: {
2261
- "Content-Type": "application/json"
2262
- },
2263
- body: JSON.stringify({
2264
- licenseKey,
2265
- domain: currentDomain
2266
- })
2267
- });
2268
- if (validationResponse.ok) {
2269
- const validationData = await validationResponse.json();
2270
- if (validationData.valid && validationData.hasProAccess) {
2271
- console.log("[MoonUI Auth] License key validated successfully");
2272
- const newState = {
2273
- isLoading: false,
2274
- hasProAccess: validationData.hasProAccess,
2275
- isAuthenticated: true,
2276
- subscriptionPlan: validationData.plan === "lifetime" ? "lifetime" : "free",
2277
- subscription: {
2278
- status: validationData.hasProAccess ? "active" : "inactive",
2279
- plan: validationData.plan === "lifetime" ? "lifetime" : "free"
2280
- },
2281
- isAdmin: false
2282
- };
2283
- if (typeof document !== "undefined" && validationData.cacheDuration) {
2284
- const cacheData = {
2285
- valid: true,
2286
- hasProAccess: validationData.hasProAccess,
2287
- timestamp: Date.now()
2288
- };
2289
- document.cookie = `moonui_pro_status=${encodeURIComponent(
2290
- JSON.stringify(cacheData)
2291
- )}; max-age=${Math.floor(validationData.cacheDuration / 1e3)}; path=/; SameSite=Strict`;
2292
- }
2293
- if (isMounted.current) {
2294
- setState(newState);
2295
- }
2296
- authPromise = null;
2297
- return newState;
2298
- } else {
2299
- console.warn("[MoonUI Auth] License key validation failed:", validationData.error || "Invalid license");
2300
- }
2301
- } else {
2302
- console.error("[MoonUI Auth] License validation request failed:", validationResponse.status);
2303
- }
2304
- } catch (error) {
2305
- 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);
2306
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);
2307
2280
  }
2281
+ authPromise = null;
2282
+ return newState;
2308
2283
  }
2309
2284
  const freeState = {
2310
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.15",
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",