The Documents API provides endpoints for managing documents in the vault, including upload, processing, tagging, and retrieval.
Query Endpoints
get
Retrieve a paginated list of documents.
Search query for document name or content
Start date filter (ISO 8601)
End date filter (ISO 8601)
Number of results per page
import { trpc } from '@/lib/trpc' ;
const { data , meta } = await trpc . documents . get . query ({
tag: 'receipts' ,
start: '2024-01-01' ,
end: '2024-12-31' ,
});
getById
Retrieve a specific document by ID or file path.
Array of path tokens (alternative to id)
File metadata including mimetype
“pending” | “processing” | “completed” | “failed”
const document = await trpc . documents . getById . query ({
id: 'document-uuid' ,
});
// Or by file path
const document = await trpc . documents . getById . query ({
filePath: [ 'vault' , 'team-id' , 'receipt.pdf' ],
});
Get documents related to a specific document (based on tags, date, etc.).
Number of results to return
Array of related document objects
const related = await trpc . documents . getRelatedDocuments . query ({
id: 'document-uuid' ,
pageSize: 5 ,
});
checkAttachments
Check if a document is attached to any transactions or invoices.
Whether the document has attachments
Number of linked transactions
Number of linked invoices
const { hasAttachments , transactionCount } = await trpc . documents . checkAttachments . query ({
id: 'document-uuid' ,
});
if ( hasAttachments ) {
console . log ( `Document is attached to ${ transactionCount } transactions` );
}
Mutation Endpoints
delete
Delete a document from the vault.
The deleted document object
await trpc . documents . delete . mutate ({
id: 'document-uuid' ,
});
Deleting a document also removes it from storage. This action cannot be undone.
processDocument
Trigger processing for uploaded documents (OCR, text extraction).
Array of document objects to process
type DocumentToProcess = {
filePath : string []; // Path tokens in storage
mimetype : string ; // MIME type (e.g., 'application/pdf')
};
Array of job objects with IDs for tracking
const result = await trpc . documents . processDocument . mutate ([
{
filePath: [ 'vault' , 'team-id' , 'invoice-001.pdf' ],
mimetype: 'application/pdf' ,
},
{
filePath: [ 'vault' , 'team-id' , 'receipt-002.jpg' ],
mimetype: 'image/jpeg' ,
},
]);
console . log ( 'Processing jobs:' , result . jobs );
Supported file types for processing: PDF, images (JPEG, PNG), and text files. Other file types will be marked as completed without processing.
reprocessDocument
Reprocess a document that failed or needs updating.
Whether reprocessing was queued
True if document type is not supported
Job ID for tracking progress
const result = await trpc . documents . reprocessDocument . mutate ({
id: 'document-uuid' ,
});
if ( result . success ) {
console . log ( 'Reprocessing job ID:' , result . jobId );
}
Signed URLs
signedUrl
Generate a temporary signed URL for downloading a document.
Expiration time in seconds (default: 60)
Temporary URL for downloading the file
const { signedUrl } = await trpc . documents . signedUrl . mutate ({
filePath: [ 'vault' , 'team-id' , 'receipt.pdf' ],
expireIn: 300 , // 5 minutes
});
// Use the signed URL to download or display the file
window . open ( signedUrl );
signedUrls
Generate multiple signed URLs at once.
Array of file path arrays
Array of signed URLs (same order as input)
const urls = await trpc . documents . signedUrls . mutate ([
[ 'vault' , 'team-id' , 'file1.pdf' ],
[ 'vault' , 'team-id' , 'file2.jpg' ],
[ 'vault' , 'team-id' , 'file3.png' ],
]);
// urls is an array of signed URL strings
urls . forEach (( url , index ) => {
console . log ( `File ${ index + 1 } : ${ url } ` );
});
Document Processing
The document processing system automatically extracts text and metadata from uploaded files.
Processing Flow
Upload - Files are uploaded to Supabase storage
Queue - Call processDocument to queue processing jobs
Process - Background workers extract text using OCR/parsers
Complete - Document status changes to “completed”
Supported File Types
PDF - Text extraction and OCR for scanned PDFs
Images - JPEG, PNG (OCR applied)
Text - Plain text files
Example: Upload and Process
// 1. Upload file to storage
const filePath = await uploadToStorage ( file );
// 2. Queue processing
const result = await trpc . documents . processDocument . mutate ([{
filePath ,
mimetype: file . type ,
}]);
// 3. Monitor status
const document = await trpc . documents . getById . query ({ filePath });
console . log ( 'Processing status:' , document . processingStatus );
Tagging
Documents can be organized using tags through the tRPC API’s documentTags and documentTagAssignments routers.