Server sync, erroneous doc handling, and @binect/js v0.1.0 integration

- Add server sync to discover documents uploaded elsewhere (fixes missing
  basket documents issue)
- Handle erroneous uploads: preserve binectDocumentId for delete button
- Add "Delete from server" button for erroneous and canceled documents
- Remove archive button for active documents (in_basket, in_production)
- Auto-restore archived documents that have active status
- Refactor to use @binect/js v0.1.0 features:
  - DocumentStatus enum instead of magic numbers
  - isErroneous(), getErrors() helper functions
  - getStatusDescription() for status text
- Add binect-js improvement requirements document

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-16 22:41:43 +01:00
parent f4c0481eda
commit 327943bc18
6 changed files with 739 additions and 69 deletions

View File

@@ -18,10 +18,11 @@ import {
dismissPDF,
removePDF,
cleanupOldEntries,
syncFromServer,
PDFStatus,
PDFStatusMeta
} from '../utils/pdf-queue';
import { shipDocument, getDocumentStatus } from '../utils/binect-api';
import { shipDocument, getDocumentStatus, deleteDocument, listServerDocuments } from '../utils/binect-api';
/**
* Initialize extension on install
@@ -267,6 +268,72 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true;
}
// Delete a document from the server
if (request.action === 'deleteServerDocument') {
const { documentId, username, password } = request as {
documentId: number;
username: string;
password: string;
};
deleteDocument(documentId, username, password)
.then(() => {
sendResponse({ success: true });
})
.catch(error => {
sendResponse({
success: false,
error: error instanceof Error ? error.message : 'Failed to delete document'
});
});
return true;
}
// List all documents from the server (for sync)
if (request.action === 'listServerDocuments') {
const { username, password } = request as {
username: string;
password: string;
};
listServerDocuments(username, password)
.then(documents => {
sendResponse({ success: true, documents });
})
.catch(error => {
sendResponse({
success: false,
error: error instanceof Error ? error.message : 'Failed to list documents'
});
});
return true;
}
// Sync a server document to local proxy (create or update)
if (request.action === 'syncFromServer') {
const { binectDocumentId, filename, binectStatusCode, binectStatusText, price, recipientAddress, errorDetails } = request as {
binectDocumentId: number;
filename: string;
binectStatusCode: number;
binectStatusText: string;
price?: number;
recipientAddress?: string;
errorDetails?: string;
};
syncFromServer(binectDocumentId, filename, binectStatusCode, binectStatusText, price, recipientAddress, errorDetails)
.then(proxy => {
sendResponse({ success: true, proxy });
})
.catch(error => {
sendResponse({
success: false,
error: error instanceof Error ? error.message : 'Failed to sync document'
});
});
return true;
}
// Legacy handlers for backward compatibility
if (request.action === 'getLastPDF') {
getPendingPDFs().then(entries => {