@lark-apaas/client-toolkit 1.2.24-alpha.1 → 1.2.24-alpha.2
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.
|
@@ -139,8 +139,7 @@ class ApiProxy {
|
|
|
139
139
|
...config,
|
|
140
140
|
headers: {
|
|
141
141
|
...this.defaultConfig.headers,
|
|
142
|
-
...config.headers
|
|
143
|
-
'X-Page-Route': 'undefined' != typeof window ? window.location?.pathname || '/' : '/'
|
|
142
|
+
...config.headers
|
|
144
143
|
}
|
|
145
144
|
};
|
|
146
145
|
const requestKey = this.generateRequestKey(mergedConfig);
|
|
@@ -14,32 +14,18 @@ const Component = ()=>{
|
|
|
14
14
|
const isMobile = useIsMobile();
|
|
15
15
|
const [userinfo, setUserinfo] = useState(null);
|
|
16
16
|
const [isInternetVisible, setIsInternetVisible] = useState(false);
|
|
17
|
-
const [showBadge, setShowBadge] = useState(true);
|
|
18
|
-
const [badgeLoaded, setBadgeLoaded] = useState(false);
|
|
19
17
|
const timeoutRef = useRef(null);
|
|
20
18
|
useEffect(()=>{
|
|
21
19
|
const appId = getAppId();
|
|
22
|
-
const csrfHeaders = {
|
|
23
|
-
'X-Suda-Csrf-Token': getCsrfToken()
|
|
24
|
-
};
|
|
25
20
|
const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
|
|
26
21
|
fetch(tenantInfoUrl, {
|
|
27
|
-
headers:
|
|
22
|
+
headers: {
|
|
23
|
+
'X-Suda-Csrf-Token': getCsrfToken()
|
|
24
|
+
}
|
|
28
25
|
}).then((res)=>res.json()).then((data)=>{
|
|
29
26
|
setUserinfo(data?.data?.tenant_info);
|
|
30
27
|
setIsInternetVisible(data?.data?.is_internet_visible);
|
|
31
28
|
});
|
|
32
|
-
const getPublishedUrl = `/spark/b/${appId}/get_published`;
|
|
33
|
-
fetch(getPublishedUrl, {
|
|
34
|
-
headers: csrfHeaders
|
|
35
|
-
}).then((res)=>res.json()).then((data)=>{
|
|
36
|
-
const badge = data?.data?.app_info?.show_badge;
|
|
37
|
-
setShowBadge(false !== badge);
|
|
38
|
-
}).catch(()=>{
|
|
39
|
-
setShowBadge(true);
|
|
40
|
-
}).finally(()=>{
|
|
41
|
-
setBadgeLoaded(true);
|
|
42
|
-
});
|
|
43
29
|
}, []);
|
|
44
30
|
useEffect(()=>{
|
|
45
31
|
if (isMobile) {
|
|
@@ -53,8 +39,6 @@ const Component = ()=>{
|
|
|
53
39
|
isMobile
|
|
54
40
|
]);
|
|
55
41
|
if ('production' !== process.env.NODE_ENV) return null;
|
|
56
|
-
if (!badgeLoaded) return null;
|
|
57
|
-
if (!showBadge) return null;
|
|
58
42
|
if (!visible) return null;
|
|
59
43
|
if (isMobile) return /*#__PURE__*/ jsxs(Sheet, {
|
|
60
44
|
open: open,
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -4,6 +4,21 @@ import { logger } from "../apis/logger.js";
|
|
|
4
4
|
import { getStacktrace } from "../logger/selected-logs.js";
|
|
5
5
|
import { safeStringify } from "./safeStringify.js";
|
|
6
6
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
7
|
+
import { normalizeBasePath } from "./utils.js";
|
|
8
|
+
const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
|
|
9
|
+
function getRefererPath() {
|
|
10
|
+
try {
|
|
11
|
+
if ('undefined' != typeof window && window.location?.pathname) return stripBasePath(window.location.pathname);
|
|
12
|
+
return '/';
|
|
13
|
+
} catch {
|
|
14
|
+
return '/';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function stripBasePath(urlPath) {
|
|
18
|
+
const base = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
19
|
+
if (base && urlPath.startsWith(base)) return urlPath.slice(base.length) || '/';
|
|
20
|
+
return urlPath;
|
|
21
|
+
}
|
|
7
22
|
const isValidResponse = (resp)=>null != resp && 'object' == typeof resp && 'config' in resp && null !== resp.config && void 0 !== resp.config && 'object' == typeof resp.config && 'status' in resp && 'number' == typeof resp.status && 'data' in resp;
|
|
8
23
|
async function logResponse(ok, responseOrError) {
|
|
9
24
|
if (isValidResponse(responseOrError)) {
|
|
@@ -139,13 +154,20 @@ function handleSpanEnd(cfg, response, error) {
|
|
|
139
154
|
const errorMessage = error?.message || '未知错误';
|
|
140
155
|
const url = response?.request?.responseURL || errorResponse?.request?.responseURL || cfg.url || "";
|
|
141
156
|
const method = (cfg.method || 'GET').toUpperCase();
|
|
142
|
-
const
|
|
157
|
+
const rawPath = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
|
|
158
|
+
const path = stripBasePath(rawPath);
|
|
159
|
+
const durationMs = startTime ? Date.now() - startTime : void 0;
|
|
160
|
+
const referer_path = getRefererPath();
|
|
161
|
+
const api = `${method} ${path}`;
|
|
162
|
+
const type = APP_CLIENT_API_LOG_TYPE;
|
|
143
163
|
const logData = {
|
|
144
164
|
method,
|
|
145
165
|
path,
|
|
146
166
|
url,
|
|
147
|
-
duration_ms:
|
|
148
|
-
status: response ? response.status : errorResponse.status || 0
|
|
167
|
+
duration_ms: durationMs,
|
|
168
|
+
status: response ? response.status : errorResponse.status || 0,
|
|
169
|
+
referer_path,
|
|
170
|
+
type
|
|
149
171
|
};
|
|
150
172
|
if (error) logData.error_message = errorMessage;
|
|
151
173
|
if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
|
|
@@ -158,7 +180,12 @@ function handleSpanEnd(cfg, response, error) {
|
|
|
158
180
|
const responseData = response?.data || errorResponse?.data;
|
|
159
181
|
if (responseData) logData.response = responseData;
|
|
160
182
|
const level = error ? 'ERROR' : 'INFO';
|
|
161
|
-
observable.log(level, safeStringify(logData), {
|
|
183
|
+
observable.log(level, safeStringify(logData), {
|
|
184
|
+
referer_path,
|
|
185
|
+
api,
|
|
186
|
+
type,
|
|
187
|
+
duration_ms: durationMs
|
|
188
|
+
}, currentSpan);
|
|
162
189
|
'function' == typeof currentSpan.end && currentSpan.end();
|
|
163
190
|
} catch (e) {
|
|
164
191
|
console.error('[AxiosTrace] Log span failed:', e);
|
|
@@ -239,7 +266,11 @@ function initAxiosConfig(axiosInstance) {
|
|
|
239
266
|
config._startTime = config._startTime || Date.now();
|
|
240
267
|
const csrfToken = window.csrfToken;
|
|
241
268
|
if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
|
|
242
|
-
|
|
269
|
+
const refererPath = getRefererPath();
|
|
270
|
+
config.headers['Rpc-Persist-Apaas-Observability-Referer-Path'] = refererPath;
|
|
271
|
+
const reqMethod = (config.method || 'GET').toUpperCase();
|
|
272
|
+
const requestPath = stripBasePath((config.url || '').split('?')[0]);
|
|
273
|
+
config.headers['Rpc-Persist-Apaas-Observability-Api'] = `${reqMethod} ${requestPath}`;
|
|
243
274
|
return config;
|
|
244
275
|
}, (error)=>Promise.reject(error));
|
|
245
276
|
instance.interceptors.response.use((response)=>response, (error)=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.24-alpha.
|
|
3
|
+
"version": "1.2.24-alpha.2",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
101
|
"@data-loom/js": "0.4.9",
|
|
102
|
-
"@lark-apaas/aily-web-sdk": "^0.0.
|
|
103
|
-
"@lark-apaas/auth-sdk": "^0.1.
|
|
104
|
-
"@lark-apaas/client-capability": "^0.1.
|
|
105
|
-
"@lark-apaas/internal-slardar": "
|
|
102
|
+
"@lark-apaas/aily-web-sdk": "^0.0.6",
|
|
103
|
+
"@lark-apaas/auth-sdk": "^0.1.1",
|
|
104
|
+
"@lark-apaas/client-capability": "^0.1.5",
|
|
105
|
+
"@lark-apaas/internal-slardar": ">=0.0.1",
|
|
106
106
|
"@lark-apaas/miaoda-inspector": "^1.0.20",
|
|
107
107
|
"@lark-apaas/observable-web": "^1.0.4",
|
|
108
108
|
"@radix-ui/react-avatar": "^1.1.10",
|