@lark-apaas/client-toolkit 1.2.28-alpha.66 → 1.2.28-alpha.68
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/auth.d.ts +1 -2
- package/lib/auth.js +2 -2
- package/lib/components/AppContainer/index.js +28 -8
- package/lib/utils/axiosConfig.js +25 -2
- package/lib/utils/safeStringify.js +5 -0
- package/lib/utils/safeStringify.spec.d.ts +1 -0
- package/lib/utils/safeStringify.spec.js +125 -0
- package/package.json +5 -5
package/lib/auth.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { AuthProviderProps, PermissionApiResponse, PermissionApiConfig, PermissionPointData, AuthSdkConfig, } from '@lark-apaas/auth-sdk';
|
|
1
|
+
export { CanRole, AbilityContext, ROLE_SUBJECT, useAuth, } from '@lark-apaas/auth-sdk';
|
package/lib/auth.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AbilityContext,
|
|
2
|
-
export { AbilityContext,
|
|
1
|
+
import { AbilityContext, CanRole, ROLE_SUBJECT, useAuth } from "@lark-apaas/auth-sdk";
|
|
2
|
+
export { AbilityContext, CanRole, ROLE_SUBJECT, useAuth };
|
|
@@ -9,6 +9,7 @@ import { PageHoc } from "./PageHoc.js";
|
|
|
9
9
|
import { reportTeaEvent } from "./utils/tea.js";
|
|
10
10
|
import { useAppInfo } from "../../hooks/index.js";
|
|
11
11
|
import { TrackKey } from "../../types/tea.js";
|
|
12
|
+
import { slardar } from "@lark-apaas/internal-slardar";
|
|
12
13
|
import safety from "./safety.js";
|
|
13
14
|
import { getAppId } from "../../utils/getAppId.js";
|
|
14
15
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
@@ -38,14 +39,33 @@ const App = (props)=>{
|
|
|
38
39
|
});
|
|
39
40
|
}, []);
|
|
40
41
|
useEffect(()=>{
|
|
41
|
-
if ('production' === process.env.NODE_ENV)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if ('production' === process.env.NODE_ENV) {
|
|
43
|
+
reportTeaEvent({
|
|
44
|
+
trackKey: TrackKey.VIEW,
|
|
45
|
+
trackParams: {
|
|
46
|
+
artifact_uid: getAppId(),
|
|
47
|
+
agent_id: 'agent_miaoda',
|
|
48
|
+
url: window.location.href
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const appId = getAppId();
|
|
52
|
+
const firstRenderTime = Math.round(performance.now());
|
|
53
|
+
const navEntry = performance.getEntriesByType('navigation')[0];
|
|
54
|
+
const pageLoadTime = navEntry && navEntry.loadEventEnd > 0 ? Math.round(navEntry.loadEventEnd - navEntry.startTime) : void 0;
|
|
55
|
+
slardar.sendEvent({
|
|
56
|
+
name: 'app-first-render',
|
|
57
|
+
metrics: {
|
|
58
|
+
firstRenderTime,
|
|
59
|
+
...null != pageLoadTime ? {
|
|
60
|
+
pageLoadTime
|
|
61
|
+
} : {}
|
|
62
|
+
},
|
|
63
|
+
categories: {
|
|
64
|
+
appId: appId ?? 'unknown',
|
|
65
|
+
mode: isMiaodaPreview ? 'preview' : 'runtime'
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
49
69
|
}, []);
|
|
50
70
|
const appId = getAppId();
|
|
51
71
|
const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -372,7 +372,18 @@ function initAxiosConfig(axiosInstance) {
|
|
|
372
372
|
name: 'toolkit_axios_403_downgrade',
|
|
373
373
|
categories: {
|
|
374
374
|
url: String(error.config?.url || ''),
|
|
375
|
-
method: String(error.config?.method || '')
|
|
375
|
+
method: String(error.config?.method || ''),
|
|
376
|
+
...'production' !== process.env.NODE_ENV && {
|
|
377
|
+
responseData: (()=>{
|
|
378
|
+
try {
|
|
379
|
+
const data = error.response?.data;
|
|
380
|
+
if (!data) return '';
|
|
381
|
+
return 'string' == typeof data ? data.slice(0, 512) : JSON.stringify(data).slice(0, 512);
|
|
382
|
+
} catch {
|
|
383
|
+
return '';
|
|
384
|
+
}
|
|
385
|
+
})()
|
|
386
|
+
}
|
|
376
387
|
}
|
|
377
388
|
});
|
|
378
389
|
return error.response;
|
|
@@ -383,7 +394,19 @@ function initAxiosConfig(axiosInstance) {
|
|
|
383
394
|
categories: {
|
|
384
395
|
url: String(error.config?.url || ''),
|
|
385
396
|
method: String(error.config?.method || ''),
|
|
386
|
-
status: String(error.response?.status || '')
|
|
397
|
+
status: String(error.response?.status || ''),
|
|
398
|
+
...'production' !== process.env.NODE_ENV && {
|
|
399
|
+
errorMessage: String(error.message || ''),
|
|
400
|
+
responseData: (()=>{
|
|
401
|
+
try {
|
|
402
|
+
const data = error.response?.data;
|
|
403
|
+
if (!data) return '';
|
|
404
|
+
return 'string' == typeof data ? data.slice(0, 512) : JSON.stringify(data).slice(0, 512);
|
|
405
|
+
} catch {
|
|
406
|
+
return '';
|
|
407
|
+
}
|
|
408
|
+
})()
|
|
409
|
+
}
|
|
387
410
|
}
|
|
388
411
|
});
|
|
389
412
|
return Promise.reject(error);
|
|
@@ -12,6 +12,11 @@ function safeStringify(obj) {
|
|
|
12
12
|
if (value instanceof Set) return Array.from(value);
|
|
13
13
|
if (void 0 === value) return 'undefined';
|
|
14
14
|
if ('symbol' == typeof value) return value.toString();
|
|
15
|
+
if (value instanceof Error) return {
|
|
16
|
+
name: value.name,
|
|
17
|
+
message: value.message,
|
|
18
|
+
stack: value.stack
|
|
19
|
+
};
|
|
15
20
|
return value;
|
|
16
21
|
});
|
|
17
22
|
} catch {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { mapLogLevel, processLogParams, safeStringify } from "./safeStringify.js";
|
|
3
|
+
describe('safeStringify', ()=>{
|
|
4
|
+
it('should serialize a plain string', ()=>{
|
|
5
|
+
expect(safeStringify('hello')).toBe('"hello"');
|
|
6
|
+
});
|
|
7
|
+
it('should serialize a plain object', ()=>{
|
|
8
|
+
expect(safeStringify({
|
|
9
|
+
a: 1
|
|
10
|
+
})).toBe('{"a":1}');
|
|
11
|
+
});
|
|
12
|
+
it('should handle circular references', ()=>{
|
|
13
|
+
const obj = {
|
|
14
|
+
a: 1
|
|
15
|
+
};
|
|
16
|
+
obj.self = obj;
|
|
17
|
+
expect(safeStringify(obj)).toBe('{"a":1,"self":"[Circular]"}');
|
|
18
|
+
});
|
|
19
|
+
it('should serialize BigInt as string', ()=>{
|
|
20
|
+
expect(safeStringify(BigInt(123))).toBe('"123"');
|
|
21
|
+
});
|
|
22
|
+
it('should serialize Date as ISO string', ()=>{
|
|
23
|
+
const date = new Date('2024-01-01T00:00:00.000Z');
|
|
24
|
+
expect(safeStringify(date)).toBe('"2024-01-01T00:00:00.000Z"');
|
|
25
|
+
});
|
|
26
|
+
it('should serialize Map as object', ()=>{
|
|
27
|
+
const map = new Map([
|
|
28
|
+
[
|
|
29
|
+
'key',
|
|
30
|
+
'value'
|
|
31
|
+
]
|
|
32
|
+
]);
|
|
33
|
+
expect(safeStringify(map)).toBe('{"key":"value"}');
|
|
34
|
+
});
|
|
35
|
+
it('should serialize Set as array', ()=>{
|
|
36
|
+
const set = new Set([
|
|
37
|
+
1,
|
|
38
|
+
2,
|
|
39
|
+
3
|
|
40
|
+
]);
|
|
41
|
+
expect(safeStringify(set)).toBe('[1,2,3]');
|
|
42
|
+
});
|
|
43
|
+
it('should serialize undefined as string', ()=>{
|
|
44
|
+
expect(safeStringify({
|
|
45
|
+
a: void 0
|
|
46
|
+
})).toBe('{"a":"undefined"}');
|
|
47
|
+
});
|
|
48
|
+
it('should serialize Symbol as string', ()=>{
|
|
49
|
+
expect(safeStringify({
|
|
50
|
+
s: Symbol('test')
|
|
51
|
+
})).toBe('{"s":"Symbol(test)"}');
|
|
52
|
+
});
|
|
53
|
+
it('should serialize Error with name, message and stack', ()=>{
|
|
54
|
+
const err = new Error('something went wrong');
|
|
55
|
+
const result = JSON.parse(safeStringify(err));
|
|
56
|
+
expect(result.name).toBe('Error');
|
|
57
|
+
expect(result.message).toBe('something went wrong');
|
|
58
|
+
expect(result.stack).toContain('something went wrong');
|
|
59
|
+
});
|
|
60
|
+
it('should serialize Error subclass with correct name', ()=>{
|
|
61
|
+
const err = new TypeError('bad type');
|
|
62
|
+
const result = JSON.parse(safeStringify(err));
|
|
63
|
+
expect(result.name).toBe('TypeError');
|
|
64
|
+
expect(result.message).toBe('bad type');
|
|
65
|
+
});
|
|
66
|
+
it('should serialize Error nested in object', ()=>{
|
|
67
|
+
const err = new Error('inner error');
|
|
68
|
+
const result = JSON.parse(safeStringify({
|
|
69
|
+
err
|
|
70
|
+
}));
|
|
71
|
+
expect(result.err.name).toBe('Error');
|
|
72
|
+
expect(result.err.message).toBe('inner error');
|
|
73
|
+
});
|
|
74
|
+
it('should return empty string on unexpected failure', ()=>{
|
|
75
|
+
const bad = {
|
|
76
|
+
toJSON () {
|
|
77
|
+
throw new Error('fail');
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
expect(safeStringify(bad)).toBe('');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('processLogParams', ()=>{
|
|
84
|
+
it('should serialize single argument directly', ()=>{
|
|
85
|
+
expect(processLogParams([
|
|
86
|
+
'hello'
|
|
87
|
+
])).toBe('"hello"');
|
|
88
|
+
});
|
|
89
|
+
it('should serialize single object argument', ()=>{
|
|
90
|
+
expect(processLogParams([
|
|
91
|
+
{
|
|
92
|
+
a: 1
|
|
93
|
+
}
|
|
94
|
+
])).toBe('{"a":1}');
|
|
95
|
+
});
|
|
96
|
+
it('should serialize multiple arguments as indexed object', ()=>{
|
|
97
|
+
const result = JSON.parse(processLogParams([
|
|
98
|
+
'msg',
|
|
99
|
+
{
|
|
100
|
+
key: 'val'
|
|
101
|
+
}
|
|
102
|
+
]));
|
|
103
|
+
expect(result['0']).toBe('msg');
|
|
104
|
+
expect(result['1']).toEqual({
|
|
105
|
+
key: 'val'
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe('mapLogLevel', ()=>{
|
|
110
|
+
it('should map error to ERROR', ()=>{
|
|
111
|
+
expect(mapLogLevel('error')).toBe('ERROR');
|
|
112
|
+
});
|
|
113
|
+
it('should map info to INFO', ()=>{
|
|
114
|
+
expect(mapLogLevel('info')).toBe('INFO');
|
|
115
|
+
});
|
|
116
|
+
it('should map success to INFO', ()=>{
|
|
117
|
+
expect(mapLogLevel('success')).toBe('INFO');
|
|
118
|
+
});
|
|
119
|
+
it('should map warn to WARN', ()=>{
|
|
120
|
+
expect(mapLogLevel('warn')).toBe('WARN');
|
|
121
|
+
});
|
|
122
|
+
it('should default unknown level to INFO', ()=>{
|
|
123
|
+
expect(mapLogLevel('debug')).toBe('INFO');
|
|
124
|
+
});
|
|
125
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.28-alpha.
|
|
3
|
+
"version": "1.2.28-alpha.68",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -99,12 +99,12 @@
|
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
101
|
"@data-loom/js": "0.4.13",
|
|
102
|
-
"@lark-apaas/aily-web-sdk": "^0.0.
|
|
103
|
-
"@lark-apaas/auth-sdk": "0.1.
|
|
102
|
+
"@lark-apaas/aily-web-sdk": "^0.0.8",
|
|
103
|
+
"@lark-apaas/auth-sdk": "^0.1.3",
|
|
104
104
|
"@lark-apaas/client-capability": "^0.1.6",
|
|
105
105
|
"@lark-apaas/internal-slardar": "^0.0.3",
|
|
106
|
-
"@lark-apaas/miaoda-inspector": "^1.0.
|
|
107
|
-
"@lark-apaas/observable-web": "
|
|
106
|
+
"@lark-apaas/miaoda-inspector": "^1.0.23",
|
|
107
|
+
"@lark-apaas/observable-web": "1.0.2-alpha.11",
|
|
108
108
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
109
109
|
"@radix-ui/react-popover": "^1.1.15",
|
|
110
110
|
"@radix-ui/react-slot": "^1.2.3",
|