@lark-apaas/client-toolkit 1.2.38 → 1.2.40

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.
@@ -1,4 +1,5 @@
1
1
  function getDefaultBucketId() {
2
- return window._bucket_id;
2
+ const w = window;
3
+ return w._bucket_id ?? w.__platform__?.appPublished?.app_runtime_extra?.bucket?.default_bucket_id;
3
4
  }
4
5
  export { getDefaultBucketId };
@@ -1,6 +1,11 @@
1
1
  import { getAppId } from "./getAppId.js";
2
2
  import { getCsrfToken } from "./getCsrfToken.js";
3
3
  import { isNewPathEnabled } from "./apiPath.js";
4
+ function syncBucketIdToWindow(info) {
5
+ if (!info) return;
6
+ const bucketId = info.app_runtime_extra?.bucket?.default_bucket_id;
7
+ if (bucketId) window._bucket_id = bucketId;
8
+ }
4
9
  async function getAppPublished() {
5
10
  try {
6
11
  const headers = {
@@ -18,7 +23,10 @@ async function getAppPublished() {
18
23
  credentials: 'include'
19
24
  });
20
25
  const res = await response.json();
21
- if (0 === res.code || '0' === res.status_code) return res.data;
26
+ if (0 === res.code || '0' === res.status_code) {
27
+ syncBucketIdToWindow(res.data);
28
+ return res.data;
29
+ }
22
30
  console.error('Error fetching published app info:', res);
23
31
  } catch (error) {
24
32
  console.error('Error fetching published app info:', error);
@@ -38,14 +46,13 @@ function getInitialInfo(refresh = false) {
38
46
  const preloaded = getPreloadedInfo();
39
47
  if (preloaded) {
40
48
  initialInfo = preloaded;
41
- if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
49
+ syncBucketIdToWindow(initialInfo);
42
50
  return Promise.resolve(initialInfo);
43
51
  }
44
52
  }
45
53
  if (pendingPromise && !refresh) return pendingPromise;
46
54
  pendingPromise = getAppPublished().then((info)=>{
47
55
  initialInfo = info;
48
- if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
49
56
  return initialInfo;
50
57
  }).finally(()=>{
51
58
  pendingPromise = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.38",
3
+ "version": "1.2.40",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [