@nuskin/ns-shop 5.11.12 → 5.11.15-app-testing.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-shop",
3
- "version": "5.11.12",
3
+ "version": "5.11.15-app-testing.1",
4
4
  "description": "The description that will amaze and astound your audience when they read it",
5
5
  "main": "src/shop.js",
6
6
  "scripts": {
package/src/cart/cart.js CHANGED
@@ -847,7 +847,7 @@ export default function Cart(cartData) {
847
847
  nameMap[name] = name;
848
848
  });
849
849
  Object.keys(nameMap).forEach(eventName => {
850
- events.publish(events.salesEvent.INIT_EVENT_TICKET, eventName);
850
+ events.publish(events.salesevent.INIT_EVENT_TICKET, eventName);
851
851
  });
852
852
  }
853
853
 
@@ -1,21 +1,23 @@
1
- import $ from '@nuskin/nuskinjquery';
2
- import {RunConfigService} from '@nuskin/ns-util';
1
+ import { RunConfigService, events } from "@nuskin/ns-util";
3
2
 
4
- let CurrencyService = function() {
3
+ import $ from "@nuskin/nuskinjquery";
4
+
5
+ let CurrencyService = (function() {
5
6
  let byCountry = {},
6
7
  byCurrencyCode = {},
7
8
  runConfig = {};
8
9
 
9
- function init() {
10
- if (!runConfig.hasOwnProperty("country")) {
11
- runConfig = RunConfigService.getRunConfig();
12
- }
10
+ function setRunConfig() {
11
+ runConfig = RunConfigService.getRunConfig();
13
12
  }
14
13
 
15
14
  function getCurrency(country) {
16
- init();
15
+ if (!runConfig) {
16
+ setRunConfig();
17
+ }
18
+
17
19
  let currency = byCountry[country],
18
- baseUrl = runConfig.assessmentApp ? '' : runConfig.baseUrl;
20
+ baseUrl = runConfig.assessmentApp ? "" : runConfig.baseUrl;
19
21
 
20
22
  if (typeof baseUrl === "undefined") {
21
23
  baseUrl = "";
@@ -24,7 +26,7 @@ let CurrencyService = function() {
24
26
  if (!currency) {
25
27
  $.ajax({
26
28
  type: "GET",
27
- url: baseUrl + '/content/configuration/currencies.service.' + country + '.json',
29
+ url: `${baseUrl}/content/configuration/currencies.service.${country}.json`,
28
30
  dataType: "json",
29
31
  async: false,
30
32
  success: function(data) {
@@ -35,7 +37,7 @@ let CurrencyService = function() {
35
37
  }
36
38
  },
37
39
  error: function(xhr) {
38
- console.error("could not get the market's currency! error:"+xhr);
40
+ console.error("could not get the market's currency! error:" + xhr);
39
41
  }
40
42
  });
41
43
  }
@@ -45,23 +47,25 @@ let CurrencyService = function() {
45
47
  function setDefaults(currency) {
46
48
  if (currency) {
47
49
  if (!currency.delimiter) {
48
- currency.delimiter = ',';
50
+ currency.delimiter = ",";
49
51
  }
50
52
  if (!currency.decimal) {
51
- currency.decimal = '.';
53
+ currency.decimal = ".";
52
54
  }
53
55
  }
54
56
  }
55
57
 
56
58
  function getCountryKey(_country, _language) {
57
- init();
58
- let country,
59
- language;
59
+ if (!runConfig) {
60
+ setRunConfig();
61
+ }
62
+
63
+ let country, language;
60
64
 
61
65
  country = _country || runConfig.country;
62
66
  language = _language || runConfig.language;
63
- if (country === 'CA' && language === 'fr') {
64
- country = language + '_' + country;
67
+ if (country === "CA" && language === "fr") {
68
+ country = language + "_" + country;
65
69
  }
66
70
 
67
71
  return country;
@@ -71,7 +75,7 @@ let CurrencyService = function() {
71
75
  // Make sure the amount is a number.
72
76
  let initializedNumber = parseFloat(amount);
73
77
  if (isNaN(initializedNumber)) {
74
- initializedNumber = 0.00;
78
+ initializedNumber = 0.0;
75
79
  }
76
80
  return initializedNumber;
77
81
  }
@@ -79,12 +83,12 @@ let CurrencyService = function() {
79
83
  function applyAccuracyDelimiterDecimal(currency, amount) {
80
84
  let p = amount.toFixed(currency.accuracy).split("."),
81
85
  chars = p[0].split("").reverse(),
82
- newstr = '',
86
+ newstr = "",
83
87
  count = 0;
84
88
 
85
89
  for (let x = 0; x < chars.length; x++) {
86
90
  count++;
87
- if (count%3 == 1 && count != 1) {
91
+ if (count % 3 == 1 && count != 1) {
88
92
  // Add in the delimiter
89
93
  newstr = chars[x] + currency.delimiter + newstr;
90
94
  } else {
@@ -103,7 +107,7 @@ let CurrencyService = function() {
103
107
  }
104
108
 
105
109
  function applySymbol(currency, amount) {
106
- if (currency.after === 'true'){
110
+ if (currency.after === "true") {
107
111
  amount = amount + currency.symbol;
108
112
  } else {
109
113
  if (amount < 0) {
@@ -111,29 +115,41 @@ let CurrencyService = function() {
111
115
  } else {
112
116
  amount = currency.symbol + amount;
113
117
  }
114
-
115
118
  }
116
119
  return amount;
117
120
  }
118
121
 
119
- function parseCurrencyStringToFloat(currencyString, thousandsDelimiter, currencySymbol) {
122
+ function parseCurrencyStringToFloat(
123
+ currencyString,
124
+ thousandsDelimiter,
125
+ currencySymbol
126
+ ) {
127
+ if (!runConfig) {
128
+ setRunConfig();
129
+ }
120
130
 
121
131
  if (!thousandsDelimiter) {
122
132
  thousandsDelimiter = getCurrency(runConfig.country).delimiter;
123
133
  }
134
+
124
135
  if (!currencySymbol) {
125
- currencySymbol = getCurrency(runConfig.country).symbol ? getCurrency(runConfig.country).symbol : '';
136
+ currencySymbol = getCurrency(runConfig.country).symbol
137
+ ? getCurrency(runConfig.country).symbol
138
+ : "";
126
139
  }
127
- /* eslint-disable-next-line */
128
- const delimiterEscaped = thousandsDelimiter.replace(/\./g, '\\\.')
129
- const charactersToRemove = new RegExp(delimiterEscaped + '|' + currencySymbol, 'g');
140
+
141
+ const delimiterEscaped = thousandsDelimiter.replace(/\./g, "\\.");
142
+ const charactersToRemove = new RegExp(
143
+ `${delimiterEscaped}|${currencySymbol}`,
144
+ "g"
145
+ );
130
146
 
131
147
  return parseFloat(
132
148
  currencyString
133
- .replace(charactersToRemove, '') // remove the delimiters, they confuse parseFloat
134
- .replace(',', '.') // replace any remaining commas with periods. If these exist then we are in a market with non-regular decimals
135
- .replace(/[^\d.]/g, '') // remove extraneous characters
136
- )
149
+ .replace(charactersToRemove, "") // remove the delimiters, they confuse parseFloat
150
+ .replace(",", ".") // replace any remaining commas with periods. If these exist then we are in a market with non-regular decimals
151
+ .replace(/[^\d.]/g, "") // remove extraneous characters
152
+ );
137
153
  }
138
154
 
139
155
  let format = function(amount, country, language) {
@@ -150,12 +166,20 @@ let CurrencyService = function() {
150
166
  return formatted;
151
167
  };
152
168
 
169
+ /**
170
+ * RUN_CONFIG_CHANGED is published by ns-util when the runConfig is ready and when it changes.
171
+ * This will need to trigger setRunConfig so it is updated.
172
+ */
173
+ events.subscribe(events.global.RUN_CONFIG_CHANGED, setRunConfig);
174
+
175
+ setRunConfig();
176
+
153
177
  return {
154
178
  format: format,
155
179
  getCurrency: getCurrency,
156
- parseCurrencyStringToFloat: parseCurrencyStringToFloat/*,
180
+ parseCurrencyStringToFloat: parseCurrencyStringToFloat /*,
157
181
  getCurrencySymbol: getCurrencySymbol*/
158
- }
159
- }();
182
+ };
183
+ })();
160
184
 
161
185
  export default CurrencyService;
@@ -41,7 +41,7 @@ let ShopContextService = function() {
41
41
  // hardcoding months to 7 because only one market differentiates between wadwd and wadw in the cart for now -
42
42
  // if that changes will need to make a config
43
43
  if (user &&
44
- AdrService.getAdrMonths(storage.getItem(storage.metadata.ADR_CURRENT_ID)) > 7 &&
44
+ AdrService.getAdrMonths(storage.getItem(storage.metadata.ADR_CURRENT_ID)) >= 7 &&
45
45
  ConfigService.getMarketConfig().adpManage.EligibleWADWD) {
46
46
  priceType = PriceType.WADWD;
47
47
  } else {