@lark-apaas/client-toolkit 1.2.24 → 1.2.25

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.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.24",
3
+ "version": "1.2.25",
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",
101
+ "@data-loom/js": "0.4.11",
102
102
  "@lark-apaas/aily-web-sdk": "^0.0.7",
103
103
  "@lark-apaas/auth-sdk": "^0.1.2",
104
104
  "@lark-apaas/client-capability": "^0.1.6",
105
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",