@lark-apaas/client-toolkit 1.2.55 → 1.2.56-alpha.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.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.55",
3
+ "version": "1.2.56-alpha.1",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -100,12 +100,12 @@
100
100
  "@ant-design/colors": "^7.2.1",
101
101
  "@ant-design/cssinjs": "^1.24.0",
102
102
  "@lark-apaas/aily-web-sdk": "^0.0.11",
103
- "@lark-apaas/auth-sdk": "^0.1.7",
103
+ "@lark-apaas/auth-sdk": "^0.1.5",
104
104
  "@lark-apaas/client-capability": "^0.1.7",
105
- "@lark-apaas/dataloom": "^0.1.3",
105
+ "@lark-apaas/dataloom": "0.1.4-alpha.11",
106
106
  "@lark-apaas/internal-slardar": "^0.0.3",
107
107
  "@lark-apaas/miaoda-inspector": "^1.0.23",
108
- "@lark-apaas/observable-web": "^1.0.8",
108
+ "@lark-apaas/observable-web": "^1.0.6",
109
109
  "@radix-ui/react-avatar": "^1.1.10",
110
110
  "@radix-ui/react-popover": "^1.1.15",
111
111
  "@radix-ui/react-slot": "^1.2.3",