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

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.
@@ -1,7 +1,10 @@
1
1
  import React from 'react';
2
2
  import { IBaseThemeProviderProps } from '../theme';
3
3
  import '../../index.css';
4
+ interface IBaseAuthProviderProps {
5
+ enableAuth?: boolean;
6
+ }
4
7
  declare const AppContainer: React.FC<{
5
8
  children: React.ReactNode;
6
- } & IBaseThemeProviderProps>;
9
+ } & IBaseThemeProviderProps & IBaseAuthProviderProps>;
7
10
  export default AppContainer;
@@ -9,16 +9,14 @@ import { findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, them
9
9
  import { registerDayjsPlugins } from "./dayjsPlugins.js";
10
10
  import "../../index.css";
11
11
  import { initAxiosConfig } from "../../utils/axiosConfig.js";
12
- import { reportTeaEvent } from "./utils/tea.js";
13
12
  import { useAppInfo } from "../../hooks/index.js";
14
- import { TrackKey } from "../../types/tea.js";
15
13
  import safety from "./safety.js";
16
- import { getAppId } from "../../utils/getAppId.js";
14
+ import { AuthProvider } from "@lark-apaas/auth-sdk";
17
15
  registerDayjsPlugins();
18
16
  initAxiosConfig();
19
17
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
20
18
  const App = (props)=>{
21
- const { themeMeta = {} } = props;
19
+ const { themeMeta = {}, enableAuth } = props;
22
20
  useAppInfo();
23
21
  const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
24
22
  rem: '0.625'
@@ -39,17 +37,10 @@ const App = (props)=>{
39
37
  }, 300);
40
38
  });
41
39
  }, []);
42
- useEffect(()=>{
43
- if ('production' === process.env.NODE_ENV) reportTeaEvent({
44
- trackKey: TrackKey.VIEW,
45
- trackParams: {
46
- artifact_uid: getAppId(window.location.pathname),
47
- agent_id: 'agent_miaoda',
48
- url: window.location.href
49
- }
50
- });
51
- }, []);
52
- return /*#__PURE__*/ jsxs(Fragment, {
40
+ return /*#__PURE__*/ jsxs(AuthProvider, {
41
+ config: {
42
+ enable: enableAuth
43
+ },
53
44
  children: [
54
45
  /*#__PURE__*/ jsx(Toaster, {}),
55
46
  'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
@@ -74,6 +65,7 @@ const AppContainer = (props)=>{
74
65
  /*#__PURE__*/ jsx(safety, {}),
75
66
  /*#__PURE__*/ jsx(App, {
76
67
  themeMeta: props.themeMeta,
68
+ enableAuth: props.enableAuth,
77
69
  children: children
78
70
  })
79
71
  ]
@@ -10,6 +10,5 @@ declare global {
10
10
  _IS_Spark_RUNTIME?: boolean;
11
11
  _bucket_id?: string;
12
12
  csrfToken?: string;
13
- collectEvent?: (...args: any[]) => void;
14
13
  }
15
14
  }
@@ -1,4 +1,3 @@
1
- export declare function getEnv(): 'BOE' | 'PRE' | 'ONLINE';
2
1
  /**
3
2
  * @internal
4
3
  * 获取预览环境父级域名
@@ -1,13 +1,7 @@
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
- }
7
1
  function getPreviewParentOrigin() {
8
- const env = getEnv();
9
- if ('ONLINE' === env) return 'https://miaoda.feishu.cn';
10
- if ('PRE' === env) return 'https://miaoda.feishu-pre.cn';
2
+ const { origin } = window.location;
3
+ if (origin.includes('feishuapp.cn') || origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
4
+ if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
11
5
  return 'https://miaoda.feishu-boe.cn';
12
6
  }
13
- export { getEnv, getPreviewParentOrigin };
7
+ export { getPreviewParentOrigin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.1.20-alpha.tea.1",
3
+ "version": "1.1.21-alpha.auth.dev.0",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -76,6 +76,7 @@
76
76
  "@ant-design/colors": "^7.2.1",
77
77
  "@ant-design/cssinjs": "^1.24.0",
78
78
  "@data-loom/js": "^0.4.0",
79
+ "@lark-apaas/auth-sdk": "^0.1.0-alpha.3",
79
80
  "@lark-apaas/miaoda-inspector": "^1.0.4",
80
81
  "@radix-ui/react-avatar": "^1.1.10",
81
82
  "@radix-ui/react-popover": "^1.1.15",
@@ -83,10 +84,8 @@
83
84
  "@radix-ui/react-tooltip": "^1.2.8",
84
85
  "@zumer/snapdom": "^1.9.14",
85
86
  "axios": "^1.12.2",
86
- "blueimp-md5": "2.10.0",
87
87
  "class-variance-authority": "^0.7.1",
88
88
  "clsx": "~2.0.1",
89
- "crypto-js": "3.1.9-1",
90
89
  "dayjs": "^1.11.13",
91
90
  "echarts": "^6.0.0",
92
91
  "lodash": "^4.17.21",
@@ -1 +0,0 @@
1
- export declare function getLarkUserInfo(): Promise<any>;
@@ -1,17 +0,0 @@
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)}/tenant_info`, {
11
- headers: {
12
- 'X-Suda-Csrf-Token': getCsrfToken()
13
- }
14
- });
15
- return await response.json();
16
- }
17
- export { getLarkUserInfo };
@@ -1,8 +0,0 @@
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>;
@@ -1,51 +0,0 @@
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 };
@@ -1,7 +0,0 @@
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
- }
package/lib/types/tea.js DELETED
@@ -1,5 +0,0 @@
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 };
@@ -1,3 +0,0 @@
1
- export declare const isIpad: () => boolean;
2
- export declare const isMobile: () => boolean;
3
- export declare const isIOS: () => boolean;
@@ -1,13 +0,0 @@
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 };