@merchi/cart 1.4.63 → 1.4.65
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/esm/CartProvider.js +337 -250
- package/esm/CartProvider.load.test.js +1236 -282
- package/esm/utilities/automatedClient.js +5 -0
- package/esm/utilities/automatedClient.test.js +9 -0
- package/lib/CartProvider.js +337 -250
- package/lib/utilities/automatedClient.d.ts +2 -0
- package/lib/utilities/automatedClient.js +11 -0
- package/lib/utilities/automatedClient.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/CartProvider.load.test.tsx +278 -2
- package/src/CartProvider.tsx +85 -51
- package/src/utilities/automatedClient.test.ts +21 -0
- package/src/utilities/automatedClient.ts +6 -0
package/esm/CartProvider.js
CHANGED
|
@@ -19,7 +19,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
19
19
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
20
20
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
21
21
|
import * as React from 'react';
|
|
22
|
-
import { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
22
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
23
23
|
import { faCheckCircle, faExclamationTriangle, faInfoCircle } from '@fortawesome/free-solid-svg-icons';
|
|
24
24
|
import { makeCart, makeCartItem, stripeIsValidAndActive } from './utilities/cart';
|
|
25
25
|
import { cartEmbed } from './utilities/helpers';
|
|
@@ -34,9 +34,11 @@ import { getSavedCheckoutCustomer, saveCheckoutAddress } from './utilities/local
|
|
|
34
34
|
import { makeUser } from './utilities/user';
|
|
35
35
|
import { persistTestCheckoutFlag, readTestCheckoutFlag } from './utilities/test_checkout';
|
|
36
36
|
import { reportAddCartItemFailure, reportCartFailure, CART_FAILURE_SOURCES } from './utilities/reportFailure';
|
|
37
|
+
import { isAutomatedClient } from './utilities/automatedClient';
|
|
37
38
|
import { canReplaceMissingCart } from './utilities/cartLoadFailure';
|
|
38
39
|
import { appendJobSourceToFormData, captureAndReadJobSource, cartNeedsSourceUpdate, jobSourceFieldsForApi } from './utilities/job_source';
|
|
39
40
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
41
|
+
var useCartBindingsEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
40
42
|
var CartContext = /*#__PURE__*/createContext({
|
|
41
43
|
cart: {},
|
|
42
44
|
cartClient: {},
|
|
@@ -433,68 +435,68 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
433
435
|
return _attachSavedClientIfNeeded.apply(this, arguments);
|
|
434
436
|
} // Create cart and save cart cookie
|
|
435
437
|
function _attachSavedClientIfNeeded() {
|
|
436
|
-
_attachSavedClientIfNeeded = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
438
|
+
_attachSavedClientIfNeeded = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(cartJson) {
|
|
437
439
|
var _cartJson$client;
|
|
438
|
-
var savedCustomer, _nextCart$client, cartToken, clientEnt, cartEnt, savedCart, nextCart,
|
|
439
|
-
return _regenerator().w(function (
|
|
440
|
-
while (1) switch (
|
|
440
|
+
var savedCustomer, _nextCart$client, cartToken, clientEnt, cartEnt, savedCart, nextCart, _t3, _t4;
|
|
441
|
+
return _regenerator().w(function (_context3) {
|
|
442
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
441
443
|
case 0:
|
|
442
444
|
if (!(cartJson !== null && cartJson !== void 0 && (_cartJson$client = cartJson.client) !== null && _cartJson$client !== void 0 && _cartJson$client.id)) {
|
|
443
|
-
|
|
445
|
+
_context3.n = 1;
|
|
444
446
|
break;
|
|
445
447
|
}
|
|
446
448
|
setCartClient(cartJson.client);
|
|
447
|
-
return
|
|
449
|
+
return _context3.a(2, cartJson);
|
|
448
450
|
case 1:
|
|
449
451
|
savedCustomer = getSavedCheckoutCustomer(domainId);
|
|
450
452
|
if (savedCustomer !== null && savedCustomer !== void 0 && savedCustomer.id) {
|
|
451
|
-
|
|
453
|
+
_context3.n = 2;
|
|
452
454
|
break;
|
|
453
455
|
}
|
|
454
456
|
setCartClient(null);
|
|
455
|
-
return
|
|
457
|
+
return _context3.a(2, cartJson);
|
|
456
458
|
case 2:
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
459
|
+
_context3.p = 2;
|
|
460
|
+
_t3 = cartJson.token;
|
|
461
|
+
if (_t3) {
|
|
462
|
+
_context3.n = 4;
|
|
461
463
|
break;
|
|
462
464
|
}
|
|
463
|
-
|
|
465
|
+
_context3.n = 3;
|
|
464
466
|
return getCartCookieToken(domainId);
|
|
465
467
|
case 3:
|
|
466
|
-
|
|
468
|
+
_t3 = _context3.v;
|
|
467
469
|
case 4:
|
|
468
|
-
cartToken =
|
|
470
|
+
cartToken = _t3;
|
|
469
471
|
clientEnt = makeUser({
|
|
470
472
|
id: savedCustomer.id
|
|
471
473
|
}, true);
|
|
472
474
|
cartEnt = makeCart(_objectSpread({}, cartJson), false, cartToken);
|
|
473
475
|
cartEnt.client = clientEnt;
|
|
474
|
-
|
|
476
|
+
_context3.n = 5;
|
|
475
477
|
return cartEnt.save({
|
|
476
478
|
embed: cartEmbed
|
|
477
479
|
});
|
|
478
480
|
case 5:
|
|
479
|
-
savedCart =
|
|
481
|
+
savedCart = _context3.v;
|
|
480
482
|
nextCart = savedCart.toJson();
|
|
481
483
|
if (!(nextCart !== null && nextCart !== void 0 && (_nextCart$client = nextCart.client) !== null && _nextCart$client !== void 0 && _nextCart$client.id)) {
|
|
482
|
-
|
|
484
|
+
_context3.n = 6;
|
|
483
485
|
break;
|
|
484
486
|
}
|
|
485
487
|
setCartClient(nextCart.client);
|
|
486
|
-
return
|
|
488
|
+
return _context3.a(2, nextCart);
|
|
487
489
|
case 6:
|
|
488
|
-
|
|
490
|
+
_context3.n = 8;
|
|
489
491
|
break;
|
|
490
492
|
case 7:
|
|
491
|
-
|
|
492
|
-
|
|
493
|
+
_context3.p = 7;
|
|
494
|
+
_t4 = _context3.v;
|
|
493
495
|
case 8:
|
|
494
496
|
setCartClient(null);
|
|
495
|
-
return
|
|
497
|
+
return _context3.a(2, cartJson);
|
|
496
498
|
}
|
|
497
|
-
},
|
|
499
|
+
}, _callee3, null, [[2, 7]]);
|
|
498
500
|
}));
|
|
499
501
|
return _attachSavedClientIfNeeded.apply(this, arguments);
|
|
500
502
|
}
|
|
@@ -502,13 +504,13 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
502
504
|
return _createCartAndCookie.apply(this, arguments);
|
|
503
505
|
}
|
|
504
506
|
function _createCartAndCookie() {
|
|
505
|
-
_createCartAndCookie = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
506
|
-
var isTest, jobSource, _cart, query, created, cartJson,
|
|
507
|
-
return _regenerator().w(function (
|
|
508
|
-
while (1) switch (
|
|
507
|
+
_createCartAndCookie = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(callback) {
|
|
508
|
+
var isTest, jobSource, _cart, query, created, cartJson, _t5;
|
|
509
|
+
return _regenerator().w(function (_context4) {
|
|
510
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
509
511
|
case 0:
|
|
510
512
|
setFetchingCart(true);
|
|
511
|
-
|
|
513
|
+
_context4.p = 1;
|
|
512
514
|
isTest = readTestCheckoutFlag();
|
|
513
515
|
jobSource = jobSourceFieldsForApi(captureAndReadJobSource());
|
|
514
516
|
_cart = makeCart({
|
|
@@ -519,136 +521,150 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
519
521
|
}, true);
|
|
520
522
|
query = [['embed', JSON.stringify(cartEmbed)], ['skip_rights', 'y']];
|
|
521
523
|
if (isTest) query.push(['is_test', 'true']);
|
|
522
|
-
|
|
524
|
+
_context4.n = 2;
|
|
523
525
|
return merchi.authenticatedFetch('/carts/', {
|
|
524
526
|
method: 'POST',
|
|
525
527
|
body: appendJobSourceToFormData(_cart.toFormData(), jobSource),
|
|
526
528
|
query: query
|
|
527
529
|
});
|
|
528
530
|
case 2:
|
|
529
|
-
created =
|
|
531
|
+
created = _context4.v;
|
|
530
532
|
_cart.fromJson(created.cart);
|
|
531
|
-
|
|
533
|
+
_context4.n = 3;
|
|
532
534
|
return _cart.toJson();
|
|
533
535
|
case 3:
|
|
534
|
-
cartJson =
|
|
536
|
+
cartJson = _context4.v;
|
|
535
537
|
if (domainId) setCartCookie(Number(domainId), cartJson, undefined, isTest);
|
|
536
|
-
|
|
538
|
+
_context4.n = 4;
|
|
537
539
|
return attachSavedClientIfNeeded(cartJson);
|
|
538
540
|
case 4:
|
|
539
|
-
cartJson =
|
|
541
|
+
cartJson = _context4.v;
|
|
540
542
|
setCart(_objectSpread({}, cartJson));
|
|
541
543
|
if (callback) callback();
|
|
542
|
-
|
|
543
|
-
break;
|
|
544
|
+
return _context4.a(2, cartJson);
|
|
544
545
|
case 5:
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
reportCartFailure(
|
|
548
|
-
alertError((
|
|
546
|
+
_context4.p = 5;
|
|
547
|
+
_t5 = _context4.v;
|
|
548
|
+
reportCartFailure(_t5, CART_FAILURE_SOURCES.create);
|
|
549
|
+
alertError((_t5 === null || _t5 === void 0 ? void 0 : _t5.errorMessage) || (_t5 === null || _t5 === void 0 ? void 0 : _t5.message) || 'Unable to fetch cart.');
|
|
549
550
|
case 6:
|
|
550
|
-
|
|
551
|
+
_context4.p = 6;
|
|
551
552
|
setFetchingCart(false);
|
|
552
|
-
return
|
|
553
|
+
return _context4.f(6);
|
|
553
554
|
case 7:
|
|
554
|
-
return
|
|
555
|
+
return _context4.a(2, undefined);
|
|
555
556
|
}
|
|
556
|
-
},
|
|
557
|
+
}, _callee4, null, [[1, 5, 6, 7]]);
|
|
557
558
|
}));
|
|
558
559
|
return _createCartAndCookie.apply(this, arguments);
|
|
559
560
|
}
|
|
560
|
-
function
|
|
561
|
+
function requestNewCart(_x3) {
|
|
562
|
+
return _requestNewCart.apply(this, arguments);
|
|
563
|
+
}
|
|
564
|
+
function _requestNewCart() {
|
|
565
|
+
_requestNewCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(callback) {
|
|
566
|
+
return _regenerator().w(function (_context5) {
|
|
567
|
+
while (1) switch (_context5.n) {
|
|
568
|
+
case 0:
|
|
569
|
+
_context5.n = 1;
|
|
570
|
+
return createCartAndCookie(callback);
|
|
571
|
+
case 1:
|
|
572
|
+
return _context5.a(2);
|
|
573
|
+
}
|
|
574
|
+
}, _callee5);
|
|
575
|
+
}));
|
|
576
|
+
return _requestNewCart.apply(this, arguments);
|
|
577
|
+
}
|
|
578
|
+
function getCart(_x4) {
|
|
561
579
|
return _getCart.apply(this, arguments);
|
|
562
580
|
} // A checkout link can name the cart. Remember it once, then keep using the cookie
|
|
563
581
|
// so a later refetch does not put that cart back after the shopper replaced it.
|
|
564
582
|
function _getCart() {
|
|
565
|
-
_getCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
566
|
-
var id, _cart2, cartJson, isTest, jobSource, saved,
|
|
567
|
-
return _regenerator().w(function (
|
|
568
|
-
while (1) switch (
|
|
583
|
+
_getCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(cartIdAndToken) {
|
|
584
|
+
var id, _cart2, cartJson, isTest, jobSource, saved, _t6;
|
|
585
|
+
return _regenerator().w(function (_context6) {
|
|
586
|
+
while (1) switch (_context6.p = _context6.n) {
|
|
569
587
|
case 0:
|
|
570
588
|
id = Number(cartIdAndToken[0]); // Set the cart token on the merchi entity
|
|
571
589
|
if (cartIdAndToken[1]) merchi.cartToken = cartIdAndToken[1];
|
|
572
590
|
setFetchingCart(true);
|
|
573
|
-
|
|
574
|
-
|
|
591
|
+
_context6.p = 1;
|
|
592
|
+
_context6.n = 2;
|
|
575
593
|
return merchi.Cart.get(id, {
|
|
576
594
|
embed: cartEmbed
|
|
577
595
|
});
|
|
578
596
|
case 2:
|
|
579
|
-
_cart2 =
|
|
580
|
-
|
|
597
|
+
_cart2 = _context6.v;
|
|
598
|
+
_context6.n = 3;
|
|
581
599
|
return _cart2.toJson();
|
|
582
600
|
case 3:
|
|
583
|
-
cartJson =
|
|
601
|
+
cartJson = _context6.v;
|
|
584
602
|
isTest = readTestCheckoutFlag();
|
|
585
603
|
if (!(Boolean(cartJson.isTest) !== isTest)) {
|
|
586
|
-
|
|
604
|
+
_context6.n = 5;
|
|
587
605
|
break;
|
|
588
606
|
}
|
|
589
|
-
|
|
607
|
+
_context6.n = 4;
|
|
590
608
|
return createCartAndCookie();
|
|
591
609
|
case 4:
|
|
592
|
-
return
|
|
610
|
+
return _context6.a(2, _context6.v);
|
|
593
611
|
case 5:
|
|
594
612
|
jobSource = jobSourceFieldsForApi(captureAndReadJobSource());
|
|
595
613
|
if (!cartNeedsSourceUpdate(cartJson, jobSource)) {
|
|
596
|
-
|
|
614
|
+
_context6.n = 7;
|
|
597
615
|
break;
|
|
598
616
|
}
|
|
599
|
-
|
|
617
|
+
_context6.n = 6;
|
|
600
618
|
return merchi.authenticatedFetch("/carts/".concat(_cart2.id, "/"), {
|
|
601
619
|
method: 'PATCH',
|
|
602
620
|
body: appendJobSourceToFormData(_cart2.toFormData(), jobSource),
|
|
603
621
|
query: [['embed', JSON.stringify(cartEmbed)], ['skip_rights', 'y']]
|
|
604
622
|
});
|
|
605
623
|
case 6:
|
|
606
|
-
saved =
|
|
624
|
+
saved = _context6.v;
|
|
607
625
|
_cart2.fromJson(saved.cart);
|
|
608
626
|
cartJson = _cart2.toJson();
|
|
609
627
|
case 7:
|
|
610
628
|
if (!(stripeIsValidAndActive(cartJson) || isTest)) {
|
|
611
|
-
|
|
629
|
+
_context6.n = 9;
|
|
612
630
|
break;
|
|
613
631
|
}
|
|
614
|
-
|
|
632
|
+
_context6.n = 8;
|
|
615
633
|
return attachSavedClientIfNeeded(cartJson);
|
|
616
634
|
case 8:
|
|
617
|
-
cartJson =
|
|
635
|
+
cartJson = _context6.v;
|
|
618
636
|
setCart(_objectSpread({}, cartJson));
|
|
619
|
-
|
|
620
|
-
break;
|
|
637
|
+
return _context6.a(2, cartJson);
|
|
621
638
|
case 9:
|
|
622
639
|
console.error("MErhci cart error: Stripe payment " + "options have not been correctly set up. " + "Check the company profile payment options tab " + "to set and edit stripe payment options.");
|
|
623
640
|
setCartSettingsInvalid(true);
|
|
624
641
|
case 10:
|
|
625
|
-
|
|
642
|
+
_context6.n = 14;
|
|
626
643
|
break;
|
|
627
644
|
case 11:
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (!canReplaceMissingCart(
|
|
631
|
-
|
|
645
|
+
_context6.p = 11;
|
|
646
|
+
_t6 = _context6.v;
|
|
647
|
+
if (!canReplaceMissingCart(_t6)) {
|
|
648
|
+
_context6.n = 13;
|
|
632
649
|
break;
|
|
633
650
|
}
|
|
634
|
-
|
|
651
|
+
_context6.n = 12;
|
|
635
652
|
return createCartAndCookie();
|
|
636
653
|
case 12:
|
|
637
|
-
|
|
638
|
-
break;
|
|
654
|
+
return _context6.a(2, _context6.v);
|
|
639
655
|
case 13:
|
|
640
656
|
// A network/server/auth failure does not mean the saved cart is gone.
|
|
641
657
|
// Preserve its cookie and contents so the shopper can retry the read.
|
|
642
|
-
reportCartFailure(
|
|
643
|
-
alertError((
|
|
658
|
+
reportCartFailure(_t6, CART_FAILURE_SOURCES.load);
|
|
659
|
+
alertError((_t6 === null || _t6 === void 0 ? void 0 : _t6.errorMessage) || (_t6 === null || _t6 === void 0 ? void 0 : _t6.message) || 'Unable to load cart. Please try again.');
|
|
644
660
|
case 14:
|
|
645
|
-
|
|
661
|
+
_context6.p = 14;
|
|
646
662
|
setFetchingCart(false);
|
|
647
|
-
return
|
|
663
|
+
return _context6.f(14);
|
|
648
664
|
case 15:
|
|
649
|
-
return
|
|
665
|
+
return _context6.a(2, undefined);
|
|
650
666
|
}
|
|
651
|
-
},
|
|
667
|
+
}, _callee6, null, [[1, 11, 14, 15]]);
|
|
652
668
|
}));
|
|
653
669
|
return _getCart.apply(this, arguments);
|
|
654
670
|
}
|
|
@@ -656,92 +672,115 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
656
672
|
return _adoptHandoffCart.apply(this, arguments);
|
|
657
673
|
}
|
|
658
674
|
function _adoptHandoffCart() {
|
|
659
|
-
_adoptHandoffCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
675
|
+
_adoptHandoffCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
660
676
|
var raw, handoff;
|
|
661
|
-
return _regenerator().w(function (
|
|
662
|
-
while (1) switch (
|
|
677
|
+
return _regenerator().w(function (_context7) {
|
|
678
|
+
while (1) switch (_context7.n) {
|
|
663
679
|
case 0:
|
|
664
680
|
if (!(typeof window === 'undefined' || !domainId)) {
|
|
665
|
-
|
|
681
|
+
_context7.n = 1;
|
|
666
682
|
break;
|
|
667
683
|
}
|
|
668
|
-
return
|
|
684
|
+
return _context7.a(2);
|
|
669
685
|
case 1:
|
|
670
686
|
raw = new URLSearchParams(window.location.search).get('cart');
|
|
671
687
|
if (!(!raw || raw === appliedHandoffCart.current)) {
|
|
672
|
-
|
|
688
|
+
_context7.n = 2;
|
|
673
689
|
break;
|
|
674
690
|
}
|
|
675
|
-
return
|
|
691
|
+
return _context7.a(2);
|
|
676
692
|
case 2:
|
|
677
693
|
handoff = readHandoffCart(window.location.search);
|
|
678
694
|
if (handoff) {
|
|
679
|
-
|
|
695
|
+
_context7.n = 3;
|
|
680
696
|
break;
|
|
681
697
|
}
|
|
682
|
-
return
|
|
698
|
+
return _context7.a(2);
|
|
683
699
|
case 3:
|
|
684
700
|
appliedHandoffCart.current = raw;
|
|
685
|
-
|
|
701
|
+
_context7.n = 4;
|
|
686
702
|
return setCartCookie(Number(domainId), {
|
|
687
703
|
id: handoff[0],
|
|
688
704
|
token: handoff[1]
|
|
689
705
|
});
|
|
690
706
|
case 4:
|
|
691
|
-
return
|
|
707
|
+
return _context7.a(2);
|
|
692
708
|
}
|
|
693
|
-
},
|
|
709
|
+
}, _callee7);
|
|
694
710
|
}));
|
|
695
711
|
return _adoptHandoffCart.apply(this, arguments);
|
|
696
712
|
}
|
|
697
713
|
function actionGetMerchiCart() {
|
|
714
|
+
var allowCreation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
698
715
|
var active = cartInitializations.current.get(domainId);
|
|
699
|
-
if (active) return active;
|
|
700
716
|
// Mount, modal opening and explicit callers may run before React commits
|
|
701
717
|
// fetchingCart. Share the whole cookie lookup/read-or-create operation.
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
718
|
+
if (!active) {
|
|
719
|
+
active = Promise.resolve().then(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
720
|
+
var cartIdAndToken, _t, _t2;
|
|
721
|
+
return _regenerator().w(function (_context) {
|
|
722
|
+
while (1) switch (_context.n) {
|
|
723
|
+
case 0:
|
|
724
|
+
_context.n = 1;
|
|
725
|
+
return adoptHandoffCart();
|
|
726
|
+
case 1:
|
|
727
|
+
_context.n = 2;
|
|
728
|
+
return getCartCookie(domainId);
|
|
729
|
+
case 2:
|
|
730
|
+
cartIdAndToken = _context.v;
|
|
731
|
+
if (!cartIdAndToken) {
|
|
732
|
+
_context.n = 4;
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
_context.n = 3;
|
|
736
|
+
return getCart(cartIdAndToken);
|
|
737
|
+
case 3:
|
|
738
|
+
_t = _context.v;
|
|
739
|
+
return _context.a(2, {
|
|
740
|
+
skippedCreation: false,
|
|
741
|
+
cart: _t
|
|
742
|
+
});
|
|
743
|
+
case 4:
|
|
744
|
+
if (!allowCreation) {
|
|
745
|
+
_context.n = 6;
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
_context.n = 5;
|
|
749
|
+
return createCartAndCookie();
|
|
750
|
+
case 5:
|
|
751
|
+
_t2 = _context.v;
|
|
752
|
+
return _context.a(2, {
|
|
753
|
+
skippedCreation: false,
|
|
754
|
+
cart: _t2
|
|
755
|
+
});
|
|
756
|
+
case 6:
|
|
757
|
+
return _context.a(2, {
|
|
758
|
+
skippedCreation: true
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}, _callee);
|
|
762
|
+
})))["finally"](function () {
|
|
763
|
+
cartInitializations.current["delete"](domainId);
|
|
764
|
+
});
|
|
765
|
+
cartInitializations.current.set(domainId, active);
|
|
766
|
+
}
|
|
767
|
+
return active.then(function (result) {
|
|
768
|
+
// An explicit caller can join passive startup before its cookie lookup
|
|
769
|
+
// finishes. Once that no-op completes, create through the same shared
|
|
770
|
+
// initialization path so concurrent explicit callers still issue one POST.
|
|
771
|
+
if (result.skippedCreation && allowCreation) return actionGetMerchiCart();
|
|
772
|
+
return result.cart;
|
|
732
773
|
});
|
|
733
|
-
cartInitializations.current.set(domainId, initialization);
|
|
734
|
-
return initialization;
|
|
735
774
|
}
|
|
736
|
-
function clearCart(
|
|
775
|
+
function clearCart(_x5) {
|
|
737
776
|
return _clearCart.apply(this, arguments);
|
|
738
777
|
}
|
|
739
778
|
function _clearCart() {
|
|
740
|
-
_clearCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
741
|
-
return _regenerator().w(function (
|
|
742
|
-
while (1) switch (
|
|
779
|
+
_clearCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(callback) {
|
|
780
|
+
return _regenerator().w(function (_context8) {
|
|
781
|
+
while (1) switch (_context8.n) {
|
|
743
782
|
case 0:
|
|
744
|
-
|
|
783
|
+
_context8.n = 1;
|
|
745
784
|
return createCartAndCookie(function () {
|
|
746
785
|
setAlert(function (previous) {
|
|
747
786
|
return _objectSpread(_objectSpread({}, previous), {}, {
|
|
@@ -752,9 +791,9 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
752
791
|
closeClearCart();
|
|
753
792
|
});
|
|
754
793
|
case 1:
|
|
755
|
-
return
|
|
794
|
+
return _context8.a(2);
|
|
756
795
|
}
|
|
757
|
-
},
|
|
796
|
+
}, _callee8);
|
|
758
797
|
}));
|
|
759
798
|
return _clearCart.apply(this, arguments);
|
|
760
799
|
}
|
|
@@ -762,60 +801,60 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
762
801
|
_useState18 = _slicedToArray(_useState17, 2),
|
|
763
802
|
fetchingShipmentGroups = _useState18[0],
|
|
764
803
|
setFetchingShipmentGroups = _useState18[1];
|
|
765
|
-
function updateCartShipmentAddress(
|
|
804
|
+
function updateCartShipmentAddress(_x6) {
|
|
766
805
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
767
806
|
}
|
|
768
807
|
function _updateCartShipmentAddress() {
|
|
769
|
-
_updateCartShipmentAddress = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
770
|
-
var token, addressFields, receiverAddress, cartEnt, cartJson, query, cartWithShipmentGroups,
|
|
771
|
-
return _regenerator().w(function (
|
|
772
|
-
while (1) switch (
|
|
808
|
+
_updateCartShipmentAddress = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(address) {
|
|
809
|
+
var token, addressFields, receiverAddress, cartEnt, cartJson, query, cartWithShipmentGroups, _t7;
|
|
810
|
+
return _regenerator().w(function (_context9) {
|
|
811
|
+
while (1) switch (_context9.p = _context9.n) {
|
|
773
812
|
case 0:
|
|
774
|
-
|
|
813
|
+
_context9.n = 1;
|
|
775
814
|
return getCartCookieToken(domainId);
|
|
776
815
|
case 1:
|
|
777
|
-
token =
|
|
816
|
+
token = _context9.v;
|
|
778
817
|
addressFields = sanitizeAddressFields(address);
|
|
779
818
|
receiverAddress = makeAddress(addressFields, true);
|
|
780
819
|
cartEnt = makeCart(cart, false, token);
|
|
781
820
|
setFetchingShipmentGroups(true);
|
|
782
|
-
|
|
821
|
+
_context9.p = 2;
|
|
783
822
|
cartEnt.receiverAddress = receiverAddress;
|
|
784
|
-
|
|
823
|
+
_context9.n = 3;
|
|
785
824
|
return cartEnt.save({
|
|
786
825
|
embed: cartEmbed
|
|
787
826
|
});
|
|
788
827
|
case 3:
|
|
789
|
-
cartEnt =
|
|
828
|
+
cartEnt = _context9.v;
|
|
790
829
|
cartJson = cartEnt.toJson();
|
|
791
830
|
saveCheckoutAddress(domainId, addressFields);
|
|
792
831
|
query = [];
|
|
793
832
|
query.push(['cart_token', cart.token]);
|
|
794
|
-
|
|
833
|
+
_context9.n = 4;
|
|
795
834
|
return merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
796
835
|
method: 'GET',
|
|
797
836
|
query: query
|
|
798
837
|
});
|
|
799
838
|
case 4:
|
|
800
|
-
cartWithShipmentGroups =
|
|
839
|
+
cartWithShipmentGroups = _context9.v;
|
|
801
840
|
setCart(_objectSpread(_objectSpread({}, cartJson), {}, {
|
|
802
841
|
shipmentGroups: cartWithShipmentGroups.shipmentGroups || []
|
|
803
842
|
}));
|
|
804
|
-
|
|
843
|
+
_context9.n = 6;
|
|
805
844
|
break;
|
|
806
845
|
case 5:
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
reportCartFailure(
|
|
810
|
-
alertError(
|
|
846
|
+
_context9.p = 5;
|
|
847
|
+
_t7 = _context9.v;
|
|
848
|
+
reportCartFailure(_t7, CART_FAILURE_SOURCES.update);
|
|
849
|
+
alertError(_t7.errorMessage || _t7.message || 'Unable to set address');
|
|
811
850
|
case 6:
|
|
812
|
-
|
|
851
|
+
_context9.p = 6;
|
|
813
852
|
setFetchingShipmentGroups(false);
|
|
814
|
-
return
|
|
853
|
+
return _context9.f(6);
|
|
815
854
|
case 7:
|
|
816
|
-
return
|
|
855
|
+
return _context9.a(2);
|
|
817
856
|
}
|
|
818
|
-
},
|
|
857
|
+
}, _callee9, null, [[2, 5, 6, 7]]);
|
|
819
858
|
}));
|
|
820
859
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
821
860
|
}
|
|
@@ -823,40 +862,40 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
823
862
|
return _getCartShipmentOptions.apply(this, arguments);
|
|
824
863
|
}
|
|
825
864
|
function _getCartShipmentOptions() {
|
|
826
|
-
_getCartShipmentOptions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
827
|
-
var query, cartWithGroups,
|
|
828
|
-
return _regenerator().w(function (
|
|
829
|
-
while (1) switch (
|
|
865
|
+
_getCartShipmentOptions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
866
|
+
var query, cartWithGroups, _t8;
|
|
867
|
+
return _regenerator().w(function (_context0) {
|
|
868
|
+
while (1) switch (_context0.p = _context0.n) {
|
|
830
869
|
case 0:
|
|
831
870
|
setFetchingShipmentGroups(true);
|
|
832
|
-
|
|
871
|
+
_context0.p = 1;
|
|
833
872
|
query = [];
|
|
834
873
|
query.push(['cart_token', cart.token]);
|
|
835
|
-
|
|
874
|
+
_context0.n = 2;
|
|
836
875
|
return merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
837
876
|
method: 'GET',
|
|
838
877
|
query: query
|
|
839
878
|
});
|
|
840
879
|
case 2:
|
|
841
|
-
cartWithGroups =
|
|
880
|
+
cartWithGroups = _context0.v;
|
|
842
881
|
setCart(_objectSpread(_objectSpread({}, cart), {}, {
|
|
843
882
|
shipmentGroups: cartWithGroups.shipmentGroups || []
|
|
844
883
|
}));
|
|
845
|
-
|
|
884
|
+
_context0.n = 4;
|
|
846
885
|
break;
|
|
847
886
|
case 3:
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
reportCartFailure(
|
|
851
|
-
alertError(
|
|
887
|
+
_context0.p = 3;
|
|
888
|
+
_t8 = _context0.v;
|
|
889
|
+
reportCartFailure(_t8, CART_FAILURE_SOURCES.shipping);
|
|
890
|
+
alertError(_t8.errorMessage || _t8.message || 'Unable to fetch shipment options');
|
|
852
891
|
case 4:
|
|
853
|
-
|
|
892
|
+
_context0.p = 4;
|
|
854
893
|
setFetchingShipmentGroups(false);
|
|
855
|
-
return
|
|
894
|
+
return _context0.f(4);
|
|
856
895
|
case 5:
|
|
857
|
-
return
|
|
896
|
+
return _context0.a(2);
|
|
858
897
|
}
|
|
859
|
-
},
|
|
898
|
+
}, _callee0, null, [[1, 3, 4, 5]]);
|
|
860
899
|
}));
|
|
861
900
|
return _getCartShipmentOptions.apply(this, arguments);
|
|
862
901
|
}
|
|
@@ -864,14 +903,14 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
864
903
|
return _getMerchiCartValues.apply(this, arguments);
|
|
865
904
|
}
|
|
866
905
|
function _getMerchiCartValues() {
|
|
867
|
-
_getMerchiCartValues = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
906
|
+
_getMerchiCartValues = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
|
|
868
907
|
var _ref3, cartItems, currency, subtotalCost, taxAmount, totalCost, cartItemsCount;
|
|
869
|
-
return _regenerator().w(function (
|
|
870
|
-
while (1) switch (
|
|
908
|
+
return _regenerator().w(function (_context1) {
|
|
909
|
+
while (1) switch (_context1.n) {
|
|
871
910
|
case 0:
|
|
872
911
|
_ref3 = cart, cartItems = _ref3.cartItems, currency = _ref3.currency, subtotalCost = _ref3.subtotalCost, taxAmount = _ref3.taxAmount, totalCost = _ref3.totalCost;
|
|
873
912
|
cartItemsCount = cartItems ? cartItems.length : 0;
|
|
874
|
-
return
|
|
913
|
+
return _context1.a(2, {
|
|
875
914
|
cart: cart,
|
|
876
915
|
cartItemsCount: cartItemsCount,
|
|
877
916
|
currency: currency || '',
|
|
@@ -880,7 +919,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
880
919
|
totalCost: totalCost || 0
|
|
881
920
|
});
|
|
882
921
|
}
|
|
883
|
-
},
|
|
922
|
+
}, _callee1);
|
|
884
923
|
}));
|
|
885
924
|
return _getMerchiCartValues.apply(this, arguments);
|
|
886
925
|
}
|
|
@@ -888,13 +927,13 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
888
927
|
return _isMerchiCartFetching.apply(this, arguments);
|
|
889
928
|
}
|
|
890
929
|
function _isMerchiCartFetching() {
|
|
891
|
-
_isMerchiCartFetching = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
892
|
-
return _regenerator().w(function (
|
|
893
|
-
while (1) switch (
|
|
930
|
+
_isMerchiCartFetching = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
|
|
931
|
+
return _regenerator().w(function (_context10) {
|
|
932
|
+
while (1) switch (_context10.n) {
|
|
894
933
|
case 0:
|
|
895
|
-
return
|
|
934
|
+
return _context10.a(2, fetchingCart);
|
|
896
935
|
}
|
|
897
|
-
},
|
|
936
|
+
}, _callee10);
|
|
898
937
|
}));
|
|
899
938
|
return _isMerchiCartFetching.apply(this, arguments);
|
|
900
939
|
}
|
|
@@ -908,14 +947,14 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
908
947
|
return _actionFetchTheme.apply(this, arguments);
|
|
909
948
|
}
|
|
910
949
|
function _actionFetchTheme() {
|
|
911
|
-
_actionFetchTheme = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
912
|
-
var domain, theme,
|
|
913
|
-
return _regenerator().w(function (
|
|
914
|
-
while (1) switch (
|
|
950
|
+
_actionFetchTheme = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
|
|
951
|
+
var domain, theme, _t9;
|
|
952
|
+
return _regenerator().w(function (_context11) {
|
|
953
|
+
while (1) switch (_context11.p = _context11.n) {
|
|
915
954
|
case 0:
|
|
916
955
|
setLoading(true);
|
|
917
|
-
|
|
918
|
-
|
|
956
|
+
_context11.p = 1;
|
|
957
|
+
_context11.n = 2;
|
|
919
958
|
return merchi.Domain.get(domainId, {
|
|
920
959
|
embed: {
|
|
921
960
|
activeTheme: {
|
|
@@ -924,24 +963,24 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
924
963
|
}
|
|
925
964
|
});
|
|
926
965
|
case 2:
|
|
927
|
-
domain =
|
|
966
|
+
domain = _context11.v;
|
|
928
967
|
theme = domain.activeTheme;
|
|
929
|
-
|
|
968
|
+
_context11.n = 3;
|
|
930
969
|
return appendStyleSheetText(theme.mainCss, function () {
|
|
931
970
|
return setLoading(false);
|
|
932
971
|
});
|
|
933
972
|
case 3:
|
|
934
|
-
|
|
973
|
+
_context11.n = 5;
|
|
935
974
|
break;
|
|
936
975
|
case 4:
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
alertError(
|
|
976
|
+
_context11.p = 4;
|
|
977
|
+
_t9 = _context11.v;
|
|
978
|
+
alertError(_t9.errorMessage || _t9.message || 'Error fetching domain theme.');
|
|
940
979
|
setLoading(false);
|
|
941
980
|
case 5:
|
|
942
|
-
return
|
|
981
|
+
return _context11.a(2);
|
|
943
982
|
}
|
|
944
|
-
},
|
|
983
|
+
}, _callee11, null, [[1, 4]]);
|
|
945
984
|
}));
|
|
946
985
|
return _actionFetchTheme.apply(this, arguments);
|
|
947
986
|
}
|
|
@@ -949,18 +988,18 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
949
988
|
return _setCartComplete.apply(this, arguments);
|
|
950
989
|
}
|
|
951
990
|
function _setCartComplete() {
|
|
952
|
-
_setCartComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
953
|
-
return _regenerator().w(function (
|
|
954
|
-
while (1) switch (
|
|
991
|
+
_setCartComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
992
|
+
return _regenerator().w(function (_context12) {
|
|
993
|
+
while (1) switch (_context12.n) {
|
|
955
994
|
case 0:
|
|
956
|
-
|
|
995
|
+
_context12.n = 1;
|
|
957
996
|
return createCartAndCookie();
|
|
958
997
|
case 1:
|
|
959
998
|
location.reload();
|
|
960
999
|
case 2:
|
|
961
|
-
return
|
|
1000
|
+
return _context12.a(2);
|
|
962
1001
|
}
|
|
963
|
-
},
|
|
1002
|
+
}, _callee12);
|
|
964
1003
|
}));
|
|
965
1004
|
return _setCartComplete.apply(this, arguments);
|
|
966
1005
|
}
|
|
@@ -968,16 +1007,16 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
968
1007
|
return _refetchCart.apply(this, arguments);
|
|
969
1008
|
}
|
|
970
1009
|
function _refetchCart() {
|
|
971
|
-
_refetchCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
972
|
-
return _regenerator().w(function (
|
|
973
|
-
while (1) switch (
|
|
1010
|
+
_refetchCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
|
|
1011
|
+
return _regenerator().w(function (_context13) {
|
|
1012
|
+
while (1) switch (_context13.n) {
|
|
974
1013
|
case 0:
|
|
975
|
-
|
|
1014
|
+
_context13.n = 1;
|
|
976
1015
|
return actionGetMerchiCart();
|
|
977
1016
|
case 1:
|
|
978
|
-
return
|
|
1017
|
+
return _context13.a(2);
|
|
979
1018
|
}
|
|
980
|
-
},
|
|
1019
|
+
}, _callee13);
|
|
981
1020
|
}));
|
|
982
1021
|
return _refetchCart.apply(this, arguments);
|
|
983
1022
|
}
|
|
@@ -989,26 +1028,49 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
989
1028
|
_useState24 = _slicedToArray(_useState23, 2),
|
|
990
1029
|
loadingTotals = _useState24[0],
|
|
991
1030
|
setLoadingTotals = _useState24[1];
|
|
992
|
-
function addCartItem(
|
|
1031
|
+
function addCartItem(_x7, _x8, _x9) {
|
|
993
1032
|
return _addCartItem.apply(this, arguments);
|
|
994
1033
|
}
|
|
995
1034
|
function _addCartItem() {
|
|
996
|
-
_addCartItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
997
|
-
var jobEnt, cartToken, cartEnt, cartItemEnt,
|
|
998
|
-
return _regenerator().w(function (
|
|
999
|
-
while (1) switch (
|
|
1035
|
+
_addCartItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(jobJson, onSuccess, onError) {
|
|
1036
|
+
var jobEnt, cartItemProduct, readyCart, cartToken, cartEnt, cartItemEnt, item, itemJson, _t0, _t1;
|
|
1037
|
+
return _regenerator().w(function (_context14) {
|
|
1038
|
+
while (1) switch (_context14.p = _context14.n) {
|
|
1000
1039
|
case 0:
|
|
1001
1040
|
setFetchingCart(true);
|
|
1041
|
+
_context14.p = 1;
|
|
1002
1042
|
jobEnt = makeJob(jobJson, true);
|
|
1003
|
-
_context12.n = 1;
|
|
1004
|
-
return getCartCookieToken(domainId);
|
|
1005
|
-
case 1:
|
|
1006
|
-
cartToken = _context12.v;
|
|
1007
|
-
cartEnt = makeCart(cart, false, cartToken);
|
|
1008
|
-
cartItemEnt = makeCartItem({}, true);
|
|
1009
1043
|
cartItemProduct = makeProduct({
|
|
1010
1044
|
id: jobEnt.product.id
|
|
1011
|
-
});
|
|
1045
|
+
}); // Legacy clients can call addCartItem directly, without first opening
|
|
1046
|
+
// the cart or waiting for React to commit the initialized cart state.
|
|
1047
|
+
if (!(cart !== null && cart !== void 0 && cart.id)) {
|
|
1048
|
+
_context14.n = 2;
|
|
1049
|
+
break;
|
|
1050
|
+
}
|
|
1051
|
+
_t0 = cart;
|
|
1052
|
+
_context14.n = 4;
|
|
1053
|
+
break;
|
|
1054
|
+
case 2:
|
|
1055
|
+
_context14.n = 3;
|
|
1056
|
+
return actionGetMerchiCart();
|
|
1057
|
+
case 3:
|
|
1058
|
+
_t0 = _context14.v;
|
|
1059
|
+
case 4:
|
|
1060
|
+
readyCart = _t0;
|
|
1061
|
+
if (readyCart !== null && readyCart !== void 0 && readyCart.id) {
|
|
1062
|
+
_context14.n = 5;
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
throw new Error('Unable to initialize cart. Please try again.');
|
|
1066
|
+
case 5:
|
|
1067
|
+
setFetchingCart(true);
|
|
1068
|
+
_context14.n = 6;
|
|
1069
|
+
return getCartCookieToken(domainId);
|
|
1070
|
+
case 6:
|
|
1071
|
+
cartToken = _context14.v;
|
|
1072
|
+
cartEnt = makeCart(readyCart, false, cartToken);
|
|
1073
|
+
cartItemEnt = makeCartItem({}, true);
|
|
1012
1074
|
cartItemEnt.cart = cartEnt;
|
|
1013
1075
|
cartItemEnt.quantity = jobEnt.quantity;
|
|
1014
1076
|
cartItemEnt.product = cartItemProduct;
|
|
@@ -1021,30 +1083,29 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
1021
1083
|
if (typeof jobJson.designInputNotes === 'string' && jobJson.designInputNotes) {
|
|
1022
1084
|
cartItemEnt.notes = jobJson.designInputNotes;
|
|
1023
1085
|
}
|
|
1024
|
-
|
|
1025
|
-
_context12.n = 3;
|
|
1086
|
+
_context14.n = 7;
|
|
1026
1087
|
return cartItemEnt.create();
|
|
1027
|
-
case
|
|
1028
|
-
item =
|
|
1029
|
-
|
|
1088
|
+
case 7:
|
|
1089
|
+
item = _context14.v;
|
|
1090
|
+
_context14.n = 8;
|
|
1030
1091
|
return item.toJson();
|
|
1031
|
-
case
|
|
1032
|
-
itemJson =
|
|
1092
|
+
case 8:
|
|
1093
|
+
itemJson = _context14.v;
|
|
1033
1094
|
onSuccess(itemJson);
|
|
1034
|
-
|
|
1095
|
+
_context14.n = 10;
|
|
1035
1096
|
break;
|
|
1036
|
-
case
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
reportAddCartItemFailure(
|
|
1040
|
-
case
|
|
1041
|
-
|
|
1097
|
+
case 9:
|
|
1098
|
+
_context14.p = 9;
|
|
1099
|
+
_t1 = _context14.v;
|
|
1100
|
+
reportAddCartItemFailure(_t1, onError);
|
|
1101
|
+
case 10:
|
|
1102
|
+
_context14.p = 10;
|
|
1042
1103
|
setFetchingCart(false);
|
|
1043
|
-
return
|
|
1044
|
-
case
|
|
1045
|
-
return
|
|
1104
|
+
return _context14.f(10);
|
|
1105
|
+
case 11:
|
|
1106
|
+
return _context14.a(2);
|
|
1046
1107
|
}
|
|
1047
|
-
},
|
|
1108
|
+
}, _callee14, null, [[1, 9, 10, 11]]);
|
|
1048
1109
|
}));
|
|
1049
1110
|
return _addCartItem.apply(this, arguments);
|
|
1050
1111
|
}
|
|
@@ -1064,22 +1125,48 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
1064
1125
|
}
|
|
1065
1126
|
};
|
|
1066
1127
|
|
|
1067
|
-
//
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1128
|
+
// Publish only committed providers. Suspense can discard render-time state,
|
|
1129
|
+
// so exposing these closures during render can strand a successful cart POST.
|
|
1130
|
+
useCartBindingsEffect(function () {
|
|
1131
|
+
var bindings = {
|
|
1132
|
+
addCartItem: addCartItem,
|
|
1133
|
+
toggleCartOpen: toggleCartModal,
|
|
1134
|
+
getCart: function () {
|
|
1135
|
+
var _getCart2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
1136
|
+
return _regenerator().w(function (_context2) {
|
|
1137
|
+
while (1) switch (_context2.n) {
|
|
1138
|
+
case 0:
|
|
1139
|
+
_context2.n = 1;
|
|
1140
|
+
return actionGetMerchiCart();
|
|
1141
|
+
case 1:
|
|
1142
|
+
return _context2.a(2);
|
|
1143
|
+
}
|
|
1144
|
+
}, _callee2);
|
|
1145
|
+
}));
|
|
1146
|
+
function getCart() {
|
|
1147
|
+
return _getCart2.apply(this, arguments);
|
|
1148
|
+
}
|
|
1149
|
+
return getCart;
|
|
1150
|
+
}(),
|
|
1151
|
+
getMerchiCartValues: getMerchiCartValues,
|
|
1152
|
+
isMerchiCartFetching: isMerchiCartFetching,
|
|
1153
|
+
setCartComplete: setCartComplete,
|
|
1154
|
+
refetchCart: refetchCart,
|
|
1155
|
+
createCartAndCookie: requestNewCart
|
|
1073
1156
|
};
|
|
1074
|
-
window
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1157
|
+
Object.assign(window, bindings);
|
|
1158
|
+
return function () {
|
|
1159
|
+
for (var _i = 0, _Object$entries = Object.entries(bindings); _i < _Object$entries.length; _i++) {
|
|
1160
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1161
|
+
name = _Object$entries$_i[0],
|
|
1162
|
+
binding = _Object$entries$_i[1];
|
|
1163
|
+
if (window[name] === binding) delete window[name];
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
});
|
|
1080
1167
|
useEffect(function () {
|
|
1081
1168
|
persistTestCheckoutFlag();
|
|
1082
|
-
if (domainId) actionGetMerchiCart();
|
|
1169
|
+
if (domainId) actionGetMerchiCart(!isAutomatedClient());
|
|
1083
1170
|
if (domainId && includeTheme) actionFetchTheme();
|
|
1084
1171
|
}, [domainId]);
|
|
1085
1172
|
return /*#__PURE__*/_jsx(CartContext.Provider, {
|
|
@@ -1208,7 +1295,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
1208
1295
|
// creates a token and cart and then reloads the page
|
|
1209
1296
|
refetchCart: refetchCart,
|
|
1210
1297
|
// used to refetch the cart
|
|
1211
|
-
createCartAndCookie:
|
|
1298
|
+
createCartAndCookie: requestNewCart,
|
|
1212
1299
|
// creates a new cart and cookie
|
|
1213
1300
|
|
|
1214
1301
|
loading: loading,
|