Skip to content

Feat add endpoint to validate and preview import files before ingestion#186

Merged
Baskarayelu merged 6 commits intoCredenceOrg:mainfrom
BrayanMQ:feat-Add-endpoint-to-validate-and-preview-import-files-before-ingestion
Mar 29, 2026
Merged

Feat add endpoint to validate and preview import files before ingestion#186
Baskarayelu merged 6 commits intoCredenceOrg:mainfrom
BrayanMQ:feat-Add-endpoint-to-validate-and-preview-import-files-before-ingestion

Conversation

@BrayanMQ
Copy link
Copy Markdown
Contributor

feat(imports): pre-ingestion validation and preview endpoint

Closes #152

Summary

Adds POST /api/imports/preview for enterprise API keys. Clients upload a CSV (multipart field file) with a required address column (case-insensitive header). The handler parses and validates each row’s Stellar address format, returns aggregate counts, bounded preview samples, and row-level errors with line numbers. No data is persisted.

Requirements (issue)

Requirement Implementation
Validate schema + preview summary CSV header must include address; response includes summary, preview, rowErrors
Row-level errors with line references rowErrors[] with line, optional column, code, message
No persistence In-memory buffer only
Bounded preview Caps on valid/invalid sample sizes in importPreviewService
Summary counts validRows, invalidRows, totalRowsScanned, truncation flags when applicable
Limit upload / parse time 512 KiB file limit (multer + service), 10k rows cap, 5s validation budget
Sanitized parser errors Malformed CSV returns generic message; no stack or raw parser internals

How to test

Automated

npx vitest run src/__tests__/imports.test.ts
# or
npm test

Manual (with npm run dev)

curl -sS -X POST "http://localhost:3000/api/imports/preview" \
  -H "X-API-Key: test-enterprise-key-12345" \
  -F "file=@path/to/your.csv"

Sample CSV:

address
GABC7IXPV3YWQXKQZQXQZQXQZQXQZQXQZQXQZQXQZQXQZQXQZQXQZQXQ

Files changed (this PR)

  • package.json, package-lock.jsonmulter, csv-parse, @types/multer
  • src/lib/stellarAddress.ts — shared isValidStellarAddress
  • src/services/identityService.ts — uses shared validator
  • src/services/importPreviewService.ts — parse, validate, limits, response shape
  • src/routes/imports.tsPOST /preview, enterprise auth, multipart upload
  • src/app.ts — mount /api/imports
  • src/__tests__/imports.test.ts — malformed CSV, schema, partial errors, auth, 413, UTF-8

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@BrayanMQ 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

@Baskarayelu
Copy link
Copy Markdown
Contributor

Please resolve the conflicts

…o-validate-and-preview-import-files-before-ingestion
@BrayanMQ
Copy link
Copy Markdown
Contributor Author

@Baskarayelu done!

@Baskarayelu
Copy link
Copy Markdown
Contributor

Please revert the changes made to the package-lock.json file.

@Baskarayelu Baskarayelu merged commit 27e712c into CredenceOrg:main Mar 29, 2026
1 check failed
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.

Add endpoint to validate and preview import files before ingestion

2 participants