@authing/react-ui-components 3.0.2-Beta.0 → 3.0.2-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/lib/index.d.ts +466 -45
  2. package/lib/index.min.css +2 -2
  3. package/lib/index.min.js +1 -1
  4. package/package.json +26 -10
  5. package/.eslintignore +0 -6
  6. package/.eslintrc.js +0 -7
  7. package/.prettierrc +0 -5
  8. package/.vscode/settings.json +0 -31
  9. package/build/asset-manifest.json +0 -26
  10. package/build/favicon.ico +0 -0
  11. package/build/index.html +0 -1
  12. package/build/logo192.png +0 -0
  13. package/build/logo512.png +0 -0
  14. package/build/manifest.json +0 -25
  15. package/build/robots.txt +0 -3
  16. package/build/static/css/2.9512539b.chunk.css +0 -3
  17. package/build/static/css/2.9512539b.chunk.css.map +0 -1
  18. package/build/static/css/main.0ff9e24a.chunk.css +0 -2
  19. package/build/static/css/main.0ff9e24a.chunk.css.map +0 -1
  20. package/build/static/js/2.1105ecfb.chunk.js +0 -3
  21. package/build/static/js/2.1105ecfb.chunk.js.LICENSE.txt +0 -102
  22. package/build/static/js/2.1105ecfb.chunk.js.map +0 -1
  23. package/build/static/js/3.fd17f196.chunk.js +0 -2
  24. package/build/static/js/3.fd17f196.chunk.js.map +0 -1
  25. package/build/static/js/main.a47645ff.chunk.js +0 -2
  26. package/build/static/js/main.a47645ff.chunk.js.map +0 -1
  27. package/build/static/js/runtime-main.ef138021.js +0 -2
  28. package/build/static/js/runtime-main.ef138021.js.map +0 -1
  29. package/build/static/media/loading.4a67a5f3.svg +0 -29
  30. package/components/AuthingDropdown/index.tsx +0 -52
  31. package/components/AuthingDropdown/style.less +0 -43
  32. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  33. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  34. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  35. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  36. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  37. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  38. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  39. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  40. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  41. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  42. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  43. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  44. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  45. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  46. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  47. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  48. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  49. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  50. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  51. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  52. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  53. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  54. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  55. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  56. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  57. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  58. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  59. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  60. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  61. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  62. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  63. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  64. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  65. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  66. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  67. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  68. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  69. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  70. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  71. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  72. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  73. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  74. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  75. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  76. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  77. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  78. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  79. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  80. package/components/AuthingGuard/Forms/index.ts +0 -13
  81. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  82. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  83. package/components/AuthingGuard/Header/index.tsx +0 -25
  84. package/components/AuthingGuard/Header/style.less +0 -52
  85. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  86. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  87. package/components/AuthingGuard/IconFont/style.less +0 -6
  88. package/components/AuthingGuard/IconFont/svg.js +0 -2
  89. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  90. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  91. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  92. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  93. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  94. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  95. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  96. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  97. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  98. package/components/AuthingGuard/api/appConfig.ts +0 -146
  99. package/components/AuthingGuard/api/index.ts +0 -3
  100. package/components/AuthingGuard/api/sso.ts +0 -29
  101. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  102. package/components/AuthingGuard/constants.ts +0 -107
  103. package/components/AuthingGuard/hooks/index.tsx +0 -70
  104. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  105. package/components/AuthingGuard/index.tsx +0 -126
  106. package/components/AuthingGuard/style.less +0 -103
  107. package/components/AuthingGuard/types/Forms.ts +0 -94
  108. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  109. package/components/AuthingGuard/types/GuardState.ts +0 -7
  110. package/components/AuthingGuard/types/Locales.ts +0 -12
  111. package/components/AuthingGuard/types/index.ts +0 -4
  112. package/components/AuthingTabs/index.tsx +0 -98
  113. package/components/AuthingTabs/style.less +0 -135
  114. package/components/BindTotp/core/bindSuccess.tsx +0 -73
  115. package/components/BindTotp/core/securityCode.tsx +0 -108
  116. package/components/BindTotp/index.tsx +0 -134
  117. package/components/BindTotp/interface.ts +0 -30
  118. package/components/BindTotp/styles.less +0 -57
  119. package/components/ChangeLanguage/index.tsx +0 -35
  120. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  121. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  122. package/components/ChangePassword/index.tsx +0 -59
  123. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  124. package/components/CompleteInfo/index.tsx +0 -45
  125. package/components/CompleteInfo/interface.ts +0 -40
  126. package/components/CompleteInfo/styles.less +0 -7
  127. package/components/CopyAbleText/index.tsx +0 -54
  128. package/components/CopyAbleText/style.less +0 -13
  129. package/components/DownloadAuthenticator/index.tsx +0 -97
  130. package/components/DownloadAuthenticator/interface.ts +0 -22
  131. package/components/DownloadAuthenticator/styles.less +0 -52
  132. package/components/Error/index.tsx +0 -21
  133. package/components/Error/interface.ts +0 -9
  134. package/components/Error/styles.less +0 -12
  135. package/components/ForgetPassword/core/resetPassword.tsx +0 -162
  136. package/components/ForgetPassword/index.tsx +0 -78
  137. package/components/ForgetPassword/interface.ts +0 -32
  138. package/components/Guard/Guard.tsx +0 -255
  139. package/components/Guard/authClient.ts +0 -46
  140. package/components/Guard/config.ts +0 -19
  141. package/components/Guard/event.ts +0 -52
  142. package/components/Guard/index.tsx +0 -4
  143. package/components/Guard/module.ts +0 -20
  144. package/components/Guard/stateMachine.ts +0 -133
  145. package/components/Guard/styles.less +0 -461
  146. package/components/IconFont/iconfont.js +0 -74
  147. package/components/IconFont/index.tsx +0 -16
  148. package/components/IconFont/style.less +0 -6
  149. package/components/IconFont/svg.js +0 -2
  150. package/components/ImagePro/index.tsx +0 -53
  151. package/components/ImagePro/styles.less +0 -40
  152. package/components/InputNumber/index.tsx +0 -33
  153. package/components/Login/codemap.ts +0 -47
  154. package/components/Login/core/withAD.tsx +0 -9
  155. package/components/Login/core/withAppQrcode.tsx +0 -49
  156. package/components/Login/core/withLDAP.tsx +0 -146
  157. package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
  158. package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -31
  159. package/components/Login/core/withPassword/InputAccount.tsx +0 -64
  160. package/components/Login/core/withPassword/index.tsx +0 -173
  161. package/components/Login/core/withPhonecode.tsx +0 -122
  162. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  163. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  164. package/components/Login/index.tsx +0 -373
  165. package/components/Login/props.ts +0 -74
  166. package/components/Login/socialLogin/index.tsx +0 -407
  167. package/components/Login/socialLogin/style.less +0 -69
  168. package/components/Login/styles.less +0 -53
  169. package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
  170. package/components/MFA/VerifyCodeInput/index.tsx +0 -145
  171. package/components/MFA/VerifyCodeInput/style.less +0 -35
  172. package/components/MFA/codemap.ts +0 -24
  173. package/components/MFA/core/email.tsx +0 -203
  174. package/components/MFA/core/face.tsx +0 -297
  175. package/components/MFA/core/face_deps.tsx +0 -37
  176. package/components/MFA/core/sms.tsx +0 -204
  177. package/components/MFA/core/totp.tsx +0 -122
  178. package/components/MFA/index.tsx +0 -143
  179. package/components/MFA/mfaMethods/index.tsx +0 -88
  180. package/components/MFA/mfaMethods/style.less +0 -39
  181. package/components/MFA/props.ts +0 -51
  182. package/components/MFA/styles.less +0 -100
  183. package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
  184. package/components/NeedHelpView/index.tsx +0 -47
  185. package/components/RecoveryCode/core/useCode.tsx +0 -71
  186. package/components/RecoveryCode/index.tsx +0 -27
  187. package/components/RecoveryCode/interface.ts +0 -31
  188. package/components/RecoveryCode/style.less +0 -13
  189. package/components/Register/codemap.ts +0 -12
  190. package/components/Register/components/Agreements/index.tsx +0 -81
  191. package/components/Register/components/Agreements/style.less +0 -44
  192. package/components/Register/core/WithEmail.tsx +0 -239
  193. package/components/Register/core/WithPhone.tsx +0 -184
  194. package/components/Register/index.tsx +0 -138
  195. package/components/Register/props.ts +0 -50
  196. package/components/SendCode/SendCodeBtn.tsx +0 -96
  197. package/components/SendCode/index.tsx +0 -94
  198. package/components/SendCode/style.less +0 -31
  199. package/components/ShieldSpin/index.tsx +0 -27
  200. package/components/ShieldSpin/loading.svg +0 -29
  201. package/components/SubmitButton/index.tsx +0 -50
  202. package/components/SubmitSuccess/index.tsx +0 -66
  203. package/components/SubmitSuccess/interface.ts +0 -17
  204. package/components/Type/index.ts +0 -52
  205. package/components/ValidatorRules/EmailFormItem.tsx +0 -95
  206. package/components/ValidatorRules/PhoneFormItem.tsx +0 -100
  207. package/components/ValidatorRules/index.ts +0 -14
  208. package/components/VerifyCodeInput/index.tsx +0 -76
  209. package/components/VerifyCodeInput/style.less +0 -24
  210. package/components/_utils/GuardErrorCode.ts +0 -9
  211. package/components/_utils/clipboard.ts +0 -27
  212. package/components/_utils/config.ts +0 -118
  213. package/components/_utils/guradHttp.ts +0 -97
  214. package/components/_utils/hooks/index.ts +0 -64
  215. package/components/_utils/http.ts +0 -85
  216. package/components/_utils/index.ts +0 -322
  217. package/components/_utils/locales/en/common.json +0 -227
  218. package/components/_utils/locales/en/index.ts +0 -6
  219. package/components/_utils/locales/en/login.json +0 -96
  220. package/components/_utils/locales/en/map.json +0 -4
  221. package/components/_utils/locales/en/user.json +0 -82
  222. package/components/_utils/locales/index.ts +0 -45
  223. package/components/_utils/locales/zh/common.json +0 -227
  224. package/components/_utils/locales/zh/index.ts +0 -6
  225. package/components/_utils/locales/zh/login.json +0 -96
  226. package/components/_utils/locales/zh/map.json +0 -4
  227. package/components/_utils/locales/zh/user.json +0 -82
  228. package/components/_utils/popupCenter.ts +0 -48
  229. package/components/assets/images/error.png +0 -0
  230. package/components/context/base.tsx +0 -28
  231. package/components/context/global/context.tsx +0 -39
  232. package/components/context/global/reducer.tsx +0 -56
  233. package/components/context/module/context.tsx +0 -23
  234. package/components/index.ts +0 -12
  235. package/config/antdReplacer.js +0 -51
  236. package/config/env.js +0 -104
  237. package/config/getHttpsConfig.js +0 -66
  238. package/config/jest/cssTransform.js +0 -14
  239. package/config/jest/fileTransform.js +0 -40
  240. package/config/modules.js +0 -134
  241. package/config/paths.js +0 -71
  242. package/config/pnpTs.js +0 -35
  243. package/config/webpack.config.js +0 -835
  244. package/config/webpackDevServer.config.js +0 -130
  245. package/examples.tsx +0 -82
  246. package/index.js +0 -1
  247. package/logo.svg +0 -7
  248. package/public/favicon.ico +0 -0
  249. package/public/index.html +0 -43
  250. package/public/logo192.png +0 -0
  251. package/public/logo512.png +0 -0
  252. package/public/manifest.json +0 -25
  253. package/public/robots.txt +0 -3
  254. package/react-app-env.d.ts +0 -71
  255. package/reportWebVitals.ts +0 -15
  256. package/scripts/build.js +0 -208
  257. package/scripts/lib.js +0 -200
  258. package/scripts/publish.js +0 -57
  259. package/scripts/start.js +0 -162
  260. package/scripts/test.js +0 -49
  261. package/setupTests.ts +0 -5
  262. package/tsconfig.json +0 -30
@@ -1,27 +0,0 @@
1
- import { i18n } from './locales'
2
-
3
- // https://juejin.im/post/6844903857290477582
4
- export const copyToClipboard = (str: string) => {
5
- const el = document.createElement('textarea') // 创建一个 <textarea> 元素
6
- el.value = str // 设置它的值为你想复制的字符串
7
- el.setAttribute('readonly', '') // 设置为只读以防止干扰
8
- el.style.position = 'absolute'
9
- el.style.left = '-9999px' // 移出屏幕外以使其不可见
10
- document.body.appendChild(el) // 插入 <textarea> 元素到 HTML 文档中
11
- try {
12
- const selected =
13
- document.getSelection()!.rangeCount > 0 // 检查是否之前曾选中过内容
14
- ? document.getSelection()!.getRangeAt(0) // 如果找到,则保存选中
15
- : false // 标记为 false 以表示不存在之前选中的内容
16
- el.select() // 选中 <textarea> 的内容
17
- document.execCommand('copy') // 复制 - 仅当作为用户操作的响应结果时才可以工作(比如,点击事件)
18
- document.body.removeChild(el) // 移除 <textarea> 元素
19
- if (selected) {
20
- // 如果在复制前已存在选中的内容
21
- document.getSelection()!.removeAllRanges() // 取消 HTML 文档中所有的选中部分
22
- document.getSelection()!.addRange(selected) // 恢复原来的选中
23
- }
24
- } catch (e) {
25
- console.warn(i18n.t('common.copyFailed'))
26
- }
27
- }
@@ -1,118 +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, GuardHttp, useGuardHttp } 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))
22
- await requestPublicConfig(appId, config.host ?? defaultConfig.host)
23
- const mergedConfig = mergeConfig(
24
- config,
25
- defaultConfig,
26
- getPublicConfig(appId)
27
- )
28
-
29
- return {
30
- config: {
31
- ...mergedConfig,
32
- __publicConfig__: getPublicConfig(appId),
33
- __appHost__: assembledAppHost(
34
- getPublicConfig(appId).identifier,
35
- mergedConfig?.host!
36
- ),
37
- },
38
- publicConfig: getPublicConfig(appId),
39
- }
40
- }
41
-
42
- const mergeConfig = (
43
- config: GuardComponentConifg,
44
- defaultConfig: IG2Config,
45
- publicConfig: ApplicationConfig
46
- ): GuardLocalConfig => {
47
- const mergedPublicConfig: GuardLocalConfig = {
48
- ...defaultConfig,
49
- ...config,
50
- title: config.title ?? publicConfig.name,
51
- logo: !!config.logo ? config.logo : publicConfig.logo,
52
- loginMethods:
53
- config?.loginMethods ??
54
- (publicConfig.loginTabs?.list as LoginMethods[]) ??
55
- [],
56
- passwordLoginMethods:
57
- config?.passwordLoginMethods ??
58
- publicConfig.passwordTabConfig?.enabledLoginMethods ??
59
- [],
60
- // 默认登录方式
61
- defaultLoginMethod:
62
- config.defaultLoginMethod ??
63
- (publicConfig.loginTabs.default as LoginMethods),
64
- // 禁止重制密码
65
- disableResetPwd: !!(
66
- config.disableResetPwd ??
67
- !publicConfig.ssoPageComponentDisplay?.forgetPasswordBtn
68
- ),
69
- // 是否自动注册
70
- autoRegister:
71
- config.autoRegister ??
72
- publicConfig.ssoPageComponentDisplay.autoRegisterThenLoginHintInfo,
73
- registerMethods:
74
- config.registerMethods ??
75
- (publicConfig.registerTabs?.list as RegisterMethods[]),
76
- defaultRegisterMethod:
77
- config.defaultRegisterMethod ??
78
- (publicConfig.registerTabs.default as RegisterMethods),
79
- // 禁止注册
80
- disableRegister: !!(
81
- config.disableRegister ??
82
- !publicConfig.ssoPageComponentDisplay.registerBtn
83
- ),
84
- // publicKey
85
- publicKey: config.publicKey ?? publicConfig.publicKey,
86
- // 注册协议
87
- agreementEnabled: config.agreementEnabled ?? publicConfig.agreementEnabled,
88
- agreements: config.agreements ?? publicConfig.agreements,
89
- contentCss: config.contentCss ?? publicConfig.css,
90
- }
91
-
92
- return mergedPublicConfig
93
- }
94
-
95
- const requestPublicConfig = async (
96
- appId: string,
97
- host: string
98
- ): Promise<ApplicationConfig> => {
99
- let res: AuthingResponse<ApplicationConfig>
100
-
101
- const { get } = getGuardHttp()
102
-
103
- try {
104
- res = await get<ApplicationConfig>(
105
- `/api/v2/applications/${appId}/public-config`
106
- )
107
- } catch (error) {
108
- console.error('Please check your config or network')
109
- throw new Error('Please check your config or network')
110
- }
111
-
112
- if (res.code !== 200 || !res.data)
113
- throw new Error(res?.message ?? 'Please check your config')
114
-
115
- setPublicConfig(appId, res.data)
116
-
117
- return getPublicConfig(appId)
118
- }
@@ -1,97 +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
- public getHeaders = () => this.headers
40
-
41
- public get = async <T>(
42
- path: string,
43
- query: Record<string, any> = {},
44
- config?: RequestInit
45
- ) =>
46
- await requestClient.get<T>(path, query, {
47
- ...config,
48
- headers: { ...this.headers, ...config?.headers },
49
- })
50
-
51
- public post = async <T>(
52
- path: string,
53
- data: any,
54
- config?: {
55
- headers: any
56
- }
57
- ) =>
58
- await requestClient.post<T>(path, data, {
59
- headers: {
60
- ...this.headers,
61
- ...config?.headers,
62
- },
63
- })
64
-
65
- public postForm = async <T>(
66
- path: string,
67
- formData: any,
68
- config?: {
69
- headers: any
70
- }
71
- ) =>
72
- await requestClient.postForm<T>(path, formData, {
73
- headers: {
74
- ...this.headers,
75
- ...config?.headers,
76
- },
77
- })
78
- }
79
-
80
- export const initGuardHttp = (baseUrl: string) => {
81
- if (!httpClient) {
82
- const guardHttp = new GuardHttp(baseUrl)
83
- httpClient = guardHttp
84
- }
85
-
86
- return httpClient
87
- }
88
-
89
- export const getGuardHttp = () => {
90
- if (!httpClient) {
91
- throw new Error('Please initialize Http Client')
92
- }
93
-
94
- return httpClient
95
- }
96
-
97
- 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,322 +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
- splitHost.shift()
202
-
203
- return `${hostUrl.protocol}//${identifier}.${splitHost.join('.')}`
204
- }
205
-
206
- export enum PasswordStrength {
207
- NoCheck,
208
- Low,
209
- Middle,
210
- High,
211
- AUTO,
212
- }
213
-
214
- export const PASSWORD_STRENGTH_TEXT_MAP: Record<
215
- PasswordStrength,
216
- {
217
- placeholder: () => string
218
- validateMessage: () => string
219
- }
220
- > = {
221
- [PasswordStrength.NoCheck]: {
222
- placeholder: () => i18n.t('login.inputPwd'),
223
- validateMessage: () => i18n.t('login.inputPwd'),
224
- },
225
- [PasswordStrength.Low]: {
226
- placeholder: () => i18n.t('login.setPwdLimit1'),
227
- validateMessage: () => i18n.t('login.setPwdLimitMsg1'),
228
- },
229
- [PasswordStrength.Middle]: {
230
- placeholder: () => i18n.t('login.login.setPwdLimit2'),
231
- validateMessage: () => i18n.t('login.setPwdLimitMsg2'),
232
- },
233
- [PasswordStrength.High]: {
234
- placeholder: () => i18n.t('login.login.setPwdLimit3'),
235
- validateMessage: () => i18n.t('login.setPwdLimitMsg3'),
236
- },
237
- [PasswordStrength.AUTO]: {
238
- placeholder: () => i18n.t('login.inputPwd'),
239
- validateMessage: () => i18n.t('login.inputPwd'),
240
- },
241
- }
242
-
243
- const SYMBOL_TYPE_PATTERNS = [
244
- /\d+/,
245
- /[a-zA-Z]/,
246
- /[-!$%^&*()_+|~=`{}[\]:";'<>?,@./]/,
247
- ]
248
-
249
- export const getSymbolTypeLength = (pwd: string) => {
250
- return SYMBOL_TYPE_PATTERNS.map((pattern) => pattern.test(pwd)).filter(
251
- (item) => item
252
- ).length
253
- }
254
-
255
- export const getPasswordValidate = (
256
- strength: PasswordStrength = PasswordStrength.NoCheck,
257
- customPasswordStrength: any = {}
258
- ): Rule[] => {
259
- const required = fieldRequiredRule(i18n.t('common.password'))[0]
260
-
261
- const validateMap: Record<PasswordStrength, Rule[]> = {
262
- [PasswordStrength.NoCheck]: [required],
263
- [PasswordStrength.Low]: [
264
- required,
265
- {
266
- validator(r, v) {
267
- if (v && v.length < 6) {
268
- return Promise.reject(
269
- PASSWORD_STRENGTH_TEXT_MAP[PasswordStrength.Low].validateMessage()
270
- )
271
- }
272
- return Promise.resolve()
273
- },
274
- },
275
- ],
276
- [PasswordStrength.Middle]: [
277
- required,
278
- {
279
- validator(r, v) {
280
- if (v && (v.length < 6 || getSymbolTypeLength(v) < 2)) {
281
- return Promise.reject(
282
- PASSWORD_STRENGTH_TEXT_MAP[
283
- PasswordStrength.Middle
284
- ].validateMessage()
285
- )
286
- }
287
- return Promise.resolve()
288
- },
289
- },
290
- ],
291
- [PasswordStrength.High]: [
292
- required,
293
- {
294
- validator(r, v) {
295
- if (v && (v.length < 6 || getSymbolTypeLength(v) < 3)) {
296
- console.log(
297
- PASSWORD_STRENGTH_TEXT_MAP[PasswordStrength.High].validateMessage
298
- )
299
- return Promise.reject(
300
- PASSWORD_STRENGTH_TEXT_MAP[
301
- PasswordStrength.High
302
- ].validateMessage()
303
- )
304
- }
305
- return Promise.resolve(true)
306
- },
307
- },
308
- ],
309
- [PasswordStrength.AUTO]: [
310
- required,
311
- {
312
- pattern: customPasswordStrength?.regex,
313
- message: customPasswordStrength?.message,
314
- },
315
- ],
316
- }
317
-
318
- return validateMap[strength]
319
- }
320
-
321
- export const sleep = (delay: number) =>
322
- new Promise((resolve) => setTimeout(resolve, delay))