@ordergroove/offers 2.40.4-alpha-PR-1091-5.0 → 2.40.4

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": "@ordergroove/offers",
3
- "version": "2.40.4-alpha-PR-1091-5.0+abf9741c",
3
+ "version": "2.40.4",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -49,5 +49,5 @@
49
49
  "@ordergroove/offers-templates": "^0.9.6",
50
50
  "@types/lodash.memoize": "^4.1.9"
51
51
  },
52
- "gitHead": "abf9741c5b1b86199eade5ed2f12215835ef54c5"
52
+ "gitHead": "7047889836c2225038223496a0b0c317756fa15d"
53
53
  }
@@ -200,28 +200,6 @@ export const requestOffer = (product, module = constants.DEFAULT_OFFER_MODULE, o
200
200
 
201
201
  export const fetchOffer = requestOffer;
202
202
 
203
- export const _fetchOffer = (product, module = constants.DEFAULT_OFFER_MODULE, offerElement) =>
204
- function fetchOfferThunk(dispatch, getState) {
205
- const state = getState();
206
- const {
207
- merchantId,
208
- sessionId,
209
- environment: { apiUrl }
210
- } = state;
211
- const requestAction = requestOffer(product, module, offerElement);
212
- dispatch(requestAction);
213
-
214
- const productId = safeProductId(product);
215
- if (!productId) return null;
216
- return api
217
- .fetchOffer(apiUrl, merchantId, sessionId, productId, module, state)
218
- .then(
219
- response => dispatch(receiveOffer(response, offerElement)),
220
- err => dispatch(fetchResponseError(err))
221
- )
222
- .finally(() => dispatch(fetchDone(requestAction)));
223
- };
224
-
225
203
  export const checkout = () => ({
226
204
  type: constants.CHECKOUT
227
205
  });
@@ -114,8 +114,6 @@ export function experimentsMiddleware(store) {
114
114
  }
115
115
  }
116
116
 
117
- next(action);
117
+ return next(action);
118
118
  };
119
119
  }
120
-
121
- experimentsMiddleware.position = -1;
package/src/core/store.js CHANGED
@@ -5,6 +5,7 @@ import { loadState } from './localStorage';
5
5
  import { dispatchMiddleware, localStorageMiddleware, offerEvents } from './middleware';
6
6
  import { waitUntilOffersReady } from './waitUntilOffersReady';
7
7
  import { offerRequestMiddleware } from './offerRequest';
8
+ import { experimentsMiddleware } from './experiments';
8
9
 
9
10
  export function makeStore(reducer, ...extraMiddlewares) {
10
11
  if (window.og && window.og.store) return window.og.store;
@@ -20,7 +21,8 @@ export function makeStore(reducer, ...extraMiddlewares) {
20
21
 
21
22
  const middlewares = [
22
23
  waitUntilOffersReady,
23
- thunk, // remove thisone after migration, it will save some KB
24
+ thunk,
25
+ experimentsMiddleware,
24
26
  offerRequestMiddleware,
25
27
  dispatchMiddleware,
26
28
  offerEvents
@@ -37,13 +39,7 @@ export function makeStore(reducer, ...extraMiddlewares) {
37
39
  }
38
40
  }
39
41
 
40
- const sortedMiddlewares = extraMiddlewares
41
- .filter(it => (it?.position || 0) < 0)
42
- .concat(middlewares)
43
- .concat(extraMiddlewares.filter(it => it && (it?.position || 0) >= 0));
44
-
45
- const enhancer = composeEnhancers(applyMiddleware(...sortedMiddlewares));
46
-
42
+ const enhancer = composeEnhancers(applyMiddleware(...middlewares, ...extraMiddlewares.filter(it => it)));
47
43
  const store = createStore(reducer, initial, enhancer);
48
44
 
49
45
  window.og = window.og || {};
package/src/index.js CHANGED
@@ -7,12 +7,10 @@ import platform from './platform';
7
7
  import { autoInitializeOffers, onReady } from './core/utils';
8
8
  import { authorizeShopifyCustomer } from './shopify/shopifyBootstrap';
9
9
  import shopifyTrackingMiddleware from './shopify/shopifyTrackingMiddleware';
10
- import { experimentsMiddleware } from './core/experiments';
11
10
 
12
11
  export const store = makeStore(
13
12
  ...(platform?.shopify_selling_plans ? [shopifyReducer, shopifyMiddleware] : [defaultReducer]),
14
- platform.shopify && shopifyTrackingMiddleware,
15
- experimentsMiddleware
13
+ platform.shopify && shopifyTrackingMiddleware
16
14
  );
17
15
 
18
16
  export const offers = makeApi(store);
@@ -345,8 +345,8 @@ export function getSubscribedFrequency(productId, store) {
345
345
  * @param store
346
346
  */
347
347
  function synchronizeSellingPlan(store: any, offerElement?: HTMLElement) {
348
- if (offerElement.isCart) return; // hidden inputs are used when product page, not cart.
349
- if (!offerElement.shouldEnableOffer) return; // do not set a selling plan if we're hiding the offer
348
+ if (offerElement?.isCart) return; // hidden inputs are used when product page, not cart.
349
+ if (!offerElement?.shouldEnableOffer) return; // do not set a selling plan if we're hiding the offer
350
350
 
351
351
  [...document.querySelectorAll('form[action$="/cart/add"] [name=id]')].forEach((productIdInput: HTMLInputElement) => {
352
352
  const productId = productIdInput.value;
@@ -85,7 +85,7 @@ export const mapExistingOptinsFromOfferResponse = (state, offerEl) =>
85
85
  mapFrequencyToSellingPlan(
86
86
  offerEl?.config?.frequencies,
87
87
  offerEl?.config?.frequenciesEveryPeriod,
88
- offerEl.defaultFrequency
88
+ offerEl?.defaultFrequency
89
89
  ) ||
90
90
  getFirstSellingPlan(offerEl?.config?.frequencies)
91
91
  : it.frequency
@@ -103,7 +103,7 @@ export const reduceNewOptinsFromOfferResponse = (
103
103
  Object.keys(autoship).reduce((acc, id) => {
104
104
  if (!existingOptins.some(it => it.id === id)) {
105
105
  if (!(autoship[id] && autoship_by_default[id] && in_stock[id])) return acc;
106
- const { config: { frequencies: sellingPlans, frequenciesEveryPeriod } = {}, defaultFrequency } = offerEl;
106
+ const { config: { frequencies: sellingPlans, frequenciesEveryPeriod } = {}, defaultFrequency } = offerEl || {};
107
107
  const psdf = default_frequencies[id];
108
108
  let frequency;
109
109
 
@@ -314,7 +314,7 @@ export const config = (
314
314
  defaultFrequency,
315
315
  config: { frequencies: sellingPlans, frequenciesEveryPeriod, prepaidSellingPlans = {} } = {},
316
316
  product
317
- } = offerEl;
317
+ } = offerEl || {};
318
318
 
319
319
  // We don't want to be setting the default frequency to a prepaid selling plan
320
320
  if (prepaidSellingPlans[product?.id]?.some(({ sellingPlan }) => sellingPlan === defaultFrequency)) {
@@ -381,10 +381,10 @@ export const offer = (state = {}, _action) => state;
381
381
  function getFrequencyForPrepaidShipments({ prepaidShipments, offer: offerEl, product }) {
382
382
  if (prepaidShipments) {
383
383
  const productId = safeProductId(product.id);
384
- const plan = offerEl.config.prepaidSellingPlans[productId]?.find(p => p.numberShipments === prepaidShipments);
384
+ const plan = offerEl?.config.prepaidSellingPlans[productId]?.find(p => p.numberShipments === prepaidShipments);
385
385
  return plan ? plan.sellingPlan : null;
386
386
  }
387
- return offerEl.config.frequencies[0];
387
+ return offerEl?.config.frequencies[0];
388
388
  }
389
389
 
390
390
  function getOptedInItem(cartItem) {