@lark-apaas/client-toolkit 1.2.28-alpha.21 → 1.2.28-alpha.23
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/Group/GroupDisplay.d.ts +15 -0
- package/lib/components/Group/GroupDisplay.js +88 -0
- package/lib/components/Group/GroupSelect.d.ts +10 -0
- package/lib/components/Group/GroupSelect.js +133 -0
- package/lib/components/Group/index.d.ts +4 -0
- package/lib/components/Group/index.js +3 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/integrations/services/UserService.d.ts +1 -3
- package/lib/integrations/services/UserService.js +1 -20
- package/lib/integrations/services/types.d.ts +0 -10
- package/lib/utils/axiosConfig.js +114 -4
- package/lib/utils/hmr-api.d.ts +7 -1
- package/package.json +4 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type GroupType = 'chat_group' | 'custom_group';
|
|
3
|
+
export interface IGroupInfo {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type?: GroupType;
|
|
7
|
+
avatarUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IGroupDisplayProps {
|
|
10
|
+
groups: IGroupInfo | IGroupInfo[];
|
|
11
|
+
size?: 'small' | 'medium' | 'large';
|
|
12
|
+
className?: string;
|
|
13
|
+
style?: React.CSSProperties;
|
|
14
|
+
}
|
|
15
|
+
export declare const GroupDisplay: React.FC<IGroupDisplayProps>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { clsxWithTw } from "../../utils/utils.js";
|
|
4
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip.js";
|
|
5
|
+
const sizeConfig = {
|
|
6
|
+
small: {
|
|
7
|
+
icon: 16,
|
|
8
|
+
text: 'text-xs'
|
|
9
|
+
},
|
|
10
|
+
medium: {
|
|
11
|
+
icon: 20,
|
|
12
|
+
text: 'text-sm'
|
|
13
|
+
},
|
|
14
|
+
large: {
|
|
15
|
+
icon: 24,
|
|
16
|
+
text: 'text-base'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const GroupIcon = ({ type = 'chat_group', size })=>{
|
|
20
|
+
if ('chat_group' === type) return /*#__PURE__*/ jsx("svg", {
|
|
21
|
+
width: size,
|
|
22
|
+
height: size,
|
|
23
|
+
viewBox: "0 0 24 24",
|
|
24
|
+
fill: "none",
|
|
25
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
26
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
27
|
+
d: "M17 20H22V18C22 16.3431 20.6569 15 19 15C18.0444 15 17.1931 15.4468 16.6438 16.1429M17 20H7M17 20V18C17 17.3438 16.8736 16.717 16.6438 16.1429M7 20H2V18C2 16.3431 3.34315 15 5 15C5.95561 15 6.80686 15.4468 7.35625 16.1429M7 20V18C7 17.3438 7.12642 16.717 7.35625 16.1429M7.35625 16.1429C8.0935 14.301 9.89482 13 12 13C14.1052 13 15.9065 14.301 16.6438 16.1429M15 7C15 8.65685 13.6569 10 12 10C10.3431 10 9 8.65685 9 7C9 5.34315 10.3431 4 12 4C13.6569 4 15 5.34315 15 7ZM21 10C21 11.1046 20.1046 12 19 12C17.8954 12 17 11.1046 17 10C17 8.89543 17.8954 8 19 8C20.1046 8 21 8.89543 21 10ZM7 10C7 11.1046 6.10457 12 5 12C3.89543 12 3 11.1046 3 10C3 8.89543 3.89543 8 5 8C6.10457 8 7 8.89543 7 10Z",
|
|
28
|
+
stroke: "currentColor",
|
|
29
|
+
strokeWidth: "2",
|
|
30
|
+
strokeLinecap: "round",
|
|
31
|
+
strokeLinejoin: "round"
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
return /*#__PURE__*/ jsx("svg", {
|
|
35
|
+
width: size,
|
|
36
|
+
height: size,
|
|
37
|
+
viewBox: "0 0 24 24",
|
|
38
|
+
fill: "none",
|
|
39
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
40
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
41
|
+
d: "M18 18.72a9.094 9.094 0 003.741-.479 3 3 0 00-4.682-2.72m.94 3.198l.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0112 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 016 18.719m12 0a5.971 5.971 0 00-.941-3.197m0 0A5.995 5.995 0 0012 12.75a5.995 5.995 0 00-5.058 2.772m0 0a3 3 0 00-4.681 2.72 8.986 8.986 0 003.74.477m.94-3.197a5.971 5.971 0 00-.94 3.197M15 6.75a3 3 0 11-6 0 3 3 0 016 0zm6 3a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0zm-13.5 0a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0z",
|
|
42
|
+
stroke: "currentColor",
|
|
43
|
+
strokeWidth: "2",
|
|
44
|
+
strokeLinecap: "round",
|
|
45
|
+
strokeLinejoin: "round"
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const GroupDisplay = ({ groups, size = 'medium', className, style })=>{
|
|
50
|
+
const groupList = Array.isArray(groups) ? groups : [
|
|
51
|
+
groups
|
|
52
|
+
];
|
|
53
|
+
const config = sizeConfig[size];
|
|
54
|
+
if (!groupList.length) return null;
|
|
55
|
+
return /*#__PURE__*/ jsx("div", {
|
|
56
|
+
className: clsxWithTw('flex flex-wrap gap-1', className),
|
|
57
|
+
style: style,
|
|
58
|
+
children: /*#__PURE__*/ jsx(TooltipProvider, {
|
|
59
|
+
children: groupList.map((group)=>/*#__PURE__*/ jsxs(Tooltip, {
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ jsx(TooltipTrigger, {
|
|
62
|
+
asChild: true,
|
|
63
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
64
|
+
className: clsxWithTw('inline-flex items-center gap-1 rounded px-1.5 py-0.5', 'bg-[rgba(31,35,41,0.06)] text-[rgba(31,35,41,0.7)]', 'max-w-[200px]'),
|
|
65
|
+
children: [
|
|
66
|
+
/*#__PURE__*/ jsx("span", {
|
|
67
|
+
className: "flex-shrink-0 text-[rgba(31,35,41,0.5)]",
|
|
68
|
+
children: /*#__PURE__*/ jsx(GroupIcon, {
|
|
69
|
+
type: group.type,
|
|
70
|
+
size: config.icon
|
|
71
|
+
})
|
|
72
|
+
}),
|
|
73
|
+
/*#__PURE__*/ jsx("span", {
|
|
74
|
+
className: clsxWithTw(config.text, 'truncate leading-tight'),
|
|
75
|
+
children: group.name
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
})
|
|
79
|
+
}),
|
|
80
|
+
/*#__PURE__*/ jsx(TooltipContent, {
|
|
81
|
+
children: group.name
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
}, group.id))
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
export { GroupDisplay };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { IGroupInfo } from './GroupDisplay';
|
|
3
|
+
export interface GroupSelectProps {
|
|
4
|
+
value?: IGroupInfo[];
|
|
5
|
+
onChange?: (value: IGroupInfo[]) => void;
|
|
6
|
+
onSearch: (keyword: string) => Promise<IGroupInfo[]>;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const GroupSelect: React.FC<GroupSelectProps>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { clsxWithTw } from "../../utils/utils.js";
|
|
4
|
+
const GroupSelect = ({ value = [], onChange, onSearch, placeholder = '搜索群组', disabled = false })=>{
|
|
5
|
+
const [keyword, setKeyword] = useState('');
|
|
6
|
+
const [searchResults, setSearchResults] = useState([]);
|
|
7
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
+
const inputRef = useRef(null);
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const debounceRef = useRef(null);
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
if (!keyword.trim()) {
|
|
14
|
+
setSearchResults([]);
|
|
15
|
+
setIsLoading(false);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
setIsLoading(true);
|
|
19
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
20
|
+
debounceRef.current = setTimeout(async ()=>{
|
|
21
|
+
try {
|
|
22
|
+
const results = await onSearch(keyword.trim());
|
|
23
|
+
setSearchResults(results);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Failed to search groups:', error);
|
|
26
|
+
setSearchResults([]);
|
|
27
|
+
} finally{
|
|
28
|
+
setIsLoading(false);
|
|
29
|
+
}
|
|
30
|
+
}, 300);
|
|
31
|
+
return ()=>{
|
|
32
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
33
|
+
};
|
|
34
|
+
}, [
|
|
35
|
+
keyword,
|
|
36
|
+
onSearch
|
|
37
|
+
]);
|
|
38
|
+
useEffect(()=>{
|
|
39
|
+
const handleClickOutside = (e)=>{
|
|
40
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) setIsOpen(false);
|
|
41
|
+
};
|
|
42
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
43
|
+
return ()=>document.removeEventListener('mousedown', handleClickOutside);
|
|
44
|
+
}, []);
|
|
45
|
+
const selectedIds = new Set(value.map((g)=>g.id));
|
|
46
|
+
const handleSelect = (group)=>{
|
|
47
|
+
if (selectedIds.has(group.id)) return;
|
|
48
|
+
onChange?.([
|
|
49
|
+
...value,
|
|
50
|
+
group
|
|
51
|
+
]);
|
|
52
|
+
setKeyword('');
|
|
53
|
+
setSearchResults([]);
|
|
54
|
+
};
|
|
55
|
+
const handleRemove = (groupId)=>{
|
|
56
|
+
onChange?.(value.filter((g)=>g.id !== groupId));
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
59
|
+
ref: containerRef,
|
|
60
|
+
className: "relative w-full",
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ jsxs("div", {
|
|
63
|
+
className: clsxWithTw('flex flex-wrap items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 min-h-[36px]', disabled && 'opacity-50 cursor-not-allowed', isOpen && 'ring-2 ring-ring ring-offset-1'),
|
|
64
|
+
onClick: ()=>{
|
|
65
|
+
if (!disabled) {
|
|
66
|
+
setIsOpen(true);
|
|
67
|
+
inputRef.current?.focus();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
children: [
|
|
71
|
+
value.map((group)=>/*#__PURE__*/ jsxs("span", {
|
|
72
|
+
className: "inline-flex items-center gap-1 rounded bg-[rgba(31,35,41,0.06)] px-1.5 py-0.5 text-xs",
|
|
73
|
+
children: [
|
|
74
|
+
group.name,
|
|
75
|
+
!disabled && /*#__PURE__*/ jsx("button", {
|
|
76
|
+
type: "button",
|
|
77
|
+
className: "ml-0.5 text-[rgba(31,35,41,0.4)] hover:text-[rgba(31,35,41,0.8)]",
|
|
78
|
+
onClick: (e)=>{
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
handleRemove(group.id);
|
|
81
|
+
},
|
|
82
|
+
children: "\xd7"
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
}, group.id)),
|
|
86
|
+
/*#__PURE__*/ jsx("input", {
|
|
87
|
+
ref: inputRef,
|
|
88
|
+
type: "text",
|
|
89
|
+
className: "flex-1 min-w-[80px] border-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground",
|
|
90
|
+
placeholder: 0 === value.length ? placeholder : '',
|
|
91
|
+
value: keyword,
|
|
92
|
+
disabled: disabled,
|
|
93
|
+
onChange: (e)=>{
|
|
94
|
+
setKeyword(e.target.value);
|
|
95
|
+
setIsOpen(true);
|
|
96
|
+
},
|
|
97
|
+
onFocus: ()=>setIsOpen(true)
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
}),
|
|
101
|
+
isOpen && keyword.trim() && /*#__PURE__*/ jsx("div", {
|
|
102
|
+
className: "absolute z-50 mt-1 w-full rounded-md border border-border bg-popover shadow-md",
|
|
103
|
+
children: isLoading ? /*#__PURE__*/ jsx("div", {
|
|
104
|
+
className: "flex items-center justify-center py-4 text-sm text-muted-foreground",
|
|
105
|
+
children: "搜索中..."
|
|
106
|
+
}) : 0 === searchResults.length ? /*#__PURE__*/ jsx("div", {
|
|
107
|
+
className: "flex items-center justify-center py-4 text-sm text-muted-foreground",
|
|
108
|
+
children: "未找到匹配的群组"
|
|
109
|
+
}) : /*#__PURE__*/ jsx("ul", {
|
|
110
|
+
className: "max-h-[200px] overflow-y-auto py-1",
|
|
111
|
+
children: searchResults.map((group)=>{
|
|
112
|
+
const isSelected = selectedIds.has(group.id);
|
|
113
|
+
return /*#__PURE__*/ jsxs("li", {
|
|
114
|
+
className: clsxWithTw('flex items-center gap-2 px-3 py-2 text-sm cursor-pointer', isSelected ? 'bg-[rgba(31,35,41,0.06)] text-muted-foreground cursor-default' : 'hover:bg-[rgba(31,35,41,0.06)]'),
|
|
115
|
+
onClick: ()=>!isSelected && handleSelect(group),
|
|
116
|
+
children: [
|
|
117
|
+
/*#__PURE__*/ jsx("span", {
|
|
118
|
+
className: "truncate",
|
|
119
|
+
children: group.name
|
|
120
|
+
}),
|
|
121
|
+
isSelected && /*#__PURE__*/ jsx("span", {
|
|
122
|
+
className: "ml-auto text-xs text-muted-foreground",
|
|
123
|
+
children: "已选"
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
}, group.id);
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
export { GroupSelect };
|
package/lib/components/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { BatchGetUsersResponse,
|
|
1
|
+
import type { BatchGetUsersResponse, SearchUsersParams, SearchUsersResponse } from './types';
|
|
2
2
|
export type UserServiceConfig = {
|
|
3
3
|
getAppId?: () => string | null | undefined;
|
|
4
4
|
searchUserUrl?: (appId: string) => string;
|
|
5
5
|
listUsersUrl?: (appId: string) => string;
|
|
6
|
-
convertExternalContactUrl?: (appId: string) => string;
|
|
7
6
|
};
|
|
8
7
|
export declare class UserService {
|
|
9
8
|
private config;
|
|
10
9
|
constructor(config?: UserServiceConfig);
|
|
11
10
|
searchUsers(params: SearchUsersParams): Promise<SearchUsersResponse>;
|
|
12
11
|
listUsersByIds(userIds: string[]): Promise<BatchGetUsersResponse>;
|
|
13
|
-
convertExternalContact(larkUserID: string): Promise<ConvertExternalContactResponse>;
|
|
14
12
|
}
|
|
@@ -3,8 +3,7 @@ import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
|
3
3
|
const DEFAULT_CONFIG = {
|
|
4
4
|
getAppId: ()=>getAppId(),
|
|
5
5
|
searchUserUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/search_user` : `/af/app/${appId}/runtime/api/v1/account/search_user`,
|
|
6
|
-
listUsersUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/list_users` : `/af/app/${appId}/runtime/api/v1/account/list_users
|
|
7
|
-
convertExternalContactUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/convert_lark_user` : `/af/app/${appId}/runtime/api/v1/account/convert_lark_user`
|
|
6
|
+
listUsersUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/list_users` : `/af/app/${appId}/runtime/api/v1/account/list_users`
|
|
8
7
|
};
|
|
9
8
|
class UserService {
|
|
10
9
|
config;
|
|
@@ -44,23 +43,5 @@ class UserService {
|
|
|
44
43
|
if (!response.ok) throw new Error('Failed to fetch users by ids');
|
|
45
44
|
return response.json();
|
|
46
45
|
}
|
|
47
|
-
async convertExternalContact(larkUserID) {
|
|
48
|
-
const appId = this.config.getAppId();
|
|
49
|
-
if (!appId) throw new Error('Failed to get appId');
|
|
50
|
-
const response = await fetch(this.config.convertExternalContactUrl(appId), {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
headers: {
|
|
53
|
-
'Content-Type': 'application/json'
|
|
54
|
-
},
|
|
55
|
-
body: JSON.stringify({
|
|
56
|
-
larkUserID
|
|
57
|
-
}),
|
|
58
|
-
credentials: 'include'
|
|
59
|
-
});
|
|
60
|
-
if (!response.ok) throw new Error('Failed to convert external contact');
|
|
61
|
-
const data = await response.json();
|
|
62
|
-
if (!data?.data?.userInfo?.userID) throw new Error('Invalid response from convert external contact');
|
|
63
|
-
return data;
|
|
64
|
-
}
|
|
65
46
|
}
|
|
66
47
|
export { UserService };
|
|
@@ -15,7 +15,6 @@ export type UserInfo = {
|
|
|
15
15
|
userType: '_employee' | '_externalUser' | '_anonymousUser';
|
|
16
16
|
department: DepartmentBasic;
|
|
17
17
|
email?: string;
|
|
18
|
-
tenantName?: string;
|
|
19
18
|
};
|
|
20
19
|
export type DepartmentInfo = {
|
|
21
20
|
departmentID: string;
|
|
@@ -34,7 +33,6 @@ export type SearchUsersParams = {
|
|
|
34
33
|
query?: string;
|
|
35
34
|
offset?: number;
|
|
36
35
|
pageSize?: number;
|
|
37
|
-
searchExternalContact?: boolean;
|
|
38
36
|
};
|
|
39
37
|
export type SearchUsersResponse = {
|
|
40
38
|
data: {
|
|
@@ -43,14 +41,6 @@ export type SearchUsersResponse = {
|
|
|
43
41
|
};
|
|
44
42
|
status_code: string;
|
|
45
43
|
};
|
|
46
|
-
export type ConvertExternalContactResponse = {
|
|
47
|
-
data: {
|
|
48
|
-
userInfo: {
|
|
49
|
-
tenantID: number;
|
|
50
|
-
userID: number;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
44
|
export type BatchGetUsersResponse = {
|
|
55
45
|
data: {
|
|
56
46
|
userInfoMap: Record<string, UserInfo & SearchAvatar>;
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -4,6 +4,92 @@ import { logger } from "../apis/logger.js";
|
|
|
4
4
|
import { getStacktrace } from "../logger/selected-logs.js";
|
|
5
5
|
import { safeStringify } from "./safeStringify.js";
|
|
6
6
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
7
|
+
import { normalizeBasePath } from "./utils.js";
|
|
8
|
+
const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
|
|
9
|
+
function stripBasePath(urlPath) {
|
|
10
|
+
const base = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
11
|
+
if (base && urlPath.startsWith(base)) return urlPath.slice(base.length) || '/';
|
|
12
|
+
return urlPath;
|
|
13
|
+
}
|
|
14
|
+
let _pageRoutes = null;
|
|
15
|
+
function getPageRouteDefinitions() {
|
|
16
|
+
if (_pageRoutes) return _pageRoutes;
|
|
17
|
+
try {
|
|
18
|
+
const raw = process.env.__PAGE_ROUTE_DEFINITIONS__;
|
|
19
|
+
if (raw) {
|
|
20
|
+
const parsed = JSON.parse(raw);
|
|
21
|
+
if (Array.isArray(parsed)) {
|
|
22
|
+
_pageRoutes = parsed;
|
|
23
|
+
return _pageRoutes;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} catch {}
|
|
27
|
+
_pageRoutes = [];
|
|
28
|
+
return _pageRoutes;
|
|
29
|
+
}
|
|
30
|
+
let _apiRoutes = null;
|
|
31
|
+
function getApiRouteDefinitions() {
|
|
32
|
+
if (_apiRoutes) return _apiRoutes;
|
|
33
|
+
try {
|
|
34
|
+
const raw = process.env.__API_ROUTE_DEFINITIONS__;
|
|
35
|
+
if (raw) {
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (Array.isArray(parsed)) {
|
|
38
|
+
_apiRoutes = parsed;
|
|
39
|
+
return _apiRoutes;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch {}
|
|
43
|
+
_apiRoutes = [];
|
|
44
|
+
return _apiRoutes;
|
|
45
|
+
}
|
|
46
|
+
function matchRoute(concretePath, routes) {
|
|
47
|
+
const segments = concretePath.split('/').filter(Boolean);
|
|
48
|
+
for (const route of routes){
|
|
49
|
+
const routeSegments = route.path.split('/').filter(Boolean);
|
|
50
|
+
if (routeSegments.length !== segments.length) continue;
|
|
51
|
+
let match = true;
|
|
52
|
+
for(let i = 0; i < routeSegments.length; i++)if (!routeSegments[i].startsWith(':')) {
|
|
53
|
+
if (routeSegments[i] !== segments[i]) {
|
|
54
|
+
match = false;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (match) return route.path;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function matchApiRoute(method, concretePath) {
|
|
63
|
+
const routes = getApiRouteDefinitions();
|
|
64
|
+
const segments = concretePath.split('/').filter(Boolean);
|
|
65
|
+
for (const route of routes){
|
|
66
|
+
if ('*' !== route.method && route.method !== method) continue;
|
|
67
|
+
const routeSegments = route.path.split('/').filter(Boolean);
|
|
68
|
+
if (routeSegments.length !== segments.length) continue;
|
|
69
|
+
let match = true;
|
|
70
|
+
for(let i = 0; i < routeSegments.length; i++)if (!routeSegments[i].startsWith(':')) {
|
|
71
|
+
if (routeSegments[i] !== segments[i]) {
|
|
72
|
+
match = false;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (match) return route.path;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function getRefererPath() {
|
|
81
|
+
try {
|
|
82
|
+
if ('undefined' == typeof window || !window.location?.pathname) return '/';
|
|
83
|
+
const rawPath = stripBasePath(window.location.pathname);
|
|
84
|
+
return matchRoute(rawPath, getPageRouteDefinitions()) || rawPath;
|
|
85
|
+
} catch {
|
|
86
|
+
return '/';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function getApiField(method, path) {
|
|
90
|
+
const matched = matchApiRoute(method, path);
|
|
91
|
+
return `${method} ${matched || path}`;
|
|
92
|
+
}
|
|
7
93
|
const isValidResponse = (resp)=>null != resp && 'object' == typeof resp && 'config' in resp && null !== resp.config && void 0 !== resp.config && 'object' == typeof resp.config && 'status' in resp && 'number' == typeof resp.status && 'data' in resp;
|
|
8
94
|
async function logResponse(ok, responseOrError) {
|
|
9
95
|
if (isValidResponse(responseOrError)) {
|
|
@@ -139,13 +225,20 @@ function handleSpanEnd(cfg, response, error) {
|
|
|
139
225
|
const errorMessage = error?.message || '未知错误';
|
|
140
226
|
const url = response?.request?.responseURL || errorResponse?.request?.responseURL || cfg.url || "";
|
|
141
227
|
const method = (cfg.method || 'GET').toUpperCase();
|
|
142
|
-
const
|
|
228
|
+
const rawPath = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
|
|
229
|
+
const path = stripBasePath(rawPath);
|
|
230
|
+
const durationMs = startTime ? Date.now() - startTime : void 0;
|
|
231
|
+
const referer_path = getRefererPath();
|
|
232
|
+
const api = getApiField(method, path);
|
|
233
|
+
const type = APP_CLIENT_API_LOG_TYPE;
|
|
143
234
|
const logData = {
|
|
144
235
|
method,
|
|
145
236
|
path,
|
|
146
237
|
url,
|
|
147
|
-
duration_ms:
|
|
148
|
-
status: response ? response.status : errorResponse.status || 0
|
|
238
|
+
duration_ms: durationMs,
|
|
239
|
+
status: response ? response.status : errorResponse.status || 0,
|
|
240
|
+
referer_path,
|
|
241
|
+
type
|
|
149
242
|
};
|
|
150
243
|
if (error) logData.error_message = errorMessage;
|
|
151
244
|
if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
|
|
@@ -158,7 +251,19 @@ function handleSpanEnd(cfg, response, error) {
|
|
|
158
251
|
const responseData = response?.data || errorResponse?.data;
|
|
159
252
|
if (responseData) logData.response = responseData;
|
|
160
253
|
const level = error ? 'ERROR' : 'INFO';
|
|
161
|
-
observable.log(level, safeStringify(logData), {
|
|
254
|
+
observable.log(level, safeStringify(logData), {
|
|
255
|
+
referer_path,
|
|
256
|
+
api,
|
|
257
|
+
type,
|
|
258
|
+
duration_ms: durationMs
|
|
259
|
+
}, currentSpan);
|
|
260
|
+
if ('function' == typeof currentSpan.setAttributes) currentSpan.setAttributes({
|
|
261
|
+
referer_path,
|
|
262
|
+
api,
|
|
263
|
+
duration_ms: durationMs,
|
|
264
|
+
module: 'app_web',
|
|
265
|
+
source_type: 'platform'
|
|
266
|
+
});
|
|
162
267
|
'function' == typeof currentSpan.end && currentSpan.end();
|
|
163
268
|
} catch (e) {
|
|
164
269
|
console.error('[AxiosTrace] Log span failed:', e);
|
|
@@ -240,6 +345,11 @@ function initAxiosConfig(axiosInstance) {
|
|
|
240
345
|
const csrfToken = window.csrfToken;
|
|
241
346
|
if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
|
|
242
347
|
if ('undefined' != typeof window && window.location?.pathname) config.headers['X-Page-Route'] = window.location.pathname;
|
|
348
|
+
const refererPath = getRefererPath();
|
|
349
|
+
config.headers['Rpc-Persist-Apaas-Observability-Referer-Path'] = refererPath;
|
|
350
|
+
const reqMethod = (config.method || 'GET').toUpperCase();
|
|
351
|
+
const requestPath = stripBasePath((config.url || '').split('?')[0]);
|
|
352
|
+
config.headers['Rpc-Persist-Apaas-Observability-Api'] = getApiField(reqMethod, requestPath);
|
|
243
353
|
return config;
|
|
244
354
|
}, (error)=>Promise.reject(error));
|
|
245
355
|
instance.interceptors.response.use((response)=>response, (error)=>{
|
package/lib/utils/hmr-api.d.ts
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
* @see docs/RFC_HMR_API.md
|
|
10
10
|
*/
|
|
11
11
|
export interface HmrApi {
|
|
12
|
+
/**
|
|
13
|
+
* 注册 HMR 更新前回调(模块替换之前触发)
|
|
14
|
+
* @param callback 回调函数
|
|
15
|
+
* @returns cleanup 函数,用于取消注册
|
|
16
|
+
*/
|
|
17
|
+
onBeforeApply?(callback: () => void): () => void;
|
|
12
18
|
/**
|
|
13
19
|
* 注册 HMR 成功回调
|
|
14
20
|
* @param callback 成功回调函数
|
|
@@ -24,7 +30,7 @@ export interface HmrApi {
|
|
|
24
30
|
}
|
|
25
31
|
declare global {
|
|
26
32
|
interface Window {
|
|
27
|
-
__VITE_HMR__?: HmrApi
|
|
33
|
+
__VITE_HMR__?: Required<HmrApi>;
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.28-alpha.
|
|
3
|
+
"version": "1.2.28-alpha.23",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -98,12 +98,12 @@
|
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
|
-
"@data-loom/js": "0.4.
|
|
101
|
+
"@data-loom/js": "0.4.12",
|
|
102
102
|
"@lark-apaas/aily-web-sdk": "^0.0.7",
|
|
103
|
-
"@lark-apaas/auth-sdk": "
|
|
103
|
+
"@lark-apaas/auth-sdk": "0.1.0-alpha.62",
|
|
104
104
|
"@lark-apaas/client-capability": "^0.1.6",
|
|
105
105
|
"@lark-apaas/internal-slardar": "^0.0.3",
|
|
106
|
-
"@lark-apaas/miaoda-inspector": "^1.0.
|
|
106
|
+
"@lark-apaas/miaoda-inspector": "^1.0.21",
|
|
107
107
|
"@lark-apaas/observable-web": "^1.0.5",
|
|
108
108
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
109
109
|
"@radix-ui/react-popover": "^1.1.15",
|