@lark-apaas/client-toolkit 1.2.23 → 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.
- package/lib/integrations/services/ChatService.d.ts +12 -0
- package/lib/integrations/services/ChatService.js +67 -0
- package/lib/integrations/services/index.d.ts +1 -0
- package/lib/integrations/services/index.js +1 -0
- package/lib/integrations/services/types.d.ts +34 -0
- package/lib/logger/intercept-global-error.js +18 -11
- package/lib/utils/axiosConfig.js +20 -0
- package/lib/utils/postMessage.d.ts +0 -1
- package/lib/utils/postMessage.js +1 -6
- package/package.json +7 -6
|
@@ -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 };
|
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { slardar } from "@lark-apaas/internal-slardar";
|
|
1
2
|
import { getHmrApi } from "../utils/hmr-api.js";
|
|
2
|
-
import { submitPostMessage
|
|
3
|
+
import { submitPostMessage } from "../utils/postMessage.js";
|
|
3
4
|
import { levelSchema } from "./log-types.js";
|
|
4
5
|
import { logger } from "./logger.js";
|
|
5
6
|
let devServerDisconnectInfo = null;
|
|
@@ -19,22 +20,26 @@ function processDevServerLog(log) {
|
|
|
19
20
|
status: 'disconnected'
|
|
20
21
|
}
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
+
slardar.sendEvent({
|
|
23
24
|
name: 'sandbox-devServer',
|
|
24
|
-
|
|
25
|
-
type: 'disconnected',
|
|
25
|
+
metrics: {
|
|
26
26
|
time
|
|
27
|
+
},
|
|
28
|
+
categories: {
|
|
29
|
+
type: 'disconnected'
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
34
|
if (!devServerDisconnectInfo) return;
|
|
32
35
|
if (devFlag && log.includes('Trying to reconnect')) {
|
|
33
|
-
if (retryCount)
|
|
36
|
+
if (retryCount) slardar.sendEvent({
|
|
34
37
|
name: 'sandbox-devServer',
|
|
35
|
-
|
|
36
|
-
type: 'reconnect-failed',
|
|
38
|
+
metrics: {
|
|
37
39
|
retryCount: retryCount + 1
|
|
40
|
+
},
|
|
41
|
+
categories: {
|
|
42
|
+
type: 'reconnect-failed'
|
|
38
43
|
}
|
|
39
44
|
});
|
|
40
45
|
retryCount++;
|
|
@@ -52,12 +57,14 @@ function processDevServerLog(log) {
|
|
|
52
57
|
const startTime = devServerDisconnectInfo.time;
|
|
53
58
|
const duration = Date.now() - startTime;
|
|
54
59
|
devServerDisconnectInfo = null;
|
|
55
|
-
|
|
60
|
+
slardar.sendEvent({
|
|
56
61
|
name: 'sandbox-devServer',
|
|
57
|
-
|
|
58
|
-
type: 'devServer-reconnected',
|
|
62
|
+
metrics: {
|
|
59
63
|
startTime,
|
|
60
64
|
duration
|
|
65
|
+
},
|
|
66
|
+
categories: {
|
|
67
|
+
type: 'devServer-reconnected'
|
|
61
68
|
}
|
|
62
69
|
});
|
|
63
70
|
}
|
|
@@ -76,7 +83,7 @@ function listenModuleHmr() {
|
|
|
76
83
|
});
|
|
77
84
|
hmr.onError((error)=>{
|
|
78
85
|
console.warn('hmr apply failed', error);
|
|
79
|
-
|
|
86
|
+
slardar.sendEvent({
|
|
80
87
|
name: 'sandbox-devServer',
|
|
81
88
|
categories: {
|
|
82
89
|
type: 'hmr-apply-failed',
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -3,6 +3,7 @@ import { observable } from "@lark-apaas/observable-web";
|
|
|
3
3
|
import { logger } from "../apis/logger.js";
|
|
4
4
|
import { getStacktrace } from "../logger/selected-logs.js";
|
|
5
5
|
import { safeStringify } from "./safeStringify.js";
|
|
6
|
+
import { slardar } from "@lark-apaas/internal-slardar";
|
|
6
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;
|
|
7
8
|
async function logResponse(ok, responseOrError) {
|
|
8
9
|
if (isValidResponse(responseOrError)) {
|
|
@@ -193,6 +194,10 @@ AxiosProto.request = function(configOrUrl, config) {
|
|
|
193
194
|
return response;
|
|
194
195
|
}, (error)=>{
|
|
195
196
|
handleSpanEnd(error.config || finalConfig, null, error);
|
|
197
|
+
slardar.captureException(error, {
|
|
198
|
+
source: 'toolkit',
|
|
199
|
+
module: 'axios-request'
|
|
200
|
+
});
|
|
196
201
|
throw error;
|
|
197
202
|
});
|
|
198
203
|
};
|
|
@@ -253,9 +258,24 @@ function initAxiosConfig(axiosInstance) {
|
|
|
253
258
|
],
|
|
254
259
|
meta: {}
|
|
255
260
|
});
|
|
261
|
+
slardar.sendEvent({
|
|
262
|
+
name: 'toolkit_axios_403_downgrade',
|
|
263
|
+
categories: {
|
|
264
|
+
url: String(error.config?.url || ''),
|
|
265
|
+
method: String(error.config?.method || '')
|
|
266
|
+
}
|
|
267
|
+
});
|
|
256
268
|
return error.response;
|
|
257
269
|
}
|
|
258
270
|
} catch (e) {}
|
|
271
|
+
slardar.sendEvent({
|
|
272
|
+
name: 'toolkit_axios_response_error',
|
|
273
|
+
categories: {
|
|
274
|
+
url: String(error.config?.url || ''),
|
|
275
|
+
method: String(error.config?.method || ''),
|
|
276
|
+
status: String(error.response?.status || '')
|
|
277
|
+
}
|
|
278
|
+
});
|
|
259
279
|
return Promise.reject(error);
|
|
260
280
|
});
|
|
261
281
|
'production' !== process.env.NODE_ENV && instance.interceptors.response.use((response)=>{
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
|
|
2
2
|
export declare function resolveParentOrigin(): string;
|
|
3
3
|
export declare function submitPostMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
|
4
|
-
export declare function submitSlardarEvent(event: unknown): void;
|
|
5
4
|
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
|
6
5
|
type: T;
|
|
7
6
|
}>;
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -38,15 +38,10 @@ function submitPostMessage(message, targetOrigin) {
|
|
|
38
38
|
console.error('postMessage error', e);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function submitSlardarEvent(event) {
|
|
42
|
-
const slardar = window.KSlardarWeb;
|
|
43
|
-
if ('function' == typeof slardar) slardar('sendEvent', event);
|
|
44
|
-
else console.warn('hmr listen function not found');
|
|
45
|
-
}
|
|
46
41
|
function isOutgoingMessage(msg, type) {
|
|
47
42
|
return msg.type === type;
|
|
48
43
|
}
|
|
49
44
|
function isIncomingMessage(msg, type) {
|
|
50
45
|
return msg.type === type;
|
|
51
46
|
}
|
|
52
|
-
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage
|
|
47
|
+
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.25",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -98,12 +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.
|
|
102
|
-
"@lark-apaas/aily-web-sdk": "
|
|
103
|
-
"@lark-apaas/auth-sdk": "^0.1.
|
|
104
|
-
"@lark-apaas/client-capability": "^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",
|
|
105
106
|
"@lark-apaas/miaoda-inspector": "^1.0.20",
|
|
106
|
-
"@lark-apaas/observable-web": "^1.0.
|
|
107
|
+
"@lark-apaas/observable-web": "^1.0.5",
|
|
107
108
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
108
109
|
"@radix-ui/react-popover": "^1.1.15",
|
|
109
110
|
"@radix-ui/react-slot": "^1.2.3",
|