diff --git a/src/lib/consent/api.ts b/src/lib/consent/api.ts index f52d5e10..e3f6dedc 100644 --- a/src/lib/consent/api.ts +++ b/src/lib/consent/api.ts @@ -5,6 +5,7 @@ import type { ConsentPreferences } from './types'; const CONSENT_API = '/api/v1/consent'; +const CONSENT_EXPORT_API = '/api/v1/consent/export'; export interface RemoteConsentPayload { userId: string; @@ -24,6 +25,30 @@ export async function fetchRemoteConsent(userId: string): Promise { + try { + const res = await fetch(`${CONSENT_EXPORT_API}?userId=${encodeURIComponent(userId)}`); + if (!res.ok) return null; + const json = (await res.json()) as { data?: RemoteConsentPayload }; + return json.data ?? null; + } catch { + return null; + } +} + +/** Consolidated GDPR subject-data export bundle for a user. */ +export async function exportSubjectData(userId: string): Promise<{ + consent: RemoteConsentPayload | null; + exportedAt: string; +}> { + const consent = await fetchConsentExport(userId); + return { + consent, + exportedAt: new Date().toISOString(), + }; +} + /** Push consent preferences to the server for cross-device persistence. */ export async function pushRemoteConsent(payload: RemoteConsentPayload): Promise { try { diff --git a/src/lib/export/index.ts b/src/lib/export/index.ts index 6d5a6ef4..77593df9 100644 --- a/src/lib/export/index.ts +++ b/src/lib/export/index.ts @@ -1,2 +1,4 @@ export * from './types'; export * from './utils'; + +export { exportSubjectData } from '../consent/api'; \ No newline at end of file