@lark-apaas/client-toolkit 1.2.19 → 1.2.21
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 { resolveAppUrl } from '../../utils/resolveAppUrl';
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
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
|
+
}
|
|
1
17
|
function getLegacyParentOrigin() {
|
|
2
18
|
const { origin } = window.location;
|
|
3
19
|
if (origin.includes('force.feishuapp.net')) return 'https://force.feishu.cn';
|
|
@@ -8,6 +24,8 @@ function getLegacyParentOrigin() {
|
|
|
8
24
|
return 'https://miaoda.feishu-boe.cn';
|
|
9
25
|
}
|
|
10
26
|
function resolveParentOrigin() {
|
|
27
|
+
const paramOrigin = getParentOriginFromParams();
|
|
28
|
+
if (paramOrigin) return paramOrigin;
|
|
11
29
|
return process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN ?? getLegacyParentOrigin();
|
|
12
30
|
}
|
|
13
31
|
function submitPostMessage(message, targetOrigin) {
|
|
@@ -0,0 +1,27 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 };
|
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.21",
|
|
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": "^0.0.
|
|
102
|
+
"@lark-apaas/aily-web-sdk": "^0.0.5",
|
|
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.20",
|
|
106
|
+
"@lark-apaas/observable-web": "^1.0.3",
|
|
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",
|