@lark-apaas/client-toolkit 1.2.20 → 1.2.22-alpha.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.
- package/lib/hooks/useCurrentUserProfile.js +22 -29
- package/lib/integrations/dataloom.d.ts +3 -1
- package/lib/integrations/dataloom.js +13 -7
- package/lib/utils/getInitialInfo.d.ts +4 -3
- package/lib/utils/getInitialInfo.js +12 -5
- package/lib/utils/postMessage.js +0 -18
- package/package.json +4 -4
- package/lib/apis/utils/resolveAppUrl.d.ts +0 -1
- package/lib/apis/utils/resolveAppUrl.js +0 -2
- package/lib/utils/resolveAppUrl.d.ts +0 -27
- package/lib/utils/resolveAppUrl.js +0 -19
|
@@ -19,37 +19,29 @@ function getCompatibilityUserProfile() {
|
|
|
19
19
|
const useCurrentUserProfile = ()=>{
|
|
20
20
|
const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
|
|
21
21
|
useEffect(()=>{
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
const fetchAndSetUserInfo = async ()=>{
|
|
24
|
+
const dataloom = await getDataloom();
|
|
25
|
+
const result = await dataloom?.service?.session?.getUserInfo();
|
|
26
|
+
if (cancelled) return;
|
|
27
|
+
const info = result?.data?.user_info;
|
|
28
|
+
const userName = getNameFromArray(info?.name);
|
|
29
|
+
const newUserInfo = {
|
|
30
|
+
user_id: info?.user_id?.toString(),
|
|
31
|
+
email: info?.email,
|
|
32
|
+
name: userName,
|
|
33
|
+
avatar: info?.avatar?.image?.large,
|
|
34
|
+
userName: userName,
|
|
35
|
+
userAvatar: info?.avatar?.image?.large
|
|
36
|
+
};
|
|
37
|
+
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', newUserInfo);
|
|
38
|
+
setUserInfo(newUserInfo);
|
|
39
|
+
};
|
|
22
40
|
let handleMetaInfoChanged;
|
|
23
41
|
if (isSparkRuntime()) {
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const userInfo = result?.data?.user_info;
|
|
28
|
-
const userName = getNameFromArray(userInfo?.name);
|
|
29
|
-
setUserInfo({
|
|
30
|
-
user_id: userInfo?.user_id?.toString(),
|
|
31
|
-
email: userInfo?.email,
|
|
32
|
-
name: userName,
|
|
33
|
-
avatar: userInfo?.avatar?.image?.large,
|
|
34
|
-
userName: userName,
|
|
35
|
-
userAvatar: userInfo?.avatar?.image?.large
|
|
36
|
-
});
|
|
37
|
-
})();
|
|
38
|
-
handleMetaInfoChanged = async ()=>{
|
|
39
|
-
const dataloom = await getDataloom();
|
|
40
|
-
const result = await dataloom?.service?.session?.getUserInfo();
|
|
41
|
-
const userInfo = result?.data?.user_info;
|
|
42
|
-
const userName = getNameFromArray(userInfo?.name);
|
|
43
|
-
const newUserInfo = {
|
|
44
|
-
user_id: userInfo?.user_id?.toString(),
|
|
45
|
-
email: userInfo?.email,
|
|
46
|
-
name: userName,
|
|
47
|
-
avatar: userInfo?.avatar?.image?.large,
|
|
48
|
-
userName: userName,
|
|
49
|
-
userAvatar: userInfo?.avatar?.image?.large
|
|
50
|
-
};
|
|
51
|
-
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', newUserInfo);
|
|
52
|
-
setUserInfo(newUserInfo);
|
|
42
|
+
fetchAndSetUserInfo();
|
|
43
|
+
handleMetaInfoChanged = ()=>{
|
|
44
|
+
fetchAndSetUserInfo();
|
|
53
45
|
};
|
|
54
46
|
} else handleMetaInfoChanged = ()=>{
|
|
55
47
|
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', getCompatibilityUserProfile());
|
|
@@ -57,6 +49,7 @@ const useCurrentUserProfile = ()=>{
|
|
|
57
49
|
};
|
|
58
50
|
window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
59
51
|
return ()=>{
|
|
52
|
+
cancelled = true;
|
|
60
53
|
window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
61
54
|
};
|
|
62
55
|
}, []);
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
declare const createDataLoomClient: (url?: string, pat?: string) => import("@data-loom/js").DataloomClient<any, "public", any>;
|
|
1
2
|
/** 获取dataloom实例 */
|
|
2
|
-
export declare function getDataloom(): Promise<
|
|
3
|
+
export declare function getDataloom(): Promise<ReturnType<typeof createDataLoomClient>>;
|
|
4
|
+
export {};
|
|
@@ -23,12 +23,18 @@ const createDataLoomClient = (url, pat)=>{
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
let dataloom = null;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
let pendingPromise = null;
|
|
27
|
+
function getDataloom() {
|
|
28
|
+
if (dataloom) return Promise.resolve(dataloom);
|
|
29
|
+
if (pendingPromise) return pendingPromise;
|
|
30
|
+
pendingPromise = getInitialInfo().then((info)=>{
|
|
31
|
+
const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
|
|
32
|
+
const DATALOOM_PAT = info?.app_runtime_extra?.token;
|
|
33
|
+
dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
|
|
34
|
+
return dataloom;
|
|
35
|
+
}).finally(()=>{
|
|
36
|
+
pendingPromise = null;
|
|
37
|
+
});
|
|
38
|
+
return pendingPromise;
|
|
33
39
|
}
|
|
34
40
|
export { getDataloom };
|
|
@@ -13,9 +13,10 @@ interface AppRuntimePublished {
|
|
|
13
13
|
interface BucketConfig {
|
|
14
14
|
default_bucket_id?: string;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
export declare function getInitialInfo(refresh?: boolean): Promise<{
|
|
16
|
+
declare let initialInfo: {
|
|
18
17
|
app_info?: AppRuntimePublished;
|
|
19
18
|
app_runtime_extra?: AppRuntimeExtra;
|
|
20
|
-
}
|
|
19
|
+
} | undefined;
|
|
20
|
+
/** 获取应用初始化信息(仅全栈沙箱模式下使用) */
|
|
21
|
+
export declare function getInitialInfo(refresh?: boolean): Promise<typeof initialInfo>;
|
|
21
22
|
export {};
|
|
@@ -23,10 +23,17 @@ async function getAppPublished() {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
let initialInfo;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
initialInfo
|
|
29
|
-
if (
|
|
30
|
-
|
|
26
|
+
let pendingPromise = null;
|
|
27
|
+
function getInitialInfo(refresh = false) {
|
|
28
|
+
if (initialInfo && !refresh) return Promise.resolve(initialInfo);
|
|
29
|
+
if (pendingPromise && !refresh) return pendingPromise;
|
|
30
|
+
pendingPromise = getAppPublished().then((info)=>{
|
|
31
|
+
initialInfo = info;
|
|
32
|
+
if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
|
|
33
|
+
return initialInfo;
|
|
34
|
+
}).finally(()=>{
|
|
35
|
+
pendingPromise = null;
|
|
36
|
+
});
|
|
37
|
+
return pendingPromise;
|
|
31
38
|
}
|
|
32
39
|
export { getInitialInfo };
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
const PARENT_ORIGIN_KEY = '__parentOrigin';
|
|
2
|
-
function getParentOriginFromParams() {
|
|
3
|
-
try {
|
|
4
|
-
const params = new URLSearchParams(window.location.search);
|
|
5
|
-
const origin = params.get(PARENT_ORIGIN_KEY);
|
|
6
|
-
if (origin) {
|
|
7
|
-
sessionStorage.setItem(PARENT_ORIGIN_KEY, origin);
|
|
8
|
-
return origin;
|
|
9
|
-
}
|
|
10
|
-
} catch {}
|
|
11
|
-
try {
|
|
12
|
-
return sessionStorage.getItem(PARENT_ORIGIN_KEY) || void 0;
|
|
13
|
-
} catch {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
1
|
function getLegacyParentOrigin() {
|
|
18
2
|
const { origin } = window.location;
|
|
19
3
|
if (origin.includes('force.feishuapp.net')) return 'https://force.feishu.cn';
|
|
@@ -24,8 +8,6 @@ function getLegacyParentOrigin() {
|
|
|
24
8
|
return 'https://miaoda.feishu-boe.cn';
|
|
25
9
|
}
|
|
26
10
|
function resolveParentOrigin() {
|
|
27
|
-
const paramOrigin = getParentOriginFromParams();
|
|
28
|
-
if (paramOrigin) return paramOrigin;
|
|
29
11
|
return process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN ?? getLegacyParentOrigin();
|
|
30
12
|
}
|
|
31
13
|
function submitPostMessage(message, targetOrigin) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.22-alpha.0",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -99,11 +99,11 @@
|
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
101
|
"@data-loom/js": "0.4.7",
|
|
102
|
-
"@lark-apaas/aily-web-sdk": "
|
|
102
|
+
"@lark-apaas/aily-web-sdk": ">=0.0.1",
|
|
103
103
|
"@lark-apaas/auth-sdk": "^0.1.0",
|
|
104
104
|
"@lark-apaas/client-capability": "^0.1.4",
|
|
105
|
-
"@lark-apaas/miaoda-inspector": "^1.0.
|
|
106
|
-
"@lark-apaas/observable-web": "^1.0.
|
|
105
|
+
"@lark-apaas/miaoda-inspector": "^1.0.16",
|
|
106
|
+
"@lark-apaas/observable-web": "^1.0.1",
|
|
107
107
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
108
108
|
"@radix-ui/react-popover": "^1.1.15",
|
|
109
109
|
"@radix-ui/react-slot": "^1.2.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { resolveAppUrl } from '../../utils/resolveAppUrl';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 解析应用内路径,自动补全 CLIENT_BASE_PATH 前缀,返回完整 URL
|
|
3
|
-
* 适用于生成分享链接、二维码等需要完整 URL 的场景
|
|
4
|
-
*
|
|
5
|
-
* - 相对路径:补全前缀 + 当前域名
|
|
6
|
-
* - 当前域名的完整 URL:修正路径部分,补全前缀
|
|
7
|
-
* - 其他域名的 URL:原样返回,不做处理
|
|
8
|
-
*
|
|
9
|
-
* @param path - 应用内相对路径或完整 URL
|
|
10
|
-
* @returns 完整的 URL 字符串
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* // 假设 CLIENT_BASE_PATH = '/app/abc',当前域名为 https://example.com
|
|
14
|
-
*
|
|
15
|
-
* resolveAppUrl('/detail/123')
|
|
16
|
-
* // => 'https://example.com/app/abc/detail/123'
|
|
17
|
-
*
|
|
18
|
-
* resolveAppUrl('https://example.com/detail/123')
|
|
19
|
-
* // => 'https://example.com/app/abc/detail/123'
|
|
20
|
-
*
|
|
21
|
-
* resolveAppUrl('https://example.com/app/abc/detail/123')
|
|
22
|
-
* // => 'https://example.com/app/abc/detail/123' (已有前缀,不重复添加)
|
|
23
|
-
*
|
|
24
|
-
* resolveAppUrl('https://other-site.com/page')
|
|
25
|
-
* // => 'https://other-site.com/page' (非当前域名,原样返回)
|
|
26
|
-
*/
|
|
27
|
-
export declare function resolveAppUrl(path: string): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { normalizeBasePath } from "./utils.js";
|
|
2
|
-
function ensureBasePath(pathname, basePath) {
|
|
3
|
-
if (!basePath) return pathname;
|
|
4
|
-
if (pathname.startsWith(basePath)) return pathname;
|
|
5
|
-
return `${basePath}${pathname.startsWith('/') ? '' : '/'}${pathname}`;
|
|
6
|
-
}
|
|
7
|
-
function resolveAppUrl(path) {
|
|
8
|
-
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
9
|
-
try {
|
|
10
|
-
const url = new URL(path);
|
|
11
|
-
if (url.origin !== window.location.origin) return path;
|
|
12
|
-
url.pathname = ensureBasePath(url.pathname, basePath);
|
|
13
|
-
return url.toString();
|
|
14
|
-
} catch {}
|
|
15
|
-
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
16
|
-
const resolvedPath = ensureBasePath(normalizedPath, basePath);
|
|
17
|
-
return `${window.location.origin}${resolvedPath}`;
|
|
18
|
-
}
|
|
19
|
-
export { resolveAppUrl };
|