66 lines
2.6 KiB
JavaScript
66 lines
2.6 KiB
JavaScript
#!/usr/bin/env ts-node
|
|
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* ABE License Key Generator (internal tool)
|
|
* Usage: ts-node src/scripts/generate-license.ts --plan pro --org "Acme Corp" --email admin@acme.com --expires 2027-01-01
|
|
*/
|
|
const crypto_1 = __importDefault(require("crypto"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const path_1 = __importDefault(require("path"));
|
|
function parseArgs() {
|
|
const args = process.argv.slice(2);
|
|
const get = (flag) => {
|
|
const idx = args.indexOf(flag);
|
|
return idx >= 0 ? args[idx + 1] : undefined;
|
|
};
|
|
const plan = (get('--plan') ?? 'pro');
|
|
const org = get('--org') ?? 'Unknown Organization';
|
|
const email = get('--email') ?? '';
|
|
const expires = get('--expires') ?? null;
|
|
const keyFile = get('--key') ?? path_1.default.join(process.cwd(), 'license-private.pem');
|
|
return { plan, org, email, expires, keyFile };
|
|
}
|
|
function generateLicense(args) {
|
|
if (!fs_1.default.existsSync(args.keyFile)) {
|
|
throw new Error(`Private key not found at ${args.keyFile}.\n` +
|
|
'Generate with: openssl genrsa -out license-private.pem 2048');
|
|
}
|
|
const privateKeyPem = fs_1.default.readFileSync(args.keyFile, 'utf-8');
|
|
const privateKey = crypto_1.default.createPrivateKey(privateKeyPem);
|
|
const payload = {
|
|
plan: args.plan,
|
|
organizationName: args.org,
|
|
email: args.email,
|
|
issuedAt: new Date().toISOString(),
|
|
expiresAt: args.expires ? new Date(args.expires).toISOString() : null,
|
|
};
|
|
const payloadJson = JSON.stringify(payload);
|
|
const payloadB64 = Buffer.from(payloadJson, 'utf-8').toString('base64');
|
|
const signature = crypto_1.default.sign('sha256', Buffer.from(payloadJson, 'utf-8'), privateKey);
|
|
const signatureB64 = signature.toString('base64');
|
|
return `${payloadB64}.${signatureB64}`;
|
|
}
|
|
function main() {
|
|
const args = parseArgs();
|
|
try {
|
|
const licenseKey = generateLicense(args);
|
|
console.log('\n=== ABE License Key ===');
|
|
console.log(licenseKey);
|
|
console.log('\n=== Details ===');
|
|
console.log(`Plan: ${args.plan}`);
|
|
console.log(`Organization: ${args.org}`);
|
|
console.log(`Email: ${args.email}`);
|
|
console.log(`Expires: ${args.expires ?? 'Never'}`);
|
|
console.log('===================\n');
|
|
}
|
|
catch (err) {
|
|
console.error('Error generating license:', String(err));
|
|
process.exit(1);
|
|
}
|
|
}
|
|
main();
|