@nuskin/ns-shop 7.0.5-cx1-13272.17 → 7.0.5-cx1-13272.19
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 +1 -1
- package/src/salesEventService.js +33 -23
package/package.json
CHANGED
package/src/salesEventService.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {RunConfigService, UrlService, events, storage} from '@nuskin/ns-util';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { UserService } from '@nuskin/ns-account';
|
|
4
|
-
import CheckoutModeService from './checkout/checkoutModeService';
|
|
4
|
+
// import CheckoutModeService from './checkout/checkoutModeService';
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
init,
|
|
@@ -27,7 +27,7 @@ const ACTIVE_EVENT_TTL = ONE_MINUTE * 14;
|
|
|
27
27
|
const INITIALIZING = 'initializing';
|
|
28
28
|
const EXTERNAL_INITIALIZING = 'initializing-external';
|
|
29
29
|
|
|
30
|
-
let isGuest = false;
|
|
30
|
+
// let isGuest = false;
|
|
31
31
|
|
|
32
32
|
// Contains a map of all event tickets that are stored in localStorage.
|
|
33
33
|
let eventTicketInfoMap;
|
|
@@ -73,7 +73,7 @@ events.subscribe(events.salesevent.INIT_EVENT_TICKET, async (eventName, refresh
|
|
|
73
73
|
|
|
74
74
|
if (eventName && await _initData()) {
|
|
75
75
|
if (mktEventConfigMap[eventName]) {
|
|
76
|
-
myAlert(`events.salesevent.INIT_EVENT_TICKET, ${eventName}`);
|
|
76
|
+
// myAlert(`events.salesevent.INIT_EVENT_TICKET, ${eventName}`);
|
|
77
77
|
_initEventTicketInfo(eventName, refresh)
|
|
78
78
|
.catch((err) => {
|
|
79
79
|
console.error(`Error initializing event ticket for ${eventName}.`, err)
|
|
@@ -230,7 +230,7 @@ async function _initEventTicketInfo(eventName, refreshTicket = false) {
|
|
|
230
230
|
if (!eventTicketInfo.ticket || refreshTicket) {
|
|
231
231
|
initInfo.refreshTime = Date.now();
|
|
232
232
|
await _getRemoteTicket(eventTicketInfo);
|
|
233
|
-
myAlert(`_initEventTicketInfo, ${JSON.stringify(eventTicketInfo)}`);
|
|
233
|
+
// myAlert(`_initEventTicketInfo, ${JSON.stringify(eventTicketInfo)}`);
|
|
234
234
|
useServerWaitTime = true;
|
|
235
235
|
}
|
|
236
236
|
_marketStatusCheck(eventTicketInfo);
|
|
@@ -428,6 +428,7 @@ function _getLocalStorageTickets() {
|
|
|
428
428
|
|
|
429
429
|
Object.keys(localStorage).forEach(lsKey => {
|
|
430
430
|
if (lsKey.endsWith('-event-ticket')) {
|
|
431
|
+
// myAlert(`localStorage ticket, ${lsKey}`);
|
|
431
432
|
let ticket = getStorageItem(lsKey);
|
|
432
433
|
|
|
433
434
|
if (ticket && ticket.eventName && ticket.ticketId && ticket.status && mktEventConfigMap[ticket.eventName]) {
|
|
@@ -785,20 +786,20 @@ function getStorageItem(key) {
|
|
|
785
786
|
}
|
|
786
787
|
|
|
787
788
|
async function _checkForMissingTicket(eventName) {
|
|
788
|
-
myAlert(`_checkForMissingTicket1, ${eventName}`);
|
|
789
|
-
myAlert(`_checkForMissingTicket2, ${JSON.stringify(mktEventConfigMap[eventName])}`);
|
|
790
|
-
myAlert(`_checkForMissingTicket3, ${JSON.stringify(eventTicketInfoMap[eventName])}`);
|
|
789
|
+
// myAlert(`_checkForMissingTicket1, ${eventName}`);
|
|
790
|
+
// myAlert(`_checkForMissingTicket2, ${JSON.stringify(mktEventConfigMap[eventName])}`);
|
|
791
|
+
// myAlert(`_checkForMissingTicket3, ${JSON.stringify(eventTicketInfoMap[eventName])}`);
|
|
791
792
|
if (mktEventConfigMap[eventName] && !eventTicketInfoMap[eventName]) {
|
|
792
|
-
myAlert(`missing ticket for ${eventName}`)
|
|
793
|
+
// myAlert(`missing ticket for ${eventName}`)
|
|
793
794
|
await _initEventTicketInfo(eventName);
|
|
794
795
|
}
|
|
795
796
|
}
|
|
796
797
|
|
|
797
|
-
function myAlert(msg) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
798
|
+
// function myAlert(msg) {
|
|
799
|
+
// if (isGuest) {
|
|
800
|
+
// alert(msg);
|
|
801
|
+
// }
|
|
802
|
+
// }
|
|
802
803
|
|
|
803
804
|
/**
|
|
804
805
|
* This initializes an interval timer which checks to see if the browser (computer)
|
|
@@ -838,7 +839,7 @@ async function _initializePolling() {
|
|
|
838
839
|
if (window.location.pathname === '/static/checkout/checkout.html') {
|
|
839
840
|
// check for missing tickets. Only perform on checkout s
|
|
840
841
|
const activeEvents = await _getActiveEvents();
|
|
841
|
-
myAlert(`Active Event check, ${JSON.stringify(activeEvents.map(ae => ae.eventName))}`);
|
|
842
|
+
// myAlert(`Active Event check, ${JSON.stringify(activeEvents.map(ae => ae.eventName))}`);
|
|
842
843
|
|
|
843
844
|
for (const eventInfo of activeEvents) {
|
|
844
845
|
await _checkForMissingTicket(eventInfo.eventName);
|
|
@@ -982,14 +983,14 @@ async function _loadAwsActiveEvents(country) {
|
|
|
982
983
|
* @param eventNames
|
|
983
984
|
*/
|
|
984
985
|
let addEvents = (eventNames) => {
|
|
985
|
-
myAlert(`addEvents1 ${JSON.stringify(eventNames)}`)
|
|
986
|
+
// myAlert(`addEvents1 ${JSON.stringify(eventNames)}`)
|
|
986
987
|
eventNames.forEach(_eventName => {
|
|
987
988
|
let eventName = _eventName.eventName || _eventName;
|
|
988
989
|
|
|
989
|
-
myAlert(`addEvents2 ${JSON.stringify(mktEventConfigMap[eventName])}`)
|
|
990
|
+
// myAlert(`addEvents2 ${JSON.stringify(mktEventConfigMap[eventName])}`)
|
|
990
991
|
if (mktEventConfigMap[eventName]) {
|
|
991
992
|
eventInfos[eventName] = _createEventTicketInfo(eventName);
|
|
992
|
-
myAlert(`addEvents3 ${JSON.stringify(eventInfos)}`)
|
|
993
|
+
// myAlert(`addEvents3 ${JSON.stringify(eventInfos)}`)
|
|
993
994
|
}
|
|
994
995
|
});
|
|
995
996
|
};
|
|
@@ -999,7 +1000,7 @@ async function _loadAwsActiveEvents(country) {
|
|
|
999
1000
|
storageObj = {events: []};
|
|
1000
1001
|
storage.setItem(activeEventsName, storageObj, {ttl: 250}); // to prevent multiple calls.
|
|
1001
1002
|
try {
|
|
1002
|
-
myAlert(`_loadAwsActiveEvents - no storageObj`)
|
|
1003
|
+
// myAlert(`_loadAwsActiveEvents - no storageObj`)
|
|
1003
1004
|
addEvents(await _getActiveEvents());
|
|
1004
1005
|
} catch (e) {
|
|
1005
1006
|
// an error occurred with the call, clear active events
|
|
@@ -1033,19 +1034,28 @@ async function initActiveEvents(country = undefined) {
|
|
|
1033
1034
|
if (Object.values(mktEventConfigMap).find(mktEvent => {return mktEvent.status !== 'off'})) {
|
|
1034
1035
|
let awsEvents = await _loadAwsActiveEvents(country);
|
|
1035
1036
|
|
|
1036
|
-
|
|
1037
|
+
// if a ticket exists in localStorage for an event the is not active, remove it.
|
|
1038
|
+
Object.keys(eventTicketInfoMap).forEach((key) => {
|
|
1039
|
+
if (!awsEvents[key]) {
|
|
1040
|
+
storage.removeItem(_getTicketName(key));
|
|
1041
|
+
delete eventTicketInfoMap[key];
|
|
1042
|
+
}
|
|
1043
|
+
})
|
|
1044
|
+
|
|
1045
|
+
// myAlert(`initActiveEvents0, ${JSON.stringify(awsEvents)}`)
|
|
1046
|
+
// myAlert(`initActiveEvents1, ${JSON.stringify(eventTicketInfoMap)}`)
|
|
1037
1047
|
eventTicketInfoMap = Object.assign({}, awsEvents, eventTicketInfoMap);
|
|
1038
|
-
myAlert(`initActiveEvents2, ${JSON.stringify(eventTicketInfoMap)}`)
|
|
1048
|
+
// myAlert(`initActiveEvents2, ${JSON.stringify(eventTicketInfoMap)}`)
|
|
1039
1049
|
Object.keys(eventTicketInfoMap).forEach(eventName => {
|
|
1040
1050
|
if (mktEventConfigMap[eventName] && eventTicketInfoMap[eventName].eventName) {
|
|
1041
|
-
myAlert(`initActiveEvents, ${JSON.stringify(eventTicketInfoMap[eventName])}`)
|
|
1051
|
+
// myAlert(`initActiveEvents, ${JSON.stringify(eventTicketInfoMap[eventName])}`)
|
|
1042
1052
|
promises.push(_initEventTicketInfo(eventName));
|
|
1043
1053
|
}
|
|
1044
1054
|
});
|
|
1045
1055
|
}
|
|
1046
1056
|
|
|
1047
1057
|
return Promise.all(promises).then(async () => {
|
|
1048
|
-
myAlert(`Initial Events, ${[Object.keys(activeEventMap)]}`);
|
|
1058
|
+
// myAlert(`Initial Events, ${[Object.keys(activeEventMap)]}`);
|
|
1049
1059
|
|
|
1050
1060
|
events.setValue(events.salesevent.INITIAL_ACTIVE_EVENTS, [Object.keys(activeEventMap)]);
|
|
1051
1061
|
|
|
@@ -1129,7 +1139,7 @@ const isSubset = (array1, array2) => {
|
|
|
1129
1139
|
const csConfigCallback = async (configs) => {
|
|
1130
1140
|
if (configs != null && isSubset(configs, neededConfigMaps)) {
|
|
1131
1141
|
events.unsubscribe(events.global.CS_CONFIG_SET, csConfigCallback);
|
|
1132
|
-
isGuest = CheckoutModeService.isGuestCheckout();
|
|
1142
|
+
// isGuest = CheckoutModeService.isGuestCheckout();
|
|
1133
1143
|
_init(false).then(() => console.log('salesEventService initialized'));
|
|
1134
1144
|
}
|
|
1135
1145
|
}
|