@lark-apaas/client-toolkit 1.2.1-alpha.14 → 1.2.1-alpha.16
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/lib/index.js +3 -1
- package/lib/utils/axiosConfig.d.ts +1 -1
- package/lib/utils/axiosConfig.js +26 -16
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createClient } from "@lark-apaas/client-capability";
|
|
2
2
|
import { normalizeBasePath } from "./utils/utils.js";
|
|
3
|
+
import { logger } from "./logger/index.js";
|
|
3
4
|
import { version } from "../package.json";
|
|
4
5
|
const capabilityClient = createClient({
|
|
5
6
|
baseURL: normalizeBasePath(process.env.CLIENT_BASE_PATH),
|
|
@@ -7,7 +8,8 @@ const capabilityClient = createClient({
|
|
|
7
8
|
headers: {
|
|
8
9
|
'X-Suda-Csrf-Token': window.csrfToken ?? ''
|
|
9
10
|
}
|
|
10
|
-
}
|
|
11
|
+
},
|
|
12
|
+
logger: logger
|
|
11
13
|
});
|
|
12
14
|
const src = {
|
|
13
15
|
version: version
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -144,9 +144,9 @@ function initAxiosConfig(axiosInstance) {
|
|
|
144
144
|
'post',
|
|
145
145
|
'put',
|
|
146
146
|
'patch',
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
'postForm',
|
|
148
|
+
'putForm',
|
|
149
|
+
'patchForm'
|
|
150
150
|
];
|
|
151
151
|
const allMethods = [
|
|
152
152
|
'request',
|
|
@@ -205,16 +205,17 @@ function initAxiosConfig(axiosInstance) {
|
|
|
205
205
|
const method = (response.config.method || 'GET').toUpperCase();
|
|
206
206
|
const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
|
|
207
207
|
if (span) {
|
|
208
|
-
|
|
208
|
+
const logData = {
|
|
209
209
|
method,
|
|
210
210
|
path: cleanedPath,
|
|
211
|
-
url,
|
|
212
|
-
user_agent: response.config.headers["user-agent"],
|
|
211
|
+
url: response.request?.responseURL || url || "",
|
|
213
212
|
duration_ms: startTime ? Date.now() - startTime : void 0,
|
|
214
|
-
status: response.status
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
213
|
+
status: response.status
|
|
214
|
+
};
|
|
215
|
+
if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
|
|
216
|
+
if (response.config.data) logData.request_body = response.config.data;
|
|
217
|
+
if (response.data) logData.response = response.data || {};
|
|
218
|
+
observable.log('INFO', safeStringify(logData), {}, span);
|
|
218
219
|
'function' == typeof span.end && span.end();
|
|
219
220
|
}
|
|
220
221
|
return response;
|
|
@@ -224,17 +225,18 @@ function initAxiosConfig(axiosInstance) {
|
|
|
224
225
|
const method = (errorConfig.method || 'GET').toUpperCase();
|
|
225
226
|
const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
|
|
226
227
|
if (span) {
|
|
227
|
-
|
|
228
|
+
const logData = {
|
|
228
229
|
method,
|
|
229
230
|
path: cleanedPath,
|
|
230
|
-
url,
|
|
231
|
-
user_agent: errorConfig.headers?.["user-agent"],
|
|
231
|
+
url: errorResponse.request?.responseURL || errorConfig.url || "",
|
|
232
232
|
duration_ms: startTime ? Date.now() - startTime : void 0,
|
|
233
233
|
status: errorResponse.status || 200,
|
|
234
|
-
request_body: errorConfig.data,
|
|
235
|
-
response: errorResponse.data || {},
|
|
236
234
|
error_message: errorMessage
|
|
237
|
-
}
|
|
235
|
+
};
|
|
236
|
+
if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
|
|
237
|
+
if (errorConfig.data) logData.request_body = errorConfig.data;
|
|
238
|
+
if (errorResponse.data) logData.response = errorResponse.data || {};
|
|
239
|
+
observable.log('ERROR', safeStringify(logData), {}, span);
|
|
238
240
|
'function' == typeof span.end && span.end();
|
|
239
241
|
}
|
|
240
242
|
return Promise.reject(error);
|
|
@@ -258,5 +260,13 @@ function initAxiosConfig(axiosInstance) {
|
|
|
258
260
|
logResponse('error', error.response || error);
|
|
259
261
|
return Promise.reject(error);
|
|
260
262
|
});
|
|
263
|
+
if ('function' == typeof axiosInstance) axiosInstance = new Proxy(axiosInstance, {
|
|
264
|
+
apply (target, thisArg, args) {
|
|
265
|
+
const requestMethod = target.request;
|
|
266
|
+
if ('function' != typeof requestMethod) return Reflect.apply(target, thisArg, args);
|
|
267
|
+
return requestMethod.apply(target, args);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return axiosInstance;
|
|
261
271
|
}
|
|
262
272
|
export { initAxiosConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.1-alpha.
|
|
3
|
+
"version": "1.2.1-alpha.16",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@ant-design/colors": "^7.2.1",
|
|
87
87
|
"@ant-design/cssinjs": "^1.24.0",
|
|
88
88
|
"@data-loom/js": "^0.4.3",
|
|
89
|
-
"@lark-apaas/client-capability": "^0.1.
|
|
89
|
+
"@lark-apaas/client-capability": "^0.1.2",
|
|
90
90
|
"@lark-apaas/miaoda-inspector": "^1.0.8",
|
|
91
91
|
"@lark-apaas/observable-web": "1.0.1-alpha.2",
|
|
92
92
|
"@radix-ui/react-avatar": "^1.1.10",
|