@lark-apaas/client-toolkit 1.2.24-alpha.5 → 1.2.24-alpha.7

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.
@@ -139,7 +139,8 @@ class ApiProxy {
139
139
  ...config,
140
140
  headers: {
141
141
  ...this.defaultConfig.headers,
142
- ...config.headers
142
+ ...config.headers,
143
+ 'X-Page-Route': 'undefined' != typeof window ? window.location?.pathname || '/' : '/'
143
144
  }
144
145
  };
145
146
  const requestKey = this.generateRequestKey(mergedConfig);
@@ -14,17 +14,31 @@ const Component = ()=>{
14
14
  const isMobile = useIsMobile();
15
15
  const [userinfo, setUserinfo] = useState(null);
16
16
  const [isInternetVisible, setIsInternetVisible] = useState(false);
17
+ const [showBadge, setShowBadge] = useState(true);
18
+ const [badgeLoaded, setBadgeLoaded] = useState(false);
17
19
  const timeoutRef = useRef(null);
18
20
  useEffect(()=>{
19
21
  const appId = getAppId();
22
+ const csrfHeaders = {
23
+ 'X-Suda-Csrf-Token': getCsrfToken()
24
+ };
20
25
  const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
21
26
  fetch(tenantInfoUrl, {
22
- headers: {
23
- 'X-Suda-Csrf-Token': getCsrfToken()
24
- }
27
+ headers: csrfHeaders
25
28
  }).then((res)=>res.json()).then((data)=>{
26
29
  setUserinfo(data?.data?.tenant_info);
27
30
  setIsInternetVisible(data?.data?.is_internet_visible);
31
+ }).catch(()=>{});
32
+ const getPublishedUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/get_published` : `/spark/b/${appId}/get_published`;
33
+ fetch(getPublishedUrl, {
34
+ headers: csrfHeaders
35
+ }).then((res)=>res.json()).then((data)=>{
36
+ const badge = data?.data?.app_info?.show_badge;
37
+ setShowBadge(false !== badge);
38
+ }).catch(()=>{
39
+ setShowBadge(true);
40
+ }).finally(()=>{
41
+ setBadgeLoaded(true);
28
42
  });
29
43
  }, []);
30
44
  useEffect(()=>{
@@ -39,6 +53,8 @@ const Component = ()=>{
39
53
  isMobile
40
54
  ]);
41
55
  if ('production' !== process.env.NODE_ENV) return null;
56
+ if (!badgeLoaded) return null;
57
+ if (!showBadge) return null;
42
58
  if (!visible) return null;
43
59
  if (isMobile) return /*#__PURE__*/ jsxs(Sheet, {
44
60
  open: open,
@@ -47,7 +63,7 @@ const Component = ()=>{
47
63
  /*#__PURE__*/ jsx(SheetTrigger, {
48
64
  asChild: true,
49
65
  children: /*#__PURE__*/ jsxs("div", {
50
- className: "fixed right-[12px] bottom-[80px] inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-[10px] py-[6px] bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-md text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000]",
66
+ className: "fixed right-[12px] bottom-[80px] inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-[10px] py-[6px] bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-[6px] text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000]",
51
67
  onClick: ()=>{
52
68
  setOpen(true);
53
69
  },
@@ -242,7 +258,7 @@ const Component = ()=>{
242
258
  className: "w-full self-stretch shrink-0 flex items-start gap-x-[8px]",
243
259
  children: [
244
260
  /*#__PURE__*/ jsx("div", {
245
- className: "flex-1 flex rounded-lg items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
261
+ className: "flex-1 flex rounded-[8px] items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
246
262
  "data-custom-element": "safety-close",
247
263
  onClick: (e)=>{
248
264
  e.stopPropagation();
@@ -253,7 +269,7 @@ const Component = ()=>{
253
269
  children: "不再展示"
254
270
  }),
255
271
  /*#__PURE__*/ jsx("div", {
256
- className: "flex-1 flex rounded-lg items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
272
+ className: "flex-1 flex rounded-[8px] items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
257
273
  "data-custom-element": "safety-more",
258
274
  onClick: ()=>{
259
275
  window.open('https://miaoda.feishu.cn/landing', '_blank');
@@ -0,0 +1,12 @@
1
+ import type { BatchGetChatsResponse, SearchChatsParams, SearchChatsResponse } from './types';
2
+ export type ChatServiceConfig = {
3
+ getAppId?: () => string | null | undefined;
4
+ searchChatsUrl?: (appId: string) => string;
5
+ listChatsUrl?: (appId: string) => string;
6
+ };
7
+ export declare class ChatService {
8
+ private config;
9
+ constructor(config?: ChatServiceConfig);
10
+ searchChats(params: SearchChatsParams): Promise<SearchChatsResponse>;
11
+ listChatsByIds(chatIds: string[]): Promise<BatchGetChatsResponse>;
12
+ }
@@ -0,0 +1,67 @@
1
+ import { getAppId } from "../../utils/getAppId.js";
2
+ const DEFAULT_CONFIG = {
3
+ getAppId: ()=>getAppId(),
4
+ searchChatsUrl: (appId)=>`/app/${appId}/__runtime__/api/v1/account/search`,
5
+ listChatsUrl: (appId)=>`/app/${appId}/__runtime__/api/v1/account/chat/list_chats`
6
+ };
7
+ class ChatService {
8
+ config;
9
+ constructor(config = {}){
10
+ this.config = {
11
+ ...DEFAULT_CONFIG,
12
+ ...config
13
+ };
14
+ }
15
+ async searchChats(params) {
16
+ const appId = this.config.getAppId();
17
+ if (!appId) throw new Error('Failed to get appId');
18
+ const response = await fetch(this.config.searchChatsUrl(appId), {
19
+ method: 'POST',
20
+ headers: {
21
+ 'Content-Type': 'application/json'
22
+ },
23
+ body: JSON.stringify({
24
+ query: params.query,
25
+ filters: {
26
+ userParam: {
27
+ commonParam: {
28
+ searchable: false
29
+ }
30
+ },
31
+ departmentParam: {
32
+ commonParam: {
33
+ searchable: false
34
+ }
35
+ },
36
+ chatParam: {
37
+ commonParam: {
38
+ searchable: true,
39
+ pageSize: params.pageSize ?? 100,
40
+ offset: params.offset ?? 0
41
+ }
42
+ }
43
+ }
44
+ }),
45
+ credentials: 'include'
46
+ });
47
+ if (!response.ok) throw new Error('Failed to search chats');
48
+ return response.json();
49
+ }
50
+ async listChatsByIds(chatIds) {
51
+ const appId = this.config.getAppId();
52
+ if (!appId) throw new Error('Failed to get appId');
53
+ const response = await fetch(this.config.listChatsUrl(appId), {
54
+ method: 'POST',
55
+ headers: {
56
+ 'Content-Type': 'application/json'
57
+ },
58
+ body: JSON.stringify({
59
+ chatIDList: chatIds
60
+ }),
61
+ credentials: 'include'
62
+ });
63
+ if (!response.ok) throw new Error('Failed to fetch chats by ids');
64
+ return response.json();
65
+ }
66
+ }
67
+ export { ChatService };
@@ -1,4 +1,5 @@
1
1
  export * from './types';
2
2
  export * from './UserService';
3
3
  export * from './DepartmentService';
4
+ export * from './ChatService';
4
5
  export * from './UserProfileService';
@@ -1,4 +1,5 @@
1
1
  export * from "./types.js";
2
2
  export * from "./UserService.js";
3
3
  export * from "./DepartmentService.js";
4
+ export * from "./ChatService.js";
4
5
  export * from "./UserProfileService.js";
@@ -62,6 +62,40 @@ export type SearchDepartmentsResponse = {
62
62
  };
63
63
  status_code: string;
64
64
  };
65
+ export type ChatInfo = {
66
+ /** 群组 ID */
67
+ chatID: string;
68
+ /** 群组名称(国际化文本) */
69
+ name: I18nText;
70
+ /** 头像:URL 或 16 进制 RGB 颜色 */
71
+ avatar: string;
72
+ /** 是否是外部群 */
73
+ isExternal?: boolean;
74
+ /** 群成员数量(不包括机器人),搜索接口返回,批量查询接口不返回 */
75
+ userCount?: number;
76
+ };
77
+ export type SearchChatsParams = {
78
+ query?: string;
79
+ offset?: number;
80
+ pageSize?: number;
81
+ };
82
+ export type SearchChatsResponse = {
83
+ data: {
84
+ result: {
85
+ chatResult?: {
86
+ total: number;
87
+ items: ChatInfo[];
88
+ };
89
+ };
90
+ };
91
+ status_code: string;
92
+ };
93
+ export type BatchGetChatsResponse = {
94
+ data: {
95
+ chatInfoMap: Record<string, ChatInfo>;
96
+ };
97
+ status_code: string;
98
+ };
65
99
  export type UserProfileAccountStatus = 0 | 1 | 2 | 3 | 4;
66
100
  export type SimpleUserProfileInfo = {
67
101
  name?: string;
@@ -4,21 +4,6 @@ import { logger } from "../apis/logger.js";
4
4
  import { getStacktrace } from "../logger/selected-logs.js";
5
5
  import { safeStringify } from "./safeStringify.js";
6
6
  import { slardar } from "@lark-apaas/internal-slardar";
7
- import { normalizeBasePath } from "./utils.js";
8
- const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
9
- function getRefererPath() {
10
- try {
11
- if ('undefined' != typeof window && window.location?.pathname) return stripBasePath(window.location.pathname);
12
- return '/';
13
- } catch {
14
- return '/';
15
- }
16
- }
17
- function stripBasePath(urlPath) {
18
- const base = normalizeBasePath(process.env.CLIENT_BASE_PATH);
19
- if (base && urlPath.startsWith(base)) return urlPath.slice(base.length) || '/';
20
- return urlPath;
21
- }
22
7
  const isValidResponse = (resp)=>null != resp && 'object' == typeof resp && 'config' in resp && null !== resp.config && void 0 !== resp.config && 'object' == typeof resp.config && 'status' in resp && 'number' == typeof resp.status && 'data' in resp;
23
8
  async function logResponse(ok, responseOrError) {
24
9
  if (isValidResponse(responseOrError)) {
@@ -154,20 +139,13 @@ function handleSpanEnd(cfg, response, error) {
154
139
  const errorMessage = error?.message || '未知错误';
155
140
  const url = response?.request?.responseURL || errorResponse?.request?.responseURL || cfg.url || "";
156
141
  const method = (cfg.method || 'GET').toUpperCase();
157
- const rawPath = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
158
- const path = stripBasePath(rawPath);
159
- const durationMs = startTime ? Date.now() - startTime : void 0;
160
- const referer_path = getRefererPath();
161
- const api = `${method} ${path}`;
162
- const type = APP_CLIENT_API_LOG_TYPE;
142
+ const path = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
163
143
  const logData = {
164
144
  method,
165
145
  path,
166
146
  url,
167
- duration_ms: durationMs,
168
- status: response ? response.status : errorResponse.status || 0,
169
- referer_path,
170
- type
147
+ duration_ms: startTime ? Date.now() - startTime : void 0,
148
+ status: response ? response.status : errorResponse.status || 0
171
149
  };
172
150
  if (error) logData.error_message = errorMessage;
173
151
  if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
@@ -180,12 +158,7 @@ function handleSpanEnd(cfg, response, error) {
180
158
  const responseData = response?.data || errorResponse?.data;
181
159
  if (responseData) logData.response = responseData;
182
160
  const level = error ? 'ERROR' : 'INFO';
183
- observable.log(level, safeStringify(logData), {
184
- referer_path,
185
- api,
186
- type,
187
- duration_ms: durationMs
188
- }, currentSpan);
161
+ observable.log(level, safeStringify(logData), {}, currentSpan);
189
162
  'function' == typeof currentSpan.end && currentSpan.end();
190
163
  } catch (e) {
191
164
  console.error('[AxiosTrace] Log span failed:', e);
@@ -266,11 +239,7 @@ function initAxiosConfig(axiosInstance) {
266
239
  config._startTime = config._startTime || Date.now();
267
240
  const csrfToken = window.csrfToken;
268
241
  if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
269
- const refererPath = getRefererPath();
270
- config.headers['Rpc-Persist-Apaas-Observability-Referer-Path'] = refererPath;
271
- const reqMethod = (config.method || 'GET').toUpperCase();
272
- const requestPath = stripBasePath((config.url || '').split('?')[0]);
273
- config.headers['Rpc-Persist-Apaas-Observability-Api'] = `${reqMethod} ${requestPath}`;
242
+ if ('undefined' != typeof window && window.location?.pathname) config.headers['X-Page-Route'] = window.location.pathname;
274
243
  return config;
275
244
  }, (error)=>Promise.reject(error));
276
245
  instance.interceptors.response.use((response)=>response, (error)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.24-alpha.5",
3
+ "version": "1.2.24-alpha.7",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -98,13 +98,13 @@
98
98
  "dependencies": {
99
99
  "@ant-design/colors": "^7.2.1",
100
100
  "@ant-design/cssinjs": "^1.24.0",
101
- "@data-loom/js": "0.4.9",
102
- "@lark-apaas/aily-web-sdk": "^0.0.6",
103
- "@lark-apaas/auth-sdk": "^0.1.1",
104
- "@lark-apaas/client-capability": "^0.1.5",
105
- "@lark-apaas/internal-slardar": ">=0.0.1",
101
+ "@data-loom/js": "0.4.11",
102
+ "@lark-apaas/aily-web-sdk": "^0.0.7",
103
+ "@lark-apaas/auth-sdk": "^0.1.2",
104
+ "@lark-apaas/client-capability": "^0.1.6",
105
+ "@lark-apaas/internal-slardar": "^0.0.3",
106
106
  "@lark-apaas/miaoda-inspector": "^1.0.20",
107
- "@lark-apaas/observable-web": "^1.0.4",
107
+ "@lark-apaas/observable-web": "^1.0.5",
108
108
  "@radix-ui/react-avatar": "^1.1.10",
109
109
  "@radix-ui/react-popover": "^1.1.15",
110
110
  "@radix-ui/react-slot": "^1.2.3",