@rh-support/troubleshoot 2.4.5-beta.3 → 2.4.5-beta.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchCVEData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFetchCVEData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFetchCVEData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFetchCVEData.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,0BAA0B,EAAkB,MAAM,iCAAiC,CAAC;AAI7F,wBAAgB,eAAe;;EAwI9B"}
|
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { search } from '@cee-eng/hydrajs';
|
|
11
|
+
import { useLRUCache } from '@rh-support/components';
|
|
11
12
|
import { getRecommendationTitle } from '@rh-support/utils';
|
|
12
13
|
import filter from 'lodash/filter';
|
|
13
14
|
import isArray from 'lodash/isArray';
|
|
@@ -15,6 +16,7 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
15
16
|
import isEqual from 'lodash/isEqual';
|
|
16
17
|
import map from 'lodash/map';
|
|
17
18
|
import some from 'lodash/some';
|
|
19
|
+
import sortBy from 'lodash/sortBy';
|
|
18
20
|
import { useContext, useEffect, useState } from 'react';
|
|
19
21
|
import { useCaseDispatch, useCaseSelector } from '../context/CaseContext';
|
|
20
22
|
import { RecommendationStateContext } from '../context/RecommendationContext';
|
|
@@ -31,6 +33,7 @@ export function useFetchCVEData() {
|
|
|
31
33
|
summary: state.caseDetails.summary,
|
|
32
34
|
description: state.caseDetails.description,
|
|
33
35
|
}), isEqual);
|
|
36
|
+
const { getFromCache, setInCache } = useLRUCache(50);
|
|
34
37
|
const getFixedErrataByProduct = (releaseInfo, selectedProduct, selectedVersion) => {
|
|
35
38
|
var _a;
|
|
36
39
|
if (isEmpty(releaseInfo) || !isArray(releaseInfo) || !selectedProduct) {
|
|
@@ -59,11 +62,40 @@ export function useFetchCVEData() {
|
|
|
59
62
|
});
|
|
60
63
|
});
|
|
61
64
|
};
|
|
65
|
+
const sortCveResult = (cveData) => {
|
|
66
|
+
if (isEmpty(cveData)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const cveSeverity = {
|
|
70
|
+
Critical: 1,
|
|
71
|
+
Important: 2,
|
|
72
|
+
Moderate: 3,
|
|
73
|
+
Low: 4,
|
|
74
|
+
};
|
|
75
|
+
return sortBy(cveData, (item) => { var _a; return cveSeverity[(_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.field_cve_threat_severity_text] || Infinity; });
|
|
76
|
+
};
|
|
62
77
|
const fetchCVEData = (cveIds) => __awaiter(this, void 0, void 0, function* () {
|
|
63
78
|
if (isEmpty(cveIds))
|
|
64
79
|
return [];
|
|
65
80
|
try {
|
|
66
|
-
const results = yield Promise.allSettled(map(cveIds, (id) =>
|
|
81
|
+
const results = yield Promise.allSettled(map(cveIds, (id) => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
var _a;
|
|
83
|
+
const cachedData = getFromCache(id);
|
|
84
|
+
if (cachedData) {
|
|
85
|
+
return cachedData;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// sometime backend return html response so we need to handle this scenario so i have added this logic.
|
|
89
|
+
const data = yield search.getCVEDetailsById(id);
|
|
90
|
+
if (((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.title) === id) {
|
|
91
|
+
setInCache(id, data);
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error('unexpected response');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
})));
|
|
67
99
|
return map(filter(results, (result) => result.status === 'fulfilled'), (result) => result.value);
|
|
68
100
|
}
|
|
69
101
|
catch (error) {
|
|
@@ -74,11 +106,13 @@ export function useFetchCVEData() {
|
|
|
74
106
|
useEffect(() => {
|
|
75
107
|
const CVETextValue = `${summary || ''} ${description || ''}`;
|
|
76
108
|
const cveIds = findCVEsInString(CVETextValue);
|
|
77
|
-
const exactMatchCVEIds = filter(cveIds, (cveId) => some(recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.
|
|
109
|
+
const exactMatchCVEIds = filter(cveIds, (cveId) => some(recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.allDocs, (doc) => doc.documentKind === 'Cve' &&
|
|
78
110
|
getRecommendationTitle(doc) === cveId &&
|
|
79
111
|
(doc === null || doc === void 0 ? void 0 : doc.cve_threatSeverity) !== 'Low'));
|
|
80
|
-
fetchCVEData(exactMatchCVEIds)
|
|
81
|
-
|
|
112
|
+
fetchCVEData(exactMatchCVEIds)
|
|
113
|
+
.then((results) => {
|
|
114
|
+
const sortedData = sortCveResult(results);
|
|
115
|
+
const processedData = map(sortedData, ({ data }) => {
|
|
82
116
|
var _a, _b, _c, _d;
|
|
83
117
|
return ({
|
|
84
118
|
publicDate: (_a = data === null || data === void 0 ? void 0 : data.field_cve_public_date) === null || _a === void 0 ? void 0 : _a.value,
|
|
@@ -94,8 +128,11 @@ export function useFetchCVEData() {
|
|
|
94
128
|
setCaseState(caseDispatch, {
|
|
95
129
|
cveWorkflowRecommendation: processedData,
|
|
96
130
|
});
|
|
131
|
+
})
|
|
132
|
+
.catch((error) => {
|
|
133
|
+
console.error('Error processing CVE data:', error);
|
|
97
134
|
});
|
|
98
135
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
99
|
-
}, [summary, description, product, version, recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.
|
|
136
|
+
}, [summary, description, product, version, recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.allDocs]);
|
|
100
137
|
return { cveRecommendation };
|
|
101
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/troubleshoot",
|
|
3
|
-
"version": "2.4.5-beta.
|
|
3
|
+
"version": "2.4.5-beta.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -134,5 +134,5 @@
|
|
|
134
134
|
"defaults and supports es6-module",
|
|
135
135
|
"maintained node versions"
|
|
136
136
|
],
|
|
137
|
-
"gitHead": "
|
|
137
|
+
"gitHead": "c99f48787b265fddb0705d68884d40ede39c196d"
|
|
138
138
|
}
|