@credithub/harlan-components 1.82.1 → 1.82.3
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/liminar/liminar.js +34 -28
- package/dist/components/liminar/useLiminarProtestosDoPassado.js +1 -0
- package/dist/utils/isGlobalReady.d.ts +1 -0
- package/dist/utils/isGlobalReady.js +1 -0
- package/dist/utils/similarNames.d.ts +4 -0
- package/dist/utils/similarNames.js +72 -0
- package/lib/cjs/index.js +118 -39
- package/lib/esm/index.js +118 -39
- package/package.json +1 -1
|
@@ -49,8 +49,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
import ProtestosIcon from '../../assets/icones/protestos';
|
|
50
50
|
import { useGlobalData } from '../../contexts/globalDataContext';
|
|
51
51
|
import theme from '../../styles/theme';
|
|
52
|
+
import { isDocumentHistoryReady } from '../../utils/isGlobalReady';
|
|
52
53
|
import { formatMoney } from '../../utils/number';
|
|
53
|
-
import { normalizeName,
|
|
54
|
+
import { normalizeName, normalizeNameStrong, similarCompanyNames } from '../../utils/similarNames';
|
|
54
55
|
import { hasOneOfTags } from '../../utils/tags';
|
|
55
56
|
import { WarningCircle } from 'phosphor-react';
|
|
56
57
|
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -83,25 +84,26 @@ var businessTypes = [
|
|
|
83
84
|
'cooperativa'
|
|
84
85
|
];
|
|
85
86
|
var Liminar = function (_a) {
|
|
86
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
87
|
-
var
|
|
87
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
88
|
+
var _p = _a.isFinancial, isFinancial = _p === void 0 ? true : _p, hasCredits = _a.hasCredits, _q = _a.tags, tags = _q === void 0 ? [] : _q;
|
|
88
89
|
var ctx = useContext(Queries.LiminarCenprot);
|
|
89
|
-
var
|
|
90
|
+
var _r = useGlobalData(), globalData = _r.data, setData = _r.setData;
|
|
90
91
|
var fetchLiminarProtestosDoPassado = useLiminarProtestosDoPassado({
|
|
91
92
|
documento: ((_c = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _b === void 0 ? void 0 : _b.carousel) === null || _c === void 0 ? void 0 : _c.document) || ''
|
|
92
93
|
}).fetchLiminarProtestosDoPassado;
|
|
93
|
-
|
|
94
|
+
console.log((_d = globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory) === null || _d === void 0 ? void 0 : _d.protestoLiminar);
|
|
95
|
+
var _s = useState(false), isLoadingLiminarProtestosDoPassado = _s[0], setIsLoadingLiminarProtestosDoPassado = _s[1];
|
|
94
96
|
var processedRef = useRef(false);
|
|
95
97
|
var dataHashRef = useRef('');
|
|
96
98
|
var invertedIdsRef = useRef([]);
|
|
97
|
-
var
|
|
98
|
-
var
|
|
99
|
-
var
|
|
99
|
+
var _t = useState(false), isTooltipVisible = _t[0], setTooltipVisible = _t[1];
|
|
100
|
+
var _u = useState(false), isEmailModalOpen = _u[0], setIsEmailModalOpen = _u[1];
|
|
101
|
+
var _v = useState(''), emailModalMessage = _v[0], setEmailModalMessage = _v[1];
|
|
100
102
|
var liminarMailPrice = useMemo(function () {
|
|
101
103
|
var isDiamanteNew = hasOneOfTags(tags, ['diamante-new']);
|
|
102
104
|
return isDiamanteNew ? 0 : 50000;
|
|
103
105
|
}, [tags]);
|
|
104
|
-
var
|
|
106
|
+
var _w = useFetch("SELECT FROM 'LIMINAR'.'SENDMAIL'"), sendIndiciosEmail = _w.fetch, isEmailSending = _w.isLoading, emailError = _w.error;
|
|
105
107
|
var hideTt = useRef();
|
|
106
108
|
/*
|
|
107
109
|
* Extrai e normaliza os tipos de documento presentes em ctx.document, retornando sempre um array de strings em minúsculo.
|
|
@@ -120,14 +122,14 @@ var Liminar = function (_a) {
|
|
|
120
122
|
var _a, _b, _c, _d;
|
|
121
123
|
var carouselName = (_c = (_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
|
|
122
124
|
var empresas = (_d = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _d === void 0 ? void 0 : _d.empresa;
|
|
123
|
-
var
|
|
125
|
+
var nomeNormTokens = normalizeNameStrong(carouselName);
|
|
124
126
|
if (!Array.isArray(empresas))
|
|
125
127
|
return [];
|
|
126
128
|
return empresas.filter(function (proc) {
|
|
127
129
|
var _a;
|
|
128
130
|
var ativoMatch = (_a = proc.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (e) {
|
|
129
131
|
return e.envolvido_tipo === 'Ativo' &&
|
|
130
|
-
|
|
132
|
+
similarCompanyNames(e.nome_sem_filtro, carouselName);
|
|
131
133
|
});
|
|
132
134
|
if (!ativoMatch)
|
|
133
135
|
return false;
|
|
@@ -139,13 +141,13 @@ var Liminar = function (_a) {
|
|
|
139
141
|
});
|
|
140
142
|
});
|
|
141
143
|
}, [
|
|
142
|
-
(
|
|
143
|
-
(
|
|
144
|
+
(_e = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _e === void 0 ? void 0 : _e.carousel,
|
|
145
|
+
(_f = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _f === void 0 ? void 0 : _f.empresa
|
|
144
146
|
]);
|
|
145
147
|
/*
|
|
146
148
|
* Identifica as origens de liminares detectadas e verifica se existe liminar de protesto invertida
|
|
147
149
|
*/
|
|
148
|
-
var
|
|
150
|
+
var _x = useMemo(function () {
|
|
149
151
|
var _a, _b;
|
|
150
152
|
var labels = new Set();
|
|
151
153
|
var indiciosApi = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
|
|
@@ -180,14 +182,17 @@ var Liminar = function (_a) {
|
|
|
180
182
|
ctx.document,
|
|
181
183
|
tiposDocumento,
|
|
182
184
|
processosComAssuntoValido,
|
|
183
|
-
(
|
|
184
|
-
]), origensDetectadas =
|
|
185
|
+
(_g = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _g === void 0 ? void 0 : _g.indiciosDeLiminarProtestosDoPassado
|
|
186
|
+
]), origensDetectadas = _x.origensDetectadas, foundBusinessEntity = _x.foundBusinessEntity;
|
|
187
|
+
var documentHistoryReady = useMemo(function () { return isDocumentHistoryReady(globalData); }, [globalData]);
|
|
185
188
|
useEffect(function () {
|
|
189
|
+
if (!documentHistoryReady)
|
|
190
|
+
return;
|
|
186
191
|
var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
192
|
var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus, descricaoLiminar;
|
|
188
|
-
var _b, _c, _d;
|
|
189
|
-
return __generator(this, function (
|
|
190
|
-
switch (
|
|
193
|
+
var _b, _c, _d, _e;
|
|
194
|
+
return __generator(this, function (_f) {
|
|
195
|
+
switch (_f.label) {
|
|
191
196
|
case 0:
|
|
192
197
|
dossie = globalData === null || globalData === void 0 ? void 0 : globalData.dossie;
|
|
193
198
|
processosJuridicos = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData;
|
|
@@ -209,13 +214,13 @@ var Liminar = function (_a) {
|
|
|
209
214
|
indiciosApi = ((_c = ctx.document) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminar) === true;
|
|
210
215
|
indiciosDeLiminarProtestosDoPassado = false;
|
|
211
216
|
protestosDoPassadoIds = '';
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
console.log('status Protesto Liminar', (_d = globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory) === null || _d === void 0 ? void 0 : _d.protestoLiminar);
|
|
218
|
+
if (!((_e = globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory) === null || _e === void 0 ? void 0 : _e.protestoLiminar)) return [3 /*break*/, 2];
|
|
219
|
+
console.log('entrou');
|
|
215
220
|
setIsLoadingLiminarProtestosDoPassado(true);
|
|
216
221
|
return [4 /*yield*/, fetchLiminarProtestosDoPassado()];
|
|
217
222
|
case 1:
|
|
218
|
-
_a =
|
|
223
|
+
_a = _f.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
|
|
219
224
|
if (possuiIndiciosDeLiminarProtestosDoPassado) {
|
|
220
225
|
origensDetectadas.push('Liminar no Cenprot');
|
|
221
226
|
indiciosDeLiminarProtestosDoPassado =
|
|
@@ -223,7 +228,7 @@ var Liminar = function (_a) {
|
|
|
223
228
|
protestosDoPassadoIds = protestosIds.join(',');
|
|
224
229
|
}
|
|
225
230
|
setIsLoadingLiminarProtestosDoPassado(false);
|
|
226
|
-
|
|
231
|
+
_f.label = 2;
|
|
227
232
|
case 2:
|
|
228
233
|
finalStatus = indiciosApi ||
|
|
229
234
|
processosComAssuntoValido.length ||
|
|
@@ -260,13 +265,14 @@ var Liminar = function (_a) {
|
|
|
260
265
|
ctx.document,
|
|
261
266
|
globalData === null || globalData === void 0 ? void 0 : globalData.dossie,
|
|
262
267
|
globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData,
|
|
268
|
+
globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory,
|
|
263
269
|
processosComAssuntoValido,
|
|
264
270
|
setData,
|
|
265
271
|
foundBusinessEntity
|
|
266
272
|
]);
|
|
267
273
|
var ready = processedRef.current &&
|
|
268
|
-
!!((
|
|
269
|
-
!!((
|
|
274
|
+
!!((_h = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _h === void 0 ? void 0 : _h.isLoaded) &&
|
|
275
|
+
!!((_j = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _j === void 0 ? void 0 : _j.carousel) &&
|
|
270
276
|
!isLoadingLiminarProtestosDoPassado &&
|
|
271
277
|
ctx.type !== RequestStatus.Loading;
|
|
272
278
|
var ctxLoading = useMemo(function () { return (__assign(__assign({}, ctx), { type: RequestStatus.Loading })); }, [ctx]);
|
|
@@ -286,8 +292,8 @@ var Liminar = function (_a) {
|
|
|
286
292
|
: 'Processos com indícios encontrados:';
|
|
287
293
|
var shouldRender = isLoadingLiminarProtestosDoPassado ||
|
|
288
294
|
(ready &&
|
|
289
|
-
(((
|
|
290
|
-
((
|
|
295
|
+
(((_k = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _k === void 0 ? void 0 : _k.indiciosDeLiminar) ||
|
|
296
|
+
((_o = (_m = (_l = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _l === void 0 ? void 0 : _l.processosComLiminarIds) === null || _m === void 0 ? void 0 : _m.length) !== null && _o !== void 0 ? _o : 0) > 0));
|
|
291
297
|
// Função para disparar o envio do e-mail e configurar a mensagem do modal
|
|
292
298
|
var handleSendEmailIndicios = function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
293
299
|
var callback;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GlobalState } from '@/types/globalState.d';
|
|
2
2
|
export declare const isGlobalReady: (g: GlobalState) => boolean | undefined;
|
|
3
3
|
export declare const areModulesLoaded: (g: GlobalState) => boolean | undefined;
|
|
4
|
+
export declare const isDocumentHistoryReady: (g: GlobalState) => boolean;
|
|
@@ -14,3 +14,4 @@ export var areModulesLoaded = function (g) {
|
|
|
14
14
|
((_c = g.ccfData) === null || _c === void 0 ? void 0 : _c.isLoaded) &&
|
|
15
15
|
((_d = g.divida) === null || _d === void 0 ? void 0 : _d.isLoaded);
|
|
16
16
|
};
|
|
17
|
+
export var isDocumentHistoryReady = function (g) { return !!g.documentHistory; };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export declare const normalizeName: (name: string) => string;
|
|
2
2
|
export declare const similarNames: (name1: string, name2: string, threshold?: number) => boolean;
|
|
3
3
|
export declare const similarProcessos: (name1: string, name2: string) => boolean;
|
|
4
|
+
export declare const normalizeNameStrong: (name: string) => string[];
|
|
5
|
+
export declare const tokenCoverage: (a: string[], b: string[]) => number;
|
|
6
|
+
export declare const jaccard: (a: string[], b: string[]) => number;
|
|
7
|
+
export declare const similarCompanyNames: (raw1: string, raw2: string, jaccardThr?: number, coverThr?: number, charThr?: number) => boolean;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
1
10
|
import { remove } from 'diacritics';
|
|
2
11
|
import stringSimilarity from 'string-similarity';
|
|
3
12
|
export var normalizeName = function (name) {
|
|
@@ -18,3 +27,66 @@ export var similarProcessos = function (name1, name2) {
|
|
|
18
27
|
var similarity = stringSimilarity.compareTwoStrings(name1, name2);
|
|
19
28
|
return similarity >= 0.8;
|
|
20
29
|
};
|
|
30
|
+
// palavras que quase nunca ajudam a distinguir empresas
|
|
31
|
+
var STOP_TOKENS = new Set([
|
|
32
|
+
'ltda',
|
|
33
|
+
'limitada',
|
|
34
|
+
'eireli',
|
|
35
|
+
'sa',
|
|
36
|
+
'me',
|
|
37
|
+
'ltda',
|
|
38
|
+
'empresa',
|
|
39
|
+
'sociedade',
|
|
40
|
+
'industrial',
|
|
41
|
+
'industria',
|
|
42
|
+
'industria',
|
|
43
|
+
'industries',
|
|
44
|
+
'comercio',
|
|
45
|
+
'comercial',
|
|
46
|
+
'comerc',
|
|
47
|
+
'servicos',
|
|
48
|
+
'serviço',
|
|
49
|
+
'produtos',
|
|
50
|
+
'de',
|
|
51
|
+
'da',
|
|
52
|
+
'do',
|
|
53
|
+
'dos',
|
|
54
|
+
'e'
|
|
55
|
+
]);
|
|
56
|
+
export var normalizeNameStrong = function (name) {
|
|
57
|
+
return remove(name) // tira acentos
|
|
58
|
+
.toLowerCase()
|
|
59
|
+
.replace(/[^\w\s]/g, ' ') // só letras/números
|
|
60
|
+
.split(/\s+/) // tokeniza
|
|
61
|
+
.filter(Boolean) // remove vazios
|
|
62
|
+
.filter(function (tok) { return !STOP_TOKENS.has(tok); }) // remove termos irrelevantes
|
|
63
|
+
.sort(); // deixa ordem irrelevante
|
|
64
|
+
};
|
|
65
|
+
// porcentagem do nome mais curto que aparece no mais longo
|
|
66
|
+
export var tokenCoverage = function (a, b) {
|
|
67
|
+
var _a = a.length < b.length ? [a, b] : [b, a], shorter = _a[0], longer = _a[1];
|
|
68
|
+
var inter = shorter.filter(function (t) { return longer.includes(t); }).length;
|
|
69
|
+
return shorter.length ? inter / shorter.length : 0;
|
|
70
|
+
};
|
|
71
|
+
export var jaccard = function (a, b) {
|
|
72
|
+
var setA = new Set(a);
|
|
73
|
+
var setB = new Set(b);
|
|
74
|
+
var inter = Array.from(setA).filter(function (x) { return setB.has(x); }).length;
|
|
75
|
+
var union = new Set(__spreadArray(__spreadArray([], a, true), b, true)).size;
|
|
76
|
+
return union ? inter / union : 0;
|
|
77
|
+
};
|
|
78
|
+
export var similarCompanyNames = function (raw1, raw2, jaccardThr, coverThr, charThr) {
|
|
79
|
+
if (jaccardThr === void 0) { jaccardThr = 0.7; }
|
|
80
|
+
if (coverThr === void 0) { coverThr = 0.8; }
|
|
81
|
+
if (charThr === void 0) { charThr = 0.85; }
|
|
82
|
+
var t1 = normalizeNameStrong(raw1);
|
|
83
|
+
var t2 = normalizeNameStrong(raw2);
|
|
84
|
+
// A) Jaccard sobre tokens “bons”
|
|
85
|
+
if (jaccard(t1, t2) >= jaccardThr)
|
|
86
|
+
return true;
|
|
87
|
+
// B) Cobertura total do nome mais curto
|
|
88
|
+
if (tokenCoverage(t1, t2) >= coverThr)
|
|
89
|
+
return true;
|
|
90
|
+
// C) Fallback de similaridade de caracteres
|
|
91
|
+
return (stringSimilarity.compareTwoStrings(t1.join(' '), t2.join(' ')) >= charThr);
|
|
92
|
+
};
|