@fluwa-tool/sdk 1.0.51 → 1.0.52
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/index.js +47 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -52,6 +52,47 @@ let xmlHttpRequestInterceptor;
|
|
|
52
52
|
let mockResolver;
|
|
53
53
|
let urlFilter = null; // URL filter para evitar loops infinitos
|
|
54
54
|
// ============================================
|
|
55
|
+
// CONFIGURAÇÃO DE AXIOS
|
|
56
|
+
// ============================================
|
|
57
|
+
/**
|
|
58
|
+
* Forçar axios a usar fetch em vez de XMLHttpRequest
|
|
59
|
+
* Permite que FetchInterceptor mocke requisições de axios
|
|
60
|
+
*/
|
|
61
|
+
function configureAxiosToUseFetch(logger) {
|
|
62
|
+
try {
|
|
63
|
+
// Verificar se axios está disponível globalmente
|
|
64
|
+
const globalObj = typeof window !== 'undefined' ? window : globalThis;
|
|
65
|
+
const axios = globalObj.axios;
|
|
66
|
+
if (!axios) {
|
|
67
|
+
logger.debug('axios não encontrado globalmente - vai ser necessário importar manualmente');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Configurar axios para usar fetch adapter
|
|
71
|
+
// Isso faz com que axios use fetch internamente, que é interceptado por FetchInterceptor
|
|
72
|
+
axios.defaults.adapter = async (config) => {
|
|
73
|
+
logger.debug(`📡 [axios -> fetch] Usando fetch para: ${config.method?.toUpperCase()} ${config.url}`);
|
|
74
|
+
const fetchConfig = {
|
|
75
|
+
method: config.method?.toUpperCase() || 'GET',
|
|
76
|
+
headers: config.headers || {},
|
|
77
|
+
body: config.data,
|
|
78
|
+
};
|
|
79
|
+
const response = await fetch(config.url, fetchConfig);
|
|
80
|
+
return {
|
|
81
|
+
data: await response.json(),
|
|
82
|
+
status: response.status,
|
|
83
|
+
statusText: response.statusText,
|
|
84
|
+
headers: response.headers,
|
|
85
|
+
config,
|
|
86
|
+
request: {},
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
logger.success('✅ axios configurado para usar fetch (FetchInterceptor ativo)');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
logger.debug('Erro ao configurar axios para fetch:', error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ============================================
|
|
55
96
|
// INICIALIZAÇÃO
|
|
56
97
|
// ============================================
|
|
57
98
|
/**
|
|
@@ -91,11 +132,12 @@ async function initFluwaTool(partialConfig = {}) {
|
|
|
91
132
|
logger.debug(`URL Filter configurado com ${urlFilter.getExcludedPatterns().length} padrões excluídos`);
|
|
92
133
|
// 7. Criar interceptador de fetch
|
|
93
134
|
fetchInterceptor = new FetchInterceptor_1.FetchInterceptor(logger, requestLogger, mockResolver, sessionId, config.getAppName(), urlFilter);
|
|
94
|
-
// 7b. Criar interceptador de XMLHttpRequest (
|
|
135
|
+
// 7b. Criar interceptador de XMLHttpRequest (DESABILITADO)
|
|
136
|
+
// axios agora usa fetch via configureAxiosToUseFetch(), então não precisa mais de XHR
|
|
95
137
|
xmlHttpRequestInterceptor = new XMLHttpRequestInterceptor_1.XMLHttpRequestInterceptor(logger, requestLogger, mockResolver, sessionId, config.getAppName(), urlFilter);
|
|
96
138
|
// 8. Instalar interceptadores
|
|
97
139
|
fetchInterceptor.install();
|
|
98
|
-
xmlHttpRequestInterceptor.install();
|
|
140
|
+
// xmlHttpRequestInterceptor.install(); // ❌ Desabilitado - axios agora usa fetch
|
|
99
141
|
// 9. Conectar WebSocket
|
|
100
142
|
logger.debug('Conectando ao WebSocket...');
|
|
101
143
|
try {
|
|
@@ -113,6 +155,9 @@ async function initFluwaTool(partialConfig = {}) {
|
|
|
113
155
|
});
|
|
114
156
|
isInitialized = true;
|
|
115
157
|
logger.success('Fluwa-Tool inicializado com sucesso!');
|
|
158
|
+
// ✅ FORÇA AXIOS USAR FETCH EM VEZ DE XMLHttpRequest
|
|
159
|
+
// Isso permite que FetchInterceptor mocke requisições de axios
|
|
160
|
+
configureAxiosToUseFetch(logger);
|
|
116
161
|
}
|
|
117
162
|
catch (error) {
|
|
118
163
|
logger.error('Erro ao inicializar Fluwa', error);
|