@lark-apaas/client-toolkit 1.2.52-beta.0 → 1.2.53-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/apis/components/UniversalLink.d.ts +0 -3
- package/lib/apis/components/UniversalLink.js +3 -42
- package/lib/auth.d.ts +0 -2
- package/lib/auth.js +2 -2
- package/lib/components/AppContainer/index.js +3 -6
- package/lib/components/AppContainer/safety.js +0 -50
- package/lib/components/User/UserSelect.js +5 -3
- package/lib/hooks/useCurrentUserProfile.d.ts +15 -5
- package/lib/hooks/useCurrentUserProfile.js +12 -17
- package/lib/hooks/useLogout.js +3 -2
- package/lib/index.d.ts +0 -40
- package/lib/index.js +2 -32
- package/lib/integrations/dataloom.js +1 -6
- package/lib/integrations/getCurrentUserProfile.d.ts +4 -3
- package/lib/integrations/services/types.d.ts +34 -0
- package/lib/locales/messages.js +0 -4
- 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/lib/utils/requestManager.js +4 -2
- package/package.json +4 -5
- 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/safety-error-boundary.d.ts +0 -23
- package/lib/components/AppContainer/safety-error-boundary.js +0 -29
|
@@ -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
|
}
|
package/lib/auth.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
export { AuthProvider, useAuth, Can, CanRole, useCan, AbilityContext, useUserPermissions, PermissionClient, ROLE_SUBJECT, } from '@lark-apaas/auth-sdk';
|
|
2
2
|
export type { AuthProviderProps, PermissionApiResponse, PermissionApiConfig, PermissionPointData, AuthSdkConfig, } from '@lark-apaas/auth-sdk';
|
|
3
|
-
export { authClient, AccountClient } from '@lark-apaas/auth-sdk';
|
|
4
|
-
export type { AccountClient as AuthClient, AccountServiceResponse, AccountServiceError, SearchParams, User, UserResponse, SignInRedirectionOptions, UserBaseInfo, UserInfoResponse, Avatar, } from '@lark-apaas/auth-sdk';
|
package/lib/auth.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AbilityContext,
|
|
2
|
-
export { AbilityContext,
|
|
1
|
+
import { AbilityContext, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, useAuth, useCan, useUserPermissions } from "@lark-apaas/auth-sdk";
|
|
2
|
+
export { AbilityContext, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, useAuth, useCan, useUserPermissions };
|
|
@@ -7,7 +7,6 @@ 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";
|
|
@@ -197,11 +196,9 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
197
196
|
};
|
|
198
197
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
199
198
|
children: [
|
|
200
|
-
/*#__PURE__*/ jsx(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
children: /*#__PURE__*/ jsx(Safety, {})
|
|
204
|
-
})
|
|
199
|
+
/*#__PURE__*/ jsx(Suspense, {
|
|
200
|
+
fallback: null,
|
|
201
|
+
children: /*#__PURE__*/ jsx(Safety, {})
|
|
205
202
|
}),
|
|
206
203
|
/*#__PURE__*/ jsx(QueryProvider, {
|
|
207
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
|
}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import react from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { getDataloom } from "../../integrations/dataloom.js";
|
|
4
4
|
import { UserSelectUI } from "./UserSelectUI/index.js";
|
|
5
5
|
const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholder, fetchUsers })=>{
|
|
6
6
|
const normalizedIds = react.useMemo(()=>{
|
|
@@ -67,7 +67,8 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
|
|
|
67
67
|
if (!normalizedIds.length) return void setUiValue(void 0);
|
|
68
68
|
const fetchProfiles = async ()=>{
|
|
69
69
|
try {
|
|
70
|
-
const
|
|
70
|
+
const dataloom = await getDataloom();
|
|
71
|
+
const response = await dataloom.service.user.getByIds(normalizedIds);
|
|
71
72
|
const fetchedList = Array.isArray(response?.data) ? response?.data : Array.isArray(response?.data?.user_list) ? response?.data?.user_list : [];
|
|
72
73
|
const fetchedMap = new Map();
|
|
73
74
|
fetchedList.forEach((profile)=>{
|
|
@@ -114,7 +115,8 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
|
|
|
114
115
|
const fetchUsersImpl = react.useCallback(async (search)=>{
|
|
115
116
|
if (fetchUsers) return fetchUsers(search);
|
|
116
117
|
try {
|
|
117
|
-
const
|
|
118
|
+
const dataloom = await getDataloom();
|
|
119
|
+
const { data } = await dataloom.service.user.search({
|
|
118
120
|
name: search,
|
|
119
121
|
pageSize: 20
|
|
120
122
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { IUserProfile } from '../apis/udt-types';
|
|
2
2
|
/**
|
|
3
3
|
* useCurrentUserProfile 的返回类型。
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 初始状态为空对象 `{}`(所有字段均为 undefined),异步获取用户信息后字段才会被填充。
|
|
5
|
+
* 使用时必须通过可选链或空值合并进行安全访问,如 `userInfo?.user_id`。
|
|
6
|
+
* 判断是否已加载完成应使用 `if (!userInfo?.user_id)` 而非 `if (!userInfo)`(因为空对象是 truthy)。
|
|
6
7
|
*/
|
|
7
|
-
export
|
|
8
|
+
export type ICompatibilityUserProfile = Partial<IUserProfile & {
|
|
8
9
|
/**
|
|
9
10
|
* @deprecated please use `name`
|
|
10
11
|
*/
|
|
@@ -13,5 +14,14 @@ export interface ICompatibilityUserProfile extends IUserProfile {
|
|
|
13
14
|
* @deprecated please use `avatar`
|
|
14
15
|
*/
|
|
15
16
|
userAvatar: string;
|
|
16
|
-
}
|
|
17
|
-
export declare const useCurrentUserProfile: () =>
|
|
17
|
+
}>;
|
|
18
|
+
export declare const useCurrentUserProfile: () => Partial<IUserProfile & {
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated please use `name`
|
|
21
|
+
*/
|
|
22
|
+
userName: string;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated please use `avatar`
|
|
25
|
+
*/
|
|
26
|
+
userAvatar: string;
|
|
27
|
+
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
-
import { authClient } from "@lark-apaas/auth-sdk";
|
|
3
2
|
import { logger } from "../logger/index.js";
|
|
4
3
|
import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
|
|
4
|
+
import { getDataloom } from "../integrations/dataloom.js";
|
|
5
5
|
import { isSparkRuntime } from "../utils/utils.js";
|
|
6
6
|
import { getAxiosForBackend } from "../utils/getAxiosForBackend.js";
|
|
7
7
|
function getNameFromArray(nameArray) {
|
|
@@ -25,14 +25,9 @@ function fetchLarkUserId() {
|
|
|
25
25
|
function getCompatibilityUserProfile() {
|
|
26
26
|
const userInfo = getCurrentUserProfile();
|
|
27
27
|
return {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
avatar: userInfo.avatar ?? '',
|
|
32
|
-
status: userInfo.status,
|
|
33
|
-
lark_user_id: userInfo.lark_user_id,
|
|
34
|
-
userName: userInfo.name ?? '',
|
|
35
|
-
userAvatar: userInfo.avatar ?? ''
|
|
28
|
+
...userInfo,
|
|
29
|
+
userName: userInfo.name,
|
|
30
|
+
userAvatar: userInfo.avatar
|
|
36
31
|
};
|
|
37
32
|
}
|
|
38
33
|
const useCurrentUserProfile = ()=>{
|
|
@@ -40,18 +35,18 @@ const useCurrentUserProfile = ()=>{
|
|
|
40
35
|
useEffect(()=>{
|
|
41
36
|
let cancelled = false;
|
|
42
37
|
const fetchAndSetUserInfo = async ()=>{
|
|
43
|
-
const
|
|
38
|
+
const dataloom = await getDataloom();
|
|
39
|
+
const result = await dataloom?.service?.session?.getUserInfo();
|
|
44
40
|
if (cancelled) return;
|
|
45
41
|
const info = result?.data?.user_info;
|
|
46
|
-
const userName = getNameFromArray(info?.name)
|
|
47
|
-
const avatar = info?.avatar?.image?.large ?? '';
|
|
42
|
+
const userName = getNameFromArray(info?.name);
|
|
48
43
|
const newUserInfo = {
|
|
49
|
-
user_id: info?.user_id?.toString()
|
|
50
|
-
email: info?.email
|
|
44
|
+
user_id: info?.user_id?.toString(),
|
|
45
|
+
email: info?.email,
|
|
51
46
|
name: userName,
|
|
52
|
-
avatar,
|
|
53
|
-
userName,
|
|
54
|
-
userAvatar: avatar
|
|
47
|
+
avatar: info?.avatar?.image?.large,
|
|
48
|
+
userName: userName,
|
|
49
|
+
userAvatar: info?.avatar?.image?.large
|
|
55
50
|
};
|
|
56
51
|
const larkUserId = await fetchLarkUserId();
|
|
57
52
|
if (larkUserId) newUserInfo.lark_user_id = larkUserId;
|
package/lib/hooks/useLogout.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { getDataloom } from "../integrations/dataloom.js";
|
|
3
3
|
function useLogout() {
|
|
4
4
|
const [isLoading, setIsLoading] = useState(false);
|
|
5
5
|
async function handlerLogout() {
|
|
6
6
|
if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
|
|
7
7
|
setIsLoading(true);
|
|
8
8
|
try {
|
|
9
|
-
await
|
|
9
|
+
const dataloom = await getDataloom();
|
|
10
|
+
await dataloom.service.session.signOut();
|
|
10
11
|
} catch (error) {
|
|
11
12
|
console.error('登出失败', error);
|
|
12
13
|
} finally{
|
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,6 +1,5 @@
|
|
|
1
1
|
import { splitWorkspaceUrl } from "../utils/url.js";
|
|
2
2
|
import { createClient } from "@lark-apaas/dataloom";
|
|
3
|
-
import { authClient } from "@lark-apaas/auth-sdk";
|
|
4
3
|
import { getAppId } from "../utils/getAppId.js";
|
|
5
4
|
import { getAppPublished } from "../utils/getInitialInfo.js";
|
|
6
5
|
const createDataLoomClient = (url, pat)=>{
|
|
@@ -13,11 +12,7 @@ const createDataLoomClient = (url, pat)=>{
|
|
|
13
12
|
enableDataloomLog: 'production' !== process.env.NODE_ENV,
|
|
14
13
|
requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
|
|
15
14
|
brandName: 'miaoda',
|
|
16
|
-
appId
|
|
17
|
-
accountServices: {
|
|
18
|
-
user: authClient.user,
|
|
19
|
-
session: authClient.session
|
|
20
|
-
}
|
|
15
|
+
appId
|
|
21
16
|
}
|
|
22
17
|
});
|
|
23
18
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { IUserProfile } from '../apis/udt-types';
|
|
2
2
|
/**
|
|
3
3
|
* 获取当前用户信息。
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 返回 Partial<IUserProfile>,因为初始值来自 window._userInfo,
|
|
5
|
+
* 该值在运行时始终为空对象 {},所有字段均为 undefined。
|
|
6
|
+
* 异步获取用户信息后才会被填充为完整的 IUserProfile。
|
|
6
7
|
*/
|
|
7
|
-
export declare function getCurrentUserProfile(): IUserProfile
|
|
8
|
+
export declare function getCurrentUserProfile(): Partial<IUserProfile>;
|
|
8
9
|
/**
|
|
9
10
|
* @deprecated 请使用 getCurrentUserProfile 代替
|
|
10
11
|
*/
|
|
@@ -6,6 +6,15 @@ 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;
|
|
9
18
|
};
|
|
10
19
|
export type UserInfo = {
|
|
11
20
|
userID: string;
|
|
@@ -16,11 +25,32 @@ export type UserInfo = {
|
|
|
16
25
|
department: DepartmentBasic;
|
|
17
26
|
email?: string;
|
|
18
27
|
tenantName?: string;
|
|
28
|
+
/** 妙搭用户全局唯一 ID(来源同 userID,向前兼容别名) */
|
|
29
|
+
miaodaUserID?: string;
|
|
30
|
+
/** 飞书企业内 user_id,仅内部飞书用户;调飞书开放平台能力时使用 */
|
|
31
|
+
employeeID?: string;
|
|
32
|
+
/** 飞书用户全局唯一 ID(来源同 larkUserID 别名) */
|
|
33
|
+
larkID?: string;
|
|
34
|
+
nickname?: string;
|
|
35
|
+
mobile?: string;
|
|
36
|
+
gender?: number;
|
|
37
|
+
country?: string;
|
|
38
|
+
workStation?: string;
|
|
39
|
+
employeeNo?: string;
|
|
40
|
+
city?: string;
|
|
41
|
+
jobTitle?: string;
|
|
42
|
+
employeeType?: number;
|
|
43
|
+
/** 直属上级 */
|
|
44
|
+
leader?: LeaderUser;
|
|
45
|
+
/** 虚线上级 */
|
|
46
|
+
dottedLineLeaders?: LeaderUser[];
|
|
19
47
|
};
|
|
20
48
|
export type DepartmentInfo = {
|
|
21
49
|
departmentID: string;
|
|
22
50
|
larkDepartmentID: string;
|
|
23
51
|
name: I18nText;
|
|
52
|
+
/** 飞书部门 open id(od- 开头) */
|
|
53
|
+
openDepartmentID?: string;
|
|
24
54
|
};
|
|
25
55
|
export type AccountType = 'apaas' | 'lark';
|
|
26
56
|
export type SearchAvatar = {
|
|
@@ -35,6 +65,8 @@ export type SearchUsersParams = {
|
|
|
35
65
|
offset?: number;
|
|
36
66
|
pageSize?: number;
|
|
37
67
|
searchExternalContact?: boolean;
|
|
68
|
+
/** 是否返回 full 字段(手机号/职位/上级等),默认 false */
|
|
69
|
+
needFullFields?: boolean;
|
|
38
70
|
};
|
|
39
71
|
export type SearchUsersResponse = {
|
|
40
72
|
data: {
|
|
@@ -75,6 +107,8 @@ export type SearchDepartmentsResponse = {
|
|
|
75
107
|
export type ChatInfo = {
|
|
76
108
|
/** 群组 ID */
|
|
77
109
|
chatID: string;
|
|
110
|
+
/** 飞书群组 open id(oc_ 开头),调飞书群组能力时使用 */
|
|
111
|
+
openChatID?: string;
|
|
78
112
|
/** 群组名称(国际化文本) */
|
|
79
113
|
name: I18nText;
|
|
80
114
|
/** 头像: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'
|
|
@@ -46,18 +46,7 @@ export interface DevServerMessage extends IframeMessage<{
|
|
|
46
46
|
}> {
|
|
47
47
|
type: 'DevServerMessage';
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
* 预览态下链接点击通知父页面处理。
|
|
51
|
-
* iframe 内直接跳转可能被浏览器安全策略拦截,
|
|
52
|
-
* 通过 postMessage 让父页面在新标签页或外壳中打开链接。
|
|
53
|
-
*/
|
|
54
|
-
export interface OpenIframeLinkMessage extends IframeMessage<{
|
|
55
|
-
href: string;
|
|
56
|
-
external: boolean;
|
|
57
|
-
}> {
|
|
58
|
-
type: 'OpenIframeLink';
|
|
59
|
-
}
|
|
60
|
-
export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | DevServerMessage | UpdateRoutesMessage | OpenIframeLinkMessage;
|
|
49
|
+
export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | DevServerMessage | UpdateRoutesMessage;
|
|
61
50
|
export interface GetRoutesMessage extends IframeMessage<Record<string, never>> {
|
|
62
51
|
type: 'GetRoutes';
|
|
63
52
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
|
|
2
|
-
export declare function getParentOriginFromParams(): string | undefined;
|
|
3
2
|
export declare function resolveParentOrigin(): string;
|
|
4
3
|
export declare function submitPostMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
|
5
4
|
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -50,4 +50,4 @@ function isOutgoingMessage(msg, type) {
|
|
|
50
50
|
function isIncomingMessage(msg, type) {
|
|
51
51
|
return msg.type === type;
|
|
52
52
|
}
|
|
53
|
-
export {
|
|
53
|
+
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDataloom } from "../integrations/dataloom.js";
|
|
2
2
|
const pendingRequests = new Map();
|
|
3
3
|
async function fetchUserProfilesByIds(ids) {
|
|
4
4
|
try {
|
|
5
|
-
const
|
|
5
|
+
const dataloom = await getDataloom();
|
|
6
|
+
if (!dataloom) throw new Error('Dataloom client is unavailable');
|
|
7
|
+
const response = await dataloom.service.user.getByIds(ids);
|
|
6
8
|
return Array.isArray(response?.data) ? response.data : response?.data?.user_list || [];
|
|
7
9
|
} catch (error) {
|
|
8
10
|
console.error(`Failed to fetch profiles for user IDs ${ids.join(', ')}:`, error);
|
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.53-alpha.0",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"types": "./lib/antd-table.d.ts"
|
|
27
27
|
},
|
|
28
28
|
"./lib/index.css": "./lib/index.css",
|
|
29
|
-
"./styles.css": "./lib/index.css",
|
|
30
29
|
"./dataloom": {
|
|
31
30
|
"import": "./lib/apis/dataloom.js",
|
|
32
31
|
"require": "./lib/apis/dataloom.js",
|
|
@@ -100,9 +99,9 @@
|
|
|
100
99
|
"@ant-design/colors": "^7.2.1",
|
|
101
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
102
101
|
"@lark-apaas/aily-web-sdk": "^0.0.11",
|
|
103
|
-
"@lark-apaas/auth-sdk": "^0.1.
|
|
104
|
-
"@lark-apaas/client-capability": "^0.1.
|
|
105
|
-
"@lark-apaas/dataloom": "
|
|
102
|
+
"@lark-apaas/auth-sdk": "^0.1.4",
|
|
103
|
+
"@lark-apaas/client-capability": "^0.1.6",
|
|
104
|
+
"@lark-apaas/dataloom": "0.1.4-alpha.1",
|
|
106
105
|
"@lark-apaas/internal-slardar": "^0.0.3",
|
|
107
106
|
"@lark-apaas/miaoda-inspector": "^1.0.23",
|
|
108
107
|
"@lark-apaas/observable-web": "^1.0.6",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import "react";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import { describe, expect, it, vi } from "vitest";
|
|
5
|
-
import { slardar } from "@lark-apaas/internal-slardar";
|
|
6
|
-
import { SafetyErrorBoundary } from "../safety-error-boundary.js";
|
|
7
|
-
vi.mock('@lark-apaas/internal-slardar', ()=>({
|
|
8
|
-
slardar: {
|
|
9
|
-
sendLog: vi.fn()
|
|
10
|
-
}
|
|
11
|
-
}));
|
|
12
|
-
describe('SafetyErrorBoundary', ()=>{
|
|
13
|
-
it('renders children when no error', ()=>{
|
|
14
|
-
render(/*#__PURE__*/ jsx(SafetyErrorBoundary, {
|
|
15
|
-
children: /*#__PURE__*/ jsx("div", {
|
|
16
|
-
"data-testid": "child",
|
|
17
|
-
children: "child content"
|
|
18
|
-
})
|
|
19
|
-
}));
|
|
20
|
-
expect(screen.getByTestId('child').textContent).toBe('child content');
|
|
21
|
-
});
|
|
22
|
-
it('renders null fallback when child throws', ()=>{
|
|
23
|
-
const Throwing = ()=>{
|
|
24
|
-
throw new Error('Failed to fetch dynamically imported module: safety-XXX.js');
|
|
25
|
-
};
|
|
26
|
-
const errSpy = vi.spyOn(console, 'error').mockImplementation(()=>{});
|
|
27
|
-
const { container } = render(/*#__PURE__*/ jsx(SafetyErrorBoundary, {
|
|
28
|
-
children: /*#__PURE__*/ jsx(Throwing, {})
|
|
29
|
-
}));
|
|
30
|
-
expect(container.innerHTML).toBe('');
|
|
31
|
-
errSpy.mockRestore();
|
|
32
|
-
});
|
|
33
|
-
it('logs error via slardar when child throws', ()=>{
|
|
34
|
-
const Throwing = ()=>{
|
|
35
|
-
throw new Error('chunk load failed');
|
|
36
|
-
};
|
|
37
|
-
const errSpy = vi.spyOn(console, 'error').mockImplementation(()=>{});
|
|
38
|
-
slardar.sendLog.mockClear();
|
|
39
|
-
render(/*#__PURE__*/ jsx(SafetyErrorBoundary, {
|
|
40
|
-
children: /*#__PURE__*/ jsx(Throwing, {})
|
|
41
|
-
}));
|
|
42
|
-
expect(slardar.sendLog).toHaveBeenCalledTimes(1);
|
|
43
|
-
expect(slardar.sendLog).toHaveBeenCalledWith(expect.objectContaining({
|
|
44
|
-
content: expect.stringContaining('chunk load failed'),
|
|
45
|
-
level: 'error',
|
|
46
|
-
extra: expect.objectContaining({
|
|
47
|
-
stack: expect.any(String),
|
|
48
|
-
componentStack: expect.any(String)
|
|
49
|
-
})
|
|
50
|
-
}));
|
|
51
|
-
errSpy.mockRestore();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
interface Props {
|
|
3
|
-
children: React.ReactNode;
|
|
4
|
-
}
|
|
5
|
-
interface State {
|
|
6
|
-
hasError: boolean;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* SafetyErrorBoundary - 包裹 Safety 徽章的 lazy import 失败兜底
|
|
10
|
-
*
|
|
11
|
-
* Why: AppContainer 内 `<Suspense fallback={null}><Safety /></Suspense>` 中 Safety 是 React.lazy
|
|
12
|
-
* 拆出的非核心徽章 chunk。chunk 加载失败(CDN 缓存窗 / 部署漂移 / dev preview hash 漂移 / 网络抖动)
|
|
13
|
-
* 时 rejected Promise 越过 Suspense 上抛,会冒到 React root 让整应用 unmount = 白屏。
|
|
14
|
-
*
|
|
15
|
-
* ErrorBoundary 把失败局限在徽章自身:徽章不显示,应用继续跑。同时上报 slardar 便于事后归因。
|
|
16
|
-
*/
|
|
17
|
-
export declare class SafetyErrorBoundary extends React.Component<Props, State> {
|
|
18
|
-
state: State;
|
|
19
|
-
static getDerivedStateFromError(): State;
|
|
20
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
|
21
|
-
render(): React.ReactNode;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import react from "react";
|
|
2
|
-
import { slardar } from "@lark-apaas/internal-slardar";
|
|
3
|
-
class SafetyErrorBoundary extends react.Component {
|
|
4
|
-
state = {
|
|
5
|
-
hasError: false
|
|
6
|
-
};
|
|
7
|
-
static getDerivedStateFromError() {
|
|
8
|
-
return {
|
|
9
|
-
hasError: true
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
componentDidCatch(error, errorInfo) {
|
|
13
|
-
try {
|
|
14
|
-
slardar.sendLog({
|
|
15
|
-
content: `safety_chunk_load_error: ${error.message}`,
|
|
16
|
-
level: 'error',
|
|
17
|
-
extra: {
|
|
18
|
-
stack: error.stack ?? '',
|
|
19
|
-
componentStack: errorInfo.componentStack ?? ''
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
} catch {}
|
|
23
|
-
}
|
|
24
|
-
render() {
|
|
25
|
-
if (this.state.hasError) return null;
|
|
26
|
-
return this.props.children;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export { SafetyErrorBoundary };
|