Documents From ID — Cursor-safe pagination with multi-proof status
Version: 1.0.0 Date: 2026-03-03
Goal: Allow consumers of GET /documents/from-id to paginate with a cursor that never skips pending documents, filter by required proof types (AND logic), and know how many documents remain.
Solution: Added requiredProofs and limit query params. Status is computed service-side with smart proof checking: a proof type is only required if the doc actually has proofs of that type (backward-compatible with old docs). Documents with external proofs are always confirmed. The response stops at the first non-confirmed document to prevent data loss across paginated calls. Remaining count uses a fast indexed countDocuments.
Features:
- New
requiredProofsquery parameter (comma-separated, e.g.chainpoint,ots) - Cursor boundary: response stops at the first non-confirmed doc
- New
limitquery parameter for batch size control - Response returns
{ documents, remaining }whereremainingexcludes returned docs - Proof collection no longer hardcoded (
'ots-proofs'-> configurable via env) externalproofs: docs with an external proof are always considered confirmed- Backward-compatible: if a doc has no proofs of a required type, that type is skipped
Implementation Details:
- Pipeline simplified: fetches docs with proofs attached (
type+status), sorted by_id - Status calculation moved to service (TS):
externalshort-circuit, then per-type check only if proofs of that type exist - Boundary logic in TS:
findIndex+sliceon the first non-confirmed doc remainingviacountDocumentsondocumentscollection (indexed_id+jobRef), run inPromise.allwith the pipelinegetJobIdshelper: admin gets all company job IDs viadistinct, non-admin uses ownjobId
Files Modified:
src/domains/document/document.type.ts-DocOptionswithrequiredProofs+DocumentsFromIdResultsrc/domains/document/document.controller.ts-requiredProofsandlimitquery params, JSDocsrc/domains/document/document.service.ts-Promise.all,isConfirmed,getJobIds, boundary logicsrc/domains/document/templates/documentsFromId.ts- Simplified: removed status calc, boundary, facet