@commercelayer/react-components 4.5.1 → 4.5.2-beta.1

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 (231) 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 +1 -0
  5. package/lib/cjs/components/addresses/AddressStateSelector.d.ts +1 -0
  6. package/lib/cjs/components/addresses/AddressesEmpty.d.ts +1 -0
  7. package/lib/cjs/components/addresses/BillingAddressForm.js +1 -1
  8. package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +1 -0
  9. package/lib/cjs/components/addresses/ShippingAddressForm.js +1 -1
  10. package/lib/cjs/components/auth/CommerceLayer.d.ts +1 -0
  11. package/lib/cjs/components/customers/CustomerContainer.d.ts +1 -0
  12. package/lib/cjs/components/customers/CustomerField.d.ts +1 -0
  13. package/lib/cjs/components/customers/CustomerInput.d.ts +1 -0
  14. package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +1 -0
  15. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
  16. package/lib/cjs/components/customers/MyAccountLink.d.ts +1 -0
  17. package/lib/cjs/components/customers/MyIdentityLink.d.ts +1 -0
  18. package/lib/cjs/components/errors/Errors.d.ts +1 -0
  19. package/lib/cjs/components/gift_cards/GiftCard.d.ts +1 -0
  20. package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
  21. package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +1 -0
  22. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
  23. package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
  24. package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
  25. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
  26. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
  27. package/lib/cjs/components/line_items/LineItem.d.ts +1 -0
  28. package/lib/cjs/components/line_items/LineItemAmount.d.ts +1 -0
  29. package/lib/cjs/components/line_items/LineItemCode.d.ts +1 -0
  30. package/lib/cjs/components/line_items/LineItemField.d.ts +1 -0
  31. package/lib/cjs/components/line_items/LineItemImage.d.ts +1 -0
  32. package/lib/cjs/components/line_items/LineItemName.d.ts +1 -0
  33. package/lib/cjs/components/line_items/LineItemsContainer.d.ts +1 -0
  34. package/lib/cjs/components/line_items/LineItemsCount.d.ts +1 -0
  35. package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +1 -0
  36. package/lib/cjs/components/orders/AdjustmentAmount.d.ts +1 -0
  37. package/lib/cjs/components/orders/CheckoutLink.d.ts +1 -0
  38. package/lib/cjs/components/orders/DiscountAmount.d.ts +1 -0
  39. package/lib/cjs/components/orders/GiftCardAmount.d.ts +1 -0
  40. package/lib/cjs/components/orders/HostedCart.d.ts +2 -0
  41. package/lib/cjs/components/orders/HostedCart.js +1 -1
  42. package/lib/cjs/components/orders/OrderContainer.d.ts +1 -0
  43. package/lib/cjs/components/orders/OrderList.d.ts +1 -0
  44. package/lib/cjs/components/orders/OrderListEmpty.d.ts +1 -0
  45. package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +1 -0
  46. package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +1 -0
  47. package/lib/cjs/components/orders/OrderListRow.d.ts +1 -0
  48. package/lib/cjs/components/orders/OrderNumber.d.ts +1 -0
  49. package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +1 -0
  50. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
  51. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
  52. package/lib/cjs/components/orders/ShippingAmount.d.ts +1 -0
  53. package/lib/cjs/components/orders/SubTotalAmount.d.ts +1 -0
  54. package/lib/cjs/components/orders/TaxesAmount.d.ts +1 -0
  55. package/lib/cjs/components/orders/TotalAmount.d.ts +1 -0
  56. package/lib/cjs/components/parcels/ParcelField.d.ts +1 -0
  57. package/lib/cjs/components/parcels/ParcelLineItem.d.ts +1 -0
  58. package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +1 -0
  59. package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +1 -0
  60. package/lib/cjs/components/parcels/Parcels.d.ts +1 -0
  61. package/lib/cjs/components/parcels/ParcelsCount.d.ts +1 -0
  62. package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +1 -0
  63. package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +1 -0
  64. package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
  65. package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +1 -0
  66. package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +1 -0
  67. package/lib/cjs/components/payment_gateways/KlarnaGateway.js +1 -1
  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 +2 -1
  76. package/lib/cjs/components/payment_source/BraintreePayment.js +1 -1
  77. package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +1 -0
  78. package/lib/cjs/components/payment_source/ExternalPayment.d.ts +1 -0
  79. package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +1 -0
  80. package/lib/cjs/components/payment_source/KlarnaPayment.js +1 -1
  81. package/lib/cjs/components/payment_source/PaymentSource.d.ts +1 -0
  82. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
  83. package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
  84. package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +1 -0
  85. package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +1 -0
  86. package/lib/cjs/components/payment_source/StripePayment.d.ts +1 -0
  87. package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +1 -0
  88. package/lib/cjs/components/prices/Price.d.ts +1 -0
  89. package/lib/cjs/components/prices/PricesContainer.d.ts +1 -0
  90. package/lib/cjs/components/shipments/Shipment.js +1 -1
  91. package/lib/cjs/components/shipments/ShipmentField.d.ts +1 -0
  92. package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -1
  93. package/lib/cjs/components/shipments/ShipmentsCount.d.ts +1 -0
  94. package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +1 -0
  95. package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
  96. package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
  97. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +1 -0
  98. package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +1 -0
  99. package/lib/cjs/components/skus/SkuField.d.ts +1 -0
  100. package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +1 -0
  101. package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +1 -0
  102. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +1 -0
  103. package/lib/cjs/components/utils/BaseOrderPrice.d.ts +1 -0
  104. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +1 -0
  105. package/lib/cjs/components/utils/PriceTemplate.d.ts +1 -0
  106. package/lib/cjs/components/utils/getAllErrors.d.ts +1 -0
  107. package/lib/cjs/reducers/AddressReducer.js +1 -1
  108. package/lib/cjs/typings/globals.d.ts +1 -0
  109. package/lib/cjs/utils/filterChildren.d.ts +1 -0
  110. package/lib/cjs/utils/getCardDetails.d.ts +1 -1
  111. package/lib/cjs/utils/getCardDetails.js +1 -1
  112. package/lib/cjs/utils/getLoaderComponent.d.ts +1 -0
  113. package/lib/cjs/utils/getPrices.d.ts +1 -0
  114. package/lib/cjs/utils/shipments.js +1 -1
  115. package/lib/cjs/utils/validateFormFields.js +1 -1
  116. package/lib/esm/components/MetadataInput.d.ts +1 -0
  117. package/lib/esm/components/addresses/Address.d.ts +1 -0
  118. package/lib/esm/components/addresses/AddressCountrySelector.d.ts +1 -0
  119. package/lib/esm/components/addresses/AddressInput.d.ts +1 -0
  120. package/lib/esm/components/addresses/AddressStateSelector.d.ts +1 -0
  121. package/lib/esm/components/addresses/AddressesEmpty.d.ts +1 -0
  122. package/lib/esm/components/addresses/BillingAddressForm.js +1 -1
  123. package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +1 -0
  124. package/lib/esm/components/addresses/ShippingAddressForm.js +1 -1
  125. package/lib/esm/components/auth/CommerceLayer.d.ts +1 -0
  126. package/lib/esm/components/customers/CustomerContainer.d.ts +1 -0
  127. package/lib/esm/components/customers/CustomerField.d.ts +1 -0
  128. package/lib/esm/components/customers/CustomerInput.d.ts +1 -0
  129. package/lib/esm/components/customers/CustomerPaymentSource.d.ts +1 -0
  130. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
  131. package/lib/esm/components/customers/MyAccountLink.d.ts +1 -0
  132. package/lib/esm/components/customers/MyIdentityLink.d.ts +1 -0
  133. package/lib/esm/components/errors/Errors.d.ts +1 -0
  134. package/lib/esm/components/gift_cards/GiftCard.d.ts +1 -0
  135. package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
  136. package/lib/esm/components/gift_cards/GiftCardInput.d.ts +1 -0
  137. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
  138. package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
  139. package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
  140. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
  141. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
  142. package/lib/esm/components/line_items/LineItem.d.ts +1 -0
  143. package/lib/esm/components/line_items/LineItemAmount.d.ts +1 -0
  144. package/lib/esm/components/line_items/LineItemCode.d.ts +1 -0
  145. package/lib/esm/components/line_items/LineItemField.d.ts +1 -0
  146. package/lib/esm/components/line_items/LineItemImage.d.ts +1 -0
  147. package/lib/esm/components/line_items/LineItemName.d.ts +1 -0
  148. package/lib/esm/components/line_items/LineItemsContainer.d.ts +1 -0
  149. package/lib/esm/components/line_items/LineItemsCount.d.ts +1 -0
  150. package/lib/esm/components/line_items/LineItemsEmpty.d.ts +1 -0
  151. package/lib/esm/components/orders/AdjustmentAmount.d.ts +1 -0
  152. package/lib/esm/components/orders/CheckoutLink.d.ts +1 -0
  153. package/lib/esm/components/orders/DiscountAmount.d.ts +1 -0
  154. package/lib/esm/components/orders/GiftCardAmount.d.ts +1 -0
  155. package/lib/esm/components/orders/HostedCart.d.ts +2 -0
  156. package/lib/esm/components/orders/HostedCart.js +1 -1
  157. package/lib/esm/components/orders/OrderContainer.d.ts +1 -0
  158. package/lib/esm/components/orders/OrderList.d.ts +1 -0
  159. package/lib/esm/components/orders/OrderListEmpty.d.ts +1 -0
  160. package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +1 -0
  161. package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +1 -0
  162. package/lib/esm/components/orders/OrderListRow.d.ts +1 -0
  163. package/lib/esm/components/orders/OrderNumber.d.ts +1 -0
  164. package/lib/esm/components/orders/PaymentMethodAmount.d.ts +1 -0
  165. package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
  166. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
  167. package/lib/esm/components/orders/ShippingAmount.d.ts +1 -0
  168. package/lib/esm/components/orders/SubTotalAmount.d.ts +1 -0
  169. package/lib/esm/components/orders/TaxesAmount.d.ts +1 -0
  170. package/lib/esm/components/orders/TotalAmount.d.ts +1 -0
  171. package/lib/esm/components/parcels/ParcelField.d.ts +1 -0
  172. package/lib/esm/components/parcels/ParcelLineItem.d.ts +1 -0
  173. package/lib/esm/components/parcels/ParcelLineItemField.d.ts +1 -0
  174. package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +1 -0
  175. package/lib/esm/components/parcels/Parcels.d.ts +1 -0
  176. package/lib/esm/components/parcels/ParcelsCount.d.ts +1 -0
  177. package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +1 -0
  178. package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +1 -0
  179. package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
  180. package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +1 -0
  181. package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +1 -0
  182. package/lib/esm/components/payment_gateways/KlarnaGateway.js +1 -1
  183. package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +1 -0
  184. package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +1 -0
  185. package/lib/esm/components/payment_gateways/StripeGateway.d.ts +1 -0
  186. package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +1 -0
  187. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -0
  188. package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +1 -0
  189. package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
  190. package/lib/esm/components/payment_source/BraintreePayment.d.ts +2 -1
  191. package/lib/esm/components/payment_source/BraintreePayment.js +1 -1
  192. package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +1 -0
  193. package/lib/esm/components/payment_source/ExternalPayment.d.ts +1 -0
  194. package/lib/esm/components/payment_source/KlarnaPayment.d.ts +1 -0
  195. package/lib/esm/components/payment_source/KlarnaPayment.js +1 -1
  196. package/lib/esm/components/payment_source/PaymentSource.d.ts +1 -0
  197. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
  198. package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
  199. package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +1 -0
  200. package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +1 -0
  201. package/lib/esm/components/payment_source/StripePayment.d.ts +1 -0
  202. package/lib/esm/components/payment_source/WireTransferPayment.d.ts +1 -0
  203. package/lib/esm/components/prices/Price.d.ts +1 -0
  204. package/lib/esm/components/prices/PricesContainer.d.ts +1 -0
  205. package/lib/esm/components/shipments/Shipment.js +1 -1
  206. package/lib/esm/components/shipments/ShipmentField.d.ts +1 -0
  207. package/lib/esm/components/shipments/ShipmentsContainer.js +1 -1
  208. package/lib/esm/components/shipments/ShipmentsCount.d.ts +1 -0
  209. package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +1 -0
  210. package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
  211. package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
  212. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +1 -0
  213. package/lib/esm/components/skus/DeliveryLeadTime.d.ts +1 -0
  214. package/lib/esm/components/skus/SkuField.d.ts +1 -0
  215. package/lib/esm/components/stock_transfers/StockTransfer.d.ts +1 -0
  216. package/lib/esm/components/stock_transfers/StockTransferField.d.ts +1 -0
  217. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +1 -0
  218. package/lib/esm/components/utils/BaseOrderPrice.d.ts +1 -0
  219. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +1 -0
  220. package/lib/esm/components/utils/PriceTemplate.d.ts +1 -0
  221. package/lib/esm/components/utils/getAllErrors.d.ts +1 -0
  222. package/lib/esm/reducers/AddressReducer.js +1 -1
  223. package/lib/esm/typings/globals.d.ts +1 -0
  224. package/lib/esm/utils/filterChildren.d.ts +1 -0
  225. package/lib/esm/utils/getCardDetails.d.ts +1 -1
  226. package/lib/esm/utils/getCardDetails.js +1 -1
  227. package/lib/esm/utils/getLoaderComponent.d.ts +1 -0
  228. package/lib/esm/utils/getPrices.d.ts +1 -0
  229. package/lib/esm/utils/shipments.js +1 -1
  230. package/lib/esm/utils/validateFormFields.js +1 -1
  231. package/package.json +22 -22
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BraintreePayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),promisify_1=tslib_1.__importDefault(require("../../utils/promisify")),defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"};function BraintreePayment({authorization,config,templateCustomerSaveToWallet}){var _a,_b,_c;const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}=Object.assign(Object.assign({},defaultConfig),config),[loadBraintree,setLoadBraintree]=(0,react_1.useState)(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),ref=(0,react_1.useRef)(null),handleSubmitForm=({event,hostedFieldsInstance,threeDSInstance})=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _d,_e,_f,_g,_h,_j;const savePaymentSourceToCustomerWallet=(_e=(_d=event?.elements)===null||_d===void 0?void 0:_d.save_payment_source_to_customer_wallet)===null||_e===void 0?void 0:_e.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=yield(0,promisify_1.default)(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order?.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:order?.total_amount_with_taxes_float,email:(_f=order?.customer_email)!==null&&_f!==void 0?_f:"",billingAddress:{givenName:(_g=billingAddress?.first_name)!==null&&_g!==void 0?_g:"",surname:(_h=billingAddress?.last_name)!==null&&_h!==void 0?_h:"",phoneNumber:billingAddress?.phone,streetAddress:billingAddress?.line_1,countryCodeAlpha2:billingAddress?.country_code,postalCode:(_j=billingAddress?.zip_code)!==null&&_j!==void 0?_j:"",region:billingAddress?.state_code,locality:billingAddress?.city},onLookupComplete:(_data,next)=>{next()}},response=yield threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&(yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}})),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1});return(0,react_1.useEffect)(()=>{if(!ref&&authorization&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!(0,isEmpty_1.default)(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,threeDSInstance)=>{threeDSecureErr&&(console.error("3DSecure error",threeDSecureErr),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:threeDSecureErr.message}])),ref.current&&(ref.current.onsubmit=paymentSource2=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2})}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:(0,jsx_runtime_1.jsx)("div",{className:containerClassName,children:(0,jsx_runtime_1.jsxs)("form",{ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:fieldsContainerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:cardContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"card-number",children:(_a=fields?.number)===null||_a===void 0?void 0:_a.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"card-number"})]}),(0,jsx_runtime_1.jsxs)("div",{className:cardDetailsContainerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:expDateContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"expiration-date",children:(_b=fields?.expirationDate)===null||_b===void 0?void 0:_b.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"expiration-date"})]}),(0,jsx_runtime_1.jsxs)("div",{className:cvvContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"cvv",children:(_c=fields?.cvv)===null||_c===void 0?void 0:_c.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"cvv"})]})]})]}),(0,jsx_runtime_1.jsx)("div",{className:fieldsContainerClassName,children:templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})})]})})}exports.BraintreePayment=BraintreePayment,exports.default=BraintreePayment;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BraintreePayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),promisify_1=tslib_1.__importDefault(require("../../utils/promisify")),defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"};function BraintreePayment({authorization,config,templateCustomerSaveToWallet}){var _a,_b,_c;const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}=Object.assign(Object.assign({},defaultConfig),config),[loadBraintree,setLoadBraintree]=(0,react_1.useState)(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),ref=(0,react_1.useRef)(null),handleSubmitForm=({event,hostedFieldsInstance,threeDSInstance})=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _d,_e,_f,_g,_h,_j;const savePaymentSourceToCustomerWallet=(_e=(_d=event?.elements)===null||_d===void 0?void 0:_d.save_payment_source_to_customer_wallet)===null||_e===void 0?void 0:_e.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=yield(0,promisify_1.default)(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order?.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:`${order?.total_amount_with_taxes_float}`,email:(_f=order?.customer_email)!==null&&_f!==void 0?_f:"",billingAddress:{givenName:(_g=billingAddress?.first_name)!==null&&_g!==void 0?_g:"",surname:(_h=billingAddress?.last_name)!==null&&_h!==void 0?_h:"",phoneNumber:billingAddress?.phone,streetAddress:billingAddress?.line_1,countryCodeAlpha2:billingAddress?.country_code,postalCode:(_j=billingAddress?.zip_code)!==null&&_j!==void 0?_j:"",region:billingAddress?.state_code,locality:billingAddress?.city},onLookupComplete:(_data,next)=>{next()}},response=yield threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&(yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}})),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1});return(0,react_1.useEffect)(()=>{if(!ref&&authorization&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!(0,isEmpty_1.default)(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,threeDSInstance)=>{threeDSecureErr&&(console.error("3DSecure error",threeDSecureErr),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:threeDSecureErr.message}])),ref.current&&(ref.current.onsubmit=paymentSource2=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2})}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:(0,jsx_runtime_1.jsx)("div",{className:containerClassName,children:(0,jsx_runtime_1.jsxs)("form",{ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:fieldsContainerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:cardContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"card-number",children:(_a=fields?.number)===null||_a===void 0?void 0:_a.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"card-number"})]}),(0,jsx_runtime_1.jsxs)("div",{className:cardDetailsContainerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:expDateContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"expiration-date",children:(_b=fields?.expirationDate)===null||_b===void 0?void 0:_b.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"expiration-date"})]}),(0,jsx_runtime_1.jsxs)("div",{className:cvvContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"cvv",children:(_c=fields?.cvv)===null||_c===void 0?void 0:_c.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"cvv"})]})]})]}),(0,jsx_runtime_1.jsx)("div",{className:fieldsContainerClassName,children:templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})})]})})}exports.BraintreePayment=BraintreePayment,exports.default=BraintreePayment;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
2
3
  import { type PaymentSourceProps } from './PaymentSource';
3
4
  import { type FramesStyle } from 'frames-react';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { StripeElementLocale } from '@stripe/stripe-js';
3
4
  import { type PaymentSourceProps } from './PaymentSource';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
2
3
  import { type PaymentSourceProps } from './PaymentSource';
3
4
  type KlarnaPaymentProps = PaymentMethodConfig['klarnaPayment'] & JSX.IntrinsicElements['div'] & Partial<PaymentSourceProps['templateCustomerSaveToWallet']> & {
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript"));function typeOfLine(lineItemType){switch(lineItemType){case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical";case"payment_methods":default:return null}}function klarnaOrderLines(lineItems){return lineItems?lineItems?.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}function KlarnaPayment(_a){var _b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,{clientToken,placeOrderCallback,locale="EN"}=_a,p=tslib_1.__rest(_a,["clientToken","placeOrderCallback","locale"]);const ref=(0,react_1.useRef)(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),loaded=(0,useExternalScript_1.default)("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=(0,react_1.useState)(),{containerClassName}=p,divProps=tslib_1.__rest(p,["containerClassName"]);(0,react_1.useEffect)(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield handleClick(klarna)}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=kl=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _v,_w,_x,_y,_z,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10;const[first]=paymentSource?.payment_methods||void 0,paymentMethodCategory=first?.identifier,billingAddress={given_name:(_v=order?.billing_address)===null||_v===void 0?void 0:_v.first_name,family_name:(_w=order?.billing_address)===null||_w===void 0?void 0:_w.last_name,email:order?.customer_email,street_address:(_x=order?.billing_address)===null||_x===void 0?void 0:_x.line_1,street_address2:null,organization_name:null,postal_code:(_y=order?.billing_address)===null||_y===void 0?void 0:_y.zip_code,city:(_z=order?.billing_address)===null||_z===void 0?void 0:_z.city,region:(_0=order?.billing_address)===null||_0===void 0?void 0:_0.state_code,phone:(_1=order?.billing_address)===null||_1===void 0?void 0:_1.phone,country:(_2=order?.billing_address)===null||_2===void 0?void 0:_2.country_code},shippingAddress={given_name:(_3=order?.shipping_address)===null||_3===void 0?void 0:_3.first_name,family_name:(_4=order?.shipping_address)===null||_4===void 0?void 0:_4.last_name,email:order?.customer_email,street_address:(_5=order?.shipping_address)===null||_5===void 0?void 0:_5.line_1,street_address2:null,postal_code:(_6=order?.shipping_address)===null||_6===void 0?void 0:_6.zip_code,organization_name:null,city:(_7=order?.shipping_address)===null||_7===void 0?void 0:_7.city,region:(_8=order?.shipping_address)===null||_8===void 0?void 0:_8.state_code,phone:(_9=order?.shipping_address)===null||_9===void 0?void 0:_9.phone,country:(_10=order?.shipping_address)===null||_10===void 0?void 0:_10.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address:shippingAddress,billing_address:billingAddress,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category:paymentMethodCategory},{billing_address:billingAddress,shipping_address:shippingAddress},function({show_form}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(show_form)try{yield kl.Payments.authorize({payment_method_category:paymentMethodCategory},klarnaData,function(res){return tslib_1.__awaiter(this,void 0,void 0,function*(){console.log("res",res),console.log("paymentSource",paymentSource),console.log("order",order)})})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})})}catch(e){console.error("Load Klarna libray",e)}});if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier},{billing_address:{given_name:(_b=order?.billing_address)===null||_b===void 0?void 0:_b.first_name,family_name:(_c=order?.billing_address)===null||_c===void 0?void 0:_c.last_name,email:order?.customer_email,street_address:(_d=order?.billing_address)===null||_d===void 0?void 0:_d.line_1,street_address2:(_e=order?.billing_address)===null||_e===void 0?void 0:_e.line_2,postal_code:(_f=order?.billing_address)===null||_f===void 0?void 0:_f.zip_code,city:(_g=order?.billing_address)===null||_g===void 0?void 0:_g.city,region:(_h=order?.billing_address)===null||_h===void 0?void 0:_h.state_code,phone:(_j=order?.billing_address)===null||_j===void 0?void 0:_j.phone,country:(_k=order?.billing_address)===null||_k===void 0?void 0:_k.country_code},shipping_address:{given_name:(_l=order?.shipping_address)===null||_l===void 0?void 0:_l.first_name,family_name:(_m=order?.shipping_address)===null||_m===void 0?void 0:_m.last_name,street_address:(_o=order?.shipping_address)===null||_o===void 0?void 0:_o.line_1,street_address2:(_p=order?.shipping_address)===null||_p===void 0?void 0:_p.line_2,postal_code:(_q=order?.shipping_address)===null||_q===void 0?void 0:_q.zip_code,city:(_r=order?.shipping_address)===null||_r===void 0?void 0:_r.city,region:(_s=order?.shipping_address)===null||_s===void 0?void 0:_s.state_code,phone:(_t=order?.shipping_address)===null||_t===void 0?void 0:_t.phone,country:(_u=order?.shipping_address)===null||_u===void 0?void 0:_u.country_code}})}return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsx)("div",{id:"klarna-payments-container"})}))})}exports.default=KlarnaPayment;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript"));function typeOfLine(lineItemType){switch(lineItemType){case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical";case"payment_methods":default:return null}}function klarnaOrderLines(lineItems){return lineItems?lineItems?.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}function KlarnaPayment(_a){var{clientToken,placeOrderCallback,locale="EN"}=_a,p=tslib_1.__rest(_a,["clientToken","placeOrderCallback","locale"]);const ref=(0,react_1.useRef)(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),loaded=(0,useExternalScript_1.default)("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=(0,react_1.useState)(),{containerClassName}=p,divProps=tslib_1.__rest(p,["containerClassName"]);(0,react_1.useEffect)(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=props=>tslib_1.__awaiter(this,void 0,void 0,function*(){handleClick(klarna,props)}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=(kl,props)=>{var _a2,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r;console.log("props",props);const[first]=paymentSource?.payment_methods||void 0,paymentMethodCategories=first?.identifier,billingAddress={given_name:(_a2=order?.billing_address)===null||_a2===void 0?void 0:_a2.first_name,family_name:(_b=order?.billing_address)===null||_b===void 0?void 0:_b.last_name,email:order?.customer_email,street_address:(_c=order?.billing_address)===null||_c===void 0?void 0:_c.line_1,street_address2:null,organization_name:null,postal_code:(_d=order?.billing_address)===null||_d===void 0?void 0:_d.zip_code,city:(_e=order?.billing_address)===null||_e===void 0?void 0:_e.city,region:(_f=order?.billing_address)===null||_f===void 0?void 0:_f.state_code,phone:(_g=order?.billing_address)===null||_g===void 0?void 0:_g.phone,country:(_h=order?.billing_address)===null||_h===void 0?void 0:_h.country_code},shippingAddress={given_name:(_j=order?.shipping_address)===null||_j===void 0?void 0:_j.first_name,family_name:(_k=order?.shipping_address)===null||_k===void 0?void 0:_k.last_name,email:order?.customer_email,street_address:(_l=order?.shipping_address)===null||_l===void 0?void 0:_l.line_1,street_address2:null,postal_code:(_m=order?.shipping_address)===null||_m===void 0?void 0:_m.zip_code,organization_name:null,city:(_o=order?.shipping_address)===null||_o===void 0?void 0:_o.city,region:(_p=order?.shipping_address)===null||_p===void 0?void 0:_p.state_code,phone:(_q=order?.shipping_address)===null||_q===void 0?void 0:_q.phone,country:(_r=order?.shipping_address)===null||_r===void 0?void 0:_r.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address:shippingAddress,billing_address:billingAddress,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items),order_tax_amount:order?.total_tax_amount_cents};kl.Payments.authorize(Object.assign({payment_method_category:paymentMethodCategories},klarnaData),function(res){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(console.log("res",res),res.approved&&paymentSource&&currentPaymentMethodType){const ps=yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}});if(props.setPlaceOrder!=null){const placed=yield props.setPlaceOrder({paymentSource:ps});placed&&props.onclickCallback!=null&&props.onclickCallback(placed)}}})})};if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier})}return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsx)("div",{id:"klarna-payments-container"})}))})}exports.default=KlarnaPayment;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LoaderType } from '../../typings/index';
2
3
  import { type CustomerCardsTemplateChildren } from '../utils/PaymentCardsTemplate';
3
4
  export interface CustomerCardsProps {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type IconBrand } from '../../context/PaymentSourceContext';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type IconBrand } from '../../context/PaymentSourceContext';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  interface CustomComponent extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { ChildrenFunction } from '../../typings/index';
2
3
  export type PaymentSourceDetailType = 'last4' | 'exp_year' | 'exp_month';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  interface Props {
2
3
  clientSecret: string;
3
4
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type StripeElementLocale, type StripeElementsOptions, type StripePaymentElementOptions } from '@stripe/stripe-js';
2
3
  import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
3
4
  import { type PaymentSourceProps } from './PaymentSource';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export interface WireTransferConfig {
2
3
  infoMessage?: {
3
4
  text?: string | JSX.Element[];
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type Price as PriceType } from '@commercelayer/sdk';
2
3
  import { type ChildrenFunction, type LoaderType } from '../../typings/index';
3
4
  interface PriceChildrenProps extends Omit<PriceProps, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LoaderType } from '../../typings/index';
2
3
  interface Props {
3
4
  children: JSX.Element | JSX.Element[];
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?tslib_1.__awaiter(this,void 0,void 0,function*(){var _a;for(const shipment of shipments){const isSingle=((_a=shipment?.available_shipping_methods)===null||_a===void 0?void 0:_a.length)===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=yield setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}}):setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{var _a,_b;const shipmentLineItems=shipment.stock_line_items,lineItems=shipmentLineItems?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?(_a=shippingMethods[0])===null||_a===void 0?void 0:_a.id:(_b=shipment.shipping_method)===null||_b===void 0?void 0:_b.id;console.table([{shippingMethods},{shipment}]);const stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>{var _a2,_b2;return((_a2=time.stock_location)===null||_a2===void 0?void 0:_a2.id)===((_b2=shipment.stock_location)===null||_b2===void 0?void 0:_b2.id)}),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:shipment?.id};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,{value:shipmentProps,children},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?tslib_1.__awaiter(this,void 0,void 0,function*(){var _a;for(const shipment of shipments){const isSingle=((_a=shipment?.available_shipping_methods)===null||_a===void 0?void 0:_a.length)===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=yield setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}}):setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{var _a,_b;const shipmentLineItems=shipment.stock_line_items,lineItems=shipmentLineItems?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?(_a=shippingMethods[0])===null||_a===void 0?void 0:_a.id:(_b=shipment.shipping_method)===null||_b===void 0?void 0:_b.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>{var _a2,_b2;return((_a2=time.stock_location)===null||_a2===void 0?void 0:_a2.id)===((_b2=shipment.stock_location)===null||_b2===void 0?void 0:_b2.id)}),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:shipment?.id};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,{value:shipmentProps,children},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type Shipment } from '@commercelayer/sdk';
2
3
  type ShipmentFieldChildrenProps = Omit<Props, 'children'> & {
3
4
  shipment: Shipment;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{console.log("order?.shipments",order?.shipments),order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order?.shipments]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>{var _a,_b,_c,_d;return!!(((_a=lineItem.item)===null||_a===void 0?void 0:_a.do_not_ship)||((_b=lineItem.item)===null||_b===void 0?void 0:_b.do_not_track)||((_d=(_c=lineItem.item)===null||_c===void 0?void 0:_c.inventory)===null||_d===void 0?void 0:_d.quantity)>=lineItem?.quantity)}).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>Object.assign(Object.assign({},state),{setShipmentErrors:errors=>{ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch)},setShippingMethod:(shipmentId,shippingMethodId)=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,{value:contextValue,children})}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order?.shipments]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>{var _a,_b,_c,_d;return!!(((_a=lineItem.item)===null||_a===void 0?void 0:_a.do_not_ship)||((_b=lineItem.item)===null||_b===void 0?void 0:_b.do_not_track)||((_d=(_c=lineItem.item)===null||_c===void 0?void 0:_c.inventory)===null||_d===void 0?void 0:_d.quantity)>=lineItem?.quantity)}).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>Object.assign(Object.assign({},state),{setShipmentErrors:errors=>{ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch)},setShippingMethod:(shipmentId,shippingMethodId)=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,{value:contextValue,children})}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { Shipment } from '@commercelayer/sdk';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ShippingMethod } from '@commercelayer/sdk';
2
3
  type ChildrenProps = Omit<Props, 'children'> & {
3
4
  label: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  type Props = BaseAmountComponent & {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { Order, ShippingMethod } from '@commercelayer/sdk';
2
3
  interface ShippingMethodRadioButtonType extends Omit<Props, 'children'> {
3
4
  shippingMethod: ShippingMethod;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type TimeFormat, type ChildrenFunction } from '../../typings/index';
2
3
  import { type DeliveryLeadTime } from '../../reducers/AvailabilityReducer';
3
4
  interface AvailabilityTemplateChildrenProps extends Omit<Props, 'children'>, DeliveryLeadTime {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export type DeliveryLeadTimeField = 'min_hours' | 'max_hours' | 'min_days' | 'max_days';
2
3
  export type DeliveryLeadTimeComponentChildren = Omit<Props, 'children'>;
3
4
  type Props = Partial<JSX.IntrinsicElements['span']> & {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type SkuFieldChildrenProps = TGenericChildrenProps<TResources['Sku']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['StockTransfer']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { Address } from '@commercelayer/sdk';
2
3
  import AddressChildrenContext from '../../context/AddressChildrenContext';
3
4
  import { type ChildrenFunction } from '../../typings/index';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PropsType } from '../../utils/PropsType';
2
3
  import { type baseOrderPricePropTypes } from '../../typings/index';
3
4
  export type BaseOrderPriceProps = PropsType<typeof baseOrderPricePropTypes, unknown> & Omit<JSX.IntrinsicElements['span'], 'children'>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PaymentResource } from '../../reducers/PaymentMethodReducer';
2
3
  import PaymentSourceContext, { type IconBrand } from '../../context/PaymentSourceContext';
3
4
  import { type ChildrenFunction } from '../../typings/index';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PriceProps } from '../prices/Price';
2
3
  export type PTemplateProps = {
3
4
  formattedAmount?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LineItem } from '@commercelayer/sdk';
2
3
  import { type BaseError } from '../../typings/errors';
3
4
  import { type TResourceError } from '../errors/Errors';
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveAddresses=exports.setCloneAddress=exports.setAddress=exports.setAddressErrors=exports.addressInitialState=exports.addressFields=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),camelCase_1=tslib_1.__importDefault(require("lodash/camelCase"));exports.addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],exports.addressInitialState={errors:[]};const 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}})};exports.setAddressErrors=setAddressErrors;const setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})};exports.setAddress=setAddress;const setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${(0,camelCase_1.default)(resource)}Id`]:id}})};exports.setCloneAddress=setCloneAddress;function saveAddresses({config,updateOrder,order,state,customerEmail}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){const{shipToDifferentAddress,billing_address:billingAddress,shipping_address:shippingAddress,billingAddressId,shippingAddressId}=state;try{const sdk=(0,getSdk_1.default)(config);if(order){const currentBillingAddressRef=(_a=order?.billing_address)===null||_a===void 0?void 0:_a.reference,orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId,customer_email:customerEmail};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=(_b=order?.billing_address)===null||_b===void 0?void 0:_b.id,orderAttributes._shipping_address_clone_id=(_c=order?.shipping_address)===null||_c===void 0?void 0:_c.id),!(0,isEmpty_1.default)(billingAddress)&&billingAddress){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._shipping_address_same_as_billing=!0;const address=yield sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._shipping_address_same_as_billing,shippingAddressId&&(orderAttributes._shipping_address_clone_id=shippingAddressId),!(0,isEmpty_1.default)(shippingAddress)&&shippingAddress)){delete orderAttributes._shipping_address_clone_id;const address=yield sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(!(0,isEmpty_1.default)(orderAttributes)&&updateOrder){const orderUpdated=yield updateOrder({id:order.id,attributes:orderAttributes});return{success:!0,order:orderUpdated?.order}}}return{success:!1}}catch(error){return console.error(error),{success:!1,error}}})}exports.saveAddresses=saveAddresses;const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"],addressReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=addressReducer;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveAddresses=exports.setCloneAddress=exports.setAddress=exports.setAddressErrors=exports.addressInitialState=exports.addressFields=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),camelCase_1=tslib_1.__importDefault(require("lodash/camelCase"));exports.addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],exports.addressInitialState={errors:[]};const 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}})};exports.setAddressErrors=setAddressErrors;const setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})};exports.setAddress=setAddress;const setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${(0,camelCase_1.default)(resource)}Id`]:id}})};exports.setCloneAddress=setCloneAddress;function saveAddresses({config,updateOrder,order,state,customerEmail}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){const{shipToDifferentAddress,billing_address:billingAddress,shipping_address:shippingAddress,billingAddressId,shippingAddressId}=state;try{const sdk=(0,getSdk_1.default)(config);if(order){const currentBillingAddressRef=(_a=order?.billing_address)===null||_a===void 0?void 0:_a.reference;console.log("billingAddress",billingAddress),console.log("shippingAddress",shippingAddress);const orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId,customer_email:customerEmail};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=(_b=order?.billing_address)===null||_b===void 0?void 0:_b.id,orderAttributes._shipping_address_clone_id=(_c=order?.shipping_address)===null||_c===void 0?void 0:_c.id),!(0,isEmpty_1.default)(billingAddress)&&billingAddress){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._shipping_address_same_as_billing=!0;const address=yield sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._shipping_address_same_as_billing,shippingAddressId&&(orderAttributes._shipping_address_clone_id=shippingAddressId),!(0,isEmpty_1.default)(shippingAddress)&&shippingAddress)){delete orderAttributes._shipping_address_clone_id;const address=yield sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(!(0,isEmpty_1.default)(orderAttributes)&&updateOrder){const orderUpdated=yield updateOrder({id:order.id,attributes:orderAttributes});return{success:!0,order:orderUpdated?.order}}}return{success:!1}}catch(error){return console.error(error),{success:!1,error}}})}exports.saveAddresses=saveAddresses;const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"],addressReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=addressReducer;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export type DefaultChildrenType = JSX.Element[] | JSX.Element | null;
2
3
  type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
3
4
  export type TRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
@@ -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;
@@ -10,7 +10,7 @@ interface CardDetails {
10
10
  }
11
11
  interface Args {
12
12
  paymentType: PaymentResource;
13
- customerPayment: Partial<CustomerPaymentSource>;
13
+ customerPayment: CustomerPaymentSource;
14
14
  }
15
15
  export default function getCardDetails({ paymentType, customerPayment }: Args): CardDetails;
16
16
  export {};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps?.payment_response)===null||_a===void 0?void 0:_a.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":{const ps=customerPayment.payment_source,source=((_e=(_c=(_b=ps?.options)===null||_b===void 0?void 0:_b.card)!==null&&_c!==void 0?_c:(_d=ps?.payment_method)===null||_d===void 0?void 0:_d.card)!==null&&_e!==void 0?_e:ps?.payment_instrument)?{brand:(_f=ps?.payment_instrument)===null||_f===void 0?void 0:_f.card_type,exp_month:(_g=ps?.payment_instrument)===null||_g===void 0?void 0:_g.card_expiry_month,exp_year:(_h=ps?.payment_instrument)===null||_h===void 0?void 0:_h.card_expiry_year,last4:(_j=ps?.payment_instrument)===null||_j===void 0?void 0:_j.card_last_digits,issuer_type:(_k=ps?.payment_instrument)===null||_k===void 0?void 0:_k.issuer_type}:void 0;if(source)return Object.assign({},source);break}case"braintree_payments":{const ps=customerPayment.payment_source,source=(_l=ps?.options)===null||_l===void 0?void 0:_l.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_m=ps?.payment_request_data)===null||_m===void 0?void 0:_m.payment_method,authorized=((_o=ps?.payment_response)===null||_o===void 0?void 0:_o.resultCode)==="Authorised",last4=(_t=(_r=(_q=(_p=ps?.payment_response)===null||_p===void 0?void 0:_p.additionalData)===null||_q===void 0?void 0:_q.cardSummary)!==null&&_r!==void 0?_r:(_s=ps?.payment_instrument)===null||_s===void 0?void 0:_s.card_last_digits)!==null&&_t!==void 0?_t:"****";if(source&&authorized){const brand=source.type==="scheme"?(_u=source.brand)!==null&&_u!==void 0?_u:"credit-card":source.type.replace("_account","");return Object.assign(Object.assign({},source),{last4,brand})}break}default:{const ps=customerPayment.payment_source,source=(_v=ps?.metadata)===null||_v===void 0?void 0:_v.card;if(source)return Object.assign({},source);break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****",issuer_type:""}}exports.default=getCardDetails;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function getCardDetails({paymentType,customerPayment}){var _a,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v,_w;switch(paymentType){case"checkout_com_payments":{const ps=customerPayment.payment_source,source=(_a=ps?.payment_response)===null||_a===void 0?void 0:_a.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":{const ps=customerPayment.payment_source,source=((_e=(_c=(_b=ps?.options)===null||_b===void 0?void 0:_b.card)!==null&&_c!==void 0?_c:(_d=ps?.payment_method)===null||_d===void 0?void 0:_d.card)!==null&&_e!==void 0?_e:ps?.payment_instrument)?{brand:(_f=ps?.payment_instrument)===null||_f===void 0?void 0:_f.card_type,exp_month:(_g=ps?.payment_instrument)===null||_g===void 0?void 0:_g.card_expiry_month,exp_year:(_h=ps?.payment_instrument)===null||_h===void 0?void 0:_h.card_expiry_year,last4:(_j=ps?.payment_instrument)===null||_j===void 0?void 0:_j.card_last_digits,issuer_type:(_k=ps?.payment_instrument)===null||_k===void 0?void 0:_k.issuer_type}:void 0;if(source)return Object.assign({},source);break}case"klarna_payments":{const ps=customerPayment.payment_source,source=ps?.payment_instrument?{brand:"klarna",exp_month:"",exp_year:"",last4:"",issuer_type:(_l=ps?.payment_instrument)===null||_l===void 0?void 0:_l.issuer_type}:void 0;if(source)return Object.assign({},source);break}case"braintree_payments":{const ps=customerPayment.payment_source,source=(_m=ps?.options)===null||_m===void 0?void 0:_m.card;if(source)return Object.assign({},source);break}case"adyen_payments":{const ps=customerPayment.payment_source,source=(_o=ps?.payment_request_data)===null||_o===void 0?void 0:_o.payment_method,authorized=((_p=ps?.payment_response)===null||_p===void 0?void 0:_p.resultCode)==="Authorised",last4=(_u=(_s=(_r=(_q=ps?.payment_response)===null||_q===void 0?void 0:_q.additionalData)===null||_r===void 0?void 0:_r.cardSummary)!==null&&_s!==void 0?_s:(_t=ps?.payment_instrument)===null||_t===void 0?void 0:_t.card_last_digits)!==null&&_u!==void 0?_u:"****";if(source&&authorized){const brand=source.type==="scheme"?(_v=source.brand)!==null&&_v!==void 0?_v:"credit-card":source.type.replace("_account","");return Object.assign(Object.assign({},source),{last4,brand})}break}default:{const ps=customerPayment.payment_source,source=(_w=ps?.metadata)===null||_w===void 0?void 0:_w.card;if(source)return Object.assign({},source);break}}return{brand:"",exp_month:"**",exp_year:"**",last4:"****",issuer_type:""}}exports.default=getCardDetails;
@@ -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;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isDoNotShip=exports.shipmentsFilled=void 0;const tslib_1=require("tslib"),compact_1=tslib_1.__importDefault(require("lodash/compact")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function shipmentsFilled(shipments){const filled=(0,compact_1.default)(shipments.filter(shipment=>!(0,isEmpty_1.default)(shipment.shipping_method)));return!(0,isEmpty_1.default)(filled)}exports.shipmentsFilled=shipmentsFilled;function isDoNotShip(lineItems){const itemDoNotShip=[],items=lineItems?lineItems.filter(({item_type})=>item_type==="skus").map(lineItem=>{var _a;return lineItem.item&&(!((_a=lineItem?.item)===null||_a===void 0)&&_a.do_not_ship)&&itemDoNotShip.push(!0),lineItem}):[];return itemDoNotShip.length>0&&itemDoNotShip.length===items.length}exports.isDoNotShip=isDoNotShip;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isDoNotShip=exports.shipmentsFilled=void 0;const tslib_1=require("tslib"),compact_1=tslib_1.__importDefault(require("lodash/compact")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function shipmentsFilled(shipments){const filled=(0,compact_1.default)(shipments.filter(shipment=>!(0,isEmpty_1.default)(shipment.shipping_method)));return!(0,isEmpty_1.default)(filled)}exports.shipmentsFilled=shipmentsFilled;function isDoNotShip(lineItems){const itemDoNotShip=[],items=lineItems?lineItems.filter(({item_type})=>item_type==="skus").map(lineItem=>{var _a;return!((_a=lineItem.item)===null||_a===void 0)&&_a.do_not_ship&&itemDoNotShip.push(!0),lineItem}):[];return itemDoNotShip.length>0&&itemDoNotShip.length===items.length}exports.isDoNotShip=isDoNotShip;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.businessMandatoryField=exports.fieldsExist=exports.validateValue=void 0;const tslib_1=require("tslib"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),isString_1=tslib_1.__importDefault(require("lodash/isString")),without_1=tslib_1.__importDefault(require("lodash/without")),keys_1=tslib_1.__importDefault(require("lodash/keys")),map_1=tslib_1.__importDefault(require("lodash/map")),AddressReducer_1=require("../reducers/AddressReducer"),EMAIL_PATTERN=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/,validateValue=(val,name,type,resourceType)=>val?type==="email"&&(0,isString_1.default)(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};exports.validateValue=validateValue;const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return(0,map_1.default)(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=(0,exports.validateValue)(val,v.name,v.type,resourceType);(0,isEmpty_1.default)(error)||errors.push(error),values=Object.assign(Object.assign({},values),{[`${v.name}`]:val})}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?Object.assign(Object.assign({},values),{metadata:Object.assign(Object.assign({},values.metadata),{[`${v.name}`]:val})}):Object.assign(Object.assign({},values),{[`${v.name}`]:val}))}),{errors,values}},fieldsExist=(address,schema=AddressReducer_1.addressFields)=>{if(address.business){const required=(0,without_1.default)(schema,"first_name","last_name"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=(0,without_1.default)(schema,"line_2","company"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}};exports.fieldsExist=fieldsExist;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"];function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}exports.businessMandatoryField=businessMandatoryField,exports.default=validateFormFields;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.businessMandatoryField=exports.fieldsExist=exports.validateValue=void 0;const tslib_1=require("tslib"),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),isString_1=tslib_1.__importDefault(require("lodash/isString")),without_1=tslib_1.__importDefault(require("lodash/without")),keys_1=tslib_1.__importDefault(require("lodash/keys")),map_1=tslib_1.__importDefault(require("lodash/map")),AddressReducer_1=require("../reducers/AddressReducer"),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,}))$/,validateValue=(val,name,type,resourceType)=>val?type==="email"&&(0,isString_1.default)(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};exports.validateValue=validateValue;const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return(0,map_1.default)(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=(0,exports.validateValue)(val,v.name,v.type,resourceType);(0,isEmpty_1.default)(error)||errors.push(error),values=Object.assign(Object.assign({},values),{[`${v.name}`]:val})}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?Object.assign(Object.assign({},values),{metadata:Object.assign(Object.assign({},values.metadata),{[`${v.name}`]:val})}):Object.assign(Object.assign({},values),{[`${v.name}`]:val}))}),{errors,values}},fieldsExist=(address,schema=AddressReducer_1.addressFields)=>{if(address.business){const required=(0,without_1.default)(schema,"first_name","last_name","line_2"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=(0,without_1.default)(schema,"line_2","company"),validAddress=(0,keys_1.default)(address).filter(k=>required.includes(k));return required.length>validAddress.length}};exports.fieldsExist=fieldsExist;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"];function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}exports.businessMandatoryField=businessMandatoryField,exports.default=validateFormFields;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps } from '../typings/index';
2
3
  type Props = BaseInputComponentProps & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
3
4
  export declare function MetadataInput(props: Props): JSX.Element;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type Address as AddressType } from '@commercelayer/sdk';
2
3
  import { type AddressCardsTemplateChildren } from '../utils/AddressCardsTemplate';
3
4
  import type { DefaultChildrenType } from '../../typings/globals';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseSelectComponentProps } from '../../typings/index';
2
3
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
3
4
  type TCountryFieldName = 'billing_address_country_code' | 'shipping_address_country_code' | 'customer_address_country_code';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps, type AddressInputName } from '../../typings/index';
2
3
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
3
4
  type Props = {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type AddressStateSelectName, type BaseSelectComponentProps } from '../../typings/index';
2
3
  type Props = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
3
4
  name: AddressStateSelectName;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
3
4
  /**
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../../context/BillingAddressFormContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../../utils/localStorage";import{businessMandatoryField}from"../../utils/validateFormFields";export function BillingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,...p}=props,{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(values&&Object.keys(values).length>0){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;["billing_address_state_code"].includes(fieldName)?values?.state_code?formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName}):delete errors[fieldName]:formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=ref.current?.querySelector('[name="billing_address_save_to_customer_book"]')?.checked||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&ref&&(ref.current?.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"}))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:{...values,...field,...isBusiness&&{business:isBusiness}},resource:"billing_address"})},errorClassName,requiresBillingInfo:order?.requires_billing_info||!1,errors,resetField:name=>{resetForm({currentTarget:ref.current},name)}};return _jsx(BillingAddressFormContext.Provider,{value:providerValues,children:_jsx("form",{ref,autoComplete,...p,children})})}export default BillingAddressForm;
2
+ import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../../context/BillingAddressFormContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../../utils/localStorage";export function BillingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,...p}=props,{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(values&&Object.keys(values).length>0){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;["billing_address_state_code"].includes(fieldName)?values?.state_code?formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName}):delete errors[fieldName]:formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=ref.current?.querySelector('[name="billing_address_save_to_customer_book"]')?.checked||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&(ref.current?.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:{...values,...field,...isBusiness&&{business:isBusiness}},resource:"billing_address"})},errorClassName,requiresBillingInfo:order?.requires_billing_info||!1,errors,resetField:name=>{resetForm({currentTarget:ref.current},name)}};return _jsx(BillingAddressFormContext.Provider,{value:providerValues,children:_jsx("form",{ref,autoComplete,...p,children})})}export default BillingAddressForm;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import ShippingAddressFormContext from"../../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import{getSaveShippingAddressToAddressBook}from"../../utils/localStorage";import{businessMandatoryField}from"../../utils/validateFormFields";export function ShippingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,...p}=props,{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,shipToDifferentAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address"}),isEmpty(errors)){if(!isEmpty(values)&&shipToDifferentAddress){setAddressErrors([],"shipping_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("shipping_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"shipping_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"shipping_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;["shipping_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message:message||"",resource:"shipping_address",field:fieldName}):formErrors.push({code,message:message||"",resource:"shipping_address",field:fieldName})}shipToDifferentAddress&&setAddressErrors(formErrors,"shipping_address")}const checkboxChecked=ref.current?.querySelector('[name="shipping_address_save_to_customer_book"]')?.checked||getSaveShippingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"shipping_address",value:!1}),ref&&(ref.current?.reset(),resetForm({target:ref.current}),setAddressErrors([],"shipping_address"),setAddress({values:{},resource:"shipping_address"})))},[values,errors,shipToDifferentAddress,reset,include,includeLoaded,isBusiness]);const providerValues={values,validation,setValue:(name,value)=>{const field={[name.replace("shipping_address_","")]:value};setAddress({values:{...values,...field,...isBusiness&&{business:isBusiness}},resource:"shipping_address"})},errorClassName,errors,resetField:name=>{resetForm({currentTarget:ref.current},name)}};return _jsx(ShippingAddressFormContext.Provider,{value:providerValues,children:_jsx("form",{ref,autoComplete,...p,children})})}export default ShippingAddressForm;
2
+ import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import ShippingAddressFormContext from"../../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import{getSaveShippingAddressToAddressBook}from"../../utils/localStorage";export function ShippingAddressForm(props){const{children,errorClassName,autoComplete="on",reset=!1,...p}=props,{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,shipToDifferentAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address"}),isEmpty(errors)){if(!isEmpty(values)&&shipToDifferentAddress){setAddressErrors([],"shipping_address");for(const name in values){const field=values[name];(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("shipping_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"shipping_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"shipping_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;["shipping_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message:message||"",resource:"shipping_address",field:fieldName}):formErrors.push({code,message:message||"",resource:"shipping_address",field:fieldName})}shipToDifferentAddress&&setAddressErrors(formErrors,"shipping_address")}const checkboxChecked=ref.current?.querySelector('[name="shipping_address_save_to_customer_book"]')?.checked||getSaveShippingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"shipping_address",value:!1}),ref&&(ref.current?.reset(),resetForm({target:ref.current}),setAddressErrors([],"shipping_address"),setAddress({values:{},resource:"shipping_address"})))},[values,errors,shipToDifferentAddress,reset,include,includeLoaded,isBusiness]);const providerValues={values,validation,setValue:(name,value)=>{const field={[name.replace("shipping_address_","")]:value};setAddress({values:{...values,...field,...isBusiness&&{business:isBusiness}},resource:"shipping_address"})},errorClassName,errors,resetField:name=>{resetForm({currentTarget:ref.current},name)}};return _jsx(ShippingAddressFormContext.Provider,{value:providerValues,children:_jsx("form",{ref,autoComplete,...p,children})})}export default ShippingAddressForm;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['Customer']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps } from '../../typings/index';
2
3
  type Props = {
3
4
  name?: 'customer_email' | string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children?: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { CodeErrorType } from '../../typings/errors';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  export type TResourceError = 'addresses' | 'billing_address' | 'gift_cards' | 'gift_card_or_coupon_code' | 'line_items' | 'orders' | 'payment_methods' | 'prices' | 'shipments' | 'shipping_address' | 'customer_address' | 'sku_options' | 'variant' | 'in_stock_subscriptions';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseState } from '../../typings/index';
2
3
  import type { DefaultChildrenType } from '../../typings/globals';
3
4
  interface Props extends Omit<JSX.IntrinsicElements['form'], 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseSelectComponentProps } from '../../typings/index';
2
3
  type Props = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
3
4
  required?: boolean;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps, type GiftCardInputName } from '../../typings/index';
2
3
  type Props = {
3
4
  name: GiftCardInputName;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { CodeType } from '../../reducers/OrderReducer';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { Order } from '@commercelayer/sdk';
2
3
  import type { DefaultChildrenType } from '../../typings/globals';
3
4
  interface Props extends Omit<JSX.IntrinsicElements['form'], 'onSubmit'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps } from '../../typings/index';
2
3
  import { type OrderCodeType } from '../../reducers/OrderReducer';
3
4
  type Props = {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['button'], 'children' | 'onClick'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  /**