@authing/react-ui-components 3.0.2-beta.7 → 3.0.3-rc.4

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 (260) hide show
  1. package/lib/index.d.ts +4263 -0
  2. package/lib/index.min.css +2 -0
  3. package/lib/index.min.js +2 -0
  4. package/{build/static/js/2.142555a1.chunk.js.LICENSE.txt → lib/index.min.js.LICENSE.txt} +8 -31
  5. package/{build → lib}/static/media/loading.4a67a5f3.svg +0 -0
  6. package/package.json +35 -12
  7. package/.eslintignore +0 -6
  8. package/.eslintrc.js +0 -7
  9. package/.prettierrc +0 -5
  10. package/build/asset-manifest.json +0 -26
  11. package/build/favicon.ico +0 -0
  12. package/build/index.html +0 -1
  13. package/build/logo192.png +0 -0
  14. package/build/logo512.png +0 -0
  15. package/build/manifest.json +0 -25
  16. package/build/robots.txt +0 -3
  17. package/build/static/css/2.5c23c9b8.chunk.css +0 -3
  18. package/build/static/css/2.5c23c9b8.chunk.css.map +0 -1
  19. package/build/static/css/main.6a8701e8.chunk.css +0 -2
  20. package/build/static/css/main.6a8701e8.chunk.css.map +0 -1
  21. package/build/static/js/2.142555a1.chunk.js +0 -3
  22. package/build/static/js/2.142555a1.chunk.js.map +0 -1
  23. package/build/static/js/3.ed27e06b.chunk.js +0 -2
  24. package/build/static/js/3.ed27e06b.chunk.js.map +0 -1
  25. package/build/static/js/main.8d075e4d.chunk.js +0 -2
  26. package/build/static/js/main.8d075e4d.chunk.js.map +0 -1
  27. package/build/static/js/runtime-main.9a428724.js +0 -2
  28. package/build/static/js/runtime-main.9a428724.js.map +0 -1
  29. package/components/AuthingDropdown/index.tsx +0 -52
  30. package/components/AuthingDropdown/style.less +0 -43
  31. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  32. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  33. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  34. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  35. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  36. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  37. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  38. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  39. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  40. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  41. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  42. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  43. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  44. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  45. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  46. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  47. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  48. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  49. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  50. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  51. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  52. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  53. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  54. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  55. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  56. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  57. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  58. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  59. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  60. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  61. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  62. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  63. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  64. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  65. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  66. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  67. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  68. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  69. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  70. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  71. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  72. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  73. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  74. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  75. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  76. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  77. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  78. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  79. package/components/AuthingGuard/Forms/index.ts +0 -13
  80. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  81. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  82. package/components/AuthingGuard/Header/index.tsx +0 -25
  83. package/components/AuthingGuard/Header/style.less +0 -52
  84. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  85. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  86. package/components/AuthingGuard/IconFont/style.less +0 -6
  87. package/components/AuthingGuard/IconFont/svg.js +0 -2
  88. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  89. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  90. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  91. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  92. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  93. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  94. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  95. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  96. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  97. package/components/AuthingGuard/api/appConfig.ts +0 -146
  98. package/components/AuthingGuard/api/index.ts +0 -3
  99. package/components/AuthingGuard/api/sso.ts +0 -29
  100. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  101. package/components/AuthingGuard/constants.ts +0 -107
  102. package/components/AuthingGuard/hooks/index.tsx +0 -70
  103. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  104. package/components/AuthingGuard/index.tsx +0 -126
  105. package/components/AuthingGuard/style.less +0 -103
  106. package/components/AuthingGuard/types/Forms.ts +0 -94
  107. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  108. package/components/AuthingGuard/types/GuardState.ts +0 -7
  109. package/components/AuthingGuard/types/Locales.ts +0 -12
  110. package/components/AuthingGuard/types/index.ts +0 -4
  111. package/components/AuthingTabs/index.tsx +0 -98
  112. package/components/AuthingTabs/style.less +0 -135
  113. package/components/BindTotp/core/bindSuccess.tsx +0 -72
  114. package/components/BindTotp/core/securityCode.tsx +0 -108
  115. package/components/BindTotp/index.tsx +0 -134
  116. package/components/BindTotp/interface.ts +0 -30
  117. package/components/BindTotp/styles.less +0 -57
  118. package/components/ChangeLanguage/index.tsx +0 -35
  119. package/components/ChangePassword/core/firstLoginReset.tsx +0 -111
  120. package/components/ChangePassword/core/rotateReset.tsx +0 -125
  121. package/components/ChangePassword/index.tsx +0 -72
  122. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  123. package/components/CompleteInfo/index.tsx +0 -45
  124. package/components/CompleteInfo/interface.ts +0 -40
  125. package/components/CompleteInfo/styles.less +0 -7
  126. package/components/CopyAbleText/index.tsx +0 -54
  127. package/components/CopyAbleText/style.less +0 -13
  128. package/components/DownloadAuthenticator/index.tsx +0 -97
  129. package/components/DownloadAuthenticator/interface.ts +0 -22
  130. package/components/DownloadAuthenticator/styles.less +0 -52
  131. package/components/Error/index.tsx +0 -21
  132. package/components/Error/interface.ts +0 -9
  133. package/components/Error/styles.less +0 -12
  134. package/components/ForgetPassword/core/resetPassword.tsx +0 -162
  135. package/components/ForgetPassword/index.tsx +0 -78
  136. package/components/ForgetPassword/interface.ts +0 -32
  137. package/components/Guard/Guard.tsx +0 -295
  138. package/components/Guard/authClient.ts +0 -44
  139. package/components/Guard/config.ts +0 -19
  140. package/components/Guard/event.ts +0 -52
  141. package/components/Guard/index.tsx +0 -4
  142. package/components/Guard/module.ts +0 -20
  143. package/components/Guard/stateMachine.ts +0 -152
  144. package/components/Guard/styles.less +0 -461
  145. package/components/IconFont/iconfont.js +0 -74
  146. package/components/IconFont/index.tsx +0 -16
  147. package/components/IconFont/style.less +0 -6
  148. package/components/IconFont/svg.js +0 -2
  149. package/components/ImagePro/index.tsx +0 -53
  150. package/components/ImagePro/styles.less +0 -40
  151. package/components/InputNumber/index.tsx +0 -33
  152. package/components/Login/codemap.ts +0 -49
  153. package/components/Login/core/withAD.tsx +0 -9
  154. package/components/Login/core/withAppQrcode.tsx +0 -49
  155. package/components/Login/core/withLDAP.tsx +0 -146
  156. package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
  157. package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -30
  158. package/components/Login/core/withPassword/InputAccount.tsx +0 -64
  159. package/components/Login/core/withPassword/index.tsx +0 -173
  160. package/components/Login/core/withPhonecode.tsx +0 -122
  161. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  162. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  163. package/components/Login/index.tsx +0 -374
  164. package/components/Login/interface.ts +0 -74
  165. package/components/Login/socialLogin/index.tsx +0 -407
  166. package/components/Login/socialLogin/style.less +0 -69
  167. package/components/Login/styles.less +0 -53
  168. package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
  169. package/components/MFA/VerifyCodeInput/index.tsx +0 -145
  170. package/components/MFA/VerifyCodeInput/style.less +0 -35
  171. package/components/MFA/codemap.ts +0 -24
  172. package/components/MFA/core/email.tsx +0 -203
  173. package/components/MFA/core/face.tsx +0 -297
  174. package/components/MFA/core/face_deps.tsx +0 -37
  175. package/components/MFA/core/sms.tsx +0 -203
  176. package/components/MFA/core/totp.tsx +0 -122
  177. package/components/MFA/index.tsx +0 -143
  178. package/components/MFA/interface.ts +0 -51
  179. package/components/MFA/mfaMethods/index.tsx +0 -88
  180. package/components/MFA/mfaMethods/style.less +0 -39
  181. package/components/MFA/styles.less +0 -100
  182. package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
  183. package/components/NeedHelpView/index.tsx +0 -47
  184. package/components/RecoveryCode/core/useCode.tsx +0 -71
  185. package/components/RecoveryCode/index.tsx +0 -27
  186. package/components/RecoveryCode/interface.ts +0 -31
  187. package/components/RecoveryCode/style.less +0 -13
  188. package/components/Register/codemap.ts +0 -12
  189. package/components/Register/components/Agreements/index.tsx +0 -81
  190. package/components/Register/components/Agreements/style.less +0 -44
  191. package/components/Register/core/WithEmail.tsx +0 -242
  192. package/components/Register/core/WithPhone.tsx +0 -184
  193. package/components/Register/index.tsx +0 -139
  194. package/components/Register/interface.ts +0 -50
  195. package/components/SendCode/SendCodeBtn.tsx +0 -96
  196. package/components/SendCode/index.tsx +0 -94
  197. package/components/SendCode/style.less +0 -31
  198. package/components/ShieldSpin/index.tsx +0 -27
  199. package/components/ShieldSpin/loading.svg +0 -29
  200. package/components/SubmitButton/index.tsx +0 -50
  201. package/components/SubmitSuccess/index.tsx +0 -66
  202. package/components/SubmitSuccess/interface.ts +0 -17
  203. package/components/Type/index.ts +0 -52
  204. package/components/ValidatorRules/ValidatorFormItem.tsx +0 -139
  205. package/components/ValidatorRules/index.ts +0 -20
  206. package/components/VerifyCodeInput/index.tsx +0 -76
  207. package/components/VerifyCodeInput/style.less +0 -24
  208. package/components/_utils/GuardErrorCode.ts +0 -9
  209. package/components/_utils/clipboard.ts +0 -27
  210. package/components/_utils/config.ts +0 -116
  211. package/components/_utils/guradHttp.ts +0 -101
  212. package/components/_utils/hooks/index.ts +0 -64
  213. package/components/_utils/http.ts +0 -85
  214. package/components/_utils/index.ts +0 -326
  215. package/components/_utils/locales/en/common.json +0 -229
  216. package/components/_utils/locales/en/index.ts +0 -6
  217. package/components/_utils/locales/en/login.json +0 -96
  218. package/components/_utils/locales/en/map.json +0 -4
  219. package/components/_utils/locales/en/user.json +0 -82
  220. package/components/_utils/locales/index.ts +0 -45
  221. package/components/_utils/locales/zh/common.json +0 -229
  222. package/components/_utils/locales/zh/index.ts +0 -6
  223. package/components/_utils/locales/zh/login.json +0 -96
  224. package/components/_utils/locales/zh/map.json +0 -4
  225. package/components/_utils/locales/zh/user.json +0 -83
  226. package/components/_utils/popupCenter.ts +0 -48
  227. package/components/assets/images/error.png +0 -0
  228. package/components/context/base.tsx +0 -28
  229. package/components/context/global/context.tsx +0 -39
  230. package/components/context/global/reducer.tsx +0 -56
  231. package/components/context/module/context.tsx +0 -23
  232. package/components/index.ts +0 -9
  233. package/config/antdReplacer.js +0 -51
  234. package/config/env.js +0 -104
  235. package/config/getHttpsConfig.js +0 -66
  236. package/config/jest/cssTransform.js +0 -14
  237. package/config/jest/fileTransform.js +0 -40
  238. package/config/modules.js +0 -134
  239. package/config/paths.js +0 -71
  240. package/config/pnpTs.js +0 -35
  241. package/config/webpack.config.js +0 -835
  242. package/config/webpackDevServer.config.js +0 -130
  243. package/examples.tsx +0 -87
  244. package/index.js +0 -1
  245. package/logo.svg +0 -7
  246. package/public/favicon.ico +0 -0
  247. package/public/index.html +0 -43
  248. package/public/logo192.png +0 -0
  249. package/public/logo512.png +0 -0
  250. package/public/manifest.json +0 -25
  251. package/public/robots.txt +0 -3
  252. package/react-app-env.d.ts +0 -71
  253. package/reportWebVitals.ts +0 -15
  254. package/scripts/build.js +0 -208
  255. package/scripts/lib.js +0 -200
  256. package/scripts/publish.js +0 -57
  257. package/scripts/start.js +0 -162
  258. package/scripts/test.js +0 -49
  259. package/setupTests.ts +0 -5
  260. package/tsconfig.json +0 -30
@@ -1,116 +0,0 @@
1
- import { LoginMethods, RegisterMethods } from 'authing-js-sdk'
2
- import { IG2Config } from '../Type'
3
- import { ApplicationConfig } from '../AuthingGuard/api'
4
- import { assembledAppHost } from '.'
5
- import { getGuardHttp } from './guradHttp'
6
- import { AuthingResponse } from './http'
7
- import { GuardComponentConifg, GuardLocalConfig } from '../Guard/config'
8
-
9
- let publicConfigMap: Record<string, ApplicationConfig> = {}
10
-
11
- const getPublicConfig = (appId: string) => publicConfigMap?.[appId]
12
-
13
- const setPublicConfig = (appId: string, config: ApplicationConfig) =>
14
- (publicConfigMap[appId] = config)
15
-
16
- export const initConfig = async (
17
- appId: string,
18
- config: Partial<IG2Config>,
19
- defaultConfig: IG2Config
20
- ): Promise<{ config: GuardLocalConfig; publicConfig: ApplicationConfig }> => {
21
- if (!getPublicConfig(appId)) await requestPublicConfig(appId)
22
- const mergedConfig = mergeConfig(
23
- config,
24
- defaultConfig,
25
- getPublicConfig(appId)
26
- )
27
-
28
- return {
29
- config: {
30
- ...mergedConfig,
31
- __publicConfig__: getPublicConfig(appId),
32
- __appHost__: assembledAppHost(
33
- getPublicConfig(appId).identifier,
34
- mergedConfig?.host!
35
- ),
36
- },
37
- publicConfig: getPublicConfig(appId),
38
- }
39
- }
40
-
41
- const mergeConfig = (
42
- config: GuardComponentConifg,
43
- defaultConfig: IG2Config,
44
- publicConfig: ApplicationConfig
45
- ): GuardLocalConfig => {
46
- const mergedPublicConfig: GuardLocalConfig = {
47
- ...defaultConfig,
48
- ...config,
49
- title: config.title ?? publicConfig.name,
50
- logo: !!config.logo ? config.logo : publicConfig.logo,
51
- loginMethods:
52
- config?.loginMethods ??
53
- (publicConfig.loginTabs?.list as LoginMethods[]) ??
54
- [],
55
- passwordLoginMethods:
56
- config?.passwordLoginMethods ??
57
- publicConfig.passwordTabConfig?.enabledLoginMethods ??
58
- [],
59
- // 默认登录方式
60
- defaultLoginMethod:
61
- config.defaultLoginMethod ??
62
- (publicConfig.loginTabs.default as LoginMethods),
63
- // 禁止重制密码
64
- disableResetPwd: !!(
65
- config.disableResetPwd ??
66
- !publicConfig.ssoPageComponentDisplay?.forgetPasswordBtn
67
- ),
68
- // 是否自动注册
69
- autoRegister:
70
- config.autoRegister ??
71
- publicConfig.ssoPageComponentDisplay.autoRegisterThenLoginHintInfo,
72
- registerMethods:
73
- config.registerMethods ??
74
- (publicConfig.registerTabs?.list as RegisterMethods[]),
75
- defaultRegisterMethod:
76
- config.defaultRegisterMethod ??
77
- (publicConfig.registerTabs.default as RegisterMethods),
78
- // 禁止注册
79
- disableRegister: !!(
80
- config.disableRegister ??
81
- !publicConfig.ssoPageComponentDisplay.registerBtn
82
- ),
83
- // publicKey
84
- publicKey: config.publicKey ?? publicConfig.publicKey,
85
- // 注册协议
86
- agreementEnabled: config.agreementEnabled ?? publicConfig.agreementEnabled,
87
- agreements: config.agreements ?? publicConfig.agreements,
88
- contentCss: config.contentCss ?? publicConfig.css,
89
- }
90
-
91
- return mergedPublicConfig
92
- }
93
-
94
- const requestPublicConfig = async (
95
- appId: string
96
- ): Promise<ApplicationConfig> => {
97
- let res: AuthingResponse<ApplicationConfig>
98
-
99
- const { get } = getGuardHttp()
100
-
101
- try {
102
- res = await get<ApplicationConfig>(
103
- `/api/v2/applications/${appId}/public-config`
104
- )
105
- } catch (error) {
106
- console.error('Please check your config or network')
107
- throw new Error('Please check your config or network')
108
- }
109
-
110
- if (res.code !== 200 || !res.data)
111
- throw new Error(res?.message ?? 'Please check your config')
112
-
113
- setPublicConfig(appId, res.data)
114
-
115
- return getPublicConfig(appId)
116
- }
@@ -1,101 +0,0 @@
1
- import packageConfig from '../../package.json'
2
- import { requestClient } from './http'
3
-
4
- let httpClient: GuardHttp
5
-
6
- export class GuardHttp {
7
- private requestClient: any
8
- private headers: Record<string, string> = {
9
- 'x-authing-userpool-id': '',
10
- 'x-authing-app-id': '',
11
- 'x-authing-sdk-version': packageConfig.version,
12
- 'x-authing-request-from': `Guard-${packageConfig.framework}@${packageConfig.version}`,
13
- }
14
-
15
- constructor(baseUrl: string) {
16
- this.getRequestClient().setBaseUrl(baseUrl)
17
- }
18
-
19
- private getRequestClient() {
20
- if (!this.requestClient) {
21
- this.requestClient = requestClient
22
- }
23
-
24
- return this.requestClient
25
- }
26
-
27
- setUserpoolId(userpoolId: string) {
28
- this.headers['x-authing-userpool-id'] = userpoolId
29
- }
30
-
31
- setAppId(appId: string) {
32
- this.headers['x-authing-app-id'] = appId
33
- }
34
-
35
- setTenantId(tenantId: string) {
36
- this.headers['x-authing-app-tenant-id'] = tenantId
37
- }
38
-
39
- setBaseUrl(baseUrl: string) {
40
- this.getRequestClient().setBaseUrl(baseUrl)
41
- }
42
-
43
- public getHeaders = () => this.headers
44
-
45
- public get = async <T>(
46
- path: string,
47
- query: Record<string, any> = {},
48
- config?: RequestInit
49
- ) =>
50
- await requestClient.get<T>(path, query, {
51
- ...config,
52
- headers: { ...this.headers, ...config?.headers },
53
- })
54
-
55
- public post = async <T>(
56
- path: string,
57
- data: any,
58
- config?: {
59
- headers: any
60
- }
61
- ) =>
62
- await requestClient.post<T>(path, data, {
63
- headers: {
64
- ...this.headers,
65
- ...config?.headers,
66
- },
67
- })
68
-
69
- public postForm = async <T>(
70
- path: string,
71
- formData: any,
72
- config?: {
73
- headers: any
74
- }
75
- ) =>
76
- await requestClient.postForm<T>(path, formData, {
77
- headers: {
78
- ...this.headers,
79
- ...config?.headers,
80
- },
81
- })
82
- }
83
-
84
- export const initGuardHttp = (baseUrl: string) => {
85
- if (!httpClient) {
86
- const guardHttp = new GuardHttp(baseUrl)
87
- httpClient = guardHttp
88
- }
89
-
90
- return httpClient
91
- }
92
-
93
- export const getGuardHttp = () => {
94
- if (!httpClient) {
95
- throw new Error('Please initialize Http Client')
96
- }
97
-
98
- return httpClient
99
- }
100
-
101
- export const useGuardHttp = () => getGuardHttp()
@@ -1,64 +0,0 @@
1
- import { useRef, useCallback, useEffect } from 'react'
2
- import { GuardModuleType } from '../../Guard/module'
3
- import { useModule } from '../../context/module/context'
4
-
5
- export const useChangeModule = () => {
6
- const { module, changeModule, setInitData } = useModule()
7
-
8
- const nextModule = (nextModuleType: GuardModuleType, nextData?: any) => {
9
- if (nextModuleType !== module) changeModule(nextModuleType)
10
-
11
- setInitData(nextData ?? {})
12
- }
13
-
14
- return nextModule
15
- }
16
-
17
- let thisAppId: string = ''
18
-
19
- export const useAppId = (appId?: string) => {
20
- if (appId) {
21
- thisAppId = appId
22
- }
23
-
24
- return thisAppId
25
- }
26
-
27
- export const useDebounce = (
28
- // 回调函数
29
- fn: any,
30
- // 延迟时间
31
- delay: number
32
- ) => {
33
- const timer = useRef<{ time: any }>({ time: null })
34
- const errorBody = useRef<{ body: any }>({ body: null })
35
-
36
- useEffect(() => {
37
- return () => {
38
- // eslint-disable-next-line react-hooks/exhaustive-deps
39
- timer.current.time && clearInterval(timer.current.time)
40
- }
41
- }, [])
42
-
43
- return useCallback(
44
- (...args: any[]) => {
45
- if (timer.current.time) {
46
- clearTimeout(timer.current.time)
47
- timer.current.time = null
48
- }
49
- timer.current.time = setTimeout(() => {
50
- // fn.apply(this, args);
51
- const res = fn(...args)
52
- timer.current.time = null
53
- errorBody.current.body = res
54
- }, delay)
55
- // if (errorBody.current.body) {
56
- // return Promise.reject(errorBody.current.body)
57
- // } else {
58
- // return Promise.resolve()
59
- // }
60
- },
61
- // eslint-disable-next-line react-hooks/exhaustive-deps
62
- [timer.current, delay]
63
- )
64
- }
@@ -1,85 +0,0 @@
1
- import qs from 'qs'
2
- import { i18n } from './locales'
3
-
4
- export const requestClient = async (...rest: Parameters<typeof fetch>) => {
5
- const res = await fetch(...rest)
6
- return res.json()
7
- }
8
-
9
- export interface AuthingResponse<T = any> {
10
- code: number
11
- message?: string
12
- data?: T
13
- }
14
-
15
- requestClient.get = async <T>(
16
- path: string,
17
- query: Record<string, any> = {},
18
- init?: RequestInit
19
- ): Promise<AuthingResponse<T>> => {
20
- const res = await fetch(
21
- `${requestClient.baseUrl}${path}${qs.stringify(query, {
22
- addQueryPrefix: true,
23
- })}`,
24
- {
25
- ...init,
26
- credentials: 'include',
27
- headers: {
28
- ...init?.headers,
29
- [requestClient.langHeader]: i18n.language,
30
- },
31
- }
32
- )
33
-
34
- return res.json()
35
- }
36
-
37
- requestClient.post = async <T>(
38
- path: string,
39
- data: any,
40
- config?: {
41
- headers: any
42
- }
43
- ): Promise<AuthingResponse<T>> => {
44
- const res = await fetch(`${requestClient.baseUrl}${path}`, {
45
- method: 'POST',
46
- body: JSON.stringify(data),
47
- credentials: 'include',
48
- headers: {
49
- 'Content-Type': 'application/json',
50
- ...config?.headers,
51
- [requestClient.langHeader]: i18n.language,
52
- },
53
- })
54
- return res.json()
55
- }
56
-
57
- requestClient.postForm = async <T>(
58
- path: string,
59
- formData: any,
60
- config?: {
61
- headers: any
62
- }
63
- ): Promise<AuthingResponse<T>> => {
64
- const res = await fetch(`${requestClient.baseUrl}${path}`, {
65
- method: 'post',
66
- body: formData,
67
- credentials: 'include',
68
- headers: {
69
- ...config?.headers,
70
- [requestClient.langHeader]: i18n.language,
71
- },
72
- })
73
- return res.json()
74
- }
75
-
76
- requestClient.baseUrl = ''
77
- requestClient.setBaseUrl = (base: string) => {
78
- requestClient.baseUrl = base.replace(/\/$/, '')
79
- }
80
-
81
- const DEFAULT_LANG_HEADER = 'x-authing-lang'
82
- requestClient.langHeader = DEFAULT_LANG_HEADER
83
- requestClient.setLangHeader = (key: string | undefined) => {
84
- requestClient.langHeader = key || DEFAULT_LANG_HEADER
85
- }
@@ -1,326 +0,0 @@
1
- import { useEffect } from 'react'
2
- import { Rule } from 'antd/lib/form'
3
- import qs from 'qs'
4
- import { useGuardContext } from '../context/global/context'
5
- import { i18n } from './locales'
6
-
7
- export * from './popupCenter'
8
- export * from './clipboard'
9
-
10
- export const VALIDATE_PATTERN = {
11
- // https://emailregex.com/
12
- // eslint-disable-next-line no-control-regex
13
- email: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
14
- // 以下的来自 authing-user-portal 项目
15
- phone: /^1[3-9]\d{9}$/,
16
- ip: /^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$/,
17
- host: /^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+.?$/,
18
- } as const
19
-
20
- export const validate = (type: keyof typeof VALIDATE_PATTERN, val: string) => {
21
- return VALIDATE_PATTERN[type].test(val)
22
- }
23
-
24
- export const getRequiredRules = (msg: string): Rule[] => {
25
- return [
26
- {
27
- required: true,
28
- message: msg,
29
- },
30
- ]
31
- }
32
-
33
- export const fieldRequiredRule = (fieldRequiredRule: string): Rule[] => {
34
- return [
35
- {
36
- required: true,
37
- message: i18n.t('common.isMissing', {
38
- name: fieldRequiredRule,
39
- }),
40
- },
41
- ]
42
- }
43
-
44
- export function getDeviceName() {
45
- if (typeof window === 'undefined') {
46
- return null
47
- }
48
-
49
- const userAgent = window.navigator.userAgent
50
- const platform = window.navigator.platform
51
- const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
52
- const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']
53
- const iosPlatforms = ['iPhone', 'iPad', 'iPod']
54
-
55
- let os = null
56
-
57
- if (macosPlatforms.indexOf(platform) !== -1) {
58
- os = 'Mac OS'
59
- } else if (iosPlatforms.indexOf(platform) !== -1) {
60
- os = 'iOS'
61
- } else if (windowsPlatforms.indexOf(platform) !== -1) {
62
- os = 'Windows'
63
- } else if (/Android/.test(userAgent)) {
64
- os = 'Android'
65
- } else if (!os && /Linux/.test(platform)) {
66
- os = 'Linux'
67
- }
68
-
69
- return os
70
- }
71
-
72
- export type STYLE_RECORD_KEY = 'appConfig' | 'userConfig'
73
-
74
- /**
75
- * 传对象 {'background-color': 'red'}
76
- * 传字符串 "CSS 样式"
77
- */
78
- const insertedRecord: Record<STYLE_RECORD_KEY, any> = {
79
- appConfig: null,
80
- userConfig: null,
81
- }
82
- export const insertStyles = (
83
- styles: string | any,
84
- recordKey?: STYLE_RECORD_KEY
85
- ) => {
86
- let styleElt, styleSheet
87
- if ((document as any).createStyleSheet) {
88
- // IE
89
- styleSheet = (document as any).createStyleSheet()
90
- } else {
91
- let head = document.getElementsByTagName('head')[0]
92
- styleElt = document.createElement('style')
93
- head.appendChild(styleElt)
94
- styleSheet = document.styleSheets[document.styleSheets.length - 1]
95
- }
96
- if (typeof styles === 'string') {
97
- if (styleElt) styleElt.innerHTML = styles
98
- else styleSheet.cssText = styles // IE
99
- } else {
100
- let i = 0
101
- for (let selector in styles) {
102
- if (styleSheet.insertRule) {
103
- let rule = selector + ' {' + styles[selector] + '}'
104
- styleSheet.insertRule(rule, i++)
105
- } else {
106
- styleSheet.addRule(selector, styles[selector], i++)
107
- }
108
- }
109
- }
110
-
111
- if (recordKey) {
112
- insertedRecord[recordKey] = styleElt
113
- }
114
- }
115
-
116
- export const removeStyles = (recordKey: STYLE_RECORD_KEY) => {
117
- if (!insertedRecord[recordKey]) {
118
- return
119
- }
120
-
121
- const styleElt = insertedRecord[recordKey]
122
-
123
- styleElt.parentNode?.removeChild(styleElt)
124
-
125
- insertedRecord[recordKey] = null
126
- }
127
-
128
- export const useTitle = (title: string, prefix?: string) => {
129
- const {
130
- state: { config },
131
- } = useGuardContext()
132
-
133
- useEffect(() => {
134
- document.title = `${prefix ?? `${config.title} `} ${title}`
135
- }, [config.title, prefix, title])
136
- }
137
-
138
- export const getClassnames = (classnames: (string | boolean | undefined)[]) => {
139
- return classnames.filter(Boolean).join(' ')
140
- }
141
-
142
- /**
143
- * https://www.itranslater.com/qa/details/2115518846294557696
144
- * Simple object check.
145
- * @param item
146
- * @returns {boolean}
147
- */
148
- export function isObject(item: any) {
149
- return item && typeof item === 'object' && !Array.isArray(item)
150
- }
151
-
152
- /**
153
- * https://www.itranslater.com/qa/details/2115518846294557696
154
- * Deep merge two objects.
155
- * @param target
156
- * @param ...sources
157
- */
158
- export function deepMerge<T extends any = any>(
159
- target: T,
160
- ...sources: any[]
161
- ): T {
162
- if (!sources.length) return target
163
- const source = sources.shift()
164
-
165
- if (isObject(target) && isObject(source)) {
166
- for (const key in source) {
167
- if (isObject(source[key])) {
168
- // @ts-ignore
169
- if (!target[key]) {
170
- Object.assign(target, { [key]: {} })
171
- }
172
- // @ts-ignore
173
- deepMerge(target[key], source[key])
174
- } else {
175
- Object.assign(target, { [key]: source[key] })
176
- }
177
- }
178
- }
179
-
180
- return deepMerge(target, ...sources)
181
- }
182
-
183
- export const getUserRegisterParams = () => {
184
- const query = qs.parse(window.location.search, {
185
- ignoreQueryPrefix: true,
186
- })
187
- return Object.keys(query).map((key) => ({
188
- key,
189
- value: query[key],
190
- }))
191
- }
192
-
193
- export const isWechatBrowser = () =>
194
- /MicroMessenger/i.test(navigator?.userAgent)
195
-
196
- export const assembledAppHost = (identifier: string, host: string) => {
197
- const hostUrl = new URL(host)
198
-
199
- const splitHost = hostUrl.hostname.split('.')
200
-
201
- const port = hostUrl.port
202
-
203
- splitHost.shift()
204
-
205
- return `${hostUrl.protocol}//${identifier}.${splitHost.join('.')}${
206
- port && `:${port}`
207
- }`
208
- }
209
-
210
- export enum PasswordStrength {
211
- NoCheck,
212
- Low,
213
- Middle,
214
- High,
215
- AUTO,
216
- }
217
-
218
- export const PASSWORD_STRENGTH_TEXT_MAP: Record<
219
- PasswordStrength,
220
- {
221
- placeholder: () => string
222
- validateMessage: () => string
223
- }
224
- > = {
225
- [PasswordStrength.NoCheck]: {
226
- placeholder: () => i18n.t('login.inputPwd'),
227
- validateMessage: () => i18n.t('login.inputPwd'),
228
- },
229
- [PasswordStrength.Low]: {
230
- placeholder: () => i18n.t('login.setPwdLimit1'),
231
- validateMessage: () => i18n.t('login.setPwdLimitMsg1'),
232
- },
233
- [PasswordStrength.Middle]: {
234
- placeholder: () => i18n.t('login.login.setPwdLimit2'),
235
- validateMessage: () => i18n.t('login.setPwdLimitMsg2'),
236
- },
237
- [PasswordStrength.High]: {
238
- placeholder: () => i18n.t('login.login.setPwdLimit3'),
239
- validateMessage: () => i18n.t('login.setPwdLimitMsg3'),
240
- },
241
- [PasswordStrength.AUTO]: {
242
- placeholder: () => i18n.t('login.inputPwd'),
243
- validateMessage: () => i18n.t('login.inputPwd'),
244
- },
245
- }
246
-
247
- const SYMBOL_TYPE_PATTERNS = [
248
- /\d+/,
249
- /[a-zA-Z]/,
250
- /[-!$%^&*()_+|~=`{}[\]:";'<>?,@./]/,
251
- ]
252
-
253
- export const getSymbolTypeLength = (pwd: string) => {
254
- return SYMBOL_TYPE_PATTERNS.map((pattern) => pattern.test(pwd)).filter(
255
- (item) => item
256
- ).length
257
- }
258
-
259
- export const getPasswordValidate = (
260
- strength: PasswordStrength = PasswordStrength.NoCheck,
261
- customPasswordStrength: any = {}
262
- ): Rule[] => {
263
- const required = fieldRequiredRule(i18n.t('common.password'))[0]
264
-
265
- const validateMap: Record<PasswordStrength, Rule[]> = {
266
- [PasswordStrength.NoCheck]: [required],
267
- [PasswordStrength.Low]: [
268
- required,
269
- {
270
- validator(r, v) {
271
- if (v && v.length < 6) {
272
- return Promise.reject(
273
- PASSWORD_STRENGTH_TEXT_MAP[PasswordStrength.Low].validateMessage()
274
- )
275
- }
276
- return Promise.resolve()
277
- },
278
- },
279
- ],
280
- [PasswordStrength.Middle]: [
281
- required,
282
- {
283
- validator(r, v) {
284
- if (v && (v.length < 6 || getSymbolTypeLength(v) < 2)) {
285
- return Promise.reject(
286
- PASSWORD_STRENGTH_TEXT_MAP[
287
- PasswordStrength.Middle
288
- ].validateMessage()
289
- )
290
- }
291
- return Promise.resolve()
292
- },
293
- },
294
- ],
295
- [PasswordStrength.High]: [
296
- required,
297
- {
298
- validator(r, v) {
299
- if (v && (v.length < 6 || getSymbolTypeLength(v) < 3)) {
300
- console.log(
301
- PASSWORD_STRENGTH_TEXT_MAP[PasswordStrength.High].validateMessage
302
- )
303
- return Promise.reject(
304
- PASSWORD_STRENGTH_TEXT_MAP[
305
- PasswordStrength.High
306
- ].validateMessage()
307
- )
308
- }
309
- return Promise.resolve(true)
310
- },
311
- },
312
- ],
313
- [PasswordStrength.AUTO]: [
314
- required,
315
- {
316
- pattern: customPasswordStrength?.regex,
317
- message: customPasswordStrength?.message,
318
- },
319
- ],
320
- }
321
-
322
- return validateMap[strength]
323
- }
324
-
325
- export const sleep = (delay: number) =>
326
- new Promise((resolve) => setTimeout(resolve, delay))