The mobile GDPR export screen (app/backup/export.tsx) called backupService.exportData -> POST /compliance/export-data, an endpoint that never existed on the backend and always 404'd silently (same bug class as the web buttons fixed in 842be56e). Added requestDataExport/getDataExportStatus to backupService.ts and a new utils/dataExportFlow.ts (mirroring web/utils/dataExportFlow.ts) that drives the real async pipeline at /api/v1/data-export (request -> poll status -> download), confirmed live via backend/src/routes/dataExport.ts. Downloads the ready file to local storage with expo-file-system (already a dependency) and hands it to expo-sharing (newly added; no suitable dependency for file sharing already existed) so the user can save or share it via the OS share sheet. Collapsed the screen's fake JSON/CSV format picker to the one format the backend actually produces (JSON) and surfaces every failure (request, poll timeout, download, share) as a visible alert instead of failing silently. Added unit tests for the service calls and the export flow, plus a screen-level test for the button wiring and error paths. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import api from './api';
|
|
|
|
export type DataExportStatus = 'processing' | 'ready' | 'expired' | 'failed';
|
|
|
|
export interface DataExportRequestResponse {
|
|
success: boolean;
|
|
data: {
|
|
exportId: string;
|
|
estimatedTime: string;
|
|
createdAt: string;
|
|
};
|
|
}
|
|
|
|
export interface DataExportStatusResponse {
|
|
success: boolean;
|
|
data: {
|
|
exportId: string;
|
|
status: DataExportStatus;
|
|
progress: number;
|
|
};
|
|
}
|
|
|
|
export const backupService = {
|
|
/**
|
|
* @deprecated Hits `/compliance/export-data`, which does not exist on the
|
|
* backend (always 404s). Use `requestDataExport` + `getDataExportStatus` +
|
|
* `utils/dataExportFlow.ts`'s `requestAndDownloadDataExport`, which drive the
|
|
* real GDPR export pipeline at `/api/v1/data-export` (see
|
|
* backend/src/routes/dataExport.ts). Matches the web fix in commit 842be56e.
|
|
*/
|
|
exportData: async (format: 'json' | 'csv') => {
|
|
const response = await api.post('/compliance/export-data', { format });
|
|
return response.data;
|
|
},
|
|
|
|
// Data export (GDPR). Backend flow is async: request -> poll status -> download
|
|
// once ready. See backend/src/routes/dataExport.ts + services/dataExportService.ts.
|
|
requestDataExport: async (): Promise<DataExportRequestResponse> => {
|
|
const { data } = await api.post('/data-export/request');
|
|
return data;
|
|
},
|
|
|
|
getDataExportStatus: async (exportId: string): Promise<DataExportStatusResponse> => {
|
|
const { data } = await api.get(`/data-export/${exportId}/status`);
|
|
return data;
|
|
},
|
|
|
|
importData: async (fileUri: string) => {
|
|
const formData = new FormData();
|
|
formData.append('file', {
|
|
uri: fileUri,
|
|
type: 'application/json',
|
|
name: 'data.json',
|
|
} as any);
|
|
|
|
const response = await api.post('/compliance/import-data', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
});
|
|
return response.data;
|
|
},
|
|
};
|
|
|