@commercelayer/react-components 3.14.1 → 3.15.0-beta.10
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/components/AddToCartButton.js +1 -1
- package/lib/components/Address.js +1 -1
- package/lib/components/AddressCountrySelector.js +1 -1
- package/lib/components/AddressField.js +1 -1
- package/lib/components/AddressInput.js +1 -1
- package/lib/components/AddressStateSelector.js +1 -1
- package/lib/components/AddressesContainer.js +1 -1
- package/lib/components/AdjustmentAmount.js +1 -1
- package/lib/components/AdyenPayment.d.ts +34 -4
- package/lib/components/AdyenPayment.js +1 -1
- package/lib/components/AvailabilityContainer.js +1 -1
- package/lib/components/AvailabilityTemplate.js +1 -1
- package/lib/components/BillingAddressContainer.js +1 -1
- package/lib/components/BillingAddressForm.js +1 -1
- package/lib/components/BraintreePayment.js +1 -1
- package/lib/components/CartLink.js +1 -1
- package/lib/components/CheckoutComPayment.js +1 -1
- package/lib/components/CheckoutLink.js +1 -1
- package/lib/components/CommerceLayer.js +1 -1
- package/lib/components/CustomerContainer.js +1 -1
- package/lib/components/CustomerInput.js +1 -1
- package/lib/components/DeliveryLeadTime.js +1 -1
- package/lib/components/DiscountAmount.js +1 -1
- package/lib/components/Errors.js +1 -1
- package/lib/components/ExternalFunction.js +1 -1
- package/lib/components/GiftCard.js +1 -1
- package/lib/components/GiftCardAmount.js +1 -1
- package/lib/components/GiftCardContainer.js +1 -1
- package/lib/components/GiftCardCurrencySelector.js +1 -1
- package/lib/components/GiftCardInput.js +1 -1
- package/lib/components/GiftCardOrCouponCode.js +1 -1
- package/lib/components/GiftCardOrCouponForm.js +1 -1
- package/lib/components/GiftCardOrCouponInput.js +1 -1
- package/lib/components/GiftCardOrCouponRemoveButton.js +1 -1
- package/lib/components/GiftCardOrCouponSubmit.js +1 -1
- package/lib/components/ItemContainer.js +1 -1
- package/lib/components/KlarnaPayment.js +1 -1
- package/lib/components/LineItem.js +1 -1
- package/lib/components/LineItemAmount.js +1 -1
- package/lib/components/LineItemCode.js +1 -1
- package/lib/components/LineItemImage.js +1 -1
- package/lib/components/LineItemName.js +1 -1
- package/lib/components/LineItemOption.js +1 -1
- package/lib/components/LineItemOptions.js +1 -1
- package/lib/components/LineItemQuantity.js +1 -1
- package/lib/components/LineItemRemoveLink.js +1 -1
- package/lib/components/LineItemsContainer.js +1 -1
- package/lib/components/LineItemsCount.js +1 -1
- package/lib/components/LineItemsEmpty.js +1 -1
- package/lib/components/MetadataInput.js +1 -1
- package/lib/components/OrderContainer.js +1 -1
- package/lib/components/OrderNumber.js +1 -1
- package/lib/components/OrderStorage.js +1 -1
- package/lib/components/PaymentGateway.js +1 -1
- package/lib/components/PaymentMethod.d.ts +1 -0
- package/lib/components/PaymentMethod.js +1 -1
- package/lib/components/PaymentMethodAmount.js +1 -1
- package/lib/components/PaymentMethodName.js +1 -1
- package/lib/components/PaymentMethodPrice.js +1 -1
- package/lib/components/PaymentMethodRadioButton.js +1 -1
- package/lib/components/PaymentMethodsContainer.js +1 -1
- package/lib/components/PaymentSource.js +1 -1
- package/lib/components/PaymentSourceBrandIcon.js +1 -1
- package/lib/components/PaymentSourceBrandName.js +1 -1
- package/lib/components/PaymentSourceDetail.js +1 -1
- package/lib/components/PaymentSourceEditButton.js +1 -1
- package/lib/components/PaypalPayment.js +1 -1
- package/lib/components/PlaceOrderButton.js +1 -1
- package/lib/components/PlaceOrderContainer.js +1 -1
- package/lib/components/Price.js +1 -1
- package/lib/components/PricesContainer.js +1 -1
- package/lib/components/PrivacyAndTermsCheckbox.js +1 -1
- package/lib/components/QuantitySelector.js +1 -1
- package/lib/components/SaveAddressesButton.js +1 -1
- package/lib/components/SaveCustomerButton.js +1 -1
- package/lib/components/Shipment.js +1 -1
- package/lib/components/ShipmentField.js +1 -1
- package/lib/components/ShipmentsContainer.js +1 -1
- package/lib/components/ShippingAddressContainer.js +1 -1
- package/lib/components/ShippingAddressForm.js +1 -1
- package/lib/components/ShippingAmount.js +1 -1
- package/lib/components/ShippingMethod.js +1 -1
- package/lib/components/ShippingMethodName.js +1 -1
- package/lib/components/ShippingMethodPrice.js +1 -1
- package/lib/components/ShippingMethodRadioButton.js +1 -1
- package/lib/components/SkuField.js +1 -1
- package/lib/components/SkuListsContainer.js +1 -1
- package/lib/components/SkuOption.js +1 -1
- package/lib/components/SkuOptionInput.js +1 -1
- package/lib/components/SkuOptionsContainer.js +1 -1
- package/lib/components/Skus.js +1 -1
- package/lib/components/SkusContainer.js +1 -1
- package/lib/components/StockTransfer.js +1 -1
- package/lib/components/StockTransferField.js +1 -1
- package/lib/components/StripePayment.js +1 -1
- package/lib/components/SubTotalAmount.js +1 -1
- package/lib/components/SubmitButton.js +1 -1
- package/lib/components/TaxesAmount.js +1 -1
- package/lib/components/TotalAmount.js +1 -1
- package/lib/components/VariantSelector.js +1 -1
- package/lib/components/VariantsContainer.js +1 -1
- package/lib/components/WireTransferPayment.d.ts +3 -1
- package/lib/components/WireTransferPayment.js +1 -1
- package/lib/components/gateways/AdyenGateway.js +1 -1
- package/lib/components/gateways/BraintreeGateway.js +1 -1
- package/lib/components/gateways/CheckoutComGateway.js +1 -1
- package/lib/components/gateways/KlarnaGateway.js +1 -1
- package/lib/components/gateways/PaypalGateway.js +1 -1
- package/lib/components/gateways/StripeGateway.js +1 -1
- package/lib/components/gateways/WireTransferGateway.js +1 -1
- package/lib/components/utils/AddressCardsTemplate.js +1 -1
- package/lib/components/utils/BaseField.js +1 -1
- package/lib/components/utils/BaseInput.js +1 -1
- package/lib/components/utils/BaseOrderPrice.js +1 -1
- package/lib/components/utils/BaseSelect.js +1 -1
- package/lib/components/utils/GenericFieldComponent.js +1 -1
- package/lib/components/utils/Parent.js +1 -1
- package/lib/components/utils/PaymentCardsTemplate.js +1 -1
- package/lib/components/utils/PriceTemplate.js +1 -1
- package/lib/components/utils/VariantTemplate.js +1 -1
- package/lib/components/utils/getAllErrors.js +1 -1
- package/lib/config/components.js +1 -1
- package/lib/context/BillingAddressFormContext.d.ts +2 -2
- package/lib/context/CouponAndGiftCardFormContext.d.ts +2 -2
- package/lib/context/PlaceOrderContext.d.ts +2 -1
- package/lib/reducers/AddressReducer.js +1 -1
- package/lib/reducers/AvailabilityReducer.js +1 -1
- package/lib/reducers/BillingAddressReducer.js +1 -1
- package/lib/reducers/CustomerReducer.js +1 -1
- package/lib/reducers/GiftCardReducer.js +1 -1
- package/lib/reducers/LineItemReducer.js +1 -1
- package/lib/reducers/OrderReducer.d.ts +3 -2
- package/lib/reducers/OrderReducer.js +1 -1
- package/lib/reducers/PaymentMethodReducer.d.ts +1 -0
- package/lib/reducers/PaymentMethodReducer.js +1 -1
- package/lib/reducers/PlaceOrderReducer.d.ts +7 -4
- package/lib/reducers/PlaceOrderReducer.js +1 -1
- package/lib/reducers/PriceReducer.js +1 -1
- package/lib/reducers/ShippingAddressReducer.js +1 -1
- package/lib/reducers/SkuReducer.js +1 -1
- package/lib/reducers/VariantReducer.js +1 -1
- package/lib/typings/index.js +1 -1
- package/lib/utils/addressesManager.js +1 -1
- package/lib/utils/baseReducer.js +1 -1
- package/lib/utils/checkIncludeResource.js +1 -1
- package/lib/utils/childrenTypes.js +1 -1
- package/lib/utils/getCardDetails.js +1 -1
- package/lib/utils/getErrors.js +1 -1
- package/lib/utils/getLineItemsCount.js +1 -1
- package/lib/utils/getPrices.js +1 -1
- package/lib/utils/getSdk.js +1 -1
- package/lib/utils/getSkus.js +1 -1
- package/lib/utils/promisify.js +1 -1
- package/lib/utils/shipments.js +1 -1
- package/lib/utils/validateFormFields.js +1 -1
- package/package.json +43 -43
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { OrderCodeType } from '../reducers/OrderReducer';
|
|
2
|
-
import { RefObject } from 'react';
|
|
3
3
|
declare type DefaultContext = {
|
|
4
|
-
validation?:
|
|
4
|
+
validation?: void;
|
|
5
5
|
setValue?: (name: string, value: string) => void;
|
|
6
6
|
codeType?: OrderCodeType;
|
|
7
7
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
2
|
import { PlaceOrderOptions, PlaceOrderState, SetPlaceOrderErrors } from '../reducers/PlaceOrderReducer';
|
|
3
3
|
import { PaymentSourceType } from '../reducers/PaymentMethodReducer';
|
|
4
4
|
declare type DefaultContext = {
|
|
@@ -10,6 +10,7 @@ declare type DefaultContext = {
|
|
|
10
10
|
placed: boolean;
|
|
11
11
|
}>;
|
|
12
12
|
placeOrderPermitted?: () => void;
|
|
13
|
+
setButtonRef?: (ref: RefObject<HTMLButtonElement>) => void;
|
|
13
14
|
} & PlaceOrderState;
|
|
14
15
|
export declare const defaultPlaceOrderContext: {
|
|
15
16
|
setPlaceOrderErrors: SetPlaceOrderErrors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";export const addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],addressInitialState={errors:[]},setAddressErrors=({errors,dispatch,currentErrors=[],resource})=>{const billingErrors=resource==="billing_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="billing_address"),shippingErrors=resource==="shipping_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="shipping_address"),finalErrors=[...billingErrors,...shippingErrors];dispatch&&dispatch({type:"setErrors",payload:{errors:finalErrors}})},setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})},setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${camelCase(resource)}Id`]:id}})},saveAddresses=async({config,updateOrder,order,state})=>{
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";export const addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],addressInitialState={errors:[]},setAddressErrors=({errors,dispatch,currentErrors=[],resource})=>{const billingErrors=resource==="billing_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="billing_address"),shippingErrors=resource==="shipping_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="shipping_address"),finalErrors=[...billingErrors,...shippingErrors];dispatch&&dispatch({type:"setErrors",payload:{errors:finalErrors}})},setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})},setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${camelCase(resource)}Id`]:id}})},saveAddresses=async({config,updateOrder,order,state})=>{const{shipToDifferentAddress,billing_address,shipping_address,billingAddressId,shippingAddressId}=state;try{const sdk=getSdk(config);if(order){const currentBillingAddressRef=order?.billing_address?.reference,orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=order?.billing_address?.id,orderAttributes._shipping_address_clone_id=order?.shipping_address?.id),!isEmpty(billing_address)&&billing_address){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._shipping_address_same_as_billing=!0;const address=await sdk.addresses.create(billing_address);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._shipping_address_same_as_billing,shippingAddressId&&(orderAttributes._shipping_address_clone_id=shippingAddressId),!isEmpty(shipping_address)&&shipping_address)){delete orderAttributes._shipping_address_clone_id;const address=await sdk.addresses.create(shipping_address);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}!isEmpty(orderAttributes)&&updateOrder&&await updateOrder({id:order.id,attributes:orderAttributes})}}catch(error){console.error(error)}};const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"],addressReducer=(state,reducer)=>baseReducer(state,reducer,type);export default addressReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const availabilityInitialState={quantity:null,min:{days:0,hours:0},max:{days:0,hours:0},errors:[]},getAvailability=async({skuCode,dispatch,config,setItem,item})=>{
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const availabilityInitialState={quantity:null,min:{days:0,hours:0},max:{days:0,hours:0},errors:[]},getAvailability=async({skuCode,dispatch,config,setItem,item})=>{const sdk=getSdk(config);try{const[sku]=await sdk.skus.list({fields:{skus:["id"]},filters:{code_in:skuCode}});if(sku){const skuInventory=await sdk.skus.retrieve(sku.id,{fields:{skus:["inventory"]}}),[level]=skuInventory.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];dispatch({type:"setAvailability",payload:{...delivery,quantity:skuInventory.inventory.quantity}}),setItem&&setItem({...item,[skuCode]:skuInventory})}}catch(error){console.error("Get SKU availability",error)}};export async function getAvailabilityByIds({skusIds,config,setItem}){const sdk=getSdk(config);try{const inventories=await Promise.all(skusIds.map(async id=>await sdk.skus.retrieve(id,{fields:{skus:["inventory","code"]}}))),item={};inventories.forEach(v=>{v?.code&&(item[v.code]=v)}),setItem&&setItem(item)}catch(error){console.error("Get SKU availability",error)}}const typeAction=["setAvailability","setErrors"],availabilityReducer=(state,reducer)=>baseReducer(state,reducer,typeAction);export default availabilityReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const billingAddressInitialState={_billing_address_clone_id:""},setBillingAddress=async(id,options)=>{try{if(options
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const billingAddressInitialState={_billing_address_clone_id:""},setBillingAddress=async(id,options)=>{try{if(options?.order){if(options.customerAddressId){const sdk=getSdk(options.config),attributes={id,reference:options.customerAddressId};await sdk.addresses.update(attributes)}options.dispatch({type:"setBillingAddress",payload:{_billing_address_clone_id:id}})}}catch(error){console.error("Set billing address",error)}},setBillingCustomerAddressId=async({dispatch,order,setCloneAddress})=>{const customerAddressId=order?.billing_address?.reference;try{customerAddressId&&(dispatch({type:"setBillingCustomerAddressId",payload:{billingCustomerAddressId:customerAddressId}}),setCloneAddress(customerAddressId,"billing_address"))}catch(error){console.error("error",error)}};const type=["setBillingAddress","setBillingCustomerAddressId","cleanup"],billingAddressReducer=(state,reducer)=>baseReducer(state,reducer,type);export default billingAddressReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const saveCustomerUser=async({customerEmail,order,updateOrder})=>{if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}},setCustomerErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},setCustomerEmail=(customerEmail,dispatch)=>{dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})},getCustomerAddresses=async({config,dispatch})=>{try{const addresses=[];(await getSdk(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=getErrors(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}},getCustomerPaymentSources=async({dispatch,order})=>{
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const saveCustomerUser=async({customerEmail,order,updateOrder})=>{if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}},setCustomerErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},setCustomerEmail=(customerEmail,dispatch)=>{dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})},getCustomerAddresses=async({config,dispatch})=>{try{const addresses=[];(await getSdk(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=getErrors(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}},getCustomerPaymentSources=async({dispatch,order})=>{order?.available_customer_payment_sources&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})},customerInitialState={errors:[],addresses:[],payments:[]};const type=["setErrors","setCustomerEmail","setAddresses","setPayments"],customerReducer=(state,reducer)=>baseReducer(state,reducer,type);export default customerReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import{isEmpty}from"lodash";import getErrors from"../utils/getErrors";import getSdk from"../utils/getSdk";export const giftCardInitialState={currencyCode:"",balanceCent:0,singleUse:!1,rechargeable:!0,loading:!1,expiresAt:null,errors:[]},addGiftCardRecipient=async(values,config,dispatch)=>{try{const recipient=await getSdk(config).gift_card_recipients.create(values);dispatch({type:"setGiftCardRecipient",payload:{giftCardRecipient:recipient}})}catch(error){console.error(error)}},addGiftCardLoading=(loading,dispatch)=>{dispatch({type:"setGiftCardLoading",payload:{loading}})},addGiftCard=async(values,{config,dispatch,getOrder,createOrder,order})=>{try{const sdk=getSdk(config);addGiftCardLoading(!0,dispatch);const{firstName,lastName,email,...val}=values,giftCardValue={recipient_email:email,...val},giftCard=await sdk.gift_cards.create(giftCardValue,{include:["gift_card_recipient"]}),recipientValues={id:giftCard.gift_card_recipient?.id};if(firstName&&(recipientValues.first_name=firstName),lastName&&(recipientValues.last_name=lastName),isEmpty(recipientValues)||await sdk.gift_card_recipients.update(recipientValues),createOrder&&getOrder){const id=order?order.id:await createOrder();if(id){const order2=sdk.orders.relationship(id),item=sdk.gift_cards.relationship(giftCard.id);await sdk.line_items.create({quantity:1,order:order2,item}),getOrder&&await getOrder(id)}}dispatch({type:"setGiftCardRecipient",payload:{...giftCardValue}}),addGiftCardLoading(!1,dispatch)}catch(error){const errors=getErrors(error,"gift_cards");dispatch({type:"setGiftCardErrors",payload:{errors}}),addGiftCardLoading(!1,dispatch)}},addGiftCardError=(errors,dispatch)=>{dispatch({type:"setGiftCardErrors",payload:{errors}})};const type=["setAvailability","setGiftCardRecipient","setGiftCardErrors","setGiftCardLoading"],giftCardReducer=(state,reducer)=>baseReducer(state,reducer,type);export default giftCardReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const getLineItems=params=>{const{order,dispatch,config}=params,sdk=getSdk(config);let allLineItems=[];order&&sdk.orders.retrieve(order
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const getLineItems=params=>{const{order,dispatch,config}=params,sdk=getSdk(config);let allLineItems=[];order&&sdk.orders.retrieve(order?.id,{include:["line_items","line_items.line_item_options.sku_option"],fields:{orders:["line_items"]}}).then(response=>{dispatch({type:"setLoading",payload:{loading:!1}});const items=response.line_items||[];allLineItems=[...allLineItems,...items],dispatch({type:"setLineItems",payload:{lineItems:allLineItems}})}).catch(error=>{const errors=getErrors(error,"line_items");dispatch({type:"setErrors",payload:{errors}})})},updateLineItem=async params=>{const{config,lineItemId,quantity,getOrder,orderId,dispatch}=params,sdk=getSdk(config);try{await sdk.line_items.update({id:lineItemId,quantity}),getOrder&&await getOrder(orderId),dispatch({type:"setErrors",payload:{errors:[]}})}catch(error){const errors=getErrors(error,"line_items");dispatch({type:"setErrors",payload:{errors}})}},deleteLineItem=async params=>{const{config,lineItemId,getOrder,orderId,dispatch}=params,sdk=getSdk(config);try{await sdk.line_items.delete(lineItemId),getOrder&&await getOrder(orderId),dispatch({type:"setErrors",payload:{errors:[]}})}catch(error){const errors=getErrors(error,"line_items");dispatch({type:"setErrors",payload:{errors}})}},lineItemInitialState={loading:!1,lineItems:[],errors:[]};const actionType=["setLineItems","setErrors","setLoading"],lineItemReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default lineItemReducer;
|
|
@@ -63,8 +63,9 @@ export interface OrderPayload {
|
|
|
63
63
|
orderId?: string;
|
|
64
64
|
order?: Order;
|
|
65
65
|
errors?: BaseError[];
|
|
66
|
-
include?: ResourceIncluded[];
|
|
66
|
+
include?: ResourceIncluded[] | undefined;
|
|
67
67
|
includeLoaded?: ResourceIncludedLoaded;
|
|
68
|
+
withoutIncludes?: boolean;
|
|
68
69
|
}
|
|
69
70
|
export declare type AddToCartValues = Pick<AddToCartParams, 'bundleCode' | 'lineItem' | 'quantity' | 'skuCode' | 'skuId' | 'option' | 'buyNowMode' | 'checkoutUrl'>;
|
|
70
71
|
export declare type AddToCartImportValues = Pick<AddToCartImportParams, 'lineItems'>;
|
|
@@ -92,7 +93,7 @@ export declare function updateOrder({ id, attributes, dispatch, config, include,
|
|
|
92
93
|
success: boolean;
|
|
93
94
|
error: unknown;
|
|
94
95
|
}>;
|
|
95
|
-
export declare const setOrder: (order: Order, dispatch?: Dispatch<OrderActions>
|
|
96
|
+
export declare const setOrder: (order: Order, dispatch?: Dispatch<OrderActions>) => void;
|
|
96
97
|
export declare type AddResourceToInclude = {
|
|
97
98
|
resourcesIncluded?: ResourceIncluded[];
|
|
98
99
|
dispatch?: Dispatch<OrderActions>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import size from"lodash/size";import map from"lodash/map";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state
|
|
1
|
+
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import size from"lodash/size";import map from"lodash/map";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=getSdk(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=getErrors(error,"orders");console.error("Create order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""},getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=getSdk(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.status==="placed"||order.status==="approved"||order.status==="cancelled"?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=getErrors(error,"orders");console.error("Retrieve order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch});return}};export async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=getSdk(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await getApiOrder({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0}}catch(error){const errors=getErrors(error,"orders");return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}export const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};export function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...resourcesIncluded,...resources],resources.forEach(resource=>{payload.includeLoaded={...payload.includeLoaded,[resource]:!0}})}else delete payload.include;payload.includeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded},dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}export const addToCart=async params=>{const{skuCode,bundleCode,skuId,quantity,option,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl}=params;try{if(!config)throw{errors:[{code:"INVALID_RESOURCE",resource:"orders",title:"Markup error",message:"You are trying to place an order outside the OrderContainer component"}]};const sdk=getSdk(config),id=await createOrder(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});line_items&&line_items?.length>0&&await Promise.all(line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity||1,_update_quantity:!0,bundle_code:bundleCode};skuId&&(attrs.item=sdk.skus.relationship(skuId));const newLineItem=await sdk.line_items.create(attrs);if(isEmpty(option))await getApiOrder({id,...params,state});else{let c=0;map(option,async opt=>{const{options,skuOptionId}=opt,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),c+=1,c===size(option)&&await getApiOrder({id,...params})})}if(!isEmpty(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=getOrganizationSlug(config.endpoint),params2=`${id}?accessToken=${config.accessToken}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}return{success:!1,orderId:void 0}}catch(error){const errors2=getErrors(error,"orders");return console.error("Add to cart",errors2),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1,orderId:void 0}}},unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};export function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}export const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value}`;setCustomerOrderParam(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})},setGiftCardOrCouponCode=async({code,codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},removeGiftCardOrCouponCode=async({codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&dispatch){const attributes={[codeType]:""};return await updateOrder({id:order.id,attributes,config,include,dispatch,state}),dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default orderReducer;
|
|
@@ -11,6 +11,7 @@ import { Dispatch, MutableRefObject } from 'react';
|
|
|
11
11
|
import { CheckoutComConfig } from '../components/CheckoutComPayment';
|
|
12
12
|
export declare type PaymentSourceType = AdyenPayment | BraintreePayment | CheckoutComPayment | ExternalPayment | PaypalPayment | StripePayment | WireTransfer;
|
|
13
13
|
declare type Card = {
|
|
14
|
+
type: string;
|
|
14
15
|
brand: string;
|
|
15
16
|
last4: string;
|
|
16
17
|
exp_year: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getErrors,{setErrors}from"../utils/getErrors";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function setLoading({loading,dispatch}){dispatch&&dispatch({type:"setLoading",payload:{loading}})}export const setPaymentRef=({ref,dispatch})=>{ref&&dispatch&&dispatch({type:"setPaymentRef",payload:{currentPaymentMethodRef:ref}})},paymentMethodInitialState={errors:[]},setPaymentMethodErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},getPaymentMethods=async({order,dispatch})=>{const paymentMethods=order.available_payment_methods,paymentMethod=order.payment_method,paymentSource=order.payment_source;dispatch({type:"setPaymentMethods",payload:{paymentMethods,currentPaymentMethodId:paymentMethod
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getErrors,{setErrors}from"../utils/getErrors";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function setLoading({loading,dispatch}){dispatch&&dispatch({type:"setLoading",payload:{loading}})}export const setPaymentRef=({ref,dispatch})=>{ref&&dispatch&&dispatch({type:"setPaymentRef",payload:{currentPaymentMethodRef:ref}})},paymentMethodInitialState={errors:[]},setPaymentMethodErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},getPaymentMethods=async({order,dispatch})=>{const paymentMethods=order.available_payment_methods,paymentMethod=order.payment_method,paymentSource=order.payment_source;dispatch({type:"setPaymentMethods",payload:{paymentMethods,currentPaymentMethodId:paymentMethod?.id,currentPaymentMethodType:paymentMethod?.payment_source_type,paymentSource}})},setPaymentMethod=async({config,dispatch,order,paymentMethodId,updateOrder,setOrderErrors,paymentResource})=>{try{if(config&&order&&dispatch&&paymentResource){localStorage.removeItem("_save_payment_source_to_customer_wallet");const attributes={payment_method:getSdk(config).payment_methods.relationship(paymentMethodId)};updateOrder&&await updateOrder({id:order.id,attributes}),dispatch({type:"setPaymentMethods",payload:{currentPaymentMethodId:paymentMethodId,currentPaymentMethodType:paymentResource,errors:[]}}),setOrderErrors&&setOrderErrors([])}}catch(error){const errors=getErrors(error,"orders",paymentResource);console.error("Set payment method",errors)}},setPaymentSource=async({config,dispatch,getOrder,attributes={},order,paymentResource,customerPaymentSourceId,paymentSourceId,updateOrder,errors:currentErrors})=>{try{if(config&&order){let paymentSource;const sdk=getSdk(config);if(customerPaymentSourceId)updateOrder&&await updateOrder({id:order.id,attributes:{_customer_payment_source_id:customerPaymentSourceId}});else{if(paymentSourceId){const attrs={id:paymentSourceId,...attributes};paymentSource=await sdk[paymentResource].update(attrs)}else{const attrs={...attributes,order:sdk.orders.relationship(order.id)};paymentSource=await sdk[paymentResource].create(attrs)}return getOrder&&await getOrder(order.id),dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource,errors:[]}}),paymentSource}}}catch(error){const errors=getErrors(error,"payment_methods",paymentResource);console.error("Set payment source:",errors),dispatch&&setErrors({currentErrors,newErrors:errors,dispatch})}},updatePaymentSource=async({id,attributes,config,dispatch,paymentResource})=>{if(config)try{const paymentSource=await getSdk(config)[paymentResource].update({id,...attributes});dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource}})}catch(err){console.error("Update payment source:",err)}},destroyPaymentSource=async({paymentSourceId,paymentResource,dispatch})=>{paymentSourceId&&paymentResource&&dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},setPaymentMethodConfig=(config,dispatch)=>{dispatch({type:"setPaymentMethodConfig",payload:{config}})};export function getPaymentConfig(paymentResource,config){const resource=camelCase(paymentResource).replace("Payments","Payment").replace("Transfers","Transfer");return!isEmpty(config)&&has(config,resource)?config[resource]:void 0}const type=["setErrors","setPaymentMethodConfig","setPaymentMethods","setPaymentSource","setPaymentRef","setLoading"],paymentMethodReducer=(state,reducer)=>baseReducer(state,reducer,type);export default paymentMethodReducer;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { Dispatch } from 'react';
|
|
1
|
+
import { Dispatch, RefObject } from 'react';
|
|
2
2
|
import { BaseError } from '../typings/errors';
|
|
3
3
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
4
4
|
import { Order } from '@commercelayer/sdk';
|
|
5
5
|
import { PaymentResource } from './PaymentMethodReducer';
|
|
6
6
|
import { PaymentSourceType } from './PaymentMethodReducer';
|
|
7
|
-
export declare type PlaceOrderActionType = 'setErrors' | 'setPlaceOrderPermitted';
|
|
7
|
+
export declare type PlaceOrderActionType = 'setErrors' | 'setPlaceOrderPermitted' | 'setButtonRef';
|
|
8
8
|
export declare type PlaceOrderOptions = {
|
|
9
9
|
paypalPayerId?: string;
|
|
10
10
|
adyen?: {
|
|
11
|
-
MD
|
|
12
|
-
PaRes
|
|
11
|
+
MD?: string;
|
|
12
|
+
PaRes?: string;
|
|
13
|
+
redirectResult?: string;
|
|
13
14
|
};
|
|
14
15
|
checkoutCom?: {
|
|
15
16
|
session_id: string;
|
|
@@ -23,7 +24,9 @@ export interface PlaceOrderActionPayload {
|
|
|
23
24
|
paymentId: string;
|
|
24
25
|
paymentSource: PaymentSourceType;
|
|
25
26
|
options?: PlaceOrderOptions;
|
|
27
|
+
placeOrderButtonRef?: RefObject<HTMLButtonElement>;
|
|
26
28
|
}
|
|
29
|
+
export declare function setButtonRef(ref: RefObject<HTMLButtonElement>, dispatch: Dispatch<PlaceOrderAction>): void;
|
|
27
30
|
export declare type PlaceOrderState = Partial<PlaceOrderActionPayload>;
|
|
28
31
|
export interface PlaceOrderAction {
|
|
29
32
|
type: PlaceOrderActionType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{isDoNotShip,shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:!1},setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},placeOrderPermitted=async({config,order,dispatch,options})=>{
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{isDoNotShip,shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export function setButtonRef(ref,dispatch){ref!=null&&ref.current!=null&&dispatch({type:"setButtonRef",payload:{placeOrderButtonRef:ref}})}export const placeOrderInitialState={errors:[],isPermitted:!1},setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},placeOrderPermitted=async({config,order,dispatch,options})=>{if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address,shippingAddress=order.shipping_address,doNotShip=isDoNotShip(order.line_items),shipments=order.shipments,shipment=shipments&&shipmentsFilled(shipments),paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&isEmpty(paymentMethod?.id)&&(isPermitted=!1),isEmpty(billingAddress)&&(isPermitted=!1),isEmpty(shippingAddress)&&!doNotShip&&(isPermitted=!1),!isEmpty(shipments)&&!shipment&&(isPermitted=!1),paymentSource?.mismatched_amounts&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod?.payment_source_type,paymentSecret:paymentSource?.client_secret,paymentId:paymentSource?.options?.id,paymentSource,options}})}},setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource,setOrder,include})=>{const response={placed:!1};if(state&&config&&order){const sdk=getSdk(config),{options,paymentType}=state;try{if(paymentType==="paypal_payments"&&paymentSource){if(!options?.paypalPayerId&&paymentSource?.approval_url)return window.location.href=paymentSource?.approval_url,response;await sdk[paymentType].update({id:paymentSource.id,paypal_payer_id:options?.paypalPayerId})}if(paymentType==="checkout_com_payments"&&paymentSource&&options?.checkoutCom?.session_id){const payment=await sdk[paymentType].update({id:paymentSource.id,_details:!0,session_id:options?.checkoutCom?.session_id});if(payment?.payment_response?.status!=="Authorized"){const[action]=payment?.payment_response?.actions||[""];throw{errors:[{code:"PAYMENT_NOT_APPROVED_FOR_EXECUTION",message:action?.response_summary,resource:"orders",field:"checkout_com_payments"}]}}}const updateAttributes={id:order.id,_place:!0};switch(saveBillingAddress()&&await sdk.orders.update({id:order.id,_save_billing_address_to_customer_address_book:!0}),saveShippingAddress()&&await sdk.orders.update({id:order.id,_save_shipping_address_to_customer_address_book:!0}),paymentType){case"braintree_payments":{saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0});const orderUpdated=await sdk.orders.update(updateAttributes,{include});return setOrder&&setOrder(orderUpdated),setOrderErrors&&setOrderErrors([]),{placed:!0}}default:{const orderUpdated=await sdk.orders.update(updateAttributes,{include});return setOrder&&setOrder(orderUpdated),saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),setOrderErrors&&setOrderErrors([]),{placed:!0}}}}catch(error){const errors=getErrors(error,"orders",paymentType);return setOrderErrors&&setOrderErrors(errors),{...response,errors}}}return response};const type=["setErrors","setPlaceOrderPermitted","setButtonRef"],placeOrderReducer=(state,reducer)=>baseReducer(state,reducer,type);export default placeOrderReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import getPrices from"../utils/getPrices";import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const priceInitialState={loading:!0,prices:{},skuCodes:[],errors:[]},getSkusPrice=(skuCodes,{config,dispatch,setPrices,prices,perPage,filters})=>{let allPrices={};const sdk=getSdk(config);sdk.prices.list({filters:
|
|
1
|
+
import getPrices from"../utils/getPrices";import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const priceInitialState={loading:!0,prices:{},skuCodes:[],errors:[]},getSkusPrice=(skuCodes,{config,dispatch,setPrices,prices,perPage,filters})=>{let allPrices={};const sdk=getSdk(config);sdk.prices.list({filters:{sku_code_in:skuCodes.join(","),...filters},pageSize:perPage}).then(async response=>{const pricesObj=getPrices(response);allPrices={...allPrices,...prices,...pricesObj},setPrices&&setPrices(allPrices),dispatch({type:"setPrices",payload:{prices:allPrices}}),dispatch({type:"setLoading",payload:{loading:!1}});const meta=response.meta;if(meta.pageCount>1)for(let pageNumber=meta.currentPage+1;pageNumber<=meta.pageCount;pageNumber++){const pageResponse=await sdk.prices.list({filters:{sku_code_in:skuCodes.join(","),...filters},pageSize:perPage,pageNumber}),pricesObj2=getPrices(pageResponse);allPrices={...allPrices,...pricesObj2},setPrices&&setPrices(allPrices),dispatch({type:"setPrices",payload:{prices:allPrices}})}}).catch(error=>{const errors=getErrors(error,"prices");dispatch({type:"setErrors",payload:{errors}})})},unsetPriceState=dispatch=>{dispatch({type:"setPrices",payload:{prices:{}}}),dispatch({type:"setLoading",payload:{loading:!1}})};const typeAction=["setLoading","setPrices","setSkuCodes","setErrors"],priceReducer=(state,reducer)=>baseReducer(state,reducer,typeAction);export default priceReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const shippingAddressInitialState={_shipping_address_clone_id:""},setShippingAddress=async(id,options)=>{try{if(options
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const shippingAddressInitialState={_shipping_address_clone_id:""},setShippingAddress=async(id,options)=>{try{if(options?.order){if(options.customerAddressId){const sdk=getSdk(options.config),attributes={id,reference:options.customerAddressId};await sdk.addresses.update(attributes)}options.dispatch({type:"setShippingAddress",payload:{_shipping_address_clone_id:id}})}}catch(error){console.error(error)}},setShippingCustomerAddressId=async({dispatch,order,setCloneAddress})=>{const customerAddressId=order?.shipping_address?.reference;try{customerAddressId&&(dispatch({type:"setShippingCustomerAddressId",payload:{shippingCustomerAddressId:customerAddressId}}),setCloneAddress(customerAddressId,"shipping_address"))}catch(error){console.error("error",error)}};const type=["setShippingAddress","setShippingCustomerAddressId","cleanup"],shippingAddressReducer=(state,reducer)=>baseReducer(state,reducer,type);export default shippingAddressReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";const actionType=["getSkus"];export const skuInitialState={skus:[],loading:!0,skuCodes:[]};export async function getSku({config,skus,dispatch,queryParams}){if(!config.accessToken||skus.length===0)return;const sdk=getSdk(config);let allSkus=[];const get=await sdk.skus.list(
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";const actionType=["getSkus"];export const skuInitialState={skus:[],loading:!0,skuCodes:[]};export async function getSku({config,skus,dispatch,queryParams}){if(!config.accessToken||skus.length===0)return;const sdk=getSdk(config);let allSkus=[];const get=await sdk.skus.list({...queryParams,filters:{...queryParams?.filters,code_in:skus.join(",")}});allSkus=[...get];const meta=get.meta;if(meta.pageCount>1)for(let pageNumber=meta.currentPage+1;pageNumber<=meta.pageCount;pageNumber++){const getPage=await sdk.skus.list({...queryParams,filters:{...queryParams?.filters,code_in:skus.join(",")},pageNumber});allSkus=[...allSkus,...getPage]}dispatch({type:"getSkus",payload:{skus:allSkus,loading:!1,skuCodes:skus}})}export default function skuReducer(state,reducer){return baseReducer(state,reducer,actionType)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSkus from"../utils/getSkus";import{isEmpty,has}from"lodash";import getSdk from"../utils/getSdk";export const setVariantSkuCodes=({skuCodes,dispatch,setCustomLineItems})=>{const lineItems={},sCodes=skuCodes.map(s=>(has(s,"lineItem")&&(lineItems[s.code]=s.lineItem),s.code));isEmpty(lineItems)||setCustomLineItems&&setCustomLineItems(lineItems),dispatch({type:"setSkuCodes",payload:{skuCodes:sCodes}})},setSkuCode=params=>{const{id,code,config,setItem,dispatch,setItemSkuCode}=params;id&&getSdk(config).skus.retrieve(id,{include:["sku_options"]}).then(sku=>{setItem&&setItem({[`${code}`]:sku}),setItemSkuCode&&setItemSkuCode(code)}).catch(errors=>{dispatch({type:"setErrors",payload:{errors}})})},getVariants=params=>{const{config,state,skuCode,dispatch,setItem,filters}=params;getSdk(config).skus.list({filters:
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSkus from"../utils/getSkus";import{isEmpty,has}from"lodash";import getSdk from"../utils/getSdk";export const setVariantSkuCodes=({skuCodes,dispatch,setCustomLineItems})=>{const lineItems={},sCodes=skuCodes.map(s=>(has(s,"lineItem")&&(lineItems[s.code]=s.lineItem),s.code));isEmpty(lineItems)||setCustomLineItems&&setCustomLineItems(lineItems),dispatch({type:"setSkuCodes",payload:{skuCodes:sCodes}})},setSkuCode=params=>{const{id,code,config,setItem,dispatch,setItemSkuCode}=params;id&&getSdk(config).skus.retrieve(id,{include:["sku_options"]}).then(sku=>{setItem&&setItem({[`${code}`]:sku}),setItemSkuCode&&setItemSkuCode(code)}).catch(errors=>{dispatch({type:"setErrors",payload:{errors}})})},getVariants=params=>{const{config,state,skuCode,dispatch,setItem,filters}=params;getSdk(config).skus.list({filters:{code_in:state.skuCodes.join(","),...filters}}).then(skus=>{const skusObj=getSkus(skus,state.skuCodes);skuCode&&setSkuCode({code:skusObj[skuCode].code,id:skusObj[skuCode].id,config,dispatch,setItem}),dispatch({type:"setVariants",payload:{variants:skusObj}}),dispatch({type:"setLoading",payload:{loading:!1}})}).catch(errors=>{dispatch({type:"setErrors",payload:{errors}})})},unsetVariantState=dispatch=>{dispatch({type:"setSkuCode",payload:{skuCode:""}}),dispatch({type:"setVariants",payload:{variants:{}}}),dispatch({type:"setLoading",payload:{loading:!1}})},variantInitialState={loading:!1,variants:{},skuCodes:[],skuCode:"",errors:[],currentSkuId:"",currentSkuInventory:{available:!1,quantity:0,levels:[]},currentQuantity:1,currentPrices:[]};const actionType=["setLoading","setVariants","setSkuCodes","setSkuCode","setCurrentSkuId","setCurrentSkuInventory","setCurrentPrices","setErrors"],variantReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default variantReducer;
|
package/lib/typings/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import PropTypes from"prop-types";export const BC={id:PropTypes.string,className:PropTypes.string,style:PropTypes.object,name:PropTypes.string},PTLoader=PropTypes.oneOfType([PropTypes.element,PropTypes.string]),BaseSelectComponentPropTypes={children:PropTypes.func,options:PropTypes.arrayOf(PropTypes.shape({label:PropTypes.string.isRequired,value:PropTypes.oneOfType([PropTypes.string,PropTypes.number]).isRequired,selected:PropTypes.bool}).isRequired).isRequired,placeholder:PropTypes.shape({label:PropTypes.string.isRequired,value:PropTypes.oneOfType([PropTypes.string,PropTypes.number]).isRequired}),value:PropTypes.string,name:PropTypes.string.isRequired},BaseInputComponentPropTypes={children:PropTypes.func,name:PropTypes.string.isRequired,type:PropTypes.oneOf(["text","email","number","date","checkbox","textarea"]).isRequired,onChange:PropTypes.func,placeholder:PropTypes.string},BMObject=PropTypes.objectOf(PropTypes.string),baseOrderPricePropTypes=
|
|
1
|
+
import PropTypes from"prop-types";export const BC={id:PropTypes.string,className:PropTypes.string,style:PropTypes.object,name:PropTypes.string},PTLoader=PropTypes.oneOfType([PropTypes.element,PropTypes.string]),BaseSelectComponentPropTypes={children:PropTypes.func,options:PropTypes.arrayOf(PropTypes.shape({label:PropTypes.string.isRequired,value:PropTypes.oneOfType([PropTypes.string,PropTypes.number]).isRequired,selected:PropTypes.bool}).isRequired).isRequired,placeholder:PropTypes.shape({label:PropTypes.string.isRequired,value:PropTypes.oneOfType([PropTypes.string,PropTypes.number]).isRequired}),value:PropTypes.string,name:PropTypes.string.isRequired},BaseInputComponentPropTypes={children:PropTypes.func,name:PropTypes.string.isRequired,type:PropTypes.oneOf(["text","email","number","date","checkbox","textarea"]).isRequired,onChange:PropTypes.func,placeholder:PropTypes.string},BMObject=PropTypes.objectOf(PropTypes.string),baseOrderPricePropTypes={base:PropTypes.string.isRequired,type:PropTypes.string.isRequired,children:PropTypes.func,format:PropTypes.oneOf(["formatted","cents","float"]),...BC},baseOrderComponentPricePropTypes={children:baseOrderPricePropTypes.children,format:baseOrderPricePropTypes.format,...BC};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isEmpty}from"lodash";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export const billingAddressController=({billing_address,billingAddressId,errors,requiresBillingInfo})=>{let billingDisable=!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address)){let billingInfo=[...addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),billingDisable=!!(billing_address&&fieldsExist(billing_address,billingInfo))}return billingDisable&&!isEmpty(billingAddressId)&&isEmpty(billing_address)&&(billingDisable=!1),billingDisable},shippingAddressController=({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId})=>{let shippingDisable=!!(!billingDisable&&shipToDifferentAddress);return shippingDisable&&isEmpty(errors)&&!isEmpty(shipping_address)&&(shippingDisable=!!(shipping_address&&fieldsExist(shipping_address))),shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable},countryLockController=({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId})=>{if(countryCodeLock&&!isEmpty(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses
|
|
1
|
+
import{isEmpty}from"lodash";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export const billingAddressController=({billing_address,billingAddressId,errors,requiresBillingInfo})=>{let billingDisable=!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address)){let billingInfo=[...addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),billingDisable=!!(billing_address&&fieldsExist(billing_address,billingInfo))}return billingDisable&&!isEmpty(billingAddressId)&&isEmpty(billing_address)&&(billingDisable=!1),billingDisable},shippingAddressController=({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId})=>{let shippingDisable=!!(!billingDisable&&shipToDifferentAddress);return shippingDisable&&isEmpty(errors)&&!isEmpty(shipping_address)&&(shippingDisable=!!(shipping_address&&fieldsExist(shipping_address))),shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable},countryLockController=({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId})=>{if(countryCodeLock&&!isEmpty(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses?.find(a=>(a?.id===billingAddressId||a?.reference===billingAddressId)&&a?.country_code!==countryCodeLock);if(!isEmpty(addressLocked))return!0}if(countryCodeLock&&!isEmpty(billing_address)&&!shipToDifferentAddress)return billing_address?.country_code!==countryCodeLock;if(countryCodeLock&&!isEmpty(shipping_address)&&shipToDifferentAddress)return shipping_address?.country_code!==countryCodeLock;if(countryCodeLock&&!isEmpty(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses?.find(a=>(a?.id===shippingAddressId||a?.reference===shippingAddressId)&&a?.country_code!==countryCodeLock);if(!isEmpty(addressLocked))return!0}return!1};
|
package/lib/utils/baseReducer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const baseReducer=(state,action,actionTypes)=>{if(actionTypes.indexOf(action.type)!==-1){const data=action.payload;state=
|
|
1
|
+
const baseReducer=(state,action,actionTypes)=>{if(actionTypes.indexOf(action.type)!==-1){const data=action.payload;state={...state,...data}}return state};export default baseReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function checkIncludeResources({order,resourceInclude}){const checkKeys=[];return resourceInclude.forEach(v=>{if(v.includes(".")){const[first]=v.split(".");
|
|
1
|
+
export default function checkIncludeResources({order,resourceInclude}){const checkKeys=[];return resourceInclude.forEach(v=>{if(v.includes(".")){const[first]=v.split(".");order?.[first]===void 0&&checkKeys.push(!1)}else order?.[v]===void 0&&checkKeys.push(!1)}),checkKeys.length===0}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isValidElement,Children}from"react";import{isEmpty,isFunction,has,get}from"lodash";import components from"../config/components";const checkChildrenTypes=(props,propName,componentName)=>{let error=null;const children=props[propName],cpName=componentName.replace("CL","");return(isEmpty(children)&&typeof children!="function"||typeof children=="function"&&!children)&&props.isRequired&&(error=new Error(`The prop '${propName}' is marked as required in '${cpName}', but its value is '${children}'.`)),Children.map(children,c=>{if(error)return error;const type=c
|
|
1
|
+
import{isValidElement,Children}from"react";import{isEmpty,isFunction,has,get}from"lodash";import components from"../config/components";const checkChildrenTypes=(props,propName,componentName)=>{let error=null;const children=props[propName],cpName=componentName.replace("CL","");return(isEmpty(children)&&typeof children!="function"||typeof children=="function"&&!children)&&props.isRequired&&(error=new Error(`The prop '${propName}' is marked as required in '${cpName}', but its value is '${children}'.`)),Children.map(children,c=>{if(error)return error;const type=c?.type,itemTypes=get(components,`${cpName}.permittedChildren`),errorMsg=`Invalid prop '${propName}' supplied to ${cpName}. Only components ${itemTypes.join(", ")} are allowed.`;if(isFunction(type)&&has(type,"displayName")){const displayName=get(type,"displayName"),childComponentName=type.name;displayName&&displayName===`${childComponentName}`&&(itemTypes.includes(childComponentName)||(error=new Error(errorMsg)))}!isValidElement(c)&&c!==null&&(error=new Error(errorMsg))}),error},childrenTypes=checkChildrenTypes;childrenTypes.isRequired=(props,propName,componentName,location,propFullName)=>checkChildrenTypes({...props,isRequired:!0},propName,componentName,location,propFullName);export default childrenTypes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getCardDetails({paymentType,customerPayment}){
|
|
1
|
+
export default function getCardDetails({paymentType,customerPayment}){switch(paymentType){case"checkout_com_payments":{const source=customerPayment.payment_source?.payment_response?.source;if(source)return{brand:source.scheme.toLowerCase(),exp_month:source.expiry_month,exp_year:source.expiry_year,last4:source.last4};break}case"stripe_payments":case"braintree_payments":{const source=customerPayment.payment_source?.options?.card;if(source)return{...source};break}case"adyen_payments":{const ps=customerPayment.payment_source,source=ps?.payment_request_data?.payment_method,authorized=ps?.payment_response?.resultCode==="Authorised";if(source&&authorized){const brand=source.type==="scheme"?source.brand??"credit-card":source.type.replace("_account","");return{...source,brand}}break}default:{const source=customerPayment.payment_source?.metadata?.card;if(source)return{...source};break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****"}}
|
package/lib/utils/getErrors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import differenceBy from"lodash/differenceBy";export default function getErrors(error,resource,field){
|
|
1
|
+
import differenceBy from"lodash/differenceBy";export default function getErrors(error,resource,field){return error?.errors?.map(e=>({...e,resource,...field&&{field}}))}export function setErrors({currentErrors=[],newErrors=[],dispatch,filterBy="code"}){const errorsDifference=differenceBy(currentErrors,newErrors,filterBy),mergeErrors=currentErrors?.length===0?newErrors:errorsDifference,errors=[...currentErrors||[],...mergeErrors];if(!dispatch)return errors;dispatch({type:"setErrors",payload:{errors}})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getLineItemsCount({lineItems,quantity=0,typeAccepted=["skus","gift_cards","bundles","adjustments"]}){return lineItems.filter(l=>typeAccepted.includes(l.item_type)&&
|
|
1
|
+
export default function getLineItemsCount({lineItems,quantity=0,typeAccepted=["skus","gift_cards","bundles","adjustments"]}){return lineItems.filter(l=>typeAccepted.includes(l.item_type)&&l?.total_amount_cents!==void 0&&l.total_amount_cents>=0).forEach(l=>{l.quantity&&(quantity+=l.quantity)}),quantity}
|
package/lib/utils/getPrices.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as _createElement}from"react";import{jsx as _jsx}from"react/jsx-runtime";import{isEmpty,first,isArray,has}from"lodash";import PriceTemplate from"../components/utils/PriceTemplate";export const getPriceByCode=(skuPrices,code="")=>code?first(skuPrices.filter(p=>p.currency_code===code)):first(skuPrices),getPricesComponent=(skuPrices,props)=>isEmpty(skuPrices)?_jsx(PriceTemplate,
|
|
1
|
+
import{createElement as _createElement}from"react";import{jsx as _jsx}from"react/jsx-runtime";import{isEmpty,first,isArray,has}from"lodash";import PriceTemplate from"../components/utils/PriceTemplate";export const getPriceByCode=(skuPrices,code="")=>code?first(skuPrices.filter(p=>p.currency_code===code)):first(skuPrices),getPricesComponent=(skuPrices,props)=>isEmpty(skuPrices)?_jsx(PriceTemplate,{...props}):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare=="undefined"&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return _createElement(PriceTemplate,{...props,key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount})});export default function getPrices(prices){const obj={};return isArray(prices)&&prices.forEach(p=>{const sku=p.sku_code;has(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}
|
package/lib/utils/getSdk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import getOrganizationSlug from"./organization";import Sdk from"@commercelayer/sdk";export default function getSdk({endpoint,accessToken}){const org=getOrganizationSlug(endpoint);return Sdk(
|
|
1
|
+
import getOrganizationSlug from"./organization";import Sdk from"@commercelayer/sdk";export default function getSdk({endpoint,accessToken}){const org=getOrganizationSlug(endpoint);return Sdk({accessToken,...org})}
|
package/lib/utils/getSkus.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const getSkus=(skus,sortBy)=>{const obj={};return sortBy.forEach(sku=>{skus.forEach(o=>{
|
|
1
|
+
const getSkus=(skus,sortBy)=>{const obj={};return sortBy.forEach(sku=>{skus.forEach(o=>{o?.code===sku&&(obj[o.code]=o)})}),obj};export default getSkus;
|
package/lib/utils/promisify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import isFunction from"lodash/isFunction";export default function promisify(cb,params){return new Promise((resolve,reject)=>{params?cb(params,(err,res)=>{err&&reject(err),resolve(res)}):isFunction(cb
|
|
1
|
+
import isFunction from"lodash/isFunction";export default function promisify(cb,params){return new Promise((resolve,reject)=>{params?cb(params,(err,res)=>{err&&reject(err),resolve(res)}):isFunction(cb?.tokenize)?cb?.tokenize((err,payload)=>{err&&reject(err),resolve(payload)}):cb((err,res)=>{err&&reject(err),resolve(res)})})}
|
package/lib/utils/shipments.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import compact from"lodash/compact";import isEmpty from"lodash/isEmpty";export function shipmentsFilled(shipments){const filled=compact(shipments.filter(shipment=>!isEmpty(shipment.shipping_method)));return!isEmpty(filled)}export function isDoNotShip(lineItems){const itemDoNotShip=[],items=lineItems?lineItems.filter(({item_type})=>item_type==="skus").map(lineItem=>
|
|
1
|
+
import compact from"lodash/compact";import isEmpty from"lodash/isEmpty";export function shipmentsFilled(shipments){const filled=compact(shipments.filter(shipment=>!isEmpty(shipment.shipping_method)));return!isEmpty(filled)}export function isDoNotShip(lineItems){const itemDoNotShip=[],items=lineItems?lineItems.filter(({item_type})=>item_type==="skus").map(lineItem=>(lineItem.item&&lineItem.item?.do_not_ship&&itemDoNotShip.push(!0),lineItem)):[];return itemDoNotShip.length>0&&itemDoNotShip.length===items.length}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import isEmpty from"lodash/isEmpty";import isString from"lodash/isString";import without from"lodash/without";import keys from"lodash/keys";import map from"lodash/map";import get from"lodash/get";import{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/;export const validateValue=(val,name,type,resourceType)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:`${name} - is not valid`,resourceType}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resourceType};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const isTick=!!get(v,"checked"),val=isTick||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.indexOf(attrName)!==-1||v.required){const error=validateValue(val,v.name,v.type,resourceType);isEmpty(error)||errors.push(error),values=
|
|
1
|
+
import isEmpty from"lodash/isEmpty";import isString from"lodash/isString";import without from"lodash/without";import keys from"lodash/keys";import map from"lodash/map";import get from"lodash/get";import{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/;export const validateValue=(val,name,type,resourceType)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:`${name} - is not valid`,resourceType}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resourceType};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const isTick=!!get(v,"checked"),val=isTick||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.indexOf(attrName)!==-1||v.required){const error=validateValue(val,v.name,v.type,resourceType);isEmpty(error)||errors.push(error),values={...values,[`${v.name}`]:val}}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?{...values,metadata:{...values.metadata,[`${v.name}`]:val}}:{...values,[`${v.name}`]:val})}),{errors,values}};export const fieldsExist=(address,schema=addressFields)=>{if(address.business){const required=without(schema,"first_name","last_name"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=without(schema,"line_2","company"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}};const businessOptionalFields=["billing_address_first_name","billing_address_last_name","shipping_address_first_name","shipping_address_last_name","first_name","last_name"],customerOptionalFields=["billing_address_company","shipping_address_company","company"];export function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}export default validateFormFields;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0-beta.10",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -49,80 +49,80 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@ac-dev/countries-service": "^1.2.0",
|
|
51
51
|
"@ac-dev/states-service": "^1.1.0",
|
|
52
|
-
"@adyen/adyen-web": "^5.
|
|
53
|
-
"@commercelayer/sdk": "^4.
|
|
54
|
-
"@stripe/react-stripe-js": "^1.
|
|
55
|
-
"@stripe/stripe-js": "^1.
|
|
52
|
+
"@adyen/adyen-web": "^5.21.0",
|
|
53
|
+
"@commercelayer/sdk": "^4.15.1",
|
|
54
|
+
"@stripe/react-stripe-js": "^1.10.0",
|
|
55
|
+
"@stripe/stripe-js": "^1.35.0",
|
|
56
56
|
"axios": "^0.27.2",
|
|
57
|
-
"braintree-web": "^3.85.
|
|
58
|
-
"frames-react": "^1.0.
|
|
57
|
+
"braintree-web": "^3.85.5",
|
|
58
|
+
"frames-react": "^1.0.12",
|
|
59
59
|
"jwt-decode": "^3.1.2",
|
|
60
60
|
"lodash": "^4.17.21",
|
|
61
61
|
"lodash-es": "^4.17.21",
|
|
62
|
-
"rapid-form": "^1.
|
|
62
|
+
"rapid-form": "^2.1.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@babel/core": "^7.
|
|
66
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
67
|
-
"@babel/plugin-syntax-flow": "^7.
|
|
68
|
-
"@babel/plugin-transform-react-jsx": "^7.
|
|
69
|
-
"@babel/preset-env": "^7.
|
|
70
|
-
"@babel/preset-react": "^7.
|
|
71
|
-
"@babel/preset-typescript": "^7.
|
|
65
|
+
"@babel/core": "^7.18.10",
|
|
66
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
67
|
+
"@babel/plugin-syntax-flow": "^7.18.6",
|
|
68
|
+
"@babel/plugin-transform-react-jsx": "^7.18.10",
|
|
69
|
+
"@babel/preset-env": "^7.18.10",
|
|
70
|
+
"@babel/preset-react": "^7.18.6",
|
|
71
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
72
72
|
"@commercelayer/js-auth": "^2.3.0",
|
|
73
|
-
"@playwright/test": "^1.
|
|
73
|
+
"@playwright/test": "^1.24.2",
|
|
74
74
|
"@semantic-release/changelog": "^6.0.1",
|
|
75
75
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
76
76
|
"@semantic-release/git": "^10.0.1",
|
|
77
|
-
"@semantic-release/github": "^8.0.
|
|
77
|
+
"@semantic-release/github": "^8.0.5",
|
|
78
78
|
"@semantic-release/npm": "^9.0.1",
|
|
79
79
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
80
80
|
"@tailwindcss/aspect-ratio": "^0.4.0",
|
|
81
|
-
"@tailwindcss/forms": "^0.5.
|
|
81
|
+
"@tailwindcss/forms": "^0.5.2",
|
|
82
82
|
"@tailwindcss/line-clamp": "^0.4.0",
|
|
83
|
-
"@tailwindcss/typography": "^0.5.
|
|
84
|
-
"@types/braintree-web": "^3.75.
|
|
85
|
-
"@types/jest": "^
|
|
83
|
+
"@tailwindcss/typography": "^0.5.4",
|
|
84
|
+
"@types/braintree-web": "^3.75.20",
|
|
85
|
+
"@types/jest": "^28.1.6",
|
|
86
86
|
"@types/lodash": "^4.14.182",
|
|
87
|
-
"@types/node": "^
|
|
87
|
+
"@types/node": "^18.6.5",
|
|
88
88
|
"@types/prop-types": "^15.7.5",
|
|
89
89
|
"@types/react": "^17.0.45",
|
|
90
90
|
"@types/react-test-renderer": "^17.0.2",
|
|
91
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
92
|
-
"@typescript-eslint/parser": "^5.
|
|
91
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
92
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
93
93
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
94
|
-
"autoprefixer": "^10.4.
|
|
95
|
-
"babel-jest": "^28.1.
|
|
94
|
+
"autoprefixer": "^10.4.8",
|
|
95
|
+
"babel-jest": "^28.1.3",
|
|
96
96
|
"babel-loader": "^8.2.5",
|
|
97
97
|
"babel-plugin-istanbul": "^6.1.1",
|
|
98
98
|
"dotenv": "^16.0.1",
|
|
99
|
-
"eslint": "^8.
|
|
99
|
+
"eslint": "^8.21.0",
|
|
100
100
|
"eslint-config-prettier": "^8.5.0",
|
|
101
101
|
"eslint-config-react-app": "^7.0.1",
|
|
102
|
-
"eslint-plugin-react": "^7.
|
|
103
|
-
"eslint-plugin-react-hooks": "^4.
|
|
104
|
-
"jest": "^28.1.
|
|
102
|
+
"eslint-plugin-react": "^7.30.1",
|
|
103
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
104
|
+
"jest": "^28.1.3",
|
|
105
105
|
"minimize-js": "^1.3.0",
|
|
106
|
-
"next": "^12.
|
|
106
|
+
"next": "^12.2.4",
|
|
107
107
|
"nyc": "^15.1.0",
|
|
108
|
-
"playwright": "^1.
|
|
109
|
-
"postcss": "^8.4.
|
|
110
|
-
"postcss-loader": "^
|
|
111
|
-
"prettier": "^2.
|
|
108
|
+
"playwright": "^1.24.2",
|
|
109
|
+
"postcss": "^8.4.16",
|
|
110
|
+
"postcss-loader": "^7.0.1",
|
|
111
|
+
"prettier": "^2.7.1",
|
|
112
112
|
"prop-types": "^15.8.1",
|
|
113
113
|
"react": "^17.0.2",
|
|
114
114
|
"react-dom": "^17.0.2",
|
|
115
115
|
"react-test-renderer": "^17.0.2",
|
|
116
|
-
"semantic-release": "^19.0.
|
|
117
|
-
"tailwindcss": "^3.
|
|
118
|
-
"ts-jest": "^28.0.
|
|
119
|
-
"ts-loader": "^9.3.
|
|
120
|
-
"tsc-alias": "^1.
|
|
116
|
+
"semantic-release": "^19.0.3",
|
|
117
|
+
"tailwindcss": "^3.1.8",
|
|
118
|
+
"ts-jest": "^28.0.7",
|
|
119
|
+
"ts-loader": "^9.3.1",
|
|
120
|
+
"tsc-alias": "^1.7.0",
|
|
121
121
|
"tsconfig-paths-jest": "^0.0.1",
|
|
122
122
|
"tslib": "^2.4.0",
|
|
123
|
-
"typescript": "^4.
|
|
124
|
-
"v8-to-istanbul": "^9.0.
|
|
125
|
-
"webpack": "^5.
|
|
123
|
+
"typescript": "^4.7.4",
|
|
124
|
+
"v8-to-istanbul": "^9.0.1",
|
|
125
|
+
"webpack": "^5.74.0"
|
|
126
126
|
},
|
|
127
127
|
"peerDependencies": {
|
|
128
128
|
"react": "^17.0.2"
|