@lark-apaas/client-toolkit 1.2.51-alpha.6 → 1.2.51-alpha.7
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.
- package/lib/components/AppContainer/safety.js +47 -0
- package/lib/integrations/dataloom.d.ts +1 -1
- package/lib/integrations/dataloom.js +11 -5
- package/lib/locales/messages.js +4 -0
- package/package.json +2 -2
- package/lib/integrations/__test__/dataloom.test.d.ts +0 -1
- package/lib/integrations/__test__/dataloom.test.js +0 -83
|
@@ -2,12 +2,29 @@ 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";
|
|
5
6
|
import { getCsrfToken } from "../../utils/getCsrfToken.js";
|
|
6
7
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
7
8
|
import { useIsMobile } from "../../hooks/index.js";
|
|
8
9
|
import { X } from "lucide-react";
|
|
9
10
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
10
11
|
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¶ms=${encodeURIComponent(params)}&lang=zh-CN`;
|
|
26
|
+
window.open(url, '_blank', 'noopener,noreferrer');
|
|
27
|
+
};
|
|
11
28
|
const Component = ()=>{
|
|
12
29
|
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
13
30
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
@@ -129,6 +146,21 @@ const Component = ()=>{
|
|
|
129
146
|
children: t('safety.ai.disclaimer')
|
|
130
147
|
})
|
|
131
148
|
]
|
|
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
|
+
]
|
|
132
164
|
})
|
|
133
165
|
]
|
|
134
166
|
}),
|
|
@@ -248,6 +280,21 @@ const Component = ()=>{
|
|
|
248
280
|
children: t('safety.ai.disclaimer')
|
|
249
281
|
})
|
|
250
282
|
]
|
|
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
|
+
]
|
|
251
298
|
})
|
|
252
299
|
]
|
|
253
300
|
}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const createDataLoomClient: () => import("@lark-apaas/dataloom").DataloomClient;
|
|
1
|
+
declare const createDataLoomClient: (url?: string, pat?: string) => import("@lark-apaas/dataloom").DataloomClient;
|
|
2
2
|
/** 获取dataloom实例 */
|
|
3
3
|
export declare function getDataloom(): Promise<ReturnType<typeof createDataLoomClient>>;
|
|
4
4
|
export {};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { splitWorkspaceUrl } from "../utils/url.js";
|
|
1
2
|
import { createClient } from "@lark-apaas/dataloom";
|
|
2
3
|
import { authClient } from "@lark-apaas/auth-sdk";
|
|
3
4
|
import { getAppId } from "../utils/getAppId.js";
|
|
4
|
-
import {
|
|
5
|
-
const createDataLoomClient = ()=>{
|
|
5
|
+
import { getAppPublished } from "../utils/getInitialInfo.js";
|
|
6
|
+
const createDataLoomClient = (url, pat)=>{
|
|
7
|
+
const { baseUrl } = url ? splitWorkspaceUrl(url) : {
|
|
8
|
+
baseUrl: ''
|
|
9
|
+
};
|
|
6
10
|
const appId = getAppId();
|
|
7
|
-
return createClient({
|
|
11
|
+
return createClient(baseUrl, pat, {
|
|
8
12
|
global: {
|
|
9
13
|
enableDataloomLog: 'production' !== process.env.NODE_ENV,
|
|
10
14
|
requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
|
|
@@ -22,8 +26,10 @@ let pendingPromise = null;
|
|
|
22
26
|
function getDataloom() {
|
|
23
27
|
if (dataloom) return Promise.resolve(dataloom);
|
|
24
28
|
if (pendingPromise) return pendingPromise;
|
|
25
|
-
pendingPromise =
|
|
26
|
-
|
|
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);
|
|
27
33
|
return dataloom;
|
|
28
34
|
}).finally(()=>{
|
|
29
35
|
pendingPromise = null;
|
package/lib/locales/messages.js
CHANGED
|
@@ -23,6 +23,10 @@ const messages_messages = {
|
|
|
23
23
|
zh: '了解更多',
|
|
24
24
|
en: 'Learn more'
|
|
25
25
|
},
|
|
26
|
+
'safety.report': {
|
|
27
|
+
zh: '投诉与举报',
|
|
28
|
+
en: 'Report'
|
|
29
|
+
},
|
|
26
30
|
'safety.cover.pc': {
|
|
27
31
|
zh: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover.png',
|
|
28
32
|
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.
|
|
3
|
+
"version": "1.2.51-alpha.7",
|
|
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.
|
|
104
|
+
"@lark-apaas/dataloom": "^0.1.3",
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
});
|