@nuskin/ns-shop 7.0.5-cx1-13272.7 → 7.0.5-cx1-13272.9

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.0.5-cx1-13272.7",
3
+ "version": "7.0.5-cx1-13272.9",
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": {
@@ -139,69 +139,32 @@ function getActiveTicketEvents() {
139
139
  return events;
140
140
  }
141
141
 
142
- async function getEventStatus(eventsToCheck = [], externalId = 'none') {
142
+ async function getEventStatus(eventsToCheck = []) {
143
143
  const eventStatus = {};
144
144
  const promises = [];
145
145
 
146
146
  eventsToCheck.forEach((toCheck) => {
147
- promises.push(_getTempTicket(toCheck, externalId));
147
+ promises.push(_checkForMissingTicket(toCheck));
148
148
  });
149
149
 
150
- const responses = await Promise.allSettled(promises);
150
+ await Promise.allSettled(promises);
151
151
 
152
- responses.forEach((response) => {
152
+ eventsToCheck.forEach((eventName) => {
153
153
  let activeStatus = false;
154
- if (response.status === 'fulfilled' && response.value) {
155
- const status = _decodeStatus(response.value.status);
154
+ const ticketInfo = eventTicketInfoMap[eventName];
155
+ if (ticketInfo.ticket) {
156
+ const status = _decodeStatus(ticketInfo.ticket.status);
156
157
  if ((status.eventStatus === PRE_EVENT && status.preWaitTime <= 30000) ||
157
158
  status.eventStatus === IN_EVENT) {
158
159
  activeStatus = true;
159
160
  }
160
- eventStatus[response.value.eventName] = activeStatus;
161
161
  }
162
+ eventStatus[eventName] = activeStatus;
162
163
  });
163
164
 
164
165
  return eventStatus;
165
166
  }
166
167
 
167
- /**
168
- * Either requests a new ticket or an updated event ticket from the AWS service
169
- *
170
- * @param eventTicketInfo - contains informatino about the ticket.
171
- *
172
- * @returns {Promise<*>} a new or updated ticket for the specified event
173
- * @private
174
- */
175
- async function _getTempTicket(eventName, externalId) {
176
- let ticket;
177
-
178
- try {
179
- let method = 'POST',
180
- seParams = _getSeParams(eventName, false),
181
- response = await axios({
182
- method: method,
183
- url: `${_getAwsUrl(eventName, null)}?orderEventCheck=${externalId}${seParams}`,
184
- headers: _getHeaders(),
185
- timeout: 7000
186
- });
187
-
188
- ticket = response.data.salesEventResponse;
189
- } catch (err) {
190
- if (err.response && err.response.data.status === 404) {
191
- console.error(`getTempTicket - unable to get a temporary ticket for ${eventName}`);
192
- throw err;
193
- } else {
194
- console.error(`getTempTicket error or timeout - waiting to try again for ${eventName}`);
195
- // Timed out or some other error
196
- // Wait and then call again.
197
- await _wait(3000);
198
- ticket = await _getTempTicket(eventName);
199
- }
200
- }
201
-
202
- return ticket;
203
- }
204
-
205
168
  function logAnalyticInfo(tag, eventName, data = {}) {
206
169
  const user = UserService.getUser();
207
170
  const eventTicketInfo = eventTicketInfoMap[eventName];
@@ -813,6 +776,12 @@ function getStorageItem(key) {
813
776
  return item;
814
777
  }
815
778
 
779
+ async function _checkForMissingTicket(eventName) {
780
+ if (mktEventConfigMap[eventName] && !eventTicketInfoMap[eventName]) {
781
+ await _initEventTicketInfo(eventName);
782
+ }
783
+ }
784
+
816
785
  /**
817
786
  * This initializes an interval timer which checks to see if the browser (computer)
818
787
  * went to sleep. It's intention is to update the wait timer if it has.
@@ -828,7 +797,7 @@ async function _initializePolling() {
828
797
  const slept = now > (lastTime + TIMEOUT + 3000)
829
798
 
830
799
  // if polling market config, only reload it every 30 seconds
831
- if (slept || pollMarketConfig && intervalCnt % 3 === 0) {
800
+ if (slept || pollMarketConfig && intervalCnt % 6 === 0) {
832
801
  await _loadMarketEventConfig(true);
833
802
  _marketStatusCheck();
834
803
  }
@@ -848,17 +817,15 @@ async function _initializePolling() {
848
817
  _checkStatus(eventTicketInfo, false);
849
818
  });
850
819
 
851
- // check for missing tickets
852
- if (slept) {
820
+ if (window.location.pathname === '/static/checkout/checkout.html') {
821
+ // check for missing tickets. Only perform on checkout s
853
822
  const activeEvents = await _getActiveEvents();
854
823
  for (const eventInfo of activeEvents) {
855
- if (mktEventConfigMap[eventInfo.eventName] && !eventTicketInfoMap[eventInfo.eventName]) {
856
- await _initEventTicketInfo(eventInfo.eventName);
857
- }
824
+ await _checkForMissingTicket(eventInfo.eventName);
858
825
  }
859
826
  }
860
827
 
861
- lastTime = Date.now();
828
+ lastTime = now;
862
829
  }, TIMEOUT);
863
830
  }
864
831
  }
@@ -1054,9 +1021,10 @@ async function initActiveEvents(country = undefined) {
1054
1021
  events.setValue(events.salesevent.INITIAL_ACTIVE_EVENTS, [Object.keys(activeEventMap)]);
1055
1022
 
1056
1023
  // If there are event tickets then initialize polling
1057
- if (Object.keys(eventTicketInfoMap).length > 0 && !country) {
1058
- await _initializePolling();
1059
- }
1024
+ // if (Object.keys(eventTicketInfoMap).length > 0 && !country) {
1025
+ // Test
1026
+ await _initializePolling();
1027
+ // }
1060
1028
  _removeWaitCheck(INITIALIZING);
1061
1029
  });
1062
1030
  }
@@ -1112,13 +1080,13 @@ async function _init(force = true) {
1112
1080
  * If there are, make sure polling is happening, otherwise, stop polling.
1113
1081
  */
1114
1082
  events.subscribe(events.salesevent.ACTIVE_EVENTS, (/*activeEvents*/) => {
1115
- if (eventTicketInfoMap) {
1116
- if (Object.keys(eventTicketInfoMap).length > 0) {
1117
- _initializePolling().then(() => console.log('Polling initialized'));
1118
- } else {
1119
- _clearPollingInterval();
1120
- }
1121
- }
1083
+ // if (eventTicketInfoMap) {
1084
+ // if (Object.keys(eventTicketInfoMap).length > 0) {
1085
+ _initializePolling().then(() => console.log('Polling initialized'));
1086
+ // } else {
1087
+ // _clearPollingInterval();
1088
+ // }
1089
+ // }
1122
1090
  });
1123
1091
 
1124
1092
  // persistentCartService needs to wait until the following configMaps are loaded