@giteeteam/apps-team-components 1.2.2-alpha.4 → 1.3.0-alpha.1

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 (170) hide show
  1. package/README.md +8 -15
  2. package/dist/components/common/expand-component/index.d.ts +23 -0
  3. package/dist/components/common/expand-component/index.js +65 -0
  4. package/dist/components/common/expand-component/style.d.ts +2 -0
  5. package/dist/components/common/expand-component/style.js +8 -0
  6. package/dist/components/common/item-icon/ItemIcon.d.ts +8 -0
  7. package/dist/components/common/item-icon/ItemIcon.js +6 -0
  8. package/dist/components/common/overflow-tooltip/OverflowTooltip.d.ts +19 -0
  9. package/dist/components/common/overflow-tooltip/OverflowTooltip.js +54 -0
  10. package/dist/components/common/style/mixin.d.ts +2 -0
  11. package/dist/components/common/style/mixin.js +17 -0
  12. package/dist/components/common/utils.d.ts +6 -0
  13. package/dist/components/common/utils.js +54 -0
  14. package/dist/components/default-empty-icon/config.d.ts +2 -0
  15. package/dist/components/default-empty-icon/config.js +19 -0
  16. package/dist/components/default-empty-icon/index.d.ts +5 -0
  17. package/dist/components/default-empty-icon/index.js +23 -0
  18. package/dist/components/default-empty-icon/style.d.ts +11 -0
  19. package/dist/components/default-empty-icon/style.js +64 -0
  20. package/dist/components/default-empty-icon/types.d.ts +29 -0
  21. package/dist/components/default-empty-icon/types.js +6 -0
  22. package/dist/components/field-behavior/fields/type.js +1 -1
  23. package/dist/components/fields/base-component/types.d.ts +1 -0
  24. package/dist/components/fields/base-component/utils.d.ts +2 -0
  25. package/dist/components/fields/base-component/utils.js +9 -0
  26. package/dist/components/fields/bind-workspace/hooks.js +3 -3
  27. package/dist/components/fields/dropdown/BaseField.d.ts +24 -2
  28. package/dist/components/fields/dropdown/BaseField.js +562 -1
  29. package/dist/components/fields/dropdown/Cell.d.ts +4 -0
  30. package/dist/components/fields/dropdown/Cell.js +6 -0
  31. package/dist/components/fields/dropdown/ReadView.js +16 -1
  32. package/dist/components/fields/dropdown/data.d.ts +9 -0
  33. package/dist/components/fields/dropdown/data.js +26 -0
  34. package/dist/components/fields/dropdown/hook.d.ts +103 -0
  35. package/dist/components/fields/dropdown/hook.js +152 -0
  36. package/dist/components/fields/dropdown/style.d.ts +16 -0
  37. package/dist/components/fields/dropdown/style.js +90 -0
  38. package/dist/components/fields/hooks/useViewClass.d.ts +11 -0
  39. package/dist/components/fields/hooks/useViewClass.js +18 -0
  40. package/dist/components/fields/item-type/ItemTypeIcon.d.ts +9 -0
  41. package/dist/components/fields/item-type/ItemTypeIcon.js +33 -0
  42. package/dist/components/fields/item-type/style/index.d.ts +1 -0
  43. package/dist/components/fields/item-type/style/index.js +6 -0
  44. package/dist/components/fields/key/ReadView.js +2 -2
  45. package/dist/components/fields/priority/ReadView.js +1 -1
  46. package/dist/components/fields/status/SelectTransition.js +2 -2
  47. package/dist/components/fields/status/TransitionButton.d.ts +0 -3
  48. package/dist/components/fields/status/TransitionButton.js +1 -7
  49. package/dist/components/fields/user-group/ReadView.js +1 -1
  50. package/dist/components/filters/filter-search/utils.d.ts +4 -0
  51. package/dist/components/filters/filter-search/utils.js +28 -0
  52. package/dist/components/table-components/EditTableCell.d.ts +1 -0
  53. package/dist/components/table-components/EditTableCell.js +2 -1
  54. package/dist/components/table-components/index.js +4 -4
  55. package/dist/components/table-components/utils.js +2 -0
  56. package/dist/icons/SyncIconFont.d.ts +6 -0
  57. package/dist/icons/SyncIconFont.js +15 -0
  58. package/dist/icons/createFromIconFontClass.d.ts +4 -0
  59. package/dist/icons/createFromIconFontClass.js +33 -0
  60. package/dist/icons/empty-icon/data-empty.png +0 -0
  61. package/dist/icons/empty-icon/forbidden.png +0 -0
  62. package/dist/icons/empty-icon/index.d.ts +1 -0
  63. package/dist/icons/empty-icon/index.js +8 -0
  64. package/dist/icons/empty-icon/large-item@2x.png +0 -0
  65. package/dist/icons/empty-icon/large-workspace@2x.png +0 -0
  66. package/dist/icons/empty-icon/load-error.png +0 -0
  67. package/dist/icons/empty-icon/not-found.png +0 -0
  68. package/dist/icons/empty-icon/small-default@2x.png +0 -0
  69. package/dist/icons/empty-icon/workspace-empty.svg +127 -0
  70. package/dist/icons/index.d.ts +58 -1
  71. package/dist/icons/index.js +294 -0
  72. package/dist/icons/style/index.d.ts +2 -0
  73. package/dist/icons/style/index.js +23 -0
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.js +1 -0
  76. package/dist/lib/app/utils.d.ts +3 -0
  77. package/dist/lib/app/utils.js +16 -0
  78. package/dist/lib/config.d.ts +14 -0
  79. package/dist/lib/config.js +45 -0
  80. package/dist/lib/constants/code.d.ts +4 -0
  81. package/dist/lib/constants/code.js +4 -0
  82. package/dist/lib/constants/field.d.ts +1 -0
  83. package/dist/lib/constants/field.js +2 -0
  84. package/dist/lib/contexts/index.js +2 -2
  85. package/dist/lib/contexts/teamConfig.d.ts +3 -0
  86. package/dist/lib/contexts/teamConfig.js +19 -4
  87. package/dist/lib/error/index.d.ts +2 -0
  88. package/dist/lib/error/index.js +2 -0
  89. package/dist/lib/error/log.d.ts +10 -0
  90. package/dist/lib/error/log.js +25 -0
  91. package/dist/lib/error/utils.d.ts +14 -0
  92. package/dist/lib/error/utils.js +50 -0
  93. package/dist/lib/error/withServerError.d.ts +1 -0
  94. package/dist/lib/error/withServerError.js +1 -0
  95. package/dist/lib/fetch.d.ts +45 -0
  96. package/dist/lib/fetch.js +301 -0
  97. package/dist/lib/global.d.ts +18 -0
  98. package/dist/lib/global.js +18 -0
  99. package/dist/lib/i18n.d.ts +1 -0
  100. package/dist/lib/i18n.js +1 -0
  101. package/dist/lib/icons/utils.d.ts +23 -0
  102. package/dist/lib/icons/utils.js +59 -0
  103. package/dist/lib/path.d.ts +5 -0
  104. package/dist/lib/path.js +47 -0
  105. package/dist/lib/router.d.ts +23 -0
  106. package/dist/lib/router.js +20 -0
  107. package/dist/lib/storage.d.ts +10 -0
  108. package/dist/lib/storage.js +62 -0
  109. package/dist/lib/swr/throttleWithCache.d.ts +17 -0
  110. package/dist/lib/swr/throttleWithCache.js +108 -0
  111. package/dist/lib/throttleFetch.d.ts +2 -0
  112. package/dist/lib/throttleFetch.js +66 -0
  113. package/dist/lib/useConfig.d.ts +8 -0
  114. package/dist/lib/useConfig.js +28 -0
  115. package/dist/lib/workflow.js +19 -85
  116. package/dist/locales/index.d.ts +45 -0
  117. package/dist/locales/index.js +45 -0
  118. package/dist/public/icons/BulbIcon.svg +1 -0
  119. package/dist/public/icons/Cloud.svg +1 -0
  120. package/dist/public/icons/ConsultIcon.svg +1 -0
  121. package/dist/public/icons/Demo.svg +1 -0
  122. package/dist/public/icons/ErrorTemplate.svg +1 -0
  123. package/dist/public/icons/Fail.svg +1 -0
  124. package/dist/public/icons/Flag.svg +1 -0
  125. package/dist/public/icons/GiteeIcon.svg +1 -0
  126. package/dist/public/icons/IntelligenceGradient.svg +1 -0
  127. package/dist/public/icons/Issue_Approval.svg +1 -0
  128. package/dist/public/icons/Issue_Bug.svg +1 -0
  129. package/dist/public/icons/Issue_Demand.svg +1 -0
  130. package/dist/public/icons/Issue_Doc.svg +1 -0
  131. package/dist/public/icons/Issue_Idea.svg +1 -0
  132. package/dist/public/icons/Issue_List.svg +1 -0
  133. package/dist/public/icons/Issue_Plan.svg +1 -0
  134. package/dist/public/icons/Issue_Product.svg +1 -0
  135. package/dist/public/icons/Issue_Risk.svg +1 -0
  136. package/dist/public/icons/Issue_Story.svg +1 -0
  137. package/dist/public/icons/Issue_Subtask.svg +1 -0
  138. package/dist/public/icons/Issue_Task.svg +1 -0
  139. package/dist/public/icons/Issue_Test.svg +1 -0
  140. package/dist/public/icons/Issue_TestExcution.svg +1 -0
  141. package/dist/public/icons/Issue_TestPlan.svg +1 -0
  142. package/dist/public/icons/Issue_Time.svg +1 -0
  143. package/dist/public/icons/Issue_develop.svg +1 -0
  144. package/dist/public/icons/KanbanCover.svg +7 -0
  145. package/dist/public/icons/ListCover.svg +118 -0
  146. package/dist/public/icons/ManHour.svg +1 -0
  147. package/dist/public/icons/MobileIcon.svg +1 -0
  148. package/dist/public/icons/NoItemType.svg +10 -0
  149. package/dist/public/icons/ProductIcon.svg +1 -0
  150. package/dist/public/icons/RedFlagIcon.svg +1 -0
  151. package/dist/public/icons/Safe.svg +1 -0
  152. package/dist/public/icons/StarIcon.svg +61 -0
  153. package/dist/public/icons/StructureCover.svg +1 -0
  154. package/dist/public/icons/Success.svg +1 -0
  155. package/dist/public/icons/TeamIcon.svg +1 -0
  156. package/dist/public/icons/WebIcon.svg +1 -0
  157. package/dist/public/icons/iconfont.svg +467 -0
  158. package/dist/public/icons/iconfont.ttf +0 -0
  159. package/dist/public/icons/iconfont.woff +0 -0
  160. package/dist/public/icons/iconfont.woff2 +0 -0
  161. package/dist/public/icons/iconfont_multiple_color.js +1 -0
  162. package/dist/public/icons/iconfont_single_color.css +912 -0
  163. package/dist/public/icons/iconfont_single_color.js +1 -0
  164. package/dist/public/icons/loginBg.svg +1 -0
  165. package/dist/public/mockServiceWorker.js +284 -0
  166. package/dist/style/common.d.ts +1 -0
  167. package/dist/style/common.js +9 -0
  168. package/dist/style/global.d.ts +1 -0
  169. package/dist/style/global.js +8 -0
  170. package/package.json +41 -6
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ export { default as CreatedAtReadView } from './components/fields/created-at/Rea
12
12
  export { default as CreatedByReadView } from './components/fields/created-by/ReadView';
13
13
  export { default as DataQuoteReadView } from './components/fields/data-quote/ReadView';
14
14
  export { default as DateReadView } from './components/fields/date/ReadView';
15
+ export { default as DropdownCell } from './components/fields/dropdown/Cell';
15
16
  export { default as DropdownReadView } from './components/fields/dropdown/ReadView';
16
17
  export { default as FileReadView } from './components/fields/file/ReadView';
17
18
  export { default as FormulaReadView } from './components/fields/formula/ReadView';
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ export declare const requestIdleCallback: (((callback: IdleRequestCallback, options?: IdleRequestOptions) => number) & typeof globalThis.requestIdleCallback) | ((cb: any) => NodeJS.Timeout);
3
+ export declare const cancelIdleCallback: ((handle: number) => void) & typeof globalThis.cancelIdleCallback;
@@ -0,0 +1,16 @@
1
+ export const requestIdleCallback = (window === null || window === void 0 ? void 0 : window.requestIdleCallback) ||
2
+ function (cb) {
3
+ const start = Date.now();
4
+ return setTimeout(function () {
5
+ cb({
6
+ didTimeout: false,
7
+ timeRemaining: function () {
8
+ return Math.max(0, 50 - (Date.now() - start));
9
+ },
10
+ });
11
+ }, 1);
12
+ };
13
+ export const cancelIdleCallback = (window === null || window === void 0 ? void 0 : window.cancelIdleCallback) ||
14
+ function (id) {
15
+ clearTimeout(id);
16
+ };
@@ -0,0 +1,14 @@
1
+ import { IPublicRuntimeProps, IUserConfig } from '../global';
2
+ export declare const getPublicRuntimeConfig: () => Partial<IPublicRuntimeProps>;
3
+ export declare const getUserConfig: () => Partial<IUserConfig>;
4
+ export declare const publicRuntimeConfig: Partial<IPublicRuntimeProps>;
5
+ export declare const userConfig: Partial<IUserConfig>;
6
+ export type LocalLng = string;
7
+ export declare function getAcceptLanguageHeader(locale: LocalLng): string;
8
+ export declare const getQiankunConfig: () => {
9
+ gateway: string;
10
+ appId: string;
11
+ sessionToken: string;
12
+ basePath: string;
13
+ locales: string;
14
+ };
@@ -0,0 +1,45 @@
1
+ export const getPublicRuntimeConfig = () => {
2
+ var _a;
3
+ if (typeof window !== 'undefined') {
4
+ return (_a = window.__PROXIMA_DATA__) === null || _a === void 0 ? void 0 : _a.publicRuntimeConfig;
5
+ }
6
+ return {};
7
+ };
8
+ export const getUserConfig = () => {
9
+ var _a;
10
+ if (typeof window !== 'undefined') {
11
+ return (_a = window.__PROXIMA_DATA__) === null || _a === void 0 ? void 0 : _a.userConfig;
12
+ }
13
+ return {};
14
+ };
15
+ export const publicRuntimeConfig = getPublicRuntimeConfig() || {};
16
+ export const userConfig = getUserConfig();
17
+ export function getAcceptLanguageHeader(locale) {
18
+ switch (locale) {
19
+ case 'zh-CN':
20
+ return 'zh-CN;q=0.9,zh;q=0.8,en;q=0.7';
21
+ case 'zh':
22
+ return 'zh;q=0.8,en;q=0.7';
23
+ case 'ru-RU':
24
+ return 'ru-RU;q=0.9,ru;q=0.8,en;q=0.7';
25
+ case 'ru':
26
+ return 'ru;q=0.8,en;q=0.7';
27
+ case 'en-US':
28
+ return 'en-US,en;q=0.9';
29
+ case 'en':
30
+ default:
31
+ return 'en;q=0.9';
32
+ }
33
+ }
34
+ export const getQiankunConfig = () => {
35
+ var _a, _b, _c;
36
+ const context = (_a = window === null || window === void 0 ? void 0 : window.QiankunProps) === null || _a === void 0 ? void 0 : _a.context;
37
+ const env = context === null || context === void 0 ? void 0 : context.env;
38
+ return {
39
+ gateway: (env === null || env === void 0 ? void 0 : env.PROXIMA_GATEWAY) || '',
40
+ appId: env === null || env === void 0 ? void 0 : env.PROXIMA_APP_ID,
41
+ sessionToken: env === null || env === void 0 ? void 0 : env.sessionToken,
42
+ basePath: env === null || env === void 0 ? void 0 : env.PROXIMA_BASE_PATH,
43
+ locales: (_c = (_b = env === null || env === void 0 ? void 0 : env.LOCALES) !== null && _b !== void 0 ? _b : process.env.LOCALES) !== null && _c !== void 0 ? _c : 'zh',
44
+ };
45
+ };
@@ -0,0 +1,4 @@
1
+ export declare const ParseErrorCode: {
2
+ INVALID_SESSION_TOKEN: number;
3
+ OBJECT_NOT_FOUND: number;
4
+ };
@@ -0,0 +1,4 @@
1
+ export const ParseErrorCode = {
2
+ INVALID_SESSION_TOKEN: 209,
3
+ OBJECT_NOT_FOUND: 101,
4
+ };
@@ -0,0 +1 @@
1
+ export declare const REMOTE_DATA_QUOTE_FIELD_TYPE: string[];
@@ -0,0 +1,2 @@
1
+ import { FIELD_TYPE_KEY_MAPPINGS } from 'lib/global';
2
+ export const REMOTE_DATA_QUOTE_FIELD_TYPE = [FIELD_TYPE_KEY_MAPPINGS.RemoteFieldRemoteDataQuote];
@@ -11,7 +11,7 @@ import { ItemConfigProvider } from './itemConfig';
11
11
  import { TeamConfigProvider } from './teamConfig';
12
12
  import { TenantProvider } from './tenant';
13
13
  import { WorkflowConfigProvider } from './workflowConfig';
14
- export const LibraryProvider = ({ getPopupContainer, locale, tenant, datetimeFormat, teamBasePath, teamGateway, isMicroApp, workspaceKey, workflow, item, currentUser, emotionCacheOptions, children, }) => {
14
+ export const LibraryProvider = ({ getPopupContainer, locale, tenant, datetimeFormat, teamBasePath, teamGateway, isMicroApp, publicRuntimeConfig, userConfig, workspaceKey, workflow, item, currentUser, emotionCacheOptions, children, }) => {
15
15
  const emotionCache = useMemo(() => {
16
16
  return createCache({
17
17
  key: 'apps',
@@ -21,5 +21,5 @@ export const LibraryProvider = ({ getPopupContainer, locale, tenant, datetimeFor
21
21
  useEffect(() => {
22
22
  i18n.setLocale(locale);
23
23
  }, [locale]);
24
- return (_jsx(CacheProvider, { value: emotionCache, children: _jsx(AntdConfigProvider, { getPopupContainer: getPopupContainer, children: _jsx(TeamConfigProvider, { teamBasePath: teamBasePath, teamGateway: teamGateway, isMicroApp: isMicroApp, children: _jsx(TenantProvider, { tenant: tenant, children: _jsx(CurrentWorkspaceProvider, { workspaceKey: workspaceKey, children: _jsx(DatetimeFormatProvider, { datetimeFormat: datetimeFormat, children: _jsx(CurrentUserProvider, { currentUser: currentUser, children: _jsx(WorkflowConfigProvider, { workflow: workflow, children: _jsx(ItemConfigProvider, { item: item, children: children }) }) }) }) }) }) }) }) }));
24
+ return (_jsx(CacheProvider, { value: emotionCache, children: _jsx(AntdConfigProvider, { getPopupContainer: getPopupContainer, children: _jsx(TeamConfigProvider, { teamBasePath: teamBasePath, teamGateway: teamGateway, isMicroApp: isMicroApp, publicRuntimeConfig: publicRuntimeConfig, userConfig: userConfig, children: _jsx(TenantProvider, { tenant: tenant, children: _jsx(CurrentWorkspaceProvider, { workspaceKey: workspaceKey, children: _jsx(DatetimeFormatProvider, { datetimeFormat: datetimeFormat, children: _jsx(CurrentUserProvider, { currentUser: currentUser, children: _jsx(WorkflowConfigProvider, { workflow: workflow, children: _jsx(ItemConfigProvider, { item: item, children: children }) }) }) }) }) }) }) }) }));
25
25
  };
@@ -1,8 +1,11 @@
1
1
  import React from 'react';
2
+ import { IPublicRuntimeProps, IUserConfig } from '../../global';
2
3
  export interface ITeamConfigContext {
3
4
  teamGateway?: string;
4
5
  teamBasePath?: string;
5
6
  isMicroApp?: boolean;
7
+ publicRuntimeConfig?: Partial<IPublicRuntimeProps>;
8
+ userConfig?: Partial<IUserConfig>;
6
9
  }
7
10
  export declare const TeamConfigContext: React.Context<ITeamConfigContext>;
8
11
  export interface TeamConfigProviderProps extends React.PropsWithChildren, ITeamConfigContext {
@@ -1,11 +1,26 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
- import { createContext } from 'react';
2
+ import { createContext, useMemo } from 'react';
3
+ import { getPublicRuntimeConfig, getQiankunConfig, getUserConfig } from 'lib/config';
3
4
  const defaultContext = {};
4
5
  export const TeamConfigContext = createContext(defaultContext);
5
- export const TeamConfigProvider = ({ teamGateway, teamBasePath, isMicroApp, children, }) => {
6
+ export const TeamConfigProvider = ({ teamGateway, teamBasePath, isMicroApp, children, publicRuntimeConfig, userConfig, }) => {
7
+ const runtimeConfig = useMemo(() => {
8
+ const config = { ...getQiankunConfig(), ...getPublicRuntimeConfig(), ...(publicRuntimeConfig || {}) };
9
+ if (teamGateway) {
10
+ config.gateway = teamGateway;
11
+ }
12
+ if (teamBasePath) {
13
+ config.basePath = teamBasePath;
14
+ }
15
+ return config;
16
+ }, [publicRuntimeConfig, teamBasePath, teamGateway]);
17
+ const _userConfig = useMemo(() => {
18
+ const config = { ...getUserConfig(), ...(userConfig || {}) };
19
+ return config;
20
+ }, [userConfig]);
6
21
  return (_jsx(TeamConfigContext.Provider, { value: {
7
- teamGateway,
8
- teamBasePath,
9
22
  isMicroApp,
23
+ publicRuntimeConfig: runtimeConfig,
24
+ userConfig: _userConfig,
10
25
  }, children: children }));
11
26
  };
@@ -0,0 +1,2 @@
1
+ export { ErrorLog, default as log } from './log';
2
+ export * from './utils';
@@ -0,0 +1,2 @@
1
+ export { ErrorLog, default as log } from './log';
2
+ export * from './utils';
@@ -0,0 +1,10 @@
1
+ type ErrorLogOptions = {
2
+ timeout?: number;
3
+ };
4
+ export declare class ErrorLog {
5
+ private showError;
6
+ constructor(options?: ErrorLogOptions);
7
+ show: (msg: string) => void;
8
+ }
9
+ declare const _default: ErrorLog;
10
+ export default _default;
@@ -0,0 +1,25 @@
1
+ import { message } from 'antd';
2
+ import debug from 'debug';
3
+ import { throttle } from 'lodash-es';
4
+ import { isChinese } from 'components/common/utils';
5
+ import { i18n, nsSeparator } from 'lib/i18n';
6
+ const logger = debug('lib:error');
7
+ export class ErrorLog {
8
+ constructor(options) {
9
+ this.show = (msg) => {
10
+ logger('errorMessage', msg);
11
+ this.showError(msg);
12
+ };
13
+ const { timeout = 1000 } = options || {};
14
+ this.showError = throttle(msg => {
15
+ if (isChinese(msg) || msg.includes(nsSeparator)) {
16
+ message.error(msg);
17
+ return;
18
+ }
19
+ const MsgSet = i18n.t(`libs.error.MsgSet.${msg}`);
20
+ const errorMessage = (MsgSet === null || MsgSet === void 0 ? void 0 : MsgSet.includes('libs.error.MsgSet.')) ? msg : MsgSet;
21
+ message.error(errorMessage);
22
+ }, timeout, { trailing: false });
23
+ }
24
+ }
25
+ export default new ErrorLog();
@@ -0,0 +1,14 @@
1
+ export declare const LOGIN_PAGE_URL = "/login";
2
+ export declare const REDIRECT_API = "/frame";
3
+ type ErrorData = any;
4
+ export type ErrorResponse = any;
5
+ type GetErrorMessageHandler = (errorData: ErrorData, defaultMessage?: string) => string;
6
+ export declare const getRedirectURI: (errorPageURL: string | URL, baseAPI?: string) => string;
7
+ export declare const getRedirectURL: (redirectConfig: {
8
+ enabled: 'true' | 'false' | undefined;
9
+ }, errorPageURL: string | URL) => string;
10
+ export declare const getKeycloakErrorMsg: GetErrorMessageHandler;
11
+ export declare const getParseErrorMsg: GetErrorMessageHandler;
12
+ export declare const getNormalErrorMsg: GetErrorMessageHandler;
13
+ export declare const getErrorMessage: GetErrorMessageHandler;
14
+ export {};
@@ -0,0 +1,50 @@
1
+ import { isEmpty } from 'lodash-es';
2
+ export const LOGIN_PAGE_URL = '/login';
3
+ export const REDIRECT_API = '/frame';
4
+ export const getRedirectURI = (errorPageURL, baseAPI = LOGIN_PAGE_URL) => {
5
+ const redirectApi = new URL(baseAPI, errorPageURL);
6
+ redirectApi.searchParams.append('redirect_uri', errorPageURL);
7
+ return encodeURIComponent(redirectApi.toString());
8
+ };
9
+ export const getRedirectURL = (redirectConfig, errorPageURL) => {
10
+ if (isEmpty(redirectConfig))
11
+ return LOGIN_PAGE_URL;
12
+ if ((redirectConfig === null || redirectConfig === void 0 ? void 0 : redirectConfig.enabled) !== 'true')
13
+ return LOGIN_PAGE_URL;
14
+ const redirectUri = getRedirectURI(errorPageURL);
15
+ return redirectUri;
16
+ };
17
+ export const getKeycloakErrorMsg = errorData => {
18
+ if (!(errorData === null || errorData === void 0 ? void 0 : errorData.error_description) || !(errorData === null || errorData === void 0 ? void 0 : errorData.error))
19
+ return null;
20
+ return `${errorData.error}: ${errorData.error_description}`;
21
+ };
22
+ export const getParseErrorMsg = errorData => {
23
+ if (!(errorData === null || errorData === void 0 ? void 0 : errorData.code) || !(errorData === null || errorData === void 0 ? void 0 : errorData.error))
24
+ return null;
25
+ if ('string' === typeof errorData.error) {
26
+ return errorData.error;
27
+ }
28
+ else {
29
+ let msg;
30
+ try {
31
+ msg = JSON.stringify(errorData.error, null, 2);
32
+ }
33
+ catch (error) {
34
+ console.warn('parse error fail, source error', errorData);
35
+ }
36
+ if (msg)
37
+ return msg;
38
+ return null;
39
+ }
40
+ };
41
+ export const getNormalErrorMsg = errorData => 'string' === typeof errorData ? errorData : null;
42
+ export const getErrorMessage = (errorData, defaultMsg = '请求失败.') => {
43
+ const errorMessage = getNormalErrorMsg(errorData) ||
44
+ (errorData === null || errorData === void 0 ? void 0 : errorData.message) ||
45
+ (errorData === null || errorData === void 0 ? void 0 : errorData.error) ||
46
+ getKeycloakErrorMsg(errorData) ||
47
+ getParseErrorMsg(errorData) ||
48
+ defaultMsg;
49
+ return errorMessage;
50
+ };
@@ -0,0 +1 @@
1
+ export declare const IGNORE_URL: string[];
@@ -0,0 +1 @@
1
+ export const IGNORE_URL = ['/', '/login', '/register', '/resetPassword', '/configuration-guide', '/reset-config'];
@@ -0,0 +1,45 @@
1
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ export type WrapperAxiosRequestConfig<T = any> = AxiosRequestConfig<T> & {
3
+ useJson?: boolean;
4
+ useCompress?: boolean;
5
+ useJsonDecompress?: boolean;
6
+ hiddenErrorModal?: boolean;
7
+ ignoreParseHeaders?: boolean;
8
+ hiddenTimeout?: boolean;
9
+ };
10
+ export interface IFetchInstance extends AxiosInstance {
11
+ $get<T = any, P = any>(url: string, config?: {
12
+ params?: P;
13
+ } & Omit<WrapperAxiosRequestConfig, 'params'>): Promise<T>;
14
+ $delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
15
+ $head<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
16
+ $options<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
17
+ $post<T = any>(url: string, data?: any, config?: WrapperAxiosRequestConfig): Promise<T>;
18
+ $put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
19
+ $patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
20
+ }
21
+ export declare const useGetConfigTimeout: () => number;
22
+ export declare const baseApi = "/parse/api";
23
+ export declare const useGetLoginBasePath: () => string;
24
+ export declare const useGetServerGateway: () => string;
25
+ export declare const useGetGateway: (extraPath?: string) => string;
26
+ interface GetConfigParams {
27
+ sessionToken: string;
28
+ tenant: string;
29
+ Cookie: string;
30
+ }
31
+ interface ConfigType {
32
+ baseURL: string;
33
+ headers: {
34
+ 'X-Parse-Session-Token': string;
35
+ 'X-Parse-Application-Id': string;
36
+ Cookie: string;
37
+ };
38
+ }
39
+ export declare function useGetRequestConfig({ sessionToken, tenant, Cookie }: GetConfigParams): ConfigType;
40
+ export declare const useAxiosConfig: () => AxiosRequestConfig;
41
+ export declare const LOCALE_KEY = "lang";
42
+ export declare const useGetHeaderLang: () => string;
43
+ export declare const getGlobalEnv: () => Record<string, any>;
44
+ declare const useFetch: () => IFetchInstance;
45
+ export default useFetch;
@@ -0,0 +1,301 @@
1
+ import { useCallback, useContext, useEffect, useMemo } from 'react';
2
+ import axios, { HttpStatusCode } from 'axios';
3
+ import cjson from 'compressed-json';
4
+ import debug from 'debug';
5
+ import { toNumber } from 'lodash-es';
6
+ import { CANCEL_FETCH_STRING, REDIRECT_URL_KEY } from 'lib/global';
7
+ import throttleWithCache, { THROTTLE_TYPE } from 'lib/swr/throttleWithCache';
8
+ import { ParseErrorCode } from './constants/code';
9
+ import { TeamConfigContext } from './contexts/teamConfig';
10
+ import { IGNORE_URL } from './error/withServerError';
11
+ import { getErrorMessage, log as ErrorLog } from './error';
12
+ import { i18n } from './i18n';
13
+ import isInOne from './isInOne';
14
+ import { useGetSourcePath } from './path';
15
+ import { getCurLocationInfo } from './router';
16
+ import { removeParseItems } from './storage';
17
+ import { useAppProps } from './useConfig';
18
+ const Blob = window.Blob;
19
+ const isDev = process.env.NODE_ENV === 'development';
20
+ const DEFAULT_TIMEOUT = 15 * 1000;
21
+ export const useGetConfigTimeout = () => {
22
+ const { publicRuntimeConfig = {} } = useContext(TeamConfigContext);
23
+ const { globalFetchTimeout } = publicRuntimeConfig;
24
+ return toNumber(globalFetchTimeout) || DEFAULT_TIMEOUT;
25
+ };
26
+ export const baseApi = '/parse/api';
27
+ export const useGetLoginBasePath = () => {
28
+ const { publicRuntimeConfig = {} } = useContext(TeamConfigContext);
29
+ const basePath = useMemo(() => {
30
+ const { basePath = '' } = publicRuntimeConfig;
31
+ if (isDev)
32
+ return basePath;
33
+ return '';
34
+ }, [publicRuntimeConfig]);
35
+ return basePath;
36
+ };
37
+ export const useGetServerGateway = () => {
38
+ const { publicRuntimeConfig } = useContext(TeamConfigContext);
39
+ return (publicRuntimeConfig === null || publicRuntimeConfig === void 0 ? void 0 : publicRuntimeConfig.gateway) || '';
40
+ };
41
+ export const useGetGateway = (extraPath = '') => {
42
+ const gateway = useGetServerGateway();
43
+ const result = useMemo(() => {
44
+ const inOne = isInOne(gateway);
45
+ if (!gateway)
46
+ return inOne ? '' : extraPath;
47
+ if (inOne)
48
+ return gateway;
49
+ return extraPath;
50
+ }, [extraPath, gateway]);
51
+ return result;
52
+ };
53
+ export function useGetRequestConfig({ sessionToken, tenant, Cookie }) {
54
+ const gateway = useGetServerGateway();
55
+ const baseURL = useMemo(() => {
56
+ return `${gateway}${baseApi}`;
57
+ }, [gateway]);
58
+ return {
59
+ baseURL,
60
+ headers: {
61
+ 'X-Parse-Session-Token': sessionToken,
62
+ 'X-Parse-Application-Id': tenant,
63
+ ...(Cookie && {
64
+ Cookie,
65
+ }),
66
+ },
67
+ };
68
+ }
69
+ export const useAxiosConfig = () => {
70
+ const gateway = useGetGateway();
71
+ const baseURL = useMemo(() => {
72
+ return `${gateway}${baseApi}`;
73
+ }, [gateway]);
74
+ const defaultTimeout = useGetConfigTimeout();
75
+ return {
76
+ baseURL,
77
+ timeout: defaultTimeout,
78
+ };
79
+ };
80
+ const errorLog = msg => {
81
+ return ErrorLog.show(msg);
82
+ };
83
+ export const LOCALE_KEY = 'lang';
84
+ export const useGetHeaderLang = () => {
85
+ const { locale } = useAppProps();
86
+ return locale;
87
+ };
88
+ export const getGlobalEnv = () => {
89
+ return window.env || {};
90
+ };
91
+ const checkLog = debug('lib:fetch:checkSessionToken');
92
+ const NO_SESSION_KEY = 'sessionToken is required';
93
+ const CHECK_WHITE_LIST = [
94
+ '/api/auth/demo/login',
95
+ '/api/auth/login',
96
+ '/api/auth/logout',
97
+ '/api/auth/code',
98
+ '/api/license/serviceId',
99
+ '/api/license/register',
100
+ '/api/license/status',
101
+ '/api/auth/install/addAdminUser',
102
+ '/submit/',
103
+ '/api/license/licenseInfo',
104
+ ];
105
+ function checkSessionToken(config) {
106
+ checkLog('......checkSessionToken', config.headers['X-Parse-Session-Token'], !!config.headers['X-Parse-Session-Token'], config.url, config.baseURL);
107
+ if (!config.baseURL) {
108
+ return;
109
+ }
110
+ if (config.baseURL.endsWith('apps/api'))
111
+ return;
112
+ if (CHECK_WHITE_LIST.includes(config.url))
113
+ return;
114
+ const hasToken = config.headers['X-Parse-Session-Token'] != null;
115
+ if (!hasToken) {
116
+ throw new Error(NO_SESSION_KEY, { cause: config.url });
117
+ }
118
+ }
119
+ const useRedirectToLogin = () => {
120
+ const { publicRuntimeConfig = {} } = useContext(TeamConfigContext);
121
+ const router = getCurLocationInfo();
122
+ const getSourcePath = useGetSourcePath();
123
+ const redirectToLogin = useCallback((_error, _form) => {
124
+ checkLog('......redirectToLogin', _error, _form);
125
+ if (publicRuntimeConfig.disableRedirect) {
126
+ return;
127
+ }
128
+ if (!IGNORE_URL.includes(router.asPath)) {
129
+ const redirectURL = getSourcePath(router.asPath);
130
+ const loginURL = getSourcePath('/login');
131
+ console.info('..........currentPath', redirectURL, loginURL);
132
+ removeParseItems();
133
+ localStorage.setItem(REDIRECT_URL_KEY, redirectURL);
134
+ window.location.href = loginURL;
135
+ }
136
+ }, [getSourcePath, publicRuntimeConfig.disableRedirect, router.asPath]);
137
+ return redirectToLogin;
138
+ };
139
+ const useRequestInterceptors = () => {
140
+ const { sessionToken, locale, appId } = useAppProps();
141
+ const requestInterceptors = useCallback(config => {
142
+ if (!config.ignoreParseHeaders) {
143
+ if (!config.headers)
144
+ config.headers = {};
145
+ if (!config.headers['X-Parse-Application-Id']) {
146
+ config.headers['X-Parse-Application-Id'] = appId;
147
+ }
148
+ if (config.headers['X-Parse-Session-Token'] == null && sessionToken) {
149
+ config.headers['X-Parse-Session-Token'] = sessionToken;
150
+ }
151
+ }
152
+ if (Object.hasOwnProperty.call(config.headers, 'Cookie') && !config.headers.Cookie) {
153
+ delete config.headers.Cookie;
154
+ }
155
+ if (Object.hasOwnProperty.call(config.headers, 'cookie') && !config.headers.cookie) {
156
+ delete config.headers.cookie;
157
+ }
158
+ const parseHeaderLang = locale;
159
+ if (parseHeaderLang && !config.headers['Accept-Language']) {
160
+ config.headers['Accept-Language'] = parseHeaderLang;
161
+ }
162
+ if (config.useCompress) {
163
+ config.headers['x-has-compression'] = 'true';
164
+ }
165
+ if (config.useJsonDecompress) {
166
+ config.headers['x-has-json-compression'] = 'true';
167
+ }
168
+ checkSessionToken(config);
169
+ return config;
170
+ }, [appId, locale, sessionToken]);
171
+ return requestInterceptors;
172
+ };
173
+ const useAddResponseInterceptors = (fetch) => {
174
+ const { publicRuntimeConfig } = useContext(TeamConfigContext);
175
+ const redirectToLogin = useRedirectToLogin();
176
+ useEffect(() => {
177
+ fetch.interceptors.response.use((response) => {
178
+ if (response.status >= 200 && response.status <= 300) {
179
+ return Promise.resolve(response);
180
+ }
181
+ else {
182
+ return Promise.reject(response);
183
+ }
184
+ }, async (error) => {
185
+ var _a;
186
+ console.error('[$fetch] response ERROR', error);
187
+ const { showTimeoutMessage: showTimeout } = publicRuntimeConfig;
188
+ const { hiddenErrorModal, hiddenTimeout } = error.config || {};
189
+ const inOne = isInOne();
190
+ if (error.code === 'ECONNREFUSED') {
191
+ errorLog(i18n.t('apis.error.refused'));
192
+ }
193
+ else if (error.code === 'ECONNABORTED') {
194
+ !hiddenTimeout && showTimeout && errorLog(i18n.t('apis.error.timeout'));
195
+ return Promise.reject('timeout');
196
+ }
197
+ else if (error.code === 'ERR_CANCELED') {
198
+ console.info('request canceled', error.message);
199
+ return Promise.reject('canceled');
200
+ }
201
+ else if (error.code === 'ERR_BAD_REQUEST' && HttpStatusCode.PayloadTooLarge === ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
202
+ errorLog(i18n.t('apis.error.payloadTooLarge'));
203
+ return Promise.reject(error.response.statusText);
204
+ }
205
+ else if (error.response) {
206
+ if (error.response.status) {
207
+ let errorData = error.response.data;
208
+ if (error.response.data instanceof Blob) {
209
+ errorData = await new Response(error.response.data).json();
210
+ }
211
+ if (typeof errorData === 'object') {
212
+ if (!inOne && errorData.code === ParseErrorCode.INVALID_SESSION_TOKEN) {
213
+ redirectToLogin(error, errorData.message);
214
+ return Promise.reject(error.response);
215
+ }
216
+ const errorMessage = getErrorMessage(errorData, i18n.t('apis.error.responseError', { dot: '.' }));
217
+ !hiddenErrorModal && errorLog(errorMessage);
218
+ }
219
+ else {
220
+ !hiddenErrorModal && errorLog(errorData || i18n.t('apis.error.responseError', { dot: '' }));
221
+ }
222
+ return Promise.reject(error.response);
223
+ }
224
+ }
225
+ else {
226
+ if (!inOne && (error === null || error === void 0 ? void 0 : error.message) === NO_SESSION_KEY) {
227
+ redirectToLogin(error, NO_SESSION_KEY);
228
+ }
229
+ else if ((error === null || error === void 0 ? void 0 : error.message) !== CANCEL_FETCH_STRING) {
230
+ errorLog(error.message);
231
+ }
232
+ else if (axios.isCancel(error)) {
233
+ console.info('.........is cancel', error);
234
+ }
235
+ return Promise.reject(error);
236
+ }
237
+ });
238
+ }, [fetch.interceptors.response, publicRuntimeConfig, redirectToLogin]);
239
+ };
240
+ const $fetch = async (method, url, ...args) => {
241
+ if (!url) {
242
+ return;
243
+ }
244
+ const toSuccessData = response => {
245
+ var _a, _b;
246
+ const requestConfig = (args[0] || {});
247
+ const { useJson, useJsonDecompress } = requestConfig;
248
+ if (useJson) {
249
+ if (response.data.code !== 0) {
250
+ return Promise.reject(response.data);
251
+ }
252
+ else {
253
+ if (useJsonDecompress) {
254
+ return cjson.decompress((_a = response.data) === null || _a === void 0 ? void 0 : _a.payload);
255
+ }
256
+ else {
257
+ return (_b = response.data) === null || _b === void 0 ? void 0 : _b.payload;
258
+ }
259
+ }
260
+ }
261
+ return response.data;
262
+ };
263
+ const response = await throttleWithCache({
264
+ type: THROTTLE_TYPE.CUSTOM_FETCH,
265
+ params: {
266
+ url,
267
+ args,
268
+ },
269
+ fn: () => {
270
+ return fetch[method](url, ...args);
271
+ },
272
+ method,
273
+ });
274
+ return toSuccessData(response);
275
+ };
276
+ const setFetchInstance = (config) => {
277
+ const fetch = axios.create(config);
278
+ fetch.$get = async (...args) => $fetch('get', ...args);
279
+ fetch.$post = async (...args) => $fetch('post', ...args);
280
+ fetch.$delete = async (...args) => $fetch('delete', ...args);
281
+ fetch.$put = async (...args) => $fetch('put', ...args);
282
+ fetch.$patch = async (...args) => $fetch('patch', ...args);
283
+ fetch.$head = async (...args) => $fetch('head', ...args);
284
+ fetch.$options = async (...args) => $fetch('options', ...args);
285
+ return fetch;
286
+ };
287
+ const useFetch = () => {
288
+ const config = useAxiosConfig();
289
+ const requestInterceptors = useRequestInterceptors();
290
+ const fetch = useMemo(() => {
291
+ const fetch = setFetchInstance(config);
292
+ fetch.interceptors.request.use(requestInterceptors, error => {
293
+ console.error('[$fetch] request ERROR', error);
294
+ return Promise.reject(error);
295
+ });
296
+ return fetch;
297
+ }, [config, requestInterceptors]);
298
+ useAddResponseInterceptors(fetch);
299
+ return fetch;
300
+ };
301
+ export default useFetch;
@@ -101,3 +101,21 @@ export declare const CustomFieldComponentTypes: {
101
101
  Radio: string;
102
102
  Checkbox: string;
103
103
  };
104
+ export declare const BASE_FIELD_WIDTH = 104;
105
+ export declare const CURRENT_WORKSPACE = "currentWorkspace()";
106
+ export declare const FIELD_CONTAINERS_PAGE: {
107
+ readonly DETAIL: "detail";
108
+ readonly MODAL: "modal";
109
+ readonly DRAWER: "drawer";
110
+ readonly FILTER: "filter";
111
+ readonly SCREEN: "screen";
112
+ readonly AUTOMATION_FIELD: "automation_field";
113
+ readonly VIEW_MODAL: "view_modal";
114
+ };
115
+ export declare const SCREEN_TYPE: {
116
+ readonly View: "view";
117
+ readonly Create: "create";
118
+ readonly Edit: "edit";
119
+ };
120
+ export declare const CANCEL_FETCH_STRING = "cancel_fetch_string";
121
+ export declare const REDIRECT_URL_KEY = "team_redirect_url";