manicanldes-backend/docs/supplier-documents-api.md

3.0 KiB

Phase 2F: private supplier documents

Supplier documents are stored as PostgreSQL bytea with a strict 2 MiB PDF limit. The API has no public file URL. Metadata responses never contain file bytes.

All routes are under /api/v1 and require a bearer token. supplier_document.read permits metadata reads and approved downloads. supplier_document.manage permits creating document records and uploading versions. supplier_document.validate permits an independent reviewer to approve or reject a version and to download pending versions for review. A reviewer also needs supplier_document.read to use the review download route. Records are organization scoped.

Method Route Purpose
GET /suppliers/:supplierId/documents Page through a supplier's document records
POST /suppliers/:supplierId/documents Create a document identity
GET /supplier-documents/:id Read metadata and all versions, newest first
POST /supplier-documents/:id/versions Upload a new PDF version as multipart field file
GET /supplier-document-versions/:id Read version metadata and decision
GET /supplier-document-versions/:id/download Download approved PDF or review a pending version
POST /supplier-document-versions/:id/decision Approve or reject a version exactly once

Create a document with {"code":"TAX-CERT","kind":"TAX_CERTIFICATE","title":"Supplier tax certificate"}. Kinds are REGISTRATION, TAX_CERTIFICATE, COMPLIANCE_CERTIFICATE, and OTHER. The code is normalized to uppercase and unique per supplier. Up to 100 documents per supplier and 20 sequential versions per document are supported. Lists use limit (default 25, maximum 100) and offset (default 0).

Upload a PDF with a simple ASCII .pdf filename. The server checks filename, MIME type, PDF signature, EOF marker, and byte size, then records SHA-256, uploader, and version number. Each version and validation decision is immutable. Reject with {"outcome":"REJECTED","reason":"Expired"} or approve with {"outcome":"APPROVED"}. The uploader cannot validate their own version. General readers can download only approved versions. Downloads are checksum-verified and sent with Content-Disposition: attachment, nosniff, no-store, and a sandbox content-security policy.

Validation is a human review step, not an antivirus scan or a legal certification. Operators should review files in an isolated environment. PostgreSQL backup access and retention need the same controls as the API; the product retention policy and automated malware scanning remain deployment decisions. A later storage adapter can move bytes to private object storage without changing document identities or version decisions.