@rh-support/utils 2.0.7 → 2.0.8
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.js +39 -77
- 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/package.json +6 -2
package/lib/cjs/dateUtils.js
CHANGED
|
@@ -4,10 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.addDaysToDate = exports.isFutureDate = exports.isCurrentDateSameAsOrBeforeDate = exports.getPastUTCDateFromNow = exports.getTimezoneOffsetFromTZName = exports.isoDate = exports.formatDateTime = exports.formatDate = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (locale === void 0) { locale = 'en-us'; }
|
|
10
|
-
if (format === void 0) { format = { month: 'short', day: 'numeric', year: 'numeric' }; }
|
|
7
|
+
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
8
|
+
const formatDate = (date, locale = 'en-us', format = { month: 'short', day: 'numeric', year: 'numeric' }) => {
|
|
11
9
|
if (!date) {
|
|
12
10
|
return '';
|
|
13
11
|
}
|
|
@@ -17,46 +15,42 @@ var formatDate = function (date, locale, format) {
|
|
|
17
15
|
return new Intl.DateTimeFormat(locale, format).format(date);
|
|
18
16
|
};
|
|
19
17
|
exports.formatDate = formatDate;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
timeZoneName: 'short',
|
|
31
|
-
}; }
|
|
18
|
+
const formatDateTime = (date, locale = 'en-us', format = {
|
|
19
|
+
weekday: 'short',
|
|
20
|
+
month: 'short',
|
|
21
|
+
day: 'numeric',
|
|
22
|
+
year: 'numeric',
|
|
23
|
+
hour: '2-digit',
|
|
24
|
+
minute: '2-digit',
|
|
25
|
+
second: '2-digit',
|
|
26
|
+
timeZoneName: 'short',
|
|
27
|
+
}) => {
|
|
32
28
|
if (!date) {
|
|
33
29
|
return '';
|
|
34
30
|
}
|
|
35
31
|
return exports.formatDate(date, locale, format);
|
|
36
32
|
};
|
|
37
33
|
exports.formatDateTime = formatDateTime;
|
|
38
|
-
|
|
34
|
+
const isoDate = (date) => new Date(date).toString();
|
|
39
35
|
exports.isoDate = isoDate;
|
|
40
|
-
|
|
36
|
+
const getTimezoneOffsetFromTZName = (tzName) => {
|
|
41
37
|
return moment_timezone_1.default().tz(tzName).format('Z');
|
|
42
38
|
};
|
|
43
39
|
exports.getTimezoneOffsetFromTZName = getTimezoneOffsetFromTZName;
|
|
44
|
-
|
|
40
|
+
const getPastUTCDateFromNow = (pastDays) => {
|
|
45
41
|
return moment_timezone_1.default().subtract(pastDays, 'days').utc().format();
|
|
46
42
|
};
|
|
47
43
|
exports.getPastUTCDateFromNow = getPastUTCDateFromNow;
|
|
48
|
-
|
|
49
|
-
if (granularity === void 0) { granularity = 'day'; }
|
|
44
|
+
const isCurrentDateSameAsOrBeforeDate = (date, granularity = 'day') => {
|
|
50
45
|
return moment_timezone_1.default(moment_timezone_1.default.now()).isSameOrBefore(date, granularity);
|
|
51
46
|
};
|
|
52
47
|
exports.isCurrentDateSameAsOrBeforeDate = isCurrentDateSameAsOrBeforeDate;
|
|
53
|
-
|
|
54
|
-
if (granularity === void 0) { granularity = 'day'; }
|
|
48
|
+
const isFutureDate = (date, granularity = 'day') => {
|
|
55
49
|
return moment_timezone_1.default(date).isAfter(moment_timezone_1.default(), granularity);
|
|
56
50
|
};
|
|
57
51
|
exports.isFutureDate = isFutureDate;
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const addDaysToDate = (params) => {
|
|
53
|
+
const { days, date = new Date() } = params;
|
|
60
54
|
return moment_timezone_1.default(date).add(days, 'days');
|
|
61
55
|
};
|
|
62
56
|
exports.addDaysToDate = addDaysToDate;
|
package/lib/cjs/dropdownUtils.js
CHANGED
|
@@ -4,12 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getDropdownBtnPlaceholder = exports.toOptions = exports.toOption = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function toOption(value, config) {
|
|
10
|
-
if (config === void 0) { config = {}; }
|
|
7
|
+
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
8
|
+
const map_1 = __importDefault(require("lodash/map"));
|
|
9
|
+
function toOption(value, config = {}) {
|
|
11
10
|
return (value && {
|
|
12
|
-
value
|
|
11
|
+
value,
|
|
13
12
|
label: ((config === null || config === void 0 ? void 0 : config.labelKey)
|
|
14
13
|
? isFunction_1.default(config === null || config === void 0 ? void 0 : config.labelKey)
|
|
15
14
|
? config === null || config === void 0 ? void 0 : config.labelKey(value)
|
|
@@ -38,9 +37,8 @@ function toOption(value, config) {
|
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
39
|
exports.toOption = toOption;
|
|
41
|
-
function toOptions(values, config) {
|
|
42
|
-
|
|
43
|
-
return map_1.default(values, function (v) { return toOption(v, config); });
|
|
40
|
+
function toOptions(values, config = {}) {
|
|
41
|
+
return map_1.default(values, (v) => toOption(v, config));
|
|
44
42
|
}
|
|
45
43
|
exports.toOptions = toOptions;
|
|
46
44
|
function getDropdownBtnPlaceholder(btnPlaceholder, selectedValues, type, totalLength, totalLengthString) {
|
|
@@ -48,14 +46,14 @@ function getDropdownBtnPlaceholder(btnPlaceholder, selectedValues, type, totalLe
|
|
|
48
46
|
return btnPlaceholder;
|
|
49
47
|
}
|
|
50
48
|
else if (selectedValues && selectedValues.length === 1) {
|
|
51
|
-
|
|
49
|
+
const selectedItem = selectedValues[0];
|
|
52
50
|
return typeof selectedItem === 'string' ? selectedItem : selectedItem.value;
|
|
53
51
|
}
|
|
54
52
|
else if (selectedValues && totalLength && selectedValues.length === totalLength) {
|
|
55
53
|
return totalLengthString || btnPlaceholder;
|
|
56
54
|
}
|
|
57
55
|
else {
|
|
58
|
-
return selectedValues.length
|
|
56
|
+
return `${selectedValues.length} ${type} selected`;
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
exports.getDropdownBtnPlaceholder = getDropdownBtnPlaceholder;
|
package/lib/cjs/eventUtils.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.dtmTrackEvent = exports.pendoTrackEvent = exports.haltEvent = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const hydrajs_1 = require("@cee-eng/hydrajs");
|
|
8
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
9
9
|
function haltEvent(event) {
|
|
10
10
|
if (event) {
|
|
11
11
|
event.stopPropagation();
|
|
@@ -16,9 +16,8 @@ exports.haltEvent = haltEvent;
|
|
|
16
16
|
// https://support.pendo.io/hc/en-us/articles/360032294291-Track-Events-Configuration
|
|
17
17
|
// if event name is not exist in the pendo then it will create
|
|
18
18
|
// new event otherwise it will update existing event.
|
|
19
|
-
function pendoTrackEvent(name, properties) {
|
|
20
|
-
|
|
21
|
-
var pendo = window.pendo;
|
|
19
|
+
function pendoTrackEvent(name, properties = {}) {
|
|
20
|
+
const pendo = window.pendo;
|
|
22
21
|
// log the event for prod and local envirnoment
|
|
23
22
|
if (!isEmpty_1.default(pendo) && (hydrajs_1.Env.getEnvName() === hydrajs_1.Env.EnvNames.PROD || hydrajs_1.Env.isLocalEnv())) {
|
|
24
23
|
pendo.track(name, properties);
|
package/lib/cjs/hostNameUtils.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSFDCSecureSupportCaseLink = exports.getSFDCEnv = exports.APP_HOST_NAMES = void 0;
|
|
4
|
-
|
|
4
|
+
const hydrajs_1 = require("@cee-eng/hydrajs");
|
|
5
5
|
var APP_HOST_NAMES;
|
|
6
6
|
(function (APP_HOST_NAMES) {
|
|
7
7
|
APP_HOST_NAMES["supportHubHostName"] = "supportHubHostName";
|
|
8
8
|
})(APP_HOST_NAMES || (APP_HOST_NAMES = {}));
|
|
9
9
|
exports.APP_HOST_NAMES = APP_HOST_NAMES;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const getSFDCEnv = () => {
|
|
11
|
+
const env = hydrajs_1.Env.getEnvName();
|
|
12
12
|
// Prod HostName
|
|
13
|
-
|
|
13
|
+
let hostName = 'gss.my.salesforce.com';
|
|
14
14
|
switch (env) {
|
|
15
15
|
case hydrajs_1.Env.EnvNames.QA:
|
|
16
16
|
hostName = 'gss--qa.cs53.my.salesforce.com';
|
|
@@ -28,8 +28,8 @@ var getSFDCEnv = function () {
|
|
|
28
28
|
return hostName;
|
|
29
29
|
};
|
|
30
30
|
exports.getSFDCEnv = getSFDCEnv;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
31
|
+
const getSFDCSecureSupportCaseLink = (caseNumber) => {
|
|
32
|
+
const hostName = getSFDCEnv();
|
|
33
|
+
return `https://${hostName}/apex/Support#/cases/${caseNumber}`;
|
|
34
34
|
};
|
|
35
35
|
exports.getSFDCSecureSupportCaseLink = getSFDCSecureSupportCaseLink;
|
|
@@ -1,35 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
19
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
20
|
-
to[j] = from[i];
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
4
|
};
|
|
26
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
6
|
exports.getFieldInParts = exports.getConfigField = exports.PCM_CONFIG_FIELD_TYPE = void 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
const concat_1 = __importDefault(require("lodash/concat"));
|
|
8
|
+
const map_1 = __importDefault(require("lodash/map"));
|
|
9
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
10
|
+
const reduce_1 = __importDefault(require("lodash/reduce"));
|
|
11
|
+
const startsWith_1 = __importDefault(require("lodash/startsWith"));
|
|
33
12
|
var PCM_CONFIG_FIELD_TYPE;
|
|
34
13
|
(function (PCM_CONFIG_FIELD_TYPE) {
|
|
35
14
|
PCM_CONFIG_FIELD_TYPE["JSON"] = "JSON";
|
|
@@ -38,10 +17,9 @@ var PCM_CONFIG_FIELD_TYPE;
|
|
|
38
17
|
PCM_CONFIG_FIELD_TYPE["FEATURE_FLAG"] = "FEATURE-FLAG";
|
|
39
18
|
PCM_CONFIG_FIELD_TYPE["STRING_COMMA_SEPERATED"] = "STRING-COMMA-SEPERATED";
|
|
40
19
|
})(PCM_CONFIG_FIELD_TYPE = exports.PCM_CONFIG_FIELD_TYPE || (exports.PCM_CONFIG_FIELD_TYPE = {}));
|
|
41
|
-
function getConfigField(config, fieldName, fieldType) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return v.fieldName.startsWith(fieldName) ? __spreadArray(__spreadArray([], __read(result)), [v.fieldValue]) : result;
|
|
20
|
+
function getConfigField(config, fieldName, fieldType = null) {
|
|
21
|
+
let values = reduce_1.default(config, (result, v) => {
|
|
22
|
+
return v.fieldName.startsWith(fieldName) ? [...result, v.fieldValue] : result;
|
|
45
23
|
}, []);
|
|
46
24
|
if (fieldType && fieldType === PCM_CONFIG_FIELD_TYPE.FEATURE_FLAG) {
|
|
47
25
|
return values.length === 0 ? false : Boolean(parseInt(values[0]));
|
|
@@ -51,7 +29,7 @@ function getConfigField(config, fieldName, fieldType) {
|
|
|
51
29
|
if (!fieldType)
|
|
52
30
|
return values;
|
|
53
31
|
try {
|
|
54
|
-
|
|
32
|
+
const parsed = values.map((value) => JSON.parse(value));
|
|
55
33
|
if (fieldType === PCM_CONFIG_FIELD_TYPE.JSON)
|
|
56
34
|
return parsed;
|
|
57
35
|
if (fieldType === PCM_CONFIG_FIELD_TYPE.JSON_ARRAY)
|
|
@@ -64,10 +42,9 @@ function getConfigField(config, fieldName, fieldType) {
|
|
|
64
42
|
}
|
|
65
43
|
}
|
|
66
44
|
exports.getConfigField = getConfigField;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return startsWith_1.default(v.fieldName, fieldName) ? __spreadArray(__spreadArray([], __read(result)), [v.fieldValue]) : result;
|
|
45
|
+
const getFieldInParts = (config, fieldName, fieldType = null) => {
|
|
46
|
+
const values = reduce_1.default(config, (result, v) => {
|
|
47
|
+
return startsWith_1.default(v.fieldName, fieldName) ? [...result, v.fieldValue] : result;
|
|
71
48
|
}, []);
|
|
72
49
|
if (values.length === 0) {
|
|
73
50
|
return null;
|
|
@@ -77,11 +54,11 @@ var getFieldInParts = function (config, fieldName, fieldType) {
|
|
|
77
54
|
}
|
|
78
55
|
try {
|
|
79
56
|
if (fieldType === 'STRING-COMMA-SEPERATED') {
|
|
80
|
-
return reduce_1.default(values,
|
|
57
|
+
return reduce_1.default(values, (acc, value) => {
|
|
81
58
|
return acc.concat(value.split(','));
|
|
82
59
|
}, []);
|
|
83
60
|
}
|
|
84
|
-
|
|
61
|
+
const parsed = map_1.default(values, JSON.parse);
|
|
85
62
|
if (fieldType === 'JSON') {
|
|
86
63
|
return parsed;
|
|
87
64
|
}
|
|
@@ -4,23 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseDotTemplate = exports.getRuleReasonHtml = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const ui_toolkit_1 = require("@cee-eng/ui-toolkit");
|
|
8
|
+
const doT_1 = __importDefault(require("dot/doT"));
|
|
9
|
+
const assign_1 = __importDefault(require("lodash/assign"));
|
|
10
10
|
doT_1.default.templateSettings = assign_1.default({}, doT_1.default.templateSettings, {
|
|
11
11
|
varname: 'pydata',
|
|
12
12
|
strip: false,
|
|
13
13
|
});
|
|
14
14
|
function getRuleReasonHtml(ruleReason, reportDetails) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const resultText = parseDotTemplate(ruleReason, reportDetails);
|
|
16
|
+
const html = ui_toolkit_1.markdownToHTML(resultText);
|
|
17
17
|
return html;
|
|
18
18
|
}
|
|
19
19
|
exports.getRuleReasonHtml = getRuleReasonHtml;
|
|
20
20
|
function parseDotTemplate(dotString, reportDetails) {
|
|
21
|
-
|
|
21
|
+
let parsedDotString = '';
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
const tempFn = doT_1.default.template(dotString);
|
|
24
24
|
parsedDotString = tempFn(reportDetails);
|
|
25
25
|
}
|
|
26
26
|
catch (e) {
|
package/lib/cjs/lruCacheUtils.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LRUCache = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (max === void 0) { max = 10; }
|
|
4
|
+
class LRUCache {
|
|
5
|
+
constructor(max = 10) {
|
|
7
6
|
this.max = max;
|
|
8
7
|
this.cache = new Map();
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
get(key) {
|
|
10
|
+
let item = this.cache.get(key);
|
|
12
11
|
if (item) {
|
|
13
12
|
// refresh key
|
|
14
13
|
this.cache.delete(key);
|
|
15
14
|
this.cache.set(key, item);
|
|
16
15
|
}
|
|
17
16
|
return item;
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
}
|
|
18
|
+
set(key, val) {
|
|
20
19
|
// refresh key
|
|
21
20
|
if (this.cache.has(key))
|
|
22
21
|
this.cache.delete(key);
|
|
@@ -24,24 +23,23 @@ var LRUCache = /** @class */ (function () {
|
|
|
24
23
|
else if (this.cache.size === this.max)
|
|
25
24
|
this.cache.delete(this.first());
|
|
26
25
|
this.cache.set(key, val);
|
|
27
|
-
}
|
|
28
|
-
|
|
26
|
+
}
|
|
27
|
+
has(key) {
|
|
29
28
|
return this.cache.has(key);
|
|
30
|
-
}
|
|
31
|
-
|
|
29
|
+
}
|
|
30
|
+
size() {
|
|
32
31
|
return this.cache.size;
|
|
33
|
-
}
|
|
34
|
-
|
|
32
|
+
}
|
|
33
|
+
first() {
|
|
35
34
|
return this.cache.keys().next().value;
|
|
36
|
-
}
|
|
37
|
-
|
|
35
|
+
}
|
|
36
|
+
peek(key) {
|
|
38
37
|
if (this.cache.has(key)) {
|
|
39
38
|
return this.cache.get(key);
|
|
40
39
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
40
|
+
}
|
|
41
|
+
clear() {
|
|
43
42
|
this.cache.clear();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
47
45
|
exports.LRUCache = LRUCache;
|
package/lib/cjs/outlier.js
CHANGED
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.outlier = void 0;
|
|
18
|
-
|
|
18
|
+
const outlier = (array) => {
|
|
19
19
|
// Take array length
|
|
20
|
-
|
|
20
|
+
const arrayLength = array.length;
|
|
21
21
|
// Check if length is smaller than four then return array result as it is
|
|
22
22
|
if (arrayLength < 4) {
|
|
23
23
|
return array;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
let q1, q3, iqr, upperBoundary, lowerBoundary;
|
|
26
26
|
// Make a copy of array plus sort it in ascending order
|
|
27
|
-
|
|
27
|
+
const sortedArray = array.slice().sort((a, b) => a - b);
|
|
28
28
|
// Find the quartiles range
|
|
29
29
|
// If median is odd adjust the index by minus one
|
|
30
30
|
if (((arrayLength - 1) / 4) % 1 === 0 || (arrayLength / 4) % 1 === 0) {
|
package/lib/cjs/productsUtils.js
CHANGED
|
@@ -1,72 +1,38 @@
|
|
|
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
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
30
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
31
|
-
to[j] = from[i];
|
|
32
|
-
return to;
|
|
33
|
-
};
|
|
34
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
4
|
};
|
|
37
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
6
|
exports.isSpecialSupportOfferingEnabled = exports.getVersion = exports.versionSort = exports.versionSorter = exports.getUniqueSortedVersions = exports.getVersionIfOnlyVersion = exports.isOnlyVersion = exports.getTopProducts = exports.handleEntitledProductResponse = exports.handleProductSearchResponse = void 0;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var productsResultEntitledMap = {};
|
|
51
|
-
forEach_1.default(productsResultEntitled, function (p) {
|
|
7
|
+
const difference_1 = __importDefault(require("lodash/difference"));
|
|
8
|
+
const forEach_1 = __importDefault(require("lodash/forEach"));
|
|
9
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
10
|
+
const map_1 = __importDefault(require("lodash/map"));
|
|
11
|
+
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
12
|
+
const remove_1 = __importDefault(require("lodash/remove"));
|
|
13
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
14
|
+
const validatorUtils_1 = require("./validatorUtils");
|
|
15
|
+
const handleProductSearchResponse = (productsResultAll, productsResultEntitled = [], topCount = 5) => {
|
|
16
|
+
const productsResultEntitledMap = {};
|
|
17
|
+
forEach_1.default(productsResultEntitled, (p) => {
|
|
52
18
|
// If (p.supportedForCustomer)
|
|
53
19
|
// Needs confirmation froom CCM team before adding
|
|
54
|
-
productsResultEntitledMap[
|
|
20
|
+
productsResultEntitledMap[`${p.name}`] = p;
|
|
55
21
|
});
|
|
56
|
-
|
|
22
|
+
const productsResult = map_1.default(productsResultAll, (product) => {
|
|
57
23
|
var _c, _d;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
24
|
+
const entitledProduct = productsResultEntitledMap[product.product];
|
|
25
|
+
const uniqueVersions = getUniqueSortedVersions(product.versions);
|
|
26
|
+
return Object.assign(Object.assign(Object.assign({}, product), entitledProduct), { versions: uniqueVersions, isEntitledProduct: !isEmpty_1.default(entitledProduct), featuredVersion: ((_c = product.versions) === null || _c === void 0 ? void 0 : _c.includes(product.featuredVersion))
|
|
61
27
|
? product.featuredVersion
|
|
62
28
|
: (_d = product === null || product === void 0 ? void 0 : product.versions[0]) !== null && _d !== void 0 ? _d : '' });
|
|
63
29
|
});
|
|
64
30
|
// We get products based on the highest number of support cases
|
|
65
|
-
|
|
66
|
-
|
|
31
|
+
const topProducts = getTopProducts(productsResult, topCount);
|
|
32
|
+
const productsResultSorted = orderBy_1.default(productsResult, ['product'], ['asc']);
|
|
67
33
|
return {
|
|
68
34
|
productsResult: productsResultSorted,
|
|
69
|
-
topProducts
|
|
35
|
+
topProducts,
|
|
70
36
|
otherProducts: difference_1.default(productsResultSorted, topProducts),
|
|
71
37
|
};
|
|
72
38
|
};
|
|
@@ -77,16 +43,15 @@ exports.handleProductSearchResponse = handleProductSearchResponse;
|
|
|
77
43
|
* @param productsResultEntitled IProductV2[]
|
|
78
44
|
* @returns ITroubleshootProductResponse
|
|
79
45
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return __assign(__assign({}, product), { product: product.name, isEntitledProduct: true });
|
|
46
|
+
const handleEntitledProductResponse = (productsResultEntitled = []) => {
|
|
47
|
+
const productsResult = productsResultEntitled.map((product) => {
|
|
48
|
+
return Object.assign(Object.assign({}, product), { product: product.name, isEntitledProduct: true });
|
|
84
49
|
});
|
|
85
|
-
|
|
86
|
-
|
|
50
|
+
const topProducts = getTopProducts(productsResult);
|
|
51
|
+
const productsResultSorted = orderBy_1.default(productsResult, ['product'], ['asc']);
|
|
87
52
|
return {
|
|
88
53
|
productsResult: productsResultSorted,
|
|
89
|
-
topProducts
|
|
54
|
+
topProducts,
|
|
90
55
|
otherProducts: difference_1.default(productsResultSorted, topProducts),
|
|
91
56
|
};
|
|
92
57
|
};
|
|
@@ -96,12 +61,11 @@ exports.handleEntitledProductResponse = handleEntitledProductResponse;
|
|
|
96
61
|
* before checking general top products from un-authed SE API
|
|
97
62
|
* @param products Partial<ISEProduct>
|
|
98
63
|
*/
|
|
99
|
-
function getTopProducts(products, topCount) {
|
|
100
|
-
|
|
101
|
-
var toReturn = remove_1.default(__spreadArray([], __read(products)), function (o) { return o.recentlyFiledAgainst; });
|
|
64
|
+
function getTopProducts(products, topCount = 5) {
|
|
65
|
+
const toReturn = remove_1.default([...products], (o) => o.recentlyFiledAgainst);
|
|
102
66
|
if (toReturn.length < topCount) {
|
|
103
|
-
|
|
104
|
-
toReturn.push
|
|
67
|
+
const generalTopProducts = remove_1.default([...products], (o) => !o.recentlyFiledAgainst && o.isTopProduct);
|
|
68
|
+
toReturn.push(...generalTopProducts);
|
|
105
69
|
}
|
|
106
70
|
return toReturn.slice(0, topCount);
|
|
107
71
|
}
|
|
@@ -118,13 +82,13 @@ function getUniqueSortedVersions(versions) {
|
|
|
118
82
|
return exports.versionSort(uniq_1.default(versions));
|
|
119
83
|
}
|
|
120
84
|
exports.getUniqueSortedVersions = getUniqueSortedVersions;
|
|
121
|
-
|
|
85
|
+
const versionSorter = (_a, _b) => {
|
|
122
86
|
//Added because of wrong order of versions
|
|
123
|
-
|
|
124
|
-
|
|
87
|
+
let a = _a.match(/(\d+|\w+)/gm);
|
|
88
|
+
let b = _b.match(/(\d+|\w+)/gm);
|
|
125
89
|
for (var i = 0; i < (a.length > b.length ? a.length : b.length); i++) {
|
|
126
|
-
|
|
127
|
-
|
|
90
|
+
const x = parseInt(a[i]) || a[i];
|
|
91
|
+
const y = parseInt(b[i]) || b[i];
|
|
128
92
|
if (x === undefined || x < y) {
|
|
129
93
|
return 1;
|
|
130
94
|
}
|
|
@@ -141,16 +105,16 @@ var versionSorter = function (_a, _b) {
|
|
|
141
105
|
return 0;
|
|
142
106
|
};
|
|
143
107
|
exports.versionSorter = versionSorter;
|
|
144
|
-
|
|
108
|
+
const versionSort = (arr) => {
|
|
145
109
|
return arr.sort(exports.versionSorter);
|
|
146
110
|
};
|
|
147
111
|
exports.versionSort = versionSort;
|
|
148
112
|
function getVersion(version) {
|
|
149
113
|
// 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)
|
|
150
|
-
|
|
114
|
+
const versionPartsArray = version.split(' ');
|
|
151
115
|
// find the index that has the version and split it into its parts
|
|
152
|
-
|
|
153
|
-
|
|
116
|
+
const indexOfVersion = versionPartsArray.findIndex((p) => p.includes('.'));
|
|
117
|
+
const splitArray = indexOfVersion > -1 ? versionPartsArray[indexOfVersion].split('.') : version.split('.');
|
|
154
118
|
// if the length of the split array is not 2, or 3 it is not a regular version
|
|
155
119
|
// b/c version === major.minor.patch (patch === component in the request body)
|
|
156
120
|
if (splitArray.length !== 2 && splitArray.length !== 3 && splitArray.length !== 4)
|
|
@@ -168,9 +132,7 @@ function getVersion(version) {
|
|
|
168
132
|
exports.getVersion = getVersion;
|
|
169
133
|
function isSpecialSupportOfferingEnabled(allProducts, selectedProduct) {
|
|
170
134
|
var _c;
|
|
171
|
-
|
|
172
|
-
return product === selectedProduct && product.hasSpecialSupportOffering ? true : false;
|
|
173
|
-
});
|
|
135
|
+
const productDetails = (((_c = allProducts.data) === null || _c === void 0 ? void 0 : _c.productsResult) || []).find((product) => product === selectedProduct && product.hasSpecialSupportOffering ? true : false);
|
|
174
136
|
return productDetails ? true : false;
|
|
175
137
|
}
|
|
176
138
|
exports.isSpecialSupportOfferingEnabled = isSpecialSupportOfferingEnabled;
|
package/lib/cjs/promiseUtils.js
CHANGED
|
@@ -8,51 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.promiseReflection = void 0;
|
|
40
13
|
// Promise.allSetteled is not supported in IE11. Here we use a helper function to mock the functionality
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return [2 /*return*/, { v: v, status: 'fulfilled' }];
|
|
51
|
-
case 2:
|
|
52
|
-
e_1 = _a.sent();
|
|
53
|
-
return [2 /*return*/, { e: e_1, status: 'rejected' }];
|
|
54
|
-
case 3: return [2 /*return*/];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}); };
|
|
14
|
+
const promiseReflection = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
const v = yield p;
|
|
17
|
+
return { v, status: 'fulfilled' };
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return { e, status: 'rejected' };
|
|
21
|
+
}
|
|
22
|
+
});
|
|
58
23
|
exports.promiseReflection = promiseReflection;
|