@ordergroove/offers 2.26.2 → 2.26.3-alpha-PR-593-20.20

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.
Files changed (48) hide show
  1. package/build.js +3 -1
  2. package/dist/bundle-report.html +170 -104
  3. package/dist/offers.js +64 -75
  4. package/dist/offers.js.map +3 -3
  5. package/examples/cart.js +105 -0
  6. package/examples/index.html +2 -2
  7. package/examples/products/cheap-watch.js +183 -0
  8. package/examples/shopify-cart.html +26 -0
  9. package/examples/shopify-pdp.html +34 -0
  10. package/karma.conf.js +2 -1
  11. package/package.json +4 -4
  12. package/src/__tests__/offers.spec.js +35 -10
  13. package/src/components/FrequencyStatus.js +14 -11
  14. package/src/components/Offer.js +11 -7
  15. package/src/components/OptinButton.js +1 -1
  16. package/src/components/OptinSelect.js +2 -2
  17. package/src/components/OptinToggle.js +2 -2
  18. package/src/components/OptoutButton.js +1 -1
  19. package/src/components/Price.js +8 -4
  20. package/src/components/Select.js +3 -13
  21. package/src/components/SelectFrequency.js +24 -6
  22. package/src/components/TestWizard.js +1 -1
  23. package/src/components/__tests__/OG.fspec.js +24 -0
  24. package/src/components/__tests__/Offer.spec.js +4 -4
  25. package/src/components/__tests__/OptinButton.spec.js +2 -2
  26. package/src/components/__tests__/OptinToggle.spec.js +2 -2
  27. package/src/components/__tests__/OptoutButton.spec.js +1 -1
  28. package/src/components/__tests__/SelectFrequency.fspec.js +1 -0
  29. package/src/components/__tests__/SelectFrequency.spec.js +1 -1
  30. package/src/components/__tests__/TestWizard.spec.js +2 -2
  31. package/src/components/__tests__/Text.spec.js +3 -0
  32. package/src/core/__tests__/actions.spec.js +6 -6
  33. package/src/core/actions.js +12 -10
  34. package/src/core/constants.js +3 -0
  35. package/src/core/reducer.js +14 -14
  36. package/src/core/resolveProperties.js +2 -7
  37. package/src/core/selectors.js +1 -1
  38. package/src/core/store.js +6 -5
  39. package/src/index.js +57 -202
  40. package/src/make-api.js +190 -0
  41. package/src/platform.ts +5 -0
  42. package/src/shopify/__tests__/shopifyReducer.spec.js +477 -0
  43. package/src/shopify/shopifyMiddleware.ts +202 -0
  44. package/src/shopify/shopifyReducer.js +214 -0
  45. package/tsconfig.json +35 -0
  46. package/examples/5starnutrition-main.js +0 -3
  47. package/examples/single-offer.html +0 -9
  48. package/src/init-test.js +0 -3
@@ -0,0 +1,214 @@
1
+ /* eslint-disable no-case-declarations */
2
+ import { combineReducers } from 'redux';
3
+ import * as constants from '../core/constants';
4
+
5
+ import {
6
+ autoshipByDefault,
7
+ auth,
8
+ authUrl,
9
+ defaultFrequencies,
10
+ eligibilityGroups,
11
+ environment,
12
+ firstOrderPlaceDate,
13
+ incentives,
14
+ locale,
15
+ merchantId,
16
+ nextUpcomingOrder,
17
+ optedin as coreOptedin,
18
+ optedout,
19
+ previewStandardOffer,
20
+ previewUpsellOffer,
21
+ productToSubscribe,
22
+ sessionId,
23
+ templates
24
+ } from '../core/reducer';
25
+
26
+ const money = val => `$${val.toString().replace(/(\d\d)$/, '.$1')}`;
27
+
28
+ const percentage = val => `${val}%`;
29
+
30
+ const mapSellingPlanToDiscount = allocation => {
31
+ let formatted_discount = '%';
32
+ if (allocation?.price_adjustments.length > 0) {
33
+ if (allocation.price_adjustments[0].value_type === 'percentage') {
34
+ formatted_discount = percentage(allocation.price_adjustments[0].value);
35
+ } else if (allocation.price_adjustments[0].value) {
36
+ formatted_discount = money(allocation.price_adjustments[0].value);
37
+ } else {
38
+ formatted_discount = money(allocation.compare_at_price - allocation.price);
39
+ }
40
+ }
41
+
42
+ return [money(allocation.compare_at_price), formatted_discount, money(allocation.price)];
43
+ };
44
+
45
+ const productOrVariantInStockReducer = (acc, cur) => ({ ...acc, [cur.id]: cur.available });
46
+
47
+ const productTrue = (acc, [id]) => ({ ...acc, [id]: true });
48
+
49
+ const sellingPlanAllocationsReducer = (acc, cur) => ({
50
+ ...acc,
51
+ // now frequency every_period will match with selling_plan_id so no need to convert it
52
+ [cur.selling_plan_id || cur.selling_plan?.id]: mapSellingPlanToDiscount(cur)
53
+ });
54
+
55
+ export const autoshipEligible = (state = {}, action) => {
56
+ if (constants.RECEIVE_PRODUCT_PLANS === action.type) {
57
+ return Object.entries(action.payload).reduce(productTrue, state);
58
+ }
59
+ if (constants.SETUP_CART === action.type) {
60
+ const { payload: cart } = action;
61
+
62
+ return cart.items.reduce((acc, cur) => ({ ...acc, [cur.key]: true }), state);
63
+ }
64
+ if (constants.SETUP_PRODUCT === action.type) {
65
+ const { payload: product } = action;
66
+ return (
67
+ [product, ...(product?.variants || [])]?.reduce(
68
+ (acc, cur) => ({ ...acc, [cur.id]: cur.selling_plan_allocations?.length > 0 }),
69
+ state
70
+ ) || state
71
+ );
72
+ }
73
+ return state;
74
+ };
75
+
76
+ export const config = (
77
+ state = {
78
+ frequencies: [],
79
+ offerType: 'radio'
80
+ },
81
+ action
82
+ ) => {
83
+ if (constants.RECEIVE_PRODUCT_PLANS === action.type) {
84
+ const frequencies = [
85
+ ...new Set(
86
+ Object.values(action.payload)
87
+ .map(Object.keys)
88
+ .flat()
89
+ )
90
+ ];
91
+ return {
92
+ ...state,
93
+ frequencies
94
+ };
95
+ }
96
+
97
+ if (constants.SETUP_PRODUCT === action.type) {
98
+ const product = action.payload;
99
+ const frequencies = product?.selling_plan_groups?.[0]?.selling_plans?.map(({ id }) => `${id}`);
100
+ if (frequencies?.length) {
101
+ const frequenciesText = product?.selling_plan_groups?.[0]?.options?.[0]?.values || frequencies;
102
+ return {
103
+ ...state,
104
+ defaultFrequency: frequencies[0],
105
+ frequencies,
106
+ frequenciesText
107
+ };
108
+ }
109
+ }
110
+
111
+ return state;
112
+ };
113
+
114
+ export const inStock = (state = {}, action) => {
115
+ if (constants.RECEIVE_PRODUCT_PLANS === action.type) {
116
+ return Object.entries(action.payload).reduce(productTrue, state);
117
+ }
118
+
119
+ if (constants.SETUP_CART === action.type) {
120
+ const cart = action.payload;
121
+
122
+ return cart.items.reduce((acc, cur) => ({ ...acc, [cur.key]: true }), state);
123
+ }
124
+
125
+ if (constants.SETUP_PRODUCT === action.type) {
126
+ const product = action.payload;
127
+
128
+ return [product, ...product?.variants]?.reduce(productOrVariantInStockReducer, state) || state;
129
+ }
130
+
131
+ return state;
132
+ };
133
+
134
+ export const offer = (state = {}, action) => state;
135
+
136
+ export const offerId = (state = '', action) => 'native-shopify-offer';
137
+
138
+ export const optedin = (state = [], action) => {
139
+ if (constants.SETUP_CART === action.type) {
140
+ const cart = action.payload;
141
+ return cart.items.reduce(
142
+ (acc, cur) =>
143
+ cur.selling_plan_allocation
144
+ ? [...acc, { id: cur.key, frequency: `${cur.selling_plan_allocation.selling_plan.id}` }]
145
+ : acc,
146
+ []
147
+ );
148
+ }
149
+ return coreOptedin(state, action);
150
+ };
151
+
152
+ export const productOffer = (state = {}, action) => state;
153
+
154
+ export const productPlans = (state = {}, action) => {
155
+ if (constants.SETUP_PRODUCT === action.type) {
156
+ const product = action.payload;
157
+ return (
158
+ [product, ...product?.variants]?.reduce(
159
+ (acc, cur) => ({
160
+ ...acc,
161
+ [cur.id]: cur.selling_plan_allocations?.reduce(sellingPlanAllocationsReducer, {})
162
+ }),
163
+ state
164
+ ) || state
165
+ );
166
+ }
167
+ if (constants.SETUP_CART === action.type) {
168
+ const cart = action.payload;
169
+ return (
170
+ cart.items.reduce(
171
+ (acc, cur) =>
172
+ cur.selling_plan_allocation
173
+ ? {
174
+ ...acc,
175
+ [cur.key]: sellingPlanAllocationsReducer({}, cur.selling_plan_allocation)
176
+ }
177
+ : acc,
178
+ state
179
+ ) || state
180
+ );
181
+ }
182
+ if (constants.RECEIVE_PRODUCT_PLANS === action.type) {
183
+ return { ...action.payload };
184
+ }
185
+ return state;
186
+ };
187
+
188
+ export default combineReducers({
189
+ auth,
190
+ authUrl,
191
+ autoshipByDefault,
192
+ autoshipEligible,
193
+ config,
194
+ defaultFrequencies,
195
+ eligibilityGroups,
196
+ environment,
197
+ firstOrderPlaceDate,
198
+ incentives,
199
+ inStock,
200
+ locale,
201
+ merchantId,
202
+ nextUpcomingOrder,
203
+ offer,
204
+ offerId,
205
+ optedin,
206
+ optedout,
207
+ previewStandardOffer,
208
+ previewUpsellOffer,
209
+ productOffer,
210
+ productPlans,
211
+ productToSubscribe,
212
+ sessionId,
213
+ templates
214
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "compilerOptions": {
3
+ "noEmit": true,
4
+ "composite": true,
5
+ "target": "es2019",
6
+ "module": "es2020",
7
+ "lib": ["es2020", "DOM", "DOM.Iterable"],
8
+ "rootDir": "./src",
9
+ "moduleResolution": "node",
10
+ "allowSyntheticDefaultImports": true,
11
+ "stripInternal": true,
12
+ "noImplicitOverride": true,
13
+ "allowJs": true
14
+ },
15
+ "include": [
16
+ "node_modules/lit-html/lit-html.d.ts",
17
+ "node_modules/dayjs-es/index.d.ts",
18
+ "node_modules/lodash-es/index.d.ts",
19
+ "src/**/*.ts",
20
+ "src/**/*.js"
21
+ ],
22
+ "typedocOptions": {
23
+ "name": "SMI",
24
+ "entryPoints": [
25
+ "./src/index.ts",
26
+ "./src/shopify.ts",
27
+ ],
28
+ "out": "docs/",
29
+ "readme": "none",
30
+ "disableSources": true,
31
+
32
+ "categoryOrder": ["Type aliases", "*"],
33
+ "validation": { "invalidLink": true }
34
+ }
35
+ }
@@ -1,3 +0,0 @@
1
- import offers from '../src';
2
-
3
- offers('bc678090fa6211e9b99abc764e10b970', 'prod', false);
@@ -1,9 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Ordergroove Offers</title>
5
- </head>
6
- <body id="single-offer" onload="og.offers('0e5de2bedc5e11e3a2e4bc764e106cf4', 'staging')">
7
- <og-offer product="UD729" id="regular1" preview-standard-offer></og-offer>
8
- </body>
9
- </html>
package/src/init-test.js DELETED
@@ -1,3 +0,0 @@
1
- import { initialize } from './index';
2
-
3
- initialize('some-merchant', 'staging');