@nuskin/cs-product-lib 1.0.32 → 1.1.0-subscription-dc.2

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/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@nuskin/cs-product-lib",
3
- "version": "1.0.32",
3
+ "version": "1.1.0-subscription-dc.2",
4
4
  "description": "Library for pulling and parsing product content (and applying business logic) retrieved from Contentstack",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "audit": "yarn audit --level high",
8
8
  "jsdoc": "node_modules/.bin/jsdoc -a all -c jsdoc.json -r -d jsdocs",
9
9
  "lint": "eslint src __tests__",
10
- "test": "jest --coverage",
10
+ "test": "jest --coverage --testPathPattern=__tests__",
11
11
  "security-check": "yarn audit --groups 'dependencies devDependencies' --level high",
12
+ "test-integration": "jest --testPathPattern=e2e",
12
13
  "sc": "yarn security-check"
13
14
  },
14
15
  "publishConfig": {
@@ -19,7 +20,7 @@
19
20
  "url": "git@code.tls.nuskin.io:ns-am/product/js-libs/cs-product-lib.git"
20
21
  },
21
22
  "keywords": [],
22
- "author": "Nuskin BFF Team",
23
+ "author": "Nuskin Browse Team",
23
24
  "license": "MIT",
24
25
  "homepage": "https://code.tls.nuskin.io/ns-am/product/js-libs/cs-product-lib/blob/master/README.md",
25
26
  "devDependencies": {
package/src/formatKit.js CHANGED
@@ -1,4 +1,5 @@
1
- const { isNullOrEmpty, isTrue } = require('@nuskin/ns-common-lib')
1
+ const { isNullOrEmpty, isTrue } = require('@nuskin/ns-common-lib');
2
+ const { formatDiscounts } = require('./helpers/formatDiscounts');
2
3
  const moment = require('moment')
3
4
 
4
5
  const parseStatus = (variant) => {
@@ -206,6 +207,8 @@ const parseKit = (product, market) => {
206
207
  buyOnce: kits?.availableChannels?.includes('web'),
207
208
  subscription: kits?.availableChannels?.includes('subscription')
208
209
  }
210
+
211
+ kits.subscriptionDiscounts = formatDiscounts(properties, 'subscriptionDiscounts');
209
212
  kits.retailDiscount = properties?.retailDiscount
210
213
  kits.wholesaleDiscount = properties?.wholesaleDiscount
211
214
  kits.pvDiscount = properties?.pvDiscount
@@ -0,0 +1,17 @@
1
+ const { get } = require('lodash');
2
+
3
+ const formatDiscounts = (parent, key = 'discounts') => {
4
+ const isDiscount = key === 'discounts';
5
+ return {
6
+ retailDiscount: get(parent, `${key}.retailDiscount`, isDiscount ? get(parent, 'rtlpricedis', 0) : 0),
7
+ wholesaleDiscount: get(parent, `${key}.wholesaleDiscount`, isDiscount ? get(parent, 'whlpricedis', 0) : 0),
8
+ pvDiscount: get(parent, `${key}.pvDiscount`, isDiscount ? get(parent, 'pvdis', 0) : 0),
9
+ cvDiscount: get(parent, `${key}.cvDiscount`, isDiscount ? get(parent, 'cvdis', 0) : 0),
10
+ sbDiscount: get(parent, `${key}.sbDiscount`, isDiscount ? get(parent, 'sbdis', 0) : 0),
11
+ grpDiscount: get(parent, `${key}.grpDiscount`, isDiscount ? get(parent, 'grpdis', 0) : 0)
12
+ }
13
+ }
14
+
15
+ module.exports = {
16
+ formatDiscounts
17
+ };
@@ -1,4 +1,5 @@
1
1
  const helpers = require('./helpers')
2
+ const { formatDiscounts } = require('./helpers/formatDiscounts');
2
3
 
3
4
  /* istanbul ignore next */
4
5
  const transformBundle = (parent, homeUrl) => ({
@@ -14,12 +15,8 @@ const transformBundle = (parent, homeUrl) => ({
14
15
  product: o?.product?.[0],
15
16
  quantity: o.quantity
16
17
  })),
17
- retailDiscount: parent?.discounts?.retailDiscount || parent?.rtlpricedis || 0,
18
- wholesaleDiscount: parent?.discounts?.wholesaleDiscount || parent?.whlpricedis || 0,
19
- pvDiscount: parent?.discounts?.pvDiscount || parent?.pvdis || 0,
20
- cvDiscount: parent?.discounts?.cvDiscount || parent?.cvdis || 0,
21
- sbDiscount: parent?.discounts?.sbDiscount || parent?.sbdis || 0,
22
- grpDiscount: parent?.discounts?.grpDiscount || parent?.grpdis || 0,
18
+ ...formatDiscounts(parent),
19
+ subscriptionDiscounts: formatDiscounts(parent, 'subscription_discounts'),
23
20
  shortDescription: parent?.short_description,
24
21
  description: helpers?.createMarkdown(parent?.description),
25
22
  salesLabel: parent?.sales_label,