JavaScript Projects
Integrate abystrixLicense into your Node.js or browser-based JavaScript project.
Node.js (using fetch)
javascript
class abystrixLicense {
constructor(serverUrl, apiToken) {
this.baseUrl = serverUrl.replace(/\/$/, '');
this.apiToken = apiToken;
}
async validate(licenseKey, productId, hwid) {
const response = await fetch(`${this.baseUrl}/api/v1/validate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
licenseKey,
productId,
hwid: hwid || require('os').hostname()
})
});
return response.json();
}
async getLicense(licenseKey) {
const response = await fetch(
`${this.baseUrl}/api/v2/licenses/by-license-key/${licenseKey}`,
{ headers: { 'TOKEN': this.apiToken } }
);
if (!response.ok) return null;
return response.json();
}
}
// Usage
const license = new abystrixLicense('https://your-server.com', 'your-api-token');
const result = await license.validate('XXXXX-XXXXX-XXXXX-XXXXX', 1);
console.log(result.valid ? 'License is valid!' : 'License is invalid!');Express.js Middleware
javascript
import fetch from 'node-fetch';
const LICENSE_SERVER = 'https://your-server.com';
const API_TOKEN = 'your-api-token';
export async function licenseMiddleware(req, res, next) {
const licenseKey = req.headers['x-license-key'];
const productId = req.headers['x-product-id'];
if (!licenseKey || !productId) {
return res.status(401).json({ error: 'Missing license credentials' });
}
try {
const response = await fetch(`${LICENSE_SERVER}/api/v1/validate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ licenseKey, productId: parseInt(productId) })
});
const data = await response.json();
if (data.valid) {
req.license = data;
next();
} else {
res.status(403).json({ error: 'Invalid license' });
}
} catch (error) {
res.status(500).json({ error: 'License validation failed' });
}
}Browser (Vanilla JS)
javascript
class LicenseClient {
constructor(serverUrl) {
this.serverUrl = serverUrl;
}
async validate(licenseKey, productId) {
try {
const res = await fetch(`${this.serverUrl}/api/v1/validate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ licenseKey, productId })
});
return await res.json();
} catch {
return { valid: false, message: 'Connection failed' };
}
}
}
const client = new LicenseClient('https://your-server.com');
client.validate('XXXXX-XXXXX-XXXXX-XXXXX', 1).then(result => {
if (result.valid) {
document.getElementById('app').style.display = 'block';
} else {
document.getElementById('license-error').textContent = 'Invalid license';
}
});