@lark-apaas/client-toolkit 1.2.28-alpha.61 → 1.2.28-alpha.62

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.
@@ -2,12 +2,26 @@ import { useEffect, useState } from "react";
2
2
  import { logger } from "../logger/index.js";
3
3
  import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
4
4
  import { getDataloom } from "../integrations/dataloom.js";
5
- import { isSparkRuntime, normalizeBasePath } from "../utils/utils.js";
5
+ import { isSparkRuntime } from "../utils/utils.js";
6
+ import { getAxiosForBackend } from "../utils/getAxiosForBackend.js";
6
7
  function getNameFromArray(nameArray) {
7
8
  if (!nameArray || 0 === nameArray.length) return;
8
9
  const chineseName = nameArray.find((item)=>2052 === item.language_code);
9
10
  return chineseName?.text ?? nameArray[0]?.text;
10
11
  }
12
+ let _larkUserIdCache = null;
13
+ let _larkUserIdPromise = null;
14
+ function fetchLarkUserId() {
15
+ if (null !== _larkUserIdCache) return Promise.resolve(_larkUserIdCache);
16
+ if (_larkUserIdPromise) return _larkUserIdPromise;
17
+ _larkUserIdPromise = getAxiosForBackend().get('/api/authnpaas/lark-user-id').then(({ data })=>{
18
+ _larkUserIdCache = data?.lark_user_id || null;
19
+ return _larkUserIdCache;
20
+ }).catch(()=>null).finally(()=>{
21
+ _larkUserIdPromise = null;
22
+ });
23
+ return _larkUserIdPromise;
24
+ }
11
25
  function getCompatibilityUserProfile() {
12
26
  const userInfo = getCurrentUserProfile();
13
27
  return {
@@ -34,20 +48,8 @@ const useCurrentUserProfile = ()=>{
34
48
  userName: userName,
35
49
  userAvatar: info?.avatar?.image?.large
36
50
  };
37
- try {
38
- const csrfToken = document.cookie.match(/suda-csrf-token=([^;]+)/)?.[1] || '';
39
- const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
40
- const resp = await fetch(`${basePath}/api/authnpaas/lark-user-id`, {
41
- credentials: 'include',
42
- headers: {
43
- 'x-suda-csrf-token': csrfToken
44
- }
45
- });
46
- if (resp.ok) {
47
- const data = await resp.json();
48
- if (data?.lark_user_id) newUserInfo.lark_user_id = data.lark_user_id;
49
- }
50
- } catch {}
51
+ const larkUserId = await fetchLarkUserId();
52
+ if (larkUserId) newUserInfo.lark_user_id = larkUserId;
51
53
  if ('development' === process.env.NODE_ENV) logger.info('MiaoDaMetaInfoChanged', newUserInfo);
52
54
  setUserInfo(newUserInfo);
53
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.28-alpha.61",
3
+ "version": "1.2.28-alpha.62",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [