@ordergroove/offers 2.34.7-alpha-PR-789-9.10 → 2.34.7

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.34.7-alpha-PR-789-9.10+9e577f43",
3
+ "version": "2.34.7",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -35,8 +35,8 @@
35
35
  }
36
36
  ],
37
37
  "dependencies": {
38
- "@ordergroove/auth": "^2.3.0",
39
- "@ordergroove/offers-live-editor": "^0.6.3-alpha-PR-789-7.14",
38
+ "@ordergroove/auth": "^2.3.1",
39
+ "@ordergroove/offers-live-editor": "^0.6.3",
40
40
  "lit-element": "^2.1.0",
41
41
  "lodash.memoize": "^4.1.2",
42
42
  "logical-expression-parser": "1.0.0",
@@ -45,7 +45,7 @@
45
45
  "throttle-debounce": "^2.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@ordergroove/offers-templates": "^0.9.1"
48
+ "@ordergroove/offers-templates": "^0.9.2"
49
49
  },
50
- "gitHead": "9e577f43f6ce9a0079f7c2d32a4f90458124df88"
50
+ "gitHead": "1b08ceb2cca573488a040e8645304a446d72cd31"
51
51
  }
@@ -63,7 +63,6 @@ export class FrequencyStatus extends withProduct(TemplateElement) {
63
63
 
64
64
  render() {
65
65
  const frequency = this.frequency || this.defaultFrequency;
66
- // eslint-disable-next-line camelcase
67
66
  return html`
68
67
  <span>
69
68
  ${(this.subscribed &&
@@ -1,4 +1,4 @@
1
- import { LitElement, html, css } from 'lit-element';
1
+ import { LitElement, html } from 'lit-element';
2
2
  import { connect } from '../core/connect';
3
3
  import {
4
4
  makeProductPrepaidShipmentOptionsSelector,
@@ -8,11 +8,11 @@ async function simulateChange(element, value) {
8
8
  }
9
9
 
10
10
  const expectToBeVisible = offer => {
11
- const { x, y, width, height } = offer.getClientRects()[0];
11
+ const { height } = offer.getClientRects()[0];
12
12
  expect(height).toBeGreaterThan(30);
13
13
  };
14
14
  const expectNotToBeVisible = offer => {
15
- const { x, y, width, height } = offer.getClientRects()[0];
15
+ const { height } = offer.getClientRects()[0];
16
16
  expect(height).toBeLessThan(30);
17
17
  };
18
18
  const waitUpdate = async offer => {
@@ -1,4 +1,3 @@
1
- /* eslint-disable jasmine/no-unsafe-spy */
2
1
  import { Offer, mapStateToProps } from '../Offer';
3
2
  import { appendToBody } from './utils';
4
3
 
@@ -76,7 +76,7 @@ describe('Price', () => {
76
76
  const template = html`
77
77
  <og-some-price pay-as-you-go product="yum id"> </og-some-price>
78
78
  `;
79
- const priceDivUndefinedPrepaid = await renderPriceTemplate(template, {
79
+ await renderPriceTemplate(template, {
80
80
  frequency: '1_3',
81
81
  productPlans: {
82
82
  'yum id': [
@@ -1,4 +1,3 @@
1
- import { html, render } from 'lit-html';
2
1
  import { SelectFrequency, frequencyEquals } from '../SelectFrequency';
3
2
  import { simulateChange } from './utils';
4
3
 
@@ -1,6 +1,3 @@
1
- /* eslint-disable jasmine/no-unsafe-spy */
2
- /* eslint-disable object-shorthand */
3
- /* eslint-disable no-underscore-dangle */
4
1
  import { connect, createRecalcProps, resolveStore, setStore, unsetStore } from '../connect';
5
2
 
6
3
  describe('connect', () => {
@@ -73,7 +70,6 @@ describe('connect', () => {
73
70
  });
74
71
 
75
72
  it('should call mapStateToProps with state and ownProps', () => {
76
- // eslint-disable-next-line no-shadow
77
73
  const getState = jasmine.createSpy('getState').and.returnValue({ the: 'state' });
78
74
  const _enqueueUpdate = jasmine.createSpy('_enqueueUpdate');
79
75
  setStore({ subscribe, getState, dispatch });
@@ -36,10 +36,9 @@ describe('serializeState', () => {
36
36
  });
37
37
 
38
38
  describe('loadState', () => {
39
- let getItemSpy, setItemSpy;
39
+ let getItemSpy;
40
40
  beforeEach(() => {
41
41
  getItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'getItem');
42
- setItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'setItem');
43
42
  });
44
43
 
45
44
  it('should return undefined on empty state', () => {
@@ -169,7 +169,7 @@ describe('middleware', () => {
169
169
  });
170
170
 
171
171
  describe('localStorageMiddleware', () => {
172
- let getItemSpy, setItemSpy;
172
+ let setItemSpy;
173
173
  beforeEach(() => {
174
174
  // getItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'getItem');
175
175
  setItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'setItem');
@@ -264,7 +264,7 @@ export const setPreviewPrepaid = (isPreview, productId, offer) =>
264
264
  };
265
265
 
266
266
  export const setPreview = (value, oldValue, offer) =>
267
- async function(dispatch, getState) {
267
+ async function(dispatch, _getState) {
268
268
  await dispatch({ type: constants.LOCAL_STORAGE_CLEAR });
269
269
  await dispatch({
270
270
  type: constants.SET_PREVIEW_STANDARD_OFFER,
@@ -89,7 +89,6 @@ export const fetchAuth = (authResolver = resolveAuth) =>
89
89
 
90
90
  return authResolver(authUrl)
91
91
  .then(
92
- // eslint-disable-next-line camelcase
93
92
  ({ sig_field, ts, sig }) => dispatch(authorize(merchantId, sig_field, ts, sig)),
94
93
  err => dispatch(unauthorized(err))
95
94
  )
@@ -130,7 +129,6 @@ export const fetchOrders = (status = 1, ordering = 'place') =>
130
129
  return api
131
130
  .fetchOrders(legoUrl, auth, status, ordering)
132
131
  .then(
133
- // eslint-disable-next-line camelcase
134
132
  response => {
135
133
  if (response.results) {
136
134
  dispatch(receiveOrders(response));
@@ -1,4 +1,3 @@
1
- /* eslint-disable camelcase */
2
1
  import { parseFrequency } from './api';
3
2
 
4
3
  /**
package/src/core/api.js CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable camelcase */
2
1
  import memoize from 'lodash.memoize';
3
2
 
4
3
  const memoizeKey = (...args) => JSON.stringify(args);
@@ -1,12 +1,10 @@
1
- /* eslint-disable no-underscore-dangle */
2
1
  import { bindActionCreators } from 'redux';
3
2
 
4
3
  let storeInstance = null;
5
4
 
6
5
  const defaultMapDispatchToProps = dispatch => ({ dispatch });
7
6
 
8
- // eslint-disable-next-line no-unused-vars
9
- export const resolveStore = obj => {
7
+ export const resolveStore = _obj => {
10
8
  if (!storeInstance) throw new Error('Missing redux store.');
11
9
  return storeInstance;
12
10
  };
@@ -1,7 +1,5 @@
1
- /* eslint-disable no-fallthrough */
2
1
  import { throttle } from 'throttle-debounce';
3
2
  import * as constants from './constants';
4
- import { isSameProduct, kebabCase } from './selectors';
5
3
  import { saveState } from './localStorage';
6
4
 
7
5
  export const dispatchEvent = (name, detail, el = document) =>
@@ -61,9 +59,9 @@ export const dispatchMiddleware = store => next => action => {
61
59
  * @param {*} store
62
60
  * @returns
63
61
  */
64
- export const offerEvents = store => next => action => {
62
+ export const offerEvents = _store => next => action => {
65
63
  let ev;
66
-
64
+ /* eslint-disable no-fallthrough */
67
65
  switch (action.type) {
68
66
  // event: og-receive-offer
69
67
  case constants.RECEIVE_OFFER:
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-case-declarations */
2
1
  import { combineReducers } from 'redux';
3
2
  import * as constants from './constants';
4
3
  import { isSameProduct } from './selectors';
@@ -22,7 +21,7 @@ export const optedin = (state = [], action) => {
22
21
  frequency: action.payload.frequency
23
22
  });
24
23
  }
25
- case constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS:
24
+ case constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS: {
26
25
  const { payload } = action;
27
26
  const [{ prepaidShipments, ...oldone }, rest] = getMatchingProductIfExists(state, payload.product);
28
27
  const newState = {
@@ -33,6 +32,7 @@ export const optedin = (state = [], action) => {
33
32
  newState.prepaidShipments = payload.prepaidShipments;
34
33
  }
35
34
  return rest.concat(newState);
35
+ }
36
36
  case constants.OPTOUT_PRODUCT:
37
37
  return state.filter(a => !isSameProduct(action.payload.product, a));
38
38
  case constants.PRODUCT_HAS_CHANGED:
@@ -57,13 +57,14 @@ export const optedout = (state = [], action) => {
57
57
  case constants.OPTIN_PRODUCT:
58
58
  case constants.PRODUCT_CHANGE_FREQUENCY:
59
59
  return state.filter(a => !isSameProduct(action.payload.product, a));
60
- case constants.OPTOUT_PRODUCT:
60
+ case constants.OPTOUT_PRODUCT: {
61
61
  const [oldone, rest] = getMatchingProductIfExists(state, action.payload.product);
62
62
  return rest.concat({
63
63
  ...oldone,
64
64
  ...action.payload.product,
65
65
  frequency: action.payload.frequency
66
66
  });
67
+ }
67
68
  case constants.PRODUCT_HAS_CHANGED:
68
69
  return state.map(product =>
69
70
  isSameProduct(action.payload.product, product) ? { ...product, ...action.payload.newProduct } : product
@@ -482,9 +483,10 @@ export const prepaidShipmentsSelected = (state = {}, action) => {
482
483
  // a product changes in the cart we need to sync these changes back with the eComm platform, this operation
483
484
  // may result in a new cartId that needs to replace the old product's cartId in order to have the
484
485
  // prepaidShipmentsSelected object up-to-date
485
- case constants.CART_PRODUCT_KEY_HAS_CHANGED:
486
+ case constants.CART_PRODUCT_KEY_HAS_CHANGED: {
486
487
  const { [action.payload.oldCartProductKey]: preservedPrepaidShipments, ...stateWithoutOldCartProductKey } = state;
487
488
  return { ...stateWithoutOldCartProductKey, [action.payload.newCartProductKey]: preservedPrepaidShipments };
489
+ }
488
490
  case constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS:
489
491
  if (action.payload.prepaidShipments) {
490
492
  return { ...state, [action.payload.product.id]: action.payload.prepaidShipments };
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console */
2
1
  import { LitElement } from 'lit-element';
3
2
 
4
3
  export const sanitizeFrequencyString = value => {
@@ -16,7 +16,6 @@ function arraysEqual(a, b) {
16
16
  // Please note that calling sort on an array will modify that array.
17
17
  // you might want to clone your array first.
18
18
 
19
- // eslint-disable-next-line no-plusplus
20
19
  for (let i = 0; i < a.length; ++i) {
21
20
  if (a[i] !== b[i]) return false;
22
21
  }
package/src/core/store.js CHANGED
@@ -11,10 +11,8 @@ export function makeStore(reducer, ...extraMiddlewares) {
11
11
  const isPreviewMode = window.og && window.og.previewMode;
12
12
 
13
13
  const composeEnhancers =
14
- // eslint-disable-next-line no-underscore-dangle
15
14
  typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
16
- ? // eslint-disable-next-line no-underscore-dangle
17
- window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
15
+ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
18
16
  name: 'Ordergroove Offers'
19
17
  })
20
18
  : compose;
package/src/make-api.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { offersLiveEditor } from '@ordergroove/offers-live-editor';
2
2
  import { setStore } from './core/connect';
3
- import { listenLocalStorageChanges } from './core/localStorage';
4
3
  import * as adapters from './core/adapters';
5
4
  import * as actions from './core/actions';
6
5
  import { ConnectedWhen } from './components/When';
@@ -27,8 +26,8 @@ import { ConnectedPrepaidSelect } from './components/PrepaidSelect';
27
26
  import { ConnectedSubscriptionButton } from './components/SubscriptionButton';
28
27
  import * as testMode from './test-mode';
29
28
  import { api } from './core/api';
30
- import { environment, offer } from './core/reducer';
31
- import { DEFAULT_OFFER_MODULE, RECEIVE_PRODUCT_PLANS, SETUP_CART, SETUP_PRODUCT } from './core/constants';
29
+ import { environment } from './core/reducer';
30
+ import { DEFAULT_OFFER_MODULE, RECEIVE_PRODUCT_PLANS } from './core/constants';
32
31
  import ConnectedPrice from './components/Price';
33
32
  import { safeProductId } from './core/utils';
34
33
 
@@ -131,7 +130,7 @@ export default function makeApi(store) {
131
130
  return this;
132
131
  },
133
132
 
134
- setPublicPath(publicPath) {
133
+ setPublicPath(_publicPath) {
135
134
  return this;
136
135
  },
137
136
 
package/src/run-tests.js CHANGED
@@ -1,4 +1,4 @@
1
- const { TestWizard } = require('./components/TestWizard');
1
+ import { TestWizard } from './components/TestWizard';
2
2
 
3
3
  export default function() {
4
4
  const name = 'og-test-wizard';
@@ -152,7 +152,7 @@ describe('synchronizeCartOptin', () => {
152
152
 
153
153
  it('should dispatch cart updated event', async () => {
154
154
  let called;
155
- document.addEventListener(CART_UPDATED_EVENT, ev => {
155
+ document.addEventListener(CART_UPDATED_EVENT, () => {
156
156
  called = true;
157
157
  });
158
158
 
@@ -17,7 +17,7 @@ export const getPrepaidShipmentsNumberFromOptions = options => {
17
17
 
18
18
  export const getAllocationFrequency = (allocation: ShopifySellingPlanAllocationsEntity) => {
19
19
  // now frequency every_period will match with selling_plan_id so no need to convert it
20
- return (allocation.selling_plan_id || allocation.selling_plan?.id).toString();
20
+ return (allocation.selling_plan_id || (allocation.selling_plan?.id ?? '')).toString();
21
21
  };
22
22
 
23
23
  export const getAllocationRegularPrice = (allocation: ShopifySellingPlanAllocationsEntity) => {
@@ -7,7 +7,7 @@ const SHOPIFY_OG_AUTH_END = 'og_auth_end';
7
7
 
8
8
  type ShopifyOGAuth = {
9
9
  customerId: string;
10
- timestamp: Number;
10
+ timestamp: number;
11
11
  signature: string;
12
12
  };
13
13
 
@@ -45,7 +45,7 @@ declare global {
45
45
  previewMode: boolean;
46
46
  };
47
47
  ogShopifyConfig: OgShopifyConfig;
48
- Shopify: { routes?: { root: String } };
48
+ Shopify: { routes?: { root: string } };
49
49
  }
50
50
  }
51
51
 
@@ -71,7 +71,7 @@ async function setupPdp(store, offer) {
71
71
  if (form) {
72
72
  // since syncProductId is debounced not matter which comes first mutation or onchange
73
73
  const syncProductId = makeSyncProductId(offer);
74
- form.addEventListener('change', ev => syncProductId(form));
74
+ form.addEventListener('change', () => syncProductId(form));
75
75
  const mo = new MutationObserver(() => syncProductId(form));
76
76
  mo.observe(form, { subtree: true, childList: true });
77
77
  } else {
@@ -85,7 +85,7 @@ const getCart = async () => await (await fetch(CART_JS_URL)).json();
85
85
  * Attemps to guess the product handle o
86
86
  * @returns
87
87
  */
88
- export function guessProductHandle(offer): String {
88
+ export function guessProductHandle(offer): string {
89
89
  return (
90
90
  [
91
91
  // Allow specify data-shopify-product-handle attribute offer level so it will work on category qv
@@ -98,7 +98,7 @@ export function guessProductHandle(offer): String {
98
98
  (document
99
99
  .querySelector('[href$=".oembed"]')
100
100
  ?.getAttribute('href')
101
- ?.match(/\/([^\/]+)\.oembed$/) || [])[1],
101
+ ?.match(/\/([^/]+)\.oembed$/) || [])[1],
102
102
 
103
103
  () =>
104
104
  // Use the open graph og:type==product and og:url to get the product handle
@@ -106,7 +106,7 @@ export function guessProductHandle(offer): String {
106
106
  document
107
107
  .querySelector('meta[property="og:url"][content]')
108
108
  ?.getAttribute('content')
109
- ?.match(/\/([^\/]+)$/)) ||
109
+ ?.match(/\/([^/]+)$/)) ||
110
110
  [])[1],
111
111
 
112
112
  () =>
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-case-declarations */
2
1
  import { combineReducers } from 'redux';
3
2
  import * as constants from '../core/constants';
4
3
 
@@ -262,7 +261,7 @@ export const config = (
262
261
 
263
262
  if (constants.SETUP_PRODUCT === action.type) {
264
263
  const {
265
- payload: { offer: offerEl, product }
264
+ payload: { product }
266
265
  } = action;
267
266
  let configToAdd = {};
268
267
  // pay as you go selling plans
@@ -349,7 +348,7 @@ export const inStock = (state = {}, action) => {
349
348
  const {
350
349
  payload: { product }
351
350
  } = action;
352
- return [product, ...product?.variants]?.reduce(productOrVariantInStockReducer, state) || state;
351
+ return [product, ...(product?.variants ?? [])]?.reduce(productOrVariantInStockReducer, state) || state;
353
352
  }
354
353
  // force offer to refresh when requesting a new one
355
354
  if (constants.REQUEST_OFFER === action.type && action.payload.product === null) {
@@ -358,7 +357,7 @@ export const inStock = (state = {}, action) => {
358
357
  return state;
359
358
  };
360
359
 
361
- export const offer = (state = {}, action) => state;
360
+ export const offer = (state = {}, _action) => state;
362
361
 
363
362
  function getFrequencyForPrepaidShipments({ prepaidShipments, offer: offerEl, product }) {
364
363
  if (prepaidShipments) {
@@ -436,7 +435,7 @@ export const optedin = (state = [], action) => {
436
435
  return coreOptedin(state, action);
437
436
  };
438
437
 
439
- export const productOffer = (state = {}, action) => state;
438
+ export const productOffer = (state = {}, _action) => state;
440
439
 
441
440
  export const productPlans = (state = {}, action) => {
442
441
  if (constants.SETUP_PRODUCT === action.type) {
@@ -448,7 +447,7 @@ export const productPlans = (state = {}, action) => {
448
447
 
449
448
  return (
450
449
  // We consider the product here as well for cases where we don't have any variants
451
- [product, ...product?.variants]?.reduce(
450
+ [product, ...(product?.variants ?? [])]?.reduce(
452
451
  (acc, cur) => ({
453
452
  ...acc,
454
453
  [cur.id]: cur.selling_plan_allocations?.reduce(
@@ -49,7 +49,6 @@ export function addDefaultToSubTracking(action, store) {
49
49
  const value = [productId, OPTIN_PRODUCT.toLowerCase(), location, frequency, variation];
50
50
  const inputValue = value.join(',');
51
51
  updateTrackingInputs(productId, key, inputValue);
52
-
53
52
  }
54
53
 
55
54
  export default function shopifyTrackingMiddleware(store) {
@@ -59,7 +58,7 @@ export default function shopifyTrackingMiddleware(store) {
59
58
  switch (action.type) {
60
59
  case OPTIN_PRODUCT:
61
60
  case OPTOUT_PRODUCT:
62
- case PRODUCT_CHANGE_FREQUENCY:
61
+ case PRODUCT_CHANGE_FREQUENCY: {
63
62
  const offerElement = action.payload.offer;
64
63
  const trackingEvent = getTrackingEvent(action);
65
64
 
@@ -67,6 +66,7 @@ export default function shopifyTrackingMiddleware(store) {
67
66
  updateTrackingInputs(offerElement.product.id, trackingEvent[0], trackingEvent[1]);
68
67
  }
69
68
  break;
69
+ }
70
70
  case RECEIVE_OFFER:
71
71
  addDefaultToSubTracking(action, store);
72
72
  break;