@ordergroove/offers 2.27.23-alpha-PR-672-4.2 → 2.27.23
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/CHANGELOG.md +8 -0
- package/dist/bundle-report.html +9 -9
- package/dist/examples.js +47 -43
- package/dist/examples.js.map +1 -1
- package/dist/offers.js +24 -24
- package/dist/offers.js.map +2 -2
- package/package.json +3 -3
- package/src/shopify/__tests__/shopifyReducer.spec.js +137 -271
- package/src/shopify/shopifyMiddleware.ts +15 -7
- package/src/shopify/shopifyReducer.js +34 -107
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.27.23
|
|
3
|
+
"version": "2.27.23",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"throttle-debounce": "^2.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ordergroove/offers-templates": "^0.4.
|
|
46
|
+
"@ordergroove/offers-templates": "^0.4.16"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "474581ad550212f9ee3f15ab60c7aff06bb4e3b6"
|
|
49
49
|
}
|
|
@@ -52,16 +52,14 @@ describe('autoshipEligible', () => {
|
|
|
52
52
|
{
|
|
53
53
|
type: constants.SETUP_PRODUCT,
|
|
54
54
|
payload: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
]
|
|
64
|
-
}
|
|
55
|
+
id: 'yum product id',
|
|
56
|
+
selling_plan_allocations: [{ 'yum key': 'yum value' }],
|
|
57
|
+
variants: [
|
|
58
|
+
{
|
|
59
|
+
id: 'yum variant id',
|
|
60
|
+
selling_plan_allocations: [{ 'yum key': 'yum value' }]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
);
|
|
@@ -75,16 +73,14 @@ describe('autoshipEligible', () => {
|
|
|
75
73
|
{
|
|
76
74
|
type: constants.SETUP_PRODUCT,
|
|
77
75
|
payload: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
]
|
|
87
|
-
}
|
|
76
|
+
id: 'yum product id',
|
|
77
|
+
selling_plan_allocations: [],
|
|
78
|
+
variants: [
|
|
79
|
+
{
|
|
80
|
+
id: 'yum variant id',
|
|
81
|
+
selling_plan_allocations: []
|
|
82
|
+
}
|
|
83
|
+
]
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
86
|
);
|
|
@@ -124,27 +120,55 @@ describe('config', () => {
|
|
|
124
120
|
);
|
|
125
121
|
});
|
|
126
122
|
|
|
123
|
+
it('should return first selling plan id as default frequency given action SETUP_PRODUCT', () => {
|
|
124
|
+
const actual = config(
|
|
125
|
+
{},
|
|
126
|
+
{
|
|
127
|
+
type: constants.SETUP_PRODUCT,
|
|
128
|
+
payload: {
|
|
129
|
+
selling_plan_groups: [
|
|
130
|
+
{
|
|
131
|
+
name: 'Subscribe and Save',
|
|
132
|
+
selling_plans: [
|
|
133
|
+
{
|
|
134
|
+
id: 'yum selling plan id 1'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'yum selling plan id 2'
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(actual).toEqual(
|
|
147
|
+
jasmine.objectContaining({
|
|
148
|
+
defaultFrequency: 'yum selling plan id 1'
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
127
153
|
it('should return selling plan ids as frequencies given action SETUP_PRODUCT', () => {
|
|
128
154
|
const actual = config(
|
|
129
155
|
{},
|
|
130
156
|
{
|
|
131
157
|
type: constants.SETUP_PRODUCT,
|
|
132
158
|
payload: {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
]
|
|
147
|
-
}
|
|
159
|
+
selling_plan_groups: [
|
|
160
|
+
{
|
|
161
|
+
name: 'Subscribe and Save',
|
|
162
|
+
selling_plans: [
|
|
163
|
+
{
|
|
164
|
+
id: 'yum selling plan id 1'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: 'yum selling plan id 2'
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
]
|
|
148
172
|
}
|
|
149
173
|
}
|
|
150
174
|
);
|
|
@@ -162,28 +186,26 @@ describe('config', () => {
|
|
|
162
186
|
{
|
|
163
187
|
type: constants.SETUP_PRODUCT,
|
|
164
188
|
payload: {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
]
|
|
186
|
-
}
|
|
189
|
+
selling_plan_groups: [
|
|
190
|
+
{
|
|
191
|
+
name: 'Old Selling Plan Group',
|
|
192
|
+
options: [{ values: 'old yum values' }],
|
|
193
|
+
selling_plans: [
|
|
194
|
+
{
|
|
195
|
+
id: 'old yum selling plan id'
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'Subscribe and Save',
|
|
201
|
+
options: [{ values: 'yum values' }],
|
|
202
|
+
selling_plans: [
|
|
203
|
+
{
|
|
204
|
+
id: 'yum selling plan id'
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
]
|
|
187
209
|
}
|
|
188
210
|
}
|
|
189
211
|
);
|
|
@@ -242,16 +264,14 @@ describe('inStock', () => {
|
|
|
242
264
|
{
|
|
243
265
|
type: constants.SETUP_PRODUCT,
|
|
244
266
|
payload: {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
]
|
|
254
|
-
}
|
|
267
|
+
id: 'yum product id',
|
|
268
|
+
available: true,
|
|
269
|
+
variants: [
|
|
270
|
+
{
|
|
271
|
+
id: 'yum variant id',
|
|
272
|
+
available: true
|
|
273
|
+
}
|
|
274
|
+
]
|
|
255
275
|
}
|
|
256
276
|
}
|
|
257
277
|
);
|
|
@@ -268,16 +288,14 @@ describe('inStock', () => {
|
|
|
268
288
|
{
|
|
269
289
|
type: constants.SETUP_PRODUCT,
|
|
270
290
|
payload: {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
]
|
|
280
|
-
}
|
|
291
|
+
id: 'yum product id',
|
|
292
|
+
available: false,
|
|
293
|
+
variants: [
|
|
294
|
+
{
|
|
295
|
+
id: 'yum variant id',
|
|
296
|
+
available: false
|
|
297
|
+
}
|
|
298
|
+
]
|
|
281
299
|
}
|
|
282
300
|
}
|
|
283
301
|
);
|
|
@@ -347,156 +365,6 @@ describe('optedin', () => {
|
|
|
347
365
|
]);
|
|
348
366
|
});
|
|
349
367
|
|
|
350
|
-
it('should return existing optin given action RECEIVE_OFFER and optin already exists in state, and new optin is ineligible for autoship by default', () => {
|
|
351
|
-
const actual = optedin(
|
|
352
|
-
[
|
|
353
|
-
{
|
|
354
|
-
id: 'yum product id 1',
|
|
355
|
-
frequency: 'yum existing frequency'
|
|
356
|
-
}
|
|
357
|
-
],
|
|
358
|
-
{
|
|
359
|
-
type: constants.RECEIVE_OFFER,
|
|
360
|
-
payload: {
|
|
361
|
-
autoship: {
|
|
362
|
-
'yum product id 1': false
|
|
363
|
-
},
|
|
364
|
-
autoship_by_default: {
|
|
365
|
-
'yum product id 1': false
|
|
366
|
-
},
|
|
367
|
-
in_stock: {
|
|
368
|
-
'yum product id 1': false
|
|
369
|
-
},
|
|
370
|
-
offer: {
|
|
371
|
-
defaultFrequency: 'yum offer default frequency'
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
expect(actual).toEqual([
|
|
378
|
-
{
|
|
379
|
-
id: 'yum product id 1',
|
|
380
|
-
frequency: 'yum existing frequency'
|
|
381
|
-
}
|
|
382
|
-
]);
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('should return existing optin given action RECEIVE_OFFER, optin already exists in state, and new optin is eligible for autoship by default', () => {
|
|
386
|
-
const actual = optedin(
|
|
387
|
-
[
|
|
388
|
-
{
|
|
389
|
-
id: 'yum product id 1',
|
|
390
|
-
frequency: 'yum existing frequency'
|
|
391
|
-
}
|
|
392
|
-
],
|
|
393
|
-
{
|
|
394
|
-
type: constants.RECEIVE_OFFER,
|
|
395
|
-
payload: {
|
|
396
|
-
autoship: {
|
|
397
|
-
'yum product id 1': true
|
|
398
|
-
},
|
|
399
|
-
autoship_by_default: {
|
|
400
|
-
'yum product id 1': true
|
|
401
|
-
},
|
|
402
|
-
in_stock: {
|
|
403
|
-
'yum product id 1': true
|
|
404
|
-
},
|
|
405
|
-
offer: {
|
|
406
|
-
defaultFrequency: 'yum offer default frequency'
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
expect(actual).toEqual([
|
|
413
|
-
{
|
|
414
|
-
id: 'yum product id 1',
|
|
415
|
-
frequency: 'yum existing frequency'
|
|
416
|
-
}
|
|
417
|
-
]);
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
it('should return existing optin given action RECEIVE_OFFER, optin already exists in state, and new optin is eligible for autoship by default', () => {
|
|
421
|
-
const actual = optedin(
|
|
422
|
-
[
|
|
423
|
-
{
|
|
424
|
-
id: 'yum product id 1',
|
|
425
|
-
frequency: 'yum existing frequency'
|
|
426
|
-
}
|
|
427
|
-
],
|
|
428
|
-
{
|
|
429
|
-
type: constants.RECEIVE_OFFER,
|
|
430
|
-
payload: {
|
|
431
|
-
autoship: {
|
|
432
|
-
'yum product id 1': true
|
|
433
|
-
},
|
|
434
|
-
autoship_by_default: {
|
|
435
|
-
'yum product id 1': true
|
|
436
|
-
},
|
|
437
|
-
in_stock: {
|
|
438
|
-
'yum product id 1': true
|
|
439
|
-
},
|
|
440
|
-
offer: {
|
|
441
|
-
defaultFrequency: 'yum offer default frequency'
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
expect(actual).toEqual([
|
|
448
|
-
{
|
|
449
|
-
id: 'yum product id 1',
|
|
450
|
-
frequency: 'yum existing frequency'
|
|
451
|
-
}
|
|
452
|
-
]);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it('should return no optin given action RECEIVE_OFFER, optin does not exist in state, and product is not eligible for default to subscription', () => {
|
|
456
|
-
const actual = optedin([], {
|
|
457
|
-
type: constants.RECEIVE_OFFER,
|
|
458
|
-
payload: {
|
|
459
|
-
product: {},
|
|
460
|
-
offer: {
|
|
461
|
-
autoship: false,
|
|
462
|
-
autoship_by_default: false,
|
|
463
|
-
in_stock: false
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
expect(actual).toEqual([]);
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
it('should return optin given action RECEIVE_OFFER, optin does not exist in state, and product is eligible for default to subscription', () => {
|
|
472
|
-
const actual = optedin(
|
|
473
|
-
[
|
|
474
|
-
{
|
|
475
|
-
id: 'yum item id 1',
|
|
476
|
-
frequency: 'yum selling plan id 1'
|
|
477
|
-
}
|
|
478
|
-
],
|
|
479
|
-
{
|
|
480
|
-
type: constants.RECEIVE_OFFER,
|
|
481
|
-
payload: {
|
|
482
|
-
product: {},
|
|
483
|
-
offer: {
|
|
484
|
-
autoship: true,
|
|
485
|
-
autoship_by_default: true,
|
|
486
|
-
in_stock: true
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
expect(actual).toEqual([
|
|
493
|
-
{
|
|
494
|
-
id: 'yum item id 1',
|
|
495
|
-
frequency: 'yum selling plan id 1'
|
|
496
|
-
}
|
|
497
|
-
]);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
368
|
it('should return unmodified state given unsupported action', () => {
|
|
501
369
|
const actual = optedin(
|
|
502
370
|
{ 'yum existing key': 'yum existing value' },
|
|
@@ -525,50 +393,48 @@ describe('productPlans', () => {
|
|
|
525
393
|
{
|
|
526
394
|
type: constants.SETUP_PRODUCT,
|
|
527
395
|
payload: {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
]
|
|
571
|
-
}
|
|
396
|
+
id: 'yum product id',
|
|
397
|
+
selling_plan_allocations: [
|
|
398
|
+
{
|
|
399
|
+
selling_plan_id: 'yum selling plan id 1',
|
|
400
|
+
compare_at_price: 100,
|
|
401
|
+
price: 50,
|
|
402
|
+
price_adjustments: [
|
|
403
|
+
{
|
|
404
|
+
value: 50,
|
|
405
|
+
value_type: 'percentage'
|
|
406
|
+
}
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
],
|
|
410
|
+
variants: [
|
|
411
|
+
{
|
|
412
|
+
id: 'yum variant id 1',
|
|
413
|
+
selling_plan_allocations: [
|
|
414
|
+
{
|
|
415
|
+
selling_plan_id: 'yum selling plan id 2',
|
|
416
|
+
compare_at_price: 50,
|
|
417
|
+
price: 25,
|
|
418
|
+
price_adjustments: [
|
|
419
|
+
{
|
|
420
|
+
value: 25
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
}
|
|
424
|
+
]
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
id: 'yum variant id 2',
|
|
428
|
+
selling_plan_allocations: [
|
|
429
|
+
{
|
|
430
|
+
selling_plan_id: 'yum selling plan id 3',
|
|
431
|
+
compare_at_price: 10,
|
|
432
|
+
price: 8,
|
|
433
|
+
price_adjustments: []
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
}
|
|
437
|
+
]
|
|
572
438
|
}
|
|
573
439
|
}
|
|
574
440
|
);
|
|
@@ -38,8 +38,7 @@ async function setupPdp(store, offer) {
|
|
|
38
38
|
const handle = guessProductHandle();
|
|
39
39
|
if (handle) {
|
|
40
40
|
try {
|
|
41
|
-
|
|
42
|
-
store.dispatch({ type: SETUP_PRODUCT, payload: { product, offer } });
|
|
41
|
+
store.dispatch({ type: SETUP_PRODUCT, payload: await getProduct(handle) });
|
|
43
42
|
} catch (err) {
|
|
44
43
|
console.warn('OG: Unable to fetch product details for PDP', err);
|
|
45
44
|
}
|
|
@@ -127,7 +126,7 @@ async function setupCart(store, offer) {
|
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
const products = await Promise.all(Array.from(new Set(items.map(({ handle }) => handle))).map(getProduct));
|
|
130
|
-
products.forEach(product => store.dispatch({ type: SETUP_PRODUCT, payload:
|
|
129
|
+
products.forEach(product => store.dispatch({ type: SETUP_PRODUCT, payload: product }));
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
/**
|
|
@@ -359,21 +358,30 @@ export default function shopifyMiddleware(store) {
|
|
|
359
358
|
* This redux middleware will perform Shopify specific side-effects such as change
|
|
360
359
|
* the product selling plan when offer is cart
|
|
361
360
|
*/
|
|
362
|
-
|
|
363
|
-
next(action);
|
|
364
|
-
|
|
365
361
|
switch (action.type) {
|
|
366
|
-
case
|
|
362
|
+
case OPTIN_PRODUCT:
|
|
363
|
+
case OPTOUT_PRODUCT:
|
|
364
|
+
case PRODUCT_CHANGE_FREQUENCY:
|
|
365
|
+
break;
|
|
366
|
+
case REQUEST_OFFER:
|
|
367
367
|
if (action.payload.offer?.isCart) {
|
|
368
368
|
setupCart(store, action.payload.offer);
|
|
369
369
|
} else {
|
|
370
370
|
setupPdp(store, action.payload.offer);
|
|
371
371
|
}
|
|
372
372
|
break;
|
|
373
|
+
default:
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
next(action);
|
|
377
|
+
|
|
378
|
+
switch (action.type) {
|
|
373
379
|
case OPTIN_PRODUCT:
|
|
374
380
|
case OPTOUT_PRODUCT:
|
|
375
381
|
case PRODUCT_CHANGE_FREQUENCY:
|
|
376
382
|
synchronizeCartOptin(action, store);
|
|
383
|
+
case REQUEST_OFFER:
|
|
384
|
+
case RECEIVE_OFFER:
|
|
377
385
|
case SETUP_PRODUCT:
|
|
378
386
|
synchronizeSellingPlan(store, action.payload.offer);
|
|
379
387
|
break;
|