@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
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodRadioButton(props){const{onChange}=props,p=tslib_1.__rest(props,["onChange"]),{payment,paymentSelected,setPaymentSelected,clickableContainer}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodRadioButton",key:"payment"}),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPaymentMethod,setLoading}=(0,react_1.useContext)(PaymentMethodContext_1.default),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=payment?.id,name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer){const{order:order2}=yield setPaymentMethod({paymentResource,paymentMethodId});onChange&&onChange({payment,order:order2})}setLoading({loading:!1})}),id=payment?.payment_source_type,parentProps=Object.assign({handleOnChange,checked,id,name},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("input",Object.assign({title:name,type:"radio",id,onChange:e=>{handleOnChange(e)},checked},p))}exports.PaymentMethodRadioButton=PaymentMethodRadioButton,exports.default=PaymentMethodRadioButton;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodRadioButton(props){var _a;const{onChange}=props,p=tslib_1.__rest(props,["onChange"]),{payment,paymentSelected,setPaymentSelected,clickableContainer}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodRadioButton",key:"payment"}),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPaymentMethod,setLoading}=(0,react_1.useContext)(PaymentMethodContext_1.default),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=(_a=payment?.id)!==null&&_a!==void 0?_a:"",name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer){const{order:order2}=yield setPaymentMethod({paymentResource,paymentMethodId});onChange&&onChange({payment,order:order2})}setLoading({loading:!1})}),id=payment?.payment_source_type,parentProps=Object.assign({handleOnChange,checked,id,name},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("input",Object.assign({title:name,type:"radio",id,onChange:e=>{handleOnChange(e)},checked},p))}exports.PaymentMethodRadioButton=PaymentMethodRadioButton,exports.default=PaymentMethodRadioButton;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
|
|
3
2
|
import { type PaymentSourceProps } from './PaymentSource';
|
|
4
3
|
type KlarnaPaymentProps = PaymentMethodConfig['klarnaPayment'] & JSX.IntrinsicElements['div'] & Partial<PaymentSourceProps['templateCustomerSaveToWallet']> & {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripeExpressPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),expressPaymentHelper_1=require("../../utils/expressPaymentHelper"),isEmpty_1=require("../../utils/isEmpty"),react_stripe_js_1=require("@stripe/react-stripe-js"),react_1=require("react");function StripeExpressPayment({clientSecret}){const stripe=(0,react_stripe_js_1.useStripe)(),[paymentRequest,setPaymentRequest]=(0,react_1.useState)(null),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{paymentMethods,paymentSource}=(0,react_1.useContext)(PaymentMethodContext_1.default);return(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e;if(stripe==null||order==null)return;const pr=stripe.paymentRequest({country:(_a=order?.country_code)!==null&&_a!==void 0?_a:"US",currency:(_c=(_b=order?.currency_code)===null||_b===void 0?void 0:_b.toLowerCase())!==null&&_c!==void 0?_c:"",total:{label:`#${(_d=order?.number)!==null&&_d!==void 0?_d:""}`,amount:(_e=order?.total_amount_with_taxes_cents)!==null&&_e!==void 0?_e:0},requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:!0,requestShipping:!0});pr.canMakePayment().then(result=>{result&&setPaymentRequest(pr)}).catch(err=>{console.error("Can make payment:",err)})},[(0,isEmpty_1.isEmpty)(stripe),(0,isEmpty_1.isEmpty)(order)]),paymentRequest!=null&&stripe!=null?(paymentRequest.on("shippingaddresschange",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b,_c,_d,_e,_f,_g;if(order!=null&&accessToken!=null&&endpoint!=null){const requiresBillingInfo=(_a=order?.requires_billing_info)!==null&&_a!==void 0?_a:!1,orderWithShipments=yield(0,expressPaymentHelper_1.setExpressFakeAddress)({orderId:order.id,config:{accessToken,endpoint},address:{first_name:"Fake name",last_name:"Fake lastname",country_code:(_b=ev.shippingAddress.country)!==null&&_b!==void 0?_b:"",line_1:"Fake street 123",city:(_c=ev.shippingAddress.city)!==null&&_c!==void 0?_c:"Fake city",zip_code:(_d=ev.shippingAddress.postalCode)!==null&&_d!==void 0?_d:"12345",state_code:(_e=ev.shippingAddress.region)!==null&&_e!==void 0?_e:"Fake state",phone:"1234567890",billing_info:requiresBillingInfo?"Fake billing info":void 0}}),shippingOptions=(0,expressPaymentHelper_1.getExpressShippingMethods)(orderWithShipments);shippingOptions!=null&&!(0,isEmpty_1.isEmpty)(shippingOptions)?ev.updateWith({status:"success",shippingOptions,total:{label:`#${(_f=orderWithShipments?.number)!==null&&_f!==void 0?_f:""}`,amount:(_g=orderWithShipments?.total_amount_with_taxes_cents)!==null&&_g!==void 0?_g:0}}):ev.updateWith({status:"invalid_shipping_address"})}else ev.updateWith({status:"fail"})})),paymentRequest.on("shippingoptionchange",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _h,_j;if(order!=null&&accessToken!=null&&endpoint!=null){const updatedOrder=yield(0,expressPaymentHelper_1.setExpressShippingMethod)({orderId:order.id,config:{accessToken,endpoint},selectFirst:!1,selectedShippingMethodId:ev.shippingOption.id,params:{include:["shipments.available_shipping_methods"]}});ev.updateWith({status:"success",total:{label:`#${(_h=updatedOrder?.number)!==null&&_h!==void 0?_h:""}`,amount:(_j=updatedOrder?.total_amount_with_taxes_cents)!==null&&_j!==void 0?_j:0}})}else ev.updateWith({status:"fail"})})),paymentRequest.on("paymentmethod",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v,_w,_x,_y,_z,_0;if(order?.id==null)throw new Error("Order is null");if(paymentMethods==null)throw new Error("Payment methods are null");const[paymentMethod]=(0,expressPaymentHelper_1.getAvailableExpressPayments)(paymentMethods);if(paymentMethod==null)throw new Error("Payment method is null");if(paymentSource==null)throw new Error("Payment source is null");const requiresBillingInfo=(_k=order?.requires_billing_info)!==null&&_k!==void 0?_k:!1,paymentResource=paymentMethod?.payment_source_type;if(accessToken!=null&&endpoint!=null){const[firstName,lastName]=(_m=(_l=ev.payerName)===null||_l===void 0?void 0:_l.split(" "))!==null&&_m!==void 0?_m:[],[line]=(_p=(_o=ev.shippingAddress)===null||_o===void 0?void 0:_o.addressLine)!==null&&_p!==void 0?_p:"",email=(_q=ev.payerEmail)!==null&&_q!==void 0?_q:"";yield(0,expressPaymentHelper_1.setExpressFakeAddress)({orderId:order.id,config:{accessToken,endpoint},address:{first_name:firstName??"Fake name",last_name:lastName??"Fake lastname",country_code:(_s=(_r=ev?.shippingAddress)===null||_r===void 0?void 0:_r.country)!==null&&_s!==void 0?_s:"",line_1:line??"Fake street 123",city:(_u=(_t=ev?.shippingAddress)===null||_t===void 0?void 0:_t.city)!==null&&_u!==void 0?_u:"Fake city",zip_code:(_w=(_v=ev?.shippingAddress)===null||_v===void 0?void 0:_v.postalCode)!==null&&_w!==void 0?_w:"12345",state_code:(_y=(_x=ev?.shippingAddress)===null||_x===void 0?void 0:_x.region)!==null&&_y!==void 0?_y:"Fake state",phone:(_z=ev?.payerPhone)!==null&&_z!==void 0?_z:"1234567890",billing_info:requiresBillingInfo?"Fake billing info":void 0},email}),yield(0,expressPaymentHelper_1.setExpressShippingMethod)({orderId:order.id,config:{accessToken,endpoint},selectFirst:!1,selectedShippingMethodId:(_0=ev?.shippingOption)===null||_0===void 0?void 0:_0.id,params:{include:["shipments.available_shipping_methods"]}});const placeOrderParams={config:{accessToken,endpoint},orderId:order?.id,paymentResource,paymentSourceId:paymentSource?.id};yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams);const{paymentIntent,error:confirmError}=yield stripe.confirmCardPayment(clientSecret,{payment_method:ev.paymentMethod.id},{handleActions:!1});if(confirmError)ev.complete("fail"),console.error("Confirm card payment:",confirmError);else if(ev.complete("success"),paymentIntent.status==="requires_action"){const{error}=yield stripe.confirmCardPayment(clientSecret);if(error)console.error("Confirm card payment:",error);else{const placeOrderParams2={config:{accessToken,endpoint},orderId:order?.id,placeTheOrder:!0};try{const order2=yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams2);ev.complete("success"),(0,expressPaymentHelper_1.expressRedirectUrl)({order:order2,config:{accessToken,endpoint}})}catch(err){console.error("Place order:",err),ev.complete("fail")}}}else{const placeOrderParams2={config:{accessToken,endpoint},orderId:order?.id,placeTheOrder:!0};try{const order2=yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams2);ev.complete("success"),(0,expressPaymentHelper_1.expressRedirectUrl)({order:order2,config:{accessToken,endpoint}})}catch(err){console.error("Place order:",err),ev.complete("fail")}}}})),(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentRequestButtonElement,{className:"",options:{paymentRequest}})):null}exports.StripeExpressPayment=StripeExpressPayment;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripeExpressPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),expressPaymentHelper_1=require("../../utils/expressPaymentHelper"),isEmpty_1=require("../../utils/isEmpty"),react_stripe_js_1=require("@stripe/react-stripe-js"),react_1=require("react");function StripeExpressPayment({clientSecret}){const stripe=(0,react_stripe_js_1.useStripe)(),[paymentRequest,setPaymentRequest]=(0,react_1.useState)(null),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{paymentMethods,paymentSource}=(0,react_1.useContext)(PaymentMethodContext_1.default);return(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e;if(stripe==null||order==null)return;const pr=stripe.paymentRequest({country:(_a=order?.country_code)!==null&&_a!==void 0?_a:"US",currency:(_c=(_b=order?.currency_code)===null||_b===void 0?void 0:_b.toLowerCase())!==null&&_c!==void 0?_c:"",total:{label:`#${(_d=order?.number)!==null&&_d!==void 0?_d:""}`,amount:(_e=order?.total_amount_with_taxes_cents)!==null&&_e!==void 0?_e:0},requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:!0,requestShipping:!0});pr.canMakePayment().then(result=>{result&&setPaymentRequest(pr)}).catch(err=>{console.error("Can make payment:",err)})},[(0,isEmpty_1.isEmpty)(stripe),(0,isEmpty_1.isEmpty)(order)]),paymentRequest!=null&&stripe!=null?(paymentRequest.on("shippingaddresschange",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b,_c,_d,_e,_f,_g;if(order!=null&&accessToken!=null&&endpoint!=null){const requiresBillingInfo=(_a=order?.requires_billing_info)!==null&&_a!==void 0?_a:!1,orderWithShipments=yield(0,expressPaymentHelper_1.setExpressFakeAddress)({orderId:order.id,config:{accessToken,endpoint},address:{first_name:"Fake name",last_name:"Fake lastname",country_code:(_b=ev.shippingAddress.country)!==null&&_b!==void 0?_b:"",line_1:"Fake street 123",city:(_c=ev.shippingAddress.city)!==null&&_c!==void 0?_c:"Fake city",zip_code:(_d=ev.shippingAddress.postalCode)!==null&&_d!==void 0?_d:"12345",state_code:(_e=ev.shippingAddress.region)!==null&&_e!==void 0?_e:"Fake state",phone:"1234567890",billing_info:requiresBillingInfo?"Fake billing info":void 0}}),shippingOptions=(0,expressPaymentHelper_1.getExpressShippingMethods)(orderWithShipments);shippingOptions!=null&&!(0,isEmpty_1.isEmpty)(shippingOptions)?ev.updateWith({status:"success",shippingOptions,total:{label:`#${(_f=orderWithShipments?.number)!==null&&_f!==void 0?_f:""}`,amount:(_g=orderWithShipments?.total_amount_with_taxes_cents)!==null&&_g!==void 0?_g:0}}):ev.updateWith({status:"invalid_shipping_address"})}else ev.updateWith({status:"fail"})})),paymentRequest.on("shippingoptionchange",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _h,_j;if(order!=null&&accessToken!=null&&endpoint!=null){const updatedOrder=yield(0,expressPaymentHelper_1.setExpressShippingMethod)({orderId:order.id,config:{accessToken,endpoint},selectFirst:!1,selectedShippingMethodId:ev.shippingOption.id,params:{include:["shipments.available_shipping_methods"]}});ev.updateWith({status:"success",total:{label:`#${(_h=updatedOrder?.number)!==null&&_h!==void 0?_h:""}`,amount:(_j=updatedOrder?.total_amount_with_taxes_cents)!==null&&_j!==void 0?_j:0}})}else ev.updateWith({status:"fail"})})),paymentRequest.on("paymentmethod",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v,_w,_x,_y,_z,_0;if(order?.id==null)throw new Error("Order is null");if(paymentMethods==null)throw new Error("Payment methods are null");const[paymentMethod]=(0,expressPaymentHelper_1.getAvailableExpressPayments)(paymentMethods);if(paymentMethod==null)throw new Error("Payment method is null");if(paymentSource==null)throw new Error("Payment source is null");const requiresBillingInfo=(_k=order?.requires_billing_info)!==null&&_k!==void 0?_k:!1,paymentResource=paymentMethod?.payment_source_type;if(accessToken!=null&&endpoint!=null){const[firstName,lastName]=(_m=(_l=ev.payerName)===null||_l===void 0?void 0:_l.split(" "))!==null&&_m!==void 0?_m:[],[line]=(_p=(_o=ev.shippingAddress)===null||_o===void 0?void 0:_o.addressLine)!==null&&_p!==void 0?_p:"",email=(_q=ev.payerEmail)!==null&&_q!==void 0?_q:"";yield(0,expressPaymentHelper_1.setExpressFakeAddress)({orderId:order.id,config:{accessToken,endpoint},address:{first_name:firstName??"Fake name",last_name:lastName??"Fake lastname",country_code:(_s=(_r=ev?.shippingAddress)===null||_r===void 0?void 0:_r.country)!==null&&_s!==void 0?_s:"",line_1:line??"Fake street 123",city:(_u=(_t=ev?.shippingAddress)===null||_t===void 0?void 0:_t.city)!==null&&_u!==void 0?_u:"Fake city",zip_code:(_w=(_v=ev?.shippingAddress)===null||_v===void 0?void 0:_v.postalCode)!==null&&_w!==void 0?_w:"12345",state_code:(_y=(_x=ev?.shippingAddress)===null||_x===void 0?void 0:_x.region)!==null&&_y!==void 0?_y:"Fake state",phone:(_z=ev?.payerPhone)!==null&&_z!==void 0?_z:"1234567890",billing_info:requiresBillingInfo?"Fake billing info":void 0},email}),yield(0,expressPaymentHelper_1.setExpressShippingMethod)({orderId:order.id,config:{accessToken,endpoint},selectFirst:!1,selectedShippingMethodId:(_0=ev?.shippingOption)===null||_0===void 0?void 0:_0.id,params:{include:["shipments.available_shipping_methods"]}});const placeOrderParams={config:{accessToken,endpoint},orderId:order?.id,paymentResource,paymentSourceId:paymentSource?.id};yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams);const{paymentIntent,error:confirmError}=yield stripe.confirmCardPayment(clientSecret,{payment_method:ev.paymentMethod.id},{handleActions:!1});if(confirmError)ev.complete("fail"),console.error("Confirm card payment:",confirmError);else if(ev.complete("success"),paymentIntent.status==="requires_action"){const{error}=yield stripe.confirmCardPayment(clientSecret);if(error)console.error("Confirm card payment:",error);else{const placeOrderParams2={config:{accessToken,endpoint},orderId:order?.id,placeTheOrder:!0};try{const order2=yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams2);ev.complete("success"),(0,expressPaymentHelper_1.expressRedirectUrl)({order:order2,config:{accessToken,endpoint}})}catch(err){console.error("Place order:",err),ev.complete("fail")}}}else{const placeOrderParams2={config:{accessToken,endpoint},orderId:order?.id,placeTheOrder:!0};try{const order2=yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams2);ev.complete("success"),(0,expressPaymentHelper_1.expressRedirectUrl)({order:order2,config:{accessToken,endpoint}})}catch(err){console.error("Place order:",err),ev.complete("fail")}}}})),(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentRequestButtonElement,{className:"",options:{paymentRequest}})})):null}exports.StripeExpressPayment=StripeExpressPayment;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type StripeElementLocale, type StripeElementsOptions, type StripePaymentElementOptions } from '@stripe/stripe-js';
|
|
3
2
|
import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
|
|
4
3
|
import { type PaymentSourceProps } from './PaymentSource';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripePayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),react_stripe_js_1=require("@stripe/react-stripe-js"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),StripeExpressPayment_1=require("./StripeExpressPayment"),defaultOptions={layout:{type:"accordion",defaultCollapsed:!1,radios:!0,spacedAccordionItems:!1},fields:{billingDetails:"never"}},defaultAppearance={theme:"stripe",variables:{colorText:"#32325d",fontFamily:'"Helvetica Neue", Helvetica, sans-serif'}};function StripePaymentForm({options=defaultOptions,templateCustomerSaveToWallet}){const ref=(0,react_1.useRef)(null),{currentPaymentMethodType,setPaymentMethodErrors,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),stripe=(0,react_stripe_js_1.useStripe)(),elements=(0,react_stripe_js_1.useElements)();(0,react_1.useEffect)(()=>(ref.current&&stripe&&elements&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield onSubmit({event:ref.current,stripe,elements})}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,stripe,elements]);const onSubmit=({event,stripe:stripe2,elements:elements2})=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b,_c,_d,_e,_f;if(!stripe2)return!1;const savePaymentSourceToCustomerWallet=(_b=(_a=event?.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),elements2!=null){const billingInfo=order?.billing_address,email=(_c=order?.customer_email)!==null&&_c!==void 0?_c:"",billingDetails={name:(_d=billingInfo?.full_name)!==null&&_d!==void 0?_d:"",email,phone:billingInfo?.phone,address:{city:billingInfo?.city,country:billingInfo?.country_code,line1:billingInfo?.line_1,line2:(_e=billingInfo?.line_2)!==null&&_e!==void 0?_e:"",postal_code:(_f=billingInfo?.zip_code)!==null&&_f!==void 0?_f:"",state:billingInfo?.state_code}},{error}=yield stripe2.confirmPayment({elements:elements2,confirmParams:{return_url:window.location.href,payment_method_data:{billing_details:billingDetails}},redirect:"if_required"});return error?(console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1):!0}return!1});return(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement,{id:"payment-element",options:Object.assign(Object.assign({},defaultOptions),options)}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]})}function StripePayment(_a){var{publishableKey,show,options,clientSecret,locale="auto",expressPayments=!1}=_a,p=tslib_1.__rest(_a,["publishableKey","show","options","clientSecret","locale","expressPayments"]);const[isLoaded,setIsLoaded]=(0,react_1.useState)(!1),[stripe,setStripe]=(0,react_1.useState)(null),{containerClassName,templateCustomerSaveToWallet,fonts=[],appearance}=p,divProps=tslib_1.__rest(p,["containerClassName","templateCustomerSaveToWallet","fonts","appearance"]);(0,react_1.useEffect)(()=>(show&&publishableKey&&Promise.resolve().then(()=>tslib_1.__importStar(require("@stripe/stripe-js"))).then(({loadStripe})=>{(()=>tslib_1.__awaiter(this,void 0,void 0,function*(){const res=yield loadStripe(publishableKey,{locale});res!=null&&(setStripe(res),setIsLoaded(!0))}))()}),()=>{setIsLoaded(!1)}),[show,publishableKey]);const elementsOptions={clientSecret,appearance:Object.assign(Object.assign({},defaultAppearance),appearance),fonts};return isLoaded&&stripe!=null&&clientSecret!=null?(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsx)(react_stripe_js_1.Elements,{stripe,options:elementsOptions,children:expressPayments?(0,jsx_runtime_1.jsx)(StripeExpressPayment_1.StripeExpressPayment,{clientSecret}):(0,jsx_runtime_1.jsx)(StripePaymentForm,{options,templateCustomerSaveToWallet})})})):null}exports.StripePayment=StripePayment,exports.default=StripePayment;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripePayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),react_stripe_js_1=require("@stripe/react-stripe-js"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),StripeExpressPayment_1=require("./StripeExpressPayment"),defaultOptions={layout:{type:"accordion",defaultCollapsed:!1,radios:!0,spacedAccordionItems:!1},fields:{billingDetails:"never"}},defaultAppearance={theme:"stripe",variables:{colorText:"#32325d",fontFamily:'"Helvetica Neue", Helvetica, sans-serif'}};function StripePaymentForm({options=defaultOptions,templateCustomerSaveToWallet}){const ref=(0,react_1.useRef)(null),{currentPaymentMethodType,setPaymentMethodErrors,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),stripe=(0,react_stripe_js_1.useStripe)(),elements=(0,react_stripe_js_1.useElements)();(0,react_1.useEffect)(()=>(ref.current&&stripe&&elements&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield onSubmit({event:ref.current,stripe,elements})}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,stripe,elements]);const onSubmit=({event,stripe:stripe2,elements:elements2})=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b,_c,_d,_e,_f,_g;if(!stripe2)return!1;const savePaymentSourceToCustomerWallet=(_b=(_a=event?.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),elements2!=null){const billingInfo=order?.billing_address,email=(_c=order?.customer_email)!==null&&_c!==void 0?_c:"",billingDetails={name:(_d=billingInfo?.full_name)!==null&&_d!==void 0?_d:"",email,phone:billingInfo?.phone,address:{city:billingInfo?.city,country:billingInfo?.country_code,line1:billingInfo?.line_1,line2:(_e=billingInfo?.line_2)!==null&&_e!==void 0?_e:"",postal_code:(_f=billingInfo?.zip_code)!==null&&_f!==void 0?_f:"",state:billingInfo?.state_code}},{error}=yield stripe2.confirmPayment({elements:elements2,confirmParams:{return_url:window.location.href,payment_method_data:{billing_details:billingDetails}},redirect:"if_required"});return error?(console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:(_g=error.message)!==null&&_g!==void 0?_g:""}]),!1):!0}return!1});return(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement,{id:"payment-element",options:Object.assign(Object.assign({},defaultOptions),options)}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]})}function StripePayment(_a){var{publishableKey,show,options,clientSecret,locale="auto",expressPayments=!1}=_a,p=tslib_1.__rest(_a,["publishableKey","show","options","clientSecret","locale","expressPayments"]);const[isLoaded,setIsLoaded]=(0,react_1.useState)(!1),[stripe,setStripe]=(0,react_1.useState)(null),{containerClassName,templateCustomerSaveToWallet,fonts=[],appearance}=p,divProps=tslib_1.__rest(p,["containerClassName","templateCustomerSaveToWallet","fonts","appearance"]);(0,react_1.useEffect)(()=>(show&&publishableKey&&Promise.resolve().then(()=>tslib_1.__importStar(require("@stripe/stripe-js"))).then(({loadStripe})=>{(()=>tslib_1.__awaiter(this,void 0,void 0,function*(){const res=yield loadStripe(publishableKey,{locale});res!=null&&(setStripe(res),setIsLoaded(!0))}))()}),()=>{setIsLoaded(!1)}),[show,publishableKey]);const elementsOptions={clientSecret,appearance:Object.assign(Object.assign({},defaultAppearance),appearance),fonts};return isLoaded&&stripe!=null&&clientSecret!=null?(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsx)(react_stripe_js_1.Elements,{stripe,options:elementsOptions,children:expressPayments?(0,jsx_runtime_1.jsx)(StripeExpressPayment_1.StripeExpressPayment,{clientSecret}):(0,jsx_runtime_1.jsx)(StripePaymentForm,{options,templateCustomerSaveToWallet})})})):null}exports.StripePayment=StripePayment,exports.default=StripePayment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Price=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PricesContext_1=tslib_1.__importDefault(require("../../context/PricesContext")),react_1=require("react"),getPrices_1=require("../../utils/getPrices"),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext"));function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=(0,react_1.useContext)(PricesContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),[skuPrices,setSkuPrices]=(0,react_1.useState)([]),sCode=pricesSkuCode||skuCode||sku?.code;(0,react_1.useEffect)(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps=Object.assign({loading,loader,prices:skuPrices},props),pricesComponent=prices==null||skuPrices==null?null:(0,getPrices_1.getPricesComponent)(skuPrices,props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}exports.Price=Price,exports.default=Price;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Price=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PricesContext_1=tslib_1.__importDefault(require("../../context/PricesContext")),react_1=require("react"),getPrices_1=require("../../utils/getPrices"),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext"));function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=(0,react_1.useContext)(PricesContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),[skuPrices,setSkuPrices]=(0,react_1.useState)([]),sCode=pricesSkuCode||skuCode||sku?.code||"";(0,react_1.useEffect)(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps=Object.assign({loading,loader,prices:skuPrices},props),pricesComponent=prices==null||skuPrices==null?null:(0,getPrices_1.getPricesComponent)(skuPrices,props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}exports.Price=Price,exports.default=Price;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethod=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),[items,setItems]=(0,react_1.useState)([]);(0,react_1.useEffect)(()=>{const methods=shippingMethods?.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{var
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethod=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),[items,setItems]=(0,react_1.useState)([]);(0,react_1.useEffect)(()=>{const methods=shippingMethods?.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{var _a;const[deliveryLeadTimeForShipment]=(_a=deliveryLeadTimes?.filter(delivery=>{var _a2;const deliveryShippingMethodId=(_a2=delivery.shipping_method)===null||_a2===void 0?void 0:_a2.id;return shippingMethod.id===deliveryShippingMethodId}))!==null&&_a!==void 0?_a:[],shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return(0,jsx_runtime_1.jsx)(ShippingMethodChildrenContext_1.default.Provider,{value:shippingProps,children},k)});return methods&&setItems(methods),()=>{setItems([])}},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components=!(0,isEmpty_1.default)(items)&&items||emptyText;return(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.ShippingMethod=ShippingMethod,exports.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
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.setResourceTrigger=exports.getCustomerInfo=exports.getCustomerPayments=exports.createCustomerAddress=exports.getCustomerSubscriptions=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.setResourceTrigger=exports.getCustomerInfo=exports.getCustomerPayments=exports.createCustomerAddress=exports.getCustomerSubscriptions=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=require("../utils/jwt"),getCustomerIdByToken_1=require("../utils/getCustomerIdByToken"),triggerAttributeHelper_1=require("../utils/triggerAttributeHelper");function saveCustomerUser({customerEmail,order,updateOrder}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(order){const attributes={customer_email:customerEmail,id:order.id};yield updateOrder({id:order.id,attributes})}})}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;function getCustomerAddresses({config,dispatch,isOrderAvailable}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const addresses=[];(yield(0,getSdk_1.default)(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=(0,getErrors_1.default)({error,resource:"addresses"});dispatch({type:"setErrors",payload:{errors}})}})}exports.getCustomerAddresses=getCustomerAddresses;function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config&&addresses&&dispatch&&config)try{yield(0,getSdk_1.default)(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")}})}exports.deleteCustomerAddress=deleteCustomerAddress;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}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;function getCustomerOrders({config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.jwt)(config.accessToken);if(owner?.id){const orders=yield(0,getSdk_1.default)(config).customers.orders(owner.id,{filters:{status_not_in:"draft,pending"},pageSize,pageNumber});dispatch({type:"setOrders",payload:{orders}})}}})}exports.getCustomerOrders=getCustomerOrders;function getCustomerSubscriptions({number,config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.jwt)(config.accessToken);if(owner?.id){const sdk=(0,getSdk_1.default)(config);if(number!=null){const subscriptions=yield sdk.customers.orders(owner.id,{filters:{order_subscription_number_eq:number},pageSize,pageNumber});dispatch({type:"setSubscriptions",payload:{subscriptions}})}else{const subscriptions=yield sdk.customers.order_subscriptions(owner.id,{pageSize,pageNumber});dispatch({type:"setSubscriptions",payload:{subscriptions}})}}}})}exports.getCustomerSubscriptions=getCustomerSubscriptions;function createCustomerAddress({address,config,dispatch,state}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config&&address){const sdk=(0,getSdk_1.default)(config),{id}=address;try{if(id){const upAddress=yield sdk.addresses.update(address),updatedAddresses=(_a=state?.addresses)===null||_a===void 0?void 0:_a.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=yield sdk.addresses.create(address);if(!((_b=state?.customers)===null||_b===void 0)&&_b.id&&newAddress?.id){const newCustomerAddress=yield sdk.customer_addresses.create({customer:sdk.customers.relationship((_c=state?.customers)===null||_c===void 0?void 0:_c.id),address:sdk.addresses.relationship(newAddress.id)});yield 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")}}})}exports.createCustomerAddress=createCustomerAddress;function getCustomerPayments({config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config?.accessToken!=null&&dispatch!=null){const sdk=(0,getSdk_1.default)(config),{owner}=(0,jwt_1.jwt)(config.accessToken);if(owner?.id){const payments=yield sdk.customer_payment_sources.list({include:["payment_source"],pageNumber,pageSize});dispatch({type:"setPayments",payload:{payments}})}}})}exports.getCustomerPayments=getCustomerPayments;function getCustomerInfo({config,dispatch}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken&&dispatch!=null){const sdk=(0,getSdk_1.default)(config),customerId=(0,getCustomerIdByToken_1.getCustomerIdByToken)(config.accessToken);if(customerId){const customers=yield sdk.customers.retrieve(customerId),customerEmail=customers.email;dispatch({type:"setCustomers",payload:{customers,customerEmail}})}}})}exports.getCustomerInfo=getCustomerInfo;function setResourceTrigger({config,dispatch,resource,attribute,id,pageSize=10,pageNumber=1,reloadList=!1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.jwt)(config.accessToken);if(owner?.id){const params={config,resource,attribute,id};if((yield(0,triggerAttributeHelper_1.triggerAttributeHelper)(params))!=null&&dispatch!=null&&reloadList){switch(resource){case"orders":yield getCustomerOrders({config,dispatch,pageSize,pageNumber});break;case"order_subscriptions":yield getCustomerSubscriptions({config,dispatch,pageSize,pageNumber});break;default:return!1}return!0}}}return!1})}exports.setResourceTrigger=setResourceTrigger,exports.customerInitialState={errors:[],addresses:null,payments:null};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders","setSubscriptions","setCustomers"],customerReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=customerReducer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addGiftCardError=exports.addGiftCard=exports.addGiftCardLoading=exports.addGiftCardRecipient=exports.giftCardInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.giftCardInitialState={currencyCode:"",balanceCent:0,singleUse:!1,rechargeable:!0,loading:!1,expiresAt:null,errors:[]};function addGiftCardRecipient(values,config,dispatch){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const recipient=yield(0,getSdk_1.default)(config).gift_card_recipients.create(values);dispatch({type:"setGiftCardRecipient",payload:{giftCardRecipient:recipient}})}catch(error){console.error(error)}})}exports.addGiftCardRecipient=addGiftCardRecipient;const addGiftCardLoading=(loading,dispatch)=>{dispatch({type:"setGiftCardLoading",payload:{loading}})};exports.addGiftCardLoading=addGiftCardLoading;function addGiftCard(values,{config,dispatch,getOrder,createOrder,order}){var _a;return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const sdk=(0,getSdk_1.default)(config);(0,exports.addGiftCardLoading)(!0,dispatch);const{firstName,lastName,email}=values,val=tslib_1.__rest(values,["firstName","lastName","email"]),giftCardValue=Object.assign({recipient_email:email},val),giftCard=yield sdk.gift_cards.create(giftCardValue,{include:["gift_card_recipient"]}),recipientValues={id:(_a=giftCard.gift_card_recipient)===null||_a===void 0?void 0:_a.id};if(firstName&&(recipientValues.first_name=firstName),lastName&&(recipientValues.last_name=lastName),(0,isEmpty_1.default)(recipientValues)||(yield sdk.gift_card_recipients.update(recipientValues)),createOrder&&getOrder){const id=order?order.id:yield createOrder({});if(id){const order2=sdk.orders.relationship(id),item=sdk.gift_cards.relationship(giftCard.id);yield sdk.line_items.create({quantity:1,order:order2,item}),yield getOrder(id)}}dispatch({type:"setGiftCardRecipient",payload:Object.assign({},giftCardValue)}),(0,exports.addGiftCardLoading)(!1,dispatch)}catch(error){const errors=(0,getErrors_1.default)({error,resource:"gift_cards"});dispatch({type:"setGiftCardErrors",payload:{errors}}),(0,exports.addGiftCardLoading)(!1,dispatch)}})}exports.addGiftCard=addGiftCard;const addGiftCardError=(errors,dispatch)=>{dispatch({type:"setGiftCardErrors",payload:{errors}})};exports.addGiftCardError=addGiftCardError;const type=["setAvailability","setGiftCardRecipient","setGiftCardErrors","setGiftCardLoading"],giftCardReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=giftCardReducer;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addGiftCardError=exports.addGiftCard=exports.addGiftCardLoading=exports.addGiftCardRecipient=exports.giftCardInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.giftCardInitialState={currencyCode:"",balanceCent:0,singleUse:!1,rechargeable:!0,loading:!1,expiresAt:null,errors:[]};function addGiftCardRecipient(values,config,dispatch){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const recipient=yield(0,getSdk_1.default)(config).gift_card_recipients.create(values);dispatch({type:"setGiftCardRecipient",payload:{giftCardRecipient:recipient}})}catch(error){console.error(error)}})}exports.addGiftCardRecipient=addGiftCardRecipient;const addGiftCardLoading=(loading,dispatch)=>{dispatch({type:"setGiftCardLoading",payload:{loading}})};exports.addGiftCardLoading=addGiftCardLoading;function addGiftCard(values,{config,dispatch,getOrder,createOrder,order}){var _a,_b;return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const sdk=(0,getSdk_1.default)(config);(0,exports.addGiftCardLoading)(!0,dispatch);const{firstName,lastName,email}=values,val=tslib_1.__rest(values,["firstName","lastName","email"]),giftCardValue=Object.assign({recipient_email:email},val),giftCard=yield sdk.gift_cards.create(giftCardValue,{include:["gift_card_recipient"]}),recipientValues={id:(_b=(_a=giftCard.gift_card_recipient)===null||_a===void 0?void 0:_a.id)!==null&&_b!==void 0?_b:""};if(firstName&&(recipientValues.first_name=firstName),lastName&&(recipientValues.last_name=lastName),(0,isEmpty_1.default)(recipientValues)||(yield sdk.gift_card_recipients.update(recipientValues)),createOrder&&getOrder){const id=order?order.id:yield createOrder({});if(id){const order2=sdk.orders.relationship(id),item=sdk.gift_cards.relationship(giftCard.id);yield sdk.line_items.create({quantity:1,order:order2,item}),yield getOrder(id)}}dispatch({type:"setGiftCardRecipient",payload:Object.assign({},giftCardValue)}),(0,exports.addGiftCardLoading)(!1,dispatch)}catch(error){const errors=(0,getErrors_1.default)({error,resource:"gift_cards"});dispatch({type:"setGiftCardErrors",payload:{errors}}),(0,exports.addGiftCardLoading)(!1,dispatch)}})}exports.addGiftCard=addGiftCard;const addGiftCardError=(errors,dispatch)=>{dispatch({type:"setGiftCardErrors",payload:{errors}})};exports.addGiftCardError=addGiftCardError;const type=["setAvailability","setGiftCardRecipient","setGiftCardErrors","setGiftCardLoading"],giftCardReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=giftCardReducer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.orderInitialState=exports.removeGiftCardOrCouponCode=exports.setGiftCardOrCouponCode=exports.saveAddressToCustomerAddressBook=exports.setOrderErrors=exports.unsetOrderState=exports.addToCart=exports.addResourceToInclude=exports.setOrder=exports.updateOrder=exports.getApiOrder=exports.createOrder=void 0;const tslib_1=require("tslib"),localStorage_1=require("../utils/localStorage"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importStar(require("../utils/getErrors")),organization_1=tslib_1.__importDefault(require("../utils/organization")),actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];function createOrder(params){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=(0,getSdk_1.default)(config);try{const o=yield sdk?.orders.create(Object.assign({metadata},orderAttributes));return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=(0,getErrors_1.default)({error,resource:"orders"});console.error("Create order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""})}exports.createOrder=createOrder;const getApiOrder=params=>tslib_1.__awaiter(void 0,void 0,void 0,function*(){const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=(0,getSdk_1.default)(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=yield 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=(0,getErrors_1.default)({error,resource:"orders"});console.error("Retrieve order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch});return}});exports.getApiOrder=getApiOrder;function updateOrder({id,attributes,dispatch,config,include,state}){return tslib_1.__awaiter(this,void 0,void 0,function*(){const sdk=(0,getSdk_1.default)(config);try{const resource=Object.assign(Object.assign({},attributes),{id});yield sdk.orders.update(resource,{include});const order=yield(0,exports.getApiOrder)({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0,order}}catch(error){const errors=(0,getErrors_1.default)({error,resource:"orders"});return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}})}exports.updateOrder=updateOrder;const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};exports.setOrder=setOrder;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=Object.assign(Object.assign({},payload.includeLoaded),{[resource]:!0});payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded=Object.assign(Object.assign(Object.assign({},resourceIncludedLoaded),newResourceLoaded),payload.includeLoaded&&payload.includeLoaded);payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:Object.assign(Object.assign({},payload),{withoutIncludes:!1})})}exports.addResourceToInclude=addResourceToInclude;function addToCart(params){var _a,_b,_c,_d;return tslib_1.__awaiter(this,void 0,void 0,function*(){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=(0,getSdk_1.default)(config),id=yield 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(!((_a=state?.order)===null||_a===void 0)&&_a.line_items)yield Promise.all((_b=state?.order)===null||_b===void 0?void 0:_b.line_items.map(lineItem2=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield sdk.line_items.delete(lineItem2.id)})));else{const{line_items:lineItems}=yield sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&(yield Promise.all(lineItems.map(lineItem2=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield 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=yield 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};yield sdk.line_item_options.create(lineItemOptionsAttributes),yield(0,exports.getApiOrder)(Object.assign({id},params))}else yield(0,exports.getApiOrder)(Object.assign(Object.assign({id},params),{state}));if(!(0,isEmpty_1.default)(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=(0,organization_1.default)((_c=config.endpoint)!==null&&_c!==void 0?_c:""),params2=`${id}?accessToken=${(_d=config.accessToken)!==null&&_d!==void 0?_d:""}`,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=(0,getErrors_1.default)({error,resource:"orders"});return console.error("Add to cart",errors2),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}})}exports.addToCart=addToCart;const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};exports.unsetOrderState=unsetOrderState;function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}exports.setOrderErrors=setOrderErrors;const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;(0,localStorage_1.setCustomerOrderParam)(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})};exports.saveAddressToCustomerAddressBook=saveAddressToCustomerAddressBook;function setGiftCardOrCouponCode({code,codeType,dispatch,config,order,include,state}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,order:currentOrder,error}=yield 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=(0,getErrors_1.default)({error,resource:"orders",field:codeType});return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}})}exports.setGiftCardOrCouponCode=setGiftCardOrCouponCode;function removeGiftCardOrCouponCode({codeType,dispatch,config,order,include,state}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{if(config&&order&&dispatch){const attributes={[codeType]:""},orderUpdated=yield 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=(0,getErrors_1.default)({error,resource:"orders",field:codeType});return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}})}exports.removeGiftCardOrCouponCode=removeGiftCardOrCouponCode,exports.orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,actionType);exports.default=orderReducer;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.orderInitialState=exports.removeGiftCardOrCouponCode=exports.setGiftCardOrCouponCode=exports.saveAddressToCustomerAddressBook=exports.setOrderErrors=exports.unsetOrderState=exports.addToCart=exports.addResourceToInclude=exports.setOrder=exports.updateOrder=exports.getApiOrder=exports.createOrder=void 0;const tslib_1=require("tslib"),localStorage_1=require("../utils/localStorage"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importStar(require("../utils/getErrors")),organization_1=tslib_1.__importDefault(require("../utils/organization")),actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];function createOrder(params){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=config!=null?(0,getSdk_1.default)(config):void 0;try{if(sdk==null)return"";const o=yield sdk?.orders.create(Object.assign({metadata},orderAttributes));return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=(0,getErrors_1.default)({error,resource:"orders"});console.error("Create order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""})}exports.createOrder=createOrder;const getApiOrder=params=>tslib_1.__awaiter(void 0,void 0,void 0,function*(){const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=config!=null?(0,getSdk_1.default)(config):void 0;try{if(sdk==null)return;const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=yield 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=(0,getErrors_1.default)({error,resource:"orders"});console.error("Retrieve order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch});return}});exports.getApiOrder=getApiOrder;function updateOrder({id,attributes,dispatch,config,include,state}){return tslib_1.__awaiter(this,void 0,void 0,function*(){const sdk=config!=null?(0,getSdk_1.default)(config):void 0;try{if(sdk==null)return{success:!1};const resource=Object.assign(Object.assign({},attributes),{id});yield sdk.orders.update(resource,{include});const order=yield(0,exports.getApiOrder)({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0,order}}catch(error){const errors=(0,getErrors_1.default)({error,resource:"orders"});return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}})}exports.updateOrder=updateOrder;const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};exports.setOrder=setOrder;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=Object.assign(Object.assign({},payload.includeLoaded),{[resource]:!0});payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded=Object.assign(Object.assign(Object.assign({},resourceIncludedLoaded),newResourceLoaded),payload.includeLoaded&&payload.includeLoaded);payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:Object.assign(Object.assign({},payload),{withoutIncludes:!1})})}exports.addResourceToInclude=addResourceToInclude;function addToCart(params){var _a,_b,_c,_d;return tslib_1.__awaiter(this,void 0,void 0,function*(){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=(0,getSdk_1.default)(config),id=yield 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(!((_a=state?.order)===null||_a===void 0)&&_a.line_items)yield Promise.all((_b=state?.order)===null||_b===void 0?void 0:_b.line_items.map(lineItem2=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield sdk.line_items.delete(lineItem2.id)})));else{const{line_items:lineItems}=yield sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&(yield Promise.all(lineItems.map(lineItem2=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield 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=yield 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};yield sdk.line_item_options.create(lineItemOptionsAttributes),yield(0,exports.getApiOrder)(Object.assign({id},params))}else yield(0,exports.getApiOrder)(Object.assign(Object.assign({id},params),{state}));if(!(0,isEmpty_1.default)(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=(0,organization_1.default)((_c=config.endpoint)!==null&&_c!==void 0?_c:""),params2=`${id}?accessToken=${(_d=config.accessToken)!==null&&_d!==void 0?_d:""}`,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=(0,getErrors_1.default)({error,resource:"orders"});return console.error("Add to cart",errors2),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}})}exports.addToCart=addToCart;const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};exports.unsetOrderState=unsetOrderState;function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}exports.setOrderErrors=setOrderErrors;const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;(0,localStorage_1.setCustomerOrderParam)(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})};exports.saveAddressToCustomerAddressBook=saveAddressToCustomerAddressBook;function setGiftCardOrCouponCode({code,codeType,dispatch,config,order,include,state}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,order:currentOrder,error}=yield 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=(0,getErrors_1.default)({error,resource:"orders",field:codeType});return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}})}exports.setGiftCardOrCouponCode=setGiftCardOrCouponCode;function removeGiftCardOrCouponCode({codeType,dispatch,config,order,include,state}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{if(config&&order&&dispatch){const attributes={[codeType]:""},orderUpdated=yield 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=(0,getErrors_1.default)({error,resource:"orders",field:codeType});return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}})}exports.removeGiftCardOrCouponCode=removeGiftCardOrCouponCode,exports.orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,actionType);exports.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
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCustomerIdByToken=void 0;const
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCustomerIdByToken=void 0;const jwt_1=require("./jwt");function getCustomerIdByToken(accessToken){var _a,_b;return(_b=(_a=(0,jwt_1.jwt)(accessToken))===null||_a===void 0?void 0:_a.owner)===null||_b===void 0?void 0:_b.id}exports.getCustomerIdByToken=getCustomerIdByToken;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDomain=void 0;function getDomain(endpoint){const url=new URL(endpoint),[slug]=url.hostname.split(".");return{domain:url.hostname.replace(`${slug??""}.`,""),slug}}exports.getDomain=getDomain;
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDomain=void 0;function getDomain(endpoint){const url=new URL(endpoint),[slug]=url.hostname.split(".");return{domain:url.hostname.replace(`${slug??""}.`,""),slug:slug??""}}exports.getDomain=getDomain;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPricesComponent=exports.getPriceByCode=void 0;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),lodash_1=require("lodash"),PriceTemplate_1=tslib_1.__importDefault(require("../components/utils/PriceTemplate"));function getPriceByCode(skuPrices,code=""){return code?(0,lodash_1.first)(skuPrices.filter(p=>p.currency_code===code)):(0,lodash_1.first)(skuPrices)}exports.getPriceByCode=getPriceByCode;function getPricesComponent(skuPrices,props){return(0,lodash_1.isEmpty)(skuPrices)?(0,jsx_runtime_1.jsx)(PriceTemplate_1.default,Object.assign({},props)):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return(0,react_1.createElement)(PriceTemplate_1.default,Object.assign({},props,{key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code}))})}exports.getPricesComponent=getPricesComponent;function getPrices(prices){const obj={};return(0,lodash_1.isArray)(prices)&&prices.forEach(p=>{const sku=p
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPricesComponent=exports.getPriceByCode=void 0;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),lodash_1=require("lodash"),PriceTemplate_1=tslib_1.__importDefault(require("../components/utils/PriceTemplate"));function getPriceByCode(skuPrices,code=""){return code?(0,lodash_1.first)(skuPrices.filter(p=>p.currency_code===code)):(0,lodash_1.first)(skuPrices)}exports.getPriceByCode=getPriceByCode;function getPricesComponent(skuPrices,props){return(0,lodash_1.isEmpty)(skuPrices)?(0,jsx_runtime_1.jsx)(PriceTemplate_1.default,Object.assign({},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(0,react_1.createElement)(PriceTemplate_1.default,Object.assign({},props,{key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code}))})}exports.getPricesComponent=getPricesComponent;function getPrices(prices){const obj={};return(0,lodash_1.isArray)(prices)&&prices.forEach(p=>{var _a;const sku=(_a=p?.sku_code)!==null&&_a!==void 0?_a:"";(0,lodash_1.has)(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}exports.default=getPrices;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isGuestToken=void 0;const
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isGuestToken=void 0;const jwt_1=require("./jwt");function isGuestToken(accessToken){return(0,jwt_1.jwt)(accessToken).owner==null}exports.isGuestToken=isGuestToken;
|
package/lib/cjs/utils/jwt.d.ts
CHANGED
package/lib/cjs/utils/jwt.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.jwt=void 0;const jwt_decode_1=require("jwt-decode");function jwt(accessToken){return(0,jwt_decode_1.jwtDecode)(accessToken)}exports.jwt=jwt;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type BaseInputComponentProps } from '../typings/index';
|
|
3
2
|
type Props = BaseInputComponentProps & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
|
|
4
3
|
export declare function MetadataInput(props: Props): JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import AddressChildrenContext from"../../context/AddressChildrenContext";import CustomerContext from"../../context/CustomerContext";import BillingAddressContext from"../../context/BillingAddressContext";import ShippingAddressContext from"../../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../../context/AddressContext";import OrderContext from"../../context/OrderContext";import AddressCardsTemplate from"../utils/AddressCardsTemplate";export function Address(props){const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1,...p}=props,{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.forEach((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>(setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")))()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order?.shipping_country_code_lock,components=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className||""} ${deselect?"":selectedClassName}`:className,customerAddressId=address?.reference||"",finalClassName=disabled?`${className||""} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,{value:addressProps,children:_jsx("div",{className:finalClassName,onClick:()=>{handleSelect(k,address.id,customerAddressId,disabled,address)},"data-disabled":disabled,...p,children})},k)}),parentProps={customerAddresses:items,selected,handleSelect,countryLock,...props};return typeof children=="function"?_jsx(AddressCardsTemplate,{...parentProps,children}):_jsx(_Fragment,{children:components})}export default Address;
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import AddressChildrenContext from"../../context/AddressChildrenContext";import CustomerContext from"../../context/CustomerContext";import BillingAddressContext from"../../context/BillingAddressContext";import ShippingAddressContext from"../../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../../context/AddressContext";import OrderContext from"../../context/OrderContext";import AddressCardsTemplate from"../utils/AddressCardsTemplate";export function Address(props){const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1,...p}=props,{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.forEach((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&address.reference!=null&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&address.reference!=null&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>(setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")))()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order?.shipping_country_code_lock,components=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className||""} ${deselect?"":selectedClassName}`:className,customerAddressId=address?.reference||"",finalClassName=disabled?`${className||""} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,{value:addressProps,children:_jsx("div",{className:finalClassName,onClick:()=>{handleSelect(k,address.id,customerAddressId,disabled,address)},"data-disabled":disabled,...p,children})},k)}),parentProps={customerAddresses:items,selected,handleSelect,countryLock,...props};return typeof children=="function"?_jsx(AddressCardsTemplate,{...parentProps,children}):_jsx(_Fragment,{children:components})}export default Address;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import ErrorBoundary from"../utils/ErrorBoundary";import
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import ErrorBoundary from"../utils/ErrorBoundary";import{jwt}from"../../utils/jwt";export function CommerceLayer(props){const{children,...p}=props;if(!p.endpoint){const{organization}=jwt(p.accessToken);p.endpoint=`https://${organization.slug}.${p.domain??"commercelayer.io"}`}return _jsx(ErrorBoundary,{children:_jsx(CommerceLayerContext.Provider,{value:{...p},children})})}export default CommerceLayer;
|
|
@@ -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['Customer']>;
|