// engine/license-validator/lemon-squeezy.ts — HTTP client for Lemon Squeezy license API.
// Uses native fetch() (Node 18+). No external dependencies.
const BASE_URL = 'https://api.lemonsqueezy.com/v1/licenses';
const TIMEOUT_MS = 10_000;
// ---------------------------------------------------------------------------
// Internal helpers
// ---------------------------------------------------------------------------
async function post(endpoint, body) {
    const controller = new AbortController();
    const timer = setTimeout(() => {
        controller.abort();
    }, TIMEOUT_MS);
    try {
        const res = await fetch(`${BASE_URL}/${endpoint}`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
            body: new URLSearchParams(body).toString(),
            signal: controller.signal,
        });
        if (!res.ok) {
            const text = await res.text();
            throw new Error(`Lemon Squeezy ${endpoint} failed (${String(res.status)}): ${text}`);
        }
        return (await res.json());
    }
    finally {
        clearTimeout(timer);
    }
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
export async function activateLicense(licenseKey, instanceName) {
    return post('activate', {
        license_key: licenseKey,
        instance_name: instanceName,
    });
}
export async function validateLicense(licenseKey, instanceId) {
    return post('validate', {
        license_key: licenseKey,
        instance_id: instanceId,
    });
}
export async function deactivateLicense(licenseKey, instanceId) {
    return post('deactivate', {
        license_key: licenseKey,
        instance_id: instanceId,
    });
}
//# sourceMappingURL=lemon-squeezy.js.map