Skip to content

Commit 6c406ba

Browse files
authored
feat: Allow wildcards for logs blacklist (#2396)
- Wildcards are now accepted for logs blacklist JSON paths (e.g. `dashboardData.*.sessionWrapper`) - Updated default blacklist to remove the `sessionWrapper` from any dashboard under `dashboardData` - This technically removes the ability to look for a `*` literal path and an escape could be added for that case, but it seems like an extreme edge case to handle.
1 parent ee4eba5 commit 6c406ba

2 files changed

Lines changed: 97 additions & 4 deletions

File tree

packages/log/src/LogExport.test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,94 @@ describe('getReduxDataString', () => {
8787
);
8888
expect(result).toBe(expected);
8989
});
90+
91+
it('should handle wildcards in blacklist paths', () => {
92+
const reduxData = {
93+
key1: 'not blacklisted',
94+
key2: {
95+
keyA: {
96+
key1: 'blacklisted',
97+
},
98+
keyB: {
99+
key1: 'blacklisted',
100+
},
101+
keyC: {
102+
key1: 'blacklisted',
103+
},
104+
},
105+
};
106+
const result = getReduxDataString(reduxData, [['key2', '*', 'key1']]);
107+
const expected = JSON.stringify(
108+
{
109+
key1: 'not blacklisted',
110+
key2: {
111+
keyA: {},
112+
keyB: {},
113+
keyC: {},
114+
},
115+
},
116+
null,
117+
2
118+
);
119+
expect(result).toBe(expected);
120+
});
121+
122+
it('should handle nested wildcards in blacklist paths', () => {
123+
const reduxData = {
124+
key1: 'not blacklisted',
125+
key2: {
126+
keyA: {
127+
key1: 'blacklisted',
128+
key2: {
129+
key3: 'blacklisted',
130+
},
131+
},
132+
keyB: {
133+
key1: 'blacklisted',
134+
key2: {
135+
key3: 'blacklisted',
136+
key4: 'blacklisted',
137+
},
138+
},
139+
},
140+
};
141+
const result = getReduxDataString(reduxData, [['key2', '*', '*']]);
142+
const expected = JSON.stringify(
143+
{
144+
key1: 'not blacklisted',
145+
key2: {
146+
keyA: {},
147+
keyB: {},
148+
},
149+
},
150+
null,
151+
2
152+
);
153+
expect(result).toBe(expected);
154+
});
155+
156+
it('should handle wildcard blacklist paths with no matches', () => {
157+
const reduxData = {
158+
key1: 'not blacklisted',
159+
key2: {
160+
keyA: {
161+
key1: 'not blacklisted',
162+
key2: {
163+
key3: 'not blacklisted',
164+
},
165+
},
166+
},
167+
};
168+
const result = getReduxDataString(reduxData, [['*', '*', '*', '*', '*']]); // Matching more than the depth of the object
169+
const expected = JSON.stringify(reduxData, null, 2);
170+
expect(result).toBe(expected);
171+
});
172+
173+
it('root wildcard should blacklist all', () => {
174+
const reduxData = {
175+
key1: 'should not be blacklisted',
176+
};
177+
const result = getReduxDataString(reduxData, [['*']]);
178+
expect(result).toBe('{}');
179+
});
90180
});

packages/log/src/LogExport.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import type LogHistory from './LogHistory';
33

44
// List of objects to blacklist
55
// '' represents the root object
6+
// * represents a wildcard key
67
export const DEFAULT_PATH_BLACKLIST: string[][] = [
78
['api'],
89
['client'],
9-
['dashboardData', 'default', 'connection'],
10-
['dashboardData', 'default', 'sessionWrapper', 'dh'],
10+
['dashboardData', '*', 'connection'],
11+
['dashboardData', '*', 'sessionWrapper'],
1112
['layoutStorage'],
1213
['storage'],
1314
];
@@ -43,7 +44,9 @@ function isOnBlackList(currPath: string[], blacklist: string[][]): boolean {
4344
for (let i = 0; i < blacklist.length; i += 1) {
4445
if (
4546
currPath.length === blacklist[i].length &&
46-
currPath.every((v, index) => v === blacklist[i][index])
47+
currPath.every(
48+
(v, index) => blacklist[i][index] === '*' || v === blacklist[i][index]
49+
)
4750
) {
4851
// blacklist match
4952
return true;
@@ -150,7 +153,7 @@ function formatDate(date: Date): string {
150153
* @param logHistory Log history to include in the console.txt file
151154
* @param metadata Additional metadata to include in the metadata.json file
152155
* @param reduxData Redux data to include in the redux.json file
153-
* @param blacklist List of JSON paths to blacklist in redux data. A JSON path is a list representing the path to that value (e.g. client.data would be `['client', 'data']`)
156+
* @param blacklist List of JSON paths to blacklist in redux data. A JSON path is a list representing the path to that value (e.g. client.data would be `['client', 'data']`). Wildcards (*) are accepted in the path.
154157
* @param fileNamePrefix The zip file name without the .zip extension. Ex: test will be saved as test.zip
155158
* @returns A promise that resolves successfully if the log archive is created and downloaded successfully, rejected if there's an error
156159
*/

0 commit comments

Comments
 (0)