import { existsSync, readFileSync } from 'fs';
import { join } from 'path';
import { resolveBridgeDir } from './bridge-dir.js';
import { t } from './i18n.js';
export function bundledBridgeHasClientVersion() {
    let bridgeDir;
    try {
        bridgeDir = resolveBridgeDir();
    }
    catch {
        return true;
    }
    const relayUpstream = join(bridgeDir, 'dist/relay-upstream.js');
    if (!existsSync(relayUpstream))
        return true;
    return readFileSync(relayUpstream, 'utf8').includes('clientVersion');
}
/** npm-пакет должен включать bridge с auth.clientVersion (иначе relay отклоняет connector). */
export function assertBundledBridgeSupportsRelay() {
    if (bundledBridgeHasClientVersion())
        return;
    console.error(t('bridge.staleBundle'));
    process.exit(1);
}
