@ordergroove/offers 2.24.0 → 2.24.1-alpha-PR-566-5.3
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/dist/bundle-report.html +94 -93
- package/dist/examples.js +7 -7
- package/dist/examples.js.map +2 -2
- package/dist/offers.js +159 -144
- package/dist/offers.js.map +3 -3
- package/examples/index.js +15 -2
- package/package.json +2 -2
- package/src/__tests__/offers.spec.js +100 -5
- package/src/components/Offer.js +10 -1
- package/src/components/Price.js +56 -0
- package/src/components/__tests__/OG.fspec.js +2 -2
- package/src/components/__tests__/Price.fspec.js +43 -0
- package/src/core/constants.js +1 -0
- package/src/core/reducer.js +10 -0
- package/src/index.js +188 -150
- package/src/init-func-tests.js +1 -1
- package/src/init-test.js +2 -2
package/src/index.js
CHANGED
|
@@ -1,169 +1,207 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { offersLiveEditor } from '@ordergroove/offers-live-editor';
|
|
2
|
+
import { setStore } from './core/connect';
|
|
3
|
+
import { getStore } from './core/store';
|
|
4
|
+
import { listenLocalStorageChanges } from './core/localStorage';
|
|
5
|
+
import * as adapters from './core/adapters';
|
|
6
|
+
import * as actions from './core/actions';
|
|
7
|
+
import { ConnectedWhen } from './components/When';
|
|
8
|
+
import { ConnectedOptinButton } from './components/OptinButton';
|
|
9
|
+
import { ConnectedOptoutButton } from './components/OptoutButton';
|
|
10
|
+
import { ConnectedOptinSelect } from './components/OptinSelect';
|
|
11
|
+
import { ConnectedUpsellButton } from './components/UpsellButton';
|
|
12
|
+
import { ConnectedUpsellModal } from './components/UpsellModal';
|
|
13
|
+
import { ConnectedOptinToggle } from './components/OptinToggle';
|
|
14
|
+
import { ConnectedOptinStatus } from './components/OptinStatus';
|
|
15
|
+
import { ConnectedText } from './components/Text';
|
|
16
|
+
import { ConnectedIncentiveText } from './components/IncentiveText';
|
|
17
|
+
import { ConnectedSelectFrequency } from './components/SelectFrequency';
|
|
18
|
+
import { ConnectedNextUpcomingOrder } from './components/NextUpcomingOrder';
|
|
19
|
+
import { ConnectedOffer } from './components/Offer';
|
|
20
|
+
import { Modal } from './components/Modal';
|
|
21
|
+
import { Select } from './components/Select';
|
|
22
|
+
import { Tooltip } from './components/Tooltip';
|
|
23
|
+
import { ConnectedFrequencyStatus } from './components/FrequencyStatus';
|
|
24
|
+
import * as testMode from './test-mode';
|
|
25
|
+
import { api } from './core/api';
|
|
26
|
+
import { environment, offer } from './core/reducer';
|
|
27
|
+
import { RECEIVE_PRODUCT_PLANS } from './core/constants';
|
|
28
|
+
import ConnectedPrice from './components/Price';
|
|
28
29
|
|
|
29
30
|
testMode.enable();
|
|
30
31
|
let store;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
32
|
+
|
|
33
|
+
export const offers = {};
|
|
34
|
+
|
|
35
|
+
export function setEnvironment(e) {
|
|
36
|
+
store.dispatch(actions.setEnvironment(e));
|
|
37
|
+
return offers;
|
|
38
|
+
}
|
|
39
|
+
export function setMerchantId(m) {
|
|
40
|
+
store.dispatch(actions.setMerchantId(m));
|
|
41
|
+
return offers;
|
|
42
|
+
}
|
|
43
|
+
export function setAuthUrl(authUrl) {
|
|
44
|
+
store.dispatch(actions.setAuthUrl(authUrl));
|
|
45
|
+
return offers;
|
|
46
|
+
}
|
|
47
|
+
export function getProductsForPurchasePost(productIds = []) {
|
|
48
|
+
return adapters.getProductsForPurchasePost(store.getState(), productIds);
|
|
49
|
+
}
|
|
50
|
+
export function getOptins(productIds = []) {
|
|
51
|
+
return adapters.getProductsForPurchasePost(store.getState(), productIds);
|
|
52
|
+
}
|
|
53
|
+
export function clear() {
|
|
54
|
+
store.dispatch(actions.checkout());
|
|
55
|
+
}
|
|
56
|
+
export function addOptinChangedCallback(fn) {
|
|
57
|
+
if (typeof fn === 'function') document.addEventListener('optin-changed', e => fn(e.detail));
|
|
58
|
+
}
|
|
59
|
+
export function disableOptinChangedCallbacks() {
|
|
60
|
+
document.addEventListener('optin-changed', e => e.stopPropagation(), true);
|
|
61
|
+
}
|
|
62
|
+
export function register() {
|
|
63
|
+
try {
|
|
64
|
+
customElements.define('og-when', ConnectedWhen);
|
|
65
|
+
customElements.define('og-text', ConnectedText);
|
|
66
|
+
customElements.define('og-incentive-text', ConnectedIncentiveText);
|
|
67
|
+
customElements.define('og-offer', ConnectedOffer);
|
|
68
|
+
customElements.define('og-select-frequency', ConnectedSelectFrequency);
|
|
69
|
+
customElements.define('og-optout-button', ConnectedOptoutButton);
|
|
70
|
+
customElements.define('og-optin-toggle', ConnectedOptinToggle);
|
|
71
|
+
customElements.define('og-optin-status', ConnectedOptinStatus);
|
|
72
|
+
customElements.define('og-optin-button', ConnectedOptinButton);
|
|
73
|
+
customElements.define('og-optin-select', ConnectedOptinSelect);
|
|
74
|
+
customElements.define('og-upsell-button', ConnectedUpsellButton);
|
|
75
|
+
customElements.define('og-frequency-status', ConnectedFrequencyStatus);
|
|
76
|
+
customElements.define('og-modal', Modal);
|
|
77
|
+
customElements.define('og-select', Select);
|
|
78
|
+
customElements.define('og-tooltip', Tooltip);
|
|
79
|
+
customElements.define('og-upsell-modal', ConnectedUpsellModal);
|
|
80
|
+
customElements.define('og-next-upcoming-order', ConnectedNextUpcomingOrder);
|
|
81
|
+
customElements.define('og-price', ConnectedPrice);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
console.warn(err);
|
|
85
|
+
}
|
|
86
|
+
offers.register = () => 0;
|
|
87
|
+
}
|
|
88
|
+
export function previewMode(set) {
|
|
89
|
+
window.og = window.og || {};
|
|
90
|
+
if (set === false) {
|
|
91
|
+
delete window.og;
|
|
92
|
+
} else {
|
|
93
|
+
window.og.previewMode = true;
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
export function config(configuration) {
|
|
98
|
+
store.dispatch(actions.setConfig(configuration));
|
|
99
|
+
return offers;
|
|
100
|
+
}
|
|
101
|
+
export function setLocale(locale) {
|
|
102
|
+
store.dispatch(actions.setLocale(locale));
|
|
103
|
+
return offers;
|
|
104
|
+
}
|
|
105
|
+
export function addTemplate(tagName, content, configOption) {
|
|
106
|
+
store.dispatch(actions.addTemplate(tagName, content, configOption));
|
|
107
|
+
return offers;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* templates object where keys are selectors and values are content
|
|
111
|
+
*/
|
|
112
|
+
export function setTemplates(templates) {
|
|
113
|
+
store.dispatch(actions.setTemplates(templates));
|
|
114
|
+
return offers;
|
|
115
|
+
}
|
|
116
|
+
export function setPublicPath(publicPath) {
|
|
117
|
+
return offers;
|
|
118
|
+
}
|
|
119
|
+
export function resolveSettings(merchantId, env, settings, storeInstance = store) {
|
|
120
|
+
if (merchantId && env && settings) {
|
|
121
|
+
let products = [];
|
|
122
|
+
if (settings.product) {
|
|
123
|
+
products.push(settings.product);
|
|
124
|
+
} else if (settings.cart && Array.isArray(settings.cart.products)) {
|
|
125
|
+
products = products.concat(settings.cart.products);
|
|
90
126
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*/
|
|
99
|
-
initialize(merchantId, env, authUrl) {
|
|
100
|
-
if (offers.isReady) {
|
|
101
|
-
console.warn('og.offers has been initialized already. Skipping.');
|
|
102
|
-
return offers;
|
|
127
|
+
const { apiUrl } = environment({}, actions.setEnvironment(env));
|
|
128
|
+
const { sessionId } = storeInstance.getState();
|
|
129
|
+
if (sessionId) {
|
|
130
|
+
products.forEach(product => {
|
|
131
|
+
console.log(product);
|
|
132
|
+
api.fetchOffer(apiUrl, merchantId, sessionId, `${product}`, 'pdp');
|
|
133
|
+
});
|
|
103
134
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (merchantId && env && settings) {
|
|
108
|
-
let products = [];
|
|
109
|
-
if (settings.product) {
|
|
110
|
-
products.push(settings.product);
|
|
111
|
-
} else if (settings.cart && Array.isArray(settings.cart.products)) {
|
|
112
|
-
products = products.concat(settings.cart.products);
|
|
113
|
-
}
|
|
114
|
-
const { apiUrl } = environment({}, actions.setEnvironment(env));
|
|
115
|
-
const { sessionId } = store.getState();
|
|
116
|
-
if (sessionId) {
|
|
117
|
-
products.forEach(product => api.fetchOffer(apiUrl, merchantId, sessionId, `${product}`, 'pdp'));
|
|
118
|
-
}
|
|
135
|
+
|
|
136
|
+
if (settings.product_x_plans && typeof settings.product_x_plans === 'object') {
|
|
137
|
+
storeInstance.dispatch({ type: RECEIVE_PRODUCT_PLANS, payload: settings.product_x_plans });
|
|
119
138
|
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
120
141
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Initialize OG object
|
|
144
|
+
* @param {*} merchantId
|
|
145
|
+
* @param {*} env
|
|
146
|
+
* @param {*} authUrl
|
|
147
|
+
*/
|
|
148
|
+
export function initialize(merchantId, env, authUrl) {
|
|
149
|
+
if (offers.isReady) {
|
|
150
|
+
console.warn('og.offers has been initialized already. Skipping.');
|
|
151
|
+
return offers;
|
|
152
|
+
}
|
|
125
153
|
|
|
126
|
-
|
|
154
|
+
store = getStore();
|
|
127
155
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
store.dispatch(actions.fetchAuth());
|
|
131
|
-
offers.register();
|
|
132
|
-
}
|
|
156
|
+
offers.store = store;
|
|
157
|
+
offers.resolveSettings(merchantId, env, window.og_settings, store);
|
|
133
158
|
|
|
134
|
-
|
|
159
|
+
setStore(store);
|
|
135
160
|
|
|
136
|
-
|
|
137
|
-
|
|
161
|
+
if (merchantId) offers.setMerchantId(merchantId);
|
|
162
|
+
if (env) offers.setEnvironment(env);
|
|
163
|
+
if (authUrl) offers.setAuthUrl(authUrl);
|
|
138
164
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return offers;
|
|
146
|
-
},
|
|
147
|
-
addTemplate(tagName, content, config) {
|
|
148
|
-
store.dispatch(actions.addTemplate(tagName, content, config));
|
|
149
|
-
return offers;
|
|
150
|
-
},
|
|
151
|
-
/**
|
|
152
|
-
* templates object where keys are selectors and values are content
|
|
153
|
-
*/
|
|
154
|
-
setTemplates(templates) {
|
|
155
|
-
store.dispatch(actions.setTemplates(templates));
|
|
156
|
-
return offers;
|
|
157
|
-
},
|
|
158
|
-
setPublicPath(publicPath) {
|
|
159
|
-
return offers;
|
|
165
|
+
window.addEventListener('storage', listenLocalStorageChanges(store));
|
|
166
|
+
|
|
167
|
+
if (merchantId && env) {
|
|
168
|
+
store.dispatch(actions.requestSessionId());
|
|
169
|
+
store.dispatch(actions.fetchAuth());
|
|
170
|
+
offers.register();
|
|
160
171
|
}
|
|
161
|
-
|
|
172
|
+
|
|
173
|
+
offers.isReady = true;
|
|
174
|
+
|
|
175
|
+
return offers;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export default initialize;
|
|
179
|
+
|
|
180
|
+
Object.assign(offers, {
|
|
181
|
+
setEnvironment,
|
|
182
|
+
setMerchantId,
|
|
183
|
+
setAuthUrl,
|
|
184
|
+
getProductsForPurchasePost,
|
|
185
|
+
getOptins,
|
|
186
|
+
clear,
|
|
187
|
+
addOptinChangedCallback,
|
|
188
|
+
disableOptinChangedCallbacks,
|
|
189
|
+
register,
|
|
190
|
+
previewMode,
|
|
191
|
+
config,
|
|
192
|
+
setLocale,
|
|
193
|
+
addTemplate,
|
|
194
|
+
setTemplates,
|
|
195
|
+
setPublicPath,
|
|
196
|
+
resolveSettings,
|
|
197
|
+
initialize
|
|
198
|
+
});
|
|
199
|
+
|
|
162
200
|
window.OG = window.OG || {};
|
|
163
201
|
Object.assign(window.OG, offers);
|
|
164
202
|
Object.assign(offers.initialize, offers);
|
|
165
203
|
|
|
166
204
|
offersLiveEditor();
|
|
167
205
|
|
|
168
|
-
// use this syntax to allow es6 module be called as default function og.offers(...)
|
|
169
|
-
module.exports = offers.initialize;
|
|
206
|
+
// // use this syntax to allow es6 module be called as default function og.offers(...)
|
|
207
|
+
// module.exports = offers.initialize;
|
package/src/init-func-tests.js
CHANGED
package/src/init-test.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { initialize } from './index';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
initialize('some-merchant', 'staging');
|