feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility

This commit is contained in:
2026-04-16 20:30:56 +00:00
parent 55bee02a2e
commit 3f37f6538c
60 changed files with 5723 additions and 6678 deletions
+34 -18
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env node
/// <reference types="node" />
/**
* Post-install script to download required validation resources
@@ -6,11 +7,19 @@
* All users need validation capabilities, so this is mandatory
*/
import { SchematronDownloader } from '../dist_ts/formats/validation/schematron.downloader.js';
import * as path from 'path';
import * as fs from 'fs';
import * as crypto from 'crypto';
const schematronDownloaderModulePath = '../dist_ts/formats/validation/schematron.downloader.js';
async function createDownloader() {
const { SchematronDownloader } = await import(schematronDownloaderModulePath);
const downloader = new SchematronDownloader('assets_downloaded/schematron');
await downloader.initialize();
return downloader;
}
// Version for cache invalidation
const RESOURCES_VERSION = '1.0.0';
@@ -89,15 +98,15 @@ function saveVersionFile(): void {
fs.mkdirSync(path.dirname(versionFile), { recursive: true });
fs.writeFileSync(versionFile, RESOURCES_VERSION);
} catch (error) {
console.warn('⚠️ Could not save version file:', error.message);
const errorMessage = error instanceof Error ? error.message : String(error);
console.warn('⚠️ Could not save version file:', errorMessage);
}
}
async function downloadSchematron() {
console.log('📥 Downloading Schematron validation files...\n');
const downloader = new SchematronDownloader('assets_downloaded/schematron');
await downloader.initialize();
const downloader = await createDownloader();
let successCount = 0;
let failCount = 0;
@@ -109,7 +118,8 @@ async function downloadSchematron() {
console.log(`✅ Downloaded ${en16931Files.length} EN16931 files`);
successCount += en16931Files.length;
} catch (error) {
console.error(`⚠️ Failed to download EN16931: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`⚠️ Failed to download EN16931: ${errorMessage}`);
failCount++;
}
@@ -120,7 +130,8 @@ async function downloadSchematron() {
console.log(`✅ Downloaded ${peppolFiles.length} PEPPOL files`);
successCount += peppolFiles.length;
} catch (error) {
console.error(`⚠️ Failed to download PEPPOL: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`⚠️ Failed to download PEPPOL: ${errorMessage}`);
failCount++;
}
@@ -131,7 +142,8 @@ async function downloadSchematron() {
console.log(`✅ Downloaded ${xrechnungFiles.length} XRechnung files`);
successCount += xrechnungFiles.length;
} catch (error) {
console.error(`⚠️ Failed to download XRechnung: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`⚠️ Failed to download XRechnung: ${errorMessage}`);
failCount++;
}
@@ -232,13 +244,14 @@ async function main() {
}
break;
} catch (error) {
lastError = error;
if (attempts < maxAttempts) {
console.log(`\n⚠️ Download failed: ${error.message}`);
console.log(' Retrying...');
await new Promise(resolve => setTimeout(resolve, 3000)); // Wait 3s before retry
}
} catch (error) {
lastError = error;
if (attempts < maxAttempts) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.log(`\n⚠️ Download failed: ${errorMessage}`);
console.log(' Retrying...');
await new Promise(resolve => setTimeout(resolve, 3000)); // Wait 3s before retry
}
}
}
@@ -250,13 +263,15 @@ async function main() {
console.error();
if (lastError) {
console.error(' Last error:', lastError.message);
const errorMessage = lastError instanceof Error ? lastError.message : String(lastError);
console.error(' Last error:', errorMessage);
}
} catch (error) {
// Catch-all for unexpected errors
const errorMessage = error instanceof Error ? error.message : String(error);
console.error();
console.error('⚠️ Unexpected error during resource setup:', error.message);
console.error('⚠️ Unexpected error during resource setup:', errorMessage);
console.error(' This won\'t affect library installation');
console.error(' Resources will be downloaded on first use');
console.error();
@@ -266,10 +281,11 @@ async function main() {
// Only run if this is the main module
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch(error => {
console.error('⚠️ Resource setup error:', error.message);
const errorMessage = error instanceof Error ? error.message : String(error);
console.error('⚠️ Resource setup error:', errorMessage);
// Never fail the install
process.exit(0);
});
}
export default main;
export default main;