@rh-support/troubleshoot 2.4.5-beta.5 → 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":"AAcA,OAAO,EAAE,0BAA0B,EAAkB,MAAM,iCAAiC,CAAC;AAI7F,wBAAgB,eAAe;;EAgH9B"}
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"}
@@ -16,6 +16,7 @@ import isEmpty from 'lodash/isEmpty';
16
16
  import isEqual from 'lodash/isEqual';
17
17
  import map from 'lodash/map';
18
18
  import some from 'lodash/some';
19
+ import sortBy from 'lodash/sortBy';
19
20
  import { useContext, useEffect, useState } from 'react';
20
21
  import { useCaseDispatch, useCaseSelector } from '../context/CaseContext';
21
22
  import { RecommendationStateContext } from '../context/RecommendationContext';
@@ -61,19 +62,38 @@ export function useFetchCVEData() {
61
62
  });
62
63
  });
63
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
+ };
64
77
  const fetchCVEData = (cveIds) => __awaiter(this, void 0, void 0, function* () {
65
78
  if (isEmpty(cveIds))
66
79
  return [];
67
80
  try {
68
81
  const results = yield Promise.allSettled(map(cveIds, (id) => __awaiter(this, void 0, void 0, function* () {
82
+ var _a;
69
83
  const cachedData = getFromCache(id);
70
84
  if (cachedData) {
71
85
  return cachedData;
72
86
  }
73
87
  else {
88
+ // sometime backend return html response so we need to handle this scenario so i have added this logic.
74
89
  const data = yield search.getCVEDetailsById(id);
75
- setInCache(id, data);
76
- return data;
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
+ }
77
97
  }
78
98
  })));
79
99
  return map(filter(results, (result) => result.status === 'fulfilled'), (result) => result.value);
@@ -86,11 +106,13 @@ export function useFetchCVEData() {
86
106
  useEffect(() => {
87
107
  const CVETextValue = `${summary || ''} ${description || ''}`;
88
108
  const cveIds = findCVEsInString(CVETextValue);
89
- const exactMatchCVEIds = filter(cveIds, (cveId) => some(recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.visibleDocs, (doc) => doc.documentKind === 'Cve' &&
109
+ const exactMatchCVEIds = filter(cveIds, (cveId) => some(recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.allDocs, (doc) => doc.documentKind === 'Cve' &&
90
110
  getRecommendationTitle(doc) === cveId &&
91
111
  (doc === null || doc === void 0 ? void 0 : doc.cve_threatSeverity) !== 'Low'));
92
- fetchCVEData(exactMatchCVEIds).then((results) => {
93
- const processedData = map(results, ({ data }) => {
112
+ fetchCVEData(exactMatchCVEIds)
113
+ .then((results) => {
114
+ const sortedData = sortCveResult(results);
115
+ const processedData = map(sortedData, ({ data }) => {
94
116
  var _a, _b, _c, _d;
95
117
  return ({
96
118
  publicDate: (_a = data === null || data === void 0 ? void 0 : data.field_cve_public_date) === null || _a === void 0 ? void 0 : _a.value,
@@ -106,8 +128,11 @@ export function useFetchCVEData() {
106
128
  setCaseState(caseDispatch, {
107
129
  cveWorkflowRecommendation: processedData,
108
130
  });
131
+ })
132
+ .catch((error) => {
133
+ console.error('Error processing CVE data:', error);
109
134
  });
110
135
  // eslint-disable-next-line react-hooks/exhaustive-deps
111
- }, [summary, description, product, version, recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.visibleDocs]);
136
+ }, [summary, description, product, version, recommendationState === null || recommendationState === void 0 ? void 0 : recommendationState.allDocs]);
112
137
  return { cveRecommendation };
113
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/troubleshoot",
3
- "version": "2.4.5-beta.5",
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": "ea597c370ffa9a12fa15cd8e27add093384ca898"
137
+ "gitHead": "c99f48787b265fddb0705d68884d40ede39c196d"
138
138
  }