@pisell/core 1.0.43 → 1.0.45
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/es/app/app.d.ts +1 -1
- package/es/history/index.d.ts +3 -4
- package/es/logger/index.js +35 -41
- package/es/models/index.d.ts +1 -2
- package/es/request/index.js +35 -1
- package/es/tasks/index.d.ts +1 -1
- package/lib/app/app.d.ts +1 -1
- package/lib/history/index.d.ts +3 -4
- package/lib/logger/index.js +5 -7
- package/lib/models/index.d.ts +1 -2
- package/lib/request/index.js +29 -1
- package/lib/tasks/index.d.ts +1 -1
- package/package.json +1 -1
package/es/app/app.d.ts
CHANGED
package/es/history/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LocationDescriptor } from "history";
|
|
2
2
|
import type { History as HistoryType } from "history";
|
|
3
|
-
import { useHistory, useLocation, useParams } from "react-router-dom";
|
|
4
3
|
import App from "../app";
|
|
5
4
|
export interface HistoryOptions {
|
|
6
5
|
basename?: string;
|
|
@@ -8,9 +7,9 @@ export interface HistoryOptions {
|
|
|
8
7
|
}
|
|
9
8
|
export declare class History {
|
|
10
9
|
instance: HistoryType<unknown>;
|
|
11
|
-
useHistory:
|
|
12
|
-
useLocation:
|
|
13
|
-
useParams:
|
|
10
|
+
useHistory: any;
|
|
11
|
+
useLocation: any;
|
|
12
|
+
useParams: any;
|
|
14
13
|
app: App;
|
|
15
14
|
interceptor?: (path: LocationDescriptor<unknown>, state: unknown, next: () => void) => void;
|
|
16
15
|
constructor(app: App, options?: HistoryOptions);
|
package/es/logger/index.js
CHANGED
|
@@ -73,23 +73,12 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
73
73
|
this.setStatus("running");
|
|
74
74
|
this.initTimer();
|
|
75
75
|
// 定期清理旧日志
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
case 4:
|
|
79
|
-
_context.prev = 4;
|
|
80
|
-
_context.next = 7;
|
|
81
|
-
return this.uploadIndexDBLog();
|
|
82
|
-
case 7:
|
|
83
|
-
_context.next = 11;
|
|
84
|
-
break;
|
|
85
|
-
case 9:
|
|
86
|
-
_context.prev = 9;
|
|
87
|
-
_context.t0 = _context["catch"](4);
|
|
88
|
-
case 11:
|
|
76
|
+
this.cleanupOldLogs();
|
|
77
|
+
case 3:
|
|
89
78
|
case "end":
|
|
90
79
|
return _context.stop();
|
|
91
80
|
}
|
|
92
|
-
}, _callee, this
|
|
81
|
+
}, _callee, this);
|
|
93
82
|
}));
|
|
94
83
|
function init() {
|
|
95
84
|
return _init.apply(this, arguments);
|
|
@@ -184,12 +173,12 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
184
173
|
});
|
|
185
174
|
console.log("---- 行为日志", logItem);
|
|
186
175
|
this.logBuffer.push(logItem);
|
|
187
|
-
if (log.type === "error") {
|
|
176
|
+
if (log.type === "error" || log.type === "warning") {
|
|
188
177
|
this.sendFeishuNotification(_objectSpread(_objectSpread({}, logItem || {}), {}, {
|
|
189
178
|
feishu: feishu
|
|
190
179
|
}));
|
|
191
180
|
// error 级别日志需要立即存储
|
|
192
|
-
this.storeLog(
|
|
181
|
+
this.storeLog(log.type === "error");
|
|
193
182
|
}
|
|
194
183
|
}
|
|
195
184
|
|
|
@@ -319,16 +308,18 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
319
308
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
320
309
|
while (1) switch (_context4.prev = _context4.next) {
|
|
321
310
|
case 0:
|
|
311
|
+
// 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
|
|
312
|
+
this.uploadIndexDBLog();
|
|
322
313
|
if (!(this.logBuffer.length === 0 || !this.db)) {
|
|
323
|
-
_context4.next =
|
|
314
|
+
_context4.next = 3;
|
|
324
315
|
break;
|
|
325
316
|
}
|
|
326
317
|
return _context4.abrupt("return");
|
|
327
|
-
case
|
|
328
|
-
_context4.prev =
|
|
329
|
-
_context4.next =
|
|
318
|
+
case 3:
|
|
319
|
+
_context4.prev = 3;
|
|
320
|
+
_context4.next = 6;
|
|
330
321
|
return this.createAWSFileName(urgent);
|
|
331
|
-
case
|
|
322
|
+
case 6:
|
|
332
323
|
fileName = _context4.sent;
|
|
333
324
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
334
325
|
|
|
@@ -341,35 +332,35 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
341
332
|
return item.logId;
|
|
342
333
|
});
|
|
343
334
|
logs = JSON.stringify(buffer, null, 2);
|
|
344
|
-
_context4.next =
|
|
335
|
+
_context4.next = 13;
|
|
345
336
|
return this.app.aws.upload({
|
|
346
337
|
Bucket: "",
|
|
347
338
|
Key: fileName,
|
|
348
339
|
Body: logs
|
|
349
340
|
});
|
|
350
|
-
case
|
|
341
|
+
case 13:
|
|
351
342
|
console.log("-------- 存储日志到AWS 成功");
|
|
352
343
|
// 上传成功后需要清空缓冲区,避免重复上传
|
|
353
344
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
354
345
|
return !bufferIds.includes(item.logId);
|
|
355
346
|
});
|
|
356
|
-
_context4.next =
|
|
347
|
+
_context4.next = 29;
|
|
357
348
|
break;
|
|
358
|
-
case
|
|
359
|
-
_context4.prev =
|
|
360
|
-
_context4.t0 = _context4["catch"](
|
|
349
|
+
case 17:
|
|
350
|
+
_context4.prev = 17;
|
|
351
|
+
_context4.t0 = _context4["catch"](3);
|
|
361
352
|
console.error("存储日志上传AWS失败:", _context4.t0);
|
|
362
353
|
|
|
363
354
|
// 将日志存储到IndexDB
|
|
364
|
-
_context4.prev =
|
|
365
|
-
_context4.next =
|
|
355
|
+
_context4.prev = 20;
|
|
356
|
+
_context4.next = 23;
|
|
366
357
|
return this.storeLogToIndexDB();
|
|
367
|
-
case
|
|
368
|
-
_context4.next =
|
|
358
|
+
case 23:
|
|
359
|
+
_context4.next = 29;
|
|
369
360
|
break;
|
|
370
|
-
case
|
|
371
|
-
_context4.prev =
|
|
372
|
-
_context4.t1 = _context4["catch"](
|
|
361
|
+
case 25:
|
|
362
|
+
_context4.prev = 25;
|
|
363
|
+
_context4.t1 = _context4["catch"](20);
|
|
373
364
|
this.sendFeishuNotification({
|
|
374
365
|
type: "error",
|
|
375
366
|
title: "存储日志到AWS失败",
|
|
@@ -387,11 +378,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
387
378
|
}
|
|
388
379
|
});
|
|
389
380
|
console.error("存储日志到IndexDB也失败:", _context4.t1);
|
|
390
|
-
case
|
|
381
|
+
case 29:
|
|
391
382
|
case "end":
|
|
392
383
|
return _context4.stop();
|
|
393
384
|
}
|
|
394
|
-
}, _callee4, this, [[
|
|
385
|
+
}, _callee4, this, [[3, 17], [20, 25]]);
|
|
395
386
|
}));
|
|
396
387
|
function storeLog(_x2) {
|
|
397
388
|
return _storeLog.apply(this, arguments);
|
|
@@ -591,17 +582,20 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
591
582
|
if (filesToDelete.length > 0) {
|
|
592
583
|
console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
|
|
593
584
|
}
|
|
594
|
-
|
|
585
|
+
|
|
586
|
+
// 清理完成后,将IndexDB中的日志上传到AWS
|
|
587
|
+
this.uploadIndexDBLog();
|
|
588
|
+
_context7.next = 34;
|
|
595
589
|
break;
|
|
596
|
-
case
|
|
597
|
-
_context7.prev =
|
|
590
|
+
case 31:
|
|
591
|
+
_context7.prev = 31;
|
|
598
592
|
_context7.t1 = _context7["catch"](2);
|
|
599
593
|
console.error("清理旧日志失败:", _context7.t1);
|
|
600
|
-
case
|
|
594
|
+
case 34:
|
|
601
595
|
case "end":
|
|
602
596
|
return _context7.stop();
|
|
603
597
|
}
|
|
604
|
-
}, _callee7, this, [[2,
|
|
598
|
+
}, _callee7, this, [[2, 31], [10, 21, 24, 27]]);
|
|
605
599
|
}));
|
|
606
600
|
function cleanupOldLogs() {
|
|
607
601
|
return _cleanupOldLogs.apply(this, arguments);
|
package/es/models/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import hooks from '../hooks';
|
|
2
|
-
import { Provider as StoreProvider } from "react-redux";
|
|
3
2
|
declare const models: import("./global").GlobalModal[];
|
|
4
3
|
declare type ModalsType = (typeof models[number]);
|
|
5
4
|
export interface Store {
|
|
@@ -39,7 +38,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
|
|
|
39
38
|
declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
|
|
40
39
|
declare const _default: {
|
|
41
40
|
getStore: () => Store;
|
|
42
|
-
StoreProvider:
|
|
41
|
+
StoreProvider: any;
|
|
43
42
|
setConfig: (models: any[]) => void;
|
|
44
43
|
};
|
|
45
44
|
export default _default;
|
package/es/request/index.js
CHANGED
|
@@ -25,17 +25,50 @@ axiosInstance.interceptors.response.use(interceptorsResponse, interceptorsRespon
|
|
|
25
25
|
export var createRequest = function createRequest(props) {
|
|
26
26
|
var data = props.data,
|
|
27
27
|
config = props.config,
|
|
28
|
-
method = props.method
|
|
28
|
+
method = props.method,
|
|
29
|
+
url = props.url;
|
|
29
30
|
var _getConfig = getConfig(),
|
|
30
31
|
getUrl = _getConfig.getUrl;
|
|
32
|
+
var startTime = Date.now(); // 记录请求开始时间
|
|
33
|
+
|
|
31
34
|
return new Promise(function (resolve, reject) {
|
|
32
35
|
var _method = method === "remove" ? "delete" : method;
|
|
33
36
|
var _url = getUrl === null || getUrl === void 0 ? void 0 : getUrl(props);
|
|
37
|
+
|
|
38
|
+
// 请求完成处理函数
|
|
39
|
+
var handleRequestComplete = function handleRequestComplete(result) {
|
|
40
|
+
var isError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
41
|
+
try {
|
|
42
|
+
var endTime = Date.now();
|
|
43
|
+
var duration = endTime - startTime;
|
|
44
|
+
|
|
45
|
+
// 如果请求超过5秒,触发日志报警
|
|
46
|
+
if (duration > 5000) {
|
|
47
|
+
var app = getApp();
|
|
48
|
+
if (app !== null && app !== void 0 && app.logger) {
|
|
49
|
+
app.logger.addLog({
|
|
50
|
+
type: 'warning',
|
|
51
|
+
title: '请求响应超过5秒',
|
|
52
|
+
metadata: {
|
|
53
|
+
url: _url || url,
|
|
54
|
+
data: data,
|
|
55
|
+
method: _method,
|
|
56
|
+
duration: "".concat((duration / 1000).toFixed(2), "s"),
|
|
57
|
+
timestamp: new Date(startTime).toISOString(),
|
|
58
|
+
isError: isError
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {}
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
34
66
|
axiosInstance[_method](_url, ["post", "put"].includes(_method) ? data : _objectSpread({
|
|
35
67
|
params: data
|
|
36
68
|
}, config), _objectSpread({
|
|
37
69
|
params: !["post", "put"].includes(_method) ? data : null
|
|
38
70
|
}, config)).then(function (res) {
|
|
71
|
+
handleRequestComplete(res, false);
|
|
39
72
|
requestCallback({
|
|
40
73
|
res: res,
|
|
41
74
|
reject: reject,
|
|
@@ -43,6 +76,7 @@ export var createRequest = function createRequest(props) {
|
|
|
43
76
|
props: props
|
|
44
77
|
});
|
|
45
78
|
}).catch(function (err) {
|
|
79
|
+
handleRequestComplete(err, true);
|
|
46
80
|
requestCallback({
|
|
47
81
|
err: err,
|
|
48
82
|
reject: reject,
|
package/es/tasks/index.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export declare class TasksManager {
|
|
|
108
108
|
*/
|
|
109
109
|
getQueueStatus(module: string, queueId: string): {
|
|
110
110
|
isRunning: boolean;
|
|
111
|
-
status: "
|
|
111
|
+
status: "completed" | "uncompleted";
|
|
112
112
|
progress: {
|
|
113
113
|
total: number;
|
|
114
114
|
completed: number;
|
package/lib/app/app.d.ts
CHANGED
package/lib/history/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LocationDescriptor } from "history";
|
|
2
2
|
import type { History as HistoryType } from "history";
|
|
3
|
-
import { useHistory, useLocation, useParams } from "react-router-dom";
|
|
4
3
|
import App from "../app";
|
|
5
4
|
export interface HistoryOptions {
|
|
6
5
|
basename?: string;
|
|
@@ -8,9 +7,9 @@ export interface HistoryOptions {
|
|
|
8
7
|
}
|
|
9
8
|
export declare class History {
|
|
10
9
|
instance: HistoryType<unknown>;
|
|
11
|
-
useHistory:
|
|
12
|
-
useLocation:
|
|
13
|
-
useParams:
|
|
10
|
+
useHistory: any;
|
|
11
|
+
useLocation: any;
|
|
12
|
+
useParams: any;
|
|
14
13
|
app: App;
|
|
15
14
|
interceptor?: (path: LocationDescriptor<unknown>, state: unknown, next: () => void) => void;
|
|
16
15
|
constructor(app: App, options?: HistoryOptions);
|
package/lib/logger/index.js
CHANGED
|
@@ -70,11 +70,7 @@ var LoggerManager = class {
|
|
|
70
70
|
async init() {
|
|
71
71
|
this.setStatus("running");
|
|
72
72
|
this.initTimer();
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
await this.uploadIndexDBLog();
|
|
76
|
-
} catch (error) {
|
|
77
|
-
}
|
|
73
|
+
this.cleanupOldLogs();
|
|
78
74
|
}
|
|
79
75
|
/**
|
|
80
76
|
* 初始化 IndexDB
|
|
@@ -131,9 +127,9 @@ var LoggerManager = class {
|
|
|
131
127
|
};
|
|
132
128
|
console.log("---- 行为日志", logItem);
|
|
133
129
|
this.logBuffer.push(logItem);
|
|
134
|
-
if (log.type === "error") {
|
|
130
|
+
if (log.type === "error" || log.type === "warning") {
|
|
135
131
|
this.sendFeishuNotification({ ...logItem || {}, feishu });
|
|
136
|
-
this.storeLog(
|
|
132
|
+
this.storeLog(log.type === "error");
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
/**
|
|
@@ -215,6 +211,7 @@ var LoggerManager = class {
|
|
|
215
211
|
*/
|
|
216
212
|
async storeLog(urgent) {
|
|
217
213
|
var _a;
|
|
214
|
+
this.uploadIndexDBLog();
|
|
218
215
|
if (this.logBuffer.length === 0 || !this.db) {
|
|
219
216
|
return;
|
|
220
217
|
}
|
|
@@ -327,6 +324,7 @@ var LoggerManager = class {
|
|
|
327
324
|
if (filesToDelete.length > 0) {
|
|
328
325
|
console.log(`-------- 共清理 ${filesToDelete.length} 个旧日志文件`);
|
|
329
326
|
}
|
|
327
|
+
this.uploadIndexDBLog();
|
|
330
328
|
} catch (error) {
|
|
331
329
|
console.error("清理旧日志失败:", error);
|
|
332
330
|
}
|
package/lib/models/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import hooks from '../hooks';
|
|
2
|
-
import { Provider as StoreProvider } from "react-redux";
|
|
3
2
|
declare const models: import("./global").GlobalModal[];
|
|
4
3
|
declare type ModalsType = (typeof models[number]);
|
|
5
4
|
export interface Store {
|
|
@@ -39,7 +38,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
|
|
|
39
38
|
declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
|
|
40
39
|
declare const _default: {
|
|
41
40
|
getStore: () => Store;
|
|
42
|
-
StoreProvider:
|
|
41
|
+
StoreProvider: any;
|
|
43
42
|
setConfig: (models: any[]) => void;
|
|
44
43
|
};
|
|
45
44
|
export default _default;
|
package/lib/request/index.js
CHANGED
|
@@ -52,11 +52,37 @@ var axiosInstance = import_axios.default.create(import_constants.axiosConfig);
|
|
|
52
52
|
axiosInstance.interceptors.request.use(import_utils.interceptorsRequest, import_utils.interceptorsRequestError);
|
|
53
53
|
axiosInstance.interceptors.response.use(import_utils.interceptorsResponse, import_utils.interceptorsResponseError);
|
|
54
54
|
var createRequest = (props) => {
|
|
55
|
-
const { data, config, method } = props;
|
|
55
|
+
const { data, config, method, url } = props;
|
|
56
56
|
const { getUrl } = (0, import_config.getConfig)();
|
|
57
|
+
const startTime = Date.now();
|
|
57
58
|
return new Promise((resolve, reject) => {
|
|
58
59
|
const _method = method === "remove" ? "delete" : method;
|
|
59
60
|
let _url = getUrl == null ? void 0 : getUrl(props);
|
|
61
|
+
const handleRequestComplete = (result, isError = false) => {
|
|
62
|
+
try {
|
|
63
|
+
const endTime = Date.now();
|
|
64
|
+
const duration = endTime - startTime;
|
|
65
|
+
if (duration > 5e3) {
|
|
66
|
+
const app = (0, import_app.getApp)();
|
|
67
|
+
if (app == null ? void 0 : app.logger) {
|
|
68
|
+
app.logger.addLog({
|
|
69
|
+
type: "warning",
|
|
70
|
+
title: "请求响应超过5秒",
|
|
71
|
+
metadata: {
|
|
72
|
+
url: _url || url,
|
|
73
|
+
data,
|
|
74
|
+
method: _method,
|
|
75
|
+
duration: `${(duration / 1e3).toFixed(2)}s`,
|
|
76
|
+
timestamp: new Date(startTime).toISOString(),
|
|
77
|
+
isError
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
60
86
|
axiosInstance[_method](
|
|
61
87
|
_url,
|
|
62
88
|
["post", "put"].includes(_method) ? data : {
|
|
@@ -68,8 +94,10 @@ var createRequest = (props) => {
|
|
|
68
94
|
...config
|
|
69
95
|
}
|
|
70
96
|
).then((res) => {
|
|
97
|
+
handleRequestComplete(res, false);
|
|
71
98
|
(0, import_utils.requestCallback)({ res, reject, resolve, props });
|
|
72
99
|
}).catch((err) => {
|
|
100
|
+
handleRequestComplete(err, true);
|
|
73
101
|
(0, import_utils.requestCallback)({ err, reject, resolve, props });
|
|
74
102
|
});
|
|
75
103
|
});
|
package/lib/tasks/index.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export declare class TasksManager {
|
|
|
108
108
|
*/
|
|
109
109
|
getQueueStatus(module: string, queueId: string): {
|
|
110
110
|
isRunning: boolean;
|
|
111
|
-
status: "
|
|
111
|
+
status: "completed" | "uncompleted";
|
|
112
112
|
progress: {
|
|
113
113
|
total: number;
|
|
114
114
|
completed: number;
|