v.1.0.0. initial push of license-lib

This commit is contained in:
2025-03-19 09:37:30 -05:00
commit b22a1c973c
20 changed files with 433 additions and 0 deletions

7
client/config.js Normal file
View File

@@ -0,0 +1,7 @@
// client/config.js
export const CONFIG = {
LICENSE_API_URL: 'http://localhost:3000', // backend API URL
OFFLINE_GRACE_PERIOD_DAYS: 14,
};

6
client/index.js Normal file
View File

@@ -0,0 +1,6 @@
// client/index.js
export { activateLicense } from './validate';
export { cacheLicenseData, getCachedLicenseData, isLicenseCacheValid } from './offline';
export { generateFingerprint } from './utils/fingerprint';
export { CONFIG } from './config';

24
client/offline.js Normal file
View File

@@ -0,0 +1,24 @@
// client/offline.js
const CACHE_KEY = 'license_data';
export const cacheLicenseData = (licenseData) => {
localStorage.setItem(CACHE_KEY, JSON.stringify({
data: licenseData,
cachedAt: Date.now(),
}));
};
export const getCachedLicenseData = () => {
const item = localStorage.getItem(CACHE_KEY);
return item ? JSON.parse(item) : null;
};
export const isLicenseCacheValid = () => {
const cache = getCachedLicenseData();
if (!cache) return false;
const cachedAt = cache.cachedAt;
const elapsedDays = (Date.now() - cachedAt) / (1000 * 60 * 60 * 24);
return elapsedDays <= CONFIG.OFFLINE_GRACE_PERIOD_DAYS;
};

View File

@@ -0,0 +1,6 @@
// client/utils/fingerprint.js
export const generateFingerprint = () => {
return btoa(navigator.userAgent + navigator.language + screen.width + screen.height);
};

14
client/validate.js Normal file
View File

@@ -0,0 +1,14 @@
// client/validate.js
import { CONFIG } from './config';
export const activateLicense = async (userId, licenseKey) => {
const response = await fetch(`${CONFIG.LICENSE_API_URL}/validate-license`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId, licenseKey }),
});
const { valid } = await response.json();
return valid;
};