@lark-apaas/client-toolkit 1.2.2 → 1.2.3
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/tools/services.d.ts +1 -0
- package/lib/apis/tools/services.js +1 -0
- package/lib/integrations/services/DepartmentService.d.ts +10 -0
- package/lib/integrations/services/DepartmentService.js +29 -0
- package/lib/integrations/services/UserProfileService.d.ts +14 -0
- package/lib/integrations/services/UserProfileService.js +36 -0
- package/lib/integrations/services/UserService.d.ts +12 -0
- package/lib/integrations/services/UserService.js +46 -0
- package/lib/integrations/services/index.d.ts +4 -0
- package/lib/integrations/services/index.js +4 -0
- package/lib/integrations/services/types.d.ts +91 -0
- package/lib/integrations/services/types.js +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../integrations/services';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../integrations/services/index.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SearchDepartmentsParams, SearchDepartmentsResponse } from './types';
|
|
2
|
+
export type DepartmentServiceConfig = {
|
|
3
|
+
getAppId?: () => string | null | undefined;
|
|
4
|
+
searchDepartmentUrl?: (appId: string) => string;
|
|
5
|
+
};
|
|
6
|
+
export declare class DepartmentService {
|
|
7
|
+
private config;
|
|
8
|
+
constructor(config?: DepartmentServiceConfig);
|
|
9
|
+
searchDepartments(params: SearchDepartmentsParams): Promise<SearchDepartmentsResponse>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
const DEFAULT_CONFIG = {
|
|
3
|
+
getAppId: ()=>getAppId(window.location.pathname),
|
|
4
|
+
searchDepartmentUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/search_department`
|
|
5
|
+
};
|
|
6
|
+
class DepartmentService {
|
|
7
|
+
config;
|
|
8
|
+
constructor(config = {}){
|
|
9
|
+
this.config = {
|
|
10
|
+
...DEFAULT_CONFIG,
|
|
11
|
+
...config
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async searchDepartments(params) {
|
|
15
|
+
const appId = this.config.getAppId();
|
|
16
|
+
if (!appId) throw new Error('Failed to get appId');
|
|
17
|
+
const response = await fetch(this.config.searchDepartmentUrl(appId), {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(params),
|
|
23
|
+
credentials: 'include'
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) throw new Error('Failed to search departments');
|
|
26
|
+
return response.json();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export { DepartmentService };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AccountType, UserProfileData } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 获取 CDN 资源 URL
|
|
4
|
+
*/
|
|
5
|
+
export declare function getAssetsUrl(path: string): string;
|
|
6
|
+
export type UserProfileServiceConfig = {
|
|
7
|
+
getAppId?: () => string | null | undefined;
|
|
8
|
+
userProfileUrl?: (appId: string) => string;
|
|
9
|
+
};
|
|
10
|
+
export declare class UserProfileService {
|
|
11
|
+
private config;
|
|
12
|
+
constructor(config?: UserProfileServiceConfig);
|
|
13
|
+
getUserProfile(userId: string, accountType?: AccountType, signal?: AbortSignal): Promise<UserProfileData>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
const CDN_HOST = 'https://lf3-static.bytednsdoc.com';
|
|
3
|
+
function getAssetsUrl(path) {
|
|
4
|
+
return `${CDN_HOST}${path}`;
|
|
5
|
+
}
|
|
6
|
+
const DEFAULT_CONFIG = {
|
|
7
|
+
getAppId: ()=>getAppId(window.location.pathname),
|
|
8
|
+
userProfileUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/user_profile`
|
|
9
|
+
};
|
|
10
|
+
class UserProfileService {
|
|
11
|
+
config;
|
|
12
|
+
constructor(config = {}){
|
|
13
|
+
this.config = {
|
|
14
|
+
...DEFAULT_CONFIG,
|
|
15
|
+
...config
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async getUserProfile(userId, accountType = 'apaas', signal) {
|
|
19
|
+
const appId = this.config.getAppId();
|
|
20
|
+
if (!appId) throw new Error('Failed to get appId');
|
|
21
|
+
const params = new URLSearchParams();
|
|
22
|
+
if ('lark' === accountType) params.append('larkUserID', userId);
|
|
23
|
+
else params.append('userID', userId);
|
|
24
|
+
const response = await fetch(`${this.config.userProfileUrl(appId)}?${params.toString()}`, {
|
|
25
|
+
signal,
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json'
|
|
28
|
+
},
|
|
29
|
+
credentials: 'include'
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) throw new Error(`Failed to fetch user profile: ${response.status}`);
|
|
32
|
+
const data = await response.json();
|
|
33
|
+
return data.data;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export { UserProfileService, getAssetsUrl };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BatchGetUsersResponse, SearchUsersParams, SearchUsersResponse } from './types';
|
|
2
|
+
export type UserServiceConfig = {
|
|
3
|
+
getAppId?: () => string | null | undefined;
|
|
4
|
+
searchUserUrl?: (appId: string) => string;
|
|
5
|
+
listUsersUrl?: (appId: string) => string;
|
|
6
|
+
};
|
|
7
|
+
export declare class UserService {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(config?: UserServiceConfig);
|
|
10
|
+
searchUsers(params: SearchUsersParams): Promise<SearchUsersResponse>;
|
|
11
|
+
listUsersByIds(userIds: string[]): Promise<BatchGetUsersResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
const DEFAULT_CONFIG = {
|
|
3
|
+
getAppId: ()=>getAppId(window.location.pathname),
|
|
4
|
+
searchUserUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/search_user`,
|
|
5
|
+
listUsersUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/list_users`
|
|
6
|
+
};
|
|
7
|
+
class UserService {
|
|
8
|
+
config;
|
|
9
|
+
constructor(config = {}){
|
|
10
|
+
this.config = {
|
|
11
|
+
...DEFAULT_CONFIG,
|
|
12
|
+
...config
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async searchUsers(params) {
|
|
16
|
+
const appId = this.config.getAppId();
|
|
17
|
+
if (!appId) throw new Error('Failed to get appId');
|
|
18
|
+
const response = await fetch(this.config.searchUserUrl(appId), {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify(params),
|
|
24
|
+
credentials: 'include'
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) throw new Error('Failed to search users');
|
|
27
|
+
return response.json();
|
|
28
|
+
}
|
|
29
|
+
async listUsersByIds(userIds) {
|
|
30
|
+
const appId = this.config.getAppId();
|
|
31
|
+
if (!appId) throw new Error('Failed to get appId');
|
|
32
|
+
const response = await fetch(this.config.listUsersUrl(appId), {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json'
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({
|
|
38
|
+
userIDList: userIds.map((id)=>Number(id))
|
|
39
|
+
}),
|
|
40
|
+
credentials: 'include'
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) throw new Error('Failed to fetch users by ids');
|
|
43
|
+
return response.json();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export { UserService };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type I18nText = {
|
|
2
|
+
zh_cn: string;
|
|
3
|
+
en_us?: string;
|
|
4
|
+
ja_jp?: string;
|
|
5
|
+
};
|
|
6
|
+
export type DepartmentBasic = {
|
|
7
|
+
departmentID: string;
|
|
8
|
+
name: I18nText;
|
|
9
|
+
};
|
|
10
|
+
export type UserInfo = {
|
|
11
|
+
userID: string;
|
|
12
|
+
larkUserID: string;
|
|
13
|
+
name: I18nText;
|
|
14
|
+
avatar: string;
|
|
15
|
+
userType: '_employee' | '_externalUser' | '_anonymousUser';
|
|
16
|
+
department: DepartmentBasic;
|
|
17
|
+
};
|
|
18
|
+
export type DepartmentInfo = {
|
|
19
|
+
departmentID: string;
|
|
20
|
+
larkDepartmentID: string;
|
|
21
|
+
name: I18nText;
|
|
22
|
+
};
|
|
23
|
+
export type AccountType = 'apaas' | 'lark';
|
|
24
|
+
export type SearchAvatar = {
|
|
25
|
+
avatar: {
|
|
26
|
+
image: {
|
|
27
|
+
large: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type SearchUsersParams = {
|
|
32
|
+
query?: string;
|
|
33
|
+
offset?: number;
|
|
34
|
+
pageSize?: number;
|
|
35
|
+
};
|
|
36
|
+
export type SearchUsersResponse = {
|
|
37
|
+
data: {
|
|
38
|
+
userList: UserInfo[];
|
|
39
|
+
total: number;
|
|
40
|
+
};
|
|
41
|
+
status_code: string;
|
|
42
|
+
};
|
|
43
|
+
export type BatchGetUsersResponse = {
|
|
44
|
+
data: {
|
|
45
|
+
userInfoMap: Record<string, UserInfo & SearchAvatar>;
|
|
46
|
+
baseResp?: {
|
|
47
|
+
statusCode?: number;
|
|
48
|
+
statusMessage?: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export type SearchDepartmentsParams = {
|
|
53
|
+
query?: string;
|
|
54
|
+
offset?: number;
|
|
55
|
+
pageSize?: number;
|
|
56
|
+
};
|
|
57
|
+
export type SearchDepartmentsResponse = {
|
|
58
|
+
data: {
|
|
59
|
+
departmentList: DepartmentInfo[];
|
|
60
|
+
total: number;
|
|
61
|
+
};
|
|
62
|
+
status_code: string;
|
|
63
|
+
};
|
|
64
|
+
export type UserProfileAccountStatus = 0 | 1 | 2 | 3 | 4;
|
|
65
|
+
export type SimpleUserProfileInfo = {
|
|
66
|
+
name?: string;
|
|
67
|
+
avatar?: string;
|
|
68
|
+
email?: string;
|
|
69
|
+
userStatus: UserProfileAccountStatus;
|
|
70
|
+
userType: '_employee' | '_externalUser';
|
|
71
|
+
};
|
|
72
|
+
export type LarkCardParam = {
|
|
73
|
+
needRedirect?: boolean;
|
|
74
|
+
redirectURL?: string;
|
|
75
|
+
larkAppID: string;
|
|
76
|
+
jsAPITicket: string;
|
|
77
|
+
larkOpenID: string;
|
|
78
|
+
targetLarkOpenID: string;
|
|
79
|
+
};
|
|
80
|
+
export type SimpleUserProfileData = {
|
|
81
|
+
useLarkCard: false;
|
|
82
|
+
userProfileInfo: SimpleUserProfileInfo;
|
|
83
|
+
};
|
|
84
|
+
export type OfficialUserProfileData = {
|
|
85
|
+
useLarkCard: true;
|
|
86
|
+
larkCardParam: LarkCardParam;
|
|
87
|
+
};
|
|
88
|
+
export type UserProfileData = SimpleUserProfileData | OfficialUserProfileData;
|
|
89
|
+
export type UserProfileResponse = {
|
|
90
|
+
data: UserProfileData;
|
|
91
|
+
};
|
|
File without changes
|