// Plain URL reachability check for public pages (privacy policy, app-ads.txt). No credentials are ever sent. import type { UrlCheck } from './validate-rules'; export async function checkUrl(url: string, o: { body?: boolean; timeoutMs?: number } = {}): Promise { try { const r = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(o.timeoutMs ?? 15_000), headers: { 'User-Agent': 'storebound-validate' } }); const body = o.body ? (await r.text()).slice(0, 200_000) : undefined; if (!o.body) await r.body?.cancel(); return { url, status: r.status, body }; } catch (e) { return { url, status: null, error: (e as Error).message }; } } /** * An API error body for an Error message: JSON on one line (App Store Connect and Google pretty-print their errors, * which broke tables, `lastLine` in serve and matching on the error reason), an HTML page named as such, else the text * with its whitespace collapsed. At most `max` characters. */ export function errorBody(text: string, max = 1500): string { if (/^\s* max ? s.slice(0, max) + '…' : s; }