@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
|
@@ -13,9 +13,14 @@ let eid = '';
|
|
|
13
13
|
let id = '';
|
|
14
14
|
|
|
15
15
|
const ZZIP_URLS = {
|
|
16
|
-
dev: 'https://
|
|
17
|
-
test: 'https://
|
|
18
|
-
prod: 'https://
|
|
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
|
|
234
|
-
const url =
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
240
|
-
return
|
|
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
|
|
253
|
-
return
|
|
218
|
+
const pups = sessionStorage.getItem(PICK_UP_POINTS);
|
|
219
|
+
return pups ? JSON.parse(pups) : [];
|
|
254
220
|
}
|
|
255
221
|
|
|
256
222
|
return {
|