@rh-support/utils 2.0.7 → 2.0.9
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/cjs/apiUtils.js +10 -24
- package/lib/cjs/appUtils.js +18 -19
- package/lib/cjs/cacheUtils.js +53 -93
- package/lib/cjs/caseUtils.js +15 -16
- package/lib/cjs/csvUtils.js +38 -87
- package/lib/cjs/customElementUtils.js +1 -1
- package/lib/cjs/dateUtils.js +19 -25
- package/lib/cjs/dropdownUtils.js +8 -10
- package/lib/cjs/eventUtils.js +4 -5
- package/lib/cjs/hostNameUtils.js +7 -7
- package/lib/cjs/hydraConfigUtils.js +14 -37
- package/lib/cjs/insightRuleInfoUtils.js +7 -7
- package/lib/cjs/lruCacheUtils.js +18 -20
- package/lib/cjs/outlier.js +4 -4
- package/lib/cjs/productsUtils.d.ts +1 -1
- package/lib/cjs/productsUtils.d.ts.map +1 -1
- package/lib/cjs/productsUtils.js +40 -78
- package/lib/cjs/promiseUtils.js +9 -44
- package/lib/cjs/recommendationUtils.js +7 -19
- package/lib/cjs/scrollUtils.js +14 -25
- package/lib/cjs/searchApiUtils.js +10 -21
- package/lib/cjs/sentry.js +6 -19
- package/lib/cjs/solrUtils.js +81 -108
- package/lib/cjs/translation-helper.js +2 -2
- package/lib/cjs/urlUtils.js +25 -38
- package/lib/cjs/userUtils.js +2 -2
- package/lib/cjs/validatorUtils.js +7 -7
- package/lib/esm/productsUtils.d.ts +1 -1
- package/lib/esm/productsUtils.d.ts.map +1 -1
- package/lib/esm/productsUtils.js +2 -2
- package/package.json +6 -2
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getText = void 0;
|
|
7
|
-
|
|
7
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
8
8
|
/**
|
|
9
9
|
* Translate the string using i18n.t
|
|
10
10
|
* @param {string} key the string to be translated
|
|
@@ -14,7 +14,7 @@ var i18next_1 = __importDefault(require("i18next"));
|
|
|
14
14
|
* use getText only in the case when neither <Trans /> nor useTranslation() is available
|
|
15
15
|
*/
|
|
16
16
|
function getText(key, args) {
|
|
17
|
-
|
|
17
|
+
const translatedString = i18next_1.default.t(key, args);
|
|
18
18
|
if (!translatedString) {
|
|
19
19
|
return key;
|
|
20
20
|
}
|
package/lib/cjs/urlUtils.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.isValidUrl = exports.getUpdatedQueryString = exports.getDrupalResIdIfTypeFromUrl = exports.getDrupalResIdFromUrl = exports.getResTypeFromUrl = exports.getRedhatDotComHost = exports.REDHAT_DOT_COM_HOSTNAMES = exports.getStringifiedParams = exports.getUrlParsedParams = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
const pickBy_1 = __importDefault(require("lodash/pickBy"));
|
|
8
|
+
const qs_1 = __importDefault(require("qs"));
|
|
20
9
|
// parses url query params to an obj
|
|
21
10
|
function getUrlParsedParams(urlParams, options) {
|
|
22
|
-
|
|
23
|
-
return qs_1.default.parse(urlParams,
|
|
11
|
+
const defaultOptions = { ignoreQueryPrefix: true };
|
|
12
|
+
return qs_1.default.parse(urlParams, Object.assign(Object.assign({}, defaultOptions), options));
|
|
24
13
|
}
|
|
25
14
|
exports.getUrlParsedParams = getUrlParsedParams;
|
|
26
15
|
// converts an obj to url query params
|
|
27
16
|
function getStringifiedParams(object, options) {
|
|
28
|
-
|
|
29
|
-
return qs_1.default.stringify(object,
|
|
17
|
+
const defaultOptions = { arrayFormat: 'repeat', encode: false };
|
|
18
|
+
return qs_1.default.stringify(object, Object.assign(Object.assign({}, defaultOptions), options));
|
|
30
19
|
}
|
|
31
20
|
exports.getStringifiedParams = getStringifiedParams;
|
|
32
21
|
exports.REDHAT_DOT_COM_HOSTNAMES = {
|
|
@@ -35,7 +24,7 @@ exports.REDHAT_DOT_COM_HOSTNAMES = {
|
|
|
35
24
|
DEV: 'https://www.dev.redhat.com',
|
|
36
25
|
PROD: 'https://www.redhat.com',
|
|
37
26
|
};
|
|
38
|
-
|
|
27
|
+
const getRedhatDotComHost = (env) => {
|
|
39
28
|
switch (env) {
|
|
40
29
|
case 'QA':
|
|
41
30
|
return exports.REDHAT_DOT_COM_HOSTNAMES.QA;
|
|
@@ -48,42 +37,40 @@ var getRedhatDotComHost = function (env) {
|
|
|
48
37
|
}
|
|
49
38
|
};
|
|
50
39
|
exports.getRedhatDotComHost = getRedhatDotComHost;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
const drupalUrlRegexp = /^(https:\/\/access?.?\w+.redhat.com)?\/(\w+)\/(\d+)\S*$/;
|
|
41
|
+
const openshiftDocUrlRegexp = /^https:\/\/docs.openshift.com\//;
|
|
42
|
+
const getResTypeFromUrl = (url) => {
|
|
43
|
+
const drupalUrl = drupalUrlRegexp.exec(url);
|
|
44
|
+
const isOpenshiftDocUrl = openshiftDocUrlRegexp.test(url);
|
|
56
45
|
return (drupalUrl === null || drupalUrl === void 0 ? void 0 : drupalUrl[2]) ? drupalUrl === null || drupalUrl === void 0 ? void 0 : drupalUrl[2] : isOpenshiftDocUrl ? 'documentation' : 'unknown';
|
|
57
46
|
};
|
|
58
47
|
exports.getResTypeFromUrl = getResTypeFromUrl;
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
const getDrupalResIdFromUrl = (url) => {
|
|
49
|
+
let m = drupalUrlRegexp.exec(url);
|
|
61
50
|
return m === null || m === void 0 ? void 0 : m[2];
|
|
62
51
|
};
|
|
63
52
|
exports.getDrupalResIdFromUrl = getDrupalResIdFromUrl;
|
|
64
|
-
|
|
53
|
+
const getDrupalResIdIfTypeFromUrl = (url, resourceTypes = ['solutions', 'articles']) => {
|
|
65
54
|
var _a;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var resourceId = m === null || m === void 0 ? void 0 : m[3];
|
|
55
|
+
let m = drupalUrlRegexp.exec(url);
|
|
56
|
+
const resourceType = (_a = m === null || m === void 0 ? void 0 : m[2]) !== null && _a !== void 0 ? _a : '';
|
|
57
|
+
const resourceId = m === null || m === void 0 ? void 0 : m[3];
|
|
70
58
|
return resourceTypes.includes(resourceType) && !isNaN(parseInt(resourceId)) ? parseInt(resourceId) : undefined;
|
|
71
59
|
};
|
|
72
60
|
exports.getDrupalResIdIfTypeFromUrl = getDrupalResIdIfTypeFromUrl;
|
|
73
|
-
|
|
61
|
+
const isFieldValueEmpty = function (value) {
|
|
74
62
|
return value === '' || value === undefined || value === null;
|
|
75
63
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
? pickBy_1.default(mergedQueryObject, function (item) { return !isFieldValueEmpty(item); })
|
|
64
|
+
const getUpdatedQueryString = (currentQuery, newQuery, { resetSearchParams = false, removeEmptyParams = false }) => {
|
|
65
|
+
const currentQueryObj = typeof currentQuery === 'string' ? getUrlParsedParams(currentQuery) : currentQuery;
|
|
66
|
+
const mergedQueryObject = Object.assign(Object.assign({}, currentQueryObj), newQuery);
|
|
67
|
+
const updatedQuery = removeEmptyParams
|
|
68
|
+
? pickBy_1.default(mergedQueryObject, (item) => !isFieldValueEmpty(item))
|
|
82
69
|
: mergedQueryObject;
|
|
83
70
|
return !resetSearchParams ? getStringifiedParams(updatedQuery) : getStringifiedParams(newQuery);
|
|
84
71
|
};
|
|
85
72
|
exports.getUpdatedQueryString = getUpdatedQueryString;
|
|
86
|
-
|
|
73
|
+
const isValidUrl = (url) => {
|
|
87
74
|
return /^(http(s)?:\/\/)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/.test(url);
|
|
88
75
|
};
|
|
89
76
|
exports.isValidUrl = isValidUrl;
|
package/lib/cjs/userUtils.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.sortHydraContacts = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const sortBy_1 = __importDefault(require("lodash/sortBy"));
|
|
8
|
+
const sortHydraContacts = (hydraContacts) => {
|
|
9
9
|
return sortBy_1.default(hydraContacts, 'firstName', 'lastName');
|
|
10
10
|
};
|
|
11
11
|
exports.sortHydraContacts = sortHydraContacts;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isImageFile = exports.isValidGuid = exports.mailformat = exports.emojiPattern = exports.isEmojiPattern = exports.isValidRHEmail = exports.isRegularVersion = exports.isNumber = exports.isEmailValid = void 0;
|
|
4
|
-
|
|
4
|
+
const emojiPattern = /[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/gu;
|
|
5
5
|
exports.emojiPattern = emojiPattern;
|
|
6
|
-
|
|
6
|
+
const mailformat = new RegExp(
|
|
7
7
|
// eslint-disable-next-line no-control-regex
|
|
8
8
|
"([!#-'*+/-9=?A-Z^-~-]+(.[!#-'*+/-9=?A-Z^-~-]+)*|\"([]!#-[^-~ \t]|(\\[\t -~]))+\")@([!#-'*+/-9=?A-Z^-~-]+(.[!#-'*+/-9=?A-Z^-~-]+)*|[[\t -Z^-~]*])");
|
|
9
9
|
exports.mailformat = mailformat;
|
|
10
|
-
|
|
10
|
+
const imageRegex = /^image\/(gif|png|jpeg)$/;
|
|
11
11
|
// To check if email is valid
|
|
12
12
|
function isEmailValid(object) {
|
|
13
13
|
if (object.match(mailformat)) {
|
|
@@ -38,7 +38,7 @@ function isEmojiPattern(object) {
|
|
|
38
38
|
}
|
|
39
39
|
exports.isEmojiPattern = isEmojiPattern;
|
|
40
40
|
function isValidGuid(object) {
|
|
41
|
-
|
|
41
|
+
const guidFormat = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
42
42
|
if (object.match(guidFormat)) {
|
|
43
43
|
return true;
|
|
44
44
|
}
|
|
@@ -53,10 +53,10 @@ function isNumber(str) {
|
|
|
53
53
|
exports.isNumber = isNumber;
|
|
54
54
|
function isRegularVersion(version) {
|
|
55
55
|
// splits the version into its parts because some versions can have words in front of them (e.g. Red Hat Build of Thorntail - Thorntail 1.x)
|
|
56
|
-
|
|
56
|
+
const versionPartsArray = version.split(' ');
|
|
57
57
|
// find the index that has the version and split it into its pars
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const indexOfVersion = versionPartsArray.findIndex((p) => p.includes('.'));
|
|
59
|
+
const splitArray = indexOfVersion > -1 ? versionPartsArray[indexOfVersion].split('.') : version.split('.');
|
|
60
60
|
// if the length of the split array is not 2, or 3 it is not a regular version
|
|
61
61
|
// b/c version === major.minor.patch (patch === component in the request body)
|
|
62
62
|
if (splitArray.length !== 2 && splitArray.length !== 3 && splitArray.length !== 4)
|
|
@@ -28,6 +28,6 @@ interface IGetVersionReturnValue {
|
|
|
28
28
|
minor?: string;
|
|
29
29
|
}
|
|
30
30
|
export declare function getVersion(version: string): IGetVersionReturnValue;
|
|
31
|
-
export declare function isSpecialSupportOfferingEnabled(allProducts:
|
|
31
|
+
export declare function isSpecialSupportOfferingEnabled(allProducts: Partial<ISEProduct>[], selectedProduct: string): boolean;
|
|
32
32
|
export {};
|
|
33
33
|
//# sourceMappingURL=productsUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"productsUtils.d.ts","sourceRoot":"","sources":["../../src/productsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAWhF,MAAM,WAAW,4BAA4B;IACzC,WAAW,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACnC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACrC,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;CACzC;AAED,eAAO,MAAM,2BAA2B,sBACjB,UAAU,EAAE,2BACP,UAAU,EAAE,aAC1B,MAAM,KACjB,4BA4BF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,4BACd,UAAU,EAAE,KACrC,4BAeF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,SAAI,GAAG,OAAO,CAAC,UAAU,CAAC,EAAE,CAOnG;AAED,wBAAgB,aAA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,EAAE,MAAM,EAAE,UAEzD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAEzD;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,MAAM,MAAM,eAmBnD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAS,MAAM,EAAE,aAExC,CAAC;AAEF,UAAU,sBAAsB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAkBlE;AAED,wBAAgB,+BAA+B,CAAC,WAAW,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,eAAe,EAAE,MAAM,WAK1G"}
|
package/lib/esm/productsUtils.js
CHANGED
|
@@ -117,6 +117,6 @@ export function getVersion(version) {
|
|
|
117
117
|
}
|
|
118
118
|
export function isSpecialSupportOfferingEnabled(allProducts, selectedProduct) {
|
|
119
119
|
var _c;
|
|
120
|
-
const
|
|
121
|
-
return
|
|
120
|
+
const productHasSpecialSupportOffering = (_c = allProducts.find((product) => product.name === selectedProduct)) === null || _c === void 0 ? void 0 : _c.hasSpecialSupportOffering;
|
|
121
|
+
return productHasSpecialSupportOffering;
|
|
122
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -84,5 +84,9 @@
|
|
|
84
84
|
"@types/react-dom": "^17.0.9",
|
|
85
85
|
"moment-timezone": "^0.5.40"
|
|
86
86
|
},
|
|
87
|
-
"
|
|
87
|
+
"browserslist": [
|
|
88
|
+
"defaults and supports es6-module",
|
|
89
|
+
"maintained node versions"
|
|
90
|
+
],
|
|
91
|
+
"gitHead": "19377aef011c0242cb5290e36ee927eace353f27"
|
|
88
92
|
}
|