@lark-apaas/client-toolkit 1.2.51-alpha.4 → 1.2.51-alpha.6

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.
@@ -2,29 +2,12 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
4
4
  import { getAppId } from "../../utils/getAppId.js";
5
- import { getEnv } from "../../utils/getParentOrigin.js";
6
5
  import { getCsrfToken } from "../../utils/getCsrfToken.js";
7
6
  import { isNewPathEnabled } from "../../utils/apiPath.js";
8
7
  import { useIsMobile } from "../../hooks/index.js";
9
8
  import { X } from "lucide-react";
10
9
  import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
11
10
  import { t } from "../../locales/index.js";
12
- const ICON_FEEDBACK_URL = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/miaoda-ui/icon_feedback_outlined.png';
13
- const REPORT_DOMAIN = {
14
- BOE: 'tns.feishu-boe.cn',
15
- PRE: 'tns.feishu-pre.cn',
16
- ONLINE: 'tns.feishu.cn'
17
- };
18
- const openReport = ()=>{
19
- const params = JSON.stringify({
20
- scene: 'miaoda_app_report',
21
- entity_id: getAppId() ?? '',
22
- entity_type: 'miaoda_app',
23
- extra: ''
24
- });
25
- const url = `https://${REPORT_DOMAIN[getEnv()]}/cust/lark_report/?type=common&params=${encodeURIComponent(params)}&lang=zh-CN`;
26
- window.open(url, '_blank', 'noopener,noreferrer');
27
- };
28
11
  const Component = ()=>{
29
12
  const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
30
13
  const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
@@ -146,21 +129,6 @@ const Component = ()=>{
146
129
  children: t('safety.ai.disclaimer')
147
130
  })
148
131
  ]
149
- }),
150
- /*#__PURE__*/ jsxs("div", {
151
- className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
152
- "data-custom-element": "safety-report",
153
- onClick: openReport,
154
- children: [
155
- /*#__PURE__*/ jsx("img", {
156
- src: ICON_FEEDBACK_URL,
157
- className: "shrink-0 w-[14px] h-[14px]"
158
- }),
159
- /*#__PURE__*/ jsx("p", {
160
- className: "shrink-0 m-0! text-[#646A73] text-sm underline underline-offset-2",
161
- children: t('safety.report')
162
- })
163
- ]
164
132
  })
165
133
  ]
166
134
  }),
@@ -280,21 +248,6 @@ const Component = ()=>{
280
248
  children: t('safety.ai.disclaimer')
281
249
  })
282
250
  ]
283
- }),
284
- /*#__PURE__*/ jsxs("div", {
285
- className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
286
- "data-custom-element": "safety-report",
287
- onClick: openReport,
288
- children: [
289
- /*#__PURE__*/ jsx("img", {
290
- src: ICON_FEEDBACK_URL,
291
- className: "shrink-0 w-[12px] h-[12px]"
292
- }),
293
- /*#__PURE__*/ jsx("p", {
294
- className: "shrink-0 m-0! text-[#a6a6a6] underline underline-offset-2",
295
- children: t('safety.report')
296
- })
297
- ]
298
251
  })
299
252
  ]
300
253
  }),
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,83 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { getDataloom } from "../dataloom.js";
3
+ const { getInitialInfoMock, getAppPublishedMock, getAppIdMock, createClientMock, authUserMock, authSessionMock } = vi.hoisted(()=>({
4
+ getInitialInfoMock: vi.fn(),
5
+ getAppPublishedMock: vi.fn(),
6
+ getAppIdMock: vi.fn(),
7
+ createClientMock: vi.fn(),
8
+ authUserMock: {},
9
+ authSessionMock: {}
10
+ }));
11
+ vi.mock('../../utils/getInitialInfo', ()=>({
12
+ getInitialInfo: getInitialInfoMock,
13
+ getAppPublished: getAppPublishedMock
14
+ }));
15
+ vi.mock('../../utils/getAppId', ()=>({
16
+ getAppId: getAppIdMock
17
+ }));
18
+ vi.mock('@lark-apaas/dataloom', ()=>({
19
+ createClient: createClientMock
20
+ }));
21
+ vi.mock('@lark-apaas/auth-sdk', ()=>({
22
+ authClient: {
23
+ user: authUserMock,
24
+ session: authSessionMock
25
+ }
26
+ }));
27
+ beforeEach(()=>{
28
+ getInitialInfoMock.mockReset();
29
+ getAppPublishedMock.mockReset();
30
+ getAppIdMock.mockReset();
31
+ createClientMock.mockReset();
32
+ });
33
+ afterEach(()=>{
34
+ vi.restoreAllMocks();
35
+ });
36
+ describe('getDataloom', ()=>{
37
+ it('返回-createClient实例-改用getInitialInfo-新签名不取token/url-appId注入-并发去重-缓存复用', async ()=>{
38
+ getAppIdMock.mockReturnValue('app-1');
39
+ getInitialInfoMock.mockResolvedValue({
40
+ app_runtime_extra: {
41
+ token: 'pat',
42
+ url: 'https://x'
43
+ }
44
+ });
45
+ const client = {
46
+ __id: 'client-1'
47
+ };
48
+ createClientMock.mockReturnValue(client);
49
+ const p1 = getDataloom();
50
+ const p2 = getDataloom();
51
+ expect(p1).toBe(p2);
52
+ const [c1, c2] = await Promise.all([
53
+ p1,
54
+ p2
55
+ ]);
56
+ expect(c1).toBe(client);
57
+ expect(c2).toBe(client);
58
+ expect(getInitialInfoMock).toHaveBeenCalledTimes(1);
59
+ expect(getAppPublishedMock).not.toHaveBeenCalled();
60
+ expect(createClientMock).toHaveBeenCalledTimes(1);
61
+ const args = createClientMock.mock.calls[0];
62
+ expect(args).toHaveLength(1);
63
+ const options = args[0];
64
+ expect(typeof options).toBe('object');
65
+ expect(options).not.toBe('https://x');
66
+ expect(options).not.toBe('pat');
67
+ expect(options.global).toBeDefined();
68
+ expect(options.global).not.toHaveProperty('url');
69
+ expect(options.global).not.toHaveProperty('key');
70
+ expect(options.global?.appId).toBe('app-1');
71
+ expect(options.global?.accountServices).toEqual({
72
+ user: authUserMock,
73
+ session: authSessionMock
74
+ });
75
+ const cached1 = await getDataloom();
76
+ const cached2 = await getDataloom();
77
+ expect(cached1).toBe(client);
78
+ expect(cached2).toBe(client);
79
+ expect(cached1).toBe(cached2);
80
+ expect(getInitialInfoMock).toHaveBeenCalledTimes(1);
81
+ expect(createClientMock).toHaveBeenCalledTimes(1);
82
+ });
83
+ });
@@ -1,4 +1,4 @@
1
- declare const createDataLoomClient: (url?: string, pat?: string) => import("@lark-apaas/dataloom").DataloomClient;
1
+ declare const createDataLoomClient: () => import("@lark-apaas/dataloom").DataloomClient;
2
2
  /** 获取dataloom实例 */
3
3
  export declare function getDataloom(): Promise<ReturnType<typeof createDataLoomClient>>;
4
4
  export {};
@@ -1,14 +1,10 @@
1
- import { splitWorkspaceUrl } from "../utils/url.js";
2
1
  import { createClient } from "@lark-apaas/dataloom";
3
2
  import { authClient } from "@lark-apaas/auth-sdk";
4
3
  import { getAppId } from "../utils/getAppId.js";
5
- import { getAppPublished } from "../utils/getInitialInfo.js";
6
- const createDataLoomClient = (url, pat)=>{
7
- const { baseUrl } = url ? splitWorkspaceUrl(url) : {
8
- baseUrl: ''
9
- };
4
+ import { getInitialInfo } from "../utils/getInitialInfo.js";
5
+ const createDataLoomClient = ()=>{
10
6
  const appId = getAppId();
11
- return createClient(baseUrl, pat, {
7
+ return createClient({
12
8
  global: {
13
9
  enableDataloomLog: 'production' !== process.env.NODE_ENV,
14
10
  requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
@@ -26,10 +22,8 @@ let pendingPromise = null;
26
22
  function getDataloom() {
27
23
  if (dataloom) return Promise.resolve(dataloom);
28
24
  if (pendingPromise) return pendingPromise;
29
- pendingPromise = getAppPublished().then((info)=>{
30
- const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
31
- const DATALOOM_PAT = info?.app_runtime_extra?.token;
32
- dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
25
+ pendingPromise = getInitialInfo().then(()=>{
26
+ dataloom = createDataLoomClient();
33
27
  return dataloom;
34
28
  }).finally(()=>{
35
29
  pendingPromise = null;
@@ -23,10 +23,6 @@ const messages_messages = {
23
23
  zh: '了解更多',
24
24
  en: 'Learn more'
25
25
  },
26
- 'safety.report': {
27
- zh: '投诉与举报',
28
- en: 'Report'
29
- },
30
26
  'safety.cover.pc': {
31
27
  zh: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover.png',
32
28
  en: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover-weben.png'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.51-alpha.4",
3
+ "version": "1.2.51-alpha.6",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -101,7 +101,7 @@
101
101
  "@lark-apaas/aily-web-sdk": "^0.0.11",
102
102
  "@lark-apaas/auth-sdk": "^0.1.5",
103
103
  "@lark-apaas/client-capability": "^0.1.7",
104
- "@lark-apaas/dataloom": "^0.1.3",
104
+ "@lark-apaas/dataloom": "0.1.4-alpha.0",
105
105
  "@lark-apaas/internal-slardar": "^0.0.3",
106
106
  "@lark-apaas/miaoda-inspector": "^1.0.23",
107
107
  "@lark-apaas/observable-web": "^1.0.6",