@merchi/cart 1.4.62 → 1.4.64

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