@lark-apaas/client-toolkit 0.1.0-alpha.1 → 0.1.0-alpha.log.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @lark-apaas/client-core
1
+ # @lark-apaas/client-toolkit
2
2
 
3
3
  ## 项目架构设计
4
4
 
@@ -11,6 +11,9 @@ function PageHoc(props) {
11
11
  format: 'png',
12
12
  width: document.body.scrollWidth,
13
13
  height: document.body.scrollHeight,
14
+ exclude: [
15
+ '#lucide-react-svg'
16
+ ],
14
17
  backgroundColor: '#ffffff'
15
18
  }).then(async (res)=>{
16
19
  const imgEle = await res.toPng();
@@ -9,7 +9,9 @@ import { PageHoc } from "./PageHoc.js";
9
9
  import { ThemeProvider, findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, themeMetaOptions } from "../theme/index.js";
10
10
  import { registerDayjsPlugins } from "./dayjsPlugins.js";
11
11
  import "../../index.css";
12
+ import { initAxiosConfig } from "../../utils/axiosConfig.js";
12
13
  registerDayjsPlugins();
14
+ initAxiosConfig();
13
15
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
14
16
  const App = (props)=>{
15
17
  const { themeMeta = {} } = props;
@@ -14,7 +14,19 @@ async function getRoutes() {
14
14
  }
15
15
  return routes;
16
16
  }
17
+ async function getSourceMap() {
18
+ let sourceMapContent = '';
19
+ try {
20
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
21
+ const res = await fetch(`${basePath}/main.js.map`);
22
+ sourceMapContent = await res.text();
23
+ } catch (e) {
24
+ console.warn('get main.js.map error', e);
25
+ }
26
+ return sourceMapContent;
27
+ }
17
28
  const childApi = {
18
- getRoutes
29
+ getRoutes,
30
+ getSourceMap
19
31
  };
20
32
  export { childApi };
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect } from "react";
3
3
  import { useLocation } from "react-router-dom";
4
4
  import { Button } from "antd";
@@ -9,13 +9,19 @@ const RenderError = (props)=>{
9
9
  const location = useLocation();
10
10
  const onClickCopy = useCallback(()=>{
11
11
  const { message, stack } = error ?? {};
12
- let result = error;
12
+ let result = '';
13
13
  if (message && stack) {
14
14
  const wrapIndex = stack.indexOf('\n');
15
15
  const extraMsg = -1 !== wrapIndex ? stack.slice(0, wrapIndex) : stack;
16
16
  result = `${message}
17
17
  ${extraMsg}`;
18
18
  }
19
+ if (!result) try {
20
+ result = JSON.stringify(error);
21
+ } catch (e) {
22
+ console.error('复制到剪切板失败:', error);
23
+ result = 'unknown error';
24
+ }
19
25
  copyToClipboard(result);
20
26
  }, [
21
27
  error
@@ -50,27 +56,31 @@ const RenderError = (props)=>{
50
56
  }),
51
57
  /*#__PURE__*/ jsx("p", {
52
58
  className: "text-l/[22px] text-[#1F2329] font-medium mb-2",
53
- children: "哎呀,写错代码了"
54
- }),
55
- /*#__PURE__*/ jsx("p", {
56
- className: "text-sm/[22px] text-[#646A73] font-normal mb-2",
57
- children: "可复制错误信息,或告诉妙搭进行修复"
59
+ children: 'production' !== process.env.NODE_ENV ? '哎呀,写错代码了' : '哎呀,出错了'
58
60
  }),
59
- /*#__PURE__*/ jsxs("div", {
60
- className: "flex space-x-4",
61
+ 'production' !== process.env.NODE_ENV ? /*#__PURE__*/ jsxs(Fragment, {
61
62
  children: [
62
- /*#__PURE__*/ jsx(Button, {
63
- className: "bg-white text-gray-600 font-[400] border rounded-[6px] shadow-xs hover:bg-gray-100 active:bg-gray-200 focus:outline-hidden h-[32px] border-[#D0D3D6]",
64
- onClick: onClickCopy,
65
- children: "复制错误信息"
63
+ /*#__PURE__*/ jsx("p", {
64
+ className: "text-sm/[22px] text-[#646A73] font-normal mb-2",
65
+ children: "可复制错误信息,或告诉妙搭进行修复"
66
66
  }),
67
- /*#__PURE__*/ jsx(Button, {
68
- className: "h-[32px] text-sm font-medium text-white bg-blue-600 border border-transparent rounded-[6px] shadow-xs hover:bg-blue-600 active:bg-blue-700 focus:outline-hidden ",
69
- onClick: onClickRepair,
70
- children: "告诉妙搭修复"
67
+ /*#__PURE__*/ jsxs("div", {
68
+ className: "flex space-x-4",
69
+ children: [
70
+ /*#__PURE__*/ jsx(Button, {
71
+ className: "bg-white text-gray-600 font-[400] border rounded-[6px] shadow-xs hover:bg-gray-100 active:bg-gray-200 focus:outline-hidden h-[32px] border-[#D0D3D6]",
72
+ onClick: onClickCopy,
73
+ children: "复制错误信息"
74
+ }),
75
+ /*#__PURE__*/ jsx(Button, {
76
+ className: "h-[32px] text-sm font-medium text-white bg-blue-600 border border-transparent rounded-[6px] shadow-xs hover:bg-blue-600 active:bg-blue-700 focus:outline-hidden ",
77
+ onClick: onClickRepair,
78
+ children: "告诉妙搭修复"
79
+ })
80
+ ]
71
81
  })
72
82
  ]
73
- })
83
+ }) : null
74
84
  ]
75
85
  })
76
86
  });
@@ -47,4 +47,5 @@ export interface ParentApi {
47
47
  }
48
48
  export interface ChildApi {
49
49
  getRoutes: () => Promise<any[]>;
50
+ getSourceMap: () => Promise<string>;
50
51
  }
@@ -0,0 +1,5 @@
1
+ import { type AxiosInstance } from 'axios';
2
+ /**
3
+ * axios配置内容:拦截器、日志等
4
+ */
5
+ export declare function initAxiosConfig(axiosInstance?: AxiosInstance): void;
@@ -0,0 +1,60 @@
1
+ import axios from "axios";
2
+ import { logger } from "../apis/logger.js";
3
+ function getRequestLogInfo(config) {
4
+ return {
5
+ url: config.url,
6
+ method: config.method?.toUpperCase(),
7
+ params: config.params,
8
+ data: config.data,
9
+ headers: {
10
+ ...config.headers,
11
+ 'X-Suda-Csrf-Token': config.headers['X-Suda-Csrf-Token'] ? '[REDACTED]' : void 0,
12
+ Authorization: config.headers.Authorization ? '[REDACTED]' : void 0
13
+ }
14
+ };
15
+ }
16
+ function initAxiosConfig(axiosInstance) {
17
+ if (!axiosInstance) axiosInstance = axios;
18
+ axiosInstance.defaults.timeout = 10000;
19
+ axiosInstance.interceptors.request.use((config)=>{
20
+ config._startTime = Date.now();
21
+ const csrfToken = window.csrfToken;
22
+ if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
23
+ logger.info({
24
+ type: 'HTTP Request',
25
+ ...getRequestLogInfo(config)
26
+ });
27
+ return config;
28
+ }, (error)=>{
29
+ logger.error({
30
+ type: 'HTTP Request',
31
+ ...getRequestLogInfo(error.config),
32
+ message: error.message,
33
+ stack: error.stack
34
+ });
35
+ return Promise.reject(error);
36
+ });
37
+ axiosInstance.interceptors.response.use((response)=>{
38
+ logger.info({
39
+ type: 'HTTP Response',
40
+ ...getRequestLogInfo(response.config),
41
+ status: response.status,
42
+ statusText: response.statusText,
43
+ responseData: response.data,
44
+ responseTime: Date.now() - response.config._startTime
45
+ });
46
+ return response;
47
+ }, (error)=>{
48
+ logger.error({
49
+ type: 'HTTP Response',
50
+ ...getRequestLogInfo(error.config),
51
+ status: error.response?.status,
52
+ statusText: error.response?.statusText,
53
+ message: error.message,
54
+ responseData: error.response?.data,
55
+ responseTime: Date.now() - error.config._startTime
56
+ });
57
+ return Promise.reject(error);
58
+ });
59
+ }
60
+ export { initAxiosConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.log.2",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -70,14 +70,13 @@
70
70
  "test": "echo 0",
71
71
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx",
72
72
  "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
73
- "postinstall": "yes | npx shadcn@latest add --all -o -y -c \"$INIT_CWD\"",
74
73
  "prepublishOnly": "npm run build && node scripts/replace-workspace-alias.js"
75
74
  },
76
75
  "dependencies": {
77
76
  "@ant-design/colors": "^7.2.1",
78
77
  "@ant-design/cssinjs": "^1.24.0",
79
78
  "@data-loom/js": "0.3.1",
80
- "@lark-apaas/miaoda-inspector": "0.1.0-alpha.8",
79
+ "@lark-apaas/miaoda-inspector": "^1.0.0",
81
80
  "@zumer/snapdom": "^1.9.14",
82
81
  "clsx": "~2.0.1",
83
82
  "dayjs": "^1.11.13",
@@ -113,7 +112,7 @@
113
112
  "antd": "^5.26.6",
114
113
  "eslint": "^8.57.0",
115
114
  "jsdom": "^26.1.0",
116
- "lucide-react": "npm:@lark-apaas/lucide-react@0.1.0-alpha.5",
115
+ "lucide-react": "npm:@lark-apaas/lucide-react@1.0.2",
117
116
  "react": "^18.3.1",
118
117
  "react-dom": "^18.3.1",
119
118
  "react-router-dom": "^6.26.2",