// API client for updates-api service const UPDATES_API_URL = process.env.UPDATES_API_URL || 'http://localhost:8080'; export type Link = { id: number; title: string; url: string; category: 'external' | 'internal' | 'resource' | 'tool'; description: string | null; icon: string | null; sort_order: number; }; export type Update = { id: number; slug: string; product: 'batchmaker' | 'standalone'; title: string; summary: string; body_markdown: string; published_at: string; created_at: string; updated_at: string; link_url: string | null; }; /** * Fetch visible links from the updates-api * Used for displaying links on the homepage */ export async function fetchLinks(): Promise { try { const res = await fetch(`${UPDATES_API_URL}/v1/links`, { next: { revalidate: 60 }, // ISR: Cache 60s }); if (!res.ok) { console.error('Failed to fetch links:', res.status, res.statusText); return []; } const data = await res.json(); return data.data || []; } catch (error) { console.error('Error fetching links:', error); return []; } } /** * Fetch recent product updates * @param product Filter by product (optional) * @param limit Max number of updates (default: 5) */ export async function fetchUpdates( product?: 'batchmaker' | 'standalone', limit: number = 5 ): Promise { try { const params = new URLSearchParams(); if (product) params.set('product', product); params.set('limit', String(limit)); const res = await fetch( `${UPDATES_API_URL}/v1/updates?${params}`, { next: { revalidate: 300 } } // ISR: Cache 5min ); if (!res.ok) { console.error('Failed to fetch updates:', res.status, res.statusText); return []; } const data = await res.json(); return data.data || []; } catch (error) { console.error('Error fetching updates:', error); return []; } } /** * Fetch a single update by slug */ export async function fetchUpdateBySlug(slug: string): Promise { try { const res = await fetch(`${UPDATES_API_URL}/v1/updates/${slug}`, { next: { revalidate: 300 }, }); if (!res.ok) { return null; } const data = await res.json(); return data.data || null; } catch (error) { console.error('Error fetching update:', error); return null; } }