@fluwa-tool/sdk 1.0.41 → 1.0.42
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Interceptador de XMLHttpRequest
|
|
3
|
-
*
|
|
3
|
+
* Usa fetch interno quando há mock para evitar problemas em React Native
|
|
4
4
|
*/
|
|
5
5
|
import { ILogger } from '../../core/Logger';
|
|
6
6
|
import { IRequestLogger } from './RequestLogger';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Interceptador de XMLHttpRequest
|
|
4
|
-
*
|
|
4
|
+
* Usa fetch interno quando há mock para evitar problemas em React Native
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.XMLHttpRequestInterceptor = void 0;
|
|
@@ -56,7 +56,7 @@ class XMLHttpRequestInterceptor {
|
|
|
56
56
|
const requestId = xhr._fluwaRequestId;
|
|
57
57
|
const headers = xhr._fluwaHeaders || {};
|
|
58
58
|
if (self.urlFilter && !self.urlFilter.shouldIntercept(url)) {
|
|
59
|
-
self.logger.debug(`🔧 [XMLHttpRequestInterceptor] Ignorando URL excluída: ${url}
|
|
59
|
+
self.logger.debug(`🔧 [XMLHttpRequestInterceptor] Ignorando URL excluída: ${url}`);
|
|
60
60
|
return self.originalSend.apply(this, [body]);
|
|
61
61
|
}
|
|
62
62
|
const requestMetadata = {
|
|
@@ -71,7 +71,6 @@ class XMLHttpRequestInterceptor {
|
|
|
71
71
|
source: types_1.RequestSource.REAL,
|
|
72
72
|
};
|
|
73
73
|
self.requestLogger.logStart(requestMetadata).catch(() => { });
|
|
74
|
-
const originalOnReadyStateChange = xhr.onreadystatechange;
|
|
75
74
|
// Verificar mock com retry
|
|
76
75
|
const checkMockWithRetry = async () => {
|
|
77
76
|
let mockResponse = await self.mockResolver.resolve(method, url);
|
|
@@ -83,7 +82,7 @@ class XMLHttpRequestInterceptor {
|
|
|
83
82
|
};
|
|
84
83
|
checkMockWithRetry().then(mockResponse => {
|
|
85
84
|
if (mockResponse) {
|
|
86
|
-
// Mock encontrado - simular
|
|
85
|
+
// Mock encontrado - fazer fetch interno para simular
|
|
87
86
|
requestMetadata.source = types_1.RequestSource.MOCK;
|
|
88
87
|
requestMetadata.status = mockResponse.status || 200;
|
|
89
88
|
requestMetadata.response = mockResponse.response;
|
|
@@ -92,30 +91,36 @@ class XMLHttpRequestInterceptor {
|
|
|
92
91
|
const duration = Date.now() - (xhr._fluwaStartTime || 0);
|
|
93
92
|
requestMetadata.duration = duration;
|
|
94
93
|
self.requestLogger.logComplete(requestMetadata).catch(() => { });
|
|
95
|
-
//
|
|
94
|
+
// Criar resposta fake e simular como se fosse enviada pelo servidor
|
|
96
95
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
const responseJSON = JSON.stringify(mockResponse.response);
|
|
97
|
+
const responseStatus = mockResponse.status || 200;
|
|
98
|
+
// Injetar resposta no xhr (pode não funcionar perfeitamente, mas tenta)
|
|
99
|
+
xhr.status = responseStatus;
|
|
100
|
+
xhr.statusText = 'Mock';
|
|
101
|
+
xhr.responseText = responseJSON;
|
|
102
|
+
xhr.response = mockResponse.response;
|
|
103
|
+
xhr.readyState = 4;
|
|
104
|
+
// Disparar evento de completion
|
|
105
|
+
const event = new ProgressEvent('readystatechange', {});
|
|
106
|
+
if (xhr.onreadystatechange) {
|
|
107
|
+
xhr.onreadystatechange.call(xhr, event);
|
|
108
|
+
}
|
|
109
|
+
// Disparar evento de load como fallback
|
|
110
|
+
if (xhr.onload) {
|
|
111
|
+
xhr.onload.call(xhr, event);
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
catch (error) {
|
|
112
|
-
self.logger.debug('Erro ao simular resposta
|
|
115
|
+
self.logger.debug('Erro ao simular resposta, usando fallback');
|
|
116
|
+
// Fallback: fazer request real mesmo assim
|
|
113
117
|
self.originalSend.apply(xhr, [body]);
|
|
114
118
|
}
|
|
115
119
|
}, delay);
|
|
116
120
|
return;
|
|
117
121
|
}
|
|
118
122
|
// Sem mock - fazer request real
|
|
123
|
+
const originalOnReadyStateChange = xhr.onreadystatechange;
|
|
119
124
|
xhr.onreadystatechange = function (event) {
|
|
120
125
|
if (xhr.readyState === 4) {
|
|
121
126
|
requestMetadata.status = xhr.status;
|