@commercelayer/react-components 4.9.0-beta.4 → 4.9.0
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/lib/cjs/components/MetadataInput.d.ts +0 -1
- package/lib/cjs/components/addresses/Address.d.ts +0 -1
- package/lib/cjs/components/addresses/Address.js +1 -1
- package/lib/cjs/components/addresses/AddressCountrySelector.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressInput.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressStateSelector.d.ts +0 -1
- package/lib/cjs/components/addresses/AddressesEmpty.d.ts +0 -1
- package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +0 -1
- package/lib/cjs/components/auth/CommerceLayer.d.ts +0 -1
- package/lib/cjs/components/auth/CommerceLayer.js +1 -1
- package/lib/cjs/components/customers/CustomerContainer.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerField.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerInput.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +0 -1
- package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +0 -1
- package/lib/cjs/components/customers/MyAccountLink.d.ts +0 -1
- package/lib/cjs/components/customers/MyAccountLink.js +1 -1
- package/lib/cjs/components/customers/MyIdentityLink.d.ts +0 -1
- package/lib/cjs/components/customers/SaveCustomerButton.js +1 -1
- package/lib/cjs/components/errors/Errors.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCard.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +0 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +0 -1
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +0 -1
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.js +1 -1
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItem.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemAmount.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemCode.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemField.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemImage.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemName.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemsContainer.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
- package/lib/cjs/components/line_items/LineItemsCount.d.ts +0 -1
- package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +0 -1
- package/lib/cjs/components/orders/AdjustmentAmount.d.ts +0 -1
- package/lib/cjs/components/orders/CheckoutLink.d.ts +0 -1
- package/lib/cjs/components/orders/DiscountAmount.d.ts +0 -1
- package/lib/cjs/components/orders/GiftCardAmount.d.ts +0 -1
- package/lib/cjs/components/orders/HostedCart.js +1 -1
- package/lib/cjs/components/orders/OrderContainer.d.ts +0 -1
- package/lib/cjs/components/orders/OrderList.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListEmpty.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +0 -1
- package/lib/cjs/components/orders/OrderListRow.d.ts +0 -1
- package/lib/cjs/components/orders/OrderNumber.d.ts +0 -1
- package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +0 -1
- package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -1
- package/lib/cjs/components/orders/ShippingAmount.d.ts +0 -1
- package/lib/cjs/components/orders/SubTotalAmount.d.ts +0 -1
- package/lib/cjs/components/orders/TaxesAmount.d.ts +0 -1
- package/lib/cjs/components/orders/TotalAmount.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelField.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelLineItem.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +0 -1
- package/lib/cjs/components/parcels/Parcels.d.ts +0 -1
- package/lib/cjs/components/parcels/ParcelsCount.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/AdyenGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/PaymentGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +0 -1
- package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.js +1 -1
- package/lib/cjs/components/payment_source/BraintreePayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/ExternalPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSource.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +0 -1
- package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +0 -1
- package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/StripeExpressPayment.js +1 -1
- package/lib/cjs/components/payment_source/StripePayment.d.ts +0 -1
- package/lib/cjs/components/payment_source/StripePayment.js +1 -1
- package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +0 -1
- package/lib/cjs/components/prices/Price.d.ts +0 -1
- package/lib/cjs/components/prices/Price.js +1 -1
- package/lib/cjs/components/prices/PricesContainer.d.ts +0 -1
- package/lib/cjs/components/shipments/ShipmentField.d.ts +0 -1
- package/lib/cjs/components/shipments/ShipmentsCount.d.ts +0 -1
- package/lib/cjs/components/shipping_methods/ShippingMethod.js +1 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +0 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +0 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +0 -1
- package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +0 -1
- package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +0 -1
- package/lib/cjs/components/skus/SkuField.d.ts +0 -1
- package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +0 -1
- package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +0 -1
- package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +0 -1
- package/lib/cjs/components/utils/BaseOrderPrice.d.ts +0 -1
- package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +0 -1
- package/lib/cjs/components/utils/PriceTemplate.d.ts +2 -3
- package/lib/cjs/components/utils/getAllErrors.d.ts +0 -1
- package/lib/cjs/reducers/CustomerReducer.js +1 -1
- package/lib/cjs/reducers/GiftCardReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.js +1 -1
- package/lib/cjs/typings/globals.d.ts +0 -1
- package/lib/cjs/utils/filterChildren.d.ts +0 -1
- package/lib/cjs/utils/getCustomerIdByToken.js +1 -1
- package/lib/cjs/utils/getDomain.js +1 -1
- package/lib/cjs/utils/getLoaderComponent.d.ts +0 -1
- package/lib/cjs/utils/getPrices.d.ts +0 -1
- package/lib/cjs/utils/getPrices.js +1 -1
- package/lib/cjs/utils/isGuestToken.js +1 -1
- package/lib/cjs/utils/jwt.d.ts +1 -1
- package/lib/cjs/utils/jwt.js +1 -1
- package/lib/esm/components/MetadataInput.d.ts +0 -1
- package/lib/esm/components/addresses/Address.d.ts +0 -1
- package/lib/esm/components/addresses/Address.js +1 -1
- package/lib/esm/components/addresses/AddressCountrySelector.d.ts +0 -1
- package/lib/esm/components/addresses/AddressInput.d.ts +0 -1
- package/lib/esm/components/addresses/AddressStateSelector.d.ts +0 -1
- package/lib/esm/components/addresses/AddressesEmpty.d.ts +0 -1
- package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +0 -1
- package/lib/esm/components/auth/CommerceLayer.d.ts +0 -1
- package/lib/esm/components/auth/CommerceLayer.js +1 -1
- package/lib/esm/components/customers/CustomerContainer.d.ts +0 -1
- package/lib/esm/components/customers/CustomerField.d.ts +0 -1
- package/lib/esm/components/customers/CustomerInput.d.ts +0 -1
- package/lib/esm/components/customers/CustomerPaymentSource.d.ts +0 -1
- package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +0 -1
- package/lib/esm/components/customers/MyAccountLink.d.ts +0 -1
- package/lib/esm/components/customers/MyAccountLink.js +1 -1
- package/lib/esm/components/customers/MyIdentityLink.d.ts +0 -1
- package/lib/esm/components/customers/SaveCustomerButton.js +1 -1
- package/lib/esm/components/errors/Errors.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCard.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardInput.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +0 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +0 -1
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +0 -1
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.js +1 -1
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +0 -1
- package/lib/esm/components/line_items/LineItem.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemAmount.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemCode.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemField.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemImage.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemName.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemsContainer.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemsContainer.js +1 -1
- package/lib/esm/components/line_items/LineItemsCount.d.ts +0 -1
- package/lib/esm/components/line_items/LineItemsEmpty.d.ts +0 -1
- package/lib/esm/components/orders/AdjustmentAmount.d.ts +0 -1
- package/lib/esm/components/orders/CheckoutLink.d.ts +0 -1
- package/lib/esm/components/orders/DiscountAmount.d.ts +0 -1
- package/lib/esm/components/orders/GiftCardAmount.d.ts +0 -1
- package/lib/esm/components/orders/HostedCart.js +1 -1
- package/lib/esm/components/orders/OrderContainer.d.ts +0 -1
- package/lib/esm/components/orders/OrderList.d.ts +0 -1
- package/lib/esm/components/orders/OrderListEmpty.d.ts +0 -1
- package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +0 -1
- package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +0 -1
- package/lib/esm/components/orders/OrderListRow.d.ts +0 -1
- package/lib/esm/components/orders/OrderNumber.d.ts +0 -1
- package/lib/esm/components/orders/PaymentMethodAmount.d.ts +0 -1
- package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -1
- package/lib/esm/components/orders/ShippingAmount.d.ts +0 -1
- package/lib/esm/components/orders/SubTotalAmount.d.ts +0 -1
- package/lib/esm/components/orders/TaxesAmount.d.ts +0 -1
- package/lib/esm/components/orders/TotalAmount.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelField.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelLineItem.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelLineItemField.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +0 -1
- package/lib/esm/components/parcels/Parcels.d.ts +0 -1
- package/lib/esm/components/parcels/ParcelsCount.d.ts +0 -1
- package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/AdyenGateway.js +1 -1
- package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/StripeGateway.d.ts +0 -1
- package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethod.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodRadioButton.js +1 -1
- package/lib/esm/components/payment_source/BraintreePayment.d.ts +0 -1
- package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/ExternalPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/KlarnaPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSource.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +0 -1
- package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +0 -1
- package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +0 -1
- package/lib/esm/components/payment_source/StripeExpressPayment.js +1 -1
- package/lib/esm/components/payment_source/StripePayment.d.ts +0 -1
- package/lib/esm/components/payment_source/StripePayment.js +1 -1
- package/lib/esm/components/payment_source/WireTransferPayment.d.ts +0 -1
- package/lib/esm/components/prices/Price.d.ts +0 -1
- package/lib/esm/components/prices/Price.js +1 -1
- package/lib/esm/components/prices/PricesContainer.d.ts +0 -1
- package/lib/esm/components/shipments/ShipmentField.d.ts +0 -1
- package/lib/esm/components/shipments/ShipmentsCount.d.ts +0 -1
- package/lib/esm/components/shipping_methods/ShippingMethod.js +1 -1
- package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +0 -1
- package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +0 -1
- package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +0 -1
- package/lib/esm/components/skus/AvailabilityTemplate.d.ts +0 -1
- package/lib/esm/components/skus/DeliveryLeadTime.d.ts +0 -1
- package/lib/esm/components/skus/SkuField.d.ts +0 -1
- package/lib/esm/components/stock_transfers/StockTransfer.d.ts +0 -1
- package/lib/esm/components/stock_transfers/StockTransferField.d.ts +0 -1
- package/lib/esm/components/utils/AddressCardsTemplate.d.ts +0 -1
- package/lib/esm/components/utils/BaseOrderPrice.d.ts +0 -1
- package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +0 -1
- package/lib/esm/components/utils/PriceTemplate.d.ts +2 -3
- package/lib/esm/components/utils/getAllErrors.d.ts +0 -1
- package/lib/esm/reducers/CustomerReducer.js +1 -1
- package/lib/esm/reducers/GiftCardReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.js +1 -1
- package/lib/esm/typings/globals.d.ts +0 -1
- package/lib/esm/utils/filterChildren.d.ts +0 -1
- package/lib/esm/utils/getCustomerIdByToken.js +1 -1
- package/lib/esm/utils/getDomain.js +1 -1
- package/lib/esm/utils/getLoaderComponent.d.ts +0 -1
- package/lib/esm/utils/getPrices.d.ts +0 -1
- package/lib/esm/utils/getPrices.js +1 -1
- package/lib/esm/utils/isGuestToken.js +1 -1
- package/lib/esm/utils/jwt.d.ts +1 -1
- package/lib/esm/utils/jwt.js +1 -1
- package/package.json +30 -30
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import Parent from"../utils/Parent";import PricesContext from"../../context/PricesContext";import{useState,useEffect,useContext}from"react";import{getPricesComponent}from"../../utils/getPrices";import SkuChildrenContext from"../../context/SkuChildrenContext";export function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=useContext(PricesContext),{sku}=useContext(SkuChildrenContext),[skuPrices,setSkuPrices]=useState([]),sCode=pricesSkuCode||skuCode||sku?.code;useEffect(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps={loading,loader,prices:skuPrices,...props},pricesComponent=prices==null||skuPrices==null?null:getPricesComponent(skuPrices,props);return children?_jsx(Parent,{...parentProps,children}):_jsx(_Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}export default Price;
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import Parent from"../utils/Parent";import PricesContext from"../../context/PricesContext";import{useState,useEffect,useContext}from"react";import{getPricesComponent}from"../../utils/getPrices";import SkuChildrenContext from"../../context/SkuChildrenContext";export function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=useContext(PricesContext),{sku}=useContext(SkuChildrenContext),[skuPrices,setSkuPrices]=useState([]),sCode=pricesSkuCode||skuCode||sku?.code||"";useEffect(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps={loading,loader,prices:skuPrices,...props},pricesComponent=prices==null||skuPrices==null?null:getPricesComponent(skuPrices,props);return children?_jsx(Parent,{...parentProps,children}):_jsx(_Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}export default Price;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import ShippingMethodChildrenContext from"../../context/ShippingMethodChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import isEmpty from"lodash/isEmpty";export function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=useContext(ShipmentChildrenContext),[items,setItems]=useState([]);useEffect(()=>{const methods=shippingMethods?.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{const deliveryShippingMethodId=delivery.shipping_method?.id;return shippingMethod.id===deliveryShippingMethodId}),shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return _jsx(ShippingMethodChildrenContext.Provider,{value:shippingProps,children},k)});return methods&&setItems(methods),()=>{setItems([])}},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components=!isEmpty(items)&&items||emptyText;return _jsx(_Fragment,{children:components})}export default ShippingMethod;
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import ShippingMethodChildrenContext from"../../context/ShippingMethodChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import isEmpty from"lodash/isEmpty";export function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=useContext(ShipmentChildrenContext),[items,setItems]=useState([]);useEffect(()=>{const methods=shippingMethods?.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{const deliveryShippingMethodId=delivery.shipping_method?.id;return shippingMethod.id===deliveryShippingMethodId})??[],shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return _jsx(ShippingMethodChildrenContext.Provider,{value:shippingProps,children},k)});return methods&&setItems(methods),()=>{setItems([])}},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components=!isEmpty(items)&&items||emptyText;return _jsx(_Fragment,{children:components})}export default ShippingMethod;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type TimeFormat, type ChildrenFunction } from '../../typings/index';
|
|
3
2
|
import { type DeliveryLeadTime } from '../../reducers/AvailabilityReducer';
|
|
4
3
|
interface AvailabilityTemplateChildrenProps extends Omit<Props, 'children'>, DeliveryLeadTime {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type ConditionalElement } from '../../typings/index';
|
|
3
2
|
import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
|
|
4
3
|
type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['StockTransfer']>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type PropsType } from '../../utils/PropsType';
|
|
3
2
|
import { type baseOrderPricePropTypes } from '../../typings/index';
|
|
4
3
|
export type BaseOrderPriceProps = PropsType<typeof baseOrderPricePropTypes, unknown> & Omit<JSX.IntrinsicElements['span'], 'children'>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type PriceProps } from '../prices/Price';
|
|
3
2
|
export type PTemplateProps = {
|
|
4
|
-
formattedAmount?: string;
|
|
5
|
-
formattedCompare?: string;
|
|
3
|
+
formattedAmount?: string | null;
|
|
4
|
+
formattedCompare?: string | null;
|
|
6
5
|
} & Omit<PriceProps, 'children'>;
|
|
7
6
|
export declare function PriceTemplate(props: PTemplateProps): JSX.Element;
|
|
8
7
|
export default PriceTemplate;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";import
|
|
2
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";import{jwt}from"../utils/jwt";import{getCustomerIdByToken}from"../utils/getCustomerIdByToken";import{triggerAttributeHelper}from"../utils/triggerAttributeHelper";export async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}export function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}export function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}export async function getCustomerAddresses({config,dispatch,isOrderAvailable}){try{const addresses=[];(await getSdk(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&(customerAddress.id!==customerAddress.address.reference&&!isOrderAvailable&&(customerAddress.address.reference=customerAddress.id),addresses.push(customerAddress.address))}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=getErrors({error,resource:"addresses"});dispatch({type:"setErrors",payload:{errors}})}}export async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await getSdk(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}}export function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}export async function getCustomerOrders({config,dispatch,pageSize=10,pageNumber=1}){if(config.accessToken){const{owner}=jwt(config.accessToken);if(owner?.id){const orders=await getSdk(config).customers.orders(owner.id,{filters:{status_not_in:"draft,pending"},pageSize,pageNumber});dispatch({type:"setOrders",payload:{orders}})}}}export async function getCustomerSubscriptions({number,config,dispatch,pageSize=10,pageNumber=1}){if(config.accessToken){const{owner}=jwt(config.accessToken);if(owner?.id){const sdk=getSdk(config);if(number!=null){const subscriptions=await sdk.customers.orders(owner.id,{filters:{order_subscription_number_eq:number},pageSize,pageNumber});dispatch({type:"setSubscriptions",payload:{subscriptions}})}else{const subscriptions=await sdk.customers.order_subscriptions(owner.id,{pageSize,pageNumber});dispatch({type:"setSubscriptions",payload:{subscriptions}})}}}}export async function createCustomerAddress({address,config,dispatch,state}){if(config&&address){const sdk=getSdk(config),{id}=address;try{if(id){const upAddress=await sdk.addresses.update(address),updatedAddresses=state?.addresses?.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=await sdk.addresses.create(address);if(state?.customers?.id&&newAddress?.id){const newCustomerAddress=await sdk.customer_addresses.create({customer:sdk.customers.relationship(state?.customers?.id),address:sdk.addresses.relationship(newAddress.id)});await sdk.addresses.update({id:newAddress.id,reference:newCustomerAddress.id}),dispatch&&state?.addresses&&(newAddress.reference=newCustomerAddress.id,dispatch({type:"setAddresses",payload:{addresses:[...state.addresses,newAddress]}}))}}}catch{throw new Error("Couldn't create customer address")}}}export async function getCustomerPayments({config,dispatch,pageSize=10,pageNumber=1}){if(config?.accessToken!=null&&dispatch!=null){const sdk=getSdk(config),{owner}=jwt(config.accessToken);if(owner?.id){const payments=await sdk.customer_payment_sources.list({include:["payment_source"],pageNumber,pageSize});dispatch({type:"setPayments",payload:{payments}})}}}export async function getCustomerInfo({config,dispatch}){if(config.accessToken&&dispatch!=null){const sdk=getSdk(config),customerId=getCustomerIdByToken(config.accessToken);if(customerId){const customers=await sdk.customers.retrieve(customerId),customerEmail=customers.email;dispatch({type:"setCustomers",payload:{customers,customerEmail}})}}}export async function setResourceTrigger({config,dispatch,resource,attribute,id,pageSize=10,pageNumber=1,reloadList=!1}){if(config.accessToken){const{owner}=jwt(config.accessToken);if(owner?.id&&await triggerAttributeHelper({config,resource,attribute,id})!=null&&dispatch!=null&&reloadList){switch(resource){case"orders":await getCustomerOrders({config,dispatch,pageSize,pageNumber});break;case"order_subscriptions":await getCustomerSubscriptions({config,dispatch,pageSize,pageNumber});break;default:return!1}return!0}}return!1}export const customerInitialState={errors:[],addresses:null,payments:null};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders","setSubscriptions","setCustomers"],customerReducer=(state,reducer)=>baseReducer(state,reducer,type);export default customerReducer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getErrors from"../utils/getErrors";import getSdk from"../utils/getSdk";export const giftCardInitialState={currencyCode:"",balanceCent:0,singleUse:!1,rechargeable:!0,loading:!1,expiresAt:null,errors:[]};export async function addGiftCardRecipient(values,config,dispatch){try{const recipient=await getSdk(config).gift_card_recipients.create(values);dispatch({type:"setGiftCardRecipient",payload:{giftCardRecipient:recipient}})}catch(error){console.error(error)}}export const addGiftCardLoading=(loading,dispatch)=>{dispatch({type:"setGiftCardLoading",payload:{loading}})};export async function addGiftCard(values,{config,dispatch,getOrder,createOrder,order}){try{const sdk=getSdk(config);addGiftCardLoading(!0,dispatch);const{firstName,lastName,email,...val}=values,giftCardValue={recipient_email:email,...val},giftCard=await sdk.gift_cards.create(giftCardValue,{include:["gift_card_recipient"]}),recipientValues={id:giftCard.gift_card_recipient?.id};if(firstName&&(recipientValues.first_name=firstName),lastName&&(recipientValues.last_name=lastName),isEmpty(recipientValues)||await sdk.gift_card_recipients.update(recipientValues),createOrder&&getOrder){const id=order?order.id:await createOrder({});if(id){const order2=sdk.orders.relationship(id),item=sdk.gift_cards.relationship(giftCard.id);await sdk.line_items.create({quantity:1,order:order2,item}),await getOrder(id)}}dispatch({type:"setGiftCardRecipient",payload:{...giftCardValue}}),addGiftCardLoading(!1,dispatch)}catch(error){const errors=getErrors({error,resource:"gift_cards"});dispatch({type:"setGiftCardErrors",payload:{errors}}),addGiftCardLoading(!1,dispatch)}}export const addGiftCardError=(errors,dispatch)=>{dispatch({type:"setGiftCardErrors",payload:{errors}})};const type=["setAvailability","setGiftCardRecipient","setGiftCardErrors","setGiftCardLoading"],giftCardReducer=(state,reducer)=>baseReducer(state,reducer,type);export default giftCardReducer;
|
|
2
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getErrors from"../utils/getErrors";import getSdk from"../utils/getSdk";export const giftCardInitialState={currencyCode:"",balanceCent:0,singleUse:!1,rechargeable:!0,loading:!1,expiresAt:null,errors:[]};export async function addGiftCardRecipient(values,config,dispatch){try{const recipient=await getSdk(config).gift_card_recipients.create(values);dispatch({type:"setGiftCardRecipient",payload:{giftCardRecipient:recipient}})}catch(error){console.error(error)}}export const addGiftCardLoading=(loading,dispatch)=>{dispatch({type:"setGiftCardLoading",payload:{loading}})};export async function addGiftCard(values,{config,dispatch,getOrder,createOrder,order}){try{const sdk=getSdk(config);addGiftCardLoading(!0,dispatch);const{firstName,lastName,email,...val}=values,giftCardValue={recipient_email:email,...val},giftCard=await sdk.gift_cards.create(giftCardValue,{include:["gift_card_recipient"]}),recipientValues={id:giftCard.gift_card_recipient?.id??""};if(firstName&&(recipientValues.first_name=firstName),lastName&&(recipientValues.last_name=lastName),isEmpty(recipientValues)||await sdk.gift_card_recipients.update(recipientValues),createOrder&&getOrder){const id=order?order.id:await createOrder({});if(id){const order2=sdk.orders.relationship(id),item=sdk.gift_cards.relationship(giftCard.id);await sdk.line_items.create({quantity:1,order:order2,item}),await getOrder(id)}}dispatch({type:"setGiftCardRecipient",payload:{...giftCardValue}}),addGiftCardLoading(!1,dispatch)}catch(error){const errors=getErrors({error,resource:"gift_cards"});dispatch({type:"setGiftCardErrors",payload:{errors}}),addGiftCardLoading(!1,dispatch)}}export const addGiftCardError=(errors,dispatch)=>{dispatch({type:"setGiftCardErrors",payload:{errors}})};const type=["setAvailability","setGiftCardRecipient","setGiftCardErrors","setGiftCardLoading"],giftCardReducer=(state,reducer)=>baseReducer(state,reducer,type);export default giftCardReducer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export async function createOrder(params){if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=getSdk(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=getErrors({error,resource:"orders"});console.error("Create order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""}export const getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=getSdk(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.editable===!1?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=getErrors({error,resource:"orders"});console.error("Retrieve order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch});return}};export async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=getSdk(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await getApiOrder({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0,order}}catch(error){const errors=getErrors({error,resource:"orders"});return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}export const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};export function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...new Set([...resourcesIncluded,...resources])],resources.forEach(resource=>{const includeLoaded={...payload.includeLoaded,[resource]:!0};payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded};payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}export async function addToCart(params){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=getSdk(config),id=await createOrder(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl,metadata=lineItem?.metadata,frequency=lineItem?.frequency,externalPrice=lineItem?.externalPrice;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items:lineItems}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&await Promise.all(lineItems.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity??1,_update_quantity:!0,bundle_code:bundleCode,metadata,frequency};externalPrice===!0&&(attrs._external_price=externalPrice);const newLineItem=await sdk.line_items.create(attrs);if(lineItemOption!=null){const{skuOptionId,options,quantity:quantity2}=lineItemOption,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:quantity2??1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),await getApiOrder({id,...params})}else await getApiOrder({id,...params,state});if(!isEmpty(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=getOrganizationSlug(config.endpoint??""),params2=`${id}?accessToken=${config.accessToken??""}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}}return{success:!1}}catch(error){const errors2=getErrors({error,resource:"orders"});return console.error("Add to cart",errors2),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}}export const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};export function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}export const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;setCustomerOrderParam(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})};export async function setGiftCardOrCouponCode({code,codeType,dispatch,config,order,include,state}){try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,order:currentOrder,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success,order:currentOrder}}return{success:!1}}catch(error){const errors=getErrors({error,resource:"orders",field:codeType});return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}export async function removeGiftCardOrCouponCode({codeType,dispatch,config,order,include,state}){try{if(config&&order&&dispatch){const attributes={[codeType]:""},orderUpdated=await updateOrder({id:order.id,attributes,config,include,dispatch,state});return dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0,order:orderUpdated?.order}}return{success:!1}}catch(error){const errors=getErrors({error,resource:"orders",field:codeType});return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}export const orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default orderReducer;
|
|
2
|
+
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export async function createOrder(params){if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=config!=null?getSdk(config):void 0;try{if(sdk==null)return"";const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=getErrors({error,resource:"orders"});console.error("Create order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""}export const getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=config!=null?getSdk(config):void 0;try{if(sdk==null)return;const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id??"",options);return clearWhenPlaced&&order.editable===!1?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=getErrors({error,resource:"orders"});console.error("Retrieve order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch});return}};export async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=config!=null?getSdk(config):void 0;try{if(sdk==null)return{success:!1};const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await getApiOrder({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0,order}}catch(error){const errors=getErrors({error,resource:"orders"});return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}export const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};export function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...new Set([...resourcesIncluded,...resources])],resources.forEach(resource=>{const includeLoaded={...payload.includeLoaded,[resource]:!0};payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded};payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}export async function addToCart(params){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=getSdk(config),id=await createOrder(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl,metadata=lineItem?.metadata,frequency=lineItem?.frequency,externalPrice=lineItem?.externalPrice;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items:lineItems}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&await Promise.all(lineItems.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity??1,_update_quantity:!0,bundle_code:bundleCode,metadata,frequency};externalPrice===!0&&(attrs._external_price=externalPrice);const newLineItem=await sdk.line_items.create(attrs);if(lineItemOption!=null){const{skuOptionId,options,quantity:quantity2}=lineItemOption,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:quantity2??1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),await getApiOrder({id,...params})}else await getApiOrder({id,...params,state});if(!isEmpty(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=getOrganizationSlug(config.endpoint??""),params2=`${id}?accessToken=${config.accessToken??""}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}}return{success:!1}}catch(error){const errors2=getErrors({error,resource:"orders"});return console.error("Add to cart",errors2),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}}export const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};export function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}export const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;setCustomerOrderParam(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})};export async function setGiftCardOrCouponCode({code,codeType,dispatch,config,order,include,state}){try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,order:currentOrder,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success,order:currentOrder}}return{success:!1}}catch(error){const errors=getErrors({error,resource:"orders",field:codeType});return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}export async function removeGiftCardOrCouponCode({codeType,dispatch,config,order,include,state}){try{if(config&&order&&dispatch){const attributes={[codeType]:""},orderUpdated=await updateOrder({id:order.id,attributes,config,include,dispatch,state});return dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0,order:orderUpdated?.order}}return{success:!1}}catch(error){const errors=getErrors({error,resource:"orders",field:codeType});return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}export const orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default orderReducer;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export type DefaultChildrenType = JSX.Element[] | JSX.Element | null;
|
|
3
2
|
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
4
3
|
export type TRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import{jwt}from"./jwt";export function getCustomerIdByToken(accessToken){return jwt(accessToken)?.owner?.id}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export function getDomain(endpoint){const url=new URL(endpoint),[slug]=url.hostname.split(".");return{domain:url.hostname.replace(`${slug??""}.`,""),slug}}
|
|
2
|
+
export function getDomain(endpoint){const url=new URL(endpoint),[slug]=url.hostname.split(".");return{domain:url.hostname.replace(`${slug??""}.`,""),slug:slug??""}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{createElement as _createElement}from"react";import{jsx as _jsx}from"react/jsx-runtime";import{isEmpty,first,isArray,has}from"lodash";import PriceTemplate from"../components/utils/PriceTemplate";export function getPriceByCode(skuPrices,code=""){return code?first(skuPrices.filter(p=>p.currency_code===code)):first(skuPrices)}export function getPricesComponent(skuPrices,props){return isEmpty(skuPrices)?_jsx(PriceTemplate,{...props}):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return _createElement(PriceTemplate,{...props,key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code})})}export default function getPrices(prices){const obj={};return isArray(prices)&&prices.forEach(p=>{const sku=p
|
|
2
|
+
import{createElement as _createElement}from"react";import{jsx as _jsx}from"react/jsx-runtime";import{isEmpty,first,isArray,has}from"lodash";import PriceTemplate from"../components/utils/PriceTemplate";export function getPriceByCode(skuPrices,code=""){return code?first(skuPrices.filter(p=>p.currency_code===code)):first(skuPrices)}export function getPricesComponent(skuPrices,props){return isEmpty(skuPrices)?_jsx(PriceTemplate,{...props}):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents!=null&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return _createElement(PriceTemplate,{...props,key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code})})}export default function getPrices(prices){const obj={};return isArray(prices)&&prices.forEach(p=>{const sku=p?.sku_code??"";has(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import{jwt}from"./jwt";export function isGuestToken(accessToken){return jwt(accessToken).owner==null}
|
package/lib/esm/utils/jwt.d.ts
CHANGED
package/lib/esm/utils/jwt.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import{jwtDecode}from"jwt-decode";export function jwt(accessToken){return jwtDecode(accessToken)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "4.9.0
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -165,47 +165,47 @@
|
|
|
165
165
|
},
|
|
166
166
|
"homepage": "https://github.com/commercelayer/commercelayer-react-components#readme",
|
|
167
167
|
"dependencies": {
|
|
168
|
-
"@adyen/adyen-web": "^5.
|
|
169
|
-
"@commercelayer/sdk": "^5.
|
|
170
|
-
"@stripe/react-stripe-js": "^2.
|
|
171
|
-
"@stripe/stripe-js": "^2.
|
|
172
|
-
"@tanstack/react-table": "^8.
|
|
173
|
-
"@types/iframe-resizer": "^3.5.
|
|
174
|
-
"axios": "^1.6.
|
|
175
|
-
"braintree-web": "^3.
|
|
168
|
+
"@adyen/adyen-web": "^5.57.0",
|
|
169
|
+
"@commercelayer/sdk": "^5.31.1",
|
|
170
|
+
"@stripe/react-stripe-js": "^2.4.0",
|
|
171
|
+
"@stripe/stripe-js": "^2.4.0",
|
|
172
|
+
"@tanstack/react-table": "^8.11.8",
|
|
173
|
+
"@types/iframe-resizer": "^3.5.13",
|
|
174
|
+
"axios": "^1.6.7",
|
|
175
|
+
"braintree-web": "^3.99.2",
|
|
176
176
|
"frames-react": "^1.1.0",
|
|
177
|
-
"iframe-resizer": "^4.3.
|
|
178
|
-
"jwt-decode": "^
|
|
177
|
+
"iframe-resizer": "^4.3.9",
|
|
178
|
+
"jwt-decode": "^4.0.0",
|
|
179
179
|
"lodash": "^4.17.21",
|
|
180
180
|
"rapid-form": "^2.1.0"
|
|
181
181
|
},
|
|
182
182
|
"devDependencies": {
|
|
183
|
-
"@commercelayer/js-auth": "^4.
|
|
184
|
-
"@faker-js/faker": "^8.
|
|
185
|
-
"@playwright/test": "^1.
|
|
186
|
-
"@testing-library/dom": "^9.3.
|
|
187
|
-
"@testing-library/react": "^14.
|
|
188
|
-
"@types/braintree-web": "^3.96.
|
|
189
|
-
"@types/lodash": "^4.14.
|
|
190
|
-
"@types/node": "^20.
|
|
191
|
-
"@types/prop-types": "^15.7.
|
|
192
|
-
"@types/react": "^18.2.
|
|
193
|
-
"@types/react-test-renderer": "^18.0.
|
|
194
|
-
"@types/react-window": "^1.8.
|
|
195
|
-
"@vitejs/plugin-react": "^4.1
|
|
183
|
+
"@commercelayer/js-auth": "^4.2.0",
|
|
184
|
+
"@faker-js/faker": "^8.4.0",
|
|
185
|
+
"@playwright/test": "^1.41.2",
|
|
186
|
+
"@testing-library/dom": "^9.3.4",
|
|
187
|
+
"@testing-library/react": "^14.2.1",
|
|
188
|
+
"@types/braintree-web": "^3.96.10",
|
|
189
|
+
"@types/lodash": "^4.14.202",
|
|
190
|
+
"@types/node": "^20.11.16",
|
|
191
|
+
"@types/prop-types": "^15.7.11",
|
|
192
|
+
"@types/react": "^18.2.53",
|
|
193
|
+
"@types/react-test-renderer": "^18.0.7",
|
|
194
|
+
"@types/react-window": "^1.8.8",
|
|
195
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
196
196
|
"@vitest/coverage-c8": "^0.33.0",
|
|
197
|
-
"jsdom": "^
|
|
197
|
+
"jsdom": "^24.0.0",
|
|
198
198
|
"minimize-js": "^1.4.0",
|
|
199
|
-
"msw": "^1.
|
|
199
|
+
"msw": "^2.1.5",
|
|
200
200
|
"react": "^18.2.0",
|
|
201
201
|
"react-dom": "^18.2.0",
|
|
202
202
|
"react-test-renderer": "^18.2.0",
|
|
203
203
|
"tsc-alias": "^1.8.8",
|
|
204
204
|
"tslib": "^2.6.2",
|
|
205
|
-
"typescript": "^5.
|
|
206
|
-
"vite": "^
|
|
207
|
-
"vite-tsconfig-paths": "^4.
|
|
208
|
-
"vitest": "^
|
|
205
|
+
"typescript": "^5.3.3",
|
|
206
|
+
"vite": "^5.0.12",
|
|
207
|
+
"vite-tsconfig-paths": "^4.3.1",
|
|
208
|
+
"vitest": "^1.2.2"
|
|
209
209
|
},
|
|
210
210
|
"peerDependencies": {
|
|
211
211
|
"react": "^18.0.0"
|