@alauda/doom 1.14.3 → 1.15.0

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.
Files changed (58) hide show
  1. package/lib/global/AuthCheck/index.d.ts +2 -0
  2. package/lib/global/AuthCheck/index.js +61 -0
  3. package/lib/global/Intelligence/AIAssistant/Preamble/index.js +5 -3
  4. package/lib/global/Intelligence/AIAssistant/index.js +3 -3
  5. package/lib/global/Intelligence/index.js +2 -3
  6. package/lib/login/LoginForm/index.d.ts +5 -0
  7. package/lib/login/LoginForm/index.js +67 -0
  8. package/lib/login/constants.d.ts +1 -0
  9. package/lib/login/constants.js +1 -0
  10. package/lib/login/index.d.ts +2 -0
  11. package/lib/login/index.js +16 -0
  12. package/lib/login/store.d.ts +6 -0
  13. package/lib/login/store.js +37 -0
  14. package/lib/{global/Intelligence → login}/types.d.ts +12 -3
  15. package/lib/login/utils.d.ts +8 -0
  16. package/lib/{global/Intelligence → login}/utils.js +5 -0
  17. package/lib/plugins/global/index.js +17 -1
  18. package/lib/runtime/hooks/useIsPrint.js +3 -4
  19. package/lib/runtime/hooks/useTranslation.d.ts +1 -1
  20. package/lib/runtime/translation.d.ts +8 -12
  21. package/lib/runtime/translation.js +6 -9
  22. package/package.json +6 -6
  23. package/styles/login.module.scss +9 -0
  24. package/styles/preamble.module.scss +1 -0
  25. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.d.ts +0 -3
  26. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.js +0 -88
  27. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/Radio.d.ts +0 -7
  28. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/Radio.js +0 -11
  29. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/RadioGroup.d.ts +0 -11
  30. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/RadioGroup.js +0 -21
  31. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/context.d.ts +0 -7
  32. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/context.js +0 -2
  33. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/index.d.ts +0 -2
  34. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/index.js +0 -2
  35. package/lib/global/Intelligence/AIAssistant/Preamble/types.d.ts +0 -9
  36. package/lib/global/Intelligence/AIAssistant/Preamble/types.js +0 -1
  37. package/lib/global/Intelligence/constants.d.ts +0 -6
  38. package/lib/global/Intelligence/constants.js +0 -14
  39. package/lib/global/Intelligence/context.d.ts +0 -20
  40. package/lib/global/Intelligence/context.js +0 -31
  41. package/lib/global/Intelligence/utils.d.ts +0 -3
  42. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/ApiErrorAlert/index.d.ts +0 -0
  43. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/ApiErrorAlert/index.js +0 -0
  44. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/Button/index.d.ts +0 -0
  45. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/Button/index.js +0 -0
  46. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/CaptchaInput/index.d.ts +0 -0
  47. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/CaptchaInput/index.js +0 -0
  48. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/FocusInput/index.d.ts +0 -0
  49. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/FocusInput/index.js +0 -0
  50. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/FormItem/index.d.ts +0 -0
  51. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/FormItem/index.js +0 -0
  52. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/Input/index.d.ts +0 -0
  53. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/Input/index.js +0 -0
  54. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/LoginForm/types.d.ts +0 -0
  55. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/LoginForm/types.js +0 -0
  56. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/LoginForm/utils.d.ts +0 -0
  57. /package/lib/{global/Intelligence/AIAssistant/Preamble → login}/LoginForm/utils.js +0 -0
  58. /package/lib/{global/Intelligence → login}/types.js +0 -0
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { NoSSR, useLang, useLocation, useNavigate, useSite, } from '@rspress/core/runtime';
3
+ import { useEffect, useRef } from 'react';
4
+ import siteData from 'virtual-site-data';
5
+ import { createXFetch } from 'x-fetch';
6
+ import { useCloudAuth } from "../../login/store.js";
7
+ import { isLoggedIn } from "../../login/utils.js";
8
+ import { useMemoizedFn } from '@alauda/doom/runtime';
9
+ const { xfetch } = createXFetch();
10
+ const AuthCheck = () => {
11
+ const { pathname, search, hash } = useLocation();
12
+ const navigate = useNavigate();
13
+ const lang = useLang();
14
+ const { site } = useSite();
15
+ const { authInfo, setAuthBasic } = useCloudAuth();
16
+ const login = useMemoizedFn(() => {
17
+ if (pathname === '/login' ||
18
+ site.themeConfig.locales.some((l) => pathname === `/${l.lang}/login`)) {
19
+ return;
20
+ }
21
+ navigate(`${lang === site.lang ? '' : `/${lang}`}/login?from=${encodeURIComponent(`${pathname}${search}${hash}`)}`);
22
+ });
23
+ const abortController = useRef(null);
24
+ const authCheck = useMemoizedFn(async () => {
25
+ if (!siteData.base.startsWith('/russian/')) {
26
+ return;
27
+ }
28
+ if (!isLoggedIn(authInfo)) {
29
+ login();
30
+ return;
31
+ }
32
+ abortController.current?.abort();
33
+ abortController.current = new AbortController();
34
+ const signal = abortController.current.signal;
35
+ try {
36
+ await xfetch('https://cloud.alauda.io/api/v1/tenant/info', {
37
+ headers: {
38
+ Authorization: `Bearer ${authInfo.token}`,
39
+ },
40
+ signal,
41
+ });
42
+ }
43
+ catch {
44
+ if (signal.aborted) {
45
+ return;
46
+ }
47
+ setAuthBasic();
48
+ login();
49
+ }
50
+ });
51
+ useEffect(() => {
52
+ void authCheck();
53
+ }, [authCheck, pathname]);
54
+ useEffect(() => {
55
+ if (!isLoggedIn(authInfo)) {
56
+ void authCheck();
57
+ }
58
+ }, [authCheck, authInfo]);
59
+ return null;
60
+ };
61
+ export default () => (_jsx(NoSSR, { children: _jsx(AuthCheck, {}) }));
@@ -1,10 +1,12 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { clsx } from 'clsx';
3
- import { LoginForm } from "./LoginForm/index.js";
3
+ import { LoginForm } from "../../../../login/LoginForm/index.js";
4
+ import { getCloudOrigin, isIoSite } from "../../../../login/utils.js";
5
+ import { X } from "../../../../runtime/components/_X.js";
4
6
  import AssistantIcon from '@alauda/doom/assets/assistant.svg?react';
5
7
  import { useTranslation } from '@alauda/doom/runtime';
6
8
  import classes from '@alauda/doom/styles/preamble.module.scss';
7
9
  export const Preamble = ({ loggedIn }) => {
8
10
  const t = useTranslation();
9
- return (_jsxs("div", { className: clsx(classes.preamble, loggedIn && classes.loggedIn), children: [_jsx(AssistantIcon, { width: 48, height: 40 }), _jsx("div", { className: classes.title, children: t(loggedIn ? 'hi_there' : 'user_login') }), _jsx("div", { className: classes.content, children: t(loggedIn ? 'ai_assistant_tip' : 'user_login_tip') }), loggedIn || _jsx(LoginForm, { className: classes.form })] }));
11
+ return (_jsxs("div", { className: clsx(classes.preamble, loggedIn && classes.loggedIn), children: [_jsx(AssistantIcon, { width: 48, height: 40 }), _jsx("div", { className: classes.title, children: t(loggedIn ? 'hi_there' : 'user_login') }), _jsx("div", { className: `rp-doc ${classes.content}`, children: loggedIn ? (t('ai_assistant_tip')) : (_jsxs(_Fragment, { children: [t('user_login_tip1'), _jsx(X.a, { href: getCloudOrigin(), children: t(`customer_portal_${isIoSite() ? 'global' : 'china'}`) }), t('user_login_tip2')] })) }), loggedIn || _jsx(LoginForm, { className: classes.form })] }));
10
12
  };
@@ -3,7 +3,8 @@ import { clsx } from 'clsx';
3
3
  import { useEffect, useRef, useState } from 'react';
4
4
  import { Tooltip } from 'react-tooltip';
5
5
  import { ApiMethod, interceptors, ResponseError, xfetch, } from 'x-fetch';
6
- import { getCloudAuth, useCloudAuth } from "../context.js";
6
+ import { getCloudAuth, useCloudAuth } from "../../../login/store.js";
7
+ import { getCloudOrigin, isLoggedIn } from "../../../login/utils.js";
7
8
  import { Chat } from "./Chat/index.js";
8
9
  import { Preamble } from "./Preamble/index.js";
9
10
  import { ResizableUserInput } from "./ResizableUserInput/index.js";
@@ -14,7 +15,6 @@ import LogoutIcon from '@alauda/doom/assets/logout.svg?react';
14
15
  import NewChatIcon from '@alauda/doom/assets/new-chat.svg?react';
15
16
  import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
16
17
  import classes from '@alauda/doom/styles/ai-assistant.module.scss';
17
- const isLoggedIn = (authInfo) => Boolean(authInfo?.detail);
18
18
  let textDecoder;
19
19
  export const AIAssistant = ({ open, onOpenChange }) => {
20
20
  const t = useTranslation();
@@ -40,7 +40,7 @@ export const AIAssistant = ({ open, onOpenChange }) => {
40
40
  req.headers.set('Authorization', `Bearer ${authInfo.token}`);
41
41
  }
42
42
  if (!req.headers.has('CLOUD_AUTH_ORIGIN')) {
43
- req.headers.set('CLOUD_AUTH_ORIGIN', authInfo.origin);
43
+ req.headers.set('CLOUD_AUTH_ORIGIN', getCloudOrigin());
44
44
  }
45
45
  try {
46
46
  return await next(req);
@@ -1,11 +1,10 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { isProduction, NoSSR, useLang } from '@rspress/core/runtime';
3
3
  import virtual from 'doom-@global-virtual';
4
4
  import { useState } from 'react';
5
5
  import { Tooltip } from 'react-tooltip';
6
6
  import { ACP_BASE } from "../../shared/index.js";
7
7
  import { AIAssistant } from "./AIAssistant/index.js";
8
- import { CloudAuthProvider } from "./context.js";
9
8
  import assistantIcon from '@alauda/doom/assets/assistant.svg';
10
9
  import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
11
10
  const ALLOWED_DOMAINS = new Set([
@@ -22,7 +21,7 @@ const Intelligence_ = () => {
22
21
  const toggleOpen = useMemoizedFn(() => {
23
22
  setOpen((prev) => !prev);
24
23
  });
25
- return (_jsxs(CloudAuthProvider, { children: [_jsx(AIAssistant, { open: open, onOpenChange: toggleOpen }), open || (_jsx("button", { type: "button", className: "intelligence-entry", onClick: toggleOpen, children: _jsx("img", { alt: t('ai_assistant'), src: assistantIcon }) })), _jsx(Tooltip, { anchorSelect: ".intelligence-entry", place: "left", children: t('ai_assistant') })] }));
24
+ return (_jsxs(_Fragment, { children: [_jsx(AIAssistant, { open: open, onOpenChange: toggleOpen }), open || (_jsx("button", { type: "button", className: "intelligence-entry", onClick: toggleOpen, children: _jsx("img", { alt: t('ai_assistant'), src: assistantIcon }) })), _jsx(Tooltip, { anchorSelect: ".intelligence-entry", place: "left", children: t('ai_assistant') })] }));
26
25
  };
27
26
  const Intelligence = () => {
28
27
  const lang = useLang();
@@ -0,0 +1,5 @@
1
+ import { type FormHTMLAttributes } from 'react';
2
+ export interface LoginFormProps extends FormHTMLAttributes<HTMLFormElement> {
3
+ onLoggedIn?: () => void;
4
+ }
5
+ export declare const LoginForm: ({ onSubmit, onLoggedIn, ...props }: LoginFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, } from 'react';
3
+ import { ApiMethod, ResponseError, xfetch } from 'x-fetch';
4
+ import { ApiErrorAlert } from "../ApiErrorAlert/index.js";
5
+ import { Button } from "../Button/index.js";
6
+ import { CaptchaInput } from "../CaptchaInput/index.js";
7
+ import { FocusInput } from "../FocusInput/index.js";
8
+ import { FormItem } from "../FormItem/index.js";
9
+ import { useCloudAuth } from "../store.js";
10
+ import { getCloudOrigin } from "../utils.js";
11
+ import { cryptoPassword } from "./utils.js";
12
+ import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
13
+ const isLoginError = (err) => err instanceof ResponseError;
14
+ export const LoginForm = ({ onSubmit, onLoggedIn, ...props }) => {
15
+ const t = useTranslation();
16
+ const [loading, setLoading] = useState();
17
+ const [error, setError] = useState();
18
+ const pwdPubkeyRef = useRef(null);
19
+ const { setAuthBasic } = useCloudAuth();
20
+ const captchaId = error?.data?.extra?.captchaId;
21
+ const [timestamp, setTimestamp] = useState();
22
+ const handleSubmit = useMemoizedFn(async (ev) => {
23
+ ev.preventDefault();
24
+ ev.stopPropagation();
25
+ onSubmit?.(ev);
26
+ const formData = new FormData(ev.currentTarget);
27
+ setLoading(true);
28
+ const origin = getCloudOrigin();
29
+ if (pwdPubkeyRef.current == null) {
30
+ try {
31
+ pwdPubkeyRef.current = await xfetch(`${origin}/api/v1/pubkey`);
32
+ }
33
+ catch (err) {
34
+ setError(err);
35
+ setLoading(false);
36
+ return;
37
+ }
38
+ }
39
+ formData.set('password', cryptoPassword(pwdPubkeyRef.current, formData.get('password')));
40
+ if (captchaId) {
41
+ formData.set('captchaId', captchaId);
42
+ }
43
+ try {
44
+ const { accessToken } = await xfetch(`${origin}/api/v1/login`, {
45
+ method: ApiMethod.POST,
46
+ body: formData,
47
+ });
48
+ setAuthBasic(accessToken);
49
+ onLoggedIn?.();
50
+ }
51
+ catch (err) {
52
+ if (!isLoginError(err)) {
53
+ throw err;
54
+ }
55
+ if (err.data?.reason === 'PubkeyExpireError') {
56
+ pwdPubkeyRef.current = null;
57
+ await handleSubmit(ev);
58
+ return;
59
+ }
60
+ setError(err);
61
+ }
62
+ finally {
63
+ setLoading(false);
64
+ }
65
+ });
66
+ return (_jsxs("form", { onSubmit: handleSubmit, ...props, children: [error && _jsx(ApiErrorAlert, { error: error }), _jsx(FormItem, { label: t('account_id'), required: true, children: _jsx(FocusInput, { name: "tenant", placeholder: t('account_id') }) }), _jsx(FormItem, { label: t('username'), required: true, children: _jsx(FocusInput, { name: "username", placeholder: t('username') }) }), _jsx(FormItem, { label: t('password'), required: true, children: _jsx(FocusInput, { name: "password", type: "password", placeholder: t('password') }) }), captchaId && (_jsx(FormItem, { label: t('captcha'), required: true, children: _jsx(CaptchaInput, { Component: FocusInput, placeholder: t('captcha'), origin: origin, captchaId: captchaId, timestamp: timestamp, onTimestampChange: setTimestamp }) })), _jsx(FormItem, { children: _jsx(Button, { type: "primary", htmlType: "submit", block: true, loading: loading, children: t('login') }) })] }));
67
+ };
@@ -0,0 +1 @@
1
+ export declare const CLOUD_AUTH_TOKEN_KEY = "__CLOUD_AUTH_TOKEN__";
@@ -0,0 +1 @@
1
+ export const CLOUD_AUTH_TOKEN_KEY = '__CLOUD_AUTH_TOKEN__';
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { NoSSR, useSearchParams } from '@rspress/core/runtime';
3
+ import { useCallback } from 'react';
4
+ import { useNavigate } from 'react-router-dom';
5
+ import { LoginForm } from "./LoginForm/index.js";
6
+ import classes from '@alauda/doom/styles/login.module.scss';
7
+ const Login = () => {
8
+ const navigate = useNavigate();
9
+ const [query] = useSearchParams();
10
+ const from = query.get('from');
11
+ const onLoggedIn = useCallback(() => {
12
+ navigate(from || '/');
13
+ }, [from, navigate]);
14
+ return (_jsx("div", { className: classes.container, children: _jsx(LoginForm, { onLoggedIn: onLoggedIn }) }));
15
+ };
16
+ export default () => (_jsx(NoSSR, { children: _jsx(Login, {}) }));
@@ -0,0 +1,6 @@
1
+ import type { CloudAuth } from './types.js';
2
+ export declare const getCloudAuth: () => CloudAuth | null;
3
+ export declare const useCloudAuth: () => {
4
+ authInfo: CloudAuth | null;
5
+ setAuthBasic: (token?: string | null) => void;
6
+ };
@@ -0,0 +1,37 @@
1
+ import { useCallback, useSyncExternalStore } from 'react';
2
+ import { CLOUD_AUTH_TOKEN_KEY } from './constants.js';
3
+ import { getAuthInfoFromToken, setLocalStorage } from './utils.js';
4
+ export const getCloudAuth = () => {
5
+ if (typeof localStorage === 'undefined') {
6
+ return null;
7
+ }
8
+ const token = localStorage.getItem(CLOUD_AUTH_TOKEN_KEY);
9
+ if (token == null) {
10
+ return null;
11
+ }
12
+ return { token, detail: getAuthInfoFromToken(token) };
13
+ };
14
+ let authInfo = getCloudAuth();
15
+ const subscribe = (onStoreChange) => {
16
+ const listener = (_ev) => {
17
+ const ev = _ev;
18
+ setLocalStorage(CLOUD_AUTH_TOKEN_KEY, ev.detail);
19
+ authInfo = getCloudAuth();
20
+ onStoreChange();
21
+ };
22
+ document.addEventListener('cloud-auth-change', listener);
23
+ return () => {
24
+ document.removeEventListener('cloud-auth-change', listener);
25
+ };
26
+ };
27
+ const getSnapshot = () => authInfo;
28
+ export const useCloudAuth = () => {
29
+ const authInfo = useSyncExternalStore(subscribe, getSnapshot);
30
+ const setAuthBasic = useCallback((token) => {
31
+ document.dispatchEvent(new CustomEvent('cloud-auth-change', { detail: token }));
32
+ }, []);
33
+ return {
34
+ authInfo,
35
+ setAuthBasic,
36
+ };
37
+ };
@@ -1,3 +1,12 @@
1
+ import type { ResponseError } from 'x-fetch';
2
+ export interface ApiErrorOptions<R extends string = string, E extends object = object, T = unknown> {
3
+ code: number;
4
+ reason: R;
5
+ message: string;
6
+ extra?: E;
7
+ details?: T[];
8
+ }
9
+ export type ApiError<T extends string = string, E extends object = object> = ResponseError<ApiErrorOptions<T, E>>;
1
10
  export type ValueOf<T> = T[keyof T];
2
11
  export declare const TenantType: {
3
12
  readonly Alauda: "alauda";
@@ -26,7 +35,7 @@ export interface AuthInfo {
26
35
  tenant?: string;
27
36
  user: AuthUser;
28
37
  }
29
- export interface CloudAuthRegion {
30
- name: 'global' | 'china';
31
- value: string;
38
+ export interface CloudAuth {
39
+ token?: string;
40
+ detail?: AuthInfo;
32
41
  }
@@ -0,0 +1,8 @@
1
+ import type { AuthInfo, CloudAuth } from './types.ts';
2
+ export declare const setLocalStorage: (key: string, value?: string | null) => void;
3
+ export declare const getAuthInfoFromToken: (token?: string | null) => AuthInfo | undefined;
4
+ export declare const isLoggedIn: (authInfo: CloudAuth | null) => authInfo is CloudAuth & {
5
+ detail: AuthInfo;
6
+ };
7
+ export declare const isIoSite: () => boolean;
8
+ export declare const getCloudOrigin: () => string;
@@ -1,4 +1,5 @@
1
1
  import { decodeUrl } from 'ab64';
2
+ import siteData from 'virtual-site-data';
2
3
  export const setLocalStorage = (key, value) => {
3
4
  if (value == null) {
4
5
  localStorage.removeItem(key);
@@ -30,3 +31,7 @@ export const getAuthInfoFromToken = (token) => {
30
31
  },
31
32
  };
32
33
  };
34
+ export const isLoggedIn = (authInfo) => Boolean(authInfo?.detail);
35
+ export const isIoSite = () => siteData.base.startsWith('/russian/') ||
36
+ location.hostname.endsWith('.alauda.io');
37
+ export const getCloudOrigin = () => `https://cloud.alauda.${isIoSite() ? 'io' : 'cn'}`;
@@ -11,7 +11,7 @@ export const globalPlugin = ({ version, download, }) => {
11
11
  globalStyles: pkgResolve('styles/global.scss'),
12
12
  globalUIComponents: fs
13
13
  .readdirSync(globalComponentsDir, 'utf8')
14
- .map((component) => path.resolve(globalComponentsDir, component, 'index')),
14
+ .map((component) => path.resolve(globalComponentsDir, component)),
15
15
  markdown: {
16
16
  globalComponents: fs
17
17
  .readdirSync(componentsDir)
@@ -39,5 +39,21 @@ export const globalPlugin = ({ version, download, }) => {
39
39
  }, null, isProd ? 0 : 2)}`,
40
40
  };
41
41
  },
42
+ addPages(config) {
43
+ const loginPath = baseResolve('login');
44
+ if ((config.themeConfig?.locales?.length ?? 0) < 1) {
45
+ return [
46
+ {
47
+ routePath: '/login',
48
+ filepath: loginPath,
49
+ },
50
+ ];
51
+ }
52
+ const lang = config.lang;
53
+ return config.themeConfig.locales.map((l) => ({
54
+ routePath: l.lang && l.lang !== lang ? `/${l.lang}/login` : '/login',
55
+ filepath: loginPath,
56
+ }));
57
+ },
42
58
  };
43
59
  };
@@ -1,9 +1,8 @@
1
- import { useState, useEffect, useMemo, useCallback } from 'react';
2
- import { useLocation } from 'react-router';
1
+ import { useSearchParams } from '@rspress/core/dist/runtime.js';
2
+ import { useState, useEffect, useCallback } from 'react';
3
3
  import { FALSY_VALUES } from '../../shared/index.js';
4
4
  export function useIsPrintQuery() {
5
- const { search } = useLocation();
6
- const searchParams = useMemo(() => new URLSearchParams(search), [search]);
5
+ const [searchParams] = useSearchParams();
7
6
  const print = searchParams.get('print');
8
7
  return print != null && !FALSY_VALUES.has(print);
9
8
  }
@@ -1,3 +1,3 @@
1
1
  import type { Language } from '../../shared/index.js';
2
2
  export declare const useLang: () => Language;
3
- export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "password" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "view" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf" | "view_docs_as_pdf" | "ai_assistant" | "close" | "exclamation" | "semicolon" | "period" | "colon" | "user_login" | "user_login_tip" | "customer_portal_global" | "customer_portal_china" | "user_login_region_china_tip" | "user_login_region_global_tip" | "account_id" | "username" | "captcha" | "login" | "current_field" | "field_required" | "ERR_INTERNET_DISCONNECTED" | "AccountDisabledError" | "CaptchaError" | "LoginError" | "NetworkError" | "TenantError" | "TenantNotFoundError" | "logout" | "hi_there" | "ai_assistant_tip" | "ai_assistant_placeholder" | "max_chars_exceeded_tip" | "thinking" | "thinking_process" | "referenced_doc_links" | "view_more_related_docs" | "view_less_related_docs" | "new_chat") => string;
3
+ export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "login" | "create" | "update" | "password" | "close" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "view" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf" | "view_docs_as_pdf" | "ai_assistant" | "exclamation" | "semicolon" | "period" | "colon" | "user_login" | "user_login_tip1" | "user_login_tip2" | "customer_portal_global" | "customer_portal_china" | "account_id" | "username" | "captcha" | "current_field" | "field_required" | "ERR_INTERNET_DISCONNECTED" | "AccountDisabledError" | "CaptchaError" | "LoginError" | "NetworkError" | "TenantError" | "TenantNotFoundError" | "logout" | "hi_there" | "ai_assistant_tip" | "ai_assistant_placeholder" | "max_chars_exceeded_tip" | "thinking" | "thinking_process" | "referenced_doc_links" | "view_more_related_docs" | "view_less_related_docs" | "new_chat") => string;
@@ -24,11 +24,10 @@ declare const en: {
24
24
  period: string;
25
25
  colon: string;
26
26
  user_login: string;
27
- user_login_tip: string;
27
+ user_login_tip1: string;
28
+ user_login_tip2: string;
28
29
  customer_portal_global: string;
29
30
  customer_portal_china: string;
30
- user_login_region_china_tip: string;
31
- user_login_region_global_tip: string;
32
31
  account_id: string;
33
32
  username: string;
34
33
  password: string;
@@ -83,11 +82,10 @@ export declare const TRANSLATIONS: {
83
82
  period: string;
84
83
  colon: string;
85
84
  user_login: string;
86
- user_login_tip: string;
85
+ user_login_tip1: string;
86
+ user_login_tip2: string;
87
87
  customer_portal_global: string;
88
88
  customer_portal_china: string;
89
- user_login_region_china_tip: string;
90
- user_login_region_global_tip: string;
91
89
  account_id: string;
92
90
  username: string;
93
91
  password: string;
@@ -140,11 +138,10 @@ export declare const TRANSLATIONS: {
140
138
  period: string;
141
139
  colon: string;
142
140
  user_login: string;
143
- user_login_tip: string;
141
+ user_login_tip1: string;
142
+ user_login_tip2: string;
144
143
  customer_portal_global: string;
145
144
  customer_portal_china: string;
146
- user_login_region_china_tip: string;
147
- user_login_region_global_tip: string;
148
145
  account_id: string;
149
146
  username: string;
150
147
  password: string;
@@ -197,11 +194,10 @@ export declare const TRANSLATIONS: {
197
194
  period: string;
198
195
  colon: string;
199
196
  user_login: string;
200
- user_login_tip: string;
197
+ user_login_tip1: string;
198
+ user_login_tip2: string;
201
199
  customer_portal_global: string;
202
200
  customer_portal_china: string;
203
- user_login_region_china_tip: string;
204
- user_login_region_global_tip: string;
205
201
  account_id: string;
206
202
  username: string;
207
203
  password: string;
@@ -24,11 +24,10 @@ const en = {
24
24
  period: '. ',
25
25
  colon: ': ',
26
26
  user_login: 'User login',
27
- user_login_tip: 'Use the same credentials as for the "Customer Portal" site.',
27
+ user_login_tip1: 'Use the same credentials as for the "',
28
+ user_login_tip2: '" site.',
28
29
  customer_portal_global: 'Customer Portal Global',
29
30
  customer_portal_china: 'Customer Portal China',
30
- user_login_region_china_tip: 'If you are a customer in the Chinese Mainland, select Customer Portal China;',
31
- user_login_region_global_tip: 'if you are a customer outside the Chinese Mainland, select Customer Portal Global.',
32
31
  account_id: 'Account ID',
33
32
  username: 'Username',
34
33
  password: 'Password',
@@ -81,11 +80,10 @@ const zh = {
81
80
  period: '。',
82
81
  colon: ':',
83
82
  user_login: '用户登录',
84
- user_login_tip: '使用与“客户门户”站点相同的凭据。',
83
+ user_login_tip1: '使用与“',
84
+ user_login_tip2: '”站点相同的凭据。',
85
85
  customer_portal_global: '客户门户全球',
86
86
  customer_portal_china: '客户门户中国',
87
- user_login_region_china_tip: '如果您是中国大陆的客户,请选择客户门户中国;',
88
- user_login_region_global_tip: '如果您是中国大陆以外的客户,请选择客户门户全球。',
89
87
  account_id: '账号 ID',
90
88
  username: '用户名',
91
89
  password: '密码',
@@ -138,11 +136,10 @@ const ru = {
138
136
  period: '. ',
139
137
  colon: ': ',
140
138
  user_login: 'Вход пользователя',
141
- user_login_tip: 'Используйте те же учетные данные, что и для сайта "Портал клиентов".',
139
+ user_login_tip1: 'Используйте те же учетные данные, что и для сайта "',
140
+ user_login_tip2: '".',
142
141
  customer_portal_global: 'Портал клиентов Глобальный',
143
142
  customer_portal_china: 'Портал клиентов Китай',
144
- user_login_region_china_tip: 'Если вы клиент в материковом Китае, выберите Портал клиентов Китай;',
145
- user_login_region_global_tip: 'если вы клиент за пределами материкового Китая, выберите Портал клиентов Глобальный.',
146
143
  account_id: 'Идентификатор аккаунта',
147
144
  username: 'Имя пользователя',
148
145
  password: 'Пароль',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.14.3",
3
+ "version": "1.15.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -40,9 +40,9 @@
40
40
  "rspress-plugins"
41
41
  ],
42
42
  "dependencies": {
43
- "@alauda/doom-export": "^0.2.0",
44
- "@cspell/eslint-plugin": "^9.2.1",
45
- "@eslint-react/eslint-plugin": "^2.2.2",
43
+ "@alauda/doom-export": "^0.2.1",
44
+ "@cspell/eslint-plugin": "^9.2.2",
45
+ "@eslint-react/eslint-plugin": "^2.2.3",
46
46
  "@inquirer/prompts": "^7.9.0",
47
47
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
48
48
  "@rsbuild/plugin-react": "^1.4.1",
@@ -74,7 +74,7 @@
74
74
  "mdast-util-to-markdown": "^2.1.2",
75
75
  "mdast-util-to-string": "^4.0.0",
76
76
  "mermaid": "^11.12.0",
77
- "openai": "^6.5.0",
77
+ "openai": "^6.6.0",
78
78
  "openapi-types": "^12.1.3",
79
79
  "p-ratelimit": "^1.0.1",
80
80
  "picomatch": "^4.0.3",
@@ -102,7 +102,7 @@
102
102
  "tinyglobby": "^0.2.15",
103
103
  "type-fest": "^5.1.0",
104
104
  "typescript": "^5.9.3",
105
- "typescript-eslint": "^8.46.1",
105
+ "typescript-eslint": "^8.46.2",
106
106
  "unified": "^11.0.5",
107
107
  "unified-lint-rule": "^3.0.1",
108
108
  "unist-util-position": "^5.0.0",
@@ -0,0 +1,9 @@
1
+ body:has(.container) :global {
2
+ #search-container,
3
+ .rspress-nav-search-button,
4
+ aside,
5
+ .rspress-doc-footer,
6
+ [class^='aside-container'] {
7
+ display: none;
8
+ }
9
+ }
@@ -17,6 +17,7 @@
17
17
  }
18
18
 
19
19
  .content {
20
+ margin-bottom: 12px;
20
21
  text-align: center;
21
22
  }
22
23
 
@@ -1,3 +0,0 @@
1
- import { type FormHTMLAttributes } from 'react';
2
- export type LoginFormProps = FormHTMLAttributes<HTMLFormElement>;
3
- export declare const LoginForm: ({ onSubmit, ...props }: LoginFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,88 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useRef, useState, } from 'react';
3
- import { Tooltip } from 'react-tooltip';
4
- import { ApiMethod, ResponseError, xfetch } from 'x-fetch';
5
- import { CLOUD_AUTH_ORIGIN_KEY, CLOUD_AUTH_ORIGIN_VALUES, CLOUD_AUTH_ORIGINS, } from "../../../constants.js";
6
- import { useCloudAuth } from "../../../context.js";
7
- import { ApiErrorAlert } from "../ApiErrorAlert/index.js";
8
- import { Button } from "../Button/index.js";
9
- import { CaptchaInput } from "../CaptchaInput/index.js";
10
- import { FocusInput } from "../FocusInput/index.js";
11
- import { FormItem } from "../FormItem/index.js";
12
- import { Radio, RadioGroup } from "../Radio/index.js";
13
- import { cryptoPassword } from "./utils.js";
14
- import QuestionCycleIcon from '@alauda/doom/assets/question-circle.svg?react';
15
- import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
16
- const isLoginError = (err) => err instanceof ResponseError;
17
- export const LoginForm = ({ onSubmit, ...props }) => {
18
- const t = useTranslation();
19
- const [origin, setOrigin] = useState(() => {
20
- let origin = localStorage.getItem(CLOUD_AUTH_ORIGIN_KEY);
21
- if (origin == null || !CLOUD_AUTH_ORIGIN_VALUES.includes(origin)) {
22
- origin = CLOUD_AUTH_ORIGIN_VALUES[0];
23
- localStorage.setItem(CLOUD_AUTH_ORIGIN_KEY, origin);
24
- }
25
- return origin;
26
- });
27
- const [loading, setLoading] = useState();
28
- const [error, setError] = useState();
29
- const pwdPubkeyRef = useRef(null);
30
- const onRegionChange = useMemoizedFn((ev) => {
31
- const origin = ev.target.value;
32
- setOrigin(origin);
33
- setError(undefined);
34
- pwdPubkeyRef.current = null;
35
- localStorage.setItem(CLOUD_AUTH_ORIGIN_KEY, origin);
36
- });
37
- const { setAuthBasic } = useCloudAuth();
38
- const captchaId = error?.data?.extra?.captchaId;
39
- const [timestamp, setTimestamp] = useState();
40
- const handleSubmit = useMemoizedFn(async (ev) => {
41
- ev.preventDefault();
42
- ev.stopPropagation();
43
- onSubmit?.(ev);
44
- const formData = new FormData(ev.currentTarget);
45
- const origin = formData.get('origin');
46
- formData.delete('origin');
47
- setLoading(true);
48
- if (pwdPubkeyRef.current == null) {
49
- try {
50
- pwdPubkeyRef.current = await xfetch(`${origin}/api/v1/pubkey`);
51
- }
52
- catch (err) {
53
- setError(err);
54
- setLoading(false);
55
- return;
56
- }
57
- }
58
- formData.set('password', cryptoPassword(pwdPubkeyRef.current, formData.get('password')));
59
- if (captchaId) {
60
- formData.set('captchaId', captchaId);
61
- }
62
- try {
63
- const { accessToken } = await xfetch(`${origin}/api/v1/login`, {
64
- method: ApiMethod.POST,
65
- body: formData,
66
- });
67
- setAuthBasic({
68
- origin,
69
- token: accessToken,
70
- });
71
- }
72
- catch (err) {
73
- if (!isLoginError(err)) {
74
- throw err;
75
- }
76
- if (err.data?.reason === 'PubkeyExpireError') {
77
- pwdPubkeyRef.current = null;
78
- await handleSubmit(ev);
79
- return;
80
- }
81
- setError(err);
82
- }
83
- finally {
84
- setLoading(false);
85
- }
86
- });
87
- return (_jsxs("form", { onSubmit: handleSubmit, ...props, children: [_jsx(FormItem, { children: _jsx(RadioGroup, { name: "origin", value: origin, onChange: onRegionChange, suffix: _jsxs(_Fragment, { children: [_jsx(QuestionCycleIcon, { className: "region-tip" }), _jsxs(Tooltip, { anchorSelect: ".region-tip", place: "top-start", children: [_jsx("div", { children: t('user_login_region_china_tip') }), _jsx("div", { children: t('user_login_region_global_tip') })] })] }), children: CLOUD_AUTH_ORIGINS.map(({ name, value }) => (_jsx(Radio, { label: t(`customer_portal_${name}`), value: value }, name))) }) }), error && _jsx(ApiErrorAlert, { error: error }), _jsx(FormItem, { label: t('account_id'), required: true, children: _jsx(FocusInput, { name: "tenant", placeholder: t('account_id') }) }), _jsx(FormItem, { label: t('username'), required: true, children: _jsx(FocusInput, { name: "username", placeholder: t('username') }) }), _jsx(FormItem, { label: t('password'), required: true, children: _jsx(FocusInput, { name: "password", type: "password", placeholder: t('password') }) }), captchaId && (_jsx(FormItem, { label: t('captcha'), required: true, children: _jsx(CaptchaInput, { Component: FocusInput, placeholder: t('captcha'), origin: origin, captchaId: captchaId, timestamp: timestamp, onTimestampChange: setTimestamp }) })), _jsx(FormItem, { children: _jsx(Button, { type: "primary", htmlType: "submit", block: true, loading: loading, children: t('login') }) })] }));
88
- };
@@ -1,7 +0,0 @@
1
- import { type ChangeEvent } from 'react';
2
- export interface RadioProps {
3
- label: string;
4
- value: string | number;
5
- onChange?: (ev: ChangeEvent<HTMLInputElement>) => void;
6
- }
7
- export declare const Radio: ({ label, value, onChange }: RadioProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,11 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, use } from 'react';
3
- import { RadioGroupContext } from "./context.js";
4
- export const Radio = ({ label, value, onChange }) => {
5
- const { name, value: groupValue, onChange: onGroupChange, } = use(RadioGroupContext);
6
- const handleChange = useCallback((ev) => {
7
- onChange?.(ev);
8
- onGroupChange?.(ev);
9
- }, [onChange, onGroupChange]);
10
- return (_jsxs("label", { className: "radio", children: [_jsx("input", { name: name, type: "radio", value: value, onChange: handleChange, checked: value === groupValue }), _jsx("span", { className: "radio__label", children: label })] }));
11
- };
@@ -1,11 +0,0 @@
1
- import { type ChangeEvent, type ReactNode } from 'react';
2
- export interface RadioGroupProps {
3
- id?: string;
4
- name?: string;
5
- value?: string;
6
- onChange?: (value: ChangeEvent<HTMLInputElement>) => void;
7
- children?: ReactNode;
8
- prefix?: ReactNode;
9
- suffix?: ReactNode;
10
- }
11
- export declare const RadioGroup: ({ id: id_, name, value, onChange, children, prefix, suffix, }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,21 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useId, useMemo, useState, } from 'react';
3
- import { RadioGroupContext } from "./context.js";
4
- export const RadioGroup = ({ id: id_, name, value, onChange, children, prefix, suffix, }) => {
5
- const innerId = useId();
6
- const id = id_ || innerId;
7
- name ??= id;
8
- const [innerValue, setInnerValue] = useState(value ?? '');
9
- if (value != null && innerValue !== value) {
10
- setInnerValue(value);
11
- }
12
- const handleChange = useCallback((ev) => {
13
- onChange?.(ev);
14
- setInnerValue(ev.target.value);
15
- }, [onChange]);
16
- return (_jsx("div", { id: id, className: "radio-group", children: _jsxs(RadioGroupContext, { value: useMemo(() => ({
17
- name,
18
- value: innerValue,
19
- onChange: handleChange,
20
- }), [name, innerValue, handleChange]), children: [!!prefix && _jsx("span", { className: "radio-group__prefix", children: prefix }), children, !!suffix && _jsx("span", { className: "radio-group__suffix", children: suffix })] }) }));
21
- };
@@ -1,7 +0,0 @@
1
- import { type ChangeEvent } from 'react';
2
- export interface RadioGroupContext<T = unknown> {
3
- name: string;
4
- value: T;
5
- onChange?: (value: ChangeEvent<HTMLInputElement>) => void;
6
- }
7
- export declare const RadioGroupContext: import("react").Context<RadioGroupContext<unknown>>;
@@ -1,2 +0,0 @@
1
- import { createContext } from 'react';
2
- export const RadioGroupContext = createContext(null);
@@ -1,2 +0,0 @@
1
- export * from './Radio.tsx';
2
- export * from './RadioGroup.tsx';
@@ -1,2 +0,0 @@
1
- export * from "./Radio.js";
2
- export * from "./RadioGroup.js";
@@ -1,9 +0,0 @@
1
- import type { ResponseError } from 'x-fetch';
2
- export interface ApiErrorOptions<R extends string = string, E extends object = object, T = unknown> {
3
- code: number;
4
- reason: R;
5
- message: string;
6
- extra?: E;
7
- details?: T[];
8
- }
9
- export type ApiError<T extends string = string, E extends object = object> = ResponseError<ApiErrorOptions<T, E>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { CloudAuthRegion } from './types.js';
2
- export declare const CLOUD_AUTH_ORIGIN_KEY = "__CLOUD_AUTH_ORIGIN__";
3
- export declare const CLOUD_AUTH_TOKEN_KEY = "__CLOUD_AUTH_TOKEN__";
4
- declare const CLOUD_AUTH_ORIGINS: CloudAuthRegion[];
5
- export declare const CLOUD_AUTH_ORIGIN_VALUES: string[];
6
- export { CLOUD_AUTH_ORIGINS };
@@ -1,14 +0,0 @@
1
- export const CLOUD_AUTH_ORIGIN_KEY = '__CLOUD_AUTH_ORIGIN__';
2
- export const CLOUD_AUTH_TOKEN_KEY = '__CLOUD_AUTH_TOKEN__';
3
- const CLOUD_AUTH_ORIGINS = [
4
- {
5
- name: 'global',
6
- value: 'https://cloud.alauda.io',
7
- },
8
- {
9
- name: 'china',
10
- value: 'https://cloud.alauda.cn',
11
- },
12
- ];
13
- export const CLOUD_AUTH_ORIGIN_VALUES = CLOUD_AUTH_ORIGINS.map(({ value }) => value);
14
- export { CLOUD_AUTH_ORIGINS };
@@ -1,20 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import type { AuthInfo } from './types.js';
3
- export interface CloudAuth {
4
- origin: string;
5
- token?: string;
6
- detail?: AuthInfo;
7
- }
8
- export interface CloudAuthContext {
9
- authInfo: CloudAuth | null;
10
- setAuthBasic: (authBasic?: {
11
- origin: string;
12
- token: string;
13
- } | null) => void;
14
- }
15
- export declare const CloudAuthContext: import("react").Context<CloudAuthContext>;
16
- export declare const useCloudAuth: () => CloudAuthContext;
17
- export declare const getCloudAuth: () => CloudAuth | null;
18
- export declare const CloudAuthProvider: ({ children }: {
19
- children: ReactNode;
20
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,31 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, use, useMemo, useState } from 'react';
3
- import { CLOUD_AUTH_ORIGIN_KEY, CLOUD_AUTH_TOKEN_KEY } from './constants.js';
4
- import { getAuthInfoFromToken, setLocalStorage } from './utils.js';
5
- export const CloudAuthContext = createContext(null);
6
- export const useCloudAuth = () => use(CloudAuthContext);
7
- export const getCloudAuth = () => {
8
- const origin = localStorage.getItem(CLOUD_AUTH_ORIGIN_KEY);
9
- const token = localStorage.getItem(CLOUD_AUTH_TOKEN_KEY);
10
- if (origin == null) {
11
- return null;
12
- }
13
- if (token == null) {
14
- return { origin };
15
- }
16
- return { origin, token, detail: getAuthInfoFromToken(token) };
17
- };
18
- export const CloudAuthProvider = ({ children }) => {
19
- const [authInfo, setAuthInfo] = useState(getCloudAuth);
20
- return (_jsx(CloudAuthContext, { value: useMemo(() => ({
21
- authInfo,
22
- setAuthBasic(authBasic) {
23
- // keep origin in localStorage for next login
24
- if (authBasic?.origin != null) {
25
- setLocalStorage(CLOUD_AUTH_ORIGIN_KEY, authBasic.origin);
26
- }
27
- setLocalStorage(CLOUD_AUTH_TOKEN_KEY, authBasic?.token);
28
- setAuthInfo(getCloudAuth);
29
- },
30
- }), [authInfo]), children: children }));
31
- };
@@ -1,3 +0,0 @@
1
- import type { AuthInfo } from './types.ts';
2
- export declare const setLocalStorage: (key: string, value?: string) => void;
3
- export declare const getAuthInfoFromToken: (token?: string | null) => AuthInfo | undefined;
File without changes