import 'dotenv/config'; import { prisma } from '../src/config/database.js'; import { startSync } from '../src/services/sat/sat.service.js'; const TENANT_ID = 'bcffc3ce-e5f5-4a66-b6bf-28da47bf7a41'; const CONTRIBUYENTE_ID = '75a26067-66b2-4b5c-9dde-9ecc628a1e03'; function getYesterdayEndCDMX(): Date { const now = new Date(); return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1, 12, 0, 0)); } function getThreeDaysAgoStartCDMX(): Date { const yesterday = getYesterdayEndCDMX(); return new Date(Date.UTC(yesterday.getUTCFullYear(), yesterday.getUTCMonth(), yesterday.getUTCDate() - 2, 0, 0, 0)); } async function sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); } async function main() { const dateFrom = getThreeDaysAgoStartCDMX(); const dateTo = getYesterdayEndCDMX(); console.log('[Proxy Test] Iniciando sync con proxy para Miguel Angel Romero Estrada'); console.log(`[Proxy Test] RFC: ROEM691011EZ4`); console.log(`[Proxy Test] Rango: ${dateFrom.toISOString()} → ${dateTo.toISOString()}`); const jobId = await startSync(TENANT_ID, 'daily', dateFrom, dateTo, CONTRIBUYENTE_ID); console.log(`[Proxy Test] Job creado: ${jobId}`); let previousStatus: string | null = null; while (true) { const job = await prisma.satSyncJob.findUnique({ where: { id: jobId } }); if (!job) { console.log('[Proxy Test] Job no encontrado'); process.exit(1); } const statusLine = `[Proxy Test] Status: ${job.status} | found=${job.cfdisFound} downloaded=${job.cfdisDownloaded} inserted=${job.cfdisInserted} updated=${job.cfdisUpdated} progress=${job.progressPercent}% | error=${job.errorMessage || 'none'}`; if (job.status !== previousStatus) { console.log(statusLine); previousStatus = job.status; } else { process.stdout.write('.'); } if (job.status === 'completed' || job.status === 'failed') { console.log('\n[Proxy Test] Resultado final:'); console.log(JSON.stringify({ id: job.id, status: job.status, cfdisFound: job.cfdisFound, cfdisDownloaded: job.cfdisDownloaded, cfdisInserted: job.cfdisInserted, cfdisUpdated: job.cfdisUpdated, errorMessage: job.errorMessage, completedAt: job.completedAt, }, null, 2)); break; } await sleep(15000); } } main().catch(err => { console.error('[Proxy Test] Error:', err); process.exit(1); });