@lark-apaas/client-toolkit 1.2.28-alpha.6 → 1.2.28-alpha.61
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/udt-types.d.ts +4 -0
- package/lib/auth.d.ts +1 -1
- package/lib/auth.js +2 -2
- package/lib/hooks/useCurrentUserProfile.d.ts +18 -3
- package/lib/hooks/useCurrentUserProfile.js +15 -1
- package/lib/integrations/getCurrentUserProfile.d.ts +7 -1
- package/lib/integrations/services/UserService.d.ts +3 -1
- package/lib/integrations/services/UserService.js +20 -1
- package/lib/integrations/services/types.d.ts +10 -0
- package/lib/utils/axiosConfig.js +25 -2
- package/lib/utils/hmr-api.d.ts +7 -1
- package/package.json +4 -4
package/lib/apis/udt-types.d.ts
CHANGED
package/lib/auth.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CanRole, AbilityContext, ROLE_SUBJECT } from '@lark-apaas/auth-sdk';
|
|
1
|
+
export { CanRole, AbilityContext, ROLE_SUBJECT, useAuth, } from '@lark-apaas/auth-sdk';
|
package/lib/auth.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AbilityContext, CanRole, ROLE_SUBJECT } from "@lark-apaas/auth-sdk";
|
|
2
|
-
export { AbilityContext, CanRole, ROLE_SUBJECT };
|
|
1
|
+
import { AbilityContext, CanRole, ROLE_SUBJECT, useAuth } from "@lark-apaas/auth-sdk";
|
|
2
|
+
export { AbilityContext, CanRole, ROLE_SUBJECT, useAuth };
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { IUserProfile } from '../apis/udt-types';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* useCurrentUserProfile 的返回类型。
|
|
4
|
+
* 初始状态为空对象 `{}`(所有字段均为 undefined),异步获取用户信息后字段才会被填充。
|
|
5
|
+
* 使用时必须通过可选链或空值合并进行安全访问,如 `userInfo?.user_id`。
|
|
6
|
+
* 判断是否已加载完成应使用 `if (!userInfo?.user_id)` 而非 `if (!userInfo)`(因为空对象是 truthy)。
|
|
7
|
+
*/
|
|
8
|
+
export type ICompatibilityUserProfile = Partial<IUserProfile & {
|
|
3
9
|
/**
|
|
4
10
|
* @deprecated please use `name`
|
|
5
11
|
*/
|
|
@@ -8,5 +14,14 @@ export interface ICompatibilityUserProfile extends IUserProfile {
|
|
|
8
14
|
* @deprecated please use `avatar`
|
|
9
15
|
*/
|
|
10
16
|
userAvatar: string;
|
|
11
|
-
}
|
|
12
|
-
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
|
+
}>;
|
|
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
|
|
2
2
|
import { logger } from "../logger/index.js";
|
|
3
3
|
import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
|
|
4
4
|
import { getDataloom } from "../integrations/dataloom.js";
|
|
5
|
-
import { isSparkRuntime } from "../utils/utils.js";
|
|
5
|
+
import { isSparkRuntime, normalizeBasePath } from "../utils/utils.js";
|
|
6
6
|
function getNameFromArray(nameArray) {
|
|
7
7
|
if (!nameArray || 0 === nameArray.length) return;
|
|
8
8
|
const chineseName = nameArray.find((item)=>2052 === item.language_code);
|
|
@@ -34,6 +34,20 @@ const useCurrentUserProfile = ()=>{
|
|
|
34
34
|
userName: userName,
|
|
35
35
|
userAvatar: info?.avatar?.image?.large
|
|
36
36
|
};
|
|
37
|
+
try {
|
|
38
|
+
const csrfToken = document.cookie.match(/suda-csrf-token=([^;]+)/)?.[1] || '';
|
|
39
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
40
|
+
const resp = await fetch(`${basePath}/api/authnpaas/lark-user-id`, {
|
|
41
|
+
credentials: 'include',
|
|
42
|
+
headers: {
|
|
43
|
+
'x-suda-csrf-token': csrfToken
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (resp.ok) {
|
|
47
|
+
const data = await resp.json();
|
|
48
|
+
if (data?.lark_user_id) newUserInfo.lark_user_id = data.lark_user_id;
|
|
49
|
+
}
|
|
50
|
+
} catch {}
|
|
37
51
|
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', newUserInfo);
|
|
38
52
|
setUserInfo(newUserInfo);
|
|
39
53
|
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { IUserProfile } from '../apis/udt-types';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* 获取当前用户信息。
|
|
4
|
+
* 返回 Partial<IUserProfile>,因为初始值来自 window._userInfo,
|
|
5
|
+
* 该值在运行时始终为空对象 {},所有字段均为 undefined。
|
|
6
|
+
* 异步获取用户信息后才会被填充为完整的 IUserProfile。
|
|
7
|
+
*/
|
|
8
|
+
export declare function getCurrentUserProfile(): Partial<IUserProfile>;
|
|
3
9
|
/**
|
|
4
10
|
* @deprecated 请使用 getCurrentUserProfile 代替
|
|
5
11
|
*/
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { BatchGetUsersResponse, SearchUsersParams, SearchUsersResponse } from './types';
|
|
1
|
+
import type { BatchGetUsersResponse, ConvertExternalContactResponse, 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;
|
|
6
7
|
};
|
|
7
8
|
export declare class UserService {
|
|
8
9
|
private config;
|
|
9
10
|
constructor(config?: UserServiceConfig);
|
|
10
11
|
searchUsers(params: SearchUsersParams): Promise<SearchUsersResponse>;
|
|
11
12
|
listUsersByIds(userIds: string[]): Promise<BatchGetUsersResponse>;
|
|
13
|
+
convertExternalContact(larkUserID: string): Promise<ConvertExternalContactResponse>;
|
|
12
14
|
}
|
|
@@ -3,7 +3,8 @@ 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
|
|
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`
|
|
7
8
|
};
|
|
8
9
|
class UserService {
|
|
9
10
|
config;
|
|
@@ -43,5 +44,23 @@ class UserService {
|
|
|
43
44
|
if (!response.ok) throw new Error('Failed to fetch users by ids');
|
|
44
45
|
return response.json();
|
|
45
46
|
}
|
|
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
|
+
}
|
|
46
65
|
}
|
|
47
66
|
export { UserService };
|
|
@@ -15,6 +15,7 @@ export type UserInfo = {
|
|
|
15
15
|
userType: '_employee' | '_externalUser' | '_anonymousUser';
|
|
16
16
|
department: DepartmentBasic;
|
|
17
17
|
email?: string;
|
|
18
|
+
tenantName?: string;
|
|
18
19
|
};
|
|
19
20
|
export type DepartmentInfo = {
|
|
20
21
|
departmentID: string;
|
|
@@ -33,6 +34,7 @@ export type SearchUsersParams = {
|
|
|
33
34
|
query?: string;
|
|
34
35
|
offset?: number;
|
|
35
36
|
pageSize?: number;
|
|
37
|
+
searchExternalContact?: boolean;
|
|
36
38
|
};
|
|
37
39
|
export type SearchUsersResponse = {
|
|
38
40
|
data: {
|
|
@@ -41,6 +43,14 @@ export type SearchUsersResponse = {
|
|
|
41
43
|
};
|
|
42
44
|
status_code: string;
|
|
43
45
|
};
|
|
46
|
+
export type ConvertExternalContactResponse = {
|
|
47
|
+
data: {
|
|
48
|
+
userInfo: {
|
|
49
|
+
tenantID: number;
|
|
50
|
+
userID: number;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
44
54
|
export type BatchGetUsersResponse = {
|
|
45
55
|
data: {
|
|
46
56
|
userInfoMap: Record<string, UserInfo & SearchAvatar>;
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -372,7 +372,18 @@ function initAxiosConfig(axiosInstance) {
|
|
|
372
372
|
name: 'toolkit_axios_403_downgrade',
|
|
373
373
|
categories: {
|
|
374
374
|
url: String(error.config?.url || ''),
|
|
375
|
-
method: String(error.config?.method || '')
|
|
375
|
+
method: String(error.config?.method || ''),
|
|
376
|
+
...'production' !== process.env.NODE_ENV && {
|
|
377
|
+
responseData: (()=>{
|
|
378
|
+
try {
|
|
379
|
+
const data = error.response?.data;
|
|
380
|
+
if (!data) return '';
|
|
381
|
+
return 'string' == typeof data ? data.slice(0, 512) : JSON.stringify(data).slice(0, 512);
|
|
382
|
+
} catch {
|
|
383
|
+
return '';
|
|
384
|
+
}
|
|
385
|
+
})()
|
|
386
|
+
}
|
|
376
387
|
}
|
|
377
388
|
});
|
|
378
389
|
return error.response;
|
|
@@ -383,7 +394,19 @@ function initAxiosConfig(axiosInstance) {
|
|
|
383
394
|
categories: {
|
|
384
395
|
url: String(error.config?.url || ''),
|
|
385
396
|
method: String(error.config?.method || ''),
|
|
386
|
-
status: String(error.response?.status || '')
|
|
397
|
+
status: String(error.response?.status || ''),
|
|
398
|
+
...'production' !== process.env.NODE_ENV && {
|
|
399
|
+
errorMessage: String(error.message || ''),
|
|
400
|
+
responseData: (()=>{
|
|
401
|
+
try {
|
|
402
|
+
const data = error.response?.data;
|
|
403
|
+
if (!data) return '';
|
|
404
|
+
return 'string' == typeof data ? data.slice(0, 512) : JSON.stringify(data).slice(0, 512);
|
|
405
|
+
} catch {
|
|
406
|
+
return '';
|
|
407
|
+
}
|
|
408
|
+
})()
|
|
409
|
+
}
|
|
387
410
|
}
|
|
388
411
|
});
|
|
389
412
|
return Promise.reject(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.61",
|
|
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.13",
|
|
102
102
|
"@lark-apaas/aily-web-sdk": "^0.0.7",
|
|
103
|
-
"@lark-apaas/auth-sdk": "^0.1.
|
|
103
|
+
"@lark-apaas/auth-sdk": "^0.1.3",
|
|
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.22",
|
|
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",
|