@pisell/core 1.0.44 → 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 +24 -22
- 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 +3 -2
- 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
|
@@ -173,12 +173,12 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
173
173
|
});
|
|
174
174
|
console.log("---- 行为日志", logItem);
|
|
175
175
|
this.logBuffer.push(logItem);
|
|
176
|
-
if (log.type === "error") {
|
|
176
|
+
if (log.type === "error" || log.type === "warning") {
|
|
177
177
|
this.sendFeishuNotification(_objectSpread(_objectSpread({}, logItem || {}), {}, {
|
|
178
178
|
feishu: feishu
|
|
179
179
|
}));
|
|
180
180
|
// error 级别日志需要立即存储
|
|
181
|
-
this.storeLog(
|
|
181
|
+
this.storeLog(log.type === "error");
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -308,16 +308,18 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
308
308
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
309
309
|
while (1) switch (_context4.prev = _context4.next) {
|
|
310
310
|
case 0:
|
|
311
|
+
// 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
|
|
312
|
+
this.uploadIndexDBLog();
|
|
311
313
|
if (!(this.logBuffer.length === 0 || !this.db)) {
|
|
312
|
-
_context4.next =
|
|
314
|
+
_context4.next = 3;
|
|
313
315
|
break;
|
|
314
316
|
}
|
|
315
317
|
return _context4.abrupt("return");
|
|
316
|
-
case
|
|
317
|
-
_context4.prev =
|
|
318
|
-
_context4.next =
|
|
318
|
+
case 3:
|
|
319
|
+
_context4.prev = 3;
|
|
320
|
+
_context4.next = 6;
|
|
319
321
|
return this.createAWSFileName(urgent);
|
|
320
|
-
case
|
|
322
|
+
case 6:
|
|
321
323
|
fileName = _context4.sent;
|
|
322
324
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
323
325
|
|
|
@@ -330,35 +332,35 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
330
332
|
return item.logId;
|
|
331
333
|
});
|
|
332
334
|
logs = JSON.stringify(buffer, null, 2);
|
|
333
|
-
_context4.next =
|
|
335
|
+
_context4.next = 13;
|
|
334
336
|
return this.app.aws.upload({
|
|
335
337
|
Bucket: "",
|
|
336
338
|
Key: fileName,
|
|
337
339
|
Body: logs
|
|
338
340
|
});
|
|
339
|
-
case
|
|
341
|
+
case 13:
|
|
340
342
|
console.log("-------- 存储日志到AWS 成功");
|
|
341
343
|
// 上传成功后需要清空缓冲区,避免重复上传
|
|
342
344
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
343
345
|
return !bufferIds.includes(item.logId);
|
|
344
346
|
});
|
|
345
|
-
_context4.next =
|
|
347
|
+
_context4.next = 29;
|
|
346
348
|
break;
|
|
347
|
-
case
|
|
348
|
-
_context4.prev =
|
|
349
|
-
_context4.t0 = _context4["catch"](
|
|
349
|
+
case 17:
|
|
350
|
+
_context4.prev = 17;
|
|
351
|
+
_context4.t0 = _context4["catch"](3);
|
|
350
352
|
console.error("存储日志上传AWS失败:", _context4.t0);
|
|
351
353
|
|
|
352
354
|
// 将日志存储到IndexDB
|
|
353
|
-
_context4.prev =
|
|
354
|
-
_context4.next =
|
|
355
|
+
_context4.prev = 20;
|
|
356
|
+
_context4.next = 23;
|
|
355
357
|
return this.storeLogToIndexDB();
|
|
356
|
-
case
|
|
357
|
-
_context4.next =
|
|
358
|
+
case 23:
|
|
359
|
+
_context4.next = 29;
|
|
358
360
|
break;
|
|
359
|
-
case
|
|
360
|
-
_context4.prev =
|
|
361
|
-
_context4.t1 = _context4["catch"](
|
|
361
|
+
case 25:
|
|
362
|
+
_context4.prev = 25;
|
|
363
|
+
_context4.t1 = _context4["catch"](20);
|
|
362
364
|
this.sendFeishuNotification({
|
|
363
365
|
type: "error",
|
|
364
366
|
title: "存储日志到AWS失败",
|
|
@@ -376,11 +378,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
376
378
|
}
|
|
377
379
|
});
|
|
378
380
|
console.error("存储日志到IndexDB也失败:", _context4.t1);
|
|
379
|
-
case
|
|
381
|
+
case 29:
|
|
380
382
|
case "end":
|
|
381
383
|
return _context4.stop();
|
|
382
384
|
}
|
|
383
|
-
}, _callee4, this, [[
|
|
385
|
+
}, _callee4, this, [[3, 17], [20, 25]]);
|
|
384
386
|
}));
|
|
385
387
|
function storeLog(_x2) {
|
|
386
388
|
return _storeLog.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
|
@@ -127,9 +127,9 @@ var LoggerManager = class {
|
|
|
127
127
|
};
|
|
128
128
|
console.log("---- 行为日志", logItem);
|
|
129
129
|
this.logBuffer.push(logItem);
|
|
130
|
-
if (log.type === "error") {
|
|
130
|
+
if (log.type === "error" || log.type === "warning") {
|
|
131
131
|
this.sendFeishuNotification({ ...logItem || {}, feishu });
|
|
132
|
-
this.storeLog(
|
|
132
|
+
this.storeLog(log.type === "error");
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
@@ -211,6 +211,7 @@ var LoggerManager = class {
|
|
|
211
211
|
*/
|
|
212
212
|
async storeLog(urgent) {
|
|
213
213
|
var _a;
|
|
214
|
+
this.uploadIndexDBLog();
|
|
214
215
|
if (this.logBuffer.length === 0 || !this.db) {
|
|
215
216
|
return;
|
|
216
217
|
}
|
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;
|