@moontra/moonui-pro 2.37.17 → 3.0.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 +117 -117
- package/dist/cdn/index.global.js.map +1 -1
- package/dist/index.d.ts +5 -24
- package/dist/index.mjs +125 -55
- package/dist/lib/build-time-validator.d.ts +30 -0
- package/dist/lib/build-time-validator.mjs +117 -0
- package/dist/lib/client-token-verifier.d.ts +27 -0
- package/dist/lib/client-token-verifier.mjs +44 -0
- package/dist/server.d.ts +1 -61
- package/dist/server.mjs +1 -62
- package/package.json +1 -1
- package/plugin/next.js +83 -0
- package/plugin/vite.js +76 -0
package/dist/index.d.ts
CHANGED
|
@@ -146,32 +146,13 @@ 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
|
-
}
|
|
170
149
|
/**
|
|
171
150
|
* MoonUI Auth Provider - Centralized authentication state
|
|
172
151
|
* This provider ensures only ONE API call is made for all components
|
|
173
152
|
*/
|
|
174
|
-
declare function MoonUIAuthProvider({ children
|
|
153
|
+
declare function MoonUIAuthProvider({ children }: {
|
|
154
|
+
children: ReactNode;
|
|
155
|
+
}): react_jsx_runtime.JSX.Element;
|
|
175
156
|
/**
|
|
176
157
|
* Hook to use auth context
|
|
177
158
|
* Falls back to direct API call if context is not available
|
|
@@ -395,7 +376,7 @@ declare const MoonUIAvatarFallbackPro: React$1.ForwardRefExoticComponent<Omit<Av
|
|
|
395
376
|
* Dark ve light modda uyumlu, erişilebilir ve çeşitli varyantlar sunar.
|
|
396
377
|
*/
|
|
397
378
|
declare const moonUIBadgeVariantsPro: (props?: ({
|
|
398
|
-
variant?: "primary" | "secondary" | "success" | "warning" | "ghost" | "outline" | "destructive" | "
|
|
379
|
+
variant?: "pro" | "primary" | "secondary" | "success" | "warning" | "ghost" | "outline" | "destructive" | "admin" | null | undefined;
|
|
399
380
|
size?: "sm" | "md" | "lg" | null | undefined;
|
|
400
381
|
radius?: "default" | "none" | "sm" | "lg" | null | undefined;
|
|
401
382
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
@@ -4386,7 +4367,7 @@ declare const statusVariants: (props?: ({
|
|
|
4386
4367
|
declare const badgeVariants: (props?: ({
|
|
4387
4368
|
size?: "sm" | "md" | "lg" | "xl" | "2xl" | "xs" | "3xl" | null | undefined;
|
|
4388
4369
|
position?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | null | undefined;
|
|
4389
|
-
variant?: "lifetime" | "default" | "success" | "warning" | "info" | "destructive" |
|
|
4370
|
+
variant?: "pro" | "lifetime" | "default" | "success" | "warning" | "info" | "destructive" | null | undefined;
|
|
4390
4371
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
4391
4372
|
declare const iconBadgeMap: {
|
|
4392
4373
|
crown: React$1.ForwardRefExoticComponent<Omit<lucide_react.LucideProps, "ref"> & React$1.RefAttributes<SVGSVGElement>>;
|
package/dist/index.mjs
CHANGED
|
@@ -2114,16 +2114,39 @@ var AUTH_CONFIG = {
|
|
|
2114
2114
|
session: "x-moonui-session-id"
|
|
2115
2115
|
}
|
|
2116
2116
|
};
|
|
2117
|
+
|
|
2118
|
+
// src/lib/client-token-verifier.ts
|
|
2119
|
+
function verifyBuildToken() {
|
|
2120
|
+
try {
|
|
2121
|
+
const token = process.env.MOONUI_BUILD_TOKEN;
|
|
2122
|
+
if (!token) {
|
|
2123
|
+
console.log("[MoonUI] No build token found");
|
|
2124
|
+
return null;
|
|
2125
|
+
}
|
|
2126
|
+
const decoded = JSON.parse(Buffer.from(token, "base64").toString());
|
|
2127
|
+
const payload = {
|
|
2128
|
+
licenseKey: decoded.licenseKey || "validated",
|
|
2129
|
+
domain: decoded.domain || window.location.hostname,
|
|
2130
|
+
timestamp: decoded.timestamp || Date.now(),
|
|
2131
|
+
expiresAt: decoded.expiresAt || Date.now() + 7 * 24 * 60 * 60 * 1e3,
|
|
2132
|
+
hasProAccess: decoded.hasProAccess !== false,
|
|
2133
|
+
plan: decoded.plan || "pro"
|
|
2134
|
+
};
|
|
2135
|
+
if (payload.expiresAt < Date.now()) {
|
|
2136
|
+
console.warn("[MoonUI] Build token expired, rebuild required");
|
|
2137
|
+
return null;
|
|
2138
|
+
}
|
|
2139
|
+
return payload;
|
|
2140
|
+
} catch (error) {
|
|
2141
|
+
console.error("[MoonUI] Error verifying build token:", error);
|
|
2142
|
+
return null;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2117
2145
|
var AuthContext = createContext(void 0);
|
|
2118
2146
|
var authPromise = null;
|
|
2119
2147
|
var lastFetchTime = 0;
|
|
2120
2148
|
var FETCH_COOLDOWN = 5e3;
|
|
2121
|
-
function MoonUIAuthProvider({
|
|
2122
|
-
children,
|
|
2123
|
-
environment = "development",
|
|
2124
|
-
licenseKey,
|
|
2125
|
-
forceProduction = false
|
|
2126
|
-
}) {
|
|
2149
|
+
function MoonUIAuthProvider({ children }) {
|
|
2127
2150
|
const [state, setState] = useState({
|
|
2128
2151
|
isLoading: true,
|
|
2129
2152
|
hasProAccess: false,
|
|
@@ -2164,6 +2187,23 @@ function MoonUIAuthProvider({
|
|
|
2164
2187
|
console.log("[MoonUI Auth] Using ongoing request");
|
|
2165
2188
|
return authPromise;
|
|
2166
2189
|
}
|
|
2190
|
+
const buildToken = verifyBuildToken();
|
|
2191
|
+
if (buildToken && buildToken.hasProAccess) {
|
|
2192
|
+
console.log("[MoonUI Auth] Using build-time token - Pro access granted");
|
|
2193
|
+
const tokenState = {
|
|
2194
|
+
isLoading: false,
|
|
2195
|
+
hasProAccess: true,
|
|
2196
|
+
isAuthenticated: true,
|
|
2197
|
+
subscriptionPlan: buildToken.plan === "lifetime" ? "lifetime" : "free",
|
|
2198
|
+
subscription: {
|
|
2199
|
+
status: "active",
|
|
2200
|
+
plan: buildToken.plan === "lifetime" ? "lifetime" : "free"
|
|
2201
|
+
},
|
|
2202
|
+
isAdmin: false
|
|
2203
|
+
};
|
|
2204
|
+
setState(tokenState);
|
|
2205
|
+
return tokenState;
|
|
2206
|
+
}
|
|
2167
2207
|
if (!forceRefresh2) {
|
|
2168
2208
|
const cached = readValidationFromCookie();
|
|
2169
2209
|
if (cached && cached.valid) {
|
|
@@ -2190,16 +2230,30 @@ function MoonUIAuthProvider({
|
|
|
2190
2230
|
authPromise = (async () => {
|
|
2191
2231
|
try {
|
|
2192
2232
|
lastFetchTime = now;
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
environment,
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2233
|
+
let isProduction = false;
|
|
2234
|
+
let isDevelopment = true;
|
|
2235
|
+
let environmentInfo = {};
|
|
2236
|
+
try {
|
|
2237
|
+
const envResponse = await fetch("/api/environment", {
|
|
2238
|
+
method: "GET",
|
|
2239
|
+
cache: "no-store"
|
|
2240
|
+
});
|
|
2241
|
+
if (envResponse.ok) {
|
|
2242
|
+
environmentInfo = await envResponse.json();
|
|
2243
|
+
isProduction = environmentInfo.isProduction;
|
|
2244
|
+
isDevelopment = environmentInfo.isDevelopment;
|
|
2245
|
+
console.log("[MoonUI Auth] Runtime Environment Detection:", {
|
|
2246
|
+
...environmentInfo.debug,
|
|
2247
|
+
environment: environmentInfo.environment,
|
|
2248
|
+
isProduction,
|
|
2249
|
+
isDevelopment
|
|
2250
|
+
});
|
|
2251
|
+
} else {
|
|
2252
|
+
console.warn("[MoonUI Auth] Failed to fetch environment info, falling back to development mode");
|
|
2253
|
+
}
|
|
2254
|
+
} catch (error) {
|
|
2255
|
+
console.warn("[MoonUI Auth] Error fetching environment info:", error);
|
|
2256
|
+
}
|
|
2203
2257
|
if (isDevelopment) {
|
|
2204
2258
|
let response;
|
|
2205
2259
|
const authServerUrl = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_MOONUI_AUTH_SERVER || "http://localhost:7878" : "http://localhost:7878";
|
|
@@ -2239,47 +2293,63 @@ function MoonUIAuthProvider({
|
|
|
2239
2293
|
console.log('[MoonUI Auth] Auth server not available in development. Run "moonui dev" to enable Pro features.');
|
|
2240
2294
|
}
|
|
2241
2295
|
}
|
|
2242
|
-
if (isProduction
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2296
|
+
if (isProduction) {
|
|
2297
|
+
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;
|
|
2298
|
+
if (licenseKey) {
|
|
2299
|
+
console.log("[MoonUI Auth] Production mode - validating license key...");
|
|
2300
|
+
try {
|
|
2301
|
+
const currentDomain = typeof window !== "undefined" ? window.location.hostname : process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || "";
|
|
2302
|
+
const apiUrl = "https://moonui.dev/api/v1/license/validate";
|
|
2303
|
+
const validationResponse = await fetch(apiUrl, {
|
|
2304
|
+
method: "POST",
|
|
2305
|
+
headers: {
|
|
2306
|
+
"Content-Type": "application/json"
|
|
2307
|
+
},
|
|
2308
|
+
body: JSON.stringify({
|
|
2309
|
+
licenseKey,
|
|
2310
|
+
domain: currentDomain
|
|
2311
|
+
})
|
|
2312
|
+
});
|
|
2313
|
+
if (validationResponse.ok) {
|
|
2314
|
+
const validationData = await validationResponse.json();
|
|
2315
|
+
if (validationData.valid && validationData.hasProAccess) {
|
|
2316
|
+
console.log("[MoonUI Auth] License key validated successfully");
|
|
2317
|
+
const newState = {
|
|
2318
|
+
isLoading: false,
|
|
2319
|
+
hasProAccess: validationData.hasProAccess,
|
|
2320
|
+
isAuthenticated: true,
|
|
2321
|
+
subscriptionPlan: validationData.plan === "lifetime" ? "lifetime" : "free",
|
|
2322
|
+
subscription: {
|
|
2323
|
+
status: validationData.hasProAccess ? "active" : "inactive",
|
|
2324
|
+
plan: validationData.plan === "lifetime" ? "lifetime" : "free"
|
|
2325
|
+
},
|
|
2326
|
+
isAdmin: false
|
|
2327
|
+
};
|
|
2328
|
+
if (typeof document !== "undefined" && validationData.cacheDuration) {
|
|
2329
|
+
const cacheData = {
|
|
2330
|
+
valid: true,
|
|
2331
|
+
hasProAccess: validationData.hasProAccess,
|
|
2332
|
+
timestamp: Date.now()
|
|
2333
|
+
};
|
|
2334
|
+
document.cookie = `moonui_pro_status=${encodeURIComponent(
|
|
2335
|
+
JSON.stringify(cacheData)
|
|
2336
|
+
)}; max-age=${Math.floor(validationData.cacheDuration / 1e3)}; path=/; SameSite=Strict`;
|
|
2337
|
+
}
|
|
2338
|
+
if (isMounted.current) {
|
|
2339
|
+
setState(newState);
|
|
2340
|
+
}
|
|
2341
|
+
authPromise = null;
|
|
2342
|
+
return newState;
|
|
2343
|
+
} else {
|
|
2344
|
+
console.warn("[MoonUI Auth] License key validation failed:", validationData.error || "Invalid license");
|
|
2345
|
+
}
|
|
2346
|
+
} else {
|
|
2347
|
+
console.error("[MoonUI Auth] License validation request failed:", validationResponse.status);
|
|
2348
|
+
}
|
|
2349
|
+
} catch (error) {
|
|
2350
|
+
console.error("[MoonUI Auth] License validation error:", error);
|
|
2260
2351
|
}
|
|
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);
|
|
2280
2352
|
}
|
|
2281
|
-
authPromise = null;
|
|
2282
|
-
return newState;
|
|
2283
2353
|
}
|
|
2284
2354
|
const freeState = {
|
|
2285
2355
|
isLoading: false,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time license validation and token generation
|
|
3
|
+
* This runs during build process, not in browser
|
|
4
|
+
*/
|
|
5
|
+
interface TokenPayload {
|
|
6
|
+
licenseKey: string;
|
|
7
|
+
domain: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
expiresAt: number;
|
|
10
|
+
hasProAccess: boolean;
|
|
11
|
+
plan: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Validate license key at build time
|
|
15
|
+
* Makes server-side request to avoid CORS
|
|
16
|
+
*/
|
|
17
|
+
declare function validateLicenseAtBuildTime(licenseKey: string | undefined, domain?: string): Promise<string | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Verify and decrypt token on client-side
|
|
20
|
+
*/
|
|
21
|
+
declare function verifyAndDecryptToken(token: string): TokenPayload | null;
|
|
22
|
+
/**
|
|
23
|
+
* Generate a webpack DefinePlugin config with the token
|
|
24
|
+
*/
|
|
25
|
+
declare function generateWebpackDefineConfig(token: string | null): {
|
|
26
|
+
'process.env.MOONUI_BUILD_TOKEN': string;
|
|
27
|
+
'process.env.MOONUI_BUILD_TIME': string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { generateWebpackDefineConfig, validateLicenseAtBuildTime, verifyAndDecryptToken };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @moontra/moonui-pro v2.0.9
|
|
5
|
+
* Premium UI components for MoonUI
|
|
6
|
+
* (c) 2025 MoonUI. All rights reserved.
|
|
7
|
+
* @license Commercial - https://moonui.dev/license
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var ENCRYPTION_KEY = "moonui-pro-2024-encryption-key-v1";
|
|
11
|
+
var SIGNING_KEY = "moonui-pro-2024-signing-key-v1";
|
|
12
|
+
async function validateLicenseAtBuildTime(licenseKey, domain) {
|
|
13
|
+
if (!licenseKey) {
|
|
14
|
+
console.log("[MoonUI Build] No license key provided");
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
console.log("[MoonUI Build] Validating license key...");
|
|
19
|
+
const validationDomain = domain || process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || process.env.DEPLOY_URL || "localhost";
|
|
20
|
+
const response = await fetch("https://moonui.dev/api/v1/license/validate", {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
"X-Build-Time-Validation": "true",
|
|
25
|
+
"User-Agent": "MoonUI-Build-Validator/1.0"
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
licenseKey,
|
|
29
|
+
domain: validationDomain
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
console.error("[MoonUI Build] License validation failed:", response.status);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const data = await response.json();
|
|
37
|
+
if (!data.valid || !data.hasProAccess) {
|
|
38
|
+
console.error("[MoonUI Build] Invalid license or no Pro access");
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
console.log("[MoonUI Build] License validated successfully");
|
|
42
|
+
const payload = {
|
|
43
|
+
licenseKey: licenseKey.substring(0, 8) + "...",
|
|
44
|
+
// Only store partial key
|
|
45
|
+
domain: validationDomain,
|
|
46
|
+
timestamp: Date.now(),
|
|
47
|
+
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1e3,
|
|
48
|
+
// 7 days
|
|
49
|
+
hasProAccess: data.hasProAccess,
|
|
50
|
+
plan: data.plan || "pro"
|
|
51
|
+
};
|
|
52
|
+
const token = encryptAndSignToken(payload);
|
|
53
|
+
return token;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error("[MoonUI Build] Error validating license:", error);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function encryptAndSignToken(payload) {
|
|
60
|
+
const payloadString = JSON.stringify(payload);
|
|
61
|
+
const iv = crypto.randomBytes(16);
|
|
62
|
+
const cipher = crypto.createCipheriv(
|
|
63
|
+
"aes-256-gcm",
|
|
64
|
+
crypto.scryptSync(ENCRYPTION_KEY, "salt", 32),
|
|
65
|
+
iv
|
|
66
|
+
);
|
|
67
|
+
let encrypted = cipher.update(payloadString, "utf8", "hex");
|
|
68
|
+
encrypted += cipher.final("hex");
|
|
69
|
+
const authTag = cipher.getAuthTag();
|
|
70
|
+
const hmac = crypto.createHmac("sha256", SIGNING_KEY);
|
|
71
|
+
hmac.update(encrypted);
|
|
72
|
+
const signature = hmac.digest("hex");
|
|
73
|
+
const token = Buffer.from(JSON.stringify({
|
|
74
|
+
encrypted,
|
|
75
|
+
authTag: authTag.toString("hex"),
|
|
76
|
+
signature,
|
|
77
|
+
iv: iv.toString("hex")
|
|
78
|
+
})).toString("base64");
|
|
79
|
+
return token;
|
|
80
|
+
}
|
|
81
|
+
function verifyAndDecryptToken(token) {
|
|
82
|
+
try {
|
|
83
|
+
const decoded = JSON.parse(Buffer.from(token, "base64").toString());
|
|
84
|
+
const hmac = crypto.createHmac("sha256", SIGNING_KEY);
|
|
85
|
+
hmac.update(decoded.encrypted);
|
|
86
|
+
const expectedSignature = hmac.digest("hex");
|
|
87
|
+
if (decoded.signature !== expectedSignature) {
|
|
88
|
+
console.error("[MoonUI] Invalid token signature");
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const decipher = crypto.createDecipheriv(
|
|
92
|
+
"aes-256-gcm",
|
|
93
|
+
crypto.scryptSync(ENCRYPTION_KEY, "salt", 32),
|
|
94
|
+
Buffer.from(decoded.iv, "hex")
|
|
95
|
+
);
|
|
96
|
+
decipher.setAuthTag(Buffer.from(decoded.authTag, "hex"));
|
|
97
|
+
let decrypted = decipher.update(decoded.encrypted, "hex", "utf8");
|
|
98
|
+
decrypted += decipher.final("utf8");
|
|
99
|
+
const payload = JSON.parse(decrypted);
|
|
100
|
+
if (payload.expiresAt < Date.now()) {
|
|
101
|
+
console.error("[MoonUI] Token expired");
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return payload;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("[MoonUI] Error verifying token:", error);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function generateWebpackDefineConfig(token) {
|
|
111
|
+
return {
|
|
112
|
+
"process.env.MOONUI_BUILD_TOKEN": JSON.stringify(token),
|
|
113
|
+
"process.env.MOONUI_BUILD_TIME": JSON.stringify(Date.now())
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { generateWebpackDefineConfig, validateLicenseAtBuildTime, verifyAndDecryptToken };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side token verification
|
|
3
|
+
* This runs in the browser and verifies the build-time generated token
|
|
4
|
+
*/
|
|
5
|
+
interface TokenPayload {
|
|
6
|
+
licenseKey: string;
|
|
7
|
+
domain: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
expiresAt: number;
|
|
10
|
+
hasProAccess: boolean;
|
|
11
|
+
plan: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Simple client-side token verification
|
|
15
|
+
* Note: Real decryption happens server-side, this is just a basic check
|
|
16
|
+
*/
|
|
17
|
+
declare function verifyBuildToken(): TokenPayload | null;
|
|
18
|
+
/**
|
|
19
|
+
* Check if Pro features are enabled
|
|
20
|
+
*/
|
|
21
|
+
declare function hasProAccess(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get subscription plan from token
|
|
24
|
+
*/
|
|
25
|
+
declare function getSubscriptionPlan(): string;
|
|
26
|
+
|
|
27
|
+
export { getSubscriptionPlan, hasProAccess, verifyBuildToken };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moontra/moonui-pro v2.0.9
|
|
3
|
+
* Premium UI components for MoonUI
|
|
4
|
+
* (c) 2025 MoonUI. All rights reserved.
|
|
5
|
+
* @license Commercial - https://moonui.dev/license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// src/lib/client-token-verifier.ts
|
|
9
|
+
function verifyBuildToken() {
|
|
10
|
+
try {
|
|
11
|
+
const token = process.env.MOONUI_BUILD_TOKEN;
|
|
12
|
+
if (!token) {
|
|
13
|
+
console.log("[MoonUI] No build token found");
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const decoded = JSON.parse(Buffer.from(token, "base64").toString());
|
|
17
|
+
const payload = {
|
|
18
|
+
licenseKey: decoded.licenseKey || "validated",
|
|
19
|
+
domain: decoded.domain || window.location.hostname,
|
|
20
|
+
timestamp: decoded.timestamp || Date.now(),
|
|
21
|
+
expiresAt: decoded.expiresAt || Date.now() + 7 * 24 * 60 * 60 * 1e3,
|
|
22
|
+
hasProAccess: decoded.hasProAccess !== false,
|
|
23
|
+
plan: decoded.plan || "pro"
|
|
24
|
+
};
|
|
25
|
+
if (payload.expiresAt < Date.now()) {
|
|
26
|
+
console.warn("[MoonUI] Build token expired, rebuild required");
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return payload;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error("[MoonUI] Error verifying build token:", error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function hasProAccess() {
|
|
36
|
+
const token = verifyBuildToken();
|
|
37
|
+
return token ? token.hasProAccess : false;
|
|
38
|
+
}
|
|
39
|
+
function getSubscriptionPlan() {
|
|
40
|
+
const token = verifyBuildToken();
|
|
41
|
+
return token ? token.plan : "free";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { getSubscriptionPlan, hasProAccess, verifyBuildToken };
|
package/dist/server.d.ts
CHANGED
|
@@ -53,66 +53,6 @@ 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
|
-
|
|
116
56
|
/**
|
|
117
57
|
* MoonUI Pro Authentication Configuration
|
|
118
58
|
*
|
|
@@ -160,4 +100,4 @@ type AuthConfig = typeof AUTH_CONFIG;
|
|
|
160
100
|
type CacheConfig = typeof AUTH_CONFIG.cache;
|
|
161
101
|
type SecurityConfig = typeof AUTH_CONFIG.security;
|
|
162
102
|
|
|
163
|
-
export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation,
|
|
103
|
+
export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
|
package/dist/server.mjs
CHANGED
|
@@ -3148,67 +3148,6 @@ 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
|
-
|
|
3212
3151
|
// src/server.ts
|
|
3213
3152
|
if (typeof window !== "undefined") {
|
|
3214
3153
|
console.warn(
|
|
@@ -3216,4 +3155,4 @@ if (typeof window !== "undefined") {
|
|
|
3216
3155
|
);
|
|
3217
3156
|
}
|
|
3218
3157
|
|
|
3219
|
-
export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation,
|
|
3158
|
+
export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moontra/moonui-pro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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",
|