@lark-apaas/client-toolkit 1.2.62-alpha.1 → 1.2.62-alpha.20260717075916
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/apis/components/UniversalLink.d.ts +0 -3
- package/lib/apis/components/UniversalLink.js +3 -42
- package/lib/components/AppContainer/index.js +4 -9
- package/lib/components/AppContainer/safety.js +0 -50
- package/lib/hooks/useCurrentUserProfile.js +1 -1
- package/lib/index.d.ts +0 -40
- package/lib/index.js +2 -32
- package/lib/integrations/dataloom.d.ts +1 -1
- package/lib/integrations/dataloom.js +11 -5
- package/lib/integrations/services/types.d.ts +0 -43
- package/lib/locales/messages.js +0 -4
- package/lib/runtime/index.js +2 -0
- package/lib/runtime/preview-run.d.ts +29 -0
- package/lib/runtime/preview-run.js +76 -0
- package/lib/runtime/preview-run.spec.js +94 -0
- package/lib/types/iframe-events.d.ts +1 -12
- package/lib/utils/postMessage.d.ts +0 -1
- package/lib/utils/postMessage.js +1 -1
- package/package.json +4 -5
- package/lib/components/AppContainer/Watermark.d.ts +0 -60
- package/lib/components/AppContainer/Watermark.js +0 -364
- package/lib/components/AppContainer/__test__/Watermark.test.js +0 -121
- package/lib/components/AppContainer/__test__/safety-error-boundary.test.d.ts +0 -1
- package/lib/components/AppContainer/__test__/safety-error-boundary.test.js +0 -53
- package/lib/components/AppContainer/doubao-watermark-asset.d.ts +0 -2
- package/lib/components/AppContainer/doubao-watermark-asset.js +0 -4
- package/lib/components/AppContainer/safety-error-boundary.d.ts +0 -23
- package/lib/components/AppContainer/safety-error-boundary.js +0 -29
- package/lib/integrations/__test__/dataloom.test.d.ts +0 -1
- package/lib/integrations/__test__/dataloom.test.js +0 -83
- /package/lib/{components/AppContainer/__test__/Watermark.test.d.ts → runtime/preview-run.spec.d.ts} +0 -0
|
@@ -8,8 +8,5 @@ export interface UniversalLinkProps extends Omit<React.AnchorHTMLAttributes<HTML
|
|
|
8
8
|
* - 内部路由(/dashboard)→ react-router Link
|
|
9
9
|
* - Hash 锚点(#section)→ <a>
|
|
10
10
|
* - 外链(https://...)→ <a target="_blank">
|
|
11
|
-
*
|
|
12
|
-
* 预览态(iframe 内)时,通过 postMessage 通知父页面处理链接跳转,
|
|
13
|
-
* 避免浏览器安全策略限制导致链接无法正常打开。
|
|
14
11
|
*/
|
|
15
12
|
export declare const UniversalLink: React.ForwardRefExoticComponent<UniversalLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -1,62 +1,23 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import react from "react";
|
|
3
3
|
import { Link } from "react-router-dom";
|
|
4
|
-
import { isPreview } from "../../utils/utils.js";
|
|
5
|
-
import { getParentOriginFromParams, submitPostMessage } from "../../utils/postMessage.js";
|
|
6
4
|
function isInternalRoute(to) {
|
|
7
5
|
return !to.startsWith('#') && !to.startsWith('http://') && !to.startsWith('https://') && !to.startsWith('//');
|
|
8
6
|
}
|
|
9
7
|
function isExternalLink(to) {
|
|
10
8
|
return to.startsWith('http://') || to.startsWith('https://') || to.startsWith('//');
|
|
11
9
|
}
|
|
12
|
-
function
|
|
13
|
-
if ('undefined' == typeof window) return false;
|
|
14
|
-
if (window.parent === window) return false;
|
|
15
|
-
if (getParentOriginFromParams()) return true;
|
|
16
|
-
const envOrigin = process.env.FORCE_FRAMEWORK_DOMAIN_MAIN;
|
|
17
|
-
if (!envOrigin || !document.referrer) return false;
|
|
18
|
-
try {
|
|
19
|
-
return new URL(document.referrer).origin === envOrigin;
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const UniversalLink_UniversalLink = /*#__PURE__*/ react.forwardRef(function({ to, onClick, ...props }, ref) {
|
|
25
|
-
const isExternal = isExternalLink(to);
|
|
26
|
-
const preview = (isPreview() || isIframeUnderMainHost()) && isExternal;
|
|
27
|
-
if (preview) {
|
|
28
|
-
const handlePreviewClick = (e)=>{
|
|
29
|
-
e.preventDefault();
|
|
30
|
-
onClick?.(e);
|
|
31
|
-
submitPostMessage({
|
|
32
|
-
type: 'OpenIframeLink',
|
|
33
|
-
data: {
|
|
34
|
-
href: to,
|
|
35
|
-
external: true
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
return /*#__PURE__*/ jsx("a", {
|
|
40
|
-
href: to,
|
|
41
|
-
ref: ref,
|
|
42
|
-
...props,
|
|
43
|
-
onClick: handlePreviewClick,
|
|
44
|
-
target: props.target ?? '_blank',
|
|
45
|
-
rel: props.rel ?? 'noopener noreferrer'
|
|
46
|
-
});
|
|
47
|
-
}
|
|
10
|
+
const UniversalLink_UniversalLink = /*#__PURE__*/ react.forwardRef(function({ to, ...props }, ref) {
|
|
48
11
|
if (isInternalRoute(to)) return /*#__PURE__*/ jsx(Link, {
|
|
49
12
|
to: to,
|
|
50
13
|
ref: ref,
|
|
51
|
-
...props
|
|
52
|
-
onClick: onClick
|
|
14
|
+
...props
|
|
53
15
|
});
|
|
54
16
|
return /*#__PURE__*/ jsx("a", {
|
|
55
17
|
href: to,
|
|
56
18
|
ref: ref,
|
|
57
19
|
...props,
|
|
58
|
-
|
|
59
|
-
...isExternal && {
|
|
20
|
+
...isExternalLink(to) && {
|
|
60
21
|
target: props.target ?? '_blank',
|
|
61
22
|
rel: props.rel ?? 'noopener noreferrer'
|
|
62
23
|
}
|
|
@@ -7,11 +7,9 @@ import IframeBridge from "./IframeBridge.js";
|
|
|
7
7
|
import { Toaster } from "./sonner.js";
|
|
8
8
|
import { PageHoc } from "./PageHoc.js";
|
|
9
9
|
import { reportTeaEvent } from "./utils/tea.js";
|
|
10
|
-
import { SafetyErrorBoundary } from "./safety-error-boundary.js";
|
|
11
10
|
import { useAppInfo } from "../../hooks/index.js";
|
|
12
11
|
import { TrackKey } from "../../types/tea.js";
|
|
13
12
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
14
|
-
import Watermark, { isDoubaoSource } from "./Watermark.js";
|
|
15
13
|
import { getAppId } from "../../utils/getAppId.js";
|
|
16
14
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
17
15
|
import QueryProvider from "../QueryProvider/index.js";
|
|
@@ -77,8 +75,7 @@ const App = (props)=>{
|
|
|
77
75
|
},
|
|
78
76
|
categories: {
|
|
79
77
|
appId: appId ?? 'unknown',
|
|
80
|
-
mode: isMiaodaPreview ? 'preview' : 'runtime'
|
|
81
|
-
appType: String(process.env.MIAODA_APP_TYPE ?? 'unknown')
|
|
78
|
+
mode: isMiaodaPreview ? 'preview' : 'runtime'
|
|
82
79
|
}
|
|
83
80
|
});
|
|
84
81
|
}
|
|
@@ -199,11 +196,9 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
199
196
|
};
|
|
200
197
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
201
198
|
children: [
|
|
202
|
-
/*#__PURE__*/ jsx(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
children: /*#__PURE__*/ jsx(Safety, {})
|
|
206
|
-
})
|
|
199
|
+
/*#__PURE__*/ jsx(Suspense, {
|
|
200
|
+
fallback: null,
|
|
201
|
+
children: /*#__PURE__*/ jsx(Safety, {})
|
|
207
202
|
}),
|
|
208
203
|
/*#__PURE__*/ jsx(QueryProvider, {
|
|
209
204
|
children: /*#__PURE__*/ jsx(ConfigProvider, {
|
|
@@ -2,32 +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 appId = getAppId();
|
|
20
|
-
if (!appId) return;
|
|
21
|
-
const params = JSON.stringify({
|
|
22
|
-
scene: 'miaoda_app_report',
|
|
23
|
-
entity_id: appId,
|
|
24
|
-
entity_type: 'miaoda_app',
|
|
25
|
-
extra: ''
|
|
26
|
-
});
|
|
27
|
-
const domain = REPORT_DOMAIN[getEnv()] ?? REPORT_DOMAIN.ONLINE;
|
|
28
|
-
const url = `https://${domain}/cust/lark_report/?type=common¶ms=${encodeURIComponent(params)}&lang=zh-CN`;
|
|
29
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
30
|
-
};
|
|
31
11
|
const Component = ()=>{
|
|
32
12
|
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
33
13
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
@@ -149,21 +129,6 @@ const Component = ()=>{
|
|
|
149
129
|
children: t('safety.ai.disclaimer')
|
|
150
130
|
})
|
|
151
131
|
]
|
|
152
|
-
}),
|
|
153
|
-
/*#__PURE__*/ jsxs("div", {
|
|
154
|
-
className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
|
|
155
|
-
"data-custom-element": "safety-report",
|
|
156
|
-
onClick: openReport,
|
|
157
|
-
children: [
|
|
158
|
-
/*#__PURE__*/ jsx("img", {
|
|
159
|
-
src: ICON_FEEDBACK_URL,
|
|
160
|
-
className: "shrink-0 w-[14px] h-[14px]"
|
|
161
|
-
}),
|
|
162
|
-
/*#__PURE__*/ jsx("p", {
|
|
163
|
-
className: "shrink-0 m-0! text-[#646A73] text-sm underline underline-offset-2",
|
|
164
|
-
children: t('safety.report')
|
|
165
|
-
})
|
|
166
|
-
]
|
|
167
132
|
})
|
|
168
133
|
]
|
|
169
134
|
}),
|
|
@@ -283,21 +248,6 @@ const Component = ()=>{
|
|
|
283
248
|
children: t('safety.ai.disclaimer')
|
|
284
249
|
})
|
|
285
250
|
]
|
|
286
|
-
}),
|
|
287
|
-
/*#__PURE__*/ jsxs("div", {
|
|
288
|
-
className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
|
|
289
|
-
"data-custom-element": "safety-report",
|
|
290
|
-
onClick: openReport,
|
|
291
|
-
children: [
|
|
292
|
-
/*#__PURE__*/ jsx("img", {
|
|
293
|
-
src: ICON_FEEDBACK_URL,
|
|
294
|
-
className: "shrink-0 w-[12px] h-[12px]"
|
|
295
|
-
}),
|
|
296
|
-
/*#__PURE__*/ jsx("p", {
|
|
297
|
-
className: "shrink-0 m-0! text-[#a6a6a6] underline underline-offset-2",
|
|
298
|
-
children: t('safety.report')
|
|
299
|
-
})
|
|
300
|
-
]
|
|
301
251
|
})
|
|
302
252
|
]
|
|
303
253
|
}),
|
package/lib/index.d.ts
CHANGED
|
@@ -1,46 +1,6 @@
|
|
|
1
|
-
import { getAppId } from './utils/getAppId';
|
|
2
|
-
import { logger } from './logger';
|
|
3
1
|
export declare const capabilityClient: import("@lark-apaas/client-capability").CapabilityClient;
|
|
4
2
|
export { showConfirm } from './components/ui/confirm';
|
|
5
3
|
export type { ConfirmOptions } from './components/ui/confirm';
|
|
6
|
-
export { default as AppContainer } from './components/AppContainer';
|
|
7
|
-
export { default as QueryProvider } from './components/QueryProvider';
|
|
8
|
-
export { default as PagePlaceholder } from './components/PagePlaceholder';
|
|
9
|
-
export { default as Welcome } from './components/PagePlaceholder';
|
|
10
|
-
export { default as ErrorRender } from './components/ErrorRender';
|
|
11
|
-
export { ActiveLink } from './apis/components/ActiveLink';
|
|
12
|
-
export { NavLink } from './apis/components/NavLink';
|
|
13
|
-
export { UniversalLink } from './apis/components/UniversalLink';
|
|
14
|
-
export { useAppInfo } from './hooks/useAppInfo';
|
|
15
|
-
export { useCurrentUserProfile } from './hooks/useCurrentUserProfile';
|
|
16
|
-
export { useIsMobile } from './hooks/useIsMobile';
|
|
17
|
-
export { useLogout } from './hooks/useLogout';
|
|
18
|
-
export { clsxWithTw, isPreview, normalizeBasePath, getWsPath } from './utils/utils';
|
|
19
|
-
export { getCsrfToken } from './utils/getCsrfToken';
|
|
20
|
-
export { scopedStorage } from './utils/scopedStorage';
|
|
21
|
-
export { copyToClipboard } from './utils/copyToClipboard';
|
|
22
|
-
export { isIpad, isMobile, isIOS } from './utils/deviceType';
|
|
23
|
-
export { resolveAppUrl } from './utils/resolveAppUrl';
|
|
24
|
-
export { getEnvPath } from './utils/getEnvPath';
|
|
25
|
-
export { safeStringify } from './utils/safeStringify';
|
|
26
|
-
export { getAxiosForBackend, axiosForBackend } from './utils/getAxiosForBackend';
|
|
27
|
-
export { initAxiosConfig } from './utils/axiosConfig';
|
|
28
|
-
export { getAppId };
|
|
29
|
-
export { getAppInfo } from './integrations/getAppInfo';
|
|
30
|
-
export { getCurrentUserProfile } from './integrations/getCurrentUserProfile';
|
|
31
|
-
export { getDataloom } from './integrations/dataloom';
|
|
32
|
-
export { logger };
|
|
33
|
-
export type { LogLevel, LogWithMeta } from './logger/log-types';
|
|
34
|
-
export { trace } from './trace';
|
|
35
|
-
export { initObservable } from './runtime/observable';
|
|
36
|
-
export type { AppInfoPayload } from './types/common';
|
|
37
|
-
export type { IUserProfile, IJson, IFileAttachment } from './apis/udt-types';
|
|
38
|
-
export type { TrackParams } from './types/tea';
|
|
39
|
-
export { TrackKey } from './types/tea';
|
|
40
|
-
export { reportTeaEvent } from './components/AppContainer/utils/tea';
|
|
41
|
-
export * as avatarImages from './apis/constants/img-resources/avatar';
|
|
42
|
-
export * as bannerImages from './apis/constants/img-resources/banner';
|
|
43
|
-
export * as coverImages from './apis/constants/img-resources/cover';
|
|
44
4
|
declare const _default: {
|
|
45
5
|
version: string;
|
|
46
6
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClient } from "@lark-apaas/client-capability";
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeBasePath } from "./utils/utils.js";
|
|
3
3
|
import { getAppId } from "./utils/getAppId.js";
|
|
4
4
|
import { isNewPathEnabled } from "./utils/apiPath.js";
|
|
5
5
|
import { logger } from "./logger/index.js";
|
|
@@ -7,36 +7,6 @@ import { showToast } from "./components/ui/toast.js";
|
|
|
7
7
|
import { t } from "./locales/index.js";
|
|
8
8
|
import { version } from "../package.json";
|
|
9
9
|
import { showConfirm } from "./components/ui/confirm.js";
|
|
10
|
-
import AppContainer from "./components/AppContainer/index.js";
|
|
11
|
-
import QueryProvider from "./components/QueryProvider/index.js";
|
|
12
|
-
import PagePlaceholder from "./components/PagePlaceholder/index.js";
|
|
13
|
-
import ErrorRender from "./components/ErrorRender/index.js";
|
|
14
|
-
import { ActiveLink } from "./apis/components/ActiveLink.js";
|
|
15
|
-
import { NavLink } from "./apis/components/NavLink.js";
|
|
16
|
-
import { UniversalLink } from "./apis/components/UniversalLink.js";
|
|
17
|
-
import { useAppInfo } from "./hooks/useAppInfo.js";
|
|
18
|
-
import { useCurrentUserProfile } from "./hooks/useCurrentUserProfile.js";
|
|
19
|
-
import { useIsMobile } from "./hooks/useIsMobile.js";
|
|
20
|
-
import { useLogout } from "./hooks/useLogout.js";
|
|
21
|
-
import { getCsrfToken } from "./utils/getCsrfToken.js";
|
|
22
|
-
import { scopedStorage } from "./utils/scopedStorage.js";
|
|
23
|
-
import { copyToClipboard } from "./utils/copyToClipboard.js";
|
|
24
|
-
import { isIOS, isIpad, isMobile } from "./utils/deviceType.js";
|
|
25
|
-
import { resolveAppUrl } from "./utils/resolveAppUrl.js";
|
|
26
|
-
import { getEnvPath } from "./utils/getEnvPath.js";
|
|
27
|
-
import { safeStringify } from "./utils/safeStringify.js";
|
|
28
|
-
import { axiosForBackend, getAxiosForBackend } from "./utils/getAxiosForBackend.js";
|
|
29
|
-
import { initAxiosConfig } from "./utils/axiosConfig.js";
|
|
30
|
-
import { getAppInfo } from "./integrations/getAppInfo.js";
|
|
31
|
-
import { getCurrentUserProfile } from "./integrations/getCurrentUserProfile.js";
|
|
32
|
-
import { getDataloom } from "./integrations/dataloom.js";
|
|
33
|
-
import { trace } from "./trace/index.js";
|
|
34
|
-
import { initObservable } from "./runtime/observable.js";
|
|
35
|
-
import { TrackKey } from "./types/tea.js";
|
|
36
|
-
import { reportTeaEvent } from "./components/AppContainer/utils/tea.js";
|
|
37
|
-
import * as __WEBPACK_EXTERNAL_MODULE__apis_constants_img_resources_avatar_js_2c154035__ from "./apis/constants/img-resources/avatar.js";
|
|
38
|
-
import * as __WEBPACK_EXTERNAL_MODULE__apis_constants_img_resources_banner_js_72c990bf__ from "./apis/constants/img-resources/banner.js";
|
|
39
|
-
import * as __WEBPACK_EXTERNAL_MODULE__apis_constants_img_resources_cover_js_90a812c2__ from "./apis/constants/img-resources/cover.js";
|
|
40
10
|
const _appId = getAppId();
|
|
41
11
|
const _acquireUploadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_upload_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_upload_url";
|
|
42
12
|
const _acquireDownloadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_download_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_download_url";
|
|
@@ -57,4 +27,4 @@ const capabilityClient = createClient({
|
|
|
57
27
|
const src = {
|
|
58
28
|
version: version
|
|
59
29
|
};
|
|
60
|
-
export {
|
|
30
|
+
export { capabilityClient, src as default, showConfirm };
|
|
@@ -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;
|
|
@@ -6,15 +6,6 @@ export type I18nText = {
|
|
|
6
6
|
export type DepartmentBasic = {
|
|
7
7
|
departmentID: string;
|
|
8
8
|
name: I18nText;
|
|
9
|
-
/** 飞书部门 open id(od- 开头),调飞书部门能力时使用 */
|
|
10
|
-
openDepartmentID?: string;
|
|
11
|
-
};
|
|
12
|
-
/** 直属上级 / 虚线上级,仅在 needFullFields 时返回 */
|
|
13
|
-
export type LeaderUser = {
|
|
14
|
-
/** 飞书企业内 user_id */
|
|
15
|
-
employeeID?: string;
|
|
16
|
-
/** 妙搭用户全局唯一 ID */
|
|
17
|
-
miaodaUserID?: string;
|
|
18
9
|
};
|
|
19
10
|
export type UserInfo = {
|
|
20
11
|
userID: string;
|
|
@@ -25,41 +16,11 @@ export type UserInfo = {
|
|
|
25
16
|
department: DepartmentBasic;
|
|
26
17
|
email?: string;
|
|
27
18
|
tenantName?: string;
|
|
28
|
-
/** 妙搭用户全局唯一 ID(来源同 userID,向前兼容别名) */
|
|
29
|
-
miaodaUserID?: string;
|
|
30
|
-
/** 飞书企业内 user_id,仅内部飞书用户;调飞书开放平台能力时使用 */
|
|
31
|
-
employeeID?: string;
|
|
32
|
-
/** 飞书用户全局唯一 ID(来源同 larkUserID 别名) */
|
|
33
|
-
larkID?: string;
|
|
34
|
-
/** 昵称(多语言),仅 needFullFields=true 时返回 */
|
|
35
|
-
nickname?: I18nText;
|
|
36
|
-
/** 手机号,仅 needFullFields=true 时返回 */
|
|
37
|
-
mobile?: string;
|
|
38
|
-
/** 性别,仅 needFullFields=true 时返回 */
|
|
39
|
-
gender?: string;
|
|
40
|
-
/** 国家/地区,仅 needFullFields=true 时返回 */
|
|
41
|
-
country?: string;
|
|
42
|
-
/** 工位,仅 needFullFields=true 时返回 */
|
|
43
|
-
workStation?: string;
|
|
44
|
-
/** 工号,仅 needFullFields=true 时返回 */
|
|
45
|
-
employeeNo?: string;
|
|
46
|
-
/** 城市,仅 needFullFields=true 时返回 */
|
|
47
|
-
city?: string;
|
|
48
|
-
/** 职位(多语言),仅 needFullFields=true 时返回 */
|
|
49
|
-
jobTitle?: I18nText;
|
|
50
|
-
/** 员工类型,仅 needFullFields=true 时返回 */
|
|
51
|
-
employeeType?: string;
|
|
52
|
-
/** 直属上级,仅 needFullFields=true 时返回 */
|
|
53
|
-
leader?: LeaderUser;
|
|
54
|
-
/** 虚线上级,仅 needFullFields=true 时返回 */
|
|
55
|
-
dottedLineLeaders?: LeaderUser[];
|
|
56
19
|
};
|
|
57
20
|
export type DepartmentInfo = {
|
|
58
21
|
departmentID: string;
|
|
59
22
|
larkDepartmentID: string;
|
|
60
23
|
name: I18nText;
|
|
61
|
-
/** 飞书部门 open id(od- 开头) */
|
|
62
|
-
openDepartmentID?: string;
|
|
63
24
|
};
|
|
64
25
|
export type AccountType = 'apaas' | 'lark';
|
|
65
26
|
export type SearchAvatar = {
|
|
@@ -74,8 +35,6 @@ export type SearchUsersParams = {
|
|
|
74
35
|
offset?: number;
|
|
75
36
|
pageSize?: number;
|
|
76
37
|
searchExternalContact?: boolean;
|
|
77
|
-
/** 是否返回 full 字段(手机号/职位/上级等),默认 false */
|
|
78
|
-
needFullFields?: boolean;
|
|
79
38
|
};
|
|
80
39
|
export type SearchUsersResponse = {
|
|
81
40
|
data: {
|
|
@@ -116,8 +75,6 @@ export type SearchDepartmentsResponse = {
|
|
|
116
75
|
export type ChatInfo = {
|
|
117
76
|
/** 群组 ID */
|
|
118
77
|
chatID: string;
|
|
119
|
-
/** 飞书群组 open id(oc_ 开头),调飞书群组能力时使用 */
|
|
120
|
-
openChatID?: string;
|
|
121
78
|
/** 群组名称(国际化文本) */
|
|
122
79
|
name: I18nText;
|
|
123
80
|
/** 头像:URL 或 16 进制 RGB 颜色 */
|
package/lib/locales/messages.js
CHANGED
|
@@ -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/lib/runtime/index.js
CHANGED
|
@@ -5,11 +5,13 @@ import { initAxiosConfig } from "./axios.js";
|
|
|
5
5
|
import { initObservable } from "./observable.js";
|
|
6
6
|
import { initServerLog } from "./server-log.js";
|
|
7
7
|
import { initIframeBridge } from "./iframe-bridge.js";
|
|
8
|
+
import { initPreviewRunReporting } from "./preview-run.js";
|
|
8
9
|
if (!window.__FULLSTACK_RUNTIME_INITIALIZED__) {
|
|
9
10
|
window.__FULLSTACK_RUNTIME_INITIALIZED__ = true;
|
|
10
11
|
registerDayjsPlugins();
|
|
11
12
|
initAxiosConfig();
|
|
12
13
|
initObservable();
|
|
14
|
+
initPreviewRunReporting();
|
|
13
15
|
if ('production' !== process.env.NODE_ENV) {
|
|
14
16
|
initServerLog();
|
|
15
17
|
initIframeBridge();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const PREVIEW_RUN_ID_QUERY = "__miaoda_preview_run_id";
|
|
2
|
+
export declare const PREVIEW_RENDERED_MESSAGE_TYPE = "MiaodaPreviewRendered";
|
|
3
|
+
interface PreviewRenderedMessage {
|
|
4
|
+
type: typeof PREVIEW_RENDERED_MESSAGE_TYPE;
|
|
5
|
+
data: {
|
|
6
|
+
runID: string;
|
|
7
|
+
customTtiMs: number;
|
|
8
|
+
renderedAtEpochMs: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface CreatePreviewRenderedMessageOptions {
|
|
12
|
+
search: string;
|
|
13
|
+
customTtiMs: number;
|
|
14
|
+
eventTimeStampMs: number;
|
|
15
|
+
performanceTimeOriginMs: number;
|
|
16
|
+
renderedAtEpochMs?: number;
|
|
17
|
+
}
|
|
18
|
+
interface PreviewRunReportingEnvironment {
|
|
19
|
+
search: string;
|
|
20
|
+
referrer: string;
|
|
21
|
+
performanceTimeOriginMs: number;
|
|
22
|
+
isEmbedded: boolean;
|
|
23
|
+
addEventListener(type: 'builderV3-custom-TTI', handler: (event: Event) => void): void;
|
|
24
|
+
removeEventListener(type: 'builderV3-custom-TTI', handler: (event: Event) => void): void;
|
|
25
|
+
postMessage(message: PreviewRenderedMessage, targetOrigin: string): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function createPreviewRenderedMessage(options: CreatePreviewRenderedMessageOptions): PreviewRenderedMessage | undefined;
|
|
28
|
+
export declare function initPreviewRunReporting(environment?: PreviewRunReportingEnvironment): () => void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const PREVIEW_RUN_ID_QUERY = '__miaoda_preview_run_id';
|
|
2
|
+
const PREVIEW_RENDERED_MESSAGE_TYPE = 'MiaodaPreviewRendered';
|
|
3
|
+
const PREVIEW_RUN_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
4
|
+
const EPOCH_TIME_THRESHOLD_MS = 1000000000000;
|
|
5
|
+
const ALLOWED_PARENT_ORIGINS = new Set([
|
|
6
|
+
'https://miaoda.feishu.cn',
|
|
7
|
+
'https://miaoda.feishu-pre.cn',
|
|
8
|
+
'https://miaoda.feishu-boe.cn'
|
|
9
|
+
]);
|
|
10
|
+
function isFiniteNonNegative(value) {
|
|
11
|
+
return 'number' == typeof value && Number.isFinite(value) && value >= 0;
|
|
12
|
+
}
|
|
13
|
+
function resolveRenderedAtEpochMs(renderedAtEpochMs, eventTimeStampMs, performanceTimeOriginMs) {
|
|
14
|
+
if (isFiniteNonNegative(renderedAtEpochMs) && renderedAtEpochMs > 0) return renderedAtEpochMs;
|
|
15
|
+
if (!isFiniteNonNegative(eventTimeStampMs)) return;
|
|
16
|
+
if (eventTimeStampMs >= EPOCH_TIME_THRESHOLD_MS) return eventTimeStampMs;
|
|
17
|
+
if (!isFiniteNonNegative(performanceTimeOriginMs) || performanceTimeOriginMs <= 0) return;
|
|
18
|
+
return performanceTimeOriginMs + eventTimeStampMs;
|
|
19
|
+
}
|
|
20
|
+
function resolveParentOrigin(referrer) {
|
|
21
|
+
try {
|
|
22
|
+
const origin = new URL(referrer).origin;
|
|
23
|
+
return ALLOWED_PARENT_ORIGINS.has(origin) ? origin : void 0;
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function createPreviewRenderedMessage(options) {
|
|
29
|
+
const runID = new URLSearchParams(options.search).get(PREVIEW_RUN_ID_QUERY);
|
|
30
|
+
const renderedAtEpochMs = resolveRenderedAtEpochMs(options.renderedAtEpochMs, options.eventTimeStampMs, options.performanceTimeOriginMs);
|
|
31
|
+
if (!runID || !PREVIEW_RUN_ID_PATTERN.test(runID) || !isFiniteNonNegative(options.customTtiMs) || void 0 === renderedAtEpochMs) return;
|
|
32
|
+
return {
|
|
33
|
+
type: PREVIEW_RENDERED_MESSAGE_TYPE,
|
|
34
|
+
data: {
|
|
35
|
+
runID,
|
|
36
|
+
customTtiMs: options.customTtiMs,
|
|
37
|
+
renderedAtEpochMs
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createBrowserEnvironment() {
|
|
42
|
+
const legacyNavigationStart = performance.timing?.navigationStart;
|
|
43
|
+
const performanceTimeOriginMs = 'number' == typeof performance.timeOrigin && performance.timeOrigin > 0 ? performance.timeOrigin : legacyNavigationStart ?? 0;
|
|
44
|
+
return {
|
|
45
|
+
search: window.location.search,
|
|
46
|
+
referrer: document.referrer,
|
|
47
|
+
performanceTimeOriginMs,
|
|
48
|
+
isEmbedded: window.parent !== window,
|
|
49
|
+
addEventListener: (type, handler)=>window.addEventListener(type, handler),
|
|
50
|
+
removeEventListener: (type, handler)=>window.removeEventListener(type, handler),
|
|
51
|
+
postMessage: (message, targetOrigin)=>window.parent.postMessage(message, targetOrigin)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function initPreviewRunReporting(environment = createBrowserEnvironment()) {
|
|
55
|
+
const parentOrigin = resolveParentOrigin(environment.referrer);
|
|
56
|
+
const runID = new URLSearchParams(environment.search).get(PREVIEW_RUN_ID_QUERY);
|
|
57
|
+
if (!environment.isEmbedded || !parentOrigin || !runID || !PREVIEW_RUN_ID_PATTERN.test(runID)) return ()=>void 0;
|
|
58
|
+
let lastRenderedAtEpochMs;
|
|
59
|
+
const handleCustomTti = (event)=>{
|
|
60
|
+
const detail = event.detail;
|
|
61
|
+
if (!isFiniteNonNegative(detail?.time)) return;
|
|
62
|
+
const message = createPreviewRenderedMessage({
|
|
63
|
+
search: environment.search,
|
|
64
|
+
customTtiMs: detail.time,
|
|
65
|
+
eventTimeStampMs: event.timeStamp,
|
|
66
|
+
performanceTimeOriginMs: environment.performanceTimeOriginMs,
|
|
67
|
+
renderedAtEpochMs: 'number' == typeof detail.renderedAtEpochMs ? detail.renderedAtEpochMs : void 0
|
|
68
|
+
});
|
|
69
|
+
if (!message || lastRenderedAtEpochMs === message.data.renderedAtEpochMs) return;
|
|
70
|
+
lastRenderedAtEpochMs = message.data.renderedAtEpochMs;
|
|
71
|
+
environment.postMessage(message, parentOrigin);
|
|
72
|
+
};
|
|
73
|
+
environment.addEventListener('builderV3-custom-TTI', handleCustomTti);
|
|
74
|
+
return ()=>environment.removeEventListener('builderV3-custom-TTI', handleCustomTti);
|
|
75
|
+
}
|
|
76
|
+
export { PREVIEW_RENDERED_MESSAGE_TYPE, PREVIEW_RUN_ID_QUERY, createPreviewRenderedMessage, initPreviewRunReporting };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { PREVIEW_RENDERED_MESSAGE_TYPE, createPreviewRenderedMessage, initPreviewRunReporting } from "./preview-run.js";
|
|
3
|
+
describe('createPreviewRenderedMessage', ()=>{
|
|
4
|
+
it('使用 TTI 事件时间戳生成精确的 iframe 渲染完成消息', ()=>{
|
|
5
|
+
expect(createPreviewRenderedMessage({
|
|
6
|
+
search: '?__miaoda_preview_run_id=prv_test_123',
|
|
7
|
+
customTtiMs: 8951.8,
|
|
8
|
+
eventTimeStampMs: 12643.9,
|
|
9
|
+
performanceTimeOriginMs: 1784022258000
|
|
10
|
+
})).toEqual({
|
|
11
|
+
type: PREVIEW_RENDERED_MESSAGE_TYPE,
|
|
12
|
+
data: {
|
|
13
|
+
runID: 'prv_test_123',
|
|
14
|
+
customTtiMs: 8951.8,
|
|
15
|
+
renderedAtEpochMs: 1784022270643.9
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('优先采用新版 TTI 显式提供的 epoch 时间', ()=>{
|
|
20
|
+
expect(createPreviewRenderedMessage({
|
|
21
|
+
search: '?__miaoda_preview_run_id=prv_explicit',
|
|
22
|
+
customTtiMs: 321,
|
|
23
|
+
eventTimeStampMs: 999,
|
|
24
|
+
performanceTimeOriginMs: 1000,
|
|
25
|
+
renderedAtEpochMs: 1720000000123
|
|
26
|
+
})?.data.renderedAtEpochMs).toBe(1720000000123);
|
|
27
|
+
});
|
|
28
|
+
it('拒绝非法 run_id 和非有限耗时', ()=>{
|
|
29
|
+
expect(createPreviewRenderedMessage({
|
|
30
|
+
search: '?__miaoda_preview_run_id=invalid%2Frun',
|
|
31
|
+
customTtiMs: 321,
|
|
32
|
+
eventTimeStampMs: 999,
|
|
33
|
+
performanceTimeOriginMs: 1000
|
|
34
|
+
})).toBeUndefined();
|
|
35
|
+
expect(createPreviewRenderedMessage({
|
|
36
|
+
search: '?__miaoda_preview_run_id=prv_valid',
|
|
37
|
+
customTtiMs: NaN,
|
|
38
|
+
eventTimeStampMs: 999,
|
|
39
|
+
performanceTimeOriginMs: 1000
|
|
40
|
+
})).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('initPreviewRunReporting', ()=>{
|
|
44
|
+
it('只向可信妙搭父页面回传一次 TTI,并支持旧版 detail', ()=>{
|
|
45
|
+
let listener;
|
|
46
|
+
const postMessage = vi.fn();
|
|
47
|
+
const cleanup = initPreviewRunReporting({
|
|
48
|
+
search: '?__miaoda_preview_run_id=prv_runtime',
|
|
49
|
+
referrer: 'https://miaoda.feishu-boe.cn/app/app_test',
|
|
50
|
+
performanceTimeOriginMs: 1700000000000,
|
|
51
|
+
isEmbedded: true,
|
|
52
|
+
addEventListener: (_type, handler)=>{
|
|
53
|
+
listener = handler;
|
|
54
|
+
},
|
|
55
|
+
removeEventListener: vi.fn(),
|
|
56
|
+
postMessage
|
|
57
|
+
});
|
|
58
|
+
listener?.({
|
|
59
|
+
timeStamp: 2345,
|
|
60
|
+
detail: {
|
|
61
|
+
time: 456
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
listener?.({
|
|
65
|
+
timeStamp: 2345,
|
|
66
|
+
detail: {
|
|
67
|
+
time: 456
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
expect(postMessage).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(postMessage).toHaveBeenCalledWith({
|
|
72
|
+
type: PREVIEW_RENDERED_MESSAGE_TYPE,
|
|
73
|
+
data: {
|
|
74
|
+
runID: 'prv_runtime',
|
|
75
|
+
customTtiMs: 456,
|
|
76
|
+
renderedAtEpochMs: 1700000002345
|
|
77
|
+
}
|
|
78
|
+
}, 'https://miaoda.feishu-boe.cn');
|
|
79
|
+
cleanup();
|
|
80
|
+
});
|
|
81
|
+
it('拒绝向非妙搭 referrer 回传', ()=>{
|
|
82
|
+
const addEventListener = vi.fn();
|
|
83
|
+
initPreviewRunReporting({
|
|
84
|
+
search: '?__miaoda_preview_run_id=prv_runtime',
|
|
85
|
+
referrer: 'https://evil.example/app',
|
|
86
|
+
performanceTimeOriginMs: 1700000000000,
|
|
87
|
+
isEmbedded: true,
|
|
88
|
+
addEventListener,
|
|
89
|
+
removeEventListener: vi.fn(),
|
|
90
|
+
postMessage: vi.fn()
|
|
91
|
+
});
|
|
92
|
+
expect(addEventListener).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
});
|