const BASE_URL = "https://tangled.org"; export const DEFAULT_POLL_INTERVAL = 60; export const getNotificationsUrl = (): string => `${BASE_URL}/notifications`; export const getNotificationsUrlPattern = (): string => `${BASE_URL}/notifications*`; export interface NotificationResult { count: number; pollInterval: number; } export const fetchNotificationCount = async (): Promise => { const response = await fetch(`${BASE_URL}/notifications/count`, { credentials: "include", }); // FIX: requires backend to return 401 when not logged in (currently returns 200 even if not logged in) if (!response.ok) throw new Error(`HTTP ${response.status}`); const html = await response.text(); const match = html.match(/(\d+)/); const pollInterval = Number(response.headers.get("X-Poll-Interval")) || DEFAULT_POLL_INTERVAL; return { count: match ? parseInt(match[1], 10) : 0, pollInterval, }; };