@credithub/harlan-components 1.70.2 → 1.71.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.
@@ -38,10 +38,11 @@ var byDate = function (protesto, protesto2) {
38
38
  return v0 - v1;
39
39
  };
40
40
  var Protestos = function () {
41
+ var _a;
41
42
  var ctx = useContext(Queries.Protestos);
42
43
  var ctxLiminar = useContext(Queries.Liminar);
43
- var setData = useGlobalData().setData;
44
- var _a = useState(false), dataUpdated = _a[0], setDataUpdated = _a[1];
44
+ var _b = useGlobalData(), globalData = _b.data, setData = _b.setData;
45
+ var _c = useState(false), dataUpdated = _c[0], setDataUpdated = _c[1];
45
46
  // Calcula o total e memorizamos esse valor para evitar recalcular a cada render
46
47
  var total = useMemo(function () {
47
48
  var _a;
@@ -100,26 +101,39 @@ var Protestos = function () {
100
101
  }, [ctx.type, ctx.document, dataUpdated, total, setData]);
101
102
  // Callback memorizado para a renderização do conteúdo em caso de sucesso
102
103
  var handleSuccess = useCallback(function (data, _ctx) {
104
+ var _a;
103
105
  var registrosText = XPathUtils.select('string(//registros)', data);
104
106
  var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
105
107
  var registros = haveException
106
108
  ? extractIntegerFromText(registrosText) + total
107
109
  : extractIntegerFromText(registrosText);
108
- var protestosDeCredito = XPathUtils.selectArray('//body//protesto', data)
109
- .filter(function (protesto) {
110
- return REGEX_PROTESTOS_DE_CREDITO.test(XPathUtils.select('string(./nomeCedente)', protesto));
111
- })
112
- .sort(byDate);
113
- var protestosDeImposto = XPathUtils.selectArray('//body//protesto', data)
114
- .filter(function (protesto) {
115
- return REGEX_PROTESTOS_DE_IMPOSTO.test(XPathUtils.select('string(./nomeCedente)', protesto));
116
- })
117
- .sort(byDate);
110
+ var iaOverrides = (((_a = globalData.protestosData) === null || _a === void 0 ? void 0 : _a.iaOverrides) ||
111
+ {});
112
+ var filterProtestos = function (regex, data, iaOverrides) {
113
+ return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
114
+ var cedente = XPathUtils.select('string(./nomeCedente)', protesto);
115
+ var apresentante = XPathUtils.select('string(./nomeApresentante)', protesto);
116
+ var chave = XPathUtils.select('string(./nm_chave)', protesto);
117
+ var iaNome = iaOverrides[chave] || '';
118
+ return (regex.test(cedente) ||
119
+ regex.test(apresentante) ||
120
+ regex.test(iaNome));
121
+ });
122
+ };
123
+ var protestosDeCredito = filterProtestos(REGEX_PROTESTOS_DE_CREDITO, data, iaOverrides).sort(byDate);
124
+ var protestosDeImposto = filterProtestos(REGEX_PROTESTOS_DE_IMPOSTO, data, iaOverrides).sort(byDate);
118
125
  var protestosGerais = XPathUtils.selectArray('//body//protesto', data)
119
126
  .filter(function (protesto) {
120
- var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
121
- return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
122
- !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
127
+ var cedente = XPathUtils.select('string(./nomeCedente)', protesto);
128
+ var apresentante = XPathUtils.select('string(./nomeApresentante)', protesto);
129
+ var chave = XPathUtils.select('string(./nm_chave)', protesto);
130
+ var iaNome = iaOverrides[chave] || '';
131
+ return (!REGEX_PROTESTOS_DE_IMPOSTO.test(cedente) &&
132
+ !REGEX_PROTESTOS_DE_IMPOSTO.test(apresentante) &&
133
+ !REGEX_PROTESTOS_DE_IMPOSTO.test(iaNome) &&
134
+ !REGEX_PROTESTOS_DE_CREDITO.test(cedente) &&
135
+ !REGEX_PROTESTOS_DE_CREDITO.test(apresentante) &&
136
+ !REGEX_PROTESTOS_DE_CREDITO.test(iaNome));
123
137
  })
124
138
  .sort(byDate);
125
139
  var elements = [
@@ -150,7 +164,7 @@ var Protestos = function () {
150
164
  : "Encontrados ".concat(registros, " protestos")
151
165
  : 'Não há ocorrência de protesto'))
152
166
  };
153
- }, [total]);
167
+ }, [total, (_a = globalData.protestosData) === null || _a === void 0 ? void 0 : _a.iaOverrides]);
154
168
  return (React.createElement(Section, { ctx: ctx, title: "Apontamentos na Central de Protestos (CENPROT)", subtitle: "Consulta de protestos de cr\u00E9dito, imposto e gerais.", icon: ProtestosIcon, onSuccess: handleSuccess }));
155
169
  };
156
170
  export default React.memo(Protestos);
@@ -1,3 +1,14 @@
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
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,15 +45,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
46
  }
36
47
  };
48
+ import { useGlobalData } from '../../contexts/globalDataContext';
37
49
  import { formatMoney } from '../../utils/number';
50
+ import { openFormThenRedirect } from '../../utils/protestosp';
38
51
  import { formatDocument } from '../../utils/string';
39
52
  import XPathUtils from '../../utils/xpath';
40
- import React, { memo, useContext, useState, useEffect, useMemo } from 'react';
53
+ import React, { memo, useContext, useEffect, useMemo, useState } from 'react';
41
54
  import AddItemField from '../common/addItem';
42
55
  import Button from '../common/button';
43
56
  import { ResultContent } from '../interface/result';
44
57
  import { WebService } from '../webservice';
45
- import { openFormThenRedirect } from '../../utils/protestosp';
46
58
  // Throttling mechanism for API requests
47
59
  var activeRequests = 0;
48
60
  var MAX_CONCURRENT_REQUESTS = 2;
@@ -64,7 +76,7 @@ var ThreeDotsLoader = function () {
64
76
  display: 'inline-flex',
65
77
  alignItems: 'center',
66
78
  marginLeft: '5px',
67
- height: '10px',
79
+ height: '10px'
68
80
  };
69
81
  // CSS for each dot
70
82
  var dotStyle = function (delay) { return ({
@@ -75,7 +87,7 @@ var ThreeDotsLoader = function () {
75
87
  background: '#aaa',
76
88
  opacity: 0.7,
77
89
  animation: 'blink 1.4s infinite',
78
- animationDelay: "".concat(delay, "s"),
90
+ animationDelay: "".concat(delay, "s")
79
91
  }); };
80
92
  // CSS animation keyframes defined as a style block
81
93
  var keyframes = "\n @keyframes blink {\n 0% { opacity: 0.2; }\n 20% { opacity: 0.8; }\n 100% { opacity: 0.2; }\n }\n ";
@@ -95,6 +107,7 @@ var AIIndicator = function () { return (React.createElement("span", { title: "In
95
107
  export var ProtestoItem = memo(function (_a) {
96
108
  var protesto = _a.protesto;
97
109
  var client = useContext(WebService);
110
+ var setData = useGlobalData().setData;
98
111
  var _b = useState(null), quemApresentou = _b[0], setQuemApresentou = _b[1];
99
112
  var _c = useState(false), loading = _c[0], setLoading = _c[1];
100
113
  var _d = useState(false), queued = _d[0], setQueued = _d[1];
@@ -104,12 +117,12 @@ export var ProtestoItem = memo(function (_a) {
104
117
  return formatter ? formatter(value) : value;
105
118
  };
106
119
  var documento = useMemo(function () { return getField('//consulta/@documento'); }, [protesto]);
120
+ var nm_chave = getField('./nm_chave');
107
121
  var formatBooleanField = function (value) {
108
122
  return value === 'true' ? 'Sim' : 'Não';
109
123
  };
110
- // Function to fetch Quem Apresentou/Protestou data
111
124
  var fetchQuemApresentou = function (nm_chave) { return __awaiter(void 0, void 0, void 0, function () {
112
- var response, error_1;
125
+ var response, nomeDetectado_1, error_1;
113
126
  return __generator(this, function (_a) {
114
127
  switch (_a.label) {
115
128
  case 0:
@@ -119,96 +132,83 @@ export var ProtestoItem = memo(function (_a) {
119
132
  _a.label = 1;
120
133
  case 1:
121
134
  _a.trys.push([1, 4, 5, 6]);
122
- return [4 /*yield*/, client.request("SELECT FROM 'PDFPROTESTO'.'AI'", { nm_chave: nm_chave, documento: documento })];
135
+ return [4 /*yield*/, client.request("SELECT FROM 'PDFPROTESTO'.'AI'", {
136
+ nm_chave: nm_chave,
137
+ documento: documento
138
+ })];
123
139
  case 2: return [4 /*yield*/, (_a.sent()).json()];
124
140
  case 3:
125
141
  response = _a.sent();
126
- // Check for "Quem Protestou" first, fallback to "Quem Apresentou"
127
- if (response) {
128
- if (response['Quem Protestou']) {
129
- setQuemApresentou(response['Quem Protestou']);
130
- setIsAIData(true); // Mark that data came from AI
131
- }
132
- else if (response['Quem Apresentou']) {
133
- setQuemApresentou(response['Quem Apresentou']);
134
- setIsAIData(true); // Mark that data came from AI
135
- }
142
+ nomeDetectado_1 = null;
143
+ if (response === null || response === void 0 ? void 0 : response['Quem Protestou']) {
144
+ nomeDetectado_1 = response['Quem Protestou'];
145
+ }
146
+ else if (response === null || response === void 0 ? void 0 : response['Quem Apresentou']) {
147
+ nomeDetectado_1 = response['Quem Apresentou'];
148
+ }
149
+ if (nomeDetectado_1) {
150
+ setQuemApresentou(nomeDetectado_1);
151
+ setIsAIData(true);
152
+ // Salva IA override globalmente
153
+ setData(function (prev) {
154
+ var _a;
155
+ var _b;
156
+ return (__assign(__assign({}, prev), { protestosData: __assign(__assign({}, prev.protestosData), { iaOverrides: __assign(__assign({}, (((_b = prev.protestosData) === null || _b === void 0 ? void 0 : _b.iaOverrides) || {})), (_a = {}, _a[nm_chave] = nomeDetectado_1, _a)) }) }));
157
+ });
136
158
  }
137
159
  return [3 /*break*/, 6];
138
160
  case 4:
139
161
  error_1 = _a.sent();
140
- console.error('Error fetching protesto data:', error_1);
162
+ console.error('Erro ao buscar dados de protesto IA:', error_1);
141
163
  return [3 /*break*/, 6];
142
164
  case 5:
143
165
  setLoading(false);
144
166
  activeRequests--;
145
- processQueue(); // Process next request in queue
167
+ processQueue();
146
168
  return [7 /*endfinally*/];
147
169
  case 6: return [2 /*return*/];
148
170
  }
149
171
  });
150
172
  }); };
151
- // Function to queue or execute the fetch request
152
173
  var queueOrExecuteFetch = function (nm_chave) {
153
- var executeRequest = function () {
154
- fetchQuemApresentou(nm_chave);
155
- };
174
+ var execute = function () { return fetchQuemApresentou(nm_chave); };
156
175
  if (activeRequests < MAX_CONCURRENT_REQUESTS) {
157
- // Execute immediately if under threshold
158
176
  activeRequests++;
159
- executeRequest();
177
+ execute();
160
178
  }
161
179
  else {
162
- // Queue the request
163
180
  setQueued(true);
164
181
  requestQueue.push(function () {
165
182
  setQueued(false);
166
- executeRequest();
183
+ execute();
167
184
  });
168
185
  }
169
186
  };
170
187
  useEffect(function () {
171
- // Check if nomeCedente is empty
172
188
  var nomeCedente = getField('./nomeCedente');
173
189
  if (nomeCedente && nomeCedente.trim() !== '')
174
190
  return;
175
- // Get nm_chave and queue/execute the request
176
- var nm_chave = getField('./nm_chave');
177
191
  if (nm_chave) {
178
192
  queueOrExecuteFetch(nm_chave);
179
193
  }
180
- // Cleanup function
181
194
  return function () {
182
- // If this component unmounts while in queue, try to remove it from queue
183
- var queueIndex = requestQueue.findIndex(function (req) {
195
+ var idx = requestQueue.findIndex(function (req) {
184
196
  return req.toString().includes(nm_chave);
185
197
  });
186
- if (queueIndex !== -1) {
187
- requestQueue.splice(queueIndex, 1);
188
- }
198
+ if (idx !== -1)
199
+ requestQueue.splice(idx, 1);
189
200
  };
190
201
  }, []);
191
- // Get the display value for Quem Protestou field
192
202
  var getQuemProtestouDisplay = function () {
193
- // First check if we have original data from the XML
194
- var originalValue = getField('./nomeCedente');
195
- // If we have original data, don't show the loader
196
- if (originalValue && originalValue.trim() !== '') {
197
- return originalValue;
198
- }
199
- // If we have AI data, show it with the indicator
200
- if (isAIData && quemApresentou) {
201
- return React.createElement(React.Fragment, null,
203
+ var original = getField('./nomeCedente');
204
+ if (original && original.trim() !== '')
205
+ return original;
206
+ if (isAIData && quemApresentou)
207
+ return (React.createElement(React.Fragment, null,
202
208
  quemApresentou,
203
- React.createElement(AIIndicator, null));
204
- }
205
- // If we're loading or queued and don't have data yet, show loader
206
- if ((loading || queued) && (!quemApresentou || quemApresentou.trim() === '')) {
207
- return React.createElement(React.Fragment, null,
208
- " ",
209
- React.createElement(ThreeDotsLoader, null));
210
- }
211
- // Fallback to empty string if nothing else applies
209
+ React.createElement(AIIndicator, null)));
210
+ if ((loading || queued) && !quemApresentou)
211
+ return React.createElement(ThreeDotsLoader, null);
212
212
  return quemApresentou || '';
213
213
  };
214
214
  return (React.createElement(ResultContent, { print: "repeat(7, 1fr)", desktop: "repeat(8, 1fr)", tablet: "repeat(4, 1fr)", mobile: "repeat(2, 1fr)" },
@@ -219,13 +219,13 @@ export var ProtestoItem = memo(function (_a) {
219
219
  React.createElement(AddItemField, { name: "Possui Anu\u00EAncia / Protesto Pago", value: formatBooleanField(getField('./temAnuencia')) }),
220
220
  React.createElement(AddItemField, { name: "Valor Do Protesto", value: formatMoney(getField('./valor')) }),
221
221
  getField('./vl_custas') && (React.createElement(AddItemField, { name: "Custas de Cart\u00F3rio para Baixa", value: formatMoney(getField('./vl_custas')) })),
222
- React.createElement(Instrumento, { nm_chave: getField('./nm_chave'), cpfCnpj: documento })));
222
+ React.createElement(Instrumento, { nm_chave: nm_chave, cpfCnpj: documento })));
223
223
  });
224
224
  export var Instrumento = function (_a) {
225
225
  var nm_chave = _a.nm_chave, cpfCnpj = _a.cpfCnpj;
226
226
  var client = useContext(WebService);
227
- var _b = React.useState(), error = _b[0], setError = _b[1];
228
- var _c = React.useState(false), isLoading = _c[0], setIsLoading = _c[1];
227
+ var _b = useState(), error = _b[0], setError = _b[1];
228
+ var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
229
229
  if (!nm_chave)
230
230
  return null;
231
231
  return (React.createElement(Button, { onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -237,7 +237,10 @@ export var Instrumento = function (_a) {
237
237
  _a.label = 1;
238
238
  case 1:
239
239
  _a.trys.push([1, 4, 5, 6]);
240
- return [4 /*yield*/, client.request("SELECT FROM 'IEPTB'.'PDF'", { nm_chave: nm_chave, documento: cpfCnpj })];
240
+ return [4 /*yield*/, client.request("SELECT FROM 'IEPTB'.'PDF'", {
241
+ nm_chave: nm_chave,
242
+ documento: cpfCnpj
243
+ })];
241
244
  case 2: return [4 /*yield*/, (_a.sent()).json()];
242
245
  case 3:
243
246
  request = _a.sent();
@@ -249,7 +252,6 @@ export var Instrumento = function (_a) {
249
252
  case 4:
250
253
  e_1 = _a.sent();
251
254
  if (/^35/.test(nm_chave)) {
252
- /* Instrumento de SP */
253
255
  openFormThenRedirect(nm_chave, cpfCnpj);
254
256
  return [2 /*return*/];
255
257
  }