@lark-apaas/client-toolkit 1.1.21-alpha.auth.dev.0 → 1.1.21-alpha.auth.dev.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.
@@ -0,0 +1,4 @@
1
+ import { Table } from 'antd';
2
+ import type { TableProps } from 'antd';
3
+ export { Table };
4
+ export type { TableProps };
@@ -0,0 +1,2 @@
1
+ import { Table } from "antd";
2
+ export { Table };
@@ -0,0 +1 @@
1
+ export { useAuth, useAuthAbility, Can, ROLE_SUBJECT, } from '@lark-apaas/auth-sdk';
@@ -0,0 +1,2 @@
1
+ import { Can, ROLE_SUBJECT, useAuth, useAuthAbility } from "@lark-apaas/auth-sdk";
2
+ export { Can, ROLE_SUBJECT, useAuth, useAuthAbility };
@@ -1,5 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useEffect } from "react";
2
+ import { useEffect, useState } from "react";
3
+ import { ConfigProvider } from "antd";
3
4
  import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
4
5
  import IframeBridge from "./IframeBridge.js";
5
6
  import { defaultUIConfig } from "../theme/ui-config.js";
@@ -15,6 +16,15 @@ import { AuthProvider } from "@lark-apaas/auth-sdk";
15
16
  registerDayjsPlugins();
16
17
  initAxiosConfig();
17
18
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
19
+ const readCssVarColor = (varName, fallback)=>{
20
+ try {
21
+ if ('undefined' == typeof document) return fallback;
22
+ const value = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
23
+ return value || fallback;
24
+ } catch {
25
+ return fallback;
26
+ }
27
+ };
18
28
  const App = (props)=>{
19
29
  const { themeMeta = {}, enableAuth } = props;
20
30
  useAppInfo();
@@ -58,18 +68,140 @@ const App = (props)=>{
58
68
  ]
59
69
  });
60
70
  };
61
- const AppContainer = (props)=>{
71
+ const AppContainer_AppContainer = (props)=>{
62
72
  const { children, ...rest } = props;
73
+ const [cssColors, setCssColors] = useState(()=>({
74
+ background: readCssVarColor('--background'),
75
+ destructive: readCssVarColor('--destructive'),
76
+ primary: readCssVarColor('--primary'),
77
+ foreground: readCssVarColor('--foreground'),
78
+ warning: readCssVarColor('--warning'),
79
+ success: readCssVarColor('--success'),
80
+ muted: readCssVarColor('--muted'),
81
+ mutedForeground: readCssVarColor('--muted-foreground'),
82
+ border: readCssVarColor('--border'),
83
+ popover: readCssVarColor('--popover'),
84
+ accent: readCssVarColor('--accent')
85
+ }));
86
+ useEffect(()=>{
87
+ if ('production' === process.env.NODE_ENV) return ()=>{};
88
+ const observer = new MutationObserver((mutations)=>{
89
+ for (const mutation of mutations){
90
+ let linkTag = null;
91
+ if ('attributes' === mutation.type) {
92
+ if ('fullstack-nestjs-template:chunk-main' === mutation.target.dataset.webpack) linkTag = mutation.target;
93
+ } else if ('childList' === mutation.type) {
94
+ for (const node of Array.from(mutation.addedNodes))if ('LINK' === node.nodeName && 'fullstack-nestjs-template:chunk-main' === node.dataset.webpack) {
95
+ linkTag = node;
96
+ break;
97
+ }
98
+ }
99
+ if (linkTag) {
100
+ let retryCount = 0;
101
+ const maxRetries = 10;
102
+ const retryDelay = 400;
103
+ const updateColors = ()=>{
104
+ const newColors = {
105
+ background: readCssVarColor('--background'),
106
+ destructive: readCssVarColor('--destructive'),
107
+ primary: readCssVarColor('--primary'),
108
+ foreground: readCssVarColor('--foreground'),
109
+ warning: readCssVarColor('--warning'),
110
+ success: readCssVarColor('--success'),
111
+ muted: readCssVarColor('--muted'),
112
+ mutedForeground: readCssVarColor('--muted-foreground'),
113
+ border: readCssVarColor('--border'),
114
+ popover: readCssVarColor('--popover'),
115
+ accent: readCssVarColor('--accent')
116
+ };
117
+ setCssColors((currentColors)=>{
118
+ if (JSON.stringify(currentColors) !== JSON.stringify(newColors)) {
119
+ retryCount = 0;
120
+ return newColors;
121
+ }
122
+ if (retryCount < maxRetries) {
123
+ retryCount++;
124
+ setTimeout(updateColors, retryDelay);
125
+ }
126
+ return currentColors;
127
+ });
128
+ };
129
+ setTimeout(updateColors, 100);
130
+ }
131
+ }
132
+ });
133
+ observer.observe(document.head, {
134
+ childList: true,
135
+ subtree: true,
136
+ attributes: true,
137
+ attributeFilter: [
138
+ 'href'
139
+ ]
140
+ });
141
+ return ()=>{
142
+ observer.disconnect();
143
+ };
144
+ }, []);
145
+ const antdThemeToken = {
146
+ colorBgBase: cssColors.background,
147
+ colorError: cssColors.destructive,
148
+ colorInfo: cssColors.primary,
149
+ colorLink: cssColors.primary,
150
+ colorPrimary: cssColors.primary,
151
+ colorSuccess: cssColors.primary,
152
+ colorTextBase: cssColors.foreground,
153
+ colorWarning: cssColors.destructive
154
+ };
155
+ const antdTableToken = {
156
+ bodySortBg: cssColors.muted,
157
+ borderColor: cssColors.border,
158
+ expandIconBg: cssColors.background,
159
+ filterDropdownBg: cssColors.popover,
160
+ filterDropdownMenuBg: cssColors.popover,
161
+ fixedHeaderSortActiveBg: cssColors.muted,
162
+ footerBg: cssColors.muted,
163
+ footerColor: cssColors.mutedForeground,
164
+ headerBg: cssColors.muted,
165
+ headerColor: cssColors.mutedForeground,
166
+ headerFilterHoverBg: cssColors.muted,
167
+ headerSortActiveBg: cssColors.muted,
168
+ headerSortHoverBg: cssColors.muted,
169
+ headerSplitColor: cssColors.border,
170
+ rowExpandedBg: cssColors.background,
171
+ rowHoverBg: cssColors.muted,
172
+ rowSelectedBg: cssColors.accent,
173
+ rowSelectedHoverBg: cssColors.accent,
174
+ stickyScrollBarBg: cssColors.muted
175
+ };
176
+ const antdPaginationToken = {
177
+ itemActiveBg: cssColors.background,
178
+ itemActiveBgDisabled: cssColors.muted,
179
+ itemActiveColor: cssColors.primary,
180
+ itemActiveColorDisabled: cssColors.muted,
181
+ itemActiveColorHover: cssColors.muted,
182
+ itemBg: cssColors.background,
183
+ itemInputBg: cssColors.background,
184
+ itemLinkBg: cssColors.background
185
+ };
63
186
  return /*#__PURE__*/ jsxs(Fragment, {
64
187
  children: [
65
188
  /*#__PURE__*/ jsx(safety, {}),
66
- /*#__PURE__*/ jsx(App, {
67
- themeMeta: props.themeMeta,
68
- enableAuth: props.enableAuth,
69
- children: children
189
+ /*#__PURE__*/ jsx(ConfigProvider, {
190
+ theme: {
191
+ token: antdThemeToken,
192
+ components: {
193
+ Table: antdTableToken,
194
+ Pagination: antdPaginationToken
195
+ }
196
+ },
197
+ children: /*#__PURE__*/ jsx(App, {
198
+ themeMeta: props.themeMeta,
199
+ enableAuth: props.enableAuth,
200
+ children: children
201
+ })
70
202
  })
71
203
  ]
72
204
  });
73
205
  };
74
- const components_AppContainer = AppContainer;
75
- export { components_AppContainer as default };
206
+ const AppContainer = AppContainer_AppContainer;
207
+ export { AppContainer as default };
@@ -152,7 +152,7 @@ const Component = ()=>{
152
152
  /*#__PURE__*/ jsx(PopoverTrigger, {
153
153
  asChild: true,
154
154
  children: /*#__PURE__*/ jsxs("div", {
155
- className: "fixed right-3 bottom-3 inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-2.5 py-1.5 bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-md text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000] cursor-pointer",
155
+ className: "fixed right-3 bottom-3 inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-2.5 py-1.5 bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-[6px] text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000] cursor-pointer",
156
156
  onMouseEnter: ()=>{
157
157
  clearTimeout(timeoutRef.current);
158
158
  setOpen(true);
@@ -173,7 +173,7 @@ const Component = ()=>{
173
173
  })
174
174
  }),
175
175
  /*#__PURE__*/ jsx(PopoverContent, {
176
- className: "overflow-hidden p-0 m-0 border-0 rounded-xl!",
176
+ className: "overflow-hidden p-0 m-0 border-0 rounded-[12px]!",
177
177
  style: {
178
178
  boxShadow: '0 6px 12px 0 #41444a0a, 0 8px 24px 0 #41444a0a'
179
179
  },
@@ -12,12 +12,12 @@ const UserDisplay = ({ users, size, className, style, showLabel = true })=>{
12
12
  if (0 === users.length) return [];
13
13
  const first = users[0];
14
14
  const isStringArray = 'string' == typeof first;
15
- return isStringArray ? users.filter(Boolean).map((id)=>String(id)) : users.map((u)=>String(u.user_id)).filter(Boolean);
15
+ return isStringArray ? users.filter(Boolean).map((id)=>String(id)) : users.map((u)=>String(u?.user_id)).filter(Boolean);
16
16
  }
17
17
  return 'string' == typeof users ? [
18
18
  String(users)
19
19
  ] : [
20
- String(users.user_id)
20
+ String(users?.user_id)
21
21
  ].filter(Boolean);
22
22
  }, [
23
23
  users
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const badgeVariants: (props?: {
4
- variant?: "default" | "secondary" | "destructive" | "outline";
4
+ variant?: "default" | "destructive" | "secondary" | "outline";
5
5
  } & import("class-variance-authority/dist/types").ClassProp) => string;
6
6
  declare function Badge({ className, variant, asChild, ...props }: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
7
7
  asChild?: boolean;
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const buttonVariants: (props?: {
4
- variant?: "default" | "link" | "secondary" | "destructive" | "outline" | "ghost";
4
+ variant?: "default" | "link" | "destructive" | "secondary" | "outline" | "ghost";
5
5
  size?: "default" | "icon" | "sm" | "lg" | "icon-sm" | "icon-lg";
6
6
  } & import("class-variance-authority/dist/types").ClassProp) => string;
7
7
  declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
@@ -71,18 +71,26 @@ async function sendSelectedLog(logWithoutID) {
71
71
  } catch (postError) {}
72
72
  }
73
73
  if (void 0 === log.meta.skipFrame) log.meta.skipFrame = 2;
74
- const logJSON = JSON.stringify(log);
74
+ const errorReplacer = (key, value)=>{
75
+ if (value instanceof Error) return {
76
+ message: value.message,
77
+ stack: value.stack,
78
+ name: value.name
79
+ };
80
+ return value;
81
+ };
82
+ const logJSON = JSON.stringify(log, errorReplacer);
75
83
  const logForDedup = {
76
84
  ...log
77
85
  };
78
86
  delete logForDedup.id;
79
- const logContentForDedup = JSON.stringify(logForDedup);
87
+ const logContentForDedup = JSON.stringify(logForDedup, errorReplacer);
80
88
  if (lastLogInfo && lastLogInfo.content === logContentForDedup) {
81
89
  lastLogInfo.count++;
82
90
  log.meta.isDuplicate = true;
83
91
  log.meta.duplicateCount = lastLogInfo.count;
84
92
  log.meta.duplicateOfId = lastLogInfo.id;
85
- const updatedLogJSON = JSON.stringify(log);
93
+ const updatedLogJSON = JSON.stringify(log, errorReplacer);
86
94
  try {
87
95
  batchLogInfo('info', updatedLogJSON);
88
96
  } catch (e) {}
@@ -1,59 +1,129 @@
1
1
  import axios from "axios";
2
2
  import { logger } from "../apis/logger.js";
3
3
  import { getStacktrace } from "../logger/selected-logs.js";
4
- async function logResponse(ok, response) {
5
- const okToTextMap = {
6
- success: '请求成功:',
7
- error: '请求失败:'
8
- };
9
- const realOK = 'success' === ok && response.status >= 200 && response.status < 300;
10
- const parts = [
11
- okToTextMap[realOK ? 'success' : 'error'],
12
- (response.config.url || '').split('?')[0].replace(/^\/spark\/p\/app_\w+/, ''),
13
- ' - ',
14
- Date.now() - response.config._startTime,
15
- 'ms'
16
- ];
17
- const logTraceID = response.headers['x-log-trace-id'];
18
- const queryParams = {};
19
- const url = response.config.url || '';
20
- const queryString = url.split('?')[1];
21
- if (queryString) {
22
- const urlParams = new URLSearchParams(queryString);
23
- urlParams.forEach((value, key)=>{
24
- queryParams[key] = value;
4
+ 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;
5
+ async function logResponse(ok, responseOrError) {
6
+ if (isValidResponse(responseOrError)) {
7
+ const response = responseOrError;
8
+ const okToTextMap = {
9
+ success: '请求成功:',
10
+ error: '请求失败:'
11
+ };
12
+ const realOK = 'success' === ok && response.status >= 200 && response.status < 300;
13
+ const method = (response.config.method || 'GET').toUpperCase();
14
+ const parts = [
15
+ okToTextMap[realOK ? 'success' : 'error'],
16
+ method,
17
+ ' ',
18
+ (response.config.url || '').split('?')[0].replace(/^\/spark\/p\/app_\w+/, ''),
19
+ ' - ',
20
+ Date.now() - response.config._startTime,
21
+ 'ms'
22
+ ];
23
+ const logTraceID = response.headers?.['x-log-trace-id'];
24
+ const queryParams = {};
25
+ const url = response.config.url || '';
26
+ const queryString = url.split('?')[1];
27
+ if (queryString) {
28
+ const urlParams = new URLSearchParams(queryString);
29
+ urlParams.forEach((value, key)=>{
30
+ queryParams[key] = value;
31
+ });
32
+ }
33
+ if (response.config.params) Object.assign(queryParams, response.config.params);
34
+ const args = [
35
+ {
36
+ 请求参数: response.config.data,
37
+ ...Object.keys(queryParams).length > 0 && {
38
+ 查询参数: queryParams
39
+ },
40
+ 返回数据: response.data,
41
+ 请求摘要: {
42
+ 方法: method,
43
+ TraceID: logTraceID,
44
+ 状态: `${response.statusText}[状态码${response.status}]`,
45
+ 时间: `${new Date().toLocaleString()}`
46
+ }
47
+ }
48
+ ];
49
+ const requestUUID = response.config._requestUUID;
50
+ const stacktrace = await requestStacktraceMap.get(requestUUID);
51
+ const logMeta = {
52
+ logTraceID
53
+ };
54
+ if (stacktrace) logMeta.stacktrace = stacktrace;
55
+ logger.log({
56
+ level: ok,
57
+ args: [
58
+ parts.join(''),
59
+ ...args
60
+ ],
61
+ meta: logMeta
25
62
  });
63
+ return;
26
64
  }
27
- if (response.config.params) Object.assign(queryParams, response.config.params);
28
- const args = [
29
- {
30
- '请求参数:': response.config.data,
31
- ...Object.keys(queryParams).length > 0 && {
32
- '查询参数:': queryParams
33
- },
34
- '返回数据:': response.data,
35
- '请求摘要:': {
36
- TraceID: logTraceID,
37
- 状态: `${response.statusText}[状态码${response.status}]`,
38
- 时间: `${new Date().toLocaleString()}`
39
- }
65
+ const error = responseOrError;
66
+ if (error && error.config && 'object' == typeof error.config) {
67
+ const errorType = error.code || 'UNKNOWN_ERROR';
68
+ const errorMessage = error.message || '未知错误';
69
+ const method = (error.config.method || 'GET').toUpperCase();
70
+ const url = error.config.url || '';
71
+ const startTime = error.config._startTime;
72
+ const duration = startTime ? Date.now() - startTime : 0;
73
+ const parts = [
74
+ '网络请求失败:',
75
+ method,
76
+ ' ',
77
+ url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, ''),
78
+ ' - ',
79
+ errorType,
80
+ duration > 0 ? ` (${duration}ms)` : ''
81
+ ];
82
+ const queryParams = {};
83
+ const queryString = url.split('?')[1];
84
+ if (queryString) {
85
+ const urlParams = new URLSearchParams(queryString);
86
+ urlParams.forEach((value, key)=>{
87
+ queryParams[key] = value;
88
+ });
40
89
  }
41
- ];
42
- const requestUUID = response.config._requestUUID;
43
- const stacktrace = await requestStacktraceMap.get(requestUUID);
44
- const logMeta = {
45
- logTraceID
46
- };
47
- if (stacktrace) logMeta.stacktrace = stacktrace;
90
+ if (error.config.params) Object.assign(queryParams, error.config.params);
91
+ const args = [
92
+ {
93
+ 请求参数: error.config.data,
94
+ ...Object.keys(queryParams).length > 0 && {
95
+ 查询参数: queryParams
96
+ },
97
+ 错误信息: errorMessage,
98
+ 请求摘要: {
99
+ 方法: method,
100
+ 错误类型: errorType,
101
+ 错误代码: error.code,
102
+ 超时设置: error.config.timeout,
103
+ 时间: `${new Date().toLocaleString()}`
104
+ }
105
+ }
106
+ ];
107
+ const requestUUID = error.config._requestUUID;
108
+ const stacktrace = await requestStacktraceMap.get(requestUUID);
109
+ const logMeta = {};
110
+ if (stacktrace) logMeta.stacktrace = stacktrace;
111
+ logger.log({
112
+ level: 'error',
113
+ args: [
114
+ parts.join(''),
115
+ ...args
116
+ ],
117
+ meta: logMeta
118
+ });
119
+ return;
120
+ }
48
121
  logger.log({
49
- level: ok,
122
+ level: 'error',
50
123
  args: [
51
- parts.join(''),
52
- ...args
124
+ '请求失败:无响应对象或配置信息'
53
125
  ],
54
- meta: {
55
- logTraceID
56
- }
126
+ meta: {}
57
127
  });
58
128
  }
59
129
  const requestStacktraceMap = new Map();
@@ -73,7 +143,7 @@ function initAxiosConfig(axiosInstance) {
73
143
  logResponse('success', response);
74
144
  return response;
75
145
  }, (error)=>{
76
- logResponse('error', error.response);
146
+ logResponse('error', error.response || error);
77
147
  return Promise.reject(error);
78
148
  });
79
149
  }
@@ -2,4 +2,4 @@
2
2
  * @internal
3
3
  * 获取预览环境父级域名
4
4
  */
5
- export declare function getPreviewParentOrigin(): "https://miaoda.feishu.cn" | "https://miaoda.feishu-pre.cn" | "https://miaoda.feishu-boe.cn";
5
+ export declare function getPreviewParentOrigin(): "https://force.feishu-boe.cn" | "https://miaoda.feishu.cn" | "https://miaoda.feishu-pre.cn" | "https://miaoda.feishu-boe.cn";
@@ -1,5 +1,6 @@
1
1
  function getPreviewParentOrigin() {
2
2
  const { origin } = window.location;
3
+ if (origin.includes('force.byted.org')) return 'https://force.feishu-boe.cn';
3
4
  if (origin.includes('feishuapp.cn') || origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
4
5
  if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
5
6
  return 'https://miaoda.feishu-boe.cn';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.1.21-alpha.auth.dev.0",
3
+ "version": "1.1.21-alpha.auth.dev.2",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -15,6 +15,11 @@
15
15
  "require": "./lib/index.js",
16
16
  "types": "./lib/index.d.ts"
17
17
  },
18
+ "./antd-table": {
19
+ "import": "./lib/antd-table.js",
20
+ "require": "./lib/antd-table.js",
21
+ "types": "./lib/antd-table.d.ts"
22
+ },
18
23
  "./lib/index.css": "./lib/index.css",
19
24
  "./dataloom": {
20
25
  "import": "./lib/apis/dataloom.js",
@@ -55,6 +60,11 @@
55
60
  "import": "./lib/apis/utils/*.js",
56
61
  "require": "./lib/apis/utils/*.js",
57
62
  "types": "./lib/apis/utils/*.d.ts"
63
+ },
64
+ "./auth/*": {
65
+ "import": "./lib/auth.js",
66
+ "require": "./lib/auth.js",
67
+ "types": "./lib/auth.d.ts"
58
68
  }
59
69
  },
60
70
  "scripts": {
@@ -76,7 +86,7 @@
76
86
  "@ant-design/colors": "^7.2.1",
77
87
  "@ant-design/cssinjs": "^1.24.0",
78
88
  "@data-loom/js": "^0.4.0",
79
- "@lark-apaas/auth-sdk": "^0.1.0-alpha.3",
89
+ "@lark-apaas/auth-sdk": "0.1.0-alpha.6",
80
90
  "@lark-apaas/miaoda-inspector": "^1.0.4",
81
91
  "@radix-ui/react-avatar": "^1.1.10",
82
92
  "@radix-ui/react-popover": "^1.1.15",