@lark-apaas/client-toolkit 1.2.17-alpha.10 → 1.2.17-alpha.12

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.
@@ -4,7 +4,6 @@ import { ConfigProvider } from "antd";
4
4
  import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
5
5
  import zh_CN from "antd/locale/zh_CN";
6
6
  import IframeBridge from "./IframeBridge.js";
7
- import RoutePatternTracker from "./RoutePatternTracker.js";
8
7
  import { Toaster } from "./sonner.js";
9
8
  import { PageHoc } from "./PageHoc.js";
10
9
  import { reportTeaEvent } from "./utils/tea.js";
@@ -61,7 +60,6 @@ const App = (props)=>{
61
60
  !disableToaster && true !== appFlags.customToaster && /*#__PURE__*/ jsx(Toaster, {}),
62
61
  'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {}),
63
62
  'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(IframeBridge, {}),
64
- /*#__PURE__*/ jsx(RoutePatternTracker, {}),
65
63
  /*#__PURE__*/ jsx(PageHoc, {
66
64
  children: props.children
67
65
  })
@@ -1,6 +1,5 @@
1
- import { slardar } from "@lark-apaas/internal-slardar";
2
1
  import { getHmrApi } from "../utils/hmr-api.js";
3
- import { submitPostMessage } from "../utils/postMessage.js";
2
+ import { submitPostMessage, submitSlardarEvent } from "../utils/postMessage.js";
4
3
  import { levelSchema } from "./log-types.js";
5
4
  import { logger } from "./logger.js";
6
5
  let devServerDisconnectInfo = null;
@@ -20,26 +19,22 @@ function processDevServerLog(log) {
20
19
  status: 'disconnected'
21
20
  }
22
21
  });
23
- slardar.sendEvent({
22
+ submitSlardarEvent({
24
23
  name: 'sandbox-devServer',
25
- metrics: {
26
- time
27
- },
28
24
  categories: {
29
- type: 'disconnected'
25
+ type: 'disconnected',
26
+ time
30
27
  }
31
28
  });
32
29
  return;
33
30
  }
34
31
  if (!devServerDisconnectInfo) return;
35
32
  if (devFlag && log.includes('Trying to reconnect')) {
36
- if (retryCount) slardar.sendEvent({
33
+ if (retryCount) submitSlardarEvent({
37
34
  name: 'sandbox-devServer',
38
- metrics: {
39
- retryCount: retryCount + 1
40
- },
41
35
  categories: {
42
- type: 'reconnect-failed'
36
+ type: 'reconnect-failed',
37
+ retryCount: retryCount + 1
43
38
  }
44
39
  });
45
40
  retryCount++;
@@ -57,14 +52,12 @@ function processDevServerLog(log) {
57
52
  const startTime = devServerDisconnectInfo.time;
58
53
  const duration = Date.now() - startTime;
59
54
  devServerDisconnectInfo = null;
60
- slardar.sendEvent({
55
+ submitSlardarEvent({
61
56
  name: 'sandbox-devServer',
62
- metrics: {
57
+ categories: {
58
+ type: 'devServer-reconnected',
63
59
  startTime,
64
60
  duration
65
- },
66
- categories: {
67
- type: 'devServer-reconnected'
68
61
  }
69
62
  });
70
63
  }
@@ -83,7 +76,7 @@ function listenModuleHmr() {
83
76
  });
84
77
  hmr.onError((error)=>{
85
78
  console.warn('hmr apply failed', error);
86
- slardar.sendEvent({
79
+ submitSlardarEvent({
87
80
  name: 'sandbox-devServer',
88
81
  categories: {
89
82
  type: 'hmr-apply-failed',
@@ -3,21 +3,6 @@ import { observable } from "@lark-apaas/observable-web";
3
3
  import { logger } from "../apis/logger.js";
4
4
  import { getStacktrace } from "../logger/selected-logs.js";
5
5
  import { safeStringify } from "./safeStringify.js";
6
- import { slardar } from "@lark-apaas/internal-slardar";
7
- import { getCurrentRoutePattern } from "./routePattern.js";
8
- const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
9
- function getRefererPath() {
10
- try {
11
- return getCurrentRoutePattern();
12
- } catch {
13
- return '/';
14
- }
15
- }
16
- function getApiField(method, response, errorResponse, fallbackPath) {
17
- const matchRoute = response?.headers?.['x-match-route'] || errorResponse?.headers?.['x-match-route'] || '';
18
- const routePath = matchRoute || fallbackPath;
19
- return `${method} ${routePath}`;
20
- }
21
6
  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;
22
7
  async function logResponse(ok, responseOrError) {
23
8
  if (isValidResponse(responseOrError)) {
@@ -154,17 +139,12 @@ function handleSpanEnd(cfg, response, error) {
154
139
  const url = response?.request?.responseURL || errorResponse?.request?.responseURL || cfg.url || "";
155
140
  const method = (cfg.method || 'GET').toUpperCase();
156
141
  const path = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
157
- const referer_path = getRefererPath();
158
- const api = getApiField(method, response, errorResponse, path);
159
- const type = APP_CLIENT_API_LOG_TYPE;
160
142
  const logData = {
161
143
  method,
162
144
  path,
163
145
  url,
164
146
  duration_ms: startTime ? Date.now() - startTime : void 0,
165
- status: response ? response.status : errorResponse.status || 0,
166
- referer_path,
167
- type
147
+ status: response ? response.status : errorResponse.status || 0
168
148
  };
169
149
  if (error) logData.error_message = errorMessage;
170
150
  if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
@@ -177,11 +157,7 @@ function handleSpanEnd(cfg, response, error) {
177
157
  const responseData = response?.data || errorResponse?.data;
178
158
  if (responseData) logData.response = responseData;
179
159
  const level = error ? 'ERROR' : 'INFO';
180
- observable.log(level, safeStringify(logData), {
181
- referer_path,
182
- api,
183
- type
184
- }, currentSpan);
160
+ observable.log(level, safeStringify(logData), {}, currentSpan);
185
161
  'function' == typeof currentSpan.end && currentSpan.end();
186
162
  } catch (e) {
187
163
  console.error('[AxiosTrace] Log span failed:', e);
@@ -217,10 +193,6 @@ AxiosProto.request = function(configOrUrl, config) {
217
193
  return response;
218
194
  }, (error)=>{
219
195
  handleSpanEnd(error.config || finalConfig, null, error);
220
- slardar.captureException(error, {
221
- source: 'toolkit',
222
- module: 'axios-request'
223
- });
224
196
  throw error;
225
197
  });
226
198
  };
@@ -281,24 +253,9 @@ function initAxiosConfig(axiosInstance) {
281
253
  ],
282
254
  meta: {}
283
255
  });
284
- slardar.sendEvent({
285
- name: 'toolkit_axios_403_downgrade',
286
- categories: {
287
- url: String(error.config?.url || ''),
288
- method: String(error.config?.method || '')
289
- }
290
- });
291
256
  return error.response;
292
257
  }
293
258
  } catch (e) {}
294
- slardar.sendEvent({
295
- name: 'toolkit_axios_response_error',
296
- categories: {
297
- url: String(error.config?.url || ''),
298
- method: String(error.config?.method || ''),
299
- status: String(error.response?.status || '')
300
- }
301
- });
302
259
  return Promise.reject(error);
303
260
  });
304
261
  'production' !== process.env.NODE_ENV && instance.interceptors.response.use((response)=>{
@@ -1,6 +1,7 @@
1
1
  import type { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
2
2
  export declare function resolveParentOrigin(): string;
3
3
  export declare function submitPostMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
4
+ export declare function submitSlardarEvent(event: unknown): void;
4
5
  export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
5
6
  type: T;
6
7
  }>;
@@ -38,10 +38,15 @@ function submitPostMessage(message, targetOrigin) {
38
38
  console.error('postMessage error', e);
39
39
  }
40
40
  }
41
+ function submitSlardarEvent(event) {
42
+ const slardar = window.KSlardarWeb;
43
+ if ('function' == typeof slardar) slardar('sendEvent', event);
44
+ else console.warn('hmr listen function not found');
45
+ }
41
46
  function isOutgoingMessage(msg, type) {
42
47
  return msg.type === type;
43
48
  }
44
49
  function isIncomingMessage(msg, type) {
45
50
  return msg.type === type;
46
51
  }
47
- export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage };
52
+ export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage, submitSlardarEvent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.17-alpha.10",
3
+ "version": "1.2.17-alpha.12",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -99,10 +99,9 @@
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.6",
102
+ "@lark-apaas/aily-web-sdk": "0.0.2-alpha.14",
103
103
  "@lark-apaas/auth-sdk": "^0.1.1",
104
104
  "@lark-apaas/client-capability": "^0.1.5",
105
- "@lark-apaas/internal-slardar": ">=0.0.1",
106
105
  "@lark-apaas/miaoda-inspector": "^1.0.20",
107
106
  "@lark-apaas/observable-web": "^1.0.4",
108
107
  "@radix-ui/react-avatar": "^1.1.10",
@@ -1,5 +0,0 @@
1
- /**
2
- * 监听路由变化,更新当前匹配的参数化路由模式
3
- * 供观测 SDK 获取 referer_path 字段
4
- */
5
- export default function RoutePatternTracker(): any;
@@ -1,13 +0,0 @@
1
- import { useEffect } from "react";
2
- import { useLocation } from "react-router-dom";
3
- import { updateRoutePattern } from "../../utils/routePattern.js";
4
- function RoutePatternTracker() {
5
- const location = useLocation();
6
- useEffect(()=>{
7
- updateRoutePattern(location.pathname);
8
- }, [
9
- location.pathname
10
- ]);
11
- return null;
12
- }
13
- export { RoutePatternTracker as default };
@@ -1,10 +0,0 @@
1
- /**
2
- * 根据当前 pathname 匹配路由模式并更新存储
3
- * 使用 react-router 的 matchPath 确保匹配逻辑与路由一致
4
- */
5
- export declare function updateRoutePattern(pathname: string): Promise<void>;
6
- /**
7
- * 获取当前匹配的参数化路由模式
8
- * 供 axiosConfig 等非 React 上下文使用
9
- */
10
- export declare function getCurrentRoutePattern(): string;
@@ -1,45 +0,0 @@
1
- import { matchPath } from "react-router-dom";
2
- import { normalizeBasePath } from "./utils.js";
3
- let currentRoutePattern = '/';
4
- let routeDefinitions = null;
5
- async function loadRouteDefinitions() {
6
- if (routeDefinitions) return routeDefinitions;
7
- try {
8
- const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
9
- const res = await fetch(`${basePath}/routes.json`);
10
- routeDefinitions = await res.json();
11
- } catch {
12
- routeDefinitions = [
13
- {
14
- path: '/'
15
- }
16
- ];
17
- }
18
- return routeDefinitions;
19
- }
20
- async function updateRoutePattern(pathname) {
21
- const routes = await loadRouteDefinitions();
22
- const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
23
- let relativePath = pathname;
24
- if (basePath && pathname.startsWith(basePath)) relativePath = pathname.slice(basePath.length) || '/';
25
- const sortedRoutes = [
26
- ...routes
27
- ].sort((a, b)=>b.path.length - a.path.length);
28
- for (const route of sortedRoutes){
29
- let routePath = route.path;
30
- if (basePath && routePath.startsWith(basePath)) routePath = routePath.slice(basePath.length) || '/';
31
- const match = matchPath({
32
- path: routePath,
33
- end: true
34
- }, relativePath);
35
- if (match) {
36
- currentRoutePattern = routePath;
37
- return;
38
- }
39
- }
40
- currentRoutePattern = relativePath;
41
- }
42
- function getCurrentRoutePattern() {
43
- return currentRoutePattern;
44
- }
45
- export { getCurrentRoutePattern, updateRoutePattern };