import { t } from './i18n.js';
import { isVersionAtLeast } from './semver.js';
import { CLI_VERSION } from './cli-version.js';
export async function fetchRemoteVersionPolicy(relayUrl) {
    const base = relayUrl.replace(/\/$/, '');
    try {
        const res = await fetch(`${base}/api/version-policy`, {
            signal: AbortSignal.timeout(12_000),
        });
        if (!res.ok)
            return null;
        return (await res.json());
    }
    catch {
        return null;
    }
}
export function assertCliVersionAllowed(policy, current = CLI_VERSION) {
    if (isVersionAtLeast(current, policy.minCliVersion))
        return;
    console.error(t('version.outdated', {
        current,
        min: policy.minCliVersion,
        command: policy.updateCliCommand,
    }));
    process.exit(1);
}
