@lark-apaas/client-toolkit 1.2.2-test.2 → 1.2.2-test.4
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/integrations/services/UserProfileService.d.ts +14 -0
- package/lib/integrations/services/UserProfileService.js +36 -0
- package/lib/integrations/services/index.d.ts +1 -0
- package/lib/integrations/services/index.js +1 -0
- package/lib/integrations/services/types.d.ts +28 -0
- package/package.json +1 -1
|
@@ -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 };
|
|
@@ -61,3 +61,31 @@ export type SearchDepartmentsResponse = {
|
|
|
61
61
|
};
|
|
62
62
|
status_code: string;
|
|
63
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
|
+
};
|