Initial commit: LexMind - Plataforma Jurídica Inteligente
This commit is contained in:
84
scripts/teste-standalone.ts
Normal file
84
scripts/teste-standalone.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env npx ts-node
|
||||
|
||||
/**
|
||||
* Teste Standalone da API DataJud
|
||||
* Não depende de imports externos
|
||||
*/
|
||||
|
||||
const DATAJUD_API_KEY = 'cDZHYzlZa0JadVREZDJCendQbXY6SkJlTzNjLV9TRENyQk1RdnFKZGRQdw=='
|
||||
|
||||
interface Movimento {
|
||||
codigo: number
|
||||
nome: string
|
||||
dataHora: string
|
||||
orgaoJulgador?: { nome: string }
|
||||
complementosTabelados?: Array<{ nome: string }>
|
||||
}
|
||||
|
||||
async function buscarDataJud(numeroProcesso: string, tribunal: string) {
|
||||
const endpoint = `api_publica_${tribunal.toLowerCase()}`
|
||||
const url = `https://api-publica.datajud.cnj.jus.br/${endpoint}/_search`
|
||||
const numeroLimpo = numeroProcesso.replace(/\D/g, '')
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `APIKey ${DATAJUD_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
size: 1,
|
||||
query: { match: { numeroProcesso: numeroLimpo } },
|
||||
}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${await response.text()}`)
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('='.repeat(60))
|
||||
console.log('🧪 Teste Standalone - API DataJud')
|
||||
console.log('='.repeat(60))
|
||||
|
||||
// Teste com processo que encontramos antes
|
||||
const processoNumero = '1000044-50.2025.8.26.0220'
|
||||
console.log(`\n📋 Buscando: ${processoNumero}`)
|
||||
|
||||
try {
|
||||
const data = await buscarDataJud(processoNumero, 'TJSP')
|
||||
const hits = data.hits?.hits || []
|
||||
|
||||
if (hits.length === 0) {
|
||||
console.log('❌ Processo não encontrado')
|
||||
return
|
||||
}
|
||||
|
||||
const processo = hits[0]._source
|
||||
console.log(`\n✅ Processo encontrado!`)
|
||||
console.log(` Classe: ${processo.classe?.nome}`)
|
||||
console.log(` Órgão: ${processo.orgaoJulgador?.nome}`)
|
||||
console.log(` Total movimentos: ${processo.movimentos?.length || 0}`)
|
||||
|
||||
// Filtrar publicações
|
||||
const publicacoes = (processo.movimentos || []).filter((m: Movimento) =>
|
||||
m.codigo === 92 || // Publicação
|
||||
m.nome?.toLowerCase().includes('publicação') ||
|
||||
m.nome?.toLowerCase().includes('intimação') ||
|
||||
m.nome?.toLowerCase().includes('citação')
|
||||
)
|
||||
|
||||
console.log(`\n📰 Publicações/Intimações (${publicacoes.length}):`)
|
||||
publicacoes.slice(0, 10).forEach((m: Movimento, i: number) => {
|
||||
console.log(` ${i + 1}. ${m.dataHora?.substring(0, 10)} | ${m.nome}`)
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user