import type { EventManagementBootstrap } from '@/services/eventManagement' type ApiEnvelope = { success: true; data: T } | { success: false; message: string } const resolveApiBaseUrl = () => { const raw = process.env.NEXT_PUBLIC_API_URL if (!raw) throw new Error('NEXT_PUBLIC_API_URL is not configured') const trimmed = raw.replace(/\/+$/, '') return trimmed.endsWith('/api/v1') ? trimmed : `${trimmed}/api/v1` } /** Private owner data: never enters the public Next.js or persistent browser cache. */ export async function fetchEventManagementBootstrapForOwner( eventId: string, accessToken: string ): Promise { const response = await fetch(`${resolveApiBaseUrl()}/events/${encodeURIComponent(eventId)}/management-bootstrap`, { cache: 'no-store', headers: { Authorization: `Bearer ${accessToken}` }, }) if (response.status === 401 || response.status === 403 || response.status === 404) return null if (!response.ok) throw new Error(`Management bootstrap failed: ${response.status}`) const body = (await response.json()) as ApiEnvelope return body.success ? body.data : null }