@lark-apaas/client-toolkit 1.2.10 → 1.2.11

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);
@@ -16,7 +16,7 @@ async function createTracker() {
16
16
  const userIDEncrypt = userID && '0' !== userID ? encryptTea(userID) : void 0;
17
17
  const tenantIDEncrypt = tenantID && '0' !== tenantID ? encryptTea(tenantID) : void 0;
18
18
  window.collectEvent('init', {
19
- app_id: 672575,
19
+ app_id: 788827,
20
20
  channel: 'cn',
21
21
  disable_auto_pv: false,
22
22
  enable_ab_test: false,
@@ -0,0 +1,2 @@
1
+ /** 显示 toast 提示(兼容 PC/移动端) */
2
+ export declare function showToast(message: string, duration?: number): Promise<void>;
@@ -0,0 +1,53 @@
1
+ function showToast(message, duration = 3000) {
2
+ return new Promise((resolve)=>{
3
+ const toast = document.createElement('div');
4
+ const iconSvg = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
5
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M8 1.333a6.667 6.667 0 1 1 0 13.334A6.667 6.667 0 0 1 8 1.333ZM8 10a.667.667 0 1 0 0 1.333A.667.667 0 0 0 8 10Zm0-5.333a.667.667 0 0 0-.667.666v3.334a.667.667 0 0 0 1.334 0V5.333A.667.667 0 0 0 8 4.667Z" fill="#ff811a"/>
6
+ </svg>`;
7
+ const iconWrapper = document.createElement('span');
8
+ iconWrapper.innerHTML = iconSvg;
9
+ Object.assign(iconWrapper.style, {
10
+ display: 'flex',
11
+ alignItems: 'center',
12
+ marginRight: '8px',
13
+ flexShrink: '0'
14
+ });
15
+ const textWrapper = document.createElement('span');
16
+ textWrapper.textContent = message;
17
+ toast.appendChild(iconWrapper);
18
+ toast.appendChild(textWrapper);
19
+ Object.assign(toast.style, {
20
+ position: 'fixed',
21
+ top: '32px',
22
+ left: '50%',
23
+ transform: 'translate(-50%, -50%)',
24
+ display: 'flex',
25
+ alignItems: 'center',
26
+ padding: '12px 16px',
27
+ backgroundColor: '#fff',
28
+ color: '#1f2329',
29
+ border: '1px solid #dee0e3',
30
+ borderRadius: '6px',
31
+ fontSize: '14px',
32
+ lineHeight: '1.5',
33
+ zIndex: '99999',
34
+ maxWidth: '80vw',
35
+ wordBreak: 'break-word',
36
+ boxShadow: '0 4px 8px rgba(0, 0, 0, 0.03), 0 3px 6px rgba(0, 0, 0, 0.05), 0 6px 18px rgba(0, 0, 0, 0.03)',
37
+ opacity: '0',
38
+ transition: 'opacity 0.3s ease'
39
+ });
40
+ document.body.appendChild(toast);
41
+ requestAnimationFrame(()=>{
42
+ toast.style.opacity = '1';
43
+ });
44
+ setTimeout(()=>{
45
+ toast.style.opacity = '0';
46
+ setTimeout(()=>{
47
+ document.body.removeChild(toast);
48
+ resolve();
49
+ }, 300);
50
+ }, duration);
51
+ });
52
+ }
53
+ export { showToast };
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createClient } from "@lark-apaas/client-capability";
2
2
  import { normalizeBasePath } from "./utils/utils.js";
3
3
  import { logger } from "./logger/index.js";
4
+ import { showToast } from "./components/ui/toast.js";
4
5
  import { version } from "../package.json";
5
6
  const capabilityClient = createClient({
6
7
  baseURL: normalizeBasePath(process.env.CLIENT_BASE_PATH),
@@ -9,7 +10,10 @@ const capabilityClient = createClient({
9
10
  'X-Suda-Csrf-Token': window.csrfToken ?? ''
10
11
  }
11
12
  },
12
- logger: logger
13
+ logger: logger,
14
+ onRateLimitError: ()=>{
15
+ showToast('应用额度已耗尽,请联系应用开发者');
16
+ }
13
17
  });
14
18
  const src = {
15
19
  version: version
@@ -54,7 +54,7 @@ async function logResponse(ok, responseOrError) {
54
54
  logTraceID
55
55
  };
56
56
  if (stacktrace) logMeta.stacktrace = stacktrace;
57
- logger.debug({
57
+ logger.log({
58
58
  level: ok,
59
59
  args: [
60
60
  parts.join(''),
@@ -110,7 +110,7 @@ async function logResponse(ok, responseOrError) {
110
110
  const stacktrace = await requestStacktraceMap.get(requestUUID);
111
111
  const logMeta = {};
112
112
  if (stacktrace) logMeta.stacktrace = stacktrace;
113
- logger.debug({
113
+ logger.log({
114
114
  level: 'error',
115
115
  args: [
116
116
  parts.join(''),
@@ -120,7 +120,7 @@ async function logResponse(ok, responseOrError) {
120
120
  });
121
121
  return;
122
122
  }
123
- logger.debug({
123
+ logger.log({
124
124
  level: 'error',
125
125
  args: [
126
126
  '请求失败:无响应对象或配置信息'
@@ -234,6 +234,7 @@ function initAxiosConfig(axiosInstance) {
234
234
  config._startTime = config._startTime || Date.now();
235
235
  const csrfToken = window.csrfToken;
236
236
  if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
237
+ if ('undefined' != typeof window && window.location?.pathname) config.headers['X-Page-Route'] = window.location.pathname;
237
238
  return config;
238
239
  }, (error)=>Promise.reject(error));
239
240
  instance.interceptors.response.use((response)=>response, (error)=>{
@@ -241,8 +242,8 @@ function initAxiosConfig(axiosInstance) {
241
242
  if (error.response?.status === 403) {
242
243
  const method = (error.config?.method || 'GET').toUpperCase();
243
244
  const url = (error.config?.url || '').split('?')[0];
244
- logger.debug({
245
- level: 'warning',
245
+ logger.log({
246
+ level: 'warn',
246
247
  args: [
247
248
  `请求被拒绝(403):${method} ${url}`,
248
249
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -93,9 +93,9 @@
93
93
  "dependencies": {
94
94
  "@ant-design/colors": "^7.2.1",
95
95
  "@ant-design/cssinjs": "^1.24.0",
96
- "@data-loom/js": "0.4.4",
96
+ "@data-loom/js": "0.4.5",
97
97
  "@lark-apaas/auth-sdk": "^0.1.0",
98
- "@lark-apaas/client-capability": "^0.1.3",
98
+ "@lark-apaas/client-capability": "^0.1.4",
99
99
  "@lark-apaas/miaoda-inspector": "^1.0.14",
100
100
  "@lark-apaas/observable-web": "^1.0.1",
101
101
  "@radix-ui/react-avatar": "^1.1.10",