Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
dev/v7-production-failclosed-20261021
ci/public-windows-bridge-probe-20261017
ci/windows-dispatch-bootstrap-20261016
ci/windows-dual-app-lab-20261016
dev/v7-production-failclosed-20261021
feature/reconciliation-guard-20261013
main
phase-1-foundation
phase-1-implementation
phase-2-treasury-core
phase-3-banking-reconciliation
phase-4-operations-enterprise-ux
phase-5-hardening-release
phase-6-production-platform
phase-7-production-infrastructure-bank-golive
phase-7-sql-readonly-ux-20261015
transfer-exe-to-drive-20261006
| 1 | #!/usr/bin/env node |
| 2 | // Local offline-only recovery utility. Never overwrite the active database. |
| 3 | import {existsSync} from 'node:fs'; |
| 4 | import {DatabaseSync} from 'node:sqlite'; |
| 5 | import { |
| 6 | createVerifiedSqliteBackup, |
| 7 | restoreVerifiedSqliteBackupToNewPath, |
| 8 | verifyTreasurySqliteBackup |
| 9 | } from '../src/platform/local/verified-sqlite-backup.ts'; |
| 10 | |
| 11 | const [operation,source,target,...extra]=process.argv.slice(2); |
| 12 | const valid=extra.length===0&&( |
| 13 | (operation==='verify'&&typeof source==='string'&&target===undefined)|| |
| 14 | (['backup','restore-new'].includes(operation)&&typeof source==='string'&&typeof target==='string') |
| 15 | ); |
| 16 | if(!valid){ |
| 17 | console.error('USAGE: verify <file> | backup <existing-db> <new-backup> | restore-new <verified-backup> <new-db>'); |
| 18 | process.exitCode=2; |
| 19 | }else{ |
| 20 | try{ |
| 21 | if(!existsSync(source))throw Error('SQLITE_RECOVERY_SOURCE_MISSING'); |
| 22 | let result; |
| 23 | if(operation==='verify')result=verifyTreasurySqliteBackup(source); |
| 24 | else if(operation==='restore-new')result=restoreVerifiedSqliteBackupToNewPath(source,target); |
| 25 | else{ |
| 26 | // Write-open only for a consistent SQLite VACUUM INTO snapshot. The |
| 27 | // database schema and existing payment state must never be changed. |
| 28 | const db=new DatabaseSync(source); |
| 29 | try{result=createVerifiedSqliteBackup(db,target)} |
| 30 | finally{db.close()} |
| 31 | } |
| 32 | console.log(JSON.stringify({operation,status:'VERIFIED',...result})); |
| 33 | }catch(error){ |
| 34 | // Never print credentials, local data or raw file paths in failure logs. |
| 35 | const msg=error instanceof Error?error.message:'UNKNOWN'; |
| 36 | const allowed=[ |
| 37 | 'SQLITE_BACKUP_DESTINATION_EXISTS', |
| 38 | 'SQLITE_RESTORE_WOULD_OVERWRITE_EXISTING_DATA', |
| 39 | 'SQLITE_BACKUP_INTEGRITY_FAILED', |
| 40 | 'SQLITE_BACKUP_UNSUPPORTED_SCHEMA', |
| 41 | 'SQLITE_BACKUP_REQUIRED_TABLE_MISSING', |
| 42 | 'SQLITE_BACKUP_FINANCIAL_AMOUNT_OUT_OF_SAFE_RANGE', |
| 43 | 'SQLITE_BACKUP_VERIFICATION_MISMATCH', |
| 44 | 'SQLITE_RESTORE_VERIFICATION_MISMATCH', |
| 45 | 'SQLITE_RECOVERY_SOURCE_MISSING' |
| 46 | ]; |
| 47 | console.error('RECOVERY_FAILED_'+(allowed.includes(msg)?msg:'SQLITE_OPERATION_REJECTED')); |
| 48 | process.exitCode=1; |
| 49 | } |
| 50 | } |