@lark-apaas/client-toolkit 1.2.44-alpha.1 → 1.2.44-alpha.2
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/auth.d.ts +2 -0
- package/lib/auth.js +2 -2
- package/lib/components/User/UserSelect.js +3 -5
- package/lib/hooks/useCurrentUserProfile.js +2 -3
- package/lib/hooks/useLogout.js +2 -3
- package/lib/integrations/dataloom.d.ts +1 -1
- package/lib/integrations/dataloom.js +8 -9
- package/lib/locales/messages.js +24 -0
- package/lib/utils/axiosConfig.js +10 -6
- package/lib/utils/locale.d.ts +11 -3
- package/lib/utils/locale.js +38 -2
- package/lib/utils/postMessage.js +6 -0
- package/lib/utils/requestManager.js +2 -4
- package/package.json +4 -4
package/lib/auth.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
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, 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 };
|
|
1
|
+
import { AbilityContext, AccountClient, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, authClient, useAuth, useCan, useUserPermissions } from "@lark-apaas/auth-sdk";
|
|
2
|
+
export { AbilityContext, AccountClient, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, authClient, useAuth, useCan, useUserPermissions };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import react from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { authClient } from "@lark-apaas/auth-sdk";
|
|
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,8 +67,7 @@ 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
|
|
71
|
-
const response = await dataloom.service.user.getByIds(normalizedIds);
|
|
70
|
+
const response = await authClient.user.getByIds(normalizedIds);
|
|
72
71
|
const fetchedList = Array.isArray(response?.data) ? response?.data : Array.isArray(response?.data?.user_list) ? response?.data?.user_list : [];
|
|
73
72
|
const fetchedMap = new Map();
|
|
74
73
|
fetchedList.forEach((profile)=>{
|
|
@@ -115,8 +114,7 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
|
|
|
115
114
|
const fetchUsersImpl = react.useCallback(async (search)=>{
|
|
116
115
|
if (fetchUsers) return fetchUsers(search);
|
|
117
116
|
try {
|
|
118
|
-
const
|
|
119
|
-
const { data } = await dataloom.service.user.search({
|
|
117
|
+
const { data } = await authClient.user.search({
|
|
120
118
|
name: search,
|
|
121
119
|
pageSize: 20
|
|
122
120
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
+
import { authClient } from "@lark-apaas/auth-sdk";
|
|
2
3
|
import { logger } from "../logger/index.js";
|
|
3
4
|
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) {
|
|
@@ -35,8 +35,7 @@ const useCurrentUserProfile = ()=>{
|
|
|
35
35
|
useEffect(()=>{
|
|
36
36
|
let cancelled = false;
|
|
37
37
|
const fetchAndSetUserInfo = async ()=>{
|
|
38
|
-
const
|
|
39
|
-
const result = await dataloom?.service?.session?.getUserInfo();
|
|
38
|
+
const result = await authClient.session.getUserInfo();
|
|
40
39
|
if (cancelled) return;
|
|
41
40
|
const info = result?.data?.user_info;
|
|
42
41
|
const userName = getNameFromArray(info?.name);
|
package/lib/hooks/useLogout.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { authClient } from "@lark-apaas/auth-sdk";
|
|
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
|
-
|
|
10
|
-
await dataloom.service.session.signOut();
|
|
9
|
+
await authClient.session.signOut();
|
|
11
10
|
} catch (error) {
|
|
12
11
|
console.error('登出失败', error);
|
|
13
12
|
} finally{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const createDataLoomClient: (url?: string, pat?: string) => import("@
|
|
1
|
+
declare const createDataLoomClient: (url?: string, pat?: string) => import("@lark-apaas/dataloom").DataloomClient;
|
|
2
2
|
/** 获取dataloom实例 */
|
|
3
3
|
export declare function getDataloom(): Promise<ReturnType<typeof createDataLoomClient>>;
|
|
4
4
|
export {};
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { splitWorkspaceUrl } from "../utils/url.js";
|
|
2
|
-
import { createClient } from "@
|
|
2
|
+
import { createClient } from "@lark-apaas/dataloom";
|
|
3
|
+
import { authClient } from "@lark-apaas/auth-sdk";
|
|
3
4
|
import { getAppId } from "../utils/getAppId.js";
|
|
4
5
|
import { getAppPublished } from "../utils/getInitialInfo.js";
|
|
5
6
|
const createDataLoomClient = (url, pat)=>{
|
|
6
|
-
const { baseUrl
|
|
7
|
-
baseUrl: ''
|
|
8
|
-
workspace: ''
|
|
7
|
+
const { baseUrl } = url ? splitWorkspaceUrl(url) : {
|
|
8
|
+
baseUrl: ''
|
|
9
9
|
};
|
|
10
10
|
const appId = getAppId();
|
|
11
|
-
return createClient(baseUrl, pat,
|
|
11
|
+
return createClient(baseUrl, pat, {
|
|
12
12
|
global: {
|
|
13
13
|
enableDataloomLog: 'production' !== process.env.NODE_ENV,
|
|
14
14
|
requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
|
|
15
15
|
brandName: 'miaoda',
|
|
16
16
|
appId,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
accountServices: {
|
|
18
|
+
user: authClient.user,
|
|
19
|
+
session: authClient.session
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
});
|
package/lib/locales/messages.js
CHANGED
|
@@ -102,6 +102,30 @@ const messages_messages = {
|
|
|
102
102
|
'userProfile.label.email': {
|
|
103
103
|
zh: '邮箱',
|
|
104
104
|
en: 'Email'
|
|
105
|
+
},
|
|
106
|
+
'axios.log.requestSuccess': {
|
|
107
|
+
zh: '请求成功:',
|
|
108
|
+
en: 'Request succeeded: '
|
|
109
|
+
},
|
|
110
|
+
'axios.log.requestFailed': {
|
|
111
|
+
zh: '请求失败:',
|
|
112
|
+
en: 'Request failed: '
|
|
113
|
+
},
|
|
114
|
+
'axios.log.networkFailed': {
|
|
115
|
+
zh: '网络请求失败:',
|
|
116
|
+
en: 'Network request failed: '
|
|
117
|
+
},
|
|
118
|
+
'axios.log.noResponseOrConfig': {
|
|
119
|
+
zh: '请求失败:无响应对象或配置信息',
|
|
120
|
+
en: 'Request failed: no response object or config'
|
|
121
|
+
},
|
|
122
|
+
'axios.log.forbidden': {
|
|
123
|
+
zh: '请求被拒绝(403):{method} {url}',
|
|
124
|
+
en: 'Request rejected (403): {method} {url}'
|
|
125
|
+
},
|
|
126
|
+
'axios.log.unknownError': {
|
|
127
|
+
zh: '未知错误',
|
|
128
|
+
en: 'Unknown error'
|
|
105
129
|
}
|
|
106
130
|
};
|
|
107
131
|
const messages = messages_messages;
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getStacktrace } from "../logger/selected-logs.js";
|
|
|
5
5
|
import { safeStringify } from "./safeStringify.js";
|
|
6
6
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
7
7
|
import { normalizeBasePath } from "./utils.js";
|
|
8
|
+
import { t } from "../locales/index.js";
|
|
8
9
|
const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
|
|
9
10
|
function stripBasePath(urlPath) {
|
|
10
11
|
const base = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
@@ -95,8 +96,8 @@ async function logResponse(ok, responseOrError) {
|
|
|
95
96
|
if (isValidResponse(responseOrError)) {
|
|
96
97
|
const response = responseOrError;
|
|
97
98
|
const okToTextMap = {
|
|
98
|
-
success: '
|
|
99
|
-
error: '
|
|
99
|
+
success: t('axios.log.requestSuccess'),
|
|
100
|
+
error: t('axios.log.requestFailed')
|
|
100
101
|
};
|
|
101
102
|
const realOK = 'success' === ok && response.status >= 200 && response.status < 300;
|
|
102
103
|
const method = (response.config.method || 'GET').toUpperCase();
|
|
@@ -154,13 +155,13 @@ async function logResponse(ok, responseOrError) {
|
|
|
154
155
|
const error = responseOrError;
|
|
155
156
|
if (error && error.config && 'object' == typeof error.config) {
|
|
156
157
|
const errorType = error.code || 'UNKNOWN_ERROR';
|
|
157
|
-
const errorMessage = error.message || '
|
|
158
|
+
const errorMessage = error.message || t('axios.log.unknownError');
|
|
158
159
|
const method = (error.config.method || 'GET').toUpperCase();
|
|
159
160
|
const url = error.config.url || '';
|
|
160
161
|
const startTime = error.config._startTime;
|
|
161
162
|
const duration = startTime ? Date.now() - startTime : 0;
|
|
162
163
|
const parts = [
|
|
163
|
-
'
|
|
164
|
+
t('axios.log.networkFailed'),
|
|
164
165
|
method,
|
|
165
166
|
' ',
|
|
166
167
|
url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, ''),
|
|
@@ -210,7 +211,7 @@ async function logResponse(ok, responseOrError) {
|
|
|
210
211
|
logger.log({
|
|
211
212
|
level: 'error',
|
|
212
213
|
args: [
|
|
213
|
-
'
|
|
214
|
+
t('axios.log.noResponseOrConfig')
|
|
214
215
|
],
|
|
215
216
|
meta: {}
|
|
216
217
|
});
|
|
@@ -360,7 +361,10 @@ function initAxiosConfig(axiosInstance) {
|
|
|
360
361
|
logger.log({
|
|
361
362
|
level: 'warn',
|
|
362
363
|
args: [
|
|
363
|
-
|
|
364
|
+
t('axios.log.forbidden', {
|
|
365
|
+
method,
|
|
366
|
+
url
|
|
367
|
+
}),
|
|
364
368
|
{
|
|
365
369
|
状态码: 403,
|
|
366
370
|
返回数据: error.response.data
|
package/lib/utils/locale.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 统一的语言判断方法。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 生产环境(`process.env.NODE_ENV === 'production'`):
|
|
5
|
+
* 只看浏览器容器语言(navigator.language)。
|
|
6
|
+
*
|
|
7
|
+
* 非生产环境(沙箱预览场景):
|
|
8
|
+
* 优先级 query > localStorage > navigator。
|
|
9
|
+
* URL query `locale`(值为 `zh_CN` / `en_US`)由宿主平台(miaoda)
|
|
10
|
+
* 通过 iframe src 透传,确保产物内的语言与宿主一致;
|
|
11
|
+
* 读到 query 时会同步写入 localStorage,便于后续无 query 的跳转/刷新场景使用。
|
|
12
|
+
*
|
|
13
|
+
* 返回标准化 locale code:'zh' | 'en'。
|
|
14
|
+
* 目前只区分中英文,未来扩展时在此调整。
|
|
7
15
|
*/
|
|
8
16
|
export type Locale = 'zh' | 'en';
|
|
9
17
|
export declare function getLocale(): Locale;
|
package/lib/utils/locale.js
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
|
+
const STORAGE_KEY = 'miaoda:preview-locale';
|
|
2
|
+
function toLocale(value) {
|
|
3
|
+
const lang = value ?? 'zh';
|
|
4
|
+
return lang.toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
5
|
+
}
|
|
6
|
+
function readLocaleFromQuery() {
|
|
7
|
+
if ('undefined' == typeof window) return null;
|
|
8
|
+
try {
|
|
9
|
+
const value = new URLSearchParams(window.location.search).get('locale');
|
|
10
|
+
return value && value.length > 0 ? value : null;
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function readLocaleFromStorage() {
|
|
16
|
+
if ('undefined' == typeof window) return null;
|
|
17
|
+
try {
|
|
18
|
+
const value = window.localStorage?.getItem(STORAGE_KEY);
|
|
19
|
+
return value && value.length > 0 ? value : null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function writeLocaleToStorage(value) {
|
|
25
|
+
if ('undefined' == typeof window) return;
|
|
26
|
+
try {
|
|
27
|
+
window.localStorage?.setItem(STORAGE_KEY, value);
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
1
30
|
function getLocale() {
|
|
2
|
-
|
|
3
|
-
|
|
31
|
+
if ('production' === process.env.NODE_ENV) return toLocale(navigator.language);
|
|
32
|
+
const fromQuery = readLocaleFromQuery();
|
|
33
|
+
if (fromQuery) {
|
|
34
|
+
writeLocaleToStorage(fromQuery);
|
|
35
|
+
return toLocale(fromQuery);
|
|
36
|
+
}
|
|
37
|
+
const fromStorage = readLocaleFromStorage();
|
|
38
|
+
if (fromStorage) return toLocale(fromStorage);
|
|
39
|
+
return toLocale(navigator.language);
|
|
4
40
|
}
|
|
5
41
|
export { getLocale };
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -24,6 +24,12 @@ function getLegacyParentOrigin() {
|
|
|
24
24
|
return 'https://miaoda.feishu-boe.cn';
|
|
25
25
|
}
|
|
26
26
|
function resolveParentOrigin() {
|
|
27
|
+
try {
|
|
28
|
+
if (document.referrer) {
|
|
29
|
+
const referrerOrigin = new URL(document.referrer).origin;
|
|
30
|
+
if (referrerOrigin.startsWith('http://localhost') || referrerOrigin.startsWith('http://127.0.0.1')) return referrerOrigin;
|
|
31
|
+
}
|
|
32
|
+
} catch {}
|
|
27
33
|
const paramOrigin = getParentOriginFromParams();
|
|
28
34
|
if (paramOrigin) return paramOrigin;
|
|
29
35
|
return process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN ?? getLegacyParentOrigin();
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { authClient } from "@lark-apaas/auth-sdk";
|
|
2
2
|
const pendingRequests = new Map();
|
|
3
3
|
async function fetchUserProfilesByIds(ids) {
|
|
4
4
|
try {
|
|
5
|
-
const
|
|
6
|
-
if (!dataloom) throw new Error('Dataloom client is unavailable');
|
|
7
|
-
const response = await dataloom.service.user.getByIds(ids);
|
|
5
|
+
const response = await authClient.user.getByIds(ids);
|
|
8
6
|
return Array.isArray(response?.data) ? response.data : response?.data?.user_list || [];
|
|
9
7
|
} catch (error) {
|
|
10
8
|
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.44-alpha.
|
|
3
|
+
"version": "1.2.44-alpha.2",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -98,10 +98,10 @@
|
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
|
-
"@
|
|
102
|
-
"@lark-apaas/
|
|
103
|
-
"@lark-apaas/auth-sdk": "^0.1.4",
|
|
101
|
+
"@lark-apaas/aily-web-sdk": "^0.0.9",
|
|
102
|
+
"@lark-apaas/auth-sdk": "0.1.5-alpha.0",
|
|
104
103
|
"@lark-apaas/client-capability": "^0.1.6",
|
|
104
|
+
"@lark-apaas/dataloom": "0.1.2-alpha.2",
|
|
105
105
|
"@lark-apaas/internal-slardar": "^0.0.3",
|
|
106
106
|
"@lark-apaas/miaoda-inspector": "^1.0.23",
|
|
107
107
|
"@lark-apaas/observable-web": "^1.0.6",
|