/** * Извлекает гео-данные и клиентские параметры из заголовков запроса. * Поддерживает заголовки Cloudflare (cf-ipcountry, cf-region) и кастомные (x-country-code, x-region-code). */ export function getClientHeaders(event: any) { const headers = event.node.req.headers; const countryCode = (headers['cf-ipcountry'] as string) || (headers['x-country-code'] as string) || (headers['x-country'] as string) || (Array.isArray(headers['x-country-code']) ? headers['x-country-code'][0] : undefined); const stateCode = (headers['x-region-code'] as string) || (headers['cf-region'] as string) || (Array.isArray(headers['x-region-code']) ? headers['x-region-code'][0] : undefined); const remoteIP = headers['x-real-ip'] as string | undefined; const userAgent = headers['user-agent'] as string | undefined; return { countryCode: countryCode?.trim().toUpperCase(), stateCode: stateCode?.trim().toUpperCase(), remoteIP: remoteIP?.trim(), userAgent: userAgent?.trim(), headers, }; }