@credithub/harlan-components 1.81.7 → 1.82.1

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.
@@ -53,10 +53,11 @@ import ResumoDeNegativacoesIcon from '../../assets/icones/resumoNegativacoes';
53
53
  import { useGlobalData } from '../../contexts/globalDataContext';
54
54
  import { useConsultasComplementares } from '../../hooks/useConsultasComplementares';
55
55
  import { converterParaFormatoValido } from '../../utils/date';
56
+ import { areModulesLoaded } from '../../utils/isGlobalReady';
56
57
  import { formatMoney } from '../../utils/number';
57
58
  import { isCpf } from '../../utils/string';
58
59
  import { Spinner } from 'phosphor-react';
59
- import React, { useContext, useEffect, useState } from 'react';
60
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
60
61
  import styled from 'styled-components';
61
62
  import useToggle from '../../hooks/useToggle';
62
63
  import { ConsultasComplementaresContext } from '../consultasComplementares';
@@ -90,12 +91,12 @@ var ChartSystem = function (_a) {
90
91
  var documento = _a.documento;
91
92
  var ctxConsultasComplementares = useContext(ConsultasComplementaresContext);
92
93
  var _k = useConsultasComplementares(), consultasComplementares = _k.consultasComplementares, setConsultasComplementares = _k.setConsultasComplementares, hasCredits = _k.hasCredits;
93
- var setGlobalState = useGlobalData().setData;
94
- var _l = useState(false), dataUpdated = _l[0], setDataUpdated = _l[1];
94
+ var _l = useGlobalData(), globalData = _l.data, setGlobalState = _l.setData;
95
+ var _m = useState(false), dataUpdated = _m[0], setDataUpdated = _m[1];
95
96
  var ultimaOcorrenciaCCF = useUltimaOcorrenciaCCF();
96
97
  var consultaSerasa = (_c = (_b = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _b === void 0 ? void 0 : _b.refinSerasa) === null || _c === void 0 ? void 0 : _c.data;
97
98
  var consultaBoaVista = (_e = (_d = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _d === void 0 ? void 0 : _d.refinBoaVista) === null || _e === void 0 ? void 0 : _e.data;
98
- var _m = useState({}), loadingButtons = _m[0], setLoadingButtons = _m[1];
99
+ var _o = useState({}), loadingButtons = _o[0], setLoadingButtons = _o[1];
99
100
  var productsPrices = getProductsPrices(isCpf(documento));
100
101
  var handleOnClick = function (key) {
101
102
  return function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -139,8 +140,8 @@ var ChartSystem = function (_a) {
139
140
  });
140
141
  }); };
141
142
  };
142
- var _o = useChartData(consultaSerasa, consultaBoaVista), chartData = _o.data, isLoadingChart = _o.isLoading, errorChart = _o.error, refetchChart = _o.refetch, chartDataProgress = _o.loadingProgress;
143
- var _p = useDividasPublicas(), quantidadeDividas = _p.quantidade, valorTotalDividas = _p.valorTotal, ultimaOcorrenciaDividas = _p.ultimaOcorrencia, dividasProgress = _p.loadingProgress;
143
+ var _p = useChartData(consultaSerasa, consultaBoaVista), chartData = _p.data, isLoadingChart = _p.isLoading, errorChart = _p.error, refetchChart = _p.refetch, chartDataProgress = _p.loadingProgress;
144
+ var _q = useDividasPublicas(), quantidadeDividas = _q.quantidade, valorTotalDividas = _q.valorTotal, ultimaOcorrenciaDividas = _q.ultimaOcorrencia, dividasProgress = _q.loadingProgress;
144
145
  useEffect(function () {
145
146
  if (consultaSerasa || consultaBoaVista) {
146
147
  refetchChart();
@@ -150,8 +151,8 @@ var ChartSystem = function (_a) {
150
151
  var isOpen = useToggle(true)[0];
151
152
  var quantidadeProtestos = ((_g = (_f = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _f === void 0 ? void 0 : _f[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _g === void 0 ? void 0 : _g.quantidade) || 0;
152
153
  var valorTotalProtestos = ((_j = (_h = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _h === void 0 ? void 0 : _h[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _j === void 0 ? void 0 : _j.valorTotal) || 0;
153
- var _q = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _q.quantidade, valorTotalSerasa = _q.valorTotal, ultimaOcorrenciaSerasa = _q.dataMaisRecente;
154
- var _r = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _r.quantidade, valorTotalBoaVista = _r.valorTotal, ultimaOcorrenciaBoaVista = _r.dataMaisRecente;
154
+ var _r = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _r.quantidade, valorTotalSerasa = _r.valorTotal, ultimaOcorrenciaSerasa = _r.dataMaisRecente;
155
+ var _s = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _s.quantidade, valorTotalBoaVista = _s.valorTotal, ultimaOcorrenciaBoaVista = _s.dataMaisRecente;
155
156
  var quantidadeCCFs = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.ccfs) || []).quantidade;
156
157
  var ultimaOcorrenciaProtestos = '';
157
158
  if ((chartData === null || chartData === void 0 ? void 0 : chartData.protestosCategory) && chartData.protestosCategory.length > 0) {
@@ -173,9 +174,10 @@ var ChartSystem = function (_a) {
173
174
  }
174
175
  }
175
176
  var loadingProgress = (chartDataProgress + dividasProgress) / 2;
177
+ var modulesReady = useMemo(function () { return areModulesLoaded(globalData); }, [globalData]);
176
178
  useEffect(function () {
177
179
  var _a, _b;
178
- if (!dataUpdated && chartData) {
180
+ if (!dataUpdated && chartData && modulesReady) {
179
181
  var protestoHistory_1 = (_b = (_a = chartData.protestos) === null || _a === void 0 ? void 0 : _a.map(function (p) {
180
182
  var _a, _b;
181
183
  return ({
@@ -211,13 +213,13 @@ var ChartSystem = function (_a) {
211
213
  ? ultimaOcorrenciaSerasa
212
214
  : undefined
213
215
  };
214
- console.log('documentHistory', docHistory);
215
216
  return __assign(__assign({}, prev), { documentHistory: docHistory });
216
217
  });
217
218
  setDataUpdated(true);
218
219
  }
219
220
  }, [
220
221
  chartData,
222
+ modulesReady,
221
223
  quantidadeDividas,
222
224
  valorTotalDividas,
223
225
  ultimaOcorrenciaDividas,
@@ -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
- var innerData = data[key];
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.keys(item).reduce(function (limitedItem, key, index) {
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,143 @@ export function limitDataSize(items, maxItems) {
65
49
  function isEmptyObject(obj) {
66
50
  if (typeof obj !== 'object' || obj === null)
67
51
  return false;
68
- return Object.values(obj).every(function (value) { return isEmptyObject(value); });
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 cleanedArray = data
75
- .map(function (item) { return deepCleanData(item); })
76
- .filter(function (item) {
77
- return item !== null &&
78
- item !== undefined &&
79
- item !== '' &&
80
- !(Array.isArray(item) && item.length === 0);
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 cleanedArray.length > 0 ? cleanedArray : null;
76
+ return arr.length ? arr : null;
83
77
  }
84
- var cleanedObject = Object.entries(data).reduce(function (acc, _a) {
85
- var key = _a[0], value = _a[1];
86
- if (key === 'props')
87
- return acc;
88
- var cleanedValue = deepCleanData(value);
89
- if (cleanedValue !== null &&
90
- cleanedValue !== undefined &&
91
- cleanedValue !== '' &&
92
- !(typeof cleanedValue === 'object' && isEmptyObject(cleanedValue))) {
93
- acc[key] = cleanedValue;
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
- return acc;
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 _g = data || {}, protestosDeCredito = _g.protestos, chequesSemFundo = _g.ccf, dividasPublicas = _g.dividasPublicas, contasBancarias = _g.bankAccounts, dadosDeChequesSemFundo = _g.ccfData, dividas = _g.divida, _h = _g.dossie, dossie = _h === void 0 ? {} : _h, liminar = _g.liminar, socios = _g.partners, dadosPessoasExpostasPoliticamente = _g.pepData, detalhesProcessosJuridicos = _g.processosJuridicosData, dadosReclameAqui = _g.reclameAqui, relatoriosRefinBoaVista = _g.refinBoaVista, relatoriosRefinSerasa = _g.refinSerasa, dadosScore = _g.scoreData, relatoriosSCR = _g.scr, registrosDeVeiculos = _g.veiculos, ResumoDosDados = _g.documentHistory;
102
- var _j = ResumoDosDados !== null && ResumoDosDados !== void 0 ? ResumoDosDados : {}, _omit = _j.protestoLiminar, ResumoDosDadosSafe = __rest(_j, ["protestoLiminar"]);
103
- if ((ResumoDosDadosSafe === null || ResumoDosDadosSafe === void 0 ? void 0 : ResumoDosDadosSafe.protestoHistory) &&
104
- Array.isArray(ResumoDosDadosSafe.protestoHistory) &&
105
- ResumoDosDadosSafe.protestoHistory.length) {
106
- var latest = __spreadArray([], ResumoDosDadosSafe.protestoHistory, true).sort(function (a, b) { return new Date(b.data).getTime() - new Date(a.data).getTime(); })[0];
107
- ResumoDosDadosSafe.protestoHistory = [latest];
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
- var tipoPessoa = ((_b = (_a = dossie === null || dossie === void 0 ? void 0 : dossie.carousel) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.replace(/\D/g, '').length) === 11
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
+ // ────────────────────────────────────────────────
140
+ // 3. Liminar
141
+ // ────────────────────────────────────────────────
142
+ 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)
143
+ ? { descricao: liminar.descricaoLiminar, origens: liminar.origensLiminar }
144
+ : undefined;
145
+ // ────────────────────────────────────────────────
146
+ // 4. Tipo de pessoa
147
+ // ────────────────────────────────────────────────
148
+ 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
149
  ? 'Pessoa Física'
111
150
  : 'Pessoa Jurídica';
112
- var sociosAnonimizados = (_c = socios === null || socios === void 0 ? void 0 : socios.partners) === null || _c === void 0 ? void 0 : _c.map(function (socio, index) { return ({
113
- nome: "S\u00F3cio ".concat(index + 1),
114
- cargo: socio.cargo,
115
- receitaStatus: socio.receitaStatus || {},
116
- dividasPublicas: socio.dividasPublicas || {},
117
- protestos: socio.protestos || {}
118
- }); });
119
- var empresaNomeNormalizado = normalizeName((_d = dossie.carousel) === null || _d === void 0 ? void 0 : _d.name);
120
- var processosPassivos = (_f = (_e = detalhesProcessosJuridicos === null || detalhesProcessosJuridicos === void 0 ? void 0 : detalhesProcessosJuridicos.empresa) === null || _e === void 0 ? void 0 : _e.filter(function (processo) {
121
- var _a;
122
- return (_a = processo.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (envolvido) {
123
- var nomeNormalizado = normalizeName(envolvido.nome_sem_filtro);
124
- return (similarNames(nomeNormalizado, empresaNomeNormalizado) &&
125
- envolvido.envolvido_tipo === 'Passivo');
151
+ // ────────────────────────────────────────────────
152
+ // 5. Sócios anonimizados
153
+ // ────────────────────────────────────────────────
154
+ var sociosAnonimizados = (_h = socios === null || socios === void 0 ? void 0 : socios.partners) === null || _h === void 0 ? void 0 : _h.map(function (s, i) {
155
+ var _a, _b, _c;
156
+ return ({
157
+ nome: "S\u00F3cio ".concat(i + 1),
158
+ cargo: s.cargo,
159
+ receitaStatus: (_a = s.receitaStatus) !== null && _a !== void 0 ? _a : {},
160
+ dividasPublicas: (_b = s.dividasPublicas) !== null && _b !== void 0 ? _b : {},
161
+ protestos: (_c = s.protestos) !== null && _c !== void 0 ? _c : {}
126
162
  });
127
- })) === null || _f === void 0 ? void 0 : _f.map(function (processo) { return ({
128
- assuntos: processo.assuntos,
129
- classe_processual: processo.classe_processual,
130
- diario_sigla: processo.diario_sigla,
131
- updated_at: processo.updated_at
132
- }); });
133
- var resumoDaEmpresa = dossie.summary;
134
- var statusLiminar = (liminar === null || liminar === void 0 ? void 0 : liminar.indiciosDeLiminar)
135
- ? 'Indício de Liminar para Ocultar Protestos'
136
- : undefined;
137
- var dadosOrganizados = __assign(__assign({ protestosDeCredito: protestosDeCredito, processosJuridicosPassivos: processosPassivos, chequesSemFundo: chequesSemFundo, dividasPublicas: dividasPublicas, contasBancarias: contasBancarias, dadosDeChequesSemFundo: dadosDeChequesSemFundo, dividas: dividas, resumoDaEmpresa: resumoDaEmpresa }, (statusLiminar && { liminar: statusLiminar })), { socios: sociosAnonimizados, dadosPessoasExpostasPoliticamente: dadosPessoasExpostasPoliticamente, dadosReclameAqui: dadosReclameAqui, relatoriosRefinBoaVista: relatoriosRefinBoaVista, relatoriosRefinSerasa: relatoriosRefinSerasa, dadosScore: dadosScore, relatoriosSCR: relatoriosSCR, registrosDeVeiculos: registrosDeVeiculos, ResumoDosDados: ResumoDosDadosSafe, tipoPessoa: tipoPessoa });
138
- var dadosFiltrados = deepCleanData(dadosOrganizados);
139
- return {
140
- dadosFiltrados: dadosFiltrados
163
+ });
164
+ // ────────────────────────────────────────────────
165
+ // 6. Construção final
166
+ // ────────────────────────────────────────────────
167
+ var dadosOrganizados = {
168
+ protestosData: protestosData,
169
+ quantidadeProtestos: (_j = ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.quantidadeProtestos) !== null && _j !== void 0 ? _j : protestosData.length,
170
+ ccf: (_k = ccfNumero !== null && ccfNumero !== void 0 ? ccfNumero : ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.quantidadeChequesSemFundos) !== null && _k !== void 0 ? _k : 0,
171
+ ccfData: ccfData !== null && ccfData !== void 0 ? ccfData : {},
172
+ dividasPublicas: dividasPublicas,
173
+ liminar: liminarInfo,
174
+ ProcessosJuridicos: ProcessosJuridicos,
175
+ refinBoaVista: refinBoaVista !== null && refinBoaVista !== void 0 ? refinBoaVista : [],
176
+ refinSerasa: refinSerasa !== null && refinSerasa !== void 0 ? refinSerasa : [],
177
+ scr: scr,
178
+ veiculos: veiculos,
179
+ bankAccounts: contasBancarias,
180
+ dividas: dividas,
181
+ resumoDaEmpresa: dossie.summary,
182
+ socios: sociosAnonimizados,
183
+ dadosPessoasExpostasPoliticamente: dadosPessoasExpostasPoliticamente,
184
+ dadosReclameAqui: dadosReclameAqui,
185
+ dadosScore: dadosScore,
186
+ ResumoDosDados: ResumoSafe,
187
+ tipoPessoa: tipoPessoa
141
188
  };
189
+ var dadosFiltrados = deepCleanData(dadosOrganizados);
190
+ return { dadosFiltrados: dadosFiltrados };
142
191
  };
@@ -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
- // Verifica se os dados globais estão carregados
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 && isGlobalDataLoaded) {
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 (error) {
108
- console.error('Erro ao preparar os dados para a API:', error);
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, isGlobalDataLoaded, serializedData]);
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,3 @@
1
+ import { GlobalState } from '@/types/globalState.d';
2
+ export declare const isGlobalReady: (g: GlobalState) => boolean | undefined;
3
+ export declare const areModulesLoaded: (g: GlobalState) => boolean | undefined;
@@ -0,0 +1,16 @@
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
+ };
10
+ export var areModulesLoaded = function (g) {
11
+ var _a, _b, _c, _d;
12
+ return ((_a = g.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
13
+ ((_b = g.protestosData) === null || _b === void 0 ? void 0 : _b.isLoaded) &&
14
+ ((_c = g.ccfData) === null || _c === void 0 ? void 0 : _c.isLoaded) &&
15
+ ((_d = g.divida) === null || _d === void 0 ? void 0 : _d.isLoaded);
16
+ };