/** * Legal API client — customer portal /legal/* endpoints. * * @layer Infrastructure - API Client */ import { apiClient } from '../../ApiClient'; import { CUSTOMER_LEGAL_GET_ACCEPTANCE, CUSTOMER_LEGAL_GET_ACTIVE_DOCUMENT, CUSTOMER_LEGAL_LIST_ACCEPTANCES, CUSTOMER_LEGAL_LIST_ACTIVE_DOCUMENTS, CUSTOMER_LEGAL_RE_ACCEPT, CUSTOMER_LEGAL_RENDER_PDF, } from '@archer/api-interface/endpoints/customer-api'; import type { AcceptanceDetailResponse, AcceptanceListResponse, ActiveLegalDocumentListResponse, ReAcceptLegalResponse, } from '@archer/api-interface/schemas/customer-api/response'; import type { PublicLegalDocumentResponse } from '@archer/api-interface/schemas/landing-api/response'; import { tokenStorage } from '@/infrastructure/storage/LocalTokenStorage'; async function fetchAuthed(path: string): Promise { const baseUrl = import.meta.env.VITE_API_URL as string | undefined; if (!baseUrl) throw new Error('VITE_API_URL must be set at build time'); const token = tokenStorage.getAccessToken(); return fetch(`${baseUrl}${path}`, { method: 'GET', headers: token ? { Authorization: `Bearer ${token}` } : undefined, }); } export const legalApi = { listAcceptances(): Promise { return apiClient.get(CUSTOMER_LEGAL_LIST_ACCEPTANCES.path); }, listActiveDocuments(): Promise { return apiClient.get(CUSTOMER_LEGAL_LIST_ACTIVE_DOCUMENTS.path); }, getActiveDocument(docType: string): Promise { return apiClient.get( CUSTOMER_LEGAL_GET_ACTIVE_DOCUMENT.path.replace(':docType', docType), ); }, getAcceptance(acceptanceId: string): Promise { return apiClient.get( CUSTOMER_LEGAL_GET_ACCEPTANCE.path.replace(':acceptanceId', acceptanceId), ); }, reAccept(versionIds: string[]): Promise { return apiClient.post(CUSTOMER_LEGAL_RE_ACCEPT.path, { versionIds }); }, /** Single PDF download — active version + live company cover. */ async downloadPdf(docType: string, locale: 'de' | 'en'): Promise { const path = CUSTOMER_LEGAL_RENDER_PDF.path.replace(':docType', docType); const resp = await fetchAuthed(`${path}?locale=${locale}`); if (!resp.ok) throw new Error(`Failed to fetch PDF: ${resp.status}`); return resp.blob(); }, };