Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib/consent/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,30 @@ export async function fetchRemoteConsent(userId: string): Promise<RemoteConsentP
}
}

/** Fetch consent data for GDPR subject-data export. */
export async function fetchConsentExport(userId: string): Promise<RemoteConsentPayload | null> {
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<boolean> {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/export/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './types';
export * from './utils';

export { exportSubjectData } from '../consent/api';
Loading