@lark-apaas/client-toolkit 1.1.21 → 1.1.23-dataloom-test.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.
@@ -10,8 +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";
17
+ import { getAppId } from "../../utils/getAppId.js";
15
18
  registerDayjsPlugins();
16
19
  initAxiosConfig();
17
20
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
@@ -46,6 +49,16 @@ const App = (props)=>{
46
49
  }, 300);
47
50
  });
48
51
  }, []);
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
+ }, []);
49
62
  return /*#__PURE__*/ jsxs(Fragment, {
50
63
  children: [
51
64
  /*#__PURE__*/ jsx(Toaster, {}),
@@ -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/${appId}/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
+ try {
42
+ if (!teaInstance) {
43
+ teaInstance = true;
44
+ await createTracker();
45
+ }
46
+ window.collectEvent(trackKey, trackParams);
47
+ } catch (err) {
48
+ console.error(err);
49
+ }
50
+ };
51
+ export { createTracker, encryptTea, reportTeaEvent };
@@ -2,19 +2,26 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect } from "react";
3
3
  import { logger } from "../../logger/index.js";
4
4
  import { createApplyHandle, getModuleHot } from "../../utils/module-hot.js";
5
+ import { submitPostMessage } from "../../utils/postMessage.js";
5
6
  const RenderError = (props)=>{
6
7
  const { error, resetErrorBoundary } = props;
7
8
  useEffect(()=>{
8
- if (error) logger.log({
9
- level: 'error',
10
- args: [
11
- 'Render Error',
12
- error
13
- ],
14
- meta: {
15
- type: 'render-error'
16
- }
17
- });
9
+ if (error) {
10
+ submitPostMessage({
11
+ type: 'RenderError',
12
+ data: error
13
+ });
14
+ logger.log({
15
+ level: 'error',
16
+ args: [
17
+ 'Render Error',
18
+ error
19
+ ],
20
+ meta: {
21
+ type: 'render-error'
22
+ }
23
+ });
24
+ }
18
25
  }, [
19
26
  error
20
27
  ]);
@@ -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",
3
+ "version": "1.1.23-dataloom-test.0",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -80,16 +80,18 @@
80
80
  "dependencies": {
81
81
  "@ant-design/colors": "^7.2.1",
82
82
  "@ant-design/cssinjs": "^1.24.0",
83
- "@data-loom/js": "^0.4.0",
84
- "@lark-apaas/miaoda-inspector": "^1.0.4",
83
+ "@data-loom/js": "0.4.2-alpha.1",
84
+ "@lark-apaas/miaoda-inspector": "^1.0.5",
85
85
  "@radix-ui/react-avatar": "^1.1.10",
86
86
  "@radix-ui/react-popover": "^1.1.15",
87
87
  "@radix-ui/react-slot": "^1.2.3",
88
88
  "@radix-ui/react-tooltip": "^1.2.8",
89
89
  "@zumer/snapdom": "^1.9.14",
90
90
  "axios": "^1.12.2",
91
+ "blueimp-md5": "2.10.0",
91
92
  "class-variance-authority": "^0.7.1",
92
93
  "clsx": "~2.0.1",
94
+ "crypto-js": "3.1.9-1",
93
95
  "dayjs": "^1.11.13",
94
96
  "echarts": "^6.0.0",
95
97
  "lodash": "^4.17.21",