@merchi/cart 1.4.85 → 1.4.87
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 +80 -49
- package/esm/CartProvider.load.test.js +418 -71
- package/esm/forms/FormShipmentAddressAndNotes.js +51 -20
- package/esm/utilities/checkoutCartClient.js +32 -0
- package/lib/CartProvider.js +80 -49
- package/lib/forms/FormShipmentAddressAndNotes.js +51 -20
- package/lib/utilities/checkoutCartClient.d.ts +5 -0
- package/lib/utilities/checkoutCartClient.js +38 -0
- package/package.json +4 -4
- package/src/CartProvider.load.test.tsx +110 -7
- package/src/CartProvider.tsx +34 -23
- package/src/forms/FormShipmentAddressAndNotes.tsx +21 -6
- package/src/utilities/checkoutCartClient.ts +16 -0
package/esm/CartProvider.js
CHANGED
|
@@ -36,6 +36,7 @@ import { persistTestCheckoutFlag, readTestCheckoutFlag } from './utilities/test_
|
|
|
36
36
|
import { reportAddCartItemFailure, reportCartFailure, CART_FAILURE_SOURCES } from './utilities/reportFailure';
|
|
37
37
|
import { isAutomatedClient } from './utilities/automatedClient';
|
|
38
38
|
import { canReplaceMissingCart } from './utilities/cartLoadFailure';
|
|
39
|
+
import { getCheckoutCartClient } from './utilities/checkoutCartClient';
|
|
39
40
|
import { appendJobSourceToFormData, captureAndReadJobSource, cartNeedsSourceUpdate, jobSourceFieldsForApi } from './utilities/job_source';
|
|
40
41
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
41
42
|
var useCartBindingsEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
@@ -837,55 +838,68 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
837
838
|
}
|
|
838
839
|
function _updateCartShipmentAddress() {
|
|
839
840
|
_updateCartShipmentAddress = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(address) {
|
|
840
|
-
var
|
|
841
|
+
var _cart$invoice;
|
|
842
|
+
var cartId, shipmentApi, addressFields, cartEnt, savedCart, cartJson, cartWithShipmentGroups, _t7;
|
|
841
843
|
return _regenerator().w(function (_context9) {
|
|
842
844
|
while (1) switch (_context9.p = _context9.n) {
|
|
843
845
|
case 0:
|
|
844
|
-
|
|
845
|
-
|
|
846
|
+
cartId = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
847
|
+
if (!(!cartId || ((_cart$invoice = cart.invoice) === null || _cart$invoice === void 0 ? void 0 : _cart$invoice.unpaid) === false)) {
|
|
848
|
+
_context9.n = 1;
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
return _context9.a(2);
|
|
846
852
|
case 1:
|
|
847
|
-
token = _context9.v;
|
|
848
|
-
addressFields = sanitizeAddressFields(address);
|
|
849
|
-
receiverAddress = makeAddress(addressFields, true);
|
|
850
|
-
cartEnt = makeCart(cart, false, token);
|
|
851
853
|
setFetchingShipmentGroups(true);
|
|
852
854
|
_context9.p = 2;
|
|
853
|
-
cartEnt.receiverAddress = receiverAddress;
|
|
854
855
|
_context9.n = 3;
|
|
856
|
+
return getCheckoutCartClient(cart, domainId, merchi.backendUri);
|
|
857
|
+
case 3:
|
|
858
|
+
shipmentApi = _context9.v;
|
|
859
|
+
if (shipmentApi) {
|
|
860
|
+
_context9.n = 4;
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
alertError('Unable to verify this cart. Reload checkout and try again.');
|
|
864
|
+
return _context9.a(2);
|
|
865
|
+
case 4:
|
|
866
|
+
addressFields = sanitizeAddressFields(address);
|
|
867
|
+
cartEnt = new shipmentApi.Cart().fromJson(cart);
|
|
868
|
+
cartEnt.receiverAddress = makeAddress(addressFields, true);
|
|
869
|
+
_context9.n = 5;
|
|
855
870
|
return cartEnt.save({
|
|
856
871
|
embed: cartEmbed
|
|
857
872
|
});
|
|
858
|
-
case
|
|
859
|
-
|
|
860
|
-
cartJson =
|
|
873
|
+
case 5:
|
|
874
|
+
savedCart = _context9.v;
|
|
875
|
+
cartJson = savedCart.toJson();
|
|
861
876
|
saveCheckoutAddress(domainId, addressFields);
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
866
|
-
method: 'GET',
|
|
867
|
-
query: query
|
|
877
|
+
_context9.n = 6;
|
|
878
|
+
return shipmentApi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cartId, "/"), {
|
|
879
|
+
method: 'GET'
|
|
868
880
|
});
|
|
869
|
-
case
|
|
881
|
+
case 6:
|
|
870
882
|
cartWithShipmentGroups = _context9.v;
|
|
871
|
-
setCart(
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
883
|
+
setCart(function (current) {
|
|
884
|
+
return (current === null || current === void 0 ? void 0 : current.id) === cartId ? _objectSpread(_objectSpread({}, cartJson), {}, {
|
|
885
|
+
shipmentGroups: cartWithShipmentGroups.shipmentGroups || []
|
|
886
|
+
}) : current;
|
|
887
|
+
});
|
|
888
|
+
_context9.n = 8;
|
|
875
889
|
break;
|
|
876
|
-
case
|
|
877
|
-
_context9.p =
|
|
890
|
+
case 7:
|
|
891
|
+
_context9.p = 7;
|
|
878
892
|
_t7 = _context9.v;
|
|
879
893
|
reportCartFailure(_t7, CART_FAILURE_SOURCES.update);
|
|
880
894
|
alertError(_t7.errorMessage || _t7.message || 'Unable to set address');
|
|
881
|
-
case
|
|
882
|
-
_context9.p =
|
|
895
|
+
case 8:
|
|
896
|
+
_context9.p = 8;
|
|
883
897
|
setFetchingShipmentGroups(false);
|
|
884
|
-
return _context9.f(
|
|
885
|
-
case
|
|
898
|
+
return _context9.f(8);
|
|
899
|
+
case 9:
|
|
886
900
|
return _context9.a(2);
|
|
887
901
|
}
|
|
888
|
-
}, _callee9, null, [[2,
|
|
902
|
+
}, _callee9, null, [[2, 7, 8, 9]]);
|
|
889
903
|
}));
|
|
890
904
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
891
905
|
}
|
|
@@ -894,39 +908,56 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
894
908
|
}
|
|
895
909
|
function _getCartShipmentOptions() {
|
|
896
910
|
_getCartShipmentOptions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
897
|
-
var
|
|
911
|
+
var cartId, shipmentApi, cartWithGroups, _t8;
|
|
898
912
|
return _regenerator().w(function (_context0) {
|
|
899
913
|
while (1) switch (_context0.p = _context0.n) {
|
|
900
914
|
case 0:
|
|
915
|
+
cartId = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
916
|
+
if (cartId) {
|
|
917
|
+
_context0.n = 1;
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
return _context0.a(2);
|
|
921
|
+
case 1:
|
|
901
922
|
setFetchingShipmentGroups(true);
|
|
902
|
-
_context0.p =
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
923
|
+
_context0.p = 2;
|
|
924
|
+
_context0.n = 3;
|
|
925
|
+
return getCheckoutCartClient(cart, domainId, merchi.backendUri);
|
|
926
|
+
case 3:
|
|
927
|
+
shipmentApi = _context0.v;
|
|
928
|
+
if (shipmentApi) {
|
|
929
|
+
_context0.n = 4;
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
alertError('Unable to verify this cart. Reload checkout and try again.');
|
|
933
|
+
return _context0.a(2);
|
|
934
|
+
case 4:
|
|
935
|
+
_context0.n = 5;
|
|
936
|
+
return shipmentApi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cartId, "/"), {
|
|
937
|
+
method: 'GET'
|
|
909
938
|
});
|
|
910
|
-
case
|
|
939
|
+
case 5:
|
|
911
940
|
cartWithGroups = _context0.v;
|
|
912
|
-
setCart(
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
941
|
+
setCart(function (current) {
|
|
942
|
+
return (current === null || current === void 0 ? void 0 : current.id) === cartId ? _objectSpread(_objectSpread({}, current), {}, {
|
|
943
|
+
shipmentGroups: cartWithGroups.shipmentGroups || []
|
|
944
|
+
}) : current;
|
|
945
|
+
});
|
|
946
|
+
_context0.n = 7;
|
|
916
947
|
break;
|
|
917
|
-
case
|
|
918
|
-
_context0.p =
|
|
948
|
+
case 6:
|
|
949
|
+
_context0.p = 6;
|
|
919
950
|
_t8 = _context0.v;
|
|
920
951
|
reportCartFailure(_t8, CART_FAILURE_SOURCES.shipping);
|
|
921
952
|
alertError(_t8.errorMessage || _t8.message || 'Unable to fetch shipment options');
|
|
922
|
-
case
|
|
923
|
-
_context0.p =
|
|
953
|
+
case 7:
|
|
954
|
+
_context0.p = 7;
|
|
924
955
|
setFetchingShipmentGroups(false);
|
|
925
|
-
return _context0.f(
|
|
926
|
-
case
|
|
956
|
+
return _context0.f(7);
|
|
957
|
+
case 8:
|
|
927
958
|
return _context0.a(2);
|
|
928
959
|
}
|
|
929
|
-
}, _callee0, null, [[
|
|
960
|
+
}, _callee0, null, [[2, 6, 7, 8]]);
|
|
930
961
|
}));
|
|
931
962
|
return _getCartShipmentOptions.apply(this, arguments);
|
|
932
963
|
}
|