@lark-apaas/client-toolkit 1.1.21-alpha.auth.dev.4 → 1.1.21-alpha.tea.1

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
@@ -6,71 +6,3 @@
6
6
 
7
7
  * 导出所有对外暴露的 API 和组件,并通过 npm exports 来控制
8
8
  * 其他目录作为 internal 实现,不对外暴露
9
-
10
- ### auth 目录
11
-
12
- * 包含与权限相关的 API 和组件
13
-
14
-
15
- ### 开发组件 - 使用 CanRole 组件 (推荐)
16
-
17
- ```tsx
18
- import { CanRole } from '@lark-apaas/client-toolkit';
19
-
20
- function Home() {
21
- return (
22
- <div>
23
- <CanRole roles={['role_admin']}>
24
- <div>管理员按钮</div>
25
- </CanRole>
26
- <CanRole roles={['role_admin', 'role_editor']}>
27
- <div>编辑按钮</div>
28
- </CanRole>
29
- </div>
30
- );
31
- }
32
- ```
33
-
34
- ### 开发组件 - 使用 AbilityContext 处理复杂场景
35
-
36
- ```tsx
37
- import { useContext } from 'react';
38
- import { AbilityContext, ROLE_SUBJECT } from '@lark-apaas/client-toolkit';
39
-
40
- function Home() {
41
- const ability = useContext(AbilityContext);
42
- return (
43
- <div>
44
- {ability.can('role_admin', ROLE_SUBJECT) || ability.can('role_editor', ROLE_SUBJECT) ? (
45
- <div>可见的仪表盘</div>
46
- ) : null}
47
- </div>
48
- );
49
- }
50
- ```
51
-
52
- ### 开发组件 - 进阶示例
53
-
54
- ### 菜单按权限过滤
55
-
56
- ```tsx
57
- import { useContext } from 'react';
58
- import { AbilityContext, ROLE_SUBJECT } from '@lark-apaas/client-toolkit';
59
-
60
- const menus = [
61
- { name: 'Dashboard', path: '/dashboard', p: { action: 'role_admin', subject: ROLE_SUBJECT } },
62
- { name: 'Users', path: '/users', p: { action: 'role_editor', subject: ROLE_SUBJECT } },
63
- { name: 'Settings', path: '/settings', p: { action: 'role_admin', subject: ROLE_SUBJECT } },
64
- ];
65
-
66
- function Nav() {
67
- const ability = useContext(AbilityContext);
68
- return (
69
- <nav>
70
- {menus.map(m => ability.can(m.p.action, m.p.subject) && (
71
- <a key={m.path} href={m.path}>{m.name}</a>
72
- ))}
73
- </nav>
74
- );
75
- }
76
- ```
@@ -1,10 +1,7 @@
1
1
  import React from 'react';
2
2
  import { IBaseThemeProviderProps } from '../theme';
3
3
  import '../../index.css';
4
- interface IBaseAuthProviderProps {
5
- enableAuth?: boolean;
6
- }
7
4
  declare const AppContainer: React.FC<{
8
5
  children: React.ReactNode;
9
- } & IBaseThemeProviderProps & IBaseAuthProviderProps>;
6
+ } & IBaseThemeProviderProps>;
10
7
  export default AppContainer;
@@ -10,9 +10,11 @@ import { findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, them
10
10
  import { registerDayjsPlugins } from "./dayjsPlugins.js";
11
11
  import "../../index.css";
12
12
  import { initAxiosConfig } from "../../utils/axiosConfig.js";
13
+ import { reportTeaEvent } from "./utils/tea.js";
13
14
  import { useAppInfo } from "../../hooks/index.js";
15
+ import { TrackKey } from "../../types/tea.js";
14
16
  import safety from "./safety.js";
15
- import { AuthProvider } from "@lark-apaas/auth-sdk";
17
+ import { getAppId } from "../../utils/getAppId.js";
16
18
  registerDayjsPlugins();
17
19
  initAxiosConfig();
18
20
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
@@ -26,7 +28,7 @@ const readCssVarColor = (varName, fallback)=>{
26
28
  }
27
29
  };
28
30
  const App = (props)=>{
29
- const { themeMeta = {}, enableAuth } = props;
31
+ const { themeMeta = {} } = props;
30
32
  useAppInfo();
31
33
  const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
32
34
  rem: '0.625'
@@ -47,10 +49,17 @@ const App = (props)=>{
47
49
  }, 300);
48
50
  });
49
51
  }, []);
50
- return /*#__PURE__*/ jsxs(AuthProvider, {
51
- config: {
52
- enable: enableAuth
53
- },
52
+ useEffect(()=>{
53
+ if ('production' === process.env.NODE_ENV) reportTeaEvent({
54
+ trackKey: TrackKey.VIEW,
55
+ trackParams: {
56
+ artifact_uid: getAppId(window.location.pathname),
57
+ agent_id: 'agent_miaoda',
58
+ url: window.location.href
59
+ }
60
+ });
61
+ }, []);
62
+ return /*#__PURE__*/ jsxs(Fragment, {
54
63
  children: [
55
64
  /*#__PURE__*/ jsx(Toaster, {}),
56
65
  'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
@@ -196,7 +205,6 @@ const AppContainer_AppContainer = (props)=>{
196
205
  },
197
206
  children: /*#__PURE__*/ jsx(App, {
198
207
  themeMeta: props.themeMeta,
199
- enableAuth: props.enableAuth,
200
208
  children: children
201
209
  })
202
210
  })
@@ -0,0 +1 @@
1
+ export declare function getLarkUserInfo(): Promise<any>;
@@ -0,0 +1,17 @@
1
+ import { getAppId } from "../../../utils/getAppId.js";
2
+ import { getCsrfToken } from "../../../utils/getCsrfToken.js";
3
+ async function getLarkUserInfo() {
4
+ const appId = getAppId(window.location.pathname);
5
+ if (!appId) return {
6
+ code: 1,
7
+ msg: 'appId is required',
8
+ data: {}
9
+ };
10
+ const response = await fetch(`/spark/b/${getAppId(window.location.pathname)}/lark/user_info`, {
11
+ headers: {
12
+ 'X-Suda-Csrf-Token': getCsrfToken()
13
+ }
14
+ });
15
+ return await response.json();
16
+ }
17
+ export { getLarkUserInfo };
@@ -0,0 +1,8 @@
1
+ import { type TrackParams } from '../../../types/tea';
2
+ export declare const encryptTea: (message: any) => string;
3
+ /**
4
+ * 初始化Tea 客户端
5
+ * @export
6
+ */
7
+ export declare function createTracker(): Promise<void>;
8
+ export declare const reportTeaEvent: ({ trackKey, trackParams }: TrackParams) => Promise<void>;
@@ -0,0 +1,51 @@
1
+ import blueimp_md5 from "blueimp-md5";
2
+ import sha1 from "crypto-js/sha1";
3
+ import { isMobile } from "../../../utils/deviceType.js";
4
+ import { getEnv } from "../../../utils/getParentOrigin.js";
5
+ import { getLarkUserInfo } from "./getLarkUser.js";
6
+ const saltA = '08a441';
7
+ const saltB = '42b91e';
8
+ const encryptTea = (message)=>{
9
+ const msgString = String(message);
10
+ return sha1(saltA + blueimp_md5(msgString + saltB)).toString();
11
+ };
12
+ let teaInstance = false;
13
+ async function createTracker() {
14
+ const { data } = await getLarkUserInfo();
15
+ const { tenantID, userID } = data || {};
16
+ const userIDEncrypt = userID && '0' !== userID ? encryptTea(userID) : void 0;
17
+ const tenantIDEncrypt = tenantID && '0' !== tenantID ? encryptTea(tenantID) : void 0;
18
+ window.collectEvent('init', {
19
+ app_id: 672575,
20
+ channel: 'cn',
21
+ disable_auto_pv: false,
22
+ enable_ab_test: false,
23
+ enable_debug: false,
24
+ enable_stay_duration: true,
25
+ reportTime: 1000
26
+ });
27
+ window.collectEvent('config', {
28
+ user_unique_id: userIDEncrypt,
29
+ device_type: isMobile() ? 'mobile' : 'pc',
30
+ evtParams: {
31
+ open_from: new URLSearchParams(window.location.search).get('open-from') ?? void 0,
32
+ env: getEnv(),
33
+ user_id: userIDEncrypt,
34
+ tenant_id: tenantIDEncrypt
35
+ }
36
+ });
37
+ teaInstance = true;
38
+ window.collectEvent('start');
39
+ }
40
+ const reportTeaEvent = async ({ trackKey, trackParams = {} })=>{
41
+ if (!teaInstance) {
42
+ teaInstance = true;
43
+ await createTracker();
44
+ }
45
+ try {
46
+ window.collectEvent(trackKey, trackParams);
47
+ } catch (err) {
48
+ console.error(err);
49
+ }
50
+ };
51
+ export { createTracker, encryptTea, reportTeaEvent };
@@ -10,5 +10,6 @@ declare global {
10
10
  _IS_Spark_RUNTIME?: boolean;
11
11
  _bucket_id?: string;
12
12
  csrfToken?: string;
13
+ collectEvent?: (...args: any[]) => void;
13
14
  }
14
15
  }
@@ -0,0 +1,7 @@
1
+ export interface TrackParams {
2
+ trackKey: TrackKey;
3
+ trackParams?: Record<string, unknown>;
4
+ }
5
+ export declare enum TrackKey {
6
+ VIEW = "aily_agent_artifact_page_view"
7
+ }
@@ -0,0 +1,5 @@
1
+ var tea_TrackKey = /*#__PURE__*/ function(TrackKey) {
2
+ TrackKey["VIEW"] = "aily_agent_artifact_page_view";
3
+ return TrackKey;
4
+ }({});
5
+ export { tea_TrackKey as TrackKey };
@@ -0,0 +1,3 @@
1
+ export declare const isIpad: () => boolean;
2
+ export declare const isMobile: () => boolean;
3
+ export declare const isIOS: () => boolean;
@@ -0,0 +1,13 @@
1
+ const isIpad = ()=>{
2
+ const _isIpad = /iPad|Tab|Tablet/i.test(navigator.userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 1;
3
+ return Boolean(_isIpad);
4
+ };
5
+ const isMobile = ()=>{
6
+ const isPhone = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent);
7
+ return isPhone || isIpad();
8
+ };
9
+ const isIOS = ()=>{
10
+ if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) return true;
11
+ return false;
12
+ };
13
+ export { isIOS, isIpad, isMobile };
@@ -1,3 +1,4 @@
1
+ export declare function getEnv(): 'BOE' | 'PRE' | 'ONLINE';
1
2
  /**
2
3
  * @internal
3
4
  * 获取预览环境父级域名
@@ -1,3 +1,9 @@
1
+ function getEnv() {
2
+ const { origin } = window.location;
3
+ if (origin.includes('feishuapp.cn') || origin.includes('miaoda.feishuapp.net')) return 'ONLINE';
4
+ if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'PRE';
5
+ return 'BOE';
6
+ }
1
7
  function getPreviewParentOrigin() {
2
8
  const { origin } = window.location;
3
9
  if (origin.includes('force.byted.org')) return 'https://force.feishu-boe.cn';
@@ -5,4 +11,4 @@ function getPreviewParentOrigin() {
5
11
  if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
6
12
  return 'https://miaoda.feishu-boe.cn';
7
13
  }
8
- export { getPreviewParentOrigin };
14
+ export { getEnv, getPreviewParentOrigin };
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.4",
3
+ "version": "1.1.21-alpha.tea.1",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -60,11 +60,6 @@
60
60
  "import": "./lib/apis/utils/*.js",
61
61
  "require": "./lib/apis/utils/*.js",
62
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"
68
63
  }
69
64
  },
70
65
  "scripts": {
@@ -79,13 +74,13 @@
79
74
  "storybook": "storybook dev",
80
75
  "test": "echo 0",
81
76
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx",
82
- "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix"
77
+ "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
78
+ "prepublishOnly": "npm run build && node scripts/replace-workspace-alias.js"
83
79
  },
84
80
  "dependencies": {
85
81
  "@ant-design/colors": "^7.2.1",
86
82
  "@ant-design/cssinjs": "^1.24.0",
87
83
  "@data-loom/js": "^0.4.0",
88
- "@lark-apaas/auth-sdk": "0.1.0-alpha.9",
89
84
  "@lark-apaas/miaoda-inspector": "^1.0.4",
90
85
  "@radix-ui/react-avatar": "^1.1.10",
91
86
  "@radix-ui/react-popover": "^1.1.15",
@@ -93,8 +88,10 @@
93
88
  "@radix-ui/react-tooltip": "^1.2.8",
94
89
  "@zumer/snapdom": "^1.9.14",
95
90
  "axios": "^1.12.2",
91
+ "blueimp-md5": "2.10.0",
96
92
  "class-variance-authority": "^0.7.1",
97
93
  "clsx": "~2.0.1",
94
+ "crypto-js": "3.1.9-1",
98
95
  "dayjs": "^1.11.13",
99
96
  "echarts": "^6.0.0",
100
97
  "lodash": "^4.17.21",
@@ -1 +0,0 @@
1
- export { CanRole, AbilityContext, ROLE_SUBJECT } from '@lark-apaas/auth-sdk';
package/lib/auth/index.js DELETED
@@ -1,2 +0,0 @@
1
- import { AbilityContext, CanRole, ROLE_SUBJECT } from "@lark-apaas/auth-sdk";
2
- export { AbilityContext, CanRole, ROLE_SUBJECT };