@nuskin/ns-product-lib 2.7.0-cx24-3682.26 → 2.7.0-cx24-3702.5
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/CHANGELOG.md +19 -150
- package/package.json +2 -2
- package/src/equinox-helpers/childSKU.js +1 -1
- package/src/equinox-helpers/index.js +31 -173
- package/src/product.js +69 -82
- package/src/productData.js +43 -43
- package/src/equinox-helpers/interceptors/index.js +0 -5
- package/src/equinox-helpers/interceptors/productNotFound.js +0 -72
- package/src/equinox-helpers/mappers/identifier.js +0 -13
- package/src/equinox-helpers/mappers/index.js +0 -13
- package/src/equinox-helpers/mappers/inventoryProperties.js +0 -173
- package/src/equinox-helpers/mappers/properties.js +0 -169
- package/src/equinox-helpers/mappers/variant.js +0 -51
- package/src/equinox-helpers/mappers/variantProperties.js +0 -273
- package/src/equinox-helpers/models/index.js +0 -5
- package/src/equinox-helpers/models/productNotFound.js +0 -48
@@ -1,72 +0,0 @@
|
|
1
|
-
const { getCachedConfiguration } = require('@nuskin/configuration-sdk');
|
2
|
-
const { productNotFound } = require('../models');
|
3
|
-
|
4
|
-
// httpStatus codes
|
5
|
-
const httpStatus = { notFound: 404 };
|
6
|
-
|
7
|
-
/**
|
8
|
-
* productNotFoundInterceptor returns a model "ProductNotFound" when the status code is Not Found.
|
9
|
-
* Note: Do not polute this file. Create a new file for new interceptor.
|
10
|
-
*
|
11
|
-
* @param {import('axios').AxiosError} error
|
12
|
-
* @returns {import('axios').AxiosResponse<import('../').EquinoxResponse>}
|
13
|
-
*/
|
14
|
-
function productNotFoundInterceptor(error) {
|
15
|
-
const segments = 'catalogs/search';
|
16
|
-
const { config, response } = error;
|
17
|
-
|
18
|
-
if (response.status === httpStatus.notFound && config.url.includes(segments)) {
|
19
|
-
const params = new URLSearchParams(config.url);
|
20
|
-
const filterParam = Array.from(params.values())[0];
|
21
|
-
const sku = getSKU(filterParam);
|
22
|
-
|
23
|
-
if (sku !== null) {
|
24
|
-
const market = getCachedConfiguration('Equinox_Markets').country_code;
|
25
|
-
const response = {
|
26
|
-
...error.response,
|
27
|
-
data: {
|
28
|
-
product: [
|
29
|
-
productNotFound({ identifier: sku, exists: false }, market)
|
30
|
-
]
|
31
|
-
},
|
32
|
-
statusText: getStatusText(error.response)
|
33
|
-
};
|
34
|
-
|
35
|
-
return response;
|
36
|
-
}
|
37
|
-
|
38
|
-
console.error('Unable to detect SKU from the given parameter', filterParam);
|
39
|
-
}
|
40
|
-
|
41
|
-
return Promise.reject(error);
|
42
|
-
}
|
43
|
-
|
44
|
-
/**
|
45
|
-
* getSKU returns the SKU from the given parameter.
|
46
|
-
* @param {string} param '\\''index_key_productId="02010489" OR index_key_skuId="02010489"'''
|
47
|
-
* @returns {string|null} SKU
|
48
|
-
*/
|
49
|
-
function getSKU(param) {
|
50
|
-
const result = param.match(/\d{8}/);
|
51
|
-
|
52
|
-
if (result === null) {
|
53
|
-
return null;
|
54
|
-
}
|
55
|
-
|
56
|
-
return result[0];
|
57
|
-
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* @param {import('axios').AxiosResponse<import('../').EquinoxErrorResponse>} [response]
|
61
|
-
* @returns {string}
|
62
|
-
*/
|
63
|
-
function getStatusText(response) {
|
64
|
-
if (response) {
|
65
|
-
const { code, message, timestamp } = response.data;
|
66
|
-
return `Floating product found -- ${timestamp} ${code}: ${message}`;
|
67
|
-
}
|
68
|
-
|
69
|
-
return '';
|
70
|
-
}
|
71
|
-
|
72
|
-
module.exports = productNotFoundInterceptor;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
const mapIdentifier = require('./identifier');
|
2
|
-
const mapInventoryProperties = require('./inventoryProperties');
|
3
|
-
const mapProperties = require('./properties');
|
4
|
-
const mapVariant = require('./variant');
|
5
|
-
const mapVariantProperties = require('./variantProperties');
|
6
|
-
|
7
|
-
module.exports = {
|
8
|
-
mapIdentifier,
|
9
|
-
mapInventoryProperties,
|
10
|
-
mapProperties,
|
11
|
-
mapVariant,
|
12
|
-
mapVariantProperties
|
13
|
-
};
|
@@ -1,173 +0,0 @@
|
|
1
|
-
// @ts-check
|
2
|
-
|
3
|
-
/**
|
4
|
-
* @param {import('../').EquinoxProductInventoryProperties} inventoryProperties
|
5
|
-
*/
|
6
|
-
function mapInventoryProperties(inventoryProperties = {}) {
|
7
|
-
/** @type {import('../').EquinoxProductInventoryProperties} */
|
8
|
-
const model = {};
|
9
|
-
model.available = mapAvailable(inventoryProperties.available);
|
10
|
-
model.lowStock = mapLowStock(inventoryProperties.lowStock);
|
11
|
-
model.binName = mapBinName(inventoryProperties.binName);
|
12
|
-
model.backOrdered = mapBackOrdered(inventoryProperties.backOrdered);
|
13
|
-
model.expectedBackOrderAvailabilityDate = mapExpectedBackOrderAvailabilityDate(
|
14
|
-
inventoryProperties.expectedBackOrderAvailabilityDate
|
15
|
-
);
|
16
|
-
model.preOrdered = mapPreOrdered(inventoryProperties.preOrdered);
|
17
|
-
model.expectedPreOrderAvailabilityDate = mapExpectedPreOrderAvailabilityDate(
|
18
|
-
inventoryProperties.expectedPreOrderAvailabilityDate
|
19
|
-
);
|
20
|
-
model.atpQty = mapAtpQty(inventoryProperties.atpQty);
|
21
|
-
model.preOrderedQty = mapPreOrderedQty(inventoryProperties.preOrderedQty);
|
22
|
-
model.backOrderedQty = mapBackOrderedQty(inventoryProperties.backOrderedQty);
|
23
|
-
model.lowStockThreshold = mapLowStockThreshold(inventoryProperties.lowStockThreshold);
|
24
|
-
model.outOfStockThreshold = mapOutOfStockThreshold(inventoryProperties.outOfStockThreshold);
|
25
|
-
|
26
|
-
return model;
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
* @param {boolean|undefined} available
|
31
|
-
* @returns {boolean}
|
32
|
-
*/
|
33
|
-
function mapAvailable(available) {
|
34
|
-
if (available) {
|
35
|
-
return available;
|
36
|
-
}
|
37
|
-
|
38
|
-
return false;
|
39
|
-
}
|
40
|
-
|
41
|
-
/**
|
42
|
-
* @param {boolean|undefined} lowStock
|
43
|
-
* @returns {boolean}
|
44
|
-
*/
|
45
|
-
function mapLowStock(lowStock) {
|
46
|
-
if (lowStock) {
|
47
|
-
return lowStock;
|
48
|
-
}
|
49
|
-
|
50
|
-
return false;
|
51
|
-
}
|
52
|
-
|
53
|
-
/**
|
54
|
-
* @param {string|undefined} binName
|
55
|
-
* @returns {string}
|
56
|
-
*/
|
57
|
-
function mapBinName(binName) {
|
58
|
-
if (binName) {
|
59
|
-
return binName;
|
60
|
-
}
|
61
|
-
|
62
|
-
return '';
|
63
|
-
}
|
64
|
-
|
65
|
-
/**
|
66
|
-
* @param {boolean|undefined} backOrdered
|
67
|
-
* @returns {boolean}
|
68
|
-
*/
|
69
|
-
function mapBackOrdered(backOrdered) {
|
70
|
-
if (backOrdered) {
|
71
|
-
return backOrdered;
|
72
|
-
}
|
73
|
-
|
74
|
-
return false;
|
75
|
-
}
|
76
|
-
|
77
|
-
/**
|
78
|
-
* @param {number|undefined} expectedBackOrderAvailabilityDate
|
79
|
-
* @returns {number}
|
80
|
-
*/
|
81
|
-
function mapExpectedBackOrderAvailabilityDate(expectedBackOrderAvailabilityDate) {
|
82
|
-
if (expectedBackOrderAvailabilityDate) {
|
83
|
-
return expectedBackOrderAvailabilityDate;
|
84
|
-
}
|
85
|
-
|
86
|
-
return 0;
|
87
|
-
}
|
88
|
-
|
89
|
-
/**
|
90
|
-
* @param {boolean|undefined} preOrdered
|
91
|
-
* @returns {boolean}
|
92
|
-
*/
|
93
|
-
function mapPreOrdered(preOrdered) {
|
94
|
-
if (preOrdered) {
|
95
|
-
return preOrdered;
|
96
|
-
}
|
97
|
-
|
98
|
-
return false;
|
99
|
-
}
|
100
|
-
|
101
|
-
/**
|
102
|
-
* @param {number|undefined} expectedPreOrderAvailabilityDate
|
103
|
-
* @returns {number}
|
104
|
-
*/
|
105
|
-
function mapExpectedPreOrderAvailabilityDate(expectedPreOrderAvailabilityDate) {
|
106
|
-
if (expectedPreOrderAvailabilityDate) {
|
107
|
-
return expectedPreOrderAvailabilityDate;
|
108
|
-
}
|
109
|
-
|
110
|
-
return 0;
|
111
|
-
}
|
112
|
-
|
113
|
-
/**
|
114
|
-
* @param {number|undefined} atpQty
|
115
|
-
* @returns {number}
|
116
|
-
*/
|
117
|
-
function mapAtpQty(atpQty) {
|
118
|
-
if (atpQty) {
|
119
|
-
return atpQty;
|
120
|
-
}
|
121
|
-
|
122
|
-
return 0;
|
123
|
-
}
|
124
|
-
|
125
|
-
/**
|
126
|
-
* @param {number|undefined} preOrderedQty
|
127
|
-
* @returns {number}
|
128
|
-
*/
|
129
|
-
function mapPreOrderedQty(preOrderedQty) {
|
130
|
-
if (preOrderedQty) {
|
131
|
-
return preOrderedQty;
|
132
|
-
}
|
133
|
-
|
134
|
-
return 0;
|
135
|
-
}
|
136
|
-
|
137
|
-
/**
|
138
|
-
* @param {number|undefined} backOrderedQty
|
139
|
-
* @returns {number}
|
140
|
-
*/
|
141
|
-
function mapBackOrderedQty(backOrderedQty) {
|
142
|
-
if (backOrderedQty) {
|
143
|
-
return backOrderedQty;
|
144
|
-
}
|
145
|
-
|
146
|
-
return 0;
|
147
|
-
}
|
148
|
-
|
149
|
-
/**
|
150
|
-
* @param {number|null|undefined} lowStockThreshold
|
151
|
-
* @returns {number|null}
|
152
|
-
*/
|
153
|
-
function mapLowStockThreshold(lowStockThreshold) {
|
154
|
-
if (lowStockThreshold) {
|
155
|
-
return lowStockThreshold;
|
156
|
-
}
|
157
|
-
|
158
|
-
return null;
|
159
|
-
}
|
160
|
-
|
161
|
-
/**
|
162
|
-
* @param {number|null|undefined} outOfStockThreshold
|
163
|
-
* @returns {number|null}
|
164
|
-
*/
|
165
|
-
function mapOutOfStockThreshold(outOfStockThreshold) {
|
166
|
-
if (outOfStockThreshold) {
|
167
|
-
return outOfStockThreshold;
|
168
|
-
}
|
169
|
-
|
170
|
-
return null;
|
171
|
-
}
|
172
|
-
|
173
|
-
module.exports = mapInventoryProperties;
|
@@ -1,169 +0,0 @@
|
|
1
|
-
// @ts-check
|
2
|
-
/**
|
3
|
-
* mapProperties maps the properties of a product.
|
4
|
-
* @param {import('../').EquinoxProductProperties} props
|
5
|
-
*/
|
6
|
-
function mapProperties(props = {}) {
|
7
|
-
/** @type {import('../').EquinoxProductProperties} */
|
8
|
-
const properties = {};
|
9
|
-
properties.name = mapName(props.name);
|
10
|
-
properties.description = mapDescription(props.description);
|
11
|
-
properties.productDetailsDescription = mapProductDetailsDescription(props.productDetailsDescription);
|
12
|
-
properties.ingredients = mapIngredients(props.ingredients);
|
13
|
-
properties.benefits = mapBenefits(props.benefits);
|
14
|
-
properties.usage = mapUsage(props.usage);
|
15
|
-
properties.scanQualifiedCount = mapScanQualifiedCount(props.scanQualifiedCount);
|
16
|
-
properties.division = mapDivision(props.division);
|
17
|
-
properties.imageURL = mapImageURL(props.imageURL);
|
18
|
-
properties.resources = mapResources(props.resources);
|
19
|
-
properties.customerTypes = mapCustomerTypes(props.customerTypes);
|
20
|
-
properties.size = mapSize(props.size);
|
21
|
-
|
22
|
-
return properties;
|
23
|
-
}
|
24
|
-
|
25
|
-
/**
|
26
|
-
* @param {string|undefined} name
|
27
|
-
* @returns {string}
|
28
|
-
*/
|
29
|
-
function mapName(name) {
|
30
|
-
if (name) {
|
31
|
-
return name;
|
32
|
-
}
|
33
|
-
|
34
|
-
return '';
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* @param {string|undefined} description
|
39
|
-
* @returns {string}
|
40
|
-
*/
|
41
|
-
function mapDescription(description) {
|
42
|
-
if (description) {
|
43
|
-
return description;
|
44
|
-
}
|
45
|
-
|
46
|
-
return '';
|
47
|
-
}
|
48
|
-
|
49
|
-
/**
|
50
|
-
* @param {string|undefined} productDetailsDescription
|
51
|
-
* @returns {string}
|
52
|
-
*/
|
53
|
-
function mapProductDetailsDescription(productDetailsDescription) {
|
54
|
-
if (productDetailsDescription) {
|
55
|
-
return productDetailsDescription;
|
56
|
-
}
|
57
|
-
|
58
|
-
return '';
|
59
|
-
}
|
60
|
-
|
61
|
-
/**
|
62
|
-
* @param {string|undefined} ingredients
|
63
|
-
* @returns {string}
|
64
|
-
*/
|
65
|
-
function mapIngredients(ingredients) {
|
66
|
-
if (ingredients) {
|
67
|
-
return ingredients;
|
68
|
-
}
|
69
|
-
|
70
|
-
return '';
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* @param {string|undefined} benefits
|
75
|
-
* @returns {string}
|
76
|
-
*/
|
77
|
-
function mapBenefits(benefits) {
|
78
|
-
if (benefits) {
|
79
|
-
return benefits;
|
80
|
-
}
|
81
|
-
|
82
|
-
return '';
|
83
|
-
}
|
84
|
-
|
85
|
-
/**
|
86
|
-
* @param {string|undefined} usage
|
87
|
-
* @returns {string}
|
88
|
-
*/
|
89
|
-
function mapUsage(usage) {
|
90
|
-
if (usage) {
|
91
|
-
return usage;
|
92
|
-
}
|
93
|
-
|
94
|
-
return '';
|
95
|
-
}
|
96
|
-
|
97
|
-
/**
|
98
|
-
* @param {string|undefined} scanQualifiedCount
|
99
|
-
* @returns {string}
|
100
|
-
*/
|
101
|
-
function mapScanQualifiedCount(scanQualifiedCount) {
|
102
|
-
if (scanQualifiedCount) {
|
103
|
-
return scanQualifiedCount;
|
104
|
-
}
|
105
|
-
|
106
|
-
return '';
|
107
|
-
}
|
108
|
-
|
109
|
-
/**
|
110
|
-
* @param {string|undefined} division
|
111
|
-
* @returns {string}
|
112
|
-
*/
|
113
|
-
function mapDivision(division) {
|
114
|
-
if (division) {
|
115
|
-
return division;
|
116
|
-
}
|
117
|
-
|
118
|
-
return '';
|
119
|
-
}
|
120
|
-
|
121
|
-
/**
|
122
|
-
* @param {string|undefined} imageURL
|
123
|
-
* @returns {string}
|
124
|
-
*/
|
125
|
-
function mapImageURL(imageURL) {
|
126
|
-
if (imageURL) {
|
127
|
-
return imageURL;
|
128
|
-
}
|
129
|
-
|
130
|
-
return '';
|
131
|
-
}
|
132
|
-
|
133
|
-
/**
|
134
|
-
* @param {string|undefined} resources
|
135
|
-
* @returns {string}
|
136
|
-
*/
|
137
|
-
function mapResources(resources) {
|
138
|
-
if (resources) {
|
139
|
-
return resources;
|
140
|
-
}
|
141
|
-
|
142
|
-
return '';
|
143
|
-
}
|
144
|
-
|
145
|
-
/**
|
146
|
-
* @param {string|undefined} customerTypes
|
147
|
-
* @returns {string}
|
148
|
-
*/
|
149
|
-
function mapCustomerTypes(customerTypes) {
|
150
|
-
if (customerTypes) {
|
151
|
-
return customerTypes;
|
152
|
-
}
|
153
|
-
|
154
|
-
return '';
|
155
|
-
}
|
156
|
-
|
157
|
-
/**
|
158
|
-
* @param {string|undefined} size
|
159
|
-
* @returns {string}
|
160
|
-
*/
|
161
|
-
function mapSize(size) {
|
162
|
-
if (size) {
|
163
|
-
return size;
|
164
|
-
}
|
165
|
-
|
166
|
-
return '';
|
167
|
-
}
|
168
|
-
|
169
|
-
module.exports = mapProperties;
|
@@ -1,51 +0,0 @@
|
|
1
|
-
// @ts-check
|
2
|
-
const mapIdentifier = require('./identifier');
|
3
|
-
const mapInventoryProperties = require('./inventoryProperties');
|
4
|
-
const mapVariantProperties = require('./variantProperties');
|
5
|
-
|
6
|
-
/**
|
7
|
-
* @param {import('../').EquinoxProductVariant} variant
|
8
|
-
*/
|
9
|
-
function mapVariant(variant) {
|
10
|
-
/** @type {import('../').EquinoxProductVariant} */
|
11
|
-
const model = {
|
12
|
-
identifier: mapIdentifier(variant.identifier),
|
13
|
-
inventory: '',
|
14
|
-
properties: mapVariantProperties(variant.properties),
|
15
|
-
promotion: [],
|
16
|
-
priceFacets: {
|
17
|
-
CV: '',
|
18
|
-
PV: '',
|
19
|
-
SB: '',
|
20
|
-
'Wholesale Price': '',
|
21
|
-
'Regular Price': ''
|
22
|
-
},
|
23
|
-
inventoryProperties: mapInventoryProperties(variant.inventoryProperties),
|
24
|
-
totalValue: {
|
25
|
-
originalPrice: 0,
|
26
|
-
priceAfterDiscount: 0,
|
27
|
-
priceFacets: {
|
28
|
-
CV: {
|
29
|
-
CV: 36
|
30
|
-
},
|
31
|
-
'Regular Price': {
|
32
|
-
'Regular Price': 52
|
33
|
-
},
|
34
|
-
PV: {
|
35
|
-
PV: 25.65
|
36
|
-
},
|
37
|
-
'Wholesale Price': {
|
38
|
-
'Wholesale Price': 42
|
39
|
-
},
|
40
|
-
SB: {
|
41
|
-
SB: 2
|
42
|
-
}
|
43
|
-
},
|
44
|
-
totaldiscount: 0
|
45
|
-
}
|
46
|
-
};
|
47
|
-
|
48
|
-
return model;
|
49
|
-
}
|
50
|
-
|
51
|
-
module.exports = mapVariant;
|