@lark-apaas/client-toolkit 1.2.2-test.0 → 1.2.2-test.2

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,4 @@
1
- import type { Department, SearchDepartmentsParams, SearchDepartmentsResponse } from './types';
1
+ import type { SearchDepartmentsParams, SearchDepartmentsResponse } from './types';
2
2
  export type DepartmentServiceConfig = {
3
3
  getAppId?: () => string | null | undefined;
4
4
  searchDepartmentUrl?: (appId: string) => string;
@@ -7,8 +7,4 @@ export declare class DepartmentService {
7
7
  private config;
8
8
  constructor(config?: DepartmentServiceConfig);
9
9
  searchDepartments(params: SearchDepartmentsParams): Promise<SearchDepartmentsResponse>;
10
- createFetcher(): (search: string) => Promise<{
11
- items: Department[];
12
- }>;
13
- private getDepartmentDisplayName;
14
10
  }
@@ -25,24 +25,5 @@ class DepartmentService {
25
25
  if (!response.ok) throw new Error('Failed to search departments');
26
26
  return response.json();
27
27
  }
28
- createFetcher() {
29
- return async (search)=>{
30
- const response = await this.searchDepartments({
31
- query: search,
32
- pageSize: 100
33
- });
34
- const departmentList = response?.data?.departmentList || [];
35
- return {
36
- items: departmentList.map((department)=>({
37
- id: department.departmentID,
38
- name: this.getDepartmentDisplayName(department.name),
39
- raw: department
40
- }))
41
- };
42
- };
43
- }
44
- getDepartmentDisplayName(name) {
45
- return name?.zh_cn || name?.en_us || '';
46
- }
47
28
  }
48
29
  export { DepartmentService };
@@ -1,4 +1,4 @@
1
- import type { AccountType, SearchUsersParams, SearchUsersResponse, User } from './types';
1
+ import type { BatchGetUsersResponse, SearchUsersParams, SearchUsersResponse } from './types';
2
2
  export type UserServiceConfig = {
3
3
  getAppId?: () => string | null | undefined;
4
4
  searchUserUrl?: (appId: string) => string;
@@ -6,17 +6,7 @@ export type UserServiceConfig = {
6
6
  };
7
7
  export declare class UserService {
8
8
  private config;
9
- private cache;
10
9
  constructor(config?: UserServiceConfig);
11
10
  searchUsers(params: SearchUsersParams): Promise<SearchUsersResponse>;
12
- fetchUsersByIds(userIds: string[], accountType?: AccountType): Promise<User[]>;
13
- createFetcher(accountType?: AccountType): (search: string) => Promise<{
14
- items: User[];
15
- }>;
16
- clearCache(): void;
17
- private getCachedUsers;
18
- private createUnknownUser;
19
- private userInfoToUser;
20
- private getUserDisplayName;
21
- private getUserId;
11
+ listUsersByIds(userIds: string[]): Promise<BatchGetUsersResponse>;
22
12
  }
@@ -6,7 +6,6 @@ const DEFAULT_CONFIG = {
6
6
  };
7
7
  class UserService {
8
8
  config;
9
- cache = new Map();
10
9
  constructor(config = {}){
11
10
  this.config = {
12
11
  ...DEFAULT_CONFIG,
@@ -27,96 +26,21 @@ class UserService {
27
26
  if (!response.ok) throw new Error('Failed to search users');
28
27
  return response.json();
29
28
  }
30
- async fetchUsersByIds(userIds, accountType = 'apaas') {
31
- if (0 === userIds.length) return [];
32
- const uniqueIds = [
33
- ...new Set(userIds)
34
- ];
35
- const { cachedUsers, missingIds } = this.getCachedUsers(uniqueIds);
36
- if (0 === missingIds.length) return uniqueIds.map((id)=>cachedUsers.get(id) || this.createUnknownUser(id));
29
+ async listUsersByIds(userIds) {
37
30
  const appId = this.config.getAppId();
38
31
  if (!appId) throw new Error('Failed to get appId');
39
- try {
40
- const response = await fetch(this.config.listUsersUrl(appId), {
41
- method: 'POST',
42
- headers: {
43
- 'Content-Type': 'application/json'
44
- },
45
- body: JSON.stringify({
46
- userIDList: missingIds.map((id)=>Number(id))
47
- }),
48
- credentials: 'include'
49
- });
50
- if (!response.ok) throw new Error('Failed to fetch users by ids');
51
- const data = await response.json();
52
- const userInfoMap = data?.data?.userInfoMap || {};
53
- for (const id of missingIds){
54
- const userInfo = userInfoMap[id];
55
- if (userInfo) {
56
- const user = this.userInfoToUser(userInfo, accountType);
57
- this.cache.set(user.id, user);
58
- }
59
- }
60
- return uniqueIds.map((id)=>this.cache.get(id) || this.createUnknownUser(id));
61
- } catch (error) {
62
- console.error('Failed to fetch users by ids:', error);
63
- return uniqueIds.map((id)=>this.cache.get(id) || this.createUnknownUser(id));
64
- }
65
- }
66
- createFetcher(accountType = 'apaas') {
67
- return async (search)=>{
68
- const response = await this.searchUsers({
69
- query: search,
70
- pageSize: 100
71
- });
72
- const userList = response?.data?.userList || [];
73
- return {
74
- items: userList.map((user)=>({
75
- id: this.getUserId(user, accountType),
76
- name: this.getUserDisplayName(user.name),
77
- avatar: user.avatar,
78
- raw: user
79
- }))
80
- };
81
- };
82
- }
83
- clearCache() {
84
- this.cache.clear();
85
- }
86
- getCachedUsers(ids) {
87
- const cachedUsers = new Map();
88
- const missingIds = [];
89
- for (const id of ids){
90
- const cached = this.cache.get(id);
91
- if (cached) cachedUsers.set(id, cached);
92
- else missingIds.push(id);
93
- }
94
- return {
95
- cachedUsers,
96
- missingIds
97
- };
98
- }
99
- createUnknownUser(id) {
100
- return {
101
- id,
102
- name: '未知用户',
103
- avatar: void 0,
104
- raw: void 0
105
- };
106
- }
107
- userInfoToUser(userInfo, accountType) {
108
- return {
109
- id: this.getUserId(userInfo, accountType),
110
- name: this.getUserDisplayName(userInfo.name),
111
- avatar: userInfo.avatar?.image?.large,
112
- raw: userInfo
113
- };
114
- }
115
- getUserDisplayName(name) {
116
- return name.zh_cn || name.en_us || '';
117
- }
118
- getUserId(user, accountType) {
119
- return 'lark' === accountType ? user.larkUserID : user.userID;
32
+ const response = await fetch(this.config.listUsersUrl(appId), {
33
+ method: 'POST',
34
+ headers: {
35
+ 'Content-Type': 'application/json'
36
+ },
37
+ body: JSON.stringify({
38
+ userIDList: userIds.map((id)=>Number(id))
39
+ }),
40
+ credentials: 'include'
41
+ });
42
+ if (!response.ok) throw new Error('Failed to fetch users by ids');
43
+ return response.json();
120
44
  }
121
45
  }
122
46
  export { UserService };
@@ -1,6 +1,7 @@
1
1
  export type I18nText = {
2
- zh_cn?: string;
2
+ zh_cn: string;
3
3
  en_us?: string;
4
+ ja_jp?: string;
4
5
  };
5
6
  export type DepartmentBasic = {
6
7
  departmentID: string;
@@ -60,14 +61,3 @@ export type SearchDepartmentsResponse = {
60
61
  };
61
62
  status_code: string;
62
63
  };
63
- export type User = {
64
- id: string;
65
- name: string;
66
- avatar?: string;
67
- raw?: UserInfo;
68
- };
69
- export type Department = {
70
- id: string;
71
- name: string;
72
- raw?: DepartmentInfo;
73
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.2-test.0",
3
+ "version": "1.2.2-test.2",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [