@lark-apaas/client-toolkit 1.1.8 → 1.1.9
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/components/AppContainer/IframeBridge.d.ts +0 -1
- package/lib/components/AppContainer/IframeBridge.js +0 -1
- package/lib/components/NotFoundRender/index.js +10 -1
- package/lib/logger/intercept-global-error.d.ts +1 -1
- package/lib/logger/intercept-global-error.js +27 -2
- package/lib/logger/log-types.d.ts +10 -4
- package/lib/logger/log-types.js +12 -12
- package/lib/logger/logger.js +2 -2
- package/lib/logger/selected-logs.js +12 -5
- package/lib/utils/axiosConfig.js +12 -12
- package/package.json +1 -1
- package/lib/components/AppContainer/LogInterceptor.d.ts +0 -1
- package/lib/components/AppContainer/LogInterceptor.js +0 -66
|
@@ -7,7 +7,6 @@ import { postMessage } from "../../utils/postMessage.js";
|
|
|
7
7
|
import { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
|
|
8
8
|
import { childApi } from "./utils/childApi.js";
|
|
9
9
|
import "./utils/listenHot.js";
|
|
10
|
-
import "./LogInterceptor.js";
|
|
11
10
|
var IframeBridge_RouteMessageType = /*#__PURE__*/ function(RouteMessageType) {
|
|
12
11
|
RouteMessageType["RouteChange"] = "RouteChange";
|
|
13
12
|
RouteMessageType["RouteBack"] = "RouteBack";
|
|
@@ -9,7 +9,16 @@ const NotFound = ()=>{
|
|
|
9
9
|
const navigate = useNavigate();
|
|
10
10
|
const navigateRef = useUpdatingRef(navigate);
|
|
11
11
|
useEffect(()=>{
|
|
12
|
-
logger.
|
|
12
|
+
logger.log({
|
|
13
|
+
level: 'error',
|
|
14
|
+
args: [
|
|
15
|
+
`页面 ${location.pathname} 不存在`
|
|
16
|
+
],
|
|
17
|
+
meta: {
|
|
18
|
+
repairMessage: `页面 ${location.pathname} 不存在,帮我创建`,
|
|
19
|
+
noStacktrace: true
|
|
20
|
+
}
|
|
21
|
+
});
|
|
13
22
|
}, [
|
|
14
23
|
location.pathname
|
|
15
24
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function interceptErrors(): void;
|
|
@@ -1,10 +1,35 @@
|
|
|
1
|
+
import { levelSchema } from "./log-types.js";
|
|
1
2
|
import { logger } from "./logger.js";
|
|
2
|
-
function
|
|
3
|
+
function interceptErrors() {
|
|
3
4
|
window.addEventListener('error', (event)=>{
|
|
4
5
|
logger.error(event.error);
|
|
5
6
|
});
|
|
6
7
|
window.addEventListener('unhandledrejection', (event)=>{
|
|
7
8
|
logger.error(event.reason);
|
|
8
9
|
});
|
|
10
|
+
const PROXY_CONSOLE_METHOD = [
|
|
11
|
+
'log',
|
|
12
|
+
'info',
|
|
13
|
+
'warn',
|
|
14
|
+
'error'
|
|
15
|
+
];
|
|
16
|
+
PROXY_CONSOLE_METHOD.forEach((method)=>{
|
|
17
|
+
const originalMethod = window.console[method];
|
|
18
|
+
window.console[method] = (...args)=>{
|
|
19
|
+
originalMethod(...args);
|
|
20
|
+
const log = args[0];
|
|
21
|
+
if ('string' == typeof log && log.startsWith('[Dataloom]') && levelSchema.safeParse(method).success) {
|
|
22
|
+
logger.log({
|
|
23
|
+
level: method,
|
|
24
|
+
args
|
|
25
|
+
});
|
|
26
|
+
postMessage({
|
|
27
|
+
type: 'Console',
|
|
28
|
+
method,
|
|
29
|
+
data: args
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
9
34
|
}
|
|
10
|
-
export {
|
|
35
|
+
export { interceptErrors };
|
|
@@ -42,8 +42,10 @@ export declare const logMeta: z.ZodObject<{
|
|
|
42
42
|
}, z.core.$strip>>>;
|
|
43
43
|
logTraceID: z.ZodOptional<z.ZodString>;
|
|
44
44
|
skipFrame: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
noStacktrace: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
repairMessage: z.ZodOptional<z.ZodString>;
|
|
45
47
|
}, z.core.$strip>;
|
|
46
|
-
export declare const selectedLogSchema: z.
|
|
48
|
+
export declare const selectedLogSchema: z.ZodObject<{
|
|
47
49
|
type: z.ZodLiteral<"typedLogV2">;
|
|
48
50
|
level: z.ZodEnum<{
|
|
49
51
|
success: "success";
|
|
@@ -63,8 +65,10 @@ export declare const selectedLogSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
63
65
|
}, z.core.$strip>>>;
|
|
64
66
|
logTraceID: z.ZodOptional<z.ZodString>;
|
|
65
67
|
skipFrame: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
noStacktrace: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
+
repairMessage: z.ZodOptional<z.ZodString>;
|
|
66
70
|
}, z.core.$strip>;
|
|
67
|
-
}, z.core.$strip
|
|
71
|
+
}, z.core.$strip>;
|
|
68
72
|
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'success';
|
|
69
73
|
export declare const logWithMetaSchema: z.ZodObject<{
|
|
70
74
|
level: z.ZodEnum<{
|
|
@@ -75,7 +79,7 @@ export declare const logWithMetaSchema: z.ZodObject<{
|
|
|
75
79
|
debug: "debug";
|
|
76
80
|
}>;
|
|
77
81
|
args: z.ZodArray<z.ZodUnknown>;
|
|
78
|
-
meta: z.ZodObject<{
|
|
82
|
+
meta: z.ZodOptional<z.ZodObject<{
|
|
79
83
|
stacktrace: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
80
84
|
functionName: z.ZodString;
|
|
81
85
|
fileName: z.ZodString;
|
|
@@ -84,7 +88,9 @@ export declare const logWithMetaSchema: z.ZodObject<{
|
|
|
84
88
|
}, z.core.$strip>>>;
|
|
85
89
|
logTraceID: z.ZodOptional<z.ZodString>;
|
|
86
90
|
skipFrame: z.ZodOptional<z.ZodNumber>;
|
|
87
|
-
|
|
91
|
+
noStacktrace: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
repairMessage: z.ZodOptional<z.ZodString>;
|
|
93
|
+
}, z.core.$strip>>;
|
|
88
94
|
}, z.core.$strip>;
|
|
89
95
|
export type LogStackFrame = z.infer<typeof logStackFrameSchema>;
|
|
90
96
|
export type LogWithMeta = z.infer<typeof logWithMetaSchema>;
|
package/lib/logger/log-types.js
CHANGED
|
@@ -36,20 +36,20 @@ const levelSchema = zod["enum"]([
|
|
|
36
36
|
const logMeta = zod.object({
|
|
37
37
|
stacktrace: zod.optional(zod.array(logStackFrameSchema)),
|
|
38
38
|
logTraceID: zod.optional(zod.string()),
|
|
39
|
-
skipFrame: zod.optional(zod.number())
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
id: zod.string(),
|
|
46
|
-
args: zod.array(zod.unknown()),
|
|
47
|
-
meta: logMeta
|
|
48
|
-
})
|
|
49
|
-
]);
|
|
50
|
-
const logWithMetaSchema = zod.object({
|
|
39
|
+
skipFrame: zod.optional(zod.number()),
|
|
40
|
+
noStacktrace: zod.optional(zod.boolean()),
|
|
41
|
+
repairMessage: zod.optional(zod.string())
|
|
42
|
+
});
|
|
43
|
+
const selectedLogSchema = zod.object({
|
|
44
|
+
type: zod.literal('typedLogV2'),
|
|
51
45
|
level: levelSchema,
|
|
46
|
+
id: zod.string(),
|
|
52
47
|
args: zod.array(zod.unknown()),
|
|
53
48
|
meta: logMeta
|
|
54
49
|
});
|
|
50
|
+
const logWithMetaSchema = zod.object({
|
|
51
|
+
level: levelSchema,
|
|
52
|
+
args: zod.array(zod.unknown()),
|
|
53
|
+
meta: zod.optional(logMeta)
|
|
54
|
+
});
|
|
55
55
|
export { genericErrorSchema, levelSchema, logMeta, logStackFrameSchema, logWithMetaSchema, networkRequestLogSchema, noCategoryLogSchema, routerErrorSchema, selectedLogSchema };
|
package/lib/logger/logger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { interceptors } from "./selected-logs.js";
|
|
2
|
-
import {
|
|
2
|
+
import { interceptErrors } from "./intercept-global-error.js";
|
|
3
3
|
const LOG_LEVELS = [
|
|
4
4
|
'debug',
|
|
5
5
|
'info',
|
|
@@ -60,5 +60,5 @@ let logger = {
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
for (const interceptor of interceptors)logger = interceptor(logger);
|
|
63
|
-
|
|
63
|
+
'production' !== process.env.NODE_ENV && interceptErrors();
|
|
64
64
|
export { logger };
|
|
@@ -2,6 +2,7 @@ import { SourceMapConsumer as external_source_map_SourceMapConsumer } from "sour
|
|
|
2
2
|
import "../utils/utils.js";
|
|
3
3
|
import { mappingText } from "./source-map-mappings-wasm.js";
|
|
4
4
|
import stacktrace_js from "stacktrace-js";
|
|
5
|
+
import { batchLogInfo, initBatchLogger } from "./batch-logger.js";
|
|
5
6
|
function hexToBuffer(hexString) {
|
|
6
7
|
const hex = hexString.replace(/\s/g, '').toUpperCase();
|
|
7
8
|
if (!/^[0-9A-F]+$/.test(hex)) throw new Error('Invalid hex string');
|
|
@@ -36,20 +37,25 @@ async function sendSelectedLog(logWithoutID) {
|
|
|
36
37
|
message: error.message,
|
|
37
38
|
stack: error.stack
|
|
38
39
|
};
|
|
39
|
-
if (!log.meta.stacktrace) {
|
|
40
|
+
if (!log.meta.stacktrace) try {
|
|
40
41
|
const stacktrace = await stacktrace_js.fromError(error);
|
|
41
42
|
log.meta.stacktrace = mapStacktrace(stacktrace);
|
|
42
|
-
}
|
|
43
|
+
} catch (e) {}
|
|
43
44
|
newParts.push(newError.message, newError);
|
|
44
45
|
} else newParts.push(log.args[i]);
|
|
45
|
-
if (!log.meta.stacktrace) {
|
|
46
|
-
|
|
46
|
+
if (!log.meta.stacktrace) try {
|
|
47
|
+
let frames = await getStacktrace();
|
|
48
|
+
const firstFrameIndex = frames.findIndex((frame)=>!frame.fileName.includes('node_modules/@lark-apaas/client-toolkit/lib/logger'));
|
|
49
|
+
frames = -1 === firstFrameIndex ? [] : frames.slice(firstFrameIndex);
|
|
47
50
|
log.meta.stacktrace = frames;
|
|
48
|
-
}
|
|
51
|
+
} catch (e) {}
|
|
49
52
|
if (void 0 === log.meta.skipFrame) log.meta.skipFrame = 2;
|
|
50
53
|
const logJSON = JSON.stringify(log);
|
|
51
54
|
console.log(JSON.parse(logJSON));
|
|
52
55
|
console.log(logJSON);
|
|
56
|
+
try {
|
|
57
|
+
batchLogInfo('info', logJSON);
|
|
58
|
+
} catch (e) {}
|
|
53
59
|
if (window.parent !== window) try {
|
|
54
60
|
window.parent.postMessage({
|
|
55
61
|
type: 'SELECTED_LOG',
|
|
@@ -152,6 +158,7 @@ const typedLogInterceptor = (logger)=>({
|
|
|
152
158
|
});
|
|
153
159
|
}
|
|
154
160
|
});
|
|
161
|
+
'production' !== process.env.NODE_ENV && initBatchLogger(console);
|
|
155
162
|
const interceptors = 'production' !== process.env.NODE_ENV ? [
|
|
156
163
|
typedLogInterceptor
|
|
157
164
|
] : [];
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -3,27 +3,27 @@ import { logger } from "../apis/logger.js";
|
|
|
3
3
|
import { getStacktrace } from "../logger/selected-logs.js";
|
|
4
4
|
async function logResponse(ok, response) {
|
|
5
5
|
const okToTextMap = {
|
|
6
|
-
success: '
|
|
7
|
-
error: '
|
|
6
|
+
success: '请求成功:',
|
|
7
|
+
error: '请求失败:'
|
|
8
8
|
};
|
|
9
|
+
const realOK = 'success' === ok && response.status >= 200 && response.status < 300;
|
|
9
10
|
const parts = [
|
|
10
|
-
okToTextMap[
|
|
11
|
-
(response.config.url || '').split('?')[0],
|
|
11
|
+
okToTextMap[realOK ? 'success' : 'error'],
|
|
12
|
+
(response.config.url || '').split('?')[0].replace(/^\/spark\/p\/app_\w+/, ''),
|
|
12
13
|
' - ',
|
|
13
14
|
Date.now() - response.config._startTime,
|
|
14
15
|
'ms'
|
|
15
16
|
];
|
|
16
17
|
const logTraceID = response.headers['x-log-trace-id'];
|
|
17
18
|
const args = [
|
|
18
|
-
'请求参数:',
|
|
19
|
-
response.config.data,
|
|
20
|
-
'返回数据:',
|
|
21
|
-
response.data,
|
|
22
|
-
'请求摘要:',
|
|
23
19
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
'请求参数:': response.config.data,
|
|
21
|
+
'返回数据:': response.data,
|
|
22
|
+
'请求摘要:': {
|
|
23
|
+
TraceID: logTraceID,
|
|
24
|
+
状态: `${response.statusText}[状态码${response.status}]`,
|
|
25
|
+
时间: `${new Date().toLocaleString()}`
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
];
|
|
29
29
|
const requestUUID = response.config._requestUUID;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { batchLogInfo, destroyBatchLogger, initBatchLogger } from "../../logger/batch-logger.js";
|
|
2
|
-
import { postMessage } from "../../utils/postMessage.js";
|
|
3
|
-
const PROXY_CONSOLE_METHOD = [
|
|
4
|
-
'log',
|
|
5
|
-
'info',
|
|
6
|
-
'warn',
|
|
7
|
-
'error'
|
|
8
|
-
];
|
|
9
|
-
const LOG_FILTER_PREFIX = [
|
|
10
|
-
'[Dataloom]',
|
|
11
|
-
'[MiaoDa]'
|
|
12
|
-
];
|
|
13
|
-
function formatArg(arg) {
|
|
14
|
-
if (null === arg) return 'null';
|
|
15
|
-
if (void 0 === arg) return 'undefined';
|
|
16
|
-
if ('object' == typeof arg) {
|
|
17
|
-
if (arg instanceof Error) return `${arg.name}: ${arg.message}\n${arg.stack}`;
|
|
18
|
-
try {
|
|
19
|
-
return JSON.stringify(arg, this.getCircularReplacer(), 2);
|
|
20
|
-
} catch (e) {
|
|
21
|
-
return Object.prototype.toString.call(arg);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if ('function' == typeof arg) return arg.toString();
|
|
25
|
-
return String(arg);
|
|
26
|
-
}
|
|
27
|
-
const initHandleError = ()=>{
|
|
28
|
-
window.onerror = (message, source, lineno, colno, error)=>{
|
|
29
|
-
const errorList = [];
|
|
30
|
-
if (error) errorList.push(error);
|
|
31
|
-
else {
|
|
32
|
-
if ('string' == typeof message && [
|
|
33
|
-
'Script error.'
|
|
34
|
-
].includes(message)) return;
|
|
35
|
-
if (message) errorList.push(message);
|
|
36
|
-
else if (source) errorList.push(source);
|
|
37
|
-
}
|
|
38
|
-
console.error('[MiaoDa]', ...errorList);
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
const initLogInterceptor = ()=>{
|
|
42
|
-
initBatchLogger(console);
|
|
43
|
-
window.addEventListener('beforeunload', ()=>{
|
|
44
|
-
destroyBatchLogger();
|
|
45
|
-
});
|
|
46
|
-
PROXY_CONSOLE_METHOD.forEach((method)=>{
|
|
47
|
-
const originalMethod = window.console[method];
|
|
48
|
-
window.console[method] = (...args)=>{
|
|
49
|
-
originalMethod(...args);
|
|
50
|
-
const log = args[0];
|
|
51
|
-
if ('string' == typeof log && LOG_FILTER_PREFIX.some((prefix)=>log.startsWith(prefix))) {
|
|
52
|
-
batchLogInfo(method, args.map(formatArg).join(' '));
|
|
53
|
-
postMessage({
|
|
54
|
-
type: 'Console',
|
|
55
|
-
method,
|
|
56
|
-
data: args
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
function init() {
|
|
63
|
-
initHandleError();
|
|
64
|
-
initLogInterceptor();
|
|
65
|
-
}
|
|
66
|
-
'production' !== process.env.NODE_ENV && init();
|