- Agrega tabla sat_proxy_errors con proxy_usado, error_code, stage, message. - sat-client.service.ts expone proxyInfo usado en cada conexión SAT. - sat.service.ts registra errores de bloqueo/devolución del SAT en sat_proxy_errors y guarda proxyUsed en sat_sync_jobs. - Nuevo job sat-proxy-report.job.ts: cron 8 AM CDMX, envía email a ADMIN_EMAIL con errores de las últimas 24h agrupados por proxy/error_code. - Template de email sat-proxy-report.ts y método sendSatProxyReport. - Registra el cron en src/index.ts. - Actualiza docs/SAT-SYNC-IMPLEMENTATION.md.
79 lines
2.7 KiB
TypeScript
79 lines
2.7 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import { generateAccessToken } from '../src/auth/tokens';
|
|
import axios from 'axios';
|
|
|
|
async function main() {
|
|
const prisma = new PrismaClient();
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: 'ivan@horuxfin.com' },
|
|
include: { platformRoles: true }
|
|
});
|
|
|
|
if (!user) {
|
|
console.log('User not found');
|
|
return;
|
|
}
|
|
|
|
const token = generateAccessToken({
|
|
userId: user.id,
|
|
email: user.email,
|
|
role: 'contador',
|
|
tenantId: 'c52c2f5d-b1ae-45c6-8cc8-b11c9611618a',
|
|
platformRoles: user.platformRoles.map(r => r.role as any),
|
|
tokenVersion: user.tokenVersion,
|
|
});
|
|
|
|
const baseURL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000/api';
|
|
|
|
// Test 1: Request without X-View-Tenant (should work - HORUX 360)
|
|
try {
|
|
const r1 = await axios.get(`${baseURL}/contribuyentes`, {
|
|
headers: { Authorization: `Bearer ${token}` }
|
|
});
|
|
console.log('Test 1 (no X-View-Tenant):', r1.status, '- contribuyentes count:', r1.data.data?.length ?? 'N/A');
|
|
} catch (e: any) {
|
|
console.log('Test 1 (no X-View-Tenant):', e.response?.status, e.response?.data);
|
|
}
|
|
|
|
// Test 2: Request with X-View-Tenant = Husberto (should work for platform_ti)
|
|
try {
|
|
const r2 = await axios.get(`${baseURL}/contribuyentes`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'X-View-Tenant': 'd75bf020-2008-4881-ab96-77467bf9e1fd'
|
|
}
|
|
});
|
|
console.log('Test 2 (X-View-Tenant=Husberto):', r2.status, '- contribuyentes count:', r2.data.data?.length ?? 'N/A');
|
|
} catch (e: any) {
|
|
console.log('Test 2 (X-View-Tenant=Husberto):', e.response?.status, e.response?.data);
|
|
}
|
|
|
|
// Test 3: Request with X-View-Tenant = AUZA (should work for platform_ti)
|
|
try {
|
|
const r3 = await axios.get(`${baseURL}/contribuyentes`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'X-View-Tenant': '81116985-03cd-4843-97ba-05e8be9917c6'
|
|
}
|
|
});
|
|
console.log('Test 3 (X-View-Tenant=AUZA):', r3.status, '- contribuyentes count:', r3.data.data?.length ?? 'N/A');
|
|
} catch (e: any) {
|
|
console.log('Test 3 (X-View-Tenant=AUZA):', e.response?.status, e.response?.data);
|
|
}
|
|
|
|
// Test 4: Request admin/dashboard/despachos (should work for platform_ti)
|
|
try {
|
|
const r4 = await axios.get(`${baseURL}/admin/dashboard/despachos`, {
|
|
headers: { Authorization: `Bearer ${token}` }
|
|
});
|
|
console.log('Test 4 (/admin/dashboard/despachos):', r4.status, '- despachos count:', r4.data.data?.length ?? 'N/A');
|
|
} catch (e: any) {
|
|
console.log('Test 4 (/admin/dashboard/despachos):', e.response?.status, e.response?.data);
|
|
}
|
|
|
|
await prisma.$disconnect();
|
|
}
|
|
|
|
main().catch(e => { console.error(e); process.exit(1); });
|