@commercelayer/react-components 4.10.1 → 4.11.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.
Files changed (225) hide show
  1. package/lib/cjs/components/MetadataInput.d.ts +1 -0
  2. package/lib/cjs/components/addresses/Address.d.ts +1 -0
  3. package/lib/cjs/components/addresses/AddressCountrySelector.d.ts +1 -0
  4. package/lib/cjs/components/addresses/AddressInput.d.ts +3 -2
  5. package/lib/cjs/components/addresses/AddressInputSelect.d.ts +29 -0
  6. package/lib/cjs/components/addresses/AddressInputSelect.js +2 -0
  7. package/lib/cjs/components/addresses/AddressStateSelector.d.ts +1 -0
  8. package/lib/cjs/components/addresses/AddressesEmpty.d.ts +1 -0
  9. package/lib/cjs/components/addresses/BillingAddressForm.js +1 -1
  10. package/lib/cjs/components/addresses/SaveAddressesButton.d.ts +1 -0
  11. package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
  12. package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +1 -0
  13. package/lib/cjs/components/addresses/ShippingAddressForm.js +1 -1
  14. package/lib/cjs/components/auth/CommerceLayer.d.ts +1 -0
  15. package/lib/cjs/components/customers/CustomerContainer.d.ts +1 -0
  16. package/lib/cjs/components/customers/CustomerField.d.ts +1 -0
  17. package/lib/cjs/components/customers/CustomerInput.d.ts +1 -0
  18. package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +1 -0
  19. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
  20. package/lib/cjs/components/customers/MyAccountLink.d.ts +1 -0
  21. package/lib/cjs/components/customers/MyIdentityLink.d.ts +1 -0
  22. package/lib/cjs/components/errors/Errors.d.ts +1 -0
  23. package/lib/cjs/components/gift_cards/GiftCard.d.ts +1 -0
  24. package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
  25. package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +1 -0
  26. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
  27. package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
  28. package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
  29. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
  30. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
  31. package/lib/cjs/components/line_items/LineItem.d.ts +1 -0
  32. package/lib/cjs/components/line_items/LineItemAmount.d.ts +1 -0
  33. package/lib/cjs/components/line_items/LineItemCode.d.ts +1 -0
  34. package/lib/cjs/components/line_items/LineItemField.d.ts +1 -0
  35. package/lib/cjs/components/line_items/LineItemImage.d.ts +1 -0
  36. package/lib/cjs/components/line_items/LineItemName.d.ts +1 -0
  37. package/lib/cjs/components/line_items/LineItemsContainer.d.ts +1 -0
  38. package/lib/cjs/components/line_items/LineItemsCount.d.ts +1 -0
  39. package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +1 -0
  40. package/lib/cjs/components/orders/AdjustmentAmount.d.ts +1 -0
  41. package/lib/cjs/components/orders/CheckoutLink.d.ts +1 -0
  42. package/lib/cjs/components/orders/DiscountAmount.d.ts +1 -0
  43. package/lib/cjs/components/orders/GiftCardAmount.d.ts +1 -0
  44. package/lib/cjs/components/orders/OrderContainer.d.ts +1 -0
  45. package/lib/cjs/components/orders/OrderList.d.ts +1 -0
  46. package/lib/cjs/components/orders/OrderListEmpty.d.ts +1 -0
  47. package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +1 -0
  48. package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +1 -0
  49. package/lib/cjs/components/orders/OrderListRow.d.ts +1 -0
  50. package/lib/cjs/components/orders/OrderNumber.d.ts +1 -0
  51. package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +1 -0
  52. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
  53. package/lib/cjs/components/orders/ShippingAmount.d.ts +1 -0
  54. package/lib/cjs/components/orders/SubTotalAmount.d.ts +1 -0
  55. package/lib/cjs/components/orders/TaxesAmount.d.ts +1 -0
  56. package/lib/cjs/components/orders/TotalAmount.d.ts +1 -0
  57. package/lib/cjs/components/parcels/ParcelField.d.ts +1 -0
  58. package/lib/cjs/components/parcels/ParcelLineItem.d.ts +1 -0
  59. package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +1 -0
  60. package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +1 -0
  61. package/lib/cjs/components/parcels/Parcels.d.ts +1 -0
  62. package/lib/cjs/components/parcels/ParcelsCount.d.ts +1 -0
  63. package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +1 -0
  64. package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +1 -0
  65. package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
  66. package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +1 -0
  67. package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +1 -0
  68. package/lib/cjs/components/payment_gateways/PaymentGateway.d.ts +1 -0
  69. package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +1 -0
  70. package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +1 -0
  71. package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +1 -0
  72. package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +1 -0
  73. package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +1 -0
  74. package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
  75. package/lib/cjs/components/payment_source/BraintreePayment.d.ts +1 -0
  76. package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +1 -0
  77. package/lib/cjs/components/payment_source/ExternalPayment.d.ts +1 -0
  78. package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +1 -0
  79. package/lib/cjs/components/payment_source/PaymentSource.d.ts +1 -0
  80. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
  81. package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
  82. package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +1 -0
  83. package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +1 -0
  84. package/lib/cjs/components/payment_source/StripePayment.d.ts +1 -0
  85. package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +1 -0
  86. package/lib/cjs/components/prices/Price.d.ts +1 -0
  87. package/lib/cjs/components/prices/PricesContainer.d.ts +1 -0
  88. package/lib/cjs/components/shipments/ShipmentField.d.ts +1 -0
  89. package/lib/cjs/components/shipments/ShipmentsCount.d.ts +1 -0
  90. package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +1 -0
  91. package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
  92. package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
  93. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +1 -0
  94. package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +1 -0
  95. package/lib/cjs/components/skus/SkuField.d.ts +1 -0
  96. package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +1 -0
  97. package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +1 -0
  98. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +1 -0
  99. package/lib/cjs/components/utils/BaseOrderPrice.d.ts +1 -0
  100. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +1 -0
  101. package/lib/cjs/components/utils/PriceTemplate.d.ts +1 -0
  102. package/lib/cjs/components/utils/getAllErrors.d.ts +1 -0
  103. package/lib/cjs/index.d.ts +1 -0
  104. package/lib/cjs/index.js +1 -1
  105. package/lib/cjs/typings/globals.d.ts +1 -0
  106. package/lib/cjs/utils/addressesManager.d.ts +6 -3
  107. package/lib/cjs/utils/addressesManager.js +1 -1
  108. package/lib/cjs/utils/filterChildren.d.ts +1 -0
  109. package/lib/cjs/utils/getLoaderComponent.d.ts +1 -0
  110. package/lib/cjs/utils/getPrices.d.ts +1 -0
  111. package/lib/cjs/utils/validateFormFields.d.ts +1 -1
  112. package/lib/cjs/utils/validateFormFields.js +1 -1
  113. package/lib/esm/components/MetadataInput.d.ts +1 -0
  114. package/lib/esm/components/addresses/Address.d.ts +1 -0
  115. package/lib/esm/components/addresses/AddressCountrySelector.d.ts +1 -0
  116. package/lib/esm/components/addresses/AddressInput.d.ts +3 -2
  117. package/lib/esm/components/addresses/AddressInputSelect.d.ts +29 -0
  118. package/lib/esm/components/addresses/AddressInputSelect.js +2 -0
  119. package/lib/esm/components/addresses/AddressStateSelector.d.ts +1 -0
  120. package/lib/esm/components/addresses/AddressesEmpty.d.ts +1 -0
  121. package/lib/esm/components/addresses/BillingAddressForm.js +1 -1
  122. package/lib/esm/components/addresses/SaveAddressesButton.d.ts +1 -0
  123. package/lib/esm/components/addresses/SaveAddressesButton.js +1 -1
  124. package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +1 -0
  125. package/lib/esm/components/addresses/ShippingAddressForm.js +1 -1
  126. package/lib/esm/components/auth/CommerceLayer.d.ts +1 -0
  127. package/lib/esm/components/customers/CustomerContainer.d.ts +1 -0
  128. package/lib/esm/components/customers/CustomerField.d.ts +1 -0
  129. package/lib/esm/components/customers/CustomerInput.d.ts +1 -0
  130. package/lib/esm/components/customers/CustomerPaymentSource.d.ts +1 -0
  131. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
  132. package/lib/esm/components/customers/MyAccountLink.d.ts +1 -0
  133. package/lib/esm/components/customers/MyIdentityLink.d.ts +1 -0
  134. package/lib/esm/components/errors/Errors.d.ts +1 -0
  135. package/lib/esm/components/gift_cards/GiftCard.d.ts +1 -0
  136. package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
  137. package/lib/esm/components/gift_cards/GiftCardInput.d.ts +1 -0
  138. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
  139. package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
  140. package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
  141. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
  142. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
  143. package/lib/esm/components/line_items/LineItem.d.ts +1 -0
  144. package/lib/esm/components/line_items/LineItemAmount.d.ts +1 -0
  145. package/lib/esm/components/line_items/LineItemCode.d.ts +1 -0
  146. package/lib/esm/components/line_items/LineItemField.d.ts +1 -0
  147. package/lib/esm/components/line_items/LineItemImage.d.ts +1 -0
  148. package/lib/esm/components/line_items/LineItemName.d.ts +1 -0
  149. package/lib/esm/components/line_items/LineItemsContainer.d.ts +1 -0
  150. package/lib/esm/components/line_items/LineItemsCount.d.ts +1 -0
  151. package/lib/esm/components/line_items/LineItemsEmpty.d.ts +1 -0
  152. package/lib/esm/components/orders/AdjustmentAmount.d.ts +1 -0
  153. package/lib/esm/components/orders/CheckoutLink.d.ts +1 -0
  154. package/lib/esm/components/orders/DiscountAmount.d.ts +1 -0
  155. package/lib/esm/components/orders/GiftCardAmount.d.ts +1 -0
  156. package/lib/esm/components/orders/OrderContainer.d.ts +1 -0
  157. package/lib/esm/components/orders/OrderList.d.ts +1 -0
  158. package/lib/esm/components/orders/OrderListEmpty.d.ts +1 -0
  159. package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +1 -0
  160. package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +1 -0
  161. package/lib/esm/components/orders/OrderListRow.d.ts +1 -0
  162. package/lib/esm/components/orders/OrderNumber.d.ts +1 -0
  163. package/lib/esm/components/orders/PaymentMethodAmount.d.ts +1 -0
  164. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
  165. package/lib/esm/components/orders/ShippingAmount.d.ts +1 -0
  166. package/lib/esm/components/orders/SubTotalAmount.d.ts +1 -0
  167. package/lib/esm/components/orders/TaxesAmount.d.ts +1 -0
  168. package/lib/esm/components/orders/TotalAmount.d.ts +1 -0
  169. package/lib/esm/components/parcels/ParcelField.d.ts +1 -0
  170. package/lib/esm/components/parcels/ParcelLineItem.d.ts +1 -0
  171. package/lib/esm/components/parcels/ParcelLineItemField.d.ts +1 -0
  172. package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +1 -0
  173. package/lib/esm/components/parcels/Parcels.d.ts +1 -0
  174. package/lib/esm/components/parcels/ParcelsCount.d.ts +1 -0
  175. package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +1 -0
  176. package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +1 -0
  177. package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
  178. package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +1 -0
  179. package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +1 -0
  180. package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +1 -0
  181. package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +1 -0
  182. package/lib/esm/components/payment_gateways/StripeGateway.d.ts +1 -0
  183. package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +1 -0
  184. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -0
  185. package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +1 -0
  186. package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
  187. package/lib/esm/components/payment_source/BraintreePayment.d.ts +1 -0
  188. package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +1 -0
  189. package/lib/esm/components/payment_source/ExternalPayment.d.ts +1 -0
  190. package/lib/esm/components/payment_source/KlarnaPayment.d.ts +1 -0
  191. package/lib/esm/components/payment_source/PaymentSource.d.ts +1 -0
  192. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
  193. package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
  194. package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +1 -0
  195. package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +1 -0
  196. package/lib/esm/components/payment_source/StripePayment.d.ts +1 -0
  197. package/lib/esm/components/payment_source/WireTransferPayment.d.ts +1 -0
  198. package/lib/esm/components/prices/Price.d.ts +1 -0
  199. package/lib/esm/components/prices/PricesContainer.d.ts +1 -0
  200. package/lib/esm/components/shipments/ShipmentField.d.ts +1 -0
  201. package/lib/esm/components/shipments/ShipmentsCount.d.ts +1 -0
  202. package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +1 -0
  203. package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
  204. package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
  205. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +1 -0
  206. package/lib/esm/components/skus/DeliveryLeadTime.d.ts +1 -0
  207. package/lib/esm/components/skus/SkuField.d.ts +1 -0
  208. package/lib/esm/components/stock_transfers/StockTransfer.d.ts +1 -0
  209. package/lib/esm/components/stock_transfers/StockTransferField.d.ts +1 -0
  210. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +1 -0
  211. package/lib/esm/components/utils/BaseOrderPrice.d.ts +1 -0
  212. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +1 -0
  213. package/lib/esm/components/utils/PriceTemplate.d.ts +1 -0
  214. package/lib/esm/components/utils/getAllErrors.d.ts +1 -0
  215. package/lib/esm/index.d.ts +1 -0
  216. package/lib/esm/index.js +1 -1
  217. package/lib/esm/typings/globals.d.ts +1 -0
  218. package/lib/esm/utils/addressesManager.d.ts +6 -3
  219. package/lib/esm/utils/addressesManager.js +1 -1
  220. package/lib/esm/utils/filterChildren.d.ts +1 -0
  221. package/lib/esm/utils/getLoaderComponent.d.ts +1 -0
  222. package/lib/esm/utils/getPrices.d.ts +1 -0
  223. package/lib/esm/utils/validateFormFields.d.ts +1 -1
  224. package/lib/esm/utils/validateFormFields.js +1 -1
  225. package/package.json +8 -8
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import isEmpty from"lodash/isEmpty";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export function billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo=!1,invertAddresses=!1,shipToDifferentAddress,shippingDisable}){let billingDisable=invertAddresses?!!(!shippingDisable&&shipToDifferentAddress):!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address))if(invertAddresses)billingDisable=!!(billing_address&&fieldsExist(billing_address));else{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}export function shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses=!1,requiresBillingInfo=!1}){let shippingDisable=invertAddresses?!isEmpty(errors)||isEmpty(shipping_address):!!(!billingDisable&&shipToDifferentAddress);if(isEmpty(errors)&&!isEmpty(shipping_address))if(invertAddresses){let billingInfo=[...addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),shippingDisable=!!(shipping_address&&fieldsExist(shipping_address,billingInfo))}else shipToDifferentAddress&&(delete shipping_address?.billing_info,shippingDisable=!!(shipping_address&&fieldsExist(shipping_address)));return shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable}export function countryLockController({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId,lineItems}){if(lineItems?.filter(lineItem=>lineItem?.item?.type!=null&&["skus","bundles"].includes(lineItem?.item?.type))?.every(lineItem=>lineItem?.item?.do_not_ship===!0))return!1;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}export async function invertedAddressesHandler({order,billingAddress,billingAddressId,customerEmail,shipToDifferentAddress,shippingAddress,shippingAddressId,sdk}){const currentShippingAddressRef=order?.shipping_address?.reference,orderAttributes={id:order?.id,_billing_address_clone_id:shippingAddressId,_shipping_address_clone_id:shippingAddressId,customer_email:customerEmail};if(currentShippingAddressRef===shippingAddressId&&(orderAttributes._billing_address_clone_id=order?.billing_address?.id,orderAttributes._shipping_address_clone_id=order?.shipping_address?.id),shippingAddress!=null&&Object.keys(shippingAddress).length>0){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._billing_address_same_as_shipping=!0;const hasMetadata=Object.keys(shippingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");shippingAddress.metadata={...shippingAddress.metadata||{},[metadataKey]:shippingAddress[key]},delete shippingAddress[key]});const address=await sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._billing_address_same_as_shipping,billingAddressId&&(orderAttributes._billing_address_clone_id=billingAddressId),billingAddress!=null&&Object.keys(billingAddress).length>0)){delete orderAttributes._billing_address_clone_id;const hasMetadata=Object.keys(billingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");billingAddress.metadata={...billingAddress.metadata||{},[metadataKey]:billingAddress[key]},delete billingAddress[key]});const address=await sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}return orderAttributes}export function addressesController({billing_address,billingAddressId,shipToDifferentAddress,shipping_address,shippingAddressId,errors,requiresBillingInfo,invertAddresses}){if(invertAddresses){const shippingDisable2=shippingAddressController({errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses,requiresBillingInfo}),billingDisable2=billingAddressController({shippingDisable:shippingDisable2,billing_address,billingAddressId,errors,requiresBillingInfo,invertAddresses});return{shippingDisable:shippingDisable2,billingDisable:billingDisable2}}const billingDisable=billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId});return{billingDisable,shippingDisable}}
2
+ import isEmpty from"lodash/isEmpty";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export function billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo=!1,invertAddresses=!1,shipToDifferentAddress,shippingDisable,requiredMetadataFields}){console.log("requiredMetadataFields",requiredMetadataFields);let billingDisable=invertAddresses?!!(!shippingDisable&&shipToDifferentAddress):!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address)){let formFields=[...addressFields];requiredMetadataFields!=null&&requiredMetadataFields.length>0&&(formFields=[...formFields,...requiredMetadataFields]),invertAddresses?billingDisable=!!(billing_address&&fieldsExist(billing_address,formFields)):(requiresBillingInfo&&(formFields=[...formFields,"billing_info"]),console.log("formFields",formFields),billingDisable=!!(billing_address&&fieldsExist(billing_address,formFields)))}return billingDisable&&!isEmpty(billingAddressId)&&isEmpty(billing_address)&&(billingDisable=!1),billingDisable}export function shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses=!1,requiresBillingInfo=!1,requiredMetadataFields}){let shippingDisable=invertAddresses?!isEmpty(errors)||isEmpty(shipping_address):!!(!billingDisable&&shipToDifferentAddress);if(isEmpty(errors)&&!isEmpty(shipping_address)){let formField=[...addressFields];requiredMetadataFields!=null&&requiredMetadataFields.length>0&&(formField=[...formField,...requiredMetadataFields]),invertAddresses?(requiresBillingInfo&&(formField=[...formField,"billing_info"]),shippingDisable=!!(shipping_address&&fieldsExist(shipping_address,formField))):shipToDifferentAddress&&(delete shipping_address?.billing_info,shippingDisable=!!(shipping_address&&fieldsExist(shipping_address,formField)))}return shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable}export function countryLockController({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId,lineItems}){if(lineItems?.filter(lineItem=>lineItem?.item?.type!=null&&["skus","bundles"].includes(lineItem?.item?.type))?.every(lineItem=>lineItem?.item?.do_not_ship===!0))return!1;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}export async function invertedAddressesHandler({order,billingAddress,billingAddressId,customerEmail,shipToDifferentAddress,shippingAddress,shippingAddressId,sdk}){const currentShippingAddressRef=order?.shipping_address?.reference,orderAttributes={id:order?.id,_billing_address_clone_id:shippingAddressId,_shipping_address_clone_id:shippingAddressId,customer_email:customerEmail};if(currentShippingAddressRef===shippingAddressId&&(orderAttributes._billing_address_clone_id=order?.billing_address?.id,orderAttributes._shipping_address_clone_id=order?.shipping_address?.id),shippingAddress!=null&&Object.keys(shippingAddress).length>0){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._billing_address_same_as_shipping=!0;const hasMetadata=Object.keys(shippingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");shippingAddress.metadata={...shippingAddress.metadata||{},[metadataKey]:shippingAddress[key]},delete shippingAddress[key]});const address=await sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._billing_address_same_as_shipping,billingAddressId&&(orderAttributes._billing_address_clone_id=billingAddressId),billingAddress!=null&&Object.keys(billingAddress).length>0)){delete orderAttributes._billing_address_clone_id;const hasMetadata=Object.keys(billingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");billingAddress.metadata={...billingAddress.metadata||{},[metadataKey]:billingAddress[key]},delete billingAddress[key]});const address=await sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}return orderAttributes}export function addressesController({billing_address,billingAddressId,shipToDifferentAddress,shipping_address,shippingAddressId,errors,requiresBillingInfo,invertAddresses,requiredMetadataFields}){if(invertAddresses){const shippingDisable2=shippingAddressController({errors,shipToDifferentAddress,shipping_address,shippingAddressId,invertAddresses,requiresBillingInfo,requiredMetadataFields}),billingDisable2=billingAddressController({shippingDisable:shippingDisable2,billing_address,billingAddressId,errors,requiresBillingInfo,invertAddresses,requiredMetadataFields});return{shippingDisable:shippingDisable2,billingDisable:billingDisable2}}const billingDisable=billingAddressController({billing_address,billingAddressId,errors,requiresBillingInfo,requiredMetadataFields}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId,requiredMetadataFields});return{billingDisable,shippingDisable}}
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type DefaultChildrenType } from '../typings/globals';
2
3
  interface Props<T> {
3
4
  children: DefaultChildrenType;
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  import { type LoaderType } from '../typings/index';
2
3
  export default function getLoaderComponent(loader: LoaderType): JSX.Element;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type Price } from '@commercelayer/sdk';
2
3
  import { type PTemplateProps } from '../components/utils/PriceTemplate';
3
4
  export declare function getPriceByCode(skuPrices: Price[], code?: string): Price | undefined;
@@ -11,6 +11,6 @@ export type ValidateFormFields = <R extends string[]>(fields: HTMLFormControlsCo
11
11
  export type ValidateValue = <V extends string | boolean, N extends string, T extends string, B extends TResourceError>(val: V, name: N, type: T, resource: B) => BaseError | Record<string, any>;
12
12
  export declare const validateValue: ValidateValue;
13
13
  declare const validateFormFields: ValidateFormFields;
14
- export declare function fieldsExist(address: AddressCreate, schema?: AddressField[]): boolean;
14
+ export declare function fieldsExist(address: AddressCreate, schema?: Array<AddressField | string>): boolean;
15
15
  export declare function businessMandatoryField(fieldName: AddressInputName, isBusiness?: boolean): boolean;
16
16
  export default validateFormFields;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- 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{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;export const validateValue=(val,name,type,resource)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:"please enter a valid format",resource}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resource};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const val="checked"in v||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.includes(attrName)||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 function fieldsExist(address,schema=addressFields){if(address.business){const required=without(schema,"first_name","last_name","line_2"),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;
2
+ 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{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;export const validateValue=(val,name,type,resource)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:"please enter a valid format",resource}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resource};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const val="checked"in v||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.includes(attrName)||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 function fieldsExist(address,schema=addressFields){if(console.log("address",address),address.business){const required=without(schema,"first_name","last_name","line_2"),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": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -165,10 +165,10 @@
165
165
  },
166
166
  "homepage": "https://github.com/commercelayer/commercelayer-react-components#readme",
167
167
  "dependencies": {
168
- "@adyen/adyen-web": "^5.57.0",
168
+ "@adyen/adyen-web": "^5.58.0",
169
169
  "@commercelayer/sdk": "^5.31.1",
170
170
  "@stripe/react-stripe-js": "^2.4.0",
171
- "@stripe/stripe-js": "^2.4.0",
171
+ "@stripe/stripe-js": "^3.0.5",
172
172
  "@tanstack/react-table": "^8.11.8",
173
173
  "@types/iframe-resizer": "^3.5.13",
174
174
  "axios": "^1.6.7",
@@ -187,25 +187,25 @@
187
187
  "@testing-library/react": "^14.2.1",
188
188
  "@types/braintree-web": "^3.96.10",
189
189
  "@types/lodash": "^4.14.202",
190
- "@types/node": "^20.11.16",
190
+ "@types/node": "^20.11.19",
191
191
  "@types/prop-types": "^15.7.11",
192
- "@types/react": "^18.2.53",
192
+ "@types/react": "^18.2.57",
193
193
  "@types/react-test-renderer": "^18.0.7",
194
194
  "@types/react-window": "^1.8.8",
195
195
  "@vitejs/plugin-react": "^4.2.1",
196
196
  "@vitest/coverage-c8": "^0.33.0",
197
197
  "jsdom": "^24.0.0",
198
198
  "minimize-js": "^1.4.0",
199
- "msw": "^2.1.5",
199
+ "msw": "^2.2.1",
200
200
  "react": "^18.2.0",
201
201
  "react-dom": "^18.2.0",
202
202
  "react-test-renderer": "^18.2.0",
203
203
  "tsc-alias": "^1.8.8",
204
204
  "tslib": "^2.6.2",
205
205
  "typescript": "^5.3.3",
206
- "vite": "^5.0.12",
206
+ "vite": "^5.1.4",
207
207
  "vite-tsconfig-paths": "^4.3.1",
208
- "vitest": "^1.2.2"
208
+ "vitest": "^1.3.1"
209
209
  },
210
210
  "peerDependencies": {
211
211
  "react": ">=18.0.0"