@credithub/harlan-components 1.83.7 → 1.84.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.
@@ -142,10 +142,6 @@ var ChartSystem = function (_a) {
142
142
  }, [loadingButtons, hasCredits, productsPrices, setConsultasComplementares]);
143
143
  var _p = useChartData(consultaSerasa, consultaBoaVista), chartData = _p.data, isLoadingChart = _p.isLoading, errorChart = _p.error, refetchChart = _p.refetch, chartDataProgress = _p.loadingProgress;
144
144
  var _q = useDividasPublicas(), quantidadeDividas = _q.quantidade, valorTotalDividas = _q.valorTotal, ultimaOcorrenciaDividas = _q.ultimaOcorrencia, dividasProgress = _q.loadingProgress;
145
- /**
146
- * Refaz o histórico apenas quando muda o OBJETO de resposta (não a função refetch).
147
- * Usamos um ref para lembrar o último valor e evitar chamadas repetidas.
148
- */
149
145
  var lastComplementary = useRef({
150
146
  serasa: null,
151
147
  boaVista: null
@@ -158,9 +154,8 @@ var ChartSystem = function (_a) {
158
154
  serasa: consultaSerasa,
159
155
  boaVista: consultaBoaVista
160
156
  };
161
- refetchChart(); // executa só UMA vez por nova consulta
157
+ refetchChart();
162
158
  }
163
- // refetchChart fora da lista para não disparar por identidade
164
159
  // eslint-disable-next-line react-hooks/exhaustive-deps
165
160
  }, [consultaSerasa, consultaBoaVista]);
166
161
  var errorMessage = typeof errorChart === 'string' ? new Error(errorChart) : errorChart;
@@ -27,7 +27,6 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
27
27
  }
28
28
  return [];
29
29
  }, [ctxProtestos.type, ctxProtestos.document, iaOverrides]);
30
- // aggregate progress from all contexts
31
30
  useEffect(function () {
32
31
  var _a, _b, _c, _d;
33
32
  var parts = [
@@ -47,10 +46,6 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
47
46
  ctxCCF.progress,
48
47
  ctxProcessos.progress
49
48
  ]);
50
- /**
51
- * Refaz o histórico apenas quando muda o OBJETO de resposta (não a função refetch).
52
- * Usamos um ref para lembrar o último valor e evitar chamadas repetidas.
53
- */
54
49
  var lastComplementary = useRef({
55
50
  serasa: null,
56
51
  boaVista: null
@@ -63,12 +58,10 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
63
58
  serasa: consultaSerasa,
64
59
  boaVista: consultaBoaVista
65
60
  };
66
- ctxHistory.refetch(); // executa só UMA vez por nova consulta
61
+ ctxHistory.refetch();
67
62
  }
68
- // ctxHistory.refetch fora da lista para não disparar por identidade
69
63
  // eslint-disable-next-line react-hooks/exhaustive-deps
70
64
  }, [consultaSerasa, consultaBoaVista]);
71
- // handle history response
72
65
  useEffect(function () {
73
66
  var _a;
74
67
  if (ctxHistory.type === RequestStatus.Loading) {
@@ -82,7 +75,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
82
75
  try {
83
76
  var parsed = JSON.parse(ctxHistory.document);
84
77
  parsed.protestosCategory = dadosProtestos;
85
- var processed = processData(parsed, quantidadeProcessos);
78
+ var processed = processData(structuredClone(parsed), quantidadeProcessos);
86
79
  setData(processed);
87
80
  }
88
81
  catch (_b) {
@@ -1,6 +1,6 @@
1
1
  import { ChartData, ChartOptions } from 'chart.js';
2
- import { DataInput, TimeFilter } from '../types/iChart';
3
2
  import 'chartjs-adapter-date-fns';
3
+ import { DataInput, TimeFilter } from '../types/iChart';
4
4
  export declare const useMixedChartData: (dataInput: DataInput, timeFilter?: TimeFilter) => {
5
5
  data: ChartData<"line" | "bar", (number | {
6
6
  x: string;
@@ -1,7 +1,7 @@
1
- import { useMemo } from 'react';
2
1
  import 'chartjs-adapter-date-fns';
3
- import { getEndDate, getUniqueDates, addMissingDateEntries, getFilteredStartDate, getEarliestDate } from '../utils/dataManipulation';
2
+ import { useMemo } from 'react';
4
3
  import { createDatasets, getChartOptions } from '../utils/chartCustomization';
4
+ import { addMissingDateEntries, fillMonthlyGaps, getEarliestDate, getEndDate, getFilteredStartDate, getUniqueDates } from '../utils/dataManipulation';
5
5
  export var useMixedChartData = function (dataInput, timeFilter) {
6
6
  if (timeFilter === void 0) { timeFilter = '1m'; }
7
7
  return useMemo(function () {
@@ -13,6 +13,7 @@ export var useMixedChartData = function (dataInput, timeFilter) {
13
13
  ccfs: addMissingDateEntries(dataInput.ccfs, fullDataStartDate, endDate),
14
14
  serasa: dataInput.serasa,
15
15
  boaVista: dataInput.boaVista,
16
+ processosJuridicos: fillMonthlyGaps(dataInput.processosJuridicos),
16
17
  dividasPublicasGrafico: addMissingDateEntries(dataInput.dividasPublicasGrafico, fullDataStartDate, endDate)
17
18
  };
18
19
  var processedData = {
@@ -20,6 +21,7 @@ export var useMixedChartData = function (dataInput, timeFilter) {
20
21
  ccfs: fullProcessedData.ccfs.filter(function (d) { return new Date(d.data) >= filteredStartDate; }),
21
22
  serasa: fullProcessedData.serasa.filter(function (d) { return new Date(d.data) >= filteredStartDate; }),
22
23
  boaVista: fullProcessedData.boaVista.filter(function (d) { return new Date(d.data) >= filteredStartDate; }),
24
+ processosJuridicos: fullProcessedData.processosJuridicos.filter(function (d) { return new Date(d.data) >= filteredStartDate; }),
23
25
  dividasPublicasGrafico: fullProcessedData.dividasPublicasGrafico.filter(function (d) { return new Date(d.data) >= filteredStartDate; })
24
26
  };
25
27
  var uniqueDates = getUniqueDates(processedData);
@@ -12,6 +12,7 @@ export interface DataInput {
12
12
  protestos: Consulta[];
13
13
  serasa: Consulta[];
14
14
  boaVista: Consulta[];
15
+ processosJuridicos: Consulta[];
15
16
  dividasPublicasGrafico: Consulta[];
16
17
  pieChartTotalConfig?: {
17
18
  protestos?: {
@@ -43,7 +43,8 @@ export function createDatasets(data, uniqueDates, timeFilter) {
43
43
  createDataSet(data.boaVista, 'Boa Vista - Quantidade', defaultChartColors.pefinBoaVista, 'line', 'quantidade', 'y'),
44
44
  createDataSet(data.boaVista, 'Boa Vista - Valor Total', defaultChartColors.pefinBoaVista, 'bar', 'valorTotal', 'y2'),
45
45
  createDataSet(data.dividasPublicasGrafico, 'Dívidas Públicas - Quantidade', defaultChartColors.dividasPublicas, 'line', 'quantidade', 'y'),
46
- createDataSet(data.dividasPublicasGrafico, 'Dívidas Públicas - Valor Total', defaultChartColors.dividasPublicas, 'bar', 'valorTotal', 'y2')
46
+ createDataSet(data.dividasPublicasGrafico, 'Dívidas Públicas - Valor Total', defaultChartColors.dividasPublicas, 'bar', 'valorTotal', 'y2'),
47
+ createDataSet(data.processosJuridicos, 'Processos Jurídicos', defaultChartColors.processosJuridicos, 'line', 'quantidade', 'y'),
47
48
  ];
48
49
  }
49
50
  export function getChartOptions(timeFilter) {
@@ -8,3 +8,4 @@ export declare const getBarSettings: (timeFilter: TimeFilter) => {
8
8
  categoryPercentage: number;
9
9
  barPercentage: number;
10
10
  };
11
+ export declare function fillMonthlyGaps(records: Consulta[]): Consulta[];
@@ -70,7 +70,7 @@ export var getEndDate = function () {
70
70
  return new Date();
71
71
  };
72
72
  export function getUniqueDates(data) {
73
- var allEntries = union(data.protestos, data.ccfs, data.serasa, data.boaVista, data.dividasPublicasGrafico);
73
+ var allEntries = union(data.protestos, data.ccfs, data.serasa, data.boaVista, data.dividasPublicasGrafico, data.processosJuridicos);
74
74
  var allDates = allEntries
75
75
  .map(function (entry) {
76
76
  var dateString = typeof entry.data === 'string' ? entry.data : '';
@@ -95,3 +95,53 @@ export var getBarSettings = function (timeFilter) {
95
95
  return { categoryPercentage: 1.5, barPercentage: 1.5 };
96
96
  }
97
97
  };
98
+ export function fillMonthlyGaps(records) {
99
+ if (records.length === 0)
100
+ return [];
101
+ var sortedRecords = sortByDate(records);
102
+ var result = [];
103
+ for (var i = 0; i < sortedRecords.length - 1; i++) {
104
+ var current = sortedRecords[i];
105
+ var next = sortedRecords[i + 1];
106
+ result.push(normalizeDateField(current));
107
+ var filled = generateMonthlyCopies(current, next);
108
+ result.push.apply(result, filled);
109
+ }
110
+ result.push(normalizeDateField(sortedRecords.at(-1)));
111
+ return result;
112
+ }
113
+ function sortByDate(records) {
114
+ return __spreadArray([], records, true).sort(function (a, b) {
115
+ var dateA = new Date(a.data).getTime();
116
+ var dateB = new Date(b.data).getTime();
117
+ return dateA - dateB;
118
+ });
119
+ }
120
+ function generateMonthlyCopies(start, end) {
121
+ var filledRecords = [];
122
+ var currentDate = new Date(start.data);
123
+ var endDate = new Date(end.data);
124
+ while (true) {
125
+ var nextDate = addOneMonth(currentDate);
126
+ if (nextDate >= endDate)
127
+ break;
128
+ filledRecords.push(__assign(__assign({}, start), { data: formatDateToISO(nextDate) }));
129
+ currentDate = nextDate;
130
+ }
131
+ return filledRecords;
132
+ }
133
+ function addOneMonth(date) {
134
+ var day = date.getDate();
135
+ var next = new Date(date);
136
+ next.setDate(1);
137
+ next.setMonth(next.getMonth() + 1);
138
+ var lastDayOfMonth = new Date(next.getFullYear(), next.getMonth() + 1, 0).getDate();
139
+ next.setDate(Math.min(day, lastDayOfMonth));
140
+ return next;
141
+ }
142
+ function formatDateToISO(date) {
143
+ return date.toISOString().slice(0, 10);
144
+ }
145
+ function normalizeDateField(record) {
146
+ return __assign(__assign({}, record), { data: formatDateToISO(new Date(record.data)) });
147
+ }
@@ -1,3 +1,6 @@
1
1
  import { DataInput } from '../../../components/chart/types/iChart';
2
+ /**
3
+ * Normaliza todos os datasets do DataInput.
4
+ */
2
5
  export declare const processData: (data: DataInput, quantidadeProcessosJuridicos: number) => DataInput;
3
6
  export declare function processProtestData(document: Document, iaOverrides?: Record<string, string>): DataInput['protestosCategory'];
@@ -13,63 +13,100 @@ import { classifyProtestos } from '../../../hooks/useProtestosClassification';
13
13
  import { converterParaFormatoValido, formatDatePtBrToDate } from '../../../utils/date';
14
14
  import XPathUtils from '../../../utils/xpath';
15
15
  import { groupBy, sortBy, unique } from 'underscore';
16
+ /**
17
+ * Remove pontos internos com quantidade = 0
18
+ * (mantém o 1.º e o último sempre).
19
+ */
20
+ var removeZeros = function (current, index, arr) {
21
+ return index === 0 || index === arr.length - 1
22
+ ? true
23
+ : ((current === null || current === void 0 ? void 0 : current.quantidade) || 0) > 0;
24
+ };
25
+ /** Mantém apenas break-points: 1.º, último e trocas de quantidade. */
26
+ var removeSameAsNext = function (current, index, arr) {
27
+ if (index === 0 || index === arr.length - 1)
28
+ return true;
29
+ return current.quantidade !== arr[index - 1].quantidade;
30
+ };
31
+ /** Converte chave de agrupamento (string) em timestamp ordenável. */
32
+ var keyToTime = function (key) {
33
+ return new Date(formatDatePtBrToDate(key)).getTime();
34
+ };
35
+ /**
36
+ * Normaliza todos os datasets do DataInput.
37
+ */
16
38
  export var processData = function (data, quantidadeProcessosJuridicos) {
17
- var removeZeros = function (current, index, arr) {
18
- return index === 0 || index === arr.length - 1
19
- ? true
20
- : ((current === null || current === void 0 ? void 0 : current.quantidade) || 0) > 0;
21
- };
22
- var removeSameAsNext = function (current, index, arr) {
23
- if (index === 0 || index === arr.length - 1)
24
- return true;
25
- return current.quantidade !== arr[index + 1].quantidade;
26
- };
27
- data.pieChartTotalConfig = {
28
- processosJuridicos: quantidadeProcessosJuridicos
29
- };
39
+ // ------------------------------------------------------------------
40
+ // PROTESTOS
41
+ // ------------------------------------------------------------------
30
42
  var grouped = groupBy(data.protestos, function (e) { return e.data; });
31
- data.protestos = Object.values(grouped)
32
- .map(function (e) {
33
- if (e.length === 1)
34
- return e;
35
- return e.filter(function (el) { return Number(el.quantidade) > 0; });
43
+ // transforma em array ordenado por data asc
44
+ var groupedOrdered = Object.entries(grouped).sort(function (_a, _b) {
45
+ var kA = _a[0];
46
+ var kB = _b[0];
47
+ return keyToTime(kA) - keyToTime(kB);
48
+ });
49
+ data.protestos = groupedOrdered
50
+ .map(function (_a) {
51
+ var registros = _a[1];
52
+ return registros.length === 1
53
+ ? registros
54
+ : registros.filter(function (el) { return Number(el.quantidade) > 0; });
36
55
  })
37
56
  .flat();
38
57
  data.protestos = sortBy(unique(data.protestos, function (x) { return x.data; })
39
58
  .filter(removeZeros)
40
59
  .filter(removeSameAsNext)
41
- .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data) })); }), function (info) { return info.data; });
60
+ .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data) // normaliza p/ ISO local
61
+ })); }), function (info) { return info.data; });
62
+ // ------------------------------------------------------------------
63
+ // CCFs
64
+ // ------------------------------------------------------------------
42
65
  data.ccfs = sortBy(unique(data.ccfs, function (x) { return x.data; })
43
66
  .filter(removeZeros)
44
67
  .filter(removeSameAsNext)
45
68
  .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data) })); }), function (info) { return info.data; });
69
+ // ------------------------------------------------------------------
70
+ // BOA VISTA - não tem quantidade → só formata e filtra vazios
71
+ // ------------------------------------------------------------------
46
72
  data.boaVista = data.boaVista
47
73
  .map(function (entry) {
48
74
  var formattedDate = formatDatePtBrToDate(entry.creation);
49
75
  return __assign(__assign({}, entry), { data: formattedDate, creation: undefined });
50
76
  })
51
77
  .filter(function (entry) { return entry.data; });
78
+ // ------------------------------------------------------------------
79
+ // SERASA
80
+ // ------------------------------------------------------------------
52
81
  data.serasa = data.serasa
53
82
  .map(function (entry) {
54
83
  var formattedDate = formatDatePtBrToDate(entry.creation);
55
84
  return __assign(__assign({}, entry), { data: formattedDate, creation: undefined });
56
85
  })
57
86
  .filter(function (entry) { return entry.data; });
87
+ // ------------------------------------------------------------------
88
+ // DÍVIDAS PÚBLICAS
89
+ // ------------------------------------------------------------------
58
90
  data.dividasPublicasGrafico = data.dividasPublicasGrafico
59
91
  .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data), valorTotal: info.total, total: undefined })); })
60
92
  .filter(function (info) { return info.data; });
93
+ // ------------------------------------------------------------------
94
+ // PROCESSOS JURIDICOS
95
+ // ------------------------------------------------------------------
96
+ data.processosJuridicos = data.processosJuridicos
97
+ .map(function (entry) {
98
+ var formattedDate = formatDatePtBrToDate(entry.creation);
99
+ return __assign(__assign({}, entry), { data: formattedDate, creation: undefined });
100
+ })
101
+ .filter(function (entry) { return entry.data; });
102
+ // ------------------------------------------------------------------
103
+ // PIE-CHART EXTRA
104
+ // ------------------------------------------------------------------
105
+ data.pieChartTotalConfig = {
106
+ processosJuridicos: quantidadeProcessosJuridicos
107
+ };
61
108
  return __assign(__assign({}, data), { protestos: data.protestos, ccfs: data.ccfs, boaVista: data.boaVista, serasa: data.serasa, dividasPublicasGrafico: data.dividasPublicasGrafico, pieChartTotalConfig: __assign(__assign({}, data.pieChartTotalConfig), { processosJuridicos: quantidadeProcessosJuridicos }) });
62
109
  };
63
- var obterUltimaData = function (protestos) {
64
- if (!protestos.length)
65
- return null;
66
- var datas = protestos
67
- .map(function (p) { return new Date(converterParaFormatoValido(p.dataProtesto)).getTime(); })
68
- .filter(function (d) { return !isNaN(d); });
69
- return datas.length
70
- ? new Date(Math.max.apply(Math, datas)).toLocaleDateString('pt-BR')
71
- : null;
72
- };
73
110
  export function processProtestData(document, iaOverrides) {
74
111
  var _a = classifyProtestos(document, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
75
112
  var obterUltimaData = function (protestos) {
@@ -252,7 +252,6 @@ var Liminar = function (_a) {
252
252
  }
253
253
  });
254
254
  }); };
255
- console.log('Is financial:', isFinancial);
256
255
  if (isFinancial)
257
256
  fetch();
258
257
  }, [