@lark-apaas/client-toolkit 1.2.28-alpha.76 → 1.2.28-alpha.78

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,6 +2,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
4
4
  import { getAppId } from "../../utils/getAppId.js";
5
+ import { getCsrfToken } from "../../utils/getCsrfToken.js";
6
+ import { isNewPathEnabled } from "../../utils/apiPath.js";
5
7
  import { useIsMobile } from "../../hooks/index.js";
6
8
  import { X } from "lucide-react";
7
9
  import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
@@ -12,10 +14,33 @@ const Component = ()=>{
12
14
  const [open, setOpen] = useState(false);
13
15
  const isMobile = useIsMobile();
14
16
  const timeoutRef = useRef(null);
15
- const platformData = window.__platform__ ?? {};
16
- const tenantName = platformData.tenantName ?? '';
17
- const isInternetVisible = platformData.isInternetVisible ?? false;
17
+ const platformData = window.__platform_data__ || window.__platform__ || {};
18
+ const appId = getAppId() || platformData.appId;
18
19
  const showBadge = false !== platformData.showBadge;
20
+ const [tenantName, setTenantName] = useState('');
21
+ const [isInternetVisible, setIsInternetVisible] = useState(false);
22
+ useEffect(()=>{
23
+ if (!showBadge || !visible) return;
24
+ const csrfToken = getCsrfToken() ?? '';
25
+ const csrfHeaders = {
26
+ 'X-Suda-Csrf-Token': csrfToken
27
+ };
28
+ const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
29
+ fetch(tenantInfoUrl, {
30
+ headers: csrfHeaders
31
+ }).then((res)=>res.json()).then((data)=>{
32
+ if (data?.status_code === '0' || data?.code === 0) {
33
+ setTenantName(data?.data?.tenant_info?.name || '');
34
+ setIsInternetVisible(data?.data?.is_internet_visible || false);
35
+ }
36
+ }).catch((e)=>{
37
+ console.warn('Failed to fetch tenant info:', e);
38
+ });
39
+ }, [
40
+ appId,
41
+ showBadge,
42
+ visible
43
+ ]);
19
44
  useEffect(()=>{
20
45
  if (isMobile) {
21
46
  const link = document.createElement('link');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.28-alpha.76",
3
+ "version": "1.2.28-alpha.78",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [