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