@credithub/harlan-components 1.126.0 → 1.128.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/README.md +15 -0
- package/dist/components/chart/chartSystem.js +15 -5
- package/dist/components/chart/hooks/useChartData.js +18 -18
- package/dist/components/chart/hooks/useProtestosClassification.js +11 -3
- package/dist/components/chart/types/iChart.d.ts +2 -0
- package/dist/components/chart/utils/dataProcessing.d.ts +2 -0
- package/dist/components/chart/utils/dataProcessing.js +45 -15
- package/dist/components/dossie/generativeAi/dataUtils.js +4 -1
- package/dist/components/liminar/useLiminarProtestosDoPassado.js +12 -10
- package/dist/components/protestosPagosBaixados/adaptToChart.d.ts +5 -1
- package/dist/components/protestosPagosBaixados/adaptToChart.js +19 -4
- package/dist/components/protestosPagosBaixados/index.js +1 -1
- package/dist/components/webservice.d.ts +2 -8
- package/dist/components/webservice.js +1 -2
- package/dist/hooks/useProtestosClassification.js +3 -3
- package/dist/utils/date.d.ts +11 -0
- package/dist/utils/date.js +37 -0
- package/dist/utils/parseProtesto.d.ts +4 -0
- package/dist/utils/parseProtesto.js +10 -10
- package/lib/cjs/index.js +158 -64
- package/lib/esm/index.js +158 -64
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,3 +30,18 @@ Para começar a usar o **Harlan Components** em seu projeto, siga estes passos:
|
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
3. **Implementação:** Integre os componentes importados em sua aplicação.
|
|
33
|
+
|
|
34
|
+
## Consumindo sem tag API
|
|
35
|
+
|
|
36
|
+
Quando a aplicação injeta a chave em código (em vez de repassar só via URL), envolva a árvore com `WebServiceProvider` e, se o backend exigir resolução Jurischain (challenges HTTP 402), aumente o tempo de espera com `webserviceOptions`:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { WebServiceProvider } from '@credithub/harlan-components';
|
|
40
|
+
|
|
41
|
+
<WebServiceProvider
|
|
42
|
+
credential={apiKey}
|
|
43
|
+
webserviceOptions={{ jurischain: { solveTimeout: 120_000 } }}
|
|
44
|
+
>
|
|
45
|
+
{children}
|
|
46
|
+
</WebServiceProvider>
|
|
47
|
+
```
|
|
@@ -2,7 +2,7 @@ import { __assign, __awaiter, __generator, __makeTemplateObject } from "tslib";
|
|
|
2
2
|
import ResumoDeNegativacoesIcon from '../../assets/icones/resumoNegativacoes';
|
|
3
3
|
import { useGlobalData } from '../../contexts/globalDataContext';
|
|
4
4
|
import { useConsultasComplementares } from '../../hooks/useConsultasComplementares';
|
|
5
|
-
import { converterParaFormatoValido } from '../../utils/date';
|
|
5
|
+
import { converterParaFormatoValido, parseProtestHistoryRowToTime } from '../../utils/date';
|
|
6
6
|
import { areModulesLoaded } from '../../utils/isGlobalReady';
|
|
7
7
|
import { formatMoney } from '../../utils/number';
|
|
8
8
|
import { isCpf } from '../../utils/string';
|
|
@@ -133,13 +133,23 @@ var ChartSystem = function (_a) {
|
|
|
133
133
|
if (!dataUpdated && chartData && modulesReady) {
|
|
134
134
|
var protestoHistory_1 = (_b = (_a = chartData.protestos) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
135
135
|
var _a, _b;
|
|
136
|
-
|
|
136
|
+
var t = parseProtestHistoryRowToTime(p);
|
|
137
|
+
var dataStr = t
|
|
138
|
+
? new Date(t).toISOString()
|
|
139
|
+
: typeof p.data === 'string'
|
|
140
|
+
? p.data
|
|
141
|
+
: p.data instanceof Date
|
|
142
|
+
? p.data.toISOString()
|
|
143
|
+
: '';
|
|
144
|
+
return {
|
|
137
145
|
documento: documento,
|
|
138
|
-
data:
|
|
146
|
+
data: dataStr,
|
|
139
147
|
quantidade: (_a = p.quantidade) !== null && _a !== void 0 ? _a : 0,
|
|
140
148
|
valorTotal: (_b = p.valorTotal) !== null && _b !== void 0 ? _b : 0
|
|
141
|
-
}
|
|
142
|
-
}).sort(function (a, b) {
|
|
149
|
+
};
|
|
150
|
+
}).sort(function (a, b) {
|
|
151
|
+
return parseProtestHistoryRowToTime(a) - parseProtestHistoryRowToTime(b);
|
|
152
|
+
})) !== null && _b !== void 0 ? _b : [];
|
|
143
153
|
var protestoLiminar_1 = calcularProtestoLiminar(protestoHistory_1);
|
|
144
154
|
// Cria assinatura estável para evitar setState repetido
|
|
145
155
|
var signature = JSON.stringify({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Queries, RequestStatus } from '../../../components/webservice';
|
|
2
2
|
import { useGlobalData } from '../../../contexts/globalDataContext';
|
|
3
|
-
import {
|
|
3
|
+
import { formatDatePtBrToDate, parseProtestDateToTime } from '../../../utils/date';
|
|
4
4
|
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { processData, processProtestData } from '../utils/dataProcessing';
|
|
5
|
+
import { normalizeRawProtestosFirstSeen, processData, processProtestData } from '../utils/dataProcessing';
|
|
6
6
|
function getLastQuantidadeProcessosFromHistory(parsed) {
|
|
7
7
|
var _a;
|
|
8
8
|
var arr = parsed === null || parsed === void 0 ? void 0 : parsed.processosJuridicos;
|
|
@@ -37,7 +37,8 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
37
37
|
var _g = useState(false), isProcessing = _g[0], setIsProcessing = _g[1];
|
|
38
38
|
var _h = useState(false), dataReady = _h[0], setDataReady = _h[1];
|
|
39
39
|
var lastProgress = useRef(0);
|
|
40
|
-
|
|
40
|
+
/** Evita reprocessar o mesmo JSON + mesmos totais ao vivo; totais/PJ mudam → nova chave. */
|
|
41
|
+
var lastProcessSnapshotKey = useRef(null);
|
|
41
42
|
var processingTimeout = useRef(null);
|
|
42
43
|
var ctxHistory = useContext(Queries.GraficosAnaliticos);
|
|
43
44
|
var ctxProtestos = useContext(Queries.Protestos);
|
|
@@ -66,17 +67,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
66
67
|
return null;
|
|
67
68
|
var datas = protestos
|
|
68
69
|
.map(function (p) {
|
|
69
|
-
|
|
70
|
-
var dataStr = p.dataProtesto || '';
|
|
71
|
-
if (!dataStr)
|
|
72
|
-
return null;
|
|
73
|
-
var formattedDate = converterParaFormatoValido(dataStr);
|
|
74
|
-
var date = new Date(formattedDate);
|
|
75
|
-
return isNaN(date.getTime()) ? null : date.getTime();
|
|
76
|
-
}
|
|
77
|
-
catch (_a) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
70
|
+
return parseProtestDateToTime(p.dataProtesto || p.firstSeen);
|
|
80
71
|
})
|
|
81
72
|
.filter(function (d) { return d !== null; });
|
|
82
73
|
return datas.length
|
|
@@ -192,6 +183,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
192
183
|
if (ctxHistory.type === RequestStatus.Loading ||
|
|
193
184
|
ctxProtestos.type === RequestStatus.Loading ||
|
|
194
185
|
ctxCCF.type === RequestStatus.Loading) {
|
|
186
|
+
lastProcessSnapshotKey.current = null;
|
|
195
187
|
setDataReady(false);
|
|
196
188
|
setErrorState(null);
|
|
197
189
|
setIsProcessing(false);
|
|
@@ -201,20 +193,25 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
201
193
|
setErrorState(((_a = ctxHistory.error) === null || _a === void 0 ? void 0 : _a.message) || 'Erro ao consultar histórico');
|
|
202
194
|
setIsProcessing(false);
|
|
203
195
|
setDataReady(false);
|
|
204
|
-
|
|
196
|
+
lastProcessSnapshotKey.current = null;
|
|
205
197
|
return;
|
|
206
198
|
}
|
|
207
199
|
// Só processa quando TODOS os contextos estiverem prontos
|
|
208
200
|
if (allContextsReady && ctxHistory.document) {
|
|
209
201
|
var documentSnapshot_1 = ctxHistory.document;
|
|
210
|
-
|
|
211
|
-
|
|
202
|
+
var processSnapshotKey_1 = JSON.stringify({
|
|
203
|
+
doc: documentSnapshot_1,
|
|
204
|
+
totalProtestos: totalProtestos !== null && totalProtestos !== void 0 ? totalProtestos : null,
|
|
205
|
+
valorTotalProtestos: valorTotalProtestos !== null && valorTotalProtestos !== void 0 ? valorTotalProtestos : null,
|
|
206
|
+
ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos !== null && ultimaOcorrenciaProtestos !== void 0 ? ultimaOcorrenciaProtestos : null,
|
|
207
|
+
quantidadeProcessosFromPJ: quantidadeProcessosFromPJ !== null && quantidadeProcessosFromPJ !== void 0 ? quantidadeProcessosFromPJ : null
|
|
208
|
+
});
|
|
209
|
+
if (lastProcessSnapshotKey.current === processSnapshotKey_1) {
|
|
212
210
|
return;
|
|
213
211
|
}
|
|
214
212
|
// Marca como processando
|
|
215
213
|
setIsProcessing(true);
|
|
216
214
|
setDataReady(false);
|
|
217
|
-
lastProcessedDocument.current = documentSnapshot_1;
|
|
218
215
|
// Usa setTimeout para permitir que a UI atualize o estado de loading
|
|
219
216
|
processingTimeout.current = setTimeout(function () {
|
|
220
217
|
try {
|
|
@@ -222,10 +219,12 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
222
219
|
throw new Error('Document is undefined');
|
|
223
220
|
}
|
|
224
221
|
var parsed = JSON.parse(documentSnapshot_1);
|
|
222
|
+
normalizeRawProtestosFirstSeen(parsed);
|
|
225
223
|
parsed.protestosCategory = dadosProtestos;
|
|
226
224
|
var quantidadeProcessos = quantidadeProcessosFromPJ !== null && quantidadeProcessosFromPJ !== void 0 ? quantidadeProcessosFromPJ : getLastQuantidadeProcessosFromHistory(parsed);
|
|
227
225
|
var processed = processData(structuredClone(parsed), quantidadeProcessos, totalProtestos, valorTotalProtestos, ultimaOcorrenciaProtestos);
|
|
228
226
|
setData(processed);
|
|
227
|
+
lastProcessSnapshotKey.current = processSnapshotKey_1;
|
|
229
228
|
setIsProcessing(false);
|
|
230
229
|
setDataReady(true);
|
|
231
230
|
// Garante que o progresso chegue a 100% quando dados estão prontos
|
|
@@ -236,6 +235,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
236
235
|
setErrorState('Erro ao processar os dados');
|
|
237
236
|
setIsProcessing(false);
|
|
238
237
|
setDataReady(false);
|
|
238
|
+
lastProcessSnapshotKey.current = null;
|
|
239
239
|
}
|
|
240
240
|
processingTimeout.current = null;
|
|
241
241
|
}, 0);
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { REGEX_PROTESTOS_DE_CREDITO, REGEX_PROTESTOS_DE_IMPOSTO } from '../../../constants/regex';
|
|
2
|
-
import {
|
|
2
|
+
import { parseProtestDateToTime } from '../../../utils/date';
|
|
3
|
+
import { xmlFirstSeenFromNode } from '../../../utils/parseProtesto';
|
|
3
4
|
import XPathUtils from '../../../utils/xpath';
|
|
4
5
|
import { useMemo } from 'react';
|
|
5
6
|
// Função de ordenação por data
|
|
7
|
+
var protestoEffectiveDate = function (node) {
|
|
8
|
+
var _a;
|
|
9
|
+
var dp = XPathUtils.select('string(./dataProtesto)', node);
|
|
10
|
+
if (typeof dp === 'string' && dp.trim())
|
|
11
|
+
return dp.trim();
|
|
12
|
+
return (_a = xmlFirstSeenFromNode(node)) !== null && _a !== void 0 ? _a : '';
|
|
13
|
+
};
|
|
6
14
|
var byDate = function (protesto, protesto2) {
|
|
7
15
|
var _a, _b;
|
|
8
|
-
var v0 = (
|
|
9
|
-
var v1 = (
|
|
16
|
+
var v0 = (_a = parseProtestDateToTime(protestoEffectiveDate(protesto2))) !== null && _a !== void 0 ? _a : 0;
|
|
17
|
+
var v1 = (_b = parseProtestDateToTime(protestoEffectiveDate(protesto))) !== null && _b !== void 0 ? _b : 0;
|
|
10
18
|
return v0 - v1;
|
|
11
19
|
};
|
|
12
20
|
export function classifyProtestos(document, iaOverrides) {
|
|
@@ -6,6 +6,8 @@ export interface Consulta {
|
|
|
6
6
|
creation?: string | Date;
|
|
7
7
|
valorTotal?: number | null;
|
|
8
8
|
total?: number | null;
|
|
9
|
+
/** Fallback de data quando `data` vem vazia (datalake `toArray()`: `firstSeen`; JSON cru pode vir como `first_seen` — normalizado em useChartData). */
|
|
10
|
+
firstSeen?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface DataInput {
|
|
11
13
|
ccfs: Consulta[];
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DataInput } from '../../../components/chart/types/iChart';
|
|
2
|
+
/** JSON cru pode trazer `first_seen`; unifica em `firstSeen` antes de processData. */
|
|
3
|
+
export declare function normalizeRawProtestosFirstSeen(data: DataInput): void;
|
|
2
4
|
/**
|
|
3
5
|
* Normaliza todos os datasets do DataInput.
|
|
4
6
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
2
2
|
import { classifyProtestos } from '../../../hooks/useProtestosClassification';
|
|
3
|
-
import {
|
|
3
|
+
import { formatDatePtBrToDate, parseProtestDateToTime, parseProtestStringToDate } from '../../../utils/date';
|
|
4
4
|
import { parseProtesto } from '../../../utils/parseProtesto';
|
|
5
5
|
import XPathUtils from '../../../utils/xpath';
|
|
6
6
|
import { groupBy, sortBy, unique } from 'underscore';
|
|
@@ -19,10 +19,29 @@ var removeSameAsNext = function (current, index, arr) {
|
|
|
19
19
|
return true;
|
|
20
20
|
return current.quantidade !== arr[index - 1].quantidade;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
var protestoHistoricoDataEfetiva = function (e) {
|
|
23
|
+
if (typeof e.data === 'string' && e.data.trim())
|
|
24
|
+
return e.data.trim();
|
|
25
|
+
if (e.data instanceof Date && !Number.isNaN(e.data.getTime())) {
|
|
26
|
+
return e.data.toISOString().slice(0, 10);
|
|
27
|
+
}
|
|
28
|
+
var fs = e.firstSeen;
|
|
29
|
+
return typeof fs === 'string' && fs.trim() ? fs.trim() : '';
|
|
25
30
|
};
|
|
31
|
+
/** JSON cru pode trazer `first_seen`; unifica em `firstSeen` antes de processData. */
|
|
32
|
+
export function normalizeRawProtestosFirstSeen(data) {
|
|
33
|
+
data.protestos = data.protestos.map(function (row) {
|
|
34
|
+
var extra = row;
|
|
35
|
+
var merged = (typeof extra.firstSeen === 'string' && extra.firstSeen.trim()) ||
|
|
36
|
+
(typeof extra.first_seen === 'string' && extra.first_seen.trim()) ||
|
|
37
|
+
undefined;
|
|
38
|
+
var _snake = extra.first_seen, rest = __rest(extra, ["first_seen"]);
|
|
39
|
+
if (!merged)
|
|
40
|
+
return rest;
|
|
41
|
+
return __assign(__assign({}, rest), { firstSeen: merged });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var protestoKeyToTime = function (key) { var _a; return (_a = parseProtestDateToTime(key)) !== null && _a !== void 0 ? _a : 0; };
|
|
26
45
|
/**
|
|
27
46
|
* Normaliza todos os datasets do DataInput.
|
|
28
47
|
*/
|
|
@@ -30,12 +49,18 @@ export var processData = function (data, quantidadeProcessosJuridicos, totalProt
|
|
|
30
49
|
// ------------------------------------------------------------------
|
|
31
50
|
// PROTESTOS
|
|
32
51
|
// ------------------------------------------------------------------
|
|
52
|
+
data.protestos = data.protestos.map(function (e) {
|
|
53
|
+
var merged = protestoHistoricoDataEfetiva(e);
|
|
54
|
+
if (!merged)
|
|
55
|
+
return e;
|
|
56
|
+
return __assign(__assign({}, e), { data: merged });
|
|
57
|
+
});
|
|
33
58
|
var grouped = groupBy(data.protestos, function (e) { return e.data; });
|
|
34
59
|
// transforma em array ordenado por data asc
|
|
35
60
|
var groupedOrdered = Object.entries(grouped).sort(function (_a, _b) {
|
|
36
61
|
var kA = _a[0];
|
|
37
62
|
var kB = _b[0];
|
|
38
|
-
return
|
|
63
|
+
return protestoKeyToTime(kA) - protestoKeyToTime(kB);
|
|
39
64
|
});
|
|
40
65
|
data.protestos = groupedOrdered
|
|
41
66
|
.map(function (_a) {
|
|
@@ -48,8 +73,15 @@ export var processData = function (data, quantidadeProcessosJuridicos, totalProt
|
|
|
48
73
|
data.protestos = sortBy(unique(data.protestos, function (x) { return x.data; })
|
|
49
74
|
.filter(removeZeros)
|
|
50
75
|
.filter(removeSameAsNext)
|
|
51
|
-
.map(function (info) { return (__assign(__assign({}, info), { data:
|
|
52
|
-
|
|
76
|
+
.map(function (info) { return (__assign(__assign({}, info), { data: parseProtestStringToDate(info.data) })); })
|
|
77
|
+
.filter(function (info) { return !Number.isNaN(info.data.getTime()); }), function (info) { return info.data; });
|
|
78
|
+
/** Alinha o último ponto (data da consulta mais recente no histórico) com os totais ao vivo (mesma fonte que o pie). */
|
|
79
|
+
if (totalProtestos !== undefined && data.protestos.length > 0) {
|
|
80
|
+
var i = data.protestos.length - 1;
|
|
81
|
+
data.protestos[i] = __assign(__assign(__assign({}, data.protestos[i]), { quantidade: totalProtestos }), (valorTotalProtestos !== undefined
|
|
82
|
+
? { valorTotal: valorTotalProtestos }
|
|
83
|
+
: {}));
|
|
84
|
+
}
|
|
53
85
|
// ------------------------------------------------------------------
|
|
54
86
|
// CCFs
|
|
55
87
|
// ------------------------------------------------------------------
|
|
@@ -112,14 +144,12 @@ export function processProtestData(document, iaOverrides) {
|
|
|
112
144
|
// Converte Node[] para Protesto[]
|
|
113
145
|
var protestos = XPathUtils.selectArray('//body//protesto', document).map(parseProtesto);
|
|
114
146
|
var _a = classifyProtestos(protestos, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
|
|
115
|
-
var obterUltimaData = function (
|
|
116
|
-
if (!
|
|
147
|
+
var obterUltimaData = function (lista) {
|
|
148
|
+
if (!lista.length)
|
|
117
149
|
return null;
|
|
118
|
-
var datas =
|
|
119
|
-
.map(function (p) {
|
|
120
|
-
return
|
|
121
|
-
})
|
|
122
|
-
.filter(function (d) { return !isNaN(d); });
|
|
150
|
+
var datas = lista
|
|
151
|
+
.map(function (p) { return parseProtestDateToTime(p.dataProtesto || p.firstSeen); })
|
|
152
|
+
.filter(function (d) { return d !== null; });
|
|
123
153
|
return datas.length
|
|
124
154
|
? new Date(Math.max.apply(Math, datas)).toLocaleDateString('pt-BR')
|
|
125
155
|
: null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __assign, __rest, __spreadArray } from "tslib";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import { parseProtestHistoryRowToTime } from '../../../utils/date';
|
|
3
4
|
import { normalizeName, similarNames } from '../../../utils/similarNames';
|
|
4
5
|
import { safeStringify } from './responseUtils';
|
|
5
6
|
// -----------------------------------------------------------------------------
|
|
@@ -86,7 +87,9 @@ export var selectRelevantData = function (data) {
|
|
|
86
87
|
var ultimaOcorrenciaProtestos = ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.ultimaOcorrenciaProtestos;
|
|
87
88
|
if (Array.isArray(ResumoSafe === null || ResumoSafe === void 0 ? void 0 : ResumoSafe.protestoHistory) &&
|
|
88
89
|
ResumoSafe.protestoHistory.length) {
|
|
89
|
-
var latest = __spreadArray([], ResumoSafe.protestoHistory, true).sort(function (a, b) {
|
|
90
|
+
var latest = __spreadArray([], ResumoSafe.protestoHistory, true).sort(function (a, b) {
|
|
91
|
+
return parseProtestHistoryRowToTime(b) - parseProtestHistoryRowToTime(a);
|
|
92
|
+
})[0];
|
|
90
93
|
var latestWithCorrectDate = ultimaOcorrenciaProtestos
|
|
91
94
|
? __assign(__assign({}, latest), { data: ultimaOcorrenciaProtestos }) : latest;
|
|
92
95
|
protestosData = [latestWithCorrectDate];
|
|
@@ -20,7 +20,7 @@ var useLiminarProtestosDoPassado = function (_a) {
|
|
|
20
20
|
var posthog = useContext(PostHogContext).posthog;
|
|
21
21
|
var _c = useGlobalData(), globalData = _c.data, setData = _c.setData;
|
|
22
22
|
var fetch = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
23
|
-
var data, parsedData, _a, _b, normalizedData,
|
|
23
|
+
var data, parsedData, _a, _b, normalizedData, protestosDoPassado, instrumentosParaEvento, idsSomenteComChave;
|
|
24
24
|
return __generator(this, function (_c) {
|
|
25
25
|
switch (_c.label) {
|
|
26
26
|
case 0: return [4 /*yield*/, client.request("SELECT FROM 'Protestos'.'History'", {
|
|
@@ -36,25 +36,27 @@ var useLiminarProtestosDoPassado = function (_a) {
|
|
|
36
36
|
var _a;
|
|
37
37
|
return (__assign(__assign({}, item), { cpfCnpj: (_a = item.cpfCnpj) !== null && _a !== void 0 ? _a : documento }));
|
|
38
38
|
});
|
|
39
|
-
numerosChave = normalizedData
|
|
40
|
-
.filter(function (item) { return item.missingAt; })
|
|
41
|
-
.map(function (item) { return item.chave; });
|
|
42
39
|
protestosDoPassado = normalizedData.filter(function (item) { return item.missingAt; });
|
|
43
|
-
|
|
40
|
+
instrumentosParaEvento = protestosDoPassado.map(function (item) {
|
|
41
|
+
return item.chave != null && String(item.chave).trim() !== ''
|
|
42
|
+
? String(item.chave)
|
|
43
|
+
: '(sem chave)';
|
|
44
|
+
});
|
|
45
|
+
idsSomenteComChave = instrumentosParaEvento.filter(function (c) { return c !== '(sem chave)'; });
|
|
44
46
|
setData(function (prev) { return (__assign(__assign({}, prev), { protestosPagosBaixados: {
|
|
45
47
|
isLoaded: true,
|
|
46
48
|
protestos: protestosDoPassado
|
|
47
49
|
} })); });
|
|
48
|
-
if (
|
|
50
|
+
if (protestosDoPassado.length > 0 && posthog) {
|
|
49
51
|
posthog.capture('liminar_protestos_ocultos', {
|
|
50
52
|
documento: documento,
|
|
51
|
-
quantidade:
|
|
52
|
-
instrumentos:
|
|
53
|
+
quantidade: protestosDoPassado.length,
|
|
54
|
+
instrumentos: instrumentosParaEvento
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
return [2 /*return*/, {
|
|
56
|
-
possuiIndiciosDeLiminarProtestosDoPassado:
|
|
57
|
-
protestosDoPassadoIds:
|
|
58
|
+
possuiIndiciosDeLiminarProtestosDoPassado: protestosDoPassado.length > 0,
|
|
59
|
+
protestosDoPassadoIds: idsSomenteComChave
|
|
58
60
|
}];
|
|
59
61
|
}
|
|
60
62
|
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { ProtestoHistoricoItem } from '@/@types/domain/protestosPagosBaixadosTypes';
|
|
2
2
|
import type { Consulta } from '../../components/chart/types/iChart';
|
|
3
|
-
|
|
3
|
+
/** Linha já normalizada para UI, com `rowId` único para listas React. */
|
|
4
|
+
export type ProtestoHistoricoUiRow = ProtestoHistoricoItem & {
|
|
5
|
+
rowId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function adaptToUI(items: ProtestoHistoricoItem[]): ProtestoHistoricoUiRow[];
|
|
4
8
|
export declare function buildChartSeries(items: ProtestoHistoricoItem[]): Consulta[];
|
|
@@ -2,16 +2,31 @@ import { __assign } from "tslib";
|
|
|
2
2
|
// Pré-compila regexes fora do hot path
|
|
3
3
|
var ISO_RE = /^\d{4}-\d{2}-\d{2}/;
|
|
4
4
|
var BR_RE = /^(\d{2})\/(\d{2})\/(\d{4})/;
|
|
5
|
+
function assignStableRowIds(items) {
|
|
6
|
+
var baseKeys = items.map(function (i, idx) {
|
|
7
|
+
var c = i.chave;
|
|
8
|
+
if (c != null && String(c).trim() !== '')
|
|
9
|
+
return String(c);
|
|
10
|
+
return "protesto-historico-".concat(idx);
|
|
11
|
+
});
|
|
12
|
+
var counts = new Map();
|
|
13
|
+
var rowIds = baseKeys.map(function (base) {
|
|
14
|
+
var _a;
|
|
15
|
+
var n = ((_a = counts.get(base)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
16
|
+
counts.set(base, n);
|
|
17
|
+
return n === 1 ? base : "".concat(base, "__").concat(n);
|
|
18
|
+
});
|
|
19
|
+
return { rowIds: rowIds };
|
|
20
|
+
}
|
|
5
21
|
export function adaptToUI(items) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return items.map(function (i) {
|
|
22
|
+
var rowIds = assignStableRowIds(items).rowIds;
|
|
23
|
+
return items.map(function (i, idx) {
|
|
9
24
|
var _a, _b, _c, _d, _e;
|
|
10
25
|
return (__assign(__assign({}, i), { dataProtesto: (_b = (_a = i.dataProtesto) !== null && _a !== void 0 ? _a : i.data) !== null && _b !== void 0 ? _b : '', nomeCedente: (_c = i.nomeCedente) !== null && _c !== void 0 ? _c : '', nomeApresentante: (_d = i.nomeApresentante) !== null && _d !== void 0 ? _d : '', valor: Number.isFinite(i.valor)
|
|
11
26
|
? i.valor
|
|
12
27
|
: safeNumber((_e = i.valor) !== null && _e !== void 0 ? _e : i.valorProtestado), custas: Number.isFinite(i.custas)
|
|
13
28
|
? i.custas
|
|
14
|
-
: safeNumber(i.custas) }));
|
|
29
|
+
: safeNumber(i.custas), rowId: rowIds[idx] }));
|
|
15
30
|
});
|
|
16
31
|
}
|
|
17
32
|
export function buildChartSeries(items) {
|
|
@@ -77,7 +77,7 @@ var ProtestosPagosBaixados = function (_a) {
|
|
|
77
77
|
: "Foram encontrados ".concat((_l = (_k = data === null || data === void 0 ? void 0 : data.protestosPagosBaixados) === null || _k === void 0 ? void 0 : _k.protestos) === null || _l === void 0 ? void 0 : _l.length, " protestos")), variant: ((_o = (_m = data === null || data === void 0 ? void 0 : data.protestosPagosBaixados) === null || _m === void 0 ? void 0 : _m.protestos) === null || _o === void 0 ? void 0 : _o.length) ? 'error' : 'default', icon: ProtestosIcon, onSuccess: function () {
|
|
78
78
|
var protestosAdaptados = adaptToUI(items);
|
|
79
79
|
var totalProtestos = protestosAdaptados.length;
|
|
80
|
-
var children = totalProtestos ? (React.createElement(Result, null, protestosAdaptados.map(function (protesto) { return (React.createElement(ProtestoHistoricoItemComponent, { key: protesto.
|
|
80
|
+
var children = totalProtestos ? (React.createElement(Result, null, protestosAdaptados.map(function (protesto) { return (React.createElement(ProtestoHistoricoItemComponent, { key: protesto.rowId, protesto: protesto })); }))) : null;
|
|
81
81
|
return {
|
|
82
82
|
children: children
|
|
83
83
|
};
|
|
@@ -9,18 +9,12 @@ type RequestDefaults = {
|
|
|
9
9
|
urlData?: Client.Form;
|
|
10
10
|
};
|
|
11
11
|
export declare const RequestDefaultsContext: React.Context<RequestDefaults>;
|
|
12
|
-
|
|
13
|
-
export type WebServiceProviderOptions = {
|
|
14
|
-
jurischain?: {
|
|
15
|
-
enabled?: boolean;
|
|
16
|
-
solveTimeout?: number;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
12
|
+
export type WebServiceProviderOptions = Client.WebServiceOptions;
|
|
19
13
|
export declare const WebServiceProvider: FC<PropsWithChildren<{
|
|
20
14
|
credential: string;
|
|
21
15
|
defaultData?: Client.Form;
|
|
22
16
|
defaultUrlData?: Client.Form;
|
|
23
|
-
/** Ex.: `{ jurischain: { solveTimeout: 120_000 } }
|
|
17
|
+
/** Jurischain (challenges HTTP 402). Ex.: `{ jurischain: { solveTimeout: 120_000 } }`. */
|
|
24
18
|
webserviceOptions?: WebServiceProviderOptions;
|
|
25
19
|
}>>;
|
|
26
20
|
export declare function CustomProvider<T extends Client.Form = Client.Form, R = unknown>(Provider: Context<RequestContext<R>>, query: string): FC<PropsWithChildren<{
|
|
@@ -6,10 +6,9 @@ import { RequestStatus } from './requestContextTypes';
|
|
|
6
6
|
export * from './requestContextTypes';
|
|
7
7
|
export var WebService = createContext(new Client.WebService());
|
|
8
8
|
export var RequestDefaultsContext = createContext({});
|
|
9
|
-
var WebServiceClient = Client.WebService;
|
|
10
9
|
export var WebServiceProvider = function (_a) {
|
|
11
10
|
var credential = _a.credential, defaultData = _a.defaultData, defaultUrlData = _a.defaultUrlData, webserviceOptions = _a.webserviceOptions, children = _a.children;
|
|
12
|
-
return (React.createElement(WebService.Provider, { value: new
|
|
11
|
+
return (React.createElement(WebService.Provider, { value: new Client.WebService(credential, {}, 5, webserviceOptions !== null && webserviceOptions !== void 0 ? webserviceOptions : {}) },
|
|
13
12
|
React.createElement(RequestDefaultsContext.Provider, { value: { data: defaultData, urlData: defaultUrlData } }, children)));
|
|
14
13
|
};
|
|
15
14
|
var isDocument = function (value) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { REGEX_PROTESTOS_DE_CREDITO, REGEX_PROTESTOS_DE_IMPOSTO } from '../constants/regex';
|
|
2
|
-
import {
|
|
2
|
+
import { parseProtestDateToTime } from '../utils/date';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
// Função de ordenação por data
|
|
5
5
|
var byDate = function (a, b) {
|
|
6
6
|
var _a, _b;
|
|
7
|
-
var v0 = (
|
|
8
|
-
var v1 = (
|
|
7
|
+
var v0 = (_a = parseProtestDateToTime(b.dataProtesto || b.firstSeen)) !== null && _a !== void 0 ? _a : 0;
|
|
8
|
+
var v1 = (_b = parseProtestDateToTime(a.dataProtesto || a.firstSeen)) !== null && _b !== void 0 ? _b : 0;
|
|
9
9
|
return v0 - v1;
|
|
10
10
|
};
|
|
11
11
|
export function classifyProtestos(protestos, iaOverrides) {
|
package/dist/utils/date.d.ts
CHANGED
|
@@ -2,3 +2,14 @@ export declare function isDate(date: string | Date): boolean;
|
|
|
2
2
|
export declare function parseDate(dateStr: string): Date;
|
|
3
3
|
export declare function converterParaFormatoValido(data: string): string;
|
|
4
4
|
export declare function formatDatePtBrToDate(date: string): Date;
|
|
5
|
+
/**
|
|
6
|
+
* Parses protest-related date strings (ISO `yyyy-MM-dd` or pt-BR `dd/MM/yyyy`).
|
|
7
|
+
* Used for `dataProtesto` / `data` e fallback `firstSeen` (ex.: XML `first_seen` → objeto com `firstSeen`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseProtestDateToTime(value: string | undefined | null): number | null;
|
|
10
|
+
/** Converte string de protesto/histórico (ISO ou pt-BR) em `Date` para armazenar em `Consulta.data`. */
|
|
11
|
+
export declare function parseProtestStringToDate(value: string | Date | undefined | null): Date;
|
|
12
|
+
/** Timestamp a partir de `data` já materializada (histórico gravado / pós-processData). */
|
|
13
|
+
export declare function parseProtestHistoryRowToTime(row: {
|
|
14
|
+
data?: string | Date;
|
|
15
|
+
}): number;
|
package/dist/utils/date.js
CHANGED
|
@@ -18,3 +18,40 @@ export function formatDatePtBrToDate(date) {
|
|
|
18
18
|
var b = (x === null || x === void 0 ? void 0 : x.join('-')) + 'T00:00';
|
|
19
19
|
return new Date(b);
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses protest-related date strings (ISO `yyyy-MM-dd` or pt-BR `dd/MM/yyyy`).
|
|
23
|
+
* Used for `dataProtesto` / `data` e fallback `firstSeen` (ex.: XML `first_seen` → objeto com `firstSeen`).
|
|
24
|
+
*/
|
|
25
|
+
export function parseProtestDateToTime(value) {
|
|
26
|
+
if (value == null)
|
|
27
|
+
return null;
|
|
28
|
+
var s = String(value).trim();
|
|
29
|
+
if (!s)
|
|
30
|
+
return null;
|
|
31
|
+
if (/^\d{4}-\d{2}-\d{2}/.test(s)) {
|
|
32
|
+
var t_1 = new Date(s).getTime();
|
|
33
|
+
return Number.isNaN(t_1) ? null : t_1;
|
|
34
|
+
}
|
|
35
|
+
if (s.includes('/')) {
|
|
36
|
+
var t_2 = formatDatePtBrToDate(s).getTime();
|
|
37
|
+
return Number.isNaN(t_2) ? null : t_2;
|
|
38
|
+
}
|
|
39
|
+
var t = new Date(s).getTime();
|
|
40
|
+
return Number.isNaN(t) ? null : t;
|
|
41
|
+
}
|
|
42
|
+
/** Converte string de protesto/histórico (ISO ou pt-BR) em `Date` para armazenar em `Consulta.data`. */
|
|
43
|
+
export function parseProtestStringToDate(value) {
|
|
44
|
+
if (value instanceof Date)
|
|
45
|
+
return value;
|
|
46
|
+
var t = parseProtestDateToTime(value);
|
|
47
|
+
return t == null ? new Date(NaN) : new Date(t);
|
|
48
|
+
}
|
|
49
|
+
/** Timestamp a partir de `data` já materializada (histórico gravado / pós-processData). */
|
|
50
|
+
export function parseProtestHistoryRowToTime(row) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (row.data instanceof Date && !Number.isNaN(row.data.getTime())) {
|
|
53
|
+
return row.data.getTime();
|
|
54
|
+
}
|
|
55
|
+
var s = typeof row.data === 'string' && row.data.trim() ? row.data.trim() : '';
|
|
56
|
+
return (_a = parseProtestDateToTime(s)) !== null && _a !== void 0 ? _a : 0;
|
|
57
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
/** Data da primeira vez que o protesto apareceu na base (XML datalake: `./first_seen`). */
|
|
2
|
+
export declare function xmlFirstSeenFromNode(node: Node): string | undefined;
|
|
1
3
|
export interface Protesto {
|
|
2
4
|
nm_chave: string;
|
|
3
5
|
cpfCnpj: string;
|
|
4
6
|
nomeCedente: string;
|
|
5
7
|
nomeApresentante: string;
|
|
6
8
|
dataProtesto: string;
|
|
9
|
+
/** Primeira vez que o protesto apareceu na base (XML `first_seen` → mesmo nome que `toArray()` PHP: `firstSeen`). */
|
|
10
|
+
firstSeen?: string;
|
|
7
11
|
valor: string;
|
|
8
12
|
vl_custas?: string;
|
|
9
13
|
temAnuencia: boolean;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
1
2
|
import XPathUtils from '../utils/xpath';
|
|
3
|
+
/** Data da primeira vez que o protesto apareceu na base (XML datalake: `./first_seen`). */
|
|
4
|
+
export function xmlFirstSeenFromNode(node) {
|
|
5
|
+
var raw = XPathUtils.select('string(./first_seen)', node);
|
|
6
|
+
if (typeof raw === 'string' && raw.trim())
|
|
7
|
+
return raw.trim();
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
2
10
|
export var parseProtesto = function (node) {
|
|
3
11
|
var $ = function (xp) { return XPathUtils.select("string(".concat(xp, ")"), node); };
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
cpfCnpj: $('./cpfCnpj'),
|
|
7
|
-
nomeCedente: $('./nomeCedente'),
|
|
8
|
-
nomeApresentante: $('./nomeApresentante'),
|
|
9
|
-
dataProtesto: $('./dataProtesto'),
|
|
10
|
-
valor: $('./valor'),
|
|
11
|
-
vl_custas: $('./vl_custas') || undefined,
|
|
12
|
-
temAnuencia: $('./temAnuencia') === 'true'
|
|
13
|
-
};
|
|
12
|
+
var firstSeen = xmlFirstSeenFromNode(node);
|
|
13
|
+
return __assign(__assign({ nm_chave: $('./nm_chave'), cpfCnpj: $('./cpfCnpj'), nomeCedente: $('./nomeCedente'), nomeApresentante: $('./nomeApresentante'), dataProtesto: $('./dataProtesto') }, (firstSeen ? { firstSeen: firstSeen } : {})), { valor: $('./valor'), vl_custas: $('./vl_custas') || undefined, temAnuencia: $('./temAnuencia') === 'true' });
|
|
14
14
|
};
|