Skip to content

feat(compliance): merchant data export endpoint (#313)#344

Merged
Pvsaint merged 3 commits intoMetroLogic:mainfrom
rayeberechi:feature/313-merchant-data-export
Mar 30, 2026
Merged

feat(compliance): merchant data export endpoint (#313)#344
Pvsaint merged 3 commits intoMetroLogic:mainfrom
rayeberechi:feature/313-merchant-data-export

Conversation

@rayeberechi
Copy link
Copy Markdown
Contributor

Overview

This PR implements the "Right to Portability" requirement by providing a robust, asynchronous data export engine. It allows both merchants and administrators to generate comprehensive data packages containing profile details, payment summaries, and system logs.

Core Implementation (#313)

  • Asynchronous Job Architecture:
    • Introduced a DataExportJob state machine (pending -> processing -> completed -> failed).
    • API returns a 202 Accepted immediately upon request, providing a jobId for status polling.
  • Data Aggregation Logic:
    • The dataExport.service.ts performs a scoped aggregation of:
      • Merchant Profile: Full account metadata.
      • Payment Summary: Aggregate statistics and recent transaction history.
      • Webhook Logs: Scoped delivery logs (capped at 1,000 entries for performance).
  • Secure Retrieval:
    • Exports are stored as Base64-encoded payloads on the job record (ready for future S3 migration).
    • Expiry Enforcement: Download links are programmatically invalidated after 24 hours.
  • Access Control:
    • Self-Service: Merchants can trigger and download their own data via API Key authentication.
    • Admin Overlay: Administrators can trigger exports for any merchant via the new Admin JWT/RBAC layer.

Technical Specification

  • Database: Added DataExportJob and DataExportStatus models via Prisma.
  • Security: Strict scoping ensures Merchant A cannot poll or download the jobId belonging to Merchant B.
  • Testing: Added 7 comprehensive tests in dataExport.service.test.ts covering the full lifecycle from request to expired download.

Results

  • Performance: Heavy database queries are isolated from the initial request-response cycle.
  • Compliance: Fully satisfies GDPR Article 20 requirements for data portability.

Verification

  • API returns 202 and a valid Job ID on request.
  • Polling endpoint correctly reflects processing states.
  • Download endpoint enforces the 24-hour expiration window.
  • Admin-specific endpoints respect RBAC permissions.

Closes #313

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

@rayeberechi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

- Add DataExportJob model + DataExportStatus enum to Prisma schema
- Add migration 20260329140000_add_data_export_job
- dataExport.service: enqueue + async process export (profile, payments
  summary, webhook logs); base64 payload stored on job record
- dataExport.controller: merchant self-service + admin-triggered endpoints
- dataExport.route: POST /merchants/export, GET /export/:jobId,
  GET /export/:jobId/download, admin variants
- Wire route into app.ts at /api/v1/merchants/export
- 7 unit tests: all passing
- Fix IKMSProvider/KMSFactory type errors (pre-existing)
- Fix payment.service uuid ESM issue (crypto.randomUUID)
- Add adminUser to AuthRequest type
@rayeberechi rayeberechi force-pushed the feature/313-merchant-data-export branch from dde757c to bc9f447 Compare March 29, 2026 14:18
@Pvsaint Pvsaint merged commit a7bcc4f into MetroLogic:main Mar 30, 2026
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Compliance: merchant data export endpoint

2 participants