@nuskin/ns-shop 7.5.1-pa-64.1 → 7.5.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-shop",
3
- "version": "7.5.1-pa-64.1",
3
+ "version": "7.5.2",
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": {
@@ -13,9 +13,14 @@ let eid = '';
13
13
  let id = '';
14
14
 
15
15
  const ZZIP_URLS = {
16
- dev: 'https://zzip.api.dev.nuskin.com/v2/:country/:code',
17
- test: 'https://zzip.api.test.nuskin.com/v2/:country/:code',
18
- prod: 'https://zzip.api.nuskin.com/v2/:country/:code'
16
+ dev: 'https://apis.dev.nuskin.com/zzip/v2/:country/:code',
17
+ test: 'https://apis.test.nuskin.com/zzip/v2/:country/:code',
18
+ prod: 'https://apis.nuskin.com/zzip/v2/:country/:code'
19
+ };
20
+ const STREET_ADDRESS_VALIDATOR_URLS = {
21
+ dev: 'https://apis.dev.nuskin.com/street-address/v1/',
22
+ test: 'https://apis.test.nuskin.com/street-address/v1/',
23
+ prod: 'https://apis.nuskin.com/street-address/v1/'
19
24
  };
20
25
 
21
26
  const zzipCache = {}
@@ -173,8 +178,7 @@ async function getListOfCitiesFromPostalCode (country, zip) {
173
178
 
174
179
  zzipCache[cacheKey] = fetch(url, {
175
180
  method: 'GET',
176
- credentials: 'omit',
177
- headers: ServiceUtils.getHeaders()
181
+ credentials: 'omit'
178
182
  })
179
183
  .then(ServiceUtils.transformFetchResponse)
180
184
  .then(result => zzipCache[cacheKey] = result.zzipRecords);
@@ -230,8 +234,8 @@ function getHeaders(eid) {
230
234
  */
231
235
  async function useAddressValidationService(address) {
232
236
  const country = RunConfigService.getRunConfig().country;
233
- const awsUrl = UrlService.getAwsUrl();
234
- const url = `${awsUrl}/street-address-validator/v1/${country}`;
237
+ const env = RunConfigService.getEnvironmentCode();
238
+ const url = STREET_ADDRESS_VALIDATOR_URLS[env] + country;
235
239
  let response = await fetch(url, {
236
240
  method: 'POST',
237
241
  headers: getHeaders(),
@@ -4,6 +4,9 @@ import {RunConfigService} from '@nuskin/ns-util';
4
4
  import {OrderManager, CartService, OrderType, OrderAdapter} from '../shop';
5
5
  import axios from 'axios';
6
6
 
7
+ const SHIP_METHODS = 'shipMethods';
8
+ const PICK_UP_POINTS = 'pickUpPoints';
9
+
7
10
  let PickupUtil = function() {
8
11
  'use strict';
9
12
  const SERVICE_GROUP = 'SERVICE_GROUP',
@@ -165,79 +168,42 @@ let PickupUtil = function() {
165
168
  }
166
169
  }
167
170
 
168
- function getShipToData(order) {
169
- const shippingParties = order.shipping.shippingParties || [];
170
- const shipTo = shippingParties.find((sp) => sp.type === 'SHIP_TO') || {};
171
- return {
172
- country: shipTo.shippingAddress.address.countryCode,
173
- postalCode: shipTo.shippingAddress.address.postalCode,
174
- line1: `${shipTo.shippingAddress.address.street1}, ${shipTo.shippingAddress.address.city}`,
175
- line2: shipTo.shippingAddress.address.street2,
176
- city: shipTo.shippingAddress.address.city
177
- };
178
- }
179
-
180
- function samePayload(payload) {
181
- let same = false;
182
- const shipping = sessionStorage.getItem('shipping');
183
-
184
- if (shipping) {
185
- const storedPayload = JSON.parse(shipping).payload;
186
- const shipData = getShipToData(payload.order);
187
- const storedShipData = getShipToData(storedPayload.order);
188
- same = payload.country === storedPayload.country &&
189
- payload.dangerousGoods === storedPayload.dangerousGoods &&
190
- payload.orderValue === storedPayload.orderValue &&
191
- shipData.country === storedShipData.country &&
192
- shipData.postalCode === storedShipData.postalCode &&
193
- shipData.line1 === storedShipData.line1 &&
194
- shipData.line2 === storedShipData.line2 &&
195
- shipData.city === storedShipData.city
196
- }
197
- return same
198
- }
199
-
200
171
  function loadShipMethods() {
201
172
  const order = Order.fromSalesOrderRequest(OrderAdapter.populateSalesOrder('SIMULATE'));
202
173
  const {metapackMarket} = getCachedConfiguration('Checkout');
203
174
 
204
175
  if (metapackMarket) {
205
176
  const runConfig = RunConfigService.getRunConfig();
206
- const payload = {
207
- order,
208
- orderValue: getOrderValue(),
209
- dangerousGoods: CartService.hasDangerousGoods(),
210
- language: runConfig.language,
211
- country: runConfig.country
212
- };
213
- if (!samePayload(payload)) {
214
- promise = axios.post(
215
- getUrl(),
216
- payload,
217
- {
218
- headers: {
219
- 'Content-Type': 'application/json; charset=UTF-8'
220
- }
177
+ promise = axios.post(
178
+ getUrl(),
179
+ {
180
+ order,
181
+ orderValue: getOrderValue(),
182
+ dangerousGoods: CartService.hasDangerousGoods(),
183
+ language: runConfig.language,
184
+ country: runConfig.country
185
+ },
186
+ {
187
+ headers: {
188
+ 'Content-Type': 'application/json; charset=UTF-8'
221
189
  }
222
- ).then((results) => {
223
- sessionStorage.setItem('shipping', JSON.stringify({
224
- payload,
225
- shipMethods: results.data.shipMethods,
226
- pickUpPoints: results.data.pickupPoints
227
- }))
228
- }).catch((err) => {
229
- console.log(err);
230
- sessionStorage.setItem('shipping', JSON.stringify({payload: {}, shipMethods: [], pickUpPoints: []}));
231
- });
232
- }
190
+ }
191
+ ).then((results) => {
192
+ sessionStorage.setItem(SHIP_METHODS, JSON.stringify(results.data.shipMethods))
193
+ sessionStorage.setItem(PICK_UP_POINTS, JSON.stringify(results.data.pickupPoints))
194
+ }).catch((err) => {
195
+ console.log(err);
196
+ sessionStorage.setItem(SHIP_METHODS, JSON.stringify([]));
197
+ sessionStorage.setItem(PICK_UP_POINTS, JSON.stringify([]));
198
+ });
233
199
  }
234
200
  }
235
201
 
236
202
  // if the calling code knows that loadShipMethods has finished then this
237
203
  // function can be called directly if the calling function is not async.
238
204
  function getStoredShipMethods() {
239
- const shipping = sessionStorage.getItem('shipping');
240
- return shipping ? JSON.parse(shipping).shipMethods : [];
205
+ const shipMethods = sessionStorage.getItem(SHIP_METHODS);
206
+ return shipMethods ? JSON.parse(shipMethods) : [];
241
207
  }
242
208
 
243
209
  async function getShipMethods() {
@@ -249,8 +215,8 @@ let PickupUtil = function() {
249
215
  async function getPickupPoints() {
250
216
  await promise;
251
217
 
252
- const shipping = sessionStorage.getItem('shipping');
253
- return shipping ? JSON.parse(shipping).pickUpPoints : [];
218
+ const pups = sessionStorage.getItem(PICK_UP_POINTS);
219
+ return pups ? JSON.parse(pups) : [];
254
220
  }
255
221
 
256
222
  return {