@lark-apaas/client-toolkit 1.2.53-alpha.1 → 1.2.53-alpha.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.
@@ -1,7 +1,19 @@
1
1
  import React from 'react';
2
2
  /**
3
- * 打开「投诉与举报」页:scene/entity_type 固定,entity_id 取当前妙搭 appId(getAppId
4
- * window.appId,水印仅豆包应用展示,此时必有 appId),域名按环境选,params 整体 encode。
3
+ * 是否豆包来源应用。来源由 coding/canvas 构建链编译期把 MIAODA_APP_SOURCE 注入 process.env
4
+ * (define 整体替换 `process.env.MIAODA_APP_SOURCE` 这个 key)。但完整版 toolkit 同时被其它
5
+ * 全栈构建链(fullstack-vite/rspack-preset)消费——它们不注入该 key,且浏览器没有 process 全局,
6
+ * 此时裸读会抛 `ReferenceError: process is not defined`,把整个宿主应用白屏。故 try/catch 兜底:
7
+ * 未注入 → 返回 false(非豆包,回落 Safety),绝不让水印判定拖垮宿主应用。
8
+ *
9
+ * 注意:只能裸引用完整 key `process.env.MIAODA_APP_SOURCE`(define 替换的就是它);不能写
10
+ * `typeof process` 之类——那段不会被 define 替换,注入构建里 process 仍可能未定义,反而误判。
11
+ */
12
+ export declare const isDoubaoSource: () => boolean;
13
+ /**
14
+ * 打开「投诉与举报」页:scene/entity_type 固定,entity_id 取当前妙搭 appId,域名按环境选,
15
+ * params 整体 encode。appId 为空(异常环境)时直接不跳转,避免带空 entity_id 打开举报中心
16
+ * (与 safety.tsx openReport 同口径)。
5
17
  */
6
18
  export declare const openDoubaoReport: () => void;
7
19
  export declare const FeedbackIcon: React.FC;
@@ -3,27 +3,37 @@ import { useRef, useState } from "react";
3
3
  import { Content, Portal, Root, Trigger } from "@radix-ui/react-popover";
4
4
  import { DOUBAO_LOGO_SRC, DOUBAO_PILL_MOBILE_PNG } from "./doubao-watermark-asset.js";
5
5
  import { getAppId } from "../../utils/getAppId.js";
6
+ import { getEnv } from "../../utils/getParentOrigin.js";
6
7
  import { useIsMobile } from "../../hooks/index.js";
7
8
  const DOUBAO_SOURCE = '5';
9
+ const isDoubaoSource = ()=>{
10
+ try {
11
+ return String(process.env.MIAODA_APP_SOURCE) === DOUBAO_SOURCE;
12
+ } catch {
13
+ return false;
14
+ }
15
+ };
8
16
  const REPORT_ENABLED = true;
9
17
  const BRAND_TEXT = '豆包 AI 生成';
10
18
  const POWERED_BY_TEXT = '由飞书妙搭提供支持';
11
19
  const FONT_FAMILY = "'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif";
12
20
  const PILL_SHADOW = '0px 8px 32px rgba(0,0,0,0.08), 0px 4px 16px rgba(0,0,0,0.04), 0px 2px 4px rgba(0,0,0,0.02)';
13
21
  const CARD_SHADOW = '0px 4px 16px rgba(0,0,0,0.03), 0px 4px 10px rgba(0,0,0,0.03), 0px 2px 4px rgba(0,0,0,0.02)';
14
- const reportDomainByEnv = (env)=>{
15
- if ('boe' === env) return 'tns.feishu-boe.cn';
16
- if ('pre' === env) return 'tns.feishu-pre.cn';
17
- return 'tns.feishu.cn';
22
+ const REPORT_DOMAIN = {
23
+ BOE: 'tns.feishu-boe.cn',
24
+ PRE: 'tns.feishu-pre.cn',
25
+ ONLINE: 'tns.feishu.cn'
18
26
  };
19
27
  const openDoubaoReport = ()=>{
28
+ const appId = getAppId();
29
+ if (!appId) return;
20
30
  const params = JSON.stringify({
21
31
  scene: 'miaoda_app_report',
22
- entity_id: getAppId() ?? '',
32
+ entity_id: appId,
23
33
  entity_type: 'miaoda_app',
24
34
  extra: ''
25
35
  });
26
- const domain = reportDomainByEnv(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
36
+ const domain = REPORT_DOMAIN[getEnv()] ?? REPORT_DOMAIN.ONLINE;
27
37
  const url = `https://${domain}/cust/lark_report/?type=common&params=${encodeURIComponent(params)}&lang=zh-CN`;
28
38
  window.open(url, '_blank', 'noopener,noreferrer');
29
39
  };
@@ -303,7 +313,7 @@ const Watermark_Watermark = ()=>{
303
313
  const [open, setOpen] = useState(false);
304
314
  const timer = useRef(null);
305
315
  const isMobile = useIsMobile();
306
- if (String(process.env.MIAODA_APP_SOURCE) !== DOUBAO_SOURCE) return null;
316
+ if (!isDoubaoSource()) return null;
307
317
  if (closed) return null;
308
318
  if (isMobile) return /*#__PURE__*/ jsx(MobileWatermark, {
309
319
  onDontShow: ()=>setClosed(true)
@@ -351,4 +361,4 @@ const Watermark_Watermark = ()=>{
351
361
  });
352
362
  };
353
363
  const Watermark = Watermark_Watermark;
354
- export { Avatar, CloseIcon, FeedbackIcon, MenuCard, MenuRow, Pill, Watermark as default, openDoubaoReport };
364
+ export { Avatar, CloseIcon, FeedbackIcon, MenuCard, MenuRow, Pill, Watermark as default, isDoubaoSource, openDoubaoReport };
@@ -11,6 +11,8 @@ const setViewportWidth = (w)=>Object.defineProperty(window, 'innerWidth', {
11
11
  afterEach(()=>{
12
12
  vi.unstubAllEnvs();
13
13
  vi.restoreAllMocks();
14
+ delete globalThis.ENVIRONMENT;
15
+ delete window.appId;
14
16
  setViewportWidth(1024);
15
17
  });
16
18
  describe('Watermark(豆包来源水印)', ()=>{
@@ -96,10 +98,10 @@ describe('Watermark(豆包来源水印)', ()=>{
96
98
  });
97
99
  });
98
100
  describe('openDoubaoReport(举报跳转,后端就绪后启用)', ()=>{
99
- it('按当前环境拼出飞书风控举报中心(tns) URL 并以新窗口打开', ()=>{
101
+ it('按当前环境(getEnv)拼出飞书风控举报中心(tns) URL 并以新窗口打开', ()=>{
100
102
  const openSpy = vi.spyOn(window, 'open').mockReturnValue(null);
101
103
  window.appId = 'app_abc';
102
- vi.stubEnv('FORCE_FRAMEWORK_ENVIRONMENT', 'boe');
104
+ globalThis.ENVIRONMENT = 'staging';
103
105
  openDoubaoReport();
104
106
  expect(openSpy).toHaveBeenCalledTimes(1);
105
107
  const [url, target, features] = openSpy.mock.calls[0];
@@ -109,5 +111,11 @@ describe('Watermark(豆包来源水印)', ()=>{
109
111
  expect(target).toBe('_blank');
110
112
  expect(features).toBe('noopener,noreferrer');
111
113
  });
114
+ it('无 appId 时不跳转(避免带空 entity_id 打开举报中心)', ()=>{
115
+ const openSpy = vi.spyOn(window, 'open').mockReturnValue(null);
116
+ globalThis.ENVIRONMENT = 'online';
117
+ openDoubaoReport();
118
+ expect(openSpy).not.toHaveBeenCalled();
119
+ });
112
120
  });
113
121
  });
@@ -11,13 +11,13 @@ import { SafetyErrorBoundary } from "./safety-error-boundary.js";
11
11
  import { useAppInfo } from "../../hooks/index.js";
12
12
  import { TrackKey } from "../../types/tea.js";
13
13
  import { slardar } from "@lark-apaas/internal-slardar";
14
+ import Watermark, { isDoubaoSource } from "./Watermark.js";
14
15
  import { getAppId } from "../../utils/getAppId.js";
15
16
  import { isNewPathEnabled } from "../../utils/apiPath.js";
16
17
  import QueryProvider from "../QueryProvider/index.js";
17
18
  import { AuthProvider } from "@lark-apaas/auth-sdk";
18
19
  import "../../runtime/index.js";
19
20
  const Safety = /*#__PURE__*/ react.lazy(()=>import("./safety.js"));
20
- const Watermark = /*#__PURE__*/ react.lazy(()=>import("./Watermark.js"));
21
21
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
22
22
  const readAllCssVarColors = ()=>{
23
23
  try {
@@ -196,13 +196,12 @@ const AppContainer_AppContainer = (props)=>{
196
196
  itemInputBg: cssColors.background,
197
197
  itemLinkBg: cssColors.background
198
198
  };
199
- const isDoubaoSource = '5' === String(process.env.MIAODA_APP_SOURCE);
200
199
  return /*#__PURE__*/ jsxs(Fragment, {
201
200
  children: [
202
201
  /*#__PURE__*/ jsx(SafetyErrorBoundary, {
203
- children: /*#__PURE__*/ jsx(Suspense, {
202
+ children: isDoubaoSource() ? /*#__PURE__*/ jsx(Watermark, {}) : /*#__PURE__*/ jsx(Suspense, {
204
203
  fallback: null,
205
- children: isDoubaoSource ? /*#__PURE__*/ jsx(Watermark, {}) : /*#__PURE__*/ jsx(Safety, {})
204
+ children: /*#__PURE__*/ jsx(Safety, {})
206
205
  })
207
206
  }),
208
207
  /*#__PURE__*/ jsx(QueryProvider, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.53-alpha.1",
3
+ "version": "1.2.53-alpha.2",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [