@lark-apaas/client-toolkit 1.1.35-alpha.0 → 1.1.35-alpha.10
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/index.js +2 -0
- package/lib/components/AppContainer/utils/observable.d.ts +1 -0
- package/lib/components/AppContainer/utils/observable.js +13 -0
- package/lib/hooks/useAppInfo.js +6 -6
- package/lib/logger/logger.js +19 -0
- package/lib/utils/safeStringify.d.ts +4 -0
- package/lib/utils/safeStringify.js +42 -0
- package/package.json +4 -3
|
@@ -17,8 +17,10 @@ import safety from "./safety.js";
|
|
|
17
17
|
import { getAppId } from "../../utils/getAppId.js";
|
|
18
18
|
import { ServerLogPoller } from "../../server-log/index.js";
|
|
19
19
|
import QueryProvider from "../QueryProvider/index.js";
|
|
20
|
+
import { initObservable } from "./utils/observable.js";
|
|
20
21
|
registerDayjsPlugins();
|
|
21
22
|
initAxiosConfig();
|
|
23
|
+
initObservable();
|
|
22
24
|
const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
|
|
23
25
|
const readCssVarColor = (varName, fallback)=>{
|
|
24
26
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initObservable: () => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AppEnv, observable } from "@lark-apaas/observable-web";
|
|
2
|
+
import { getAppId } from "../../../utils/getAppId.js";
|
|
3
|
+
const initObservable = ()=>{
|
|
4
|
+
observable.start({
|
|
5
|
+
serviceName: "app",
|
|
6
|
+
env: 'development' === process.env.NODE_ENV ? AppEnv.Dev : AppEnv.Prod,
|
|
7
|
+
collectorUrl: {
|
|
8
|
+
log: `/spark/app/${getAppId(window.location.pathname)}/runtime/api/v1/observability/logs/collect`,
|
|
9
|
+
metric: `/spark/app/${getAppId(window.location.pathname)}/runtime/api/v1/observability/metrics/collect`
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export { initObservable };
|
package/lib/hooks/useAppInfo.js
CHANGED
|
@@ -21,21 +21,21 @@ const useAppInfo = ()=>{
|
|
|
21
21
|
if (meta) meta.content = info.avatar;
|
|
22
22
|
}
|
|
23
23
|
if (info.description) {
|
|
24
|
-
const
|
|
25
|
-
if (ogMeta) ogMeta.content = info.description;
|
|
26
|
-
const meta = document.querySelector("meta[name='description']");
|
|
24
|
+
const meta = document.querySelector("meta[property='og:description']");
|
|
27
25
|
if (meta) meta.content = info.description;
|
|
26
|
+
const metaDom = document.querySelector("meta[name='description']");
|
|
27
|
+
if (metaDom) metaDom.content = info.description;
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
const handleMetaInfoChanged = async (info)=>{
|
|
31
|
-
if (!info) info = await getAppInfo(
|
|
30
|
+
const handleMetaInfoChanged = async (info, refresh = true)=>{
|
|
31
|
+
if (!info) info = await getAppInfo(refresh);
|
|
32
32
|
updateDomInfo(info);
|
|
33
33
|
setAppInfo((prev)=>({
|
|
34
34
|
...prev,
|
|
35
35
|
...info
|
|
36
36
|
}));
|
|
37
37
|
};
|
|
38
|
-
handleMetaInfoChanged();
|
|
38
|
+
handleMetaInfoChanged(null, false);
|
|
39
39
|
const onUpdate = (e)=>{
|
|
40
40
|
const info = e.detail;
|
|
41
41
|
handleMetaInfoChanged(info);
|
package/lib/logger/logger.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { observable } from "@lark-apaas/observable-web";
|
|
1
2
|
import { interceptors } from "./selected-logs.js";
|
|
2
3
|
import { interceptErrors } from "./intercept-global-error.js";
|
|
4
|
+
import { mapLogLevel, processLogParams } from "../utils/safeStringify.js";
|
|
3
5
|
const LOG_LEVELS = [
|
|
4
6
|
'debug',
|
|
5
7
|
'info',
|
|
@@ -45,18 +47,35 @@ let logger = {
|
|
|
45
47
|
},
|
|
46
48
|
info (message, ...args) {
|
|
47
49
|
if (shouldLog('info')) console.log(...getFormattedPrefix('info'), message, ...args);
|
|
50
|
+
if ('production' === process.env.NODE_ENV) observable.log('INFO', processLogParams([
|
|
51
|
+
message,
|
|
52
|
+
...args
|
|
53
|
+
]));
|
|
48
54
|
},
|
|
49
55
|
warn (message, ...args) {
|
|
50
56
|
if (shouldLog('warn')) console.log(...getFormattedPrefix('warn'), message, ...args);
|
|
57
|
+
if ('production' === process.env.NODE_ENV) observable.log('WARN', processLogParams([
|
|
58
|
+
message,
|
|
59
|
+
...args
|
|
60
|
+
]));
|
|
51
61
|
},
|
|
52
62
|
error (message, ...args) {
|
|
53
63
|
if (shouldLog('error')) console.error(...getFormattedPrefix('error'), message, ...args);
|
|
64
|
+
if ('production' === process.env.NODE_ENV) observable.log('ERROR', processLogParams([
|
|
65
|
+
message,
|
|
66
|
+
...args
|
|
67
|
+
]));
|
|
54
68
|
},
|
|
55
69
|
success (message, ...args) {
|
|
56
70
|
if (shouldLog('success')) console.log(...getFormattedPrefix('success'), message, ...args);
|
|
71
|
+
if ('production' === process.env.NODE_ENV) observable.log('INFO', processLogParams([
|
|
72
|
+
message,
|
|
73
|
+
...args
|
|
74
|
+
]));
|
|
57
75
|
},
|
|
58
76
|
log ({ level, args }) {
|
|
59
77
|
if (shouldLog(level)) console.log(...getFormattedPrefix(level), ...args);
|
|
78
|
+
if ('production' === process.env.NODE_ENV && "debug" !== level) observable.log(mapLogLevel(level), processLogParams(args));
|
|
60
79
|
}
|
|
61
80
|
};
|
|
62
81
|
if ('production' !== process.env.NODE_ENV) window.__RUNTIME_LOGGER__ = {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function safeStringify(obj) {
|
|
2
|
+
const seen = new Set();
|
|
3
|
+
try {
|
|
4
|
+
return JSON.stringify(obj, (key, value)=>{
|
|
5
|
+
if ('object' == typeof value && null !== value) {
|
|
6
|
+
if (seen.has(value)) return '[Circular]';
|
|
7
|
+
seen.add(value);
|
|
8
|
+
}
|
|
9
|
+
if ('bigint' == typeof value) return value.toString();
|
|
10
|
+
if (value instanceof Date) return value.toISOString();
|
|
11
|
+
if (value instanceof Map) return Object.fromEntries(value);
|
|
12
|
+
if (value instanceof Set) return Array.from(value);
|
|
13
|
+
if (void 0 === value) return 'undefined';
|
|
14
|
+
if ('symbol' == typeof value) return value.toString();
|
|
15
|
+
return value;
|
|
16
|
+
});
|
|
17
|
+
} catch {
|
|
18
|
+
return '';
|
|
19
|
+
} finally{
|
|
20
|
+
seen.clear();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function processLogParams(args) {
|
|
24
|
+
if (1 === args.length) return safeStringify(args[0]);
|
|
25
|
+
const obj = {};
|
|
26
|
+
for(let i = 0; i < args.length; i++)obj[i.toString()] = args[i];
|
|
27
|
+
return safeStringify(obj);
|
|
28
|
+
}
|
|
29
|
+
function mapLogLevel(level) {
|
|
30
|
+
switch(level){
|
|
31
|
+
case "error":
|
|
32
|
+
return "ERROR";
|
|
33
|
+
case "info":
|
|
34
|
+
case "success":
|
|
35
|
+
return "INFO";
|
|
36
|
+
case "warn":
|
|
37
|
+
return "WARN";
|
|
38
|
+
default:
|
|
39
|
+
return "INFO";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export { mapLogLevel, processLogParams, safeStringify };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.1.35-alpha.
|
|
3
|
+
"version": "1.1.35-alpha.10",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -81,7 +81,8 @@
|
|
|
81
81
|
"@ant-design/colors": "^7.2.1",
|
|
82
82
|
"@ant-design/cssinjs": "^1.24.0",
|
|
83
83
|
"@data-loom/js": "^0.4.3",
|
|
84
|
-
"@lark-apaas/miaoda-inspector": "^1.0.
|
|
84
|
+
"@lark-apaas/miaoda-inspector": "^1.0.8",
|
|
85
|
+
"@lark-apaas/observable-web": "^1.0.0-alpha.10",
|
|
85
86
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
86
87
|
"@radix-ui/react-popover": "^1.1.15",
|
|
87
88
|
"@radix-ui/react-slot": "^1.2.3",
|
|
@@ -155,4 +156,4 @@
|
|
|
155
156
|
"react-router-dom": ">=6.26.2",
|
|
156
157
|
"styled-jsx": ">=5.0.0"
|
|
157
158
|
}
|
|
158
|
-
}
|
|
159
|
+
}
|