@credithub/harlan-components 1.111.1 → 1.112.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.
@@ -0,0 +1,213 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { sendInstrumentoDiscoveryEmail, sendInstrumentoManualEmail } from '../../../adapters/instrumentoProtesto/ieptbInstrumento';
38
+ import { useCallback, useState } from 'react';
39
+ import { mockDescobertaAutomaticaEmail, mockDescobrirInstrumento, mockEnviarEmailSP } from './mocks/instrumentoMocks';
40
+ /**
41
+ * Hook para gerenciar o fluxo de instrumento de protesto (fase mockada)
42
+ *
43
+ * Gerencia estados dos modais, handlers mockados e transições de estado.
44
+ * Na fase de integração real, os handlers mockados serão substituídos
45
+ * por chamadas ao InstrumentoService.
46
+ */
47
+ export var useInstrumento = function (_a) {
48
+ var nmChave = _a.nmChave, cpfCnpj = _a.cpfCnpj, client = _a.client;
49
+ var _b = useState(false), isModalSPOpen = _b[0], setIsModalSPOpen = _b[1];
50
+ var _c = useState(false), isEmailModalOpen = _c[0], setIsEmailModalOpen = _c[1];
51
+ var _d = useState(''), emailMessage = _d[0], setEmailMessage = _d[1];
52
+ var _e = useState('Instrumento de Protesto'), emailTitle = _e[0], setEmailTitle = _e[1];
53
+ var _f = useState(false), isDescobrindo = _f[0], setIsDescobrindo = _f[1];
54
+ var _g = useState(false), isEnviandoEmail = _g[0], setIsEnviandoEmail = _g[1];
55
+ var _h = useState(false), isProcessandoDescoberta = _h[0], setIsProcessandoDescoberta = _h[1];
56
+ var openModalSP = useCallback(function () {
57
+ setIsModalSPOpen(true);
58
+ }, []);
59
+ var closeModalSP = useCallback(function () {
60
+ setIsModalSPOpen(false);
61
+ }, []);
62
+ var closeEmailModal = useCallback(function () {
63
+ setIsEmailModalOpen(false);
64
+ setEmailMessage('');
65
+ setEmailTitle('Instrumento de Protesto');
66
+ }, []);
67
+ var handleDescobrir = useCallback(function (livro, folha) { return __awaiter(void 0, void 0, void 0, function () {
68
+ var result, error_1;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0:
72
+ setIsDescobrindo(true);
73
+ _a.label = 1;
74
+ case 1:
75
+ _a.trys.push([1, 3, 4, 5]);
76
+ return [4 /*yield*/, mockDescobrirInstrumento(livro, folha)];
77
+ case 2:
78
+ result = _a.sent();
79
+ if (result.success) {
80
+ setEmailTitle('Instrumento Descoberto');
81
+ setEmailMessage(result.message);
82
+ setIsEmailModalOpen(true);
83
+ // Fecha o modal SP após sucesso
84
+ setIsModalSPOpen(false);
85
+ }
86
+ else {
87
+ setEmailTitle('Erro ao Descobrir Instrumento');
88
+ setEmailMessage(result.message);
89
+ setIsEmailModalOpen(true);
90
+ }
91
+ return [3 /*break*/, 5];
92
+ case 3:
93
+ error_1 = _a.sent();
94
+ setEmailTitle('Erro ao Descobrir Instrumento');
95
+ setEmailMessage('Ocorreu um erro inesperado ao tentar descobrir o instrumento. Tente novamente mais tarde.');
96
+ setIsEmailModalOpen(true);
97
+ return [3 /*break*/, 5];
98
+ case 4:
99
+ setIsDescobrindo(false);
100
+ return [7 /*endfinally*/];
101
+ case 5: return [2 /*return*/];
102
+ }
103
+ });
104
+ }); }, []);
105
+ var handleEnviarEmail = useCallback(function (livro, folha) { return __awaiter(void 0, void 0, void 0, function () {
106
+ var res, result, error_2;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ setIsEnviandoEmail(true);
111
+ _a.label = 1;
112
+ case 1:
113
+ _a.trys.push([1, 5, 6, 7]);
114
+ if (!(client && cpfCnpj)) return [3 /*break*/, 3];
115
+ return [4 /*yield*/, sendInstrumentoManualEmail(client, {
116
+ documento: cpfCnpj,
117
+ nm_chave: nmChave,
118
+ livro: livro,
119
+ folha: folha
120
+ })];
121
+ case 2:
122
+ res = _a.sent();
123
+ setEmailTitle('Instrumento solicitado por e-mail');
124
+ setEmailMessage((res === null || res === void 0 ? void 0 : res.message) ||
125
+ 'Ok! Vamos processar e enviar o instrumento para seu e-mail assim que estiver disponível.');
126
+ setIsEmailModalOpen(true);
127
+ setIsModalSPOpen(false);
128
+ return [2 /*return*/];
129
+ case 3: return [4 /*yield*/, mockEnviarEmailSP(livro, folha)];
130
+ case 4:
131
+ result = _a.sent();
132
+ setEmailTitle('Instrumento solicitado por e-mail');
133
+ setEmailMessage(result.message);
134
+ setIsEmailModalOpen(true);
135
+ // Fecha o modal SP após envio
136
+ setIsModalSPOpen(false);
137
+ return [3 /*break*/, 7];
138
+ case 5:
139
+ error_2 = _a.sent();
140
+ setEmailTitle('Erro ao Enviar E-mail');
141
+ setEmailMessage('Não foi possível solicitar o instrumento por e-mail agora. Tente novamente em instantes.');
142
+ setIsEmailModalOpen(true);
143
+ return [3 /*break*/, 7];
144
+ case 6:
145
+ setIsEnviandoEmail(false);
146
+ return [7 /*endfinally*/];
147
+ case 7: return [2 /*return*/];
148
+ }
149
+ });
150
+ }); }, [client, cpfCnpj, nmChave]);
151
+ var handleDescobertaAutomatica = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
152
+ var res, result, error_3;
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0:
156
+ if (!cpfCnpj) {
157
+ setEmailTitle('Erro');
158
+ setEmailMessage('Documento não disponível para descoberta automática.');
159
+ setIsEmailModalOpen(true);
160
+ return [2 /*return*/];
161
+ }
162
+ setIsProcessandoDescoberta(true);
163
+ _a.label = 1;
164
+ case 1:
165
+ _a.trys.push([1, 5, 6, 7]);
166
+ if (!client) return [3 /*break*/, 3];
167
+ return [4 /*yield*/, sendInstrumentoDiscoveryEmail(client, {
168
+ documento: cpfCnpj,
169
+ nm_chave: nmChave
170
+ })];
171
+ case 2:
172
+ res = _a.sent();
173
+ setEmailTitle('Solicitação enviada');
174
+ setEmailMessage((res === null || res === void 0 ? void 0 : res.message) ||
175
+ 'Pronto! Iniciamos o processamento e você receberá o instrumento por e-mail assim que estiver disponível.');
176
+ setIsEmailModalOpen(true);
177
+ return [2 /*return*/];
178
+ case 3: return [4 /*yield*/, mockDescobertaAutomaticaEmail(nmChave, cpfCnpj)];
179
+ case 4:
180
+ result = _a.sent();
181
+ setEmailTitle('Solicitação enviada');
182
+ setEmailMessage(result.message);
183
+ setIsEmailModalOpen(true);
184
+ return [3 /*break*/, 7];
185
+ case 5:
186
+ error_3 = _a.sent();
187
+ setEmailTitle('Erro na solicitação');
188
+ setEmailMessage('Não foi possível iniciar a solicitação por e-mail agora. Tente novamente em instantes.');
189
+ setIsEmailModalOpen(true);
190
+ return [3 /*break*/, 7];
191
+ case 6:
192
+ setIsProcessandoDescoberta(false);
193
+ return [7 /*endfinally*/];
194
+ case 7: return [2 /*return*/];
195
+ }
196
+ });
197
+ }); }, [client, nmChave, cpfCnpj]);
198
+ return {
199
+ isModalSPOpen: isModalSPOpen,
200
+ isEmailModalOpen: isEmailModalOpen,
201
+ emailMessage: emailMessage,
202
+ emailTitle: emailTitle,
203
+ isDescobrindo: isDescobrindo,
204
+ isEnviandoEmail: isEnviandoEmail,
205
+ isProcessandoDescoberta: isProcessandoDescoberta,
206
+ openModalSP: openModalSP,
207
+ closeModalSP: closeModalSP,
208
+ handleDescobrir: handleDescobrir,
209
+ handleEnviarEmail: handleEnviarEmail,
210
+ handleDescobertaAutomatica: handleDescobertaAutomatica,
211
+ closeEmailModal: closeEmailModal
212
+ };
213
+ };
@@ -58,13 +58,17 @@ var __rest = (this && this.__rest) || function (s, e) {
58
58
  };
59
59
  import { useGlobalData } from '../../contexts/globalDataContext';
60
60
  import { formatMoney } from '../../utils/number';
61
- import { openFormThenRedirect } from '../../utils/protestosp';
61
+ import { isProtestoSPByNmChave } from '../../utils/protestoUf';
62
62
  import { formatDocument } from '../../utils/string';
63
63
  import React, { memo, useCallback, useContext, useEffect, useMemo, useState } from 'react';
64
64
  import AddItemField from '../common/addItem';
65
65
  import Button from '../common/button';
66
+ import ModalInstrumentoProtestoSP from '../common/modalInstrumentoProtestoSP';
66
67
  import { ResultContent } from '../interface/result';
67
68
  import { WebService } from '../webservice';
69
+ import InstrumentoEmailStatusModal from './instrumento/InstrumentoEmailStatusModal';
70
+ import InstrumentoDiscoveryConfirmModal from './instrumento/InstrumentoDiscoveryConfirmModal';
71
+ import { useInstrumento } from './instrumento/useInstrumento';
68
72
  // Throttling mechanism for API requests
69
73
  var activeRequests = 0;
70
74
  var MAX_CONCURRENT_REQUESTS = 2;
@@ -279,6 +283,12 @@ export var Instrumento = function (_a) {
279
283
  var checkedInstruments = protestosData.checkedInstruments || {};
280
284
  var instrumentCache = protestosData.instrumentCache || {};
281
285
  var normalizedKey = useMemo(function () { return normalizeInstrumentKey(nm_chave); }, [nm_chave]);
286
+ // Hook para gerenciar fluxo de instrumento (fase mockada)
287
+ var instrumentoHook = useInstrumento({
288
+ nmChave: normalizedKey || '',
289
+ cpfCnpj: cpfCnpj || '',
290
+ client: client
291
+ });
282
292
  if (!nm_chave)
283
293
  return null;
284
294
  var hasFailedBefore = failedInstruments[nm_chave] === true;
@@ -314,6 +324,7 @@ export var Instrumento = function (_a) {
314
324
  var _c = useState(deriveErrorKind), errorKind = _c[0], setErrorKind = _c[1];
315
325
  var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
316
326
  var _e = useState(shouldPrefetch), isPrefetching = _e[0], setIsPrefetching = _e[1];
327
+ var _f = useState(false), isDiscoveryConfirmOpen = _f[0], setIsDiscoveryConfirmOpen = _f[1];
317
328
  useEffect(function () {
318
329
  setErrorKind(deriveErrorKind());
319
330
  }, [deriveErrorKind]);
@@ -402,21 +413,25 @@ export var Instrumento = function (_a) {
402
413
  setData,
403
414
  shouldPrefetch
404
415
  ]);
405
- var isDisabled = isLoading || isPrefetching || errorKind !== null;
416
+ // Mantém o botão clicável em `not-found` para permitir solicitar por e-mail
417
+ var isDisabled = isLoading ||
418
+ isPrefetching ||
419
+ errorKind === 'invalid-key' ||
420
+ errorKind === 'missing-doc';
406
421
  var getTooltipMessage = function () {
407
422
  if (errorKind === 'missing-doc')
408
423
  return 'Documento não disponível para consulta';
409
424
  if (errorKind === 'invalid-key')
410
425
  return 'Chave de instrumento inválida';
411
426
  if (errorKind === 'not-found')
412
- return 'Instrumento não localizado no sistema';
427
+ return 'PDF indisponível. Você pode solicitar por e-mail.';
413
428
  if (isPrefetching)
414
429
  return 'Verificando disponibilidade do instrumento...';
415
430
  return '';
416
431
  };
417
432
  var getButtonLabel = function () {
418
- if (errorKind === 'not-found')
419
- return 'Instrumento não Localizado';
433
+ if (errorKind === 'not-found' && !isProtestoSPByNmChave(normalizedKey))
434
+ return 'Solicitar por e-mail';
420
435
  if (errorKind === 'invalid-key' || errorKind === 'missing-doc')
421
436
  return 'Instrumento Indisponível';
422
437
  return 'Instrumento';
@@ -428,73 +443,100 @@ export var Instrumento = function (_a) {
428
443
  return;
429
444
  pdfWindow.document.write("<iframe width='100%' height='100%' src='data:application/pdf;base64,".concat(base64, "'></iframe>"));
430
445
  };
431
- return (React.createElement("span", { title: tooltipMessage, style: { display: 'inline-block' } },
432
- React.createElement(Button, { isLoading: isLoading, onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
433
- var request_1, e_1, failure_2;
434
- return __generator(this, function (_a) {
435
- switch (_a.label) {
436
- case 0:
437
- if (isDisabled)
438
- return [2 /*return*/];
439
- if (/^35/.test(normalizedKey)) {
446
+ var isSP = isProtestoSPByNmChave(normalizedKey);
447
+ return (React.createElement(React.Fragment, null,
448
+ React.createElement("span", { title: tooltipMessage, style: { display: 'inline-block' } },
449
+ React.createElement(Button, { isLoading: isLoading || instrumentoHook.isProcessandoDescoberta, onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
450
+ var request_1, e_1, failure_2;
451
+ return __generator(this, function (_a) {
452
+ switch (_a.label) {
453
+ case 0:
454
+ if (isDisabled)
455
+ return [2 /*return*/];
456
+ // Fluxo SP: abre modal para Livro/Folha
457
+ if (isSP) {
458
+ instrumentoHook.openModalSP();
459
+ return [2 /*return*/];
460
+ }
461
+ // Se já sabemos que o PDF está indisponível, oferecemos o fluxo por e-mail
462
+ if (errorKind === 'not-found') {
463
+ setIsDiscoveryConfirmOpen(true);
464
+ return [2 /*return*/];
465
+ }
466
+ // Fluxo não-SP: tenta abrir PDF se disponível
467
+ if (cachedInstrument) {
468
+ openInstrumentPdf(cachedInstrument);
469
+ return [2 /*return*/];
470
+ }
471
+ // Tenta buscar PDF do backend
440
472
  setIsLoading(true);
441
- try {
442
- openFormThenRedirect(normalizedKey, cpfCnpj);
473
+ _a.label = 1;
474
+ case 1:
475
+ _a.trys.push([1, 4, 5, 6]);
476
+ return [4 /*yield*/, client.request("SELECT FROM 'IEPTB'.'PDF'", {
477
+ nm_chave: normalizedKey,
478
+ documento: cpfCnpj
479
+ })];
480
+ case 2: return [4 /*yield*/, (_a.sent()).json()];
481
+ case 3:
482
+ request_1 = _a.sent();
483
+ if (!(request_1 === null || request_1 === void 0 ? void 0 : request_1.instrumentoProtesto)) {
484
+ throw new Error('Instrumento não retornado pela API');
443
485
  }
444
- finally {
445
- setIsLoading(false);
486
+ openInstrumentPdf(request_1.instrumentoProtesto);
487
+ setData(function (prev) {
488
+ var _a, _b;
489
+ var base = prev || {};
490
+ var prevProtestosData = base.protestosData || {};
491
+ var _c = prevProtestosData.failedInstruments || {}, _d = nm_chave, _removedFailed = _c[_d], restFailed = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
492
+ var _e = prevProtestosData.failedInstrumentReasons || {}, _f = nm_chave, _removedReason = _e[_f], restReasons = __rest(_e, [typeof _f === "symbol" ? _f : _f + ""]);
493
+ return __assign(__assign({}, base), { protestosData: __assign(__assign({}, prevProtestosData), { failedInstruments: restFailed, failedInstrumentReasons: restReasons, instrumentCache: __assign(__assign({}, (prevProtestosData.instrumentCache || {})), (_a = {}, _a[nm_chave] = request_1.instrumentoProtesto, _a)), checkedInstruments: __assign(__assign({}, (prevProtestosData.checkedInstruments || {})), (_b = {}, _b[nm_chave] = true, _b)) }) });
494
+ });
495
+ setErrorKind(null);
496
+ return [3 /*break*/, 6];
497
+ case 4:
498
+ e_1 = _a.sent();
499
+ console.error(e_1);
500
+ failure_2 = classifyInstrumentError(e_1);
501
+ setErrorKind(failure_2);
502
+ // Quando PDF não está disponível, oferece descoberta automática com confirmação (UX)
503
+ if (failure_2 === 'not-found' && hasCpfCnpj && isValidKey) {
504
+ setIsDiscoveryConfirmOpen(true);
446
505
  }
447
- return [2 /*return*/];
448
- }
449
- if (cachedInstrument) {
450
- openInstrumentPdf(cachedInstrument);
451
- return [2 /*return*/];
452
- }
453
- setIsLoading(true);
454
- _a.label = 1;
506
+ // Persistimos falha/cache para evitar loops de prefetch
507
+ setData(function (prev) {
508
+ var _a, _b, _c;
509
+ var base = prev || {};
510
+ var prevProtestosData = base.protestosData || {};
511
+ var _d = prevProtestosData.instrumentCache || {}, _e = nm_chave, _cachedInstrument = _d[_e], restCache = __rest(_d, [typeof _e === "symbol" ? _e : _e + ""]);
512
+ return __assign(__assign({}, base), { protestosData: __assign(__assign({}, prevProtestosData), { instrumentCache: restCache, failedInstruments: __assign(__assign({}, (prevProtestosData.failedInstruments || {})), (_a = {}, _a[nm_chave] = true, _a)), checkedInstruments: __assign(__assign({}, (prevProtestosData.checkedInstruments || {})), (_b = {}, _b[nm_chave] = true, _b)), failedInstrumentReasons: __assign(__assign({}, (prevProtestosData.failedInstrumentReasons || {})), (_c = {}, _c[nm_chave] = failure_2, _c)) }) });
513
+ });
514
+ return [3 /*break*/, 6];
515
+ case 5:
516
+ setIsLoading(false);
517
+ return [7 /*endfinally*/];
518
+ case 6: return [2 /*return*/];
519
+ }
520
+ });
521
+ }); }, disabled: isDisabled }, getButtonLabel())),
522
+ React.createElement(ModalInstrumentoProtestoSP, { isOpen: instrumentoHook.isModalSPOpen, onClose: instrumentoHook.closeModalSP, onDescobrir: instrumentoHook.handleDescobrir, onEnviarEmail: instrumentoHook.handleEnviarEmail, canDescobrir: true, isDescobrindo: instrumentoHook.isDescobrindo, isEnviandoEmail: instrumentoHook.isEnviandoEmail }),
523
+ React.createElement(InstrumentoEmailStatusModal, { isOpen: instrumentoHook.isEmailModalOpen, onClose: instrumentoHook.closeEmailModal, message: instrumentoHook.emailMessage, title: instrumentoHook.emailTitle }),
524
+ React.createElement(InstrumentoDiscoveryConfirmModal, { isOpen: isDiscoveryConfirmOpen, onClose: function () { return setIsDiscoveryConfirmOpen(false); }, isLoading: instrumentoHook.isProcessandoDescoberta, onConfirm: function () { return __awaiter(void 0, void 0, void 0, function () {
525
+ return __generator(this, function (_a) {
526
+ switch (_a.label) {
527
+ case 0:
528
+ _a.trys.push([0, , 2, 3]);
529
+ return [4 /*yield*/, instrumentoHook.handleDescobertaAutomatica()];
455
530
  case 1:
456
- _a.trys.push([1, 4, 5, 6]);
457
- return [4 /*yield*/, client.request("SELECT FROM 'IEPTB'.'PDF'", {
458
- nm_chave: normalizedKey,
459
- documento: cpfCnpj
460
- })];
461
- case 2: return [4 /*yield*/, (_a.sent()).json()];
462
- case 3:
463
- request_1 = _a.sent();
464
- if (!(request_1 === null || request_1 === void 0 ? void 0 : request_1.instrumentoProtesto)) {
465
- throw new Error('Instrumento não retornado pela API');
466
- }
467
- openInstrumentPdf(request_1.instrumentoProtesto);
468
- setData(function (prev) {
469
- var _a, _b;
470
- var base = prev || {};
471
- var prevProtestosData = base.protestosData || {};
472
- var _c = prevProtestosData.failedInstruments || {}, _d = nm_chave, _removedFailed = _c[_d], restFailed = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
473
- var _e = prevProtestosData.failedInstrumentReasons || {}, _f = nm_chave, _removedReason = _e[_f], restReasons = __rest(_e, [typeof _f === "symbol" ? _f : _f + ""]);
474
- return __assign(__assign({}, base), { protestosData: __assign(__assign({}, prevProtestosData), { failedInstruments: restFailed, failedInstrumentReasons: restReasons, instrumentCache: __assign(__assign({}, (prevProtestosData.instrumentCache || {})), (_a = {}, _a[nm_chave] = request_1.instrumentoProtesto, _a)), checkedInstruments: __assign(__assign({}, (prevProtestosData.checkedInstruments || {})), (_b = {}, _b[nm_chave] = true, _b)) }) });
475
- });
476
- setErrorKind(null);
477
- return [3 /*break*/, 6];
478
- case 4:
479
- e_1 = _a.sent();
480
- console.error(e_1);
481
- failure_2 = classifyInstrumentError(e_1);
482
- setErrorKind(failure_2);
483
- setData(function (prev) {
484
- var _a, _b, _c;
485
- var base = prev || {};
486
- var prevProtestosData = base.protestosData || {};
487
- var _d = prevProtestosData.instrumentCache || {}, _e = nm_chave, _cachedInstrument = _d[_e], restCache = __rest(_d, [typeof _e === "symbol" ? _e : _e + ""]);
488
- return __assign(__assign({}, base), { protestosData: __assign(__assign({}, prevProtestosData), { instrumentCache: restCache, failedInstruments: __assign(__assign({}, (prevProtestosData.failedInstruments || {})), (_a = {}, _a[nm_chave] = true, _a)), checkedInstruments: __assign(__assign({}, (prevProtestosData.checkedInstruments || {})), (_b = {}, _b[nm_chave] = true, _b)), failedInstrumentReasons: __assign(__assign({}, (prevProtestosData.failedInstrumentReasons || {})), (_c = {}, _c[nm_chave] = failure_2, _c)) }) });
489
- });
490
- return [3 /*break*/, 6];
491
- case 5:
492
- setIsLoading(false);
531
+ _a.sent();
532
+ return [3 /*break*/, 3];
533
+ case 2:
534
+ setIsDiscoveryConfirmOpen(false);
493
535
  return [7 /*endfinally*/];
494
- case 6: return [2 /*return*/];
536
+ case 3: return [2 /*return*/];
495
537
  }
496
538
  });
497
- }); }, disabled: isDisabled }, getButtonLabel())));
539
+ }); } })));
498
540
  };
499
541
  export var ProtestosList = function (_a) {
500
542
  var protestos = _a.protestos;
@@ -77,9 +77,11 @@ var useSectionPrintBlocker = function (ctx, title, enabled, registerBlocker, res
77
77
  var Section = forwardRef(function (_a, ref) {
78
78
  var onSuccess = _a.onSuccess, _b = _a.isError, isError = _b === void 0 ? function (err, ctx) {
79
79
  var shouldPush = (err === null || err === void 0 ? void 0 : err.push) === true;
80
- var message = shouldPush
81
- ? err.message
82
- : 'Problemas de comunicação, tente novamente.';
80
+ // Se push === true, não exibir erro (caso esperado, tratar como sucesso)
81
+ if (shouldPush) {
82
+ return null;
83
+ }
84
+ var message = 'Problemas de comunicação, tente novamente.';
83
85
  return {
84
86
  children: React.createElement(React.Fragment, null),
85
87
  description: (React.createElement(React.Fragment, null,
@@ -109,6 +109,31 @@ var extractWarningFromDocument = function (document) {
109
109
  }
110
110
  return null;
111
111
  };
112
+ var extractExceptionFromDocument = function (document) {
113
+ var _a, _b;
114
+ if (!document)
115
+ return null;
116
+ if (isDocument(document)) {
117
+ var header = document.querySelector('header');
118
+ if (!header)
119
+ return null;
120
+ var exceptionElement = (_a = header.querySelector('exception, Exception, EXCEPTION')) !== null && _a !== void 0 ? _a : null;
121
+ if (exceptionElement) {
122
+ var message = ((_b = exceptionElement.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '';
123
+ var pushAttr = exceptionElement.getAttribute('push');
124
+ var push = pushAttr === 'true';
125
+ return { message: message, push: push };
126
+ }
127
+ return null;
128
+ }
129
+ return null;
130
+ };
131
+ var isErrorWithPush = function (error) {
132
+ if (error && typeof error === 'object') {
133
+ return (error === null || error === void 0 ? void 0 : error.push) === true;
134
+ }
135
+ return false;
136
+ };
112
137
  export function CustomProvider(Provider, query) {
113
138
  return function (_a) {
114
139
  var children = _a.children, data = _a.data, urlData = _a.urlData, _b = _a.depends, depends = _b === void 0 ? [] : _b;
@@ -167,11 +192,22 @@ export function CustomProvider(Provider, query) {
167
192
  })
168
193
  .catch(function (requestError) {
169
194
  if (requestError.name !== 'AbortError') {
170
- setError(requestError instanceof Error
171
- ? requestError
172
- : new Error(String(requestError)));
195
+ // Se o erro tem push === true, não tratar como erro (caso esperado)
196
+ if (isErrorWithPush(requestError)) {
197
+ // Tratar como sucesso (sem erro)
198
+ setError(null);
199
+ setRequestCompleted(true);
200
+ }
201
+ else {
202
+ setError(requestError instanceof Error
203
+ ? requestError
204
+ : new Error(String(requestError)));
205
+ setRequestCompleted(true);
206
+ }
207
+ }
208
+ else {
209
+ setRequestCompleted(true);
173
210
  }
174
- setRequestCompleted(true);
175
211
  })
176
212
  .finally(function () {
177
213
  setLoading(false);
@@ -308,11 +344,22 @@ export function useQuery(query, data, enabled) {
308
344
  })
309
345
  .catch(function (requestError) {
310
346
  if (requestError.name !== 'AbortError') {
311
- setError(requestError instanceof Error
312
- ? requestError
313
- : new Error(String(requestError)));
347
+ // Se o erro tem push === true, não tratar como erro (caso esperado)
348
+ if (isErrorWithPush(requestError)) {
349
+ // Tratar como sucesso (sem erro)
350
+ setError(null);
351
+ setProgress(100);
352
+ }
353
+ else {
354
+ setError(requestError instanceof Error
355
+ ? requestError
356
+ : new Error(String(requestError)));
357
+ setProgress(100);
358
+ }
359
+ }
360
+ else {
361
+ setProgress(100);
314
362
  }
315
- setProgress(100);
316
363
  })
317
364
  .finally(function () {
318
365
  setIsLoading(false);
@@ -369,9 +416,18 @@ export function useMutation(query, data) {
369
416
  })
370
417
  .then(function (document) { return setResponse(document); })
371
418
  .catch(function (requestError) {
372
- return setError(requestError instanceof Error && requestError.name !== 'AbortError'
373
- ? requestError
374
- : new Error(requestError));
419
+ if (requestError.name !== 'AbortError') {
420
+ // Se o erro tem push === true, não tratar como erro (caso esperado)
421
+ if (isErrorWithPush(requestError)) {
422
+ // Tratar como sucesso (sem erro)
423
+ setError(null);
424
+ }
425
+ else {
426
+ setError(requestError instanceof Error
427
+ ? requestError
428
+ : new Error(String(requestError)));
429
+ }
430
+ }
375
431
  })
376
432
  .finally(function () { return setIsLoading(false); });
377
433
  }, [client, query, mergedData, defaultUrlData, abortController]);
@@ -401,9 +457,18 @@ export function useFetch(query) {
401
457
  return document;
402
458
  })
403
459
  .catch(function (requestError) {
404
- return setError(requestError instanceof Error && requestError.name !== 'AbortError'
405
- ? requestError
406
- : new Error(requestError));
460
+ if (requestError.name !== 'AbortError') {
461
+ // Se o erro tem push === true, não tratar como erro (caso esperado)
462
+ if (isErrorWithPush(requestError)) {
463
+ // Tratar como sucesso (sem erro)
464
+ setError(null);
465
+ }
466
+ else {
467
+ setError(requestError instanceof Error
468
+ ? requestError
469
+ : new Error(String(requestError)));
470
+ }
471
+ }
407
472
  })
408
473
  .finally(function () { return setIsLoading(false); })];
409
474
  });
@@ -5,7 +5,10 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
5
5
  // src/styles/globalStyle.tsx
6
6
  import React from 'react';
7
7
  import { createGlobalStyle } from 'styled-components';
8
- var GlobalStyle = createGlobalStyle(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n /* Reset + fonte padr\u00E3o para toda a aplica\u00E7\u00E3o (inclui modais e portais) */\n *, *::before, *::after {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n font-family: 'Open Sans Condensed', sans-serif;\n }\n\n body {\n -webkit-font-smoothing: antialiased;\n }\n\n /* Oculta bot\u00F5es e tooltips na impress\u00E3o */\n @media print {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n body.print-mode,\n body[data-print-mode='true'] {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n /* Anima\u00E7\u00F5es utilit\u00E1rias */\n @keyframes highlight {\n from {\n background-color: rgba(255, 215, 0, 0.35);\n }\n to {\n background-color: transparent;\n }\n }\n\n .highlighted-process {\n animation: highlight 3s ease-out forwards !important;\n }\n\n @keyframes blueHighlight {\n from {\n background-color: rgba(0, 122, 255, 0.35);\n }\n to {\n background-color: rgba(0, 122, 255, 0.15);\n }\n }\n\n .blue-highlighted-process {\n animation: blueHighlight 2.5s ease-in-out;\n background-color: rgba(0, 122, 255, 0.15);\n transition: background-color 0.3s ease-in-out;\n }\n"], ["\n /* Reset + fonte padr\u00E3o para toda a aplica\u00E7\u00E3o (inclui modais e portais) */\n *, *::before, *::after {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n font-family: 'Open Sans Condensed', sans-serif;\n }\n\n body {\n -webkit-font-smoothing: antialiased;\n }\n\n /* Oculta bot\u00F5es e tooltips na impress\u00E3o */\n @media print {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n body.print-mode,\n body[data-print-mode='true'] {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n /* Anima\u00E7\u00F5es utilit\u00E1rias */\n @keyframes highlight {\n from {\n background-color: rgba(255, 215, 0, 0.35);\n }\n to {\n background-color: transparent;\n }\n }\n\n .highlighted-process {\n animation: highlight 3s ease-out forwards !important;\n }\n\n @keyframes blueHighlight {\n from {\n background-color: rgba(0, 122, 255, 0.35);\n }\n to {\n background-color: rgba(0, 122, 255, 0.15);\n }\n }\n\n .blue-highlighted-process {\n animation: blueHighlight 2.5s ease-in-out;\n background-color: rgba(0, 122, 255, 0.15);\n transition: background-color 0.3s ease-in-out;\n }\n"])));
8
+ var GlobalStyle = createGlobalStyle(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n /* Reset + fonte padr\u00E3o para toda a aplica\u00E7\u00E3o (inclui modais e portais) */\n *, *::before, *::after {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n font-family: ", ";\n }\n\n body {\n -webkit-font-smoothing: antialiased;\n }\n\n /* Oculta bot\u00F5es e tooltips na impress\u00E3o */\n @media print {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n body.print-mode,\n body[data-print-mode='true'] {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n /* Anima\u00E7\u00F5es utilit\u00E1rias */\n @keyframes highlight {\n from {\n background-color: rgba(255, 215, 0, 0.35);\n }\n to {\n background-color: transparent;\n }\n }\n\n .highlighted-process {\n animation: highlight 3s ease-out forwards !important;\n }\n\n @keyframes blueHighlight {\n from {\n background-color: rgba(0, 122, 255, 0.35);\n }\n to {\n background-color: rgba(0, 122, 255, 0.15);\n }\n }\n\n .blue-highlighted-process {\n animation: blueHighlight 2.5s ease-in-out;\n background-color: rgba(0, 122, 255, 0.15);\n transition: background-color 0.3s ease-in-out;\n }\n"], ["\n /* Reset + fonte padr\u00E3o para toda a aplica\u00E7\u00E3o (inclui modais e portais) */\n *, *::before, *::after {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n font-family: ", ";\n }\n\n body {\n -webkit-font-smoothing: antialiased;\n }\n\n /* Oculta bot\u00F5es e tooltips na impress\u00E3o */\n @media print {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n body.print-mode,\n body[data-print-mode='true'] {\n button,\n [role=\"button\"],\n [class*=\"Button\"],\n [class^=\"Button\"],\n [class*=\"btn\"],\n [class^=\"btn\"],\n .button,\n .btn,\n [class*=\"tooltip\"],\n [class*=\"Tooltip\"],\n [data-tooltip] {\n display: none !important;\n visibility: hidden !important;\n }\n }\n\n /* Anima\u00E7\u00F5es utilit\u00E1rias */\n @keyframes highlight {\n from {\n background-color: rgba(255, 215, 0, 0.35);\n }\n to {\n background-color: transparent;\n }\n }\n\n .highlighted-process {\n animation: highlight 3s ease-out forwards !important;\n }\n\n @keyframes blueHighlight {\n from {\n background-color: rgba(0, 122, 255, 0.35);\n }\n to {\n background-color: rgba(0, 122, 255, 0.15);\n }\n }\n\n .blue-highlighted-process {\n animation: blueHighlight 2.5s ease-in-out;\n background-color: rgba(0, 122, 255, 0.15);\n transition: background-color 0.3s ease-in-out;\n }\n"])), function (_a) {
9
+ var theme = _a.theme;
10
+ return theme.typography.defaultFontFamily;
11
+ });
9
12
  // Componente que aplica os estilos globais da aplicação.
10
13
  // A fonte "Open Sans Condensed" já é carregada via index.html.
11
14
  var GlobalStyleProvider = function () { return (React.createElement(React.Fragment, null,
@@ -16,6 +16,7 @@ declare const theme: {
16
16
  cinzaClaro: string;
17
17
  cinzaBase: string;
18
18
  cinzaBackground: string;
19
+ cinzaMedio: string;
19
20
  cinzaEscuro: string;
20
21
  prata: string;
21
22
  likeButton: string;
@@ -16,6 +16,7 @@ var theme = {
16
16
  cinzaClaro: 'rgba(209, 209, 209, 1)',
17
17
  cinzaBase: 'rgba(245, 245, 245, 1)',
18
18
  cinzaBackground: '#efefef',
19
+ cinzaMedio: 'rgba(120, 120, 120, 1)',
19
20
  cinzaEscuro: 'rgba(53, 53, 53, 1)',
20
21
  prata: 'rgba(121, 129, 125, 1)',
21
22
  likeButton: '#007aff',
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Heurística atual para inferir UF do protesto.
3
+ *
4
+ * Contexto: o payload de protestos (CENPROT) que consumimos hoje não expõe UF/cidade do cartório,
5
+ * então a única pista disponível na UI é a `nm_chave`.
6
+ *
7
+ * Na prática, a `nm_chave` costuma começar com o código IBGE da UF (ex: "35" = São Paulo).
8
+ * Quando o backend passar UF explicitamente, esta lógica deve ser substituída por um campo confiável.
9
+ */
10
+ export declare const isProtestoSPByNmChave: (nmChave?: string) => boolean;