admin/lib/server/eventManagementBootstrap.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

31 lines
1.2 KiB
TypeScript

import type { EventManagementBootstrap } from '@/services/eventManagement'
type ApiEnvelope<T> = { 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<EventManagementBootstrap | null> {
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<EventManagementBootstrap>
return body.success ? body.data : null
}