@lark-apaas/client-toolkit 1.2.16 → 1.2.17-alpha.10
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/antd-table.d.ts +2 -2
- package/lib/apis/aily-chat.d.ts +2 -0
- package/lib/apis/aily-chat.js +2 -0
- package/lib/apis/utils/resolveAppUrl.d.ts +1 -0
- package/lib/apis/utils/resolveAppUrl.js +2 -0
- package/lib/components/AppContainer/RoutePatternTracker.d.ts +5 -0
- package/lib/components/AppContainer/RoutePatternTracker.js +13 -0
- package/lib/components/AppContainer/index.d.ts +5 -1
- package/lib/components/AppContainer/index.js +16 -27
- package/lib/components/AppContainer/safety.js +5 -2
- package/lib/components/AppContainer/utils/getLarkUser.js +4 -2
- package/lib/components/AppContainer/utils/observable.js +7 -1
- package/lib/components/theme/index.d.ts +0 -1
- package/lib/components/theme/index.js +0 -1
- package/lib/components/theme/util.d.ts +0 -2
- package/lib/components/theme/util.js +0 -108
- package/lib/hooks/useCurrentUserProfile.js +22 -29
- package/lib/hooks/useLogout.js +2 -17
- package/lib/index.js +7 -0
- package/lib/integrations/dataloom.d.ts +3 -1
- package/lib/integrations/dataloom.js +14 -8
- package/lib/integrations/services/DepartmentService.js +3 -2
- package/lib/integrations/services/UserProfileService.js +3 -2
- package/lib/integrations/services/UserService.js +4 -3
- package/lib/integrations/services/types.d.ts +1 -0
- package/lib/logger/intercept-global-error.js +18 -11
- package/lib/runtime/index.d.ts +1 -0
- package/lib/runtime/index.js +1 -0
- package/lib/runtime/react-devtools-hook.d.ts +19 -0
- package/lib/runtime/react-devtools-hook.js +20 -0
- package/lib/utils/apiPath.d.ts +5 -0
- package/lib/utils/apiPath.js +5 -0
- package/lib/utils/axiosConfig.js +45 -2
- package/lib/utils/getAppId.d.ts +2 -4
- package/lib/utils/getAppId.js +2 -9
- package/lib/utils/getInitialInfo.d.ts +4 -3
- package/lib/utils/getInitialInfo.js +17 -8
- package/lib/utils/getUserProfile.js +4 -12
- package/lib/utils/postMessage.d.ts +0 -1
- package/lib/utils/postMessage.js +19 -6
- package/lib/utils/resolveAppUrl.d.ts +27 -0
- package/lib/utils/resolveAppUrl.js +19 -0
- package/lib/utils/routePattern.d.ts +10 -0
- package/lib/utils/routePattern.js +45 -0
- package/lib/utils/scopedStorage.js +1 -1
- package/package.json +13 -6
- package/lib/apis/tools/generateImage.d.ts +0 -1
- package/lib/apis/tools/generateImage.js +0 -1
- package/lib/apis/tools/generateTextStream.d.ts +0 -1
- package/lib/apis/tools/generateTextStream.js +0 -1
- package/lib/components/theme/ui-config.d.ts +0 -1
- package/lib/components/theme/ui-config.js +0 -2
- package/lib/integrations/generateImage.d.ts +0 -1
- package/lib/integrations/generateImage.js +0 -47
- package/lib/integrations/generateTextStream.d.ts +0 -21
- package/lib/integrations/generateTextStream.js +0 -98
package/lib/antd-table.d.ts
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { ChatPanel, IframeEventMessage, IframeMessage, IframeMessageType, IframeRequestMessage, IframeResponseMessage, WebSDKCommonConfig, WebSDKConfig, WebSDKConversionConfig, WebSDKEditorConfig, WebSDKEvents, WebSDKSkillInfo, } from '@lark-apaas/aily-web-sdk';
|
|
2
|
+
export { DEFAULT_ANONYMOUS_CHANNEL_TYPE, DEFAULT_CHANNEL_TYPE, getIframeBaseURL, IFRAME_BASE_URL, initAilyChat, MESSAGE_TIMEOUT, } from '@lark-apaas/aily-web-sdk';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { DEFAULT_ANONYMOUS_CHANNEL_TYPE, DEFAULT_CHANNEL_TYPE, IFRAME_BASE_URL, MESSAGE_TIMEOUT, getIframeBaseURL, initAilyChat } from "@lark-apaas/aily-web-sdk";
|
|
2
|
+
export { DEFAULT_ANONYMOUS_CHANNEL_TYPE, DEFAULT_CHANNEL_TYPE, IFRAME_BASE_URL, MESSAGE_TIMEOUT, getIframeBaseURL, initAilyChat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveAppUrl } from '../../utils/resolveAppUrl';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useLocation } from "react-router-dom";
|
|
3
|
+
import { updateRoutePattern } from "../../utils/routePattern.js";
|
|
4
|
+
function RoutePatternTracker() {
|
|
5
|
+
const location = useLocation();
|
|
6
|
+
useEffect(()=>{
|
|
7
|
+
updateRoutePattern(location.pathname);
|
|
8
|
+
}, [
|
|
9
|
+
location.pathname
|
|
10
|
+
]);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
export { RoutePatternTracker as default };
|
|
@@ -4,7 +4,11 @@ import '../../runtime';
|
|
|
4
4
|
interface IBaseAuthProviderProps {
|
|
5
5
|
enableAuth?: boolean;
|
|
6
6
|
}
|
|
7
|
+
interface IToasterProps {
|
|
8
|
+
/** 禁用内建 Toaster 组件,默认 false */
|
|
9
|
+
disableToaster?: boolean;
|
|
10
|
+
}
|
|
7
11
|
declare const AppContainer: React.FC<{
|
|
8
12
|
children: React.ReactNode;
|
|
9
|
-
} & IBaseThemeProviderProps & IBaseAuthProviderProps>;
|
|
13
|
+
} & IBaseThemeProviderProps & IBaseAuthProviderProps & IToasterProps>;
|
|
10
14
|
export default AppContainer;
|
|
@@ -4,15 +4,15 @@ import { ConfigProvider } from "antd";
|
|
|
4
4
|
import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
|
|
5
5
|
import zh_CN from "antd/locale/zh_CN";
|
|
6
6
|
import IframeBridge from "./IframeBridge.js";
|
|
7
|
-
import
|
|
7
|
+
import RoutePatternTracker from "./RoutePatternTracker.js";
|
|
8
8
|
import { Toaster } from "./sonner.js";
|
|
9
9
|
import { PageHoc } from "./PageHoc.js";
|
|
10
|
-
import { findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, themeMetaOptions } from "../theme/index.js";
|
|
11
10
|
import { reportTeaEvent } from "./utils/tea.js";
|
|
12
11
|
import { useAppInfo } from "../../hooks/index.js";
|
|
13
12
|
import { TrackKey } from "../../types/tea.js";
|
|
14
13
|
import safety from "./safety.js";
|
|
15
14
|
import { getAppId } from "../../utils/getAppId.js";
|
|
15
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
16
16
|
import QueryProvider from "../QueryProvider/index.js";
|
|
17
17
|
import { AuthProvider } from "@lark-apaas/auth-sdk";
|
|
18
18
|
import "../../runtime/index.js";
|
|
@@ -26,20 +26,10 @@ const readCssVarColor = (varName, fallback)=>{
|
|
|
26
26
|
return fallback;
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
const appFlags = process.env.APP_FLAGS || {};
|
|
29
30
|
const App = (props)=>{
|
|
30
|
-
const {
|
|
31
|
+
const { enableAuth, disableToaster = false } = props;
|
|
31
32
|
useAppInfo();
|
|
32
|
-
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
|
33
|
-
rem: '0.625'
|
|
34
|
-
};
|
|
35
|
-
const radiusToken = generateTailwindRadiusToken(Number(rem));
|
|
36
|
-
const themeToken = {
|
|
37
|
-
...defaultUIConfig,
|
|
38
|
-
common: {
|
|
39
|
-
...defaultUIConfig.common,
|
|
40
|
-
borderRadius: radiusToken
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
33
|
useEffect(()=>{
|
|
44
34
|
if (isMiaodaPreview) fetch(`${location.origin}/ai/api/feida_preview/csrf`).then(()=>{
|
|
45
35
|
setTimeout(()=>{
|
|
@@ -52,27 +42,26 @@ const App = (props)=>{
|
|
|
52
42
|
if ('production' === process.env.NODE_ENV) reportTeaEvent({
|
|
53
43
|
trackKey: TrackKey.VIEW,
|
|
54
44
|
trackParams: {
|
|
55
|
-
artifact_uid: getAppId(
|
|
45
|
+
artifact_uid: getAppId(),
|
|
56
46
|
agent_id: 'agent_miaoda',
|
|
57
47
|
url: window.location.href
|
|
58
48
|
}
|
|
59
49
|
});
|
|
60
50
|
}, []);
|
|
51
|
+
const appId = getAppId();
|
|
52
|
+
const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
|
|
61
53
|
return /*#__PURE__*/ jsxs(AuthProvider, {
|
|
62
54
|
config: {
|
|
63
|
-
enable: enableAuth
|
|
55
|
+
enable: enableAuth,
|
|
56
|
+
permissionApi: {
|
|
57
|
+
url: permissionApiUrl
|
|
58
|
+
}
|
|
64
59
|
},
|
|
65
60
|
children: [
|
|
66
|
-
/*#__PURE__*/ jsx(Toaster, {}),
|
|
67
|
-
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
|
|
68
|
-
theme: {
|
|
69
|
-
themeMetaOptions: themeMetaOptions,
|
|
70
|
-
themeColorTokenMap: themeColorTokenMap,
|
|
71
|
-
themeToken
|
|
72
|
-
},
|
|
73
|
-
cwd: process.env.CWD || ''
|
|
74
|
-
}),
|
|
61
|
+
!disableToaster && true !== appFlags.customToaster && /*#__PURE__*/ jsx(Toaster, {}),
|
|
62
|
+
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {}),
|
|
75
63
|
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(IframeBridge, {}),
|
|
64
|
+
/*#__PURE__*/ jsx(RoutePatternTracker, {}),
|
|
76
65
|
/*#__PURE__*/ jsx(PageHoc, {
|
|
77
66
|
children: props.children
|
|
78
67
|
})
|
|
@@ -80,7 +69,7 @@ const App = (props)=>{
|
|
|
80
69
|
});
|
|
81
70
|
};
|
|
82
71
|
const AppContainer_AppContainer = (props)=>{
|
|
83
|
-
const { children
|
|
72
|
+
const { children } = props;
|
|
84
73
|
const [cssColors, setCssColors] = useState(()=>({
|
|
85
74
|
background: readCssVarColor('--background'),
|
|
86
75
|
destructive: readCssVarColor('--destructive'),
|
|
@@ -208,8 +197,8 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
208
197
|
}
|
|
209
198
|
},
|
|
210
199
|
children: /*#__PURE__*/ jsx(App, {
|
|
211
|
-
themeMeta: props.themeMeta,
|
|
212
200
|
enableAuth: props.enableAuth,
|
|
201
|
+
disableToaster: props.disableToaster,
|
|
213
202
|
children: children
|
|
214
203
|
})
|
|
215
204
|
})
|
|
@@ -3,11 +3,12 @@ import { useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
|
|
4
4
|
import { getCsrfToken } from "../../utils/getCsrfToken.js";
|
|
5
5
|
import { getAppId } from "../../utils/getAppId.js";
|
|
6
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
6
7
|
import { useIsMobile } from "../../hooks/index.js";
|
|
7
8
|
import { X } from "lucide-react";
|
|
8
9
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
9
10
|
const Component = ()=>{
|
|
10
|
-
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId(
|
|
11
|
+
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
11
12
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
12
13
|
const [open, setOpen] = useState(false);
|
|
13
14
|
const isMobile = useIsMobile();
|
|
@@ -15,7 +16,9 @@ const Component = ()=>{
|
|
|
15
16
|
const [isInternetVisible, setIsInternetVisible] = useState(false);
|
|
16
17
|
const timeoutRef = useRef(null);
|
|
17
18
|
useEffect(()=>{
|
|
18
|
-
|
|
19
|
+
const appId = getAppId();
|
|
20
|
+
const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
|
|
21
|
+
fetch(tenantInfoUrl, {
|
|
19
22
|
headers: {
|
|
20
23
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
21
24
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { getAppId } from "../../../utils/getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "../../../utils/getCsrfToken.js";
|
|
3
|
+
import { isNewPathEnabled } from "../../../utils/apiPath.js";
|
|
3
4
|
async function getLarkUserInfo() {
|
|
4
|
-
const appId = getAppId(
|
|
5
|
+
const appId = getAppId();
|
|
5
6
|
if (!appId) return {
|
|
6
7
|
code: 1,
|
|
7
8
|
msg: 'appId is required',
|
|
8
9
|
data: {}
|
|
9
10
|
};
|
|
10
|
-
const
|
|
11
|
+
const url = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/lark/user_info` : `/spark/b/${appId}/lark/user_info`;
|
|
12
|
+
const response = await fetch(url, {
|
|
11
13
|
headers: {
|
|
12
14
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
13
15
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { AppEnv, observable } from "@lark-apaas/observable-web";
|
|
2
|
+
import { isNewPathEnabled } from "../../../utils/apiPath.js";
|
|
2
3
|
const initObservable = ()=>{
|
|
3
4
|
try {
|
|
4
5
|
const appId = window.appId;
|
|
5
6
|
observable.start({
|
|
6
7
|
serviceName: "app",
|
|
7
8
|
env: 'development' === process.env.NODE_ENV ? AppEnv.Dev : AppEnv.Prod,
|
|
8
|
-
collectorUrl: {
|
|
9
|
+
collectorUrl: isNewPathEnabled() ? {
|
|
10
|
+
log: `/app/${appId}/__runtime__/api/v1/observability/logs/collect`,
|
|
11
|
+
trace: `/app/${appId}/__runtime__/api/v1/observability/traces/collect`,
|
|
12
|
+
metric: `/app/${appId}/__runtime__/api/v1/observability/metrics/collect`,
|
|
13
|
+
time: `/app/${appId}/__runtime__/api/v1/observability/current_server_timestamp`
|
|
14
|
+
} : {
|
|
9
15
|
log: `/spark/app/${appId}/runtime/api/v1/observability/logs/collect`,
|
|
10
16
|
trace: `/spark/app/${appId}/runtime/api/v1/observability/traces/collect`,
|
|
11
17
|
metric: `/spark/app/${appId}/runtime/api/v1/observability/metrics/collect`,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ITheme } from "../../types";
|
|
2
|
-
import { UIComponentConfig } from "./ui-config";
|
|
3
2
|
export interface IBaseThemeProviderProps {
|
|
4
3
|
defaultTheme?: ITheme;
|
|
5
4
|
themeMeta?: Partial<IThemeTokenMeta>;
|
|
@@ -18,4 +17,3 @@ export interface IThemeTokenMeta {
|
|
|
18
17
|
*/
|
|
19
18
|
spacing: number;
|
|
20
19
|
}
|
|
21
|
-
export declare const generateTailwindRadiusToken: (radiusRemValue: number) => UIComponentConfig;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const generateTailwindRadiusToken = (radiusRemValue)=>{
|
|
2
|
-
try {
|
|
3
|
-
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
4
|
-
const radiusPx = radiusRemValue * rootFontSize;
|
|
5
|
-
const tempElement = document.createElement('div');
|
|
6
|
-
tempElement.style.position = 'absolute';
|
|
7
|
-
tempElement.style.visibility = 'hidden';
|
|
8
|
-
document.body.appendChild(tempElement);
|
|
9
|
-
tempElement.style.borderRadius = `${radiusPx}px`;
|
|
10
|
-
const computed = getComputedStyle(tempElement).borderRadius;
|
|
11
|
-
document.body.removeChild(tempElement);
|
|
12
|
-
if (computed && 'auto' !== computed && 'initial' !== computed) return {
|
|
13
|
-
type: 'select',
|
|
14
|
-
options: [
|
|
15
|
-
{
|
|
16
|
-
value: 'rounded-none',
|
|
17
|
-
label: 'none(0px)',
|
|
18
|
-
rawValue: '0'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
value: 'rounded-sm',
|
|
22
|
-
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
23
|
-
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
value: 'rounded',
|
|
27
|
-
label: 's (4px)',
|
|
28
|
-
rawValue: '4'
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
value: 'rounded-md',
|
|
32
|
-
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
33
|
-
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
value: 'rounded-lg',
|
|
37
|
-
label: `l (${radiusPx}px)`,
|
|
38
|
-
rawValue: `${radiusPx}`
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
value: 'rounded-xl',
|
|
42
|
-
label: `xl (${radiusPx + 4}px)`,
|
|
43
|
-
rawValue: `${radiusPx + 4}`
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
value: 'rounded-2xl',
|
|
47
|
-
label: '2xl (16px)',
|
|
48
|
-
rawValue: '16'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
value: 'rounded-full',
|
|
52
|
-
label: 'Full',
|
|
53
|
-
rawValue: '9999'
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
throw new Error('Browser calculation validation failed');
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.warn('Failed to get computed values from browser, falling back to default calculation:', error);
|
|
60
|
-
const radiusPx = 16 * radiusRemValue;
|
|
61
|
-
return {
|
|
62
|
-
type: 'select',
|
|
63
|
-
options: [
|
|
64
|
-
{
|
|
65
|
-
value: 'rounded-none',
|
|
66
|
-
label: 'none(0px)',
|
|
67
|
-
rawValue: '0'
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
value: 'rounded-sm',
|
|
71
|
-
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
72
|
-
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
value: 'rounded',
|
|
76
|
-
label: 's (4px)',
|
|
77
|
-
rawValue: '4'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
value: 'rounded-md',
|
|
81
|
-
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
82
|
-
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
value: 'rounded-lg',
|
|
86
|
-
label: `l (${radiusPx}px)`,
|
|
87
|
-
rawValue: `${radiusPx}`
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
value: 'rounded-xl',
|
|
91
|
-
label: `xl (${radiusPx + 4}px)`,
|
|
92
|
-
rawValue: `${radiusPx + 4}`
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
value: 'rounded-2xl',
|
|
96
|
-
label: '2xl (16px)',
|
|
97
|
-
rawValue: '16'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
value: 'rounded-full',
|
|
101
|
-
label: 'Full',
|
|
102
|
-
rawValue: '9999'
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
export { generateTailwindRadiusToken };
|
|
@@ -19,37 +19,29 @@ function getCompatibilityUserProfile() {
|
|
|
19
19
|
const useCurrentUserProfile = ()=>{
|
|
20
20
|
const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
|
|
21
21
|
useEffect(()=>{
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
const fetchAndSetUserInfo = async ()=>{
|
|
24
|
+
const dataloom = await getDataloom();
|
|
25
|
+
const result = await dataloom?.service?.session?.getUserInfo();
|
|
26
|
+
if (cancelled) return;
|
|
27
|
+
const info = result?.data?.user_info;
|
|
28
|
+
const userName = getNameFromArray(info?.name);
|
|
29
|
+
const newUserInfo = {
|
|
30
|
+
user_id: info?.user_id?.toString(),
|
|
31
|
+
email: info?.email,
|
|
32
|
+
name: userName,
|
|
33
|
+
avatar: info?.avatar?.image?.large,
|
|
34
|
+
userName: userName,
|
|
35
|
+
userAvatar: info?.avatar?.image?.large
|
|
36
|
+
};
|
|
37
|
+
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', newUserInfo);
|
|
38
|
+
setUserInfo(newUserInfo);
|
|
39
|
+
};
|
|
22
40
|
let handleMetaInfoChanged;
|
|
23
41
|
if (isSparkRuntime()) {
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const userInfo = result?.data?.user_info;
|
|
28
|
-
const userName = getNameFromArray(userInfo?.name);
|
|
29
|
-
setUserInfo({
|
|
30
|
-
user_id: userInfo?.user_id?.toString(),
|
|
31
|
-
email: userInfo?.email,
|
|
32
|
-
name: userName,
|
|
33
|
-
avatar: userInfo?.avatar?.image?.large,
|
|
34
|
-
userName: userName,
|
|
35
|
-
userAvatar: userInfo?.avatar?.image?.large
|
|
36
|
-
});
|
|
37
|
-
})();
|
|
38
|
-
handleMetaInfoChanged = async ()=>{
|
|
39
|
-
const dataloom = await getDataloom();
|
|
40
|
-
const result = await dataloom?.service?.session?.getUserInfo();
|
|
41
|
-
const userInfo = result?.data?.user_info;
|
|
42
|
-
const userName = getNameFromArray(userInfo?.name);
|
|
43
|
-
const newUserInfo = {
|
|
44
|
-
user_id: userInfo?.user_id?.toString(),
|
|
45
|
-
email: userInfo?.email,
|
|
46
|
-
name: userName,
|
|
47
|
-
avatar: userInfo?.avatar?.image?.large,
|
|
48
|
-
userName: userName,
|
|
49
|
-
userAvatar: userInfo?.avatar?.image?.large
|
|
50
|
-
};
|
|
51
|
-
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', newUserInfo);
|
|
52
|
-
setUserInfo(newUserInfo);
|
|
42
|
+
fetchAndSetUserInfo();
|
|
43
|
+
handleMetaInfoChanged = ()=>{
|
|
44
|
+
fetchAndSetUserInfo();
|
|
53
45
|
};
|
|
54
46
|
} else handleMetaInfoChanged = ()=>{
|
|
55
47
|
if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', getCompatibilityUserProfile());
|
|
@@ -57,6 +49,7 @@ const useCurrentUserProfile = ()=>{
|
|
|
57
49
|
};
|
|
58
50
|
window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
59
51
|
return ()=>{
|
|
52
|
+
cancelled = true;
|
|
60
53
|
window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
61
54
|
};
|
|
62
55
|
}, []);
|
package/lib/hooks/useLogout.js
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { getDataloom } from "../integrations/dataloom.js";
|
|
3
|
-
import { isSparkRuntime } from "../utils/utils.js";
|
|
4
3
|
function useLogout() {
|
|
5
4
|
const [isLoading, setIsLoading] = useState(false);
|
|
6
5
|
async function handlerLogout() {
|
|
7
6
|
if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
|
|
8
|
-
if (isSparkRuntime()) {
|
|
9
|
-
setIsLoading(true);
|
|
10
|
-
try {
|
|
11
|
-
const dataloom = await getDataloom();
|
|
12
|
-
await dataloom.service.session.signOut();
|
|
13
|
-
} catch (error) {
|
|
14
|
-
console.error('登出失败', error);
|
|
15
|
-
} finally{
|
|
16
|
-
setIsLoading(false);
|
|
17
|
-
}
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
7
|
setIsLoading(true);
|
|
21
8
|
try {
|
|
22
|
-
await
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
window.location.reload();
|
|
9
|
+
const dataloom = await getDataloom();
|
|
10
|
+
await dataloom.service.session.signOut();
|
|
26
11
|
} catch (error) {
|
|
27
12
|
console.error('登出失败', error);
|
|
28
13
|
} finally{
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { createClient } from "@lark-apaas/client-capability";
|
|
2
2
|
import { normalizeBasePath } from "./utils/utils.js";
|
|
3
|
+
import { getAppId } from "./utils/getAppId.js";
|
|
4
|
+
import { isNewPathEnabled } from "./utils/apiPath.js";
|
|
3
5
|
import { logger } from "./logger/index.js";
|
|
4
6
|
import { showToast } from "./components/ui/toast.js";
|
|
5
7
|
import { version } from "../package.json";
|
|
8
|
+
const _appId = getAppId();
|
|
9
|
+
const _acquireUploadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_upload_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_upload_url";
|
|
10
|
+
const _acquireDownloadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_download_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_download_url";
|
|
6
11
|
const capabilityClient = createClient({
|
|
7
12
|
baseURL: normalizeBasePath(process.env.CLIENT_BASE_PATH),
|
|
13
|
+
acquireUploadUrl: _acquireUploadUrl,
|
|
14
|
+
acquireDownloadUrl: _acquireDownloadUrl,
|
|
8
15
|
fetchOptions: {
|
|
9
16
|
headers: {
|
|
10
17
|
'X-Suda-Csrf-Token': window.csrfToken ?? ''
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
declare const createDataLoomClient: (url?: string, pat?: string) => import("@data-loom/js").DataloomClient<any, "public", any>;
|
|
1
2
|
/** 获取dataloom实例 */
|
|
2
|
-
export declare function getDataloom(): Promise<
|
|
3
|
+
export declare function getDataloom(): Promise<ReturnType<typeof createDataLoomClient>>;
|
|
4
|
+
export {};
|
|
@@ -7,7 +7,7 @@ const createDataLoomClient = (url, pat)=>{
|
|
|
7
7
|
baseUrl: '',
|
|
8
8
|
workspace: ''
|
|
9
9
|
};
|
|
10
|
-
const appId = getAppId(
|
|
10
|
+
const appId = getAppId();
|
|
11
11
|
return createClient(baseUrl, pat, workspace, {
|
|
12
12
|
global: {
|
|
13
13
|
enableDataloomLog: 'production' !== process.env.NODE_ENV,
|
|
@@ -23,12 +23,18 @@ const createDataLoomClient = (url, pat)=>{
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
let dataloom = null;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
let pendingPromise = null;
|
|
27
|
+
function getDataloom() {
|
|
28
|
+
if (dataloom) return Promise.resolve(dataloom);
|
|
29
|
+
if (pendingPromise) return pendingPromise;
|
|
30
|
+
pendingPromise = getInitialInfo().then((info)=>{
|
|
31
|
+
const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
|
|
32
|
+
const DATALOOM_PAT = info?.app_runtime_extra?.token;
|
|
33
|
+
dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
|
|
34
|
+
return dataloom;
|
|
35
|
+
}).finally(()=>{
|
|
36
|
+
pendingPromise = null;
|
|
37
|
+
});
|
|
38
|
+
return pendingPromise;
|
|
33
39
|
}
|
|
34
40
|
export { getDataloom };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
2
3
|
const DEFAULT_CONFIG = {
|
|
3
|
-
getAppId: ()=>getAppId(
|
|
4
|
-
searchDepartmentUrl: (appId)
|
|
4
|
+
getAppId: ()=>getAppId(),
|
|
5
|
+
searchDepartmentUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/search_department` : `/af/app/${appId}/runtime/api/v1/account/search_department`
|
|
5
6
|
};
|
|
6
7
|
class DepartmentService {
|
|
7
8
|
config;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
2
3
|
const CDN_HOST = 'https://lf3-static.bytednsdoc.com';
|
|
3
4
|
function getAssetsUrl(path) {
|
|
4
5
|
return `${CDN_HOST}${path}`;
|
|
5
6
|
}
|
|
6
7
|
const DEFAULT_CONFIG = {
|
|
7
|
-
getAppId: ()=>getAppId(
|
|
8
|
-
userProfileUrl: (appId)
|
|
8
|
+
getAppId: ()=>getAppId(),
|
|
9
|
+
userProfileUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/user_profile` : `/af/app/${appId}/runtime/api/v1/account/user_profile`
|
|
9
10
|
};
|
|
10
11
|
class UserProfileService {
|
|
11
12
|
config;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
2
3
|
const DEFAULT_CONFIG = {
|
|
3
|
-
getAppId: ()=>getAppId(
|
|
4
|
-
searchUserUrl: (appId)
|
|
5
|
-
listUsersUrl: (appId)
|
|
4
|
+
getAppId: ()=>getAppId(),
|
|
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
7
|
};
|
|
7
8
|
class UserService {
|
|
8
9
|
config;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { slardar } from "@lark-apaas/internal-slardar";
|
|
1
2
|
import { getHmrApi } from "../utils/hmr-api.js";
|
|
2
|
-
import { submitPostMessage
|
|
3
|
+
import { submitPostMessage } from "../utils/postMessage.js";
|
|
3
4
|
import { levelSchema } from "./log-types.js";
|
|
4
5
|
import { logger } from "./logger.js";
|
|
5
6
|
let devServerDisconnectInfo = null;
|
|
@@ -19,22 +20,26 @@ function processDevServerLog(log) {
|
|
|
19
20
|
status: 'disconnected'
|
|
20
21
|
}
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
+
slardar.sendEvent({
|
|
23
24
|
name: 'sandbox-devServer',
|
|
24
|
-
|
|
25
|
-
type: 'disconnected',
|
|
25
|
+
metrics: {
|
|
26
26
|
time
|
|
27
|
+
},
|
|
28
|
+
categories: {
|
|
29
|
+
type: 'disconnected'
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
34
|
if (!devServerDisconnectInfo) return;
|
|
32
35
|
if (devFlag && log.includes('Trying to reconnect')) {
|
|
33
|
-
if (retryCount)
|
|
36
|
+
if (retryCount) slardar.sendEvent({
|
|
34
37
|
name: 'sandbox-devServer',
|
|
35
|
-
|
|
36
|
-
type: 'reconnect-failed',
|
|
38
|
+
metrics: {
|
|
37
39
|
retryCount: retryCount + 1
|
|
40
|
+
},
|
|
41
|
+
categories: {
|
|
42
|
+
type: 'reconnect-failed'
|
|
38
43
|
}
|
|
39
44
|
});
|
|
40
45
|
retryCount++;
|
|
@@ -52,12 +57,14 @@ function processDevServerLog(log) {
|
|
|
52
57
|
const startTime = devServerDisconnectInfo.time;
|
|
53
58
|
const duration = Date.now() - startTime;
|
|
54
59
|
devServerDisconnectInfo = null;
|
|
55
|
-
|
|
60
|
+
slardar.sendEvent({
|
|
56
61
|
name: 'sandbox-devServer',
|
|
57
|
-
|
|
58
|
-
type: 'devServer-reconnected',
|
|
62
|
+
metrics: {
|
|
59
63
|
startTime,
|
|
60
64
|
duration
|
|
65
|
+
},
|
|
66
|
+
categories: {
|
|
67
|
+
type: 'devServer-reconnected'
|
|
61
68
|
}
|
|
62
69
|
});
|
|
63
70
|
}
|
|
@@ -76,7 +83,7 @@ function listenModuleHmr() {
|
|
|
76
83
|
});
|
|
77
84
|
hmr.onError((error)=>{
|
|
78
85
|
console.warn('hmr apply failed', error);
|
|
79
|
-
|
|
86
|
+
slardar.sendEvent({
|
|
80
87
|
name: 'sandbox-devServer',
|
|
81
88
|
categories: {
|
|
82
89
|
type: 'hmr-apply-failed',
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED