@credithub/harlan-components 1.81.7 → 1.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chart/chartSystem.js +0 -1
- package/dist/components/dossie/generativeAi/dataUtils.js +131 -80
- package/dist/components/dossie/generativeAi/generativeAi.js +8 -13
- package/dist/components/liminar/liminar.js +9 -2
- package/dist/utils/isGlobalReady.d.ts +2 -0
- package/dist/utils/isGlobalReady.js +9 -0
- package/lib/cjs/index.js +266 -200
- package/lib/esm/index.js +266 -200
- package/package.json +1 -1
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
2
|
var t = {};
|
|
14
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -32,14 +21,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
32
21
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
33
22
|
import { normalizeName, similarNames } from '../../../utils/similarNames';
|
|
34
23
|
import { safeStringify } from './responseUtils';
|
|
24
|
+
// -----------------------------------------------------------------------------
|
|
25
|
+
// Helpers externos -------------------------------------------------------------
|
|
26
|
+
// -----------------------------------------------------------------------------
|
|
35
27
|
export function flattenData(data) {
|
|
36
28
|
var flattened = {};
|
|
37
29
|
for (var key in data) {
|
|
38
30
|
if (typeof data[key] === 'object' && !Array.isArray(data[key])) {
|
|
39
|
-
|
|
40
|
-
for (var innerKey in innerData) {
|
|
41
|
-
flattened[innerKey] = innerData[innerKey];
|
|
42
|
-
}
|
|
31
|
+
Object.assign(flattened, data[key]);
|
|
43
32
|
}
|
|
44
33
|
else {
|
|
45
34
|
flattened[key] = data[key];
|
|
@@ -52,12 +41,7 @@ export function limitDataSize(items, maxItems) {
|
|
|
52
41
|
return [];
|
|
53
42
|
return items.slice(0, maxItems).map(function (item) {
|
|
54
43
|
if (typeof item === 'object') {
|
|
55
|
-
return Object.
|
|
56
|
-
if (index < maxItems) {
|
|
57
|
-
limitedItem[key] = item[key];
|
|
58
|
-
}
|
|
59
|
-
return limitedItem;
|
|
60
|
-
}, {});
|
|
44
|
+
return Object.fromEntries(Object.entries(item).slice(0, maxItems));
|
|
61
45
|
}
|
|
62
46
|
return item;
|
|
63
47
|
});
|
|
@@ -65,78 +49,145 @@ export function limitDataSize(items, maxItems) {
|
|
|
65
49
|
function isEmptyObject(obj) {
|
|
66
50
|
if (typeof obj !== 'object' || obj === null)
|
|
67
51
|
return false;
|
|
68
|
-
|
|
52
|
+
// Remove a chave isLoaded antes de decidir se o objeto está “vazio”
|
|
53
|
+
var keys = Object.keys(obj).filter(function (k) { return k !== 'isLoaded'; });
|
|
54
|
+
if (!keys.length)
|
|
55
|
+
return true;
|
|
56
|
+
return keys.every(function (k) { return isEmptyObject(obj[k]); });
|
|
69
57
|
}
|
|
70
58
|
function deepCleanData(data) {
|
|
71
59
|
if (typeof data !== 'object' || data === null)
|
|
72
60
|
return data;
|
|
61
|
+
// Se o objeto contém apenas isLoaded, descarta-o de imediato
|
|
62
|
+
if (!Array.isArray(data) &&
|
|
63
|
+
Object.keys(data).length === 1 &&
|
|
64
|
+
'isLoaded' in data) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
73
67
|
if (Array.isArray(data)) {
|
|
74
|
-
var
|
|
75
|
-
.map(
|
|
76
|
-
.filter(function (
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
!(Array.isArray(
|
|
68
|
+
var arr = data
|
|
69
|
+
.map(deepCleanData)
|
|
70
|
+
.filter(function (i) {
|
|
71
|
+
return i !== null &&
|
|
72
|
+
i !== undefined &&
|
|
73
|
+
i !== '' &&
|
|
74
|
+
!(Array.isArray(i) && i.length === 0);
|
|
81
75
|
});
|
|
82
|
-
return
|
|
76
|
+
return arr.length ? arr : null;
|
|
83
77
|
}
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
78
|
+
var obj = {};
|
|
79
|
+
for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
|
|
80
|
+
var _b = _a[_i], k = _b[0], v = _b[1];
|
|
81
|
+
// ignora props e isLoaded
|
|
82
|
+
if (k === 'props' || k === 'isLoaded')
|
|
83
|
+
continue;
|
|
84
|
+
var cleaned = deepCleanData(v);
|
|
85
|
+
if (cleaned !== null &&
|
|
86
|
+
cleaned !== undefined &&
|
|
87
|
+
cleaned !== '' &&
|
|
88
|
+
!(typeof cleaned === 'object' && isEmptyObject(cleaned))) {
|
|
89
|
+
obj[k] = cleaned;
|
|
94
90
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return Object.keys(cleanedObject).length > 0 ? cleanedObject : null;
|
|
91
|
+
}
|
|
92
|
+
return Object.keys(obj).length ? obj : null;
|
|
98
93
|
}
|
|
94
|
+
// -----------------------------------------------------------------------------
|
|
95
|
+
// Main normaliser --------------------------------------------------------------
|
|
96
|
+
// -----------------------------------------------------------------------------
|
|
99
97
|
export var selectRelevantData = function (data) {
|
|
100
|
-
var _a, _b, _c, _d, _e, _f;
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
99
|
+
var _l = data || {}, protestosNumero = _l.protestos, ccfNumero = _l.ccf, dividasPublicas = _l.dividasPublicas, contasBancarias = _l.bankAccounts, ccfData = _l.ccfData, dividas = _l.divida, _m = _l.dossie, dossie = _m === void 0 ? {} : _m, liminar = _l.liminar, socios = _l.partners, dadosPessoasExpostasPoliticamente = _l.pepData, detalhesProcessosJuridicos = _l.processosJuridicosData, dadosReclameAqui = _l.reclameAqui, refinBoaVista = _l.refinBoaVista, refinSerasa = _l.refinSerasa, dadosScore = _l.scoreData, _o = _l.scr, scr = _o === void 0 ? { isLoaded: false } : _o, _p = _l.veiculos, veiculos = _p === void 0 ? [] : _p, ResumoDosDados = _l.documentHistory;
|
|
100
|
+
// ────────────────────────────────────────────────
|
|
101
|
+
// 1. Protestos – somente a entrada mais recente
|
|
102
|
+
// ────────────────────────────────────────────────
|
|
103
|
+
var _q = ResumoDosDados !== null && ResumoDosDados !== void 0 ? ResumoDosDados : {}, _omit = _q.protestoLiminar, ResumoSafe = __rest(_q, ["protestoLiminar"]);
|
|
104
|
+
var protestosData = [];
|
|
105
|
+
if (Array.isArray(ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.protestoHistory) &&
|
|
106
|
+
ResumoSafe.protestoHistory.length) {
|
|
107
|
+
var latest = __spreadArray([], ResumoSafe.protestoHistory, true).sort(function (a, b) { return new Date(b.data).getTime() - new Date(a.data).getTime(); })[0];
|
|
108
|
+
protestosData = [latest];
|
|
109
|
+
// 💡 mantém histórico enxuto também em ResumoSafe
|
|
110
|
+
ResumoSafe.protestoHistory = [latest];
|
|
111
|
+
}
|
|
112
|
+
if (!protestosData.length &&
|
|
113
|
+
typeof protestosNumero === 'number' &&
|
|
114
|
+
protestosNumero > 0) {
|
|
115
|
+
protestosData = [{ quantidade: protestosNumero }];
|
|
108
116
|
}
|
|
109
|
-
|
|
117
|
+
// ────────────────────────────────────────────────
|
|
118
|
+
// 2. Processos jurídicos – ativos + passivos
|
|
119
|
+
// ────────────────────────────────────────────────
|
|
120
|
+
var empresaNomeNorm = normalizeName((_a = dossie.carousel) === null || _a === void 0 ? void 0 : _a.name);
|
|
121
|
+
var processar = function (tipo) {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
return (_b = (_a = detalhesProcessosJuridicos === null || detalhesProcessosJuridicos === void 0 ? void 0 : detalhesProcessosJuridicos.empresa) === null || _a === void 0 ? void 0 : _a.filter(function (p) {
|
|
124
|
+
var _a;
|
|
125
|
+
return (_a = p.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (e) {
|
|
126
|
+
return e.envolvido_tipo === tipo &&
|
|
127
|
+
similarNames(normalizeName(e.nome_sem_filtro), empresaNomeNorm);
|
|
128
|
+
});
|
|
129
|
+
})) === null || _b === void 0 ? void 0 : _b.map(function (p) { return ({
|
|
130
|
+
assuntos: p.assuntos,
|
|
131
|
+
classe_processual: p.classe_processual,
|
|
132
|
+
diario_sigla: p.diario_sigla,
|
|
133
|
+
updated_at: p.updated_at
|
|
134
|
+
}); });
|
|
135
|
+
};
|
|
136
|
+
var processosAtivos = (_b = processar('Ativo')) !== null && _b !== void 0 ? _b : [];
|
|
137
|
+
var processosPassivos = (_c = processar('Passivo')) !== null && _c !== void 0 ? _c : [];
|
|
138
|
+
var ProcessosJuridicos = __spreadArray(__spreadArray([], processosAtivos, true), processosPassivos, true);
|
|
139
|
+
var quantidadeProcessosJuridicos = ProcessosJuridicos.length;
|
|
140
|
+
// ────────────────────────────────────────────────
|
|
141
|
+
// 3. Liminar
|
|
142
|
+
// ────────────────────────────────────────────────
|
|
143
|
+
var liminarInfo = (liminar === null || liminar === void 0 ? void 0 : liminar.descricaoLiminar) || ((_e = (_d = liminar === null || liminar === void 0 ? void 0 : liminar.origensLiminar) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0)
|
|
144
|
+
? { descricao: liminar.descricaoLiminar, origens: liminar.origensLiminar }
|
|
145
|
+
: undefined;
|
|
146
|
+
// ────────────────────────────────────────────────
|
|
147
|
+
// 4. Tipo de pessoa
|
|
148
|
+
// ────────────────────────────────────────────────
|
|
149
|
+
var tipoPessoa = ((_g = (_f = dossie === null || dossie === void 0 ? void 0 : dossie.carousel) === null || _f === void 0 ? void 0 : _f.document) === null || _g === void 0 ? void 0 : _g.replace(/\D/g, '').length) === 11
|
|
110
150
|
? 'Pessoa Física'
|
|
111
151
|
: 'Pessoa Jurídica';
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var nomeNormalizado = normalizeName(envolvido.nome_sem_filtro);
|
|
124
|
-
return (similarNames(nomeNormalizado, empresaNomeNormalizado) &&
|
|
125
|
-
envolvido.envolvido_tipo === 'Passivo');
|
|
152
|
+
// ────────────────────────────────────────────────
|
|
153
|
+
// 5. Sócios anonimizados
|
|
154
|
+
// ────────────────────────────────────────────────
|
|
155
|
+
var sociosAnonimizados = (_h = socios === null || socios === void 0 ? void 0 : socios.partners) === null || _h === void 0 ? void 0 : _h.map(function (s, i) {
|
|
156
|
+
var _a, _b, _c;
|
|
157
|
+
return ({
|
|
158
|
+
nome: "S\u00F3cio ".concat(i + 1),
|
|
159
|
+
cargo: s.cargo,
|
|
160
|
+
receitaStatus: (_a = s.receitaStatus) !== null && _a !== void 0 ? _a : {},
|
|
161
|
+
dividasPublicas: (_b = s.dividasPublicas) !== null && _b !== void 0 ? _b : {},
|
|
162
|
+
protestos: (_c = s.protestos) !== null && _c !== void 0 ? _c : {}
|
|
126
163
|
});
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
164
|
+
});
|
|
165
|
+
// ────────────────────────────────────────────────
|
|
166
|
+
// 6. Construção final
|
|
167
|
+
// ────────────────────────────────────────────────
|
|
168
|
+
var dadosOrganizados = {
|
|
169
|
+
protestosData: protestosData,
|
|
170
|
+
quantidadeProtestos: (_j = ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.quantidadeProtestos) !== null && _j !== void 0 ? _j : protestosData.length,
|
|
171
|
+
ccf: (_k = ccfNumero !== null && ccfNumero !== void 0 ? ccfNumero : ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.quantidadeChequesSemFundos) !== null && _k !== void 0 ? _k : 0,
|
|
172
|
+
ccfData: ccfData !== null && ccfData !== void 0 ? ccfData : {},
|
|
173
|
+
dividasPublicas: dividasPublicas,
|
|
174
|
+
liminar: liminarInfo,
|
|
175
|
+
ProcessosJuridicos: ProcessosJuridicos,
|
|
176
|
+
quantidadeProcessosJuridicos: quantidadeProcessosJuridicos,
|
|
177
|
+
refinBoaVista: refinBoaVista !== null && refinBoaVista !== void 0 ? refinBoaVista : [],
|
|
178
|
+
refinSerasa: refinSerasa !== null && refinSerasa !== void 0 ? refinSerasa : [],
|
|
179
|
+
scr: scr,
|
|
180
|
+
veiculos: veiculos,
|
|
181
|
+
bankAccounts: contasBancarias,
|
|
182
|
+
dividas: dividas,
|
|
183
|
+
resumoDaEmpresa: dossie.summary,
|
|
184
|
+
socios: sociosAnonimizados,
|
|
185
|
+
dadosPessoasExpostasPoliticamente: dadosPessoasExpostasPoliticamente,
|
|
186
|
+
dadosReclameAqui: dadosReclameAqui,
|
|
187
|
+
dadosScore: dadosScore,
|
|
188
|
+
ResumoDosDados: ResumoSafe,
|
|
189
|
+
tipoPessoa: tipoPessoa
|
|
141
190
|
};
|
|
191
|
+
var dadosFiltrados = deepCleanData(dadosOrganizados);
|
|
192
|
+
return { dadosFiltrados: dadosFiltrados };
|
|
142
193
|
};
|
|
@@ -65,6 +65,7 @@ import StatusMessage from '../../../components/interface/statusMessage';
|
|
|
65
65
|
import { useStreamQuery } from '../../../components/streamQuery';
|
|
66
66
|
import { useGlobalData } from '../../../contexts/globalDataContext';
|
|
67
67
|
import useToggle from '../../../hooks/useToggle';
|
|
68
|
+
import { isGlobalReady } from '../../../utils/isGlobalReady';
|
|
68
69
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
69
70
|
import ReactMarkdown from 'react-markdown';
|
|
70
71
|
import remarkGfm from 'remark-gfm';
|
|
@@ -89,29 +90,23 @@ var GenerativeAI = function (_a) {
|
|
|
89
90
|
var lastQueryRef = useRef(null);
|
|
90
91
|
var lastUserMessageRef = useRef(null);
|
|
91
92
|
var messageHistoryRef = useRef(null);
|
|
92
|
-
|
|
93
|
-
var isGlobalDataLoaded = useMemo(function () {
|
|
94
|
-
return (globalData.documentHistory !== undefined &&
|
|
95
|
-
globalData.documentHistory !== null);
|
|
96
|
-
}, [globalData]);
|
|
93
|
+
var isGlobalDataReady = useMemo(function () { return isGlobalReady(globalData); }, [globalData]);
|
|
97
94
|
// Atualiza o payload serializado sempre que os dados globais mudarem
|
|
98
95
|
useEffect(function () {
|
|
99
|
-
if (globalData && documento &&
|
|
96
|
+
if (globalData && documento && isGlobalDataReady) {
|
|
100
97
|
try {
|
|
101
98
|
var relevantData = selectRelevantData(globalData);
|
|
102
99
|
var serialized = flattenData(relevantData);
|
|
103
|
-
if (serialized !== serializedData)
|
|
100
|
+
if (serialized !== serializedData)
|
|
104
101
|
setSerializedData(serialized);
|
|
105
|
-
}
|
|
106
102
|
}
|
|
107
|
-
catch (
|
|
108
|
-
console.error('Erro ao preparar
|
|
109
|
-
if (serializedData !== '{}')
|
|
103
|
+
catch (err) {
|
|
104
|
+
console.error('Erro ao preparar dados para IA:', err);
|
|
105
|
+
if (serializedData !== '{}')
|
|
110
106
|
setSerializedData('{}');
|
|
111
|
-
}
|
|
112
107
|
}
|
|
113
108
|
}
|
|
114
|
-
}, [documento, globalData,
|
|
109
|
+
}, [documento, globalData, isGlobalDataReady, serializedData]);
|
|
115
110
|
// Deriva o payload para a consulta summary a partir do serializedData.
|
|
116
111
|
// Incluímos o refreshKey para forçar a atualização da query.
|
|
117
112
|
var summaryQueryData = useMemo(function () {
|
|
@@ -184,7 +184,7 @@ var Liminar = function (_a) {
|
|
|
184
184
|
]), origensDetectadas = _w.origensDetectadas, foundBusinessEntity = _w.foundBusinessEntity;
|
|
185
185
|
useEffect(function () {
|
|
186
186
|
var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
|
-
var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus;
|
|
187
|
+
var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus, descricaoLiminar;
|
|
188
188
|
var _b, _c, _d;
|
|
189
189
|
return __generator(this, function (_e) {
|
|
190
190
|
switch (_e.label) {
|
|
@@ -231,6 +231,11 @@ var Liminar = function (_a) {
|
|
|
231
231
|
? 'Encontrado'
|
|
232
232
|
: 'Não encontrado';
|
|
233
233
|
invertedIdsRef.current = newIds;
|
|
234
|
+
descricaoLiminar = origensDetectadas.length
|
|
235
|
+
? "Liminar encontrada ".concat(origensDetectadas
|
|
236
|
+
.map(function (o) { return o.replace(/^Liminar (no|na) /, 'no '); })
|
|
237
|
+
.join(', '))
|
|
238
|
+
: 'Não encontrado';
|
|
234
239
|
setData(function (prev) { return (__assign(__assign({}, prev), { liminar: {
|
|
235
240
|
indiciosDeLiminar: indiciosApi || indiciosDeLiminarProtestosDoPassado,
|
|
236
241
|
message: finalStatus,
|
|
@@ -238,7 +243,9 @@ var Liminar = function (_a) {
|
|
|
238
243
|
processosComLiminarIds: processosComAssuntoValido.map(function (p) { return p.id; }),
|
|
239
244
|
indiciosDeLiminarProtestosDoPassado: indiciosDeLiminarProtestosDoPassado,
|
|
240
245
|
protestosDoPassadoIds: protestosDoPassadoIds,
|
|
241
|
-
invertedProcessos: newIds
|
|
246
|
+
invertedProcessos: newIds,
|
|
247
|
+
origensLiminar: origensDetectadas,
|
|
248
|
+
descricaoLiminar: descricaoLiminar
|
|
242
249
|
} })); });
|
|
243
250
|
processedRef.current = true;
|
|
244
251
|
return [2 /*return*/];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var isGlobalReady = function (g) {
|
|
2
|
+
var _a, _b, _c, _d, _e;
|
|
3
|
+
return !!g.documentHistory && // veio do dossiê
|
|
4
|
+
((_a = g.liminar) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
|
|
5
|
+
((_b = g.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.isLoaded) &&
|
|
6
|
+
((_c = g.protestosData) === null || _c === void 0 ? void 0 : _c.isLoaded) &&
|
|
7
|
+
((_d = g.ccfData) === null || _d === void 0 ? void 0 : _d.isLoaded) &&
|
|
8
|
+
((_e = g.divida) === null || _e === void 0 ? void 0 : _e.isLoaded);
|
|
9
|
+
};
|