@commercelayer/react-components 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (233) hide show
  1. package/lib/cjs/components/SubmitButton.d.ts +6 -15
  2. package/lib/cjs/components/SubmitButton.js +1 -1
  3. package/lib/cjs/components/addresses/Address.d.ts +4 -9
  4. package/lib/cjs/components/addresses/Address.js +1 -1
  5. package/lib/cjs/components/addresses/AddressField.d.ts +8 -12
  6. package/lib/cjs/components/addresses/AddressField.js +1 -1
  7. package/lib/cjs/components/addresses/AddressInput.d.ts +0 -11
  8. package/lib/cjs/components/addresses/AddressInput.js +1 -1
  9. package/lib/cjs/components/addresses/AddressesContainer.d.ts +2 -9
  10. package/lib/cjs/components/addresses/AddressesContainer.js +1 -1
  11. package/lib/cjs/components/addresses/AddressesEmpty.d.ts +14 -0
  12. package/lib/cjs/components/addresses/AddressesEmpty.js +1 -0
  13. package/lib/cjs/components/addresses/SaveAddressesButton.d.ts +4 -3
  14. package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
  15. package/lib/cjs/components/auth/CommerceLayer.d.ts +2 -9
  16. package/lib/cjs/components/auth/CommerceLayer.js +1 -1
  17. package/lib/cjs/components/customers/CustomerContainer.d.ts +2 -2
  18. package/lib/cjs/components/customers/CustomerContainer.js +1 -1
  19. package/lib/cjs/components/customers/SaveCustomerButton.d.ts +6 -7
  20. package/lib/cjs/components/customers/SaveCustomerButton.js +1 -1
  21. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +8 -16
  22. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.js +1 -1
  23. package/lib/cjs/components/gift_cards/GiftCardOrCouponRemoveButton.d.ts +4 -12
  24. package/lib/cjs/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -1
  25. package/lib/cjs/components/gift_cards/GiftCardOrCouponSubmit.d.ts +6 -12
  26. package/lib/cjs/components/gift_cards/GiftCardOrCouponSubmit.js +1 -1
  27. package/lib/cjs/components/line_items/LineItemOption.d.ts +2 -2
  28. package/lib/cjs/components/line_items/LineItemQuantity.d.ts +4 -16
  29. package/lib/cjs/components/line_items/LineItemQuantity.js +1 -1
  30. package/lib/cjs/components/line_items/LineItemRemoveLink.d.ts +6 -16
  31. package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
  32. package/lib/cjs/components/line_items/LineItemsCount.d.ts +4 -14
  33. package/lib/cjs/components/line_items/LineItemsCount.js +1 -1
  34. package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +6 -17
  35. package/lib/cjs/components/line_items/LineItemsEmpty.js +1 -1
  36. package/lib/cjs/components/orders/AddToCartButton.d.ts +4 -5
  37. package/lib/cjs/components/orders/AddToCartButton.js +1 -1
  38. package/lib/cjs/components/orders/CartLink.d.ts +6 -6
  39. package/lib/cjs/components/orders/CartLink.js +1 -1
  40. package/lib/cjs/components/orders/CheckoutLink.d.ts +4 -4
  41. package/lib/cjs/components/orders/CheckoutLink.js +1 -1
  42. package/lib/cjs/components/orders/ItemContainer.d.ts +2 -13
  43. package/lib/cjs/components/orders/ItemContainer.js +1 -1
  44. package/lib/cjs/components/orders/OrderContainer.d.ts +4 -18
  45. package/lib/cjs/components/orders/OrderContainer.js +1 -1
  46. package/lib/cjs/components/orders/OrderList.d.ts +11 -12
  47. package/lib/cjs/components/orders/OrderList.js +1 -1
  48. package/lib/cjs/components/orders/OrderListEmpty.d.ts +14 -0
  49. package/lib/cjs/components/orders/OrderListEmpty.js +1 -0
  50. package/lib/cjs/components/orders/OrderListRow.d.ts +9 -5
  51. package/lib/cjs/components/orders/OrderListRow.js +1 -1
  52. package/lib/cjs/components/orders/PlaceOrderButton.d.ts +4 -14
  53. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
  54. package/lib/cjs/components/parcels/Parcel.d.ts +6 -0
  55. package/lib/cjs/components/parcels/Parcel.js +1 -0
  56. package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
  57. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +4 -14
  58. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.js +1 -1
  59. package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +4 -11
  60. package/lib/cjs/components/payment_source/PaymentSourceBrandName.js +1 -1
  61. package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +6 -12
  62. package/lib/cjs/components/payment_source/PaymentSourceDetail.js +1 -1
  63. package/lib/cjs/components/payment_source/PaymentSourceEditButton.d.ts +4 -10
  64. package/lib/cjs/components/payment_source/PaymentSourceEditButton.js +1 -1
  65. package/lib/cjs/components/prices/Price.d.ts +6 -18
  66. package/lib/cjs/components/prices/Price.js +1 -1
  67. package/lib/cjs/components/prices/PricesContainer.d.ts +4 -20
  68. package/lib/cjs/components/prices/PricesContainer.js +1 -1
  69. package/lib/cjs/components/shipments/Shipment.d.ts +2 -8
  70. package/lib/cjs/components/shipments/Shipment.js +1 -1
  71. package/lib/cjs/components/shipments/ShipmentField.d.ts +0 -7
  72. package/lib/cjs/components/shipments/ShipmentField.js +1 -1
  73. package/lib/cjs/components/shipments/ShipmentsContainer.d.ts +2 -8
  74. package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -1
  75. package/lib/cjs/components/shipping_methods/ShippingMethod.d.ts +2 -9
  76. package/lib/cjs/components/shipping_methods/ShippingMethod.js +1 -1
  77. package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +0 -6
  78. package/lib/cjs/components/shipping_methods/ShippingMethodName.js +1 -1
  79. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +4 -13
  80. package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
  81. package/lib/cjs/components/skus/QuantitySelector.d.ts +4 -18
  82. package/lib/cjs/components/skus/QuantitySelector.js +1 -1
  83. package/lib/cjs/components/skus/VariantSelector.d.ts +4 -27
  84. package/lib/cjs/components/skus/VariantSelector.js +1 -1
  85. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +8 -8
  86. package/lib/cjs/components/utils/AddressCardsTemplate.js +1 -1
  87. package/lib/cjs/components/utils/BaseInput.d.ts +1 -1
  88. package/lib/cjs/components/utils/ErrorBoundary.d.ts +14 -0
  89. package/lib/cjs/components/utils/ErrorBoundary.js +1 -0
  90. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +2 -2
  91. package/lib/cjs/components/utils/PriceTemplate.d.ts +2 -2
  92. package/lib/cjs/components/utils/PriceTemplate.js +1 -1
  93. package/lib/cjs/context/BillingAddressFormContext.d.ts +2 -2
  94. package/lib/cjs/context/OrderContext.d.ts +3 -3
  95. package/lib/cjs/context/OrderListChildrenContext.d.ts +8 -0
  96. package/lib/cjs/context/ParcelChildrenContext.d.ts +7 -0
  97. package/lib/cjs/context/ParcelChildrenContext.js +1 -0
  98. package/lib/cjs/context/ShipmentChildrenContext.d.ts +6 -5
  99. package/lib/cjs/context/ShipmentChildrenContext.js +1 -1
  100. package/lib/cjs/index.d.ts +36 -34
  101. package/lib/cjs/index.js +1 -1
  102. package/lib/cjs/reducers/AddressReducer.d.ts +17 -23
  103. package/lib/cjs/reducers/AddressReducer.js +1 -1
  104. package/lib/cjs/reducers/CustomerReducer.d.ts +18 -20
  105. package/lib/cjs/reducers/CustomerReducer.js +1 -1
  106. package/lib/cjs/reducers/OrderReducer.d.ts +16 -29
  107. package/lib/cjs/reducers/OrderReducer.js +1 -1
  108. package/lib/cjs/reducers/ShipmentReducer.d.ts +1 -3
  109. package/lib/cjs/typings/errors.d.ts +2 -2
  110. package/lib/cjs/typings/index.d.ts +8 -16
  111. package/lib/cjs/utils/addressesManager.d.ts +5 -4
  112. package/lib/cjs/utils/getPrices.d.ts +4 -15
  113. package/lib/cjs/utils/getPrices.js +1 -1
  114. package/lib/cjs/utils/getSdk.d.ts +1 -1
  115. package/lib/cjs/utils/organization.d.ts +2 -2
  116. package/lib/esm/components/SubmitButton.d.ts +6 -15
  117. package/lib/esm/components/SubmitButton.js +1 -1
  118. package/lib/esm/components/addresses/Address.d.ts +4 -9
  119. package/lib/esm/components/addresses/Address.js +1 -1
  120. package/lib/esm/components/addresses/AddressField.d.ts +8 -12
  121. package/lib/esm/components/addresses/AddressField.js +1 -1
  122. package/lib/esm/components/addresses/AddressInput.d.ts +0 -11
  123. package/lib/esm/components/addresses/AddressInput.js +1 -1
  124. package/lib/esm/components/addresses/AddressesContainer.d.ts +2 -9
  125. package/lib/esm/components/addresses/AddressesContainer.js +1 -1
  126. package/lib/esm/components/addresses/AddressesEmpty.d.ts +14 -0
  127. package/lib/esm/components/addresses/AddressesEmpty.js +1 -0
  128. package/lib/esm/components/addresses/SaveAddressesButton.d.ts +4 -3
  129. package/lib/esm/components/addresses/SaveAddressesButton.js +1 -1
  130. package/lib/esm/components/auth/CommerceLayer.d.ts +2 -9
  131. package/lib/esm/components/auth/CommerceLayer.js +1 -1
  132. package/lib/esm/components/customers/CustomerContainer.d.ts +2 -2
  133. package/lib/esm/components/customers/CustomerContainer.js +1 -1
  134. package/lib/esm/components/customers/SaveCustomerButton.d.ts +6 -7
  135. package/lib/esm/components/customers/SaveCustomerButton.js +1 -1
  136. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +8 -16
  137. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.js +1 -1
  138. package/lib/esm/components/gift_cards/GiftCardOrCouponRemoveButton.d.ts +4 -12
  139. package/lib/esm/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -1
  140. package/lib/esm/components/gift_cards/GiftCardOrCouponSubmit.d.ts +6 -12
  141. package/lib/esm/components/gift_cards/GiftCardOrCouponSubmit.js +1 -1
  142. package/lib/esm/components/line_items/LineItemOption.d.ts +2 -2
  143. package/lib/esm/components/line_items/LineItemQuantity.d.ts +4 -16
  144. package/lib/esm/components/line_items/LineItemQuantity.js +1 -1
  145. package/lib/esm/components/line_items/LineItemRemoveLink.d.ts +6 -16
  146. package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -1
  147. package/lib/esm/components/line_items/LineItemsCount.d.ts +4 -14
  148. package/lib/esm/components/line_items/LineItemsCount.js +1 -1
  149. package/lib/esm/components/line_items/LineItemsEmpty.d.ts +6 -17
  150. package/lib/esm/components/line_items/LineItemsEmpty.js +1 -1
  151. package/lib/esm/components/orders/AddToCartButton.d.ts +4 -5
  152. package/lib/esm/components/orders/AddToCartButton.js +1 -1
  153. package/lib/esm/components/orders/CartLink.d.ts +6 -6
  154. package/lib/esm/components/orders/CartLink.js +1 -1
  155. package/lib/esm/components/orders/CheckoutLink.d.ts +4 -4
  156. package/lib/esm/components/orders/CheckoutLink.js +1 -1
  157. package/lib/esm/components/orders/ItemContainer.d.ts +2 -13
  158. package/lib/esm/components/orders/ItemContainer.js +1 -1
  159. package/lib/esm/components/orders/OrderContainer.d.ts +4 -18
  160. package/lib/esm/components/orders/OrderContainer.js +1 -1
  161. package/lib/esm/components/orders/OrderList.d.ts +11 -12
  162. package/lib/esm/components/orders/OrderList.js +1 -1
  163. package/lib/esm/components/orders/OrderListEmpty.d.ts +14 -0
  164. package/lib/esm/components/orders/OrderListEmpty.js +1 -0
  165. package/lib/esm/components/orders/OrderListRow.d.ts +9 -5
  166. package/lib/esm/components/orders/OrderListRow.js +1 -1
  167. package/lib/esm/components/orders/PlaceOrderButton.d.ts +4 -14
  168. package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
  169. package/lib/esm/components/parcels/Parcel.d.ts +6 -0
  170. package/lib/esm/components/parcels/Parcel.js +1 -0
  171. package/lib/esm/components/payment_source/AdyenPayment.js +1 -1
  172. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +4 -14
  173. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.js +1 -1
  174. package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +4 -11
  175. package/lib/esm/components/payment_source/PaymentSourceBrandName.js +1 -1
  176. package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +6 -12
  177. package/lib/esm/components/payment_source/PaymentSourceDetail.js +1 -1
  178. package/lib/esm/components/payment_source/PaymentSourceEditButton.d.ts +4 -10
  179. package/lib/esm/components/payment_source/PaymentSourceEditButton.js +1 -1
  180. package/lib/esm/components/prices/Price.d.ts +6 -18
  181. package/lib/esm/components/prices/Price.js +1 -1
  182. package/lib/esm/components/prices/PricesContainer.d.ts +4 -20
  183. package/lib/esm/components/prices/PricesContainer.js +1 -1
  184. package/lib/esm/components/shipments/Shipment.d.ts +2 -8
  185. package/lib/esm/components/shipments/Shipment.js +1 -1
  186. package/lib/esm/components/shipments/ShipmentField.d.ts +0 -7
  187. package/lib/esm/components/shipments/ShipmentField.js +1 -1
  188. package/lib/esm/components/shipments/ShipmentsContainer.d.ts +2 -8
  189. package/lib/esm/components/shipments/ShipmentsContainer.js +1 -1
  190. package/lib/esm/components/shipping_methods/ShippingMethod.d.ts +2 -9
  191. package/lib/esm/components/shipping_methods/ShippingMethod.js +1 -1
  192. package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +0 -6
  193. package/lib/esm/components/shipping_methods/ShippingMethodName.js +1 -1
  194. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +4 -13
  195. package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
  196. package/lib/esm/components/skus/QuantitySelector.d.ts +4 -18
  197. package/lib/esm/components/skus/QuantitySelector.js +1 -1
  198. package/lib/esm/components/skus/VariantSelector.d.ts +4 -27
  199. package/lib/esm/components/skus/VariantSelector.js +1 -1
  200. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +8 -8
  201. package/lib/esm/components/utils/AddressCardsTemplate.js +1 -1
  202. package/lib/esm/components/utils/BaseInput.d.ts +1 -1
  203. package/lib/esm/components/utils/ErrorBoundary.d.ts +14 -0
  204. package/lib/esm/components/utils/ErrorBoundary.js +1 -0
  205. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +2 -2
  206. package/lib/esm/components/utils/PriceTemplate.d.ts +2 -2
  207. package/lib/esm/components/utils/PriceTemplate.js +1 -1
  208. package/lib/esm/context/BillingAddressFormContext.d.ts +2 -2
  209. package/lib/esm/context/OrderContext.d.ts +3 -3
  210. package/lib/esm/context/OrderListChildrenContext.d.ts +8 -0
  211. package/lib/esm/context/ParcelChildrenContext.d.ts +7 -0
  212. package/lib/esm/context/ParcelChildrenContext.js +1 -0
  213. package/lib/esm/context/ShipmentChildrenContext.d.ts +6 -5
  214. package/lib/esm/context/ShipmentChildrenContext.js +1 -1
  215. package/lib/esm/index.d.ts +36 -34
  216. package/lib/esm/index.js +1 -1
  217. package/lib/esm/reducers/AddressReducer.d.ts +17 -23
  218. package/lib/esm/reducers/AddressReducer.js +1 -1
  219. package/lib/esm/reducers/CustomerReducer.d.ts +18 -20
  220. package/lib/esm/reducers/CustomerReducer.js +1 -1
  221. package/lib/esm/reducers/OrderReducer.d.ts +16 -29
  222. package/lib/esm/reducers/OrderReducer.js +1 -1
  223. package/lib/esm/reducers/ShipmentReducer.d.ts +1 -3
  224. package/lib/esm/typings/errors.d.ts +2 -2
  225. package/lib/esm/typings/index.d.ts +8 -16
  226. package/lib/esm/utils/addressesManager.d.ts +5 -4
  227. package/lib/esm/utils/getPrices.d.ts +4 -15
  228. package/lib/esm/utils/getPrices.js +1 -1
  229. package/lib/esm/utils/getSdk.d.ts +1 -1
  230. package/lib/esm/utils/organization.d.ts +2 -2
  231. package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
  232. package/lib/tsconfig.prod.tsbuildinfo +1 -1
  233. package/package.json +46 -35
@@ -1 +1 @@
1
- import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import size from"lodash/size";import map from"lodash/map";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=getSdk(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=getErrors(error,"orders");console.error("Create order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""},getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=getSdk(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.status==="placed"||order.status==="approved"||order.status==="cancelled"?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=getErrors(error,"orders");console.error("Retrieve order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch});return}};export async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=getSdk(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await getApiOrder({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0}}catch(error){const errors=getErrors(error,"orders");return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}export const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};export function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...resourcesIncluded,...resources],resources.forEach(resource=>{payload.includeLoaded={...payload.includeLoaded,[resource]:!0}})}else delete payload.include;payload.includeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded},dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}export const addToCart=async params=>{const{skuCode,bundleCode,skuId,quantity,option,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl}=params;try{if(!config)throw{errors:[{code:"INVALID_RESOURCE",resource:"orders",title:"Markup error",message:"You are trying to place an order outside the OrderContainer component"}]};const sdk=getSdk(config),id=await createOrder(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});line_items&&line_items?.length>0&&await Promise.all(line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity||1,_update_quantity:!0,bundle_code:bundleCode};skuId&&(attrs.item=sdk.skus.relationship(skuId));const newLineItem=await sdk.line_items.create(attrs);if(isEmpty(option))await getApiOrder({id,...params,state});else{let c=0;map(option,async opt=>{const{options,skuOptionId}=opt,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),c+=1,c===size(option)&&await getApiOrder({id,...params})})}if(!isEmpty(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=getOrganizationSlug(config.endpoint),params2=`${id}?accessToken=${config.accessToken}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}return{success:!1,orderId:void 0}}catch(error){const errors2=getErrors(error,"orders");return console.error("Add to cart",errors2),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1,orderId:void 0}}},unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};export function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}export const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value}`;setCustomerOrderParam(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})},setGiftCardOrCouponCode=async({code,codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},removeGiftCardOrCouponCode=async({codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&dispatch){const attributes={[codeType]:""};return await updateOrder({id:order.id,attributes,config,include,dispatch,state}),dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default orderReducer;
1
+ import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import size from"lodash/size";import map from"lodash/map";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=getSdk(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=getErrors(error,"orders");console.error("Create order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""},getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=getSdk(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.status==="placed"||order.status==="approved"||order.status==="cancelled"?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=getErrors(error,"orders");console.error("Retrieve order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch});return}};export async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=getSdk(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await getApiOrder({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0}}catch(error){const errors=getErrors(error,"orders");return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}export const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};export function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...resourcesIncluded,...resources],resources.forEach(resource=>{const includeLoaded={...payload.includeLoaded,[resource]:!0};payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded};payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}export const addToCart=async params=>{const{skuCode,bundleCode,skuId,quantity,option,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl}=params;try{if(!config)throw{errors:[{code:"INVALID_RESOURCE",resource:"orders",title:"Markup error",message:"You are trying to place an order outside the OrderContainer component"}]};const sdk=getSdk(config),id=await createOrder(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items:lineItems}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&await Promise.all(lineItems.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity||1,_update_quantity:!0,bundle_code:bundleCode};skuId&&(attrs.item=sdk.skus.relationship(skuId));const newLineItem=await sdk.line_items.create(attrs);if(isEmpty(option))await getApiOrder({id,...params,state});else{let c=0;map(option,async opt=>{const{options,skuOptionId}=opt,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),c+=1,c===size(option)&&await getApiOrder({id,...params})})}if(!isEmpty(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=getOrganizationSlug(config.endpoint),params2=`${id}?accessToken=${config.accessToken}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}return{success:!1,orderId:void 0}}catch(error){const errors2=getErrors(error,"orders");return console.error("Add to cart",errors2),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1,orderId:void 0}}},unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};export function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}export const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;setCustomerOrderParam(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})},setGiftCardOrCouponCode=async({code,codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},removeGiftCardOrCouponCode=async({codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&dispatch){const attributes={[codeType]:""};return await updateOrder({id:order.id,attributes,config,include,dispatch,state}),dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default orderReducer;
@@ -18,9 +18,7 @@ export interface ShipmentAction {
18
18
  payload: Partial<ShipmentActionPayload>;
19
19
  }
20
20
  export declare const shipmentInitialState: ShipmentState;
21
- export interface SetShipmentErrors {
22
- <V extends BaseError[]>(errors: V, dispatch?: Dispatch<ShipmentAction>): void;
23
- }
21
+ export declare type SetShipmentErrors = <V extends BaseError[]>(errors: V, dispatch?: Dispatch<ShipmentAction>) => void;
24
22
  export declare const setShipmentErrors: SetShipmentErrors;
25
23
  declare type GetShipments = (args: {
26
24
  order: Order;
@@ -1,5 +1,5 @@
1
1
  import PropTypes from 'prop-types';
2
- import { FunctionChildren } from './index';
2
+ import { ChildrenFunction } from './index';
3
3
  export declare type CodeErrorType = 'EMPTY_ERROR' | 'FILTER_NOT_ALLOWED' | 'FORBIDDEN' | 'INTERNAL_SERVER_ERROR' | 'INVALID_DATA_FORMAT' | 'INVALID_FIELD' | 'INVALID_FIELD_FORMAT' | 'INVALID_FIELD_VALUE' | 'INVALID_FILTERS_SYNTAX' | 'INVALID_FILTER_VALUE' | 'INVALID_INCLUDE' | 'INVALID_LINKS_OBJECT' | 'INVALID_PAGE_OBJECT' | 'INVALID_PAGE_VALUE' | 'INVALID_RESOURCE' | 'INVALID_RESOURCE_ID' | 'INVALID_SORT_CRITERIA' | 'INVALID_TOKEN' | 'KEY_NOT_INCLUDED_IN_URL' | 'KEY_ORDER_MISMATCH' | 'LOCKED' | 'NOT_ACCEPTABLE' | 'OUT_OF_STOCK' | 'PARAM_MISSING' | 'PARAM_NOT_ALLOWED' | 'PAYMENT_NOT_APPROVED_FOR_EXECUTION' | 'PAYMENT_INTENT_AUTHENTICATION_FAILURE' | 'RECORD_NOT_FOUND' | 'RECORD_NOT_FOUND' | 'RELATION_EXISTS' | 'NO_SHIPPING_METHODS' | 'SAVE_FAILED' | 'TYPE_MISMATCH' | 'UNAUTHORIZED' | 'UNSUPPORTED_MEDIA_TYPE' | 'VALIDATION_ERROR';
4
4
  export declare type ResourceErrorType = 'addresses' | 'billing_address' | 'gift_cards' | 'gift_card_or_coupon_code' | 'line_items' | 'orders' | 'payment_methods' | 'prices' | 'shipments' | 'shipping_address' | 'customer_address' | 'sku_options' | 'variant';
5
5
  export interface BaseError {
@@ -24,7 +24,7 @@ export declare const ErrorPropTypes: {
24
24
  children: PropTypes.Requireable<(...args: any[]) => any>;
25
25
  field: PropTypes.Requireable<string>;
26
26
  };
27
- declare type ErrorChildrenComponentProps = FunctionChildren<Omit<ErrorComponentProps, 'children'> & {
27
+ declare type ErrorChildrenComponentProps = ChildrenFunction<Omit<ErrorComponentProps, 'children'> & {
28
28
  errors: string[];
29
29
  }>;
30
30
  export declare type ErrorComponentProps = {
@@ -24,11 +24,11 @@ export declare const BaseSelectComponentPropTypes: {
24
24
  };
25
25
  export declare type SelectPlaceholder = Option;
26
26
  declare type BaseSelectChildrenComponentProps = Omit<BaseSelectComponentProps, 'children'>;
27
- declare type Option = {
27
+ interface Option {
28
28
  label: string;
29
29
  value: string | number;
30
30
  disabled?: boolean;
31
- };
31
+ }
32
32
  export interface BaseSelectComponentProps {
33
33
  children?: (props: BaseSelectChildrenComponentProps) => JSX.Element;
34
34
  options: Option[];
@@ -67,9 +67,9 @@ export declare type LoaderType = string | ReactNode;
67
67
  export declare const BMObject: PropTypes.Requireable<{
68
68
  [x: string]: string | null | undefined;
69
69
  }>;
70
- export declare type BaseMetadataObject = {
70
+ export interface BaseMetadataObject {
71
71
  [key: string]: string | undefined | null;
72
- };
72
+ }
73
73
  export declare type TimeFormat = 'days' | 'hours';
74
74
  export declare type BaseComponent = InferProps<typeof BC>;
75
75
  export interface BaseAction<A = string, P = Record<string, any>> {
@@ -81,15 +81,9 @@ export interface BaseState {
81
81
  errors?: BaseError[];
82
82
  }
83
83
  export declare type BaseActionType<T = string> = T[];
84
- export interface BFSetStateContainer<T> {
85
- <P extends T>(param: P): void;
86
- }
87
- export interface BaseReducer {
88
- <S extends BaseState, A extends BaseAction, T extends BaseActionType>(state: S, action: A, type: T): S;
89
- }
90
- export interface BaseUnsetState<A> {
91
- (dispatch: Dispatch<A>): void;
92
- }
84
+ export declare type BFSetStateContainer<T> = <P extends T>(param: P) => void;
85
+ export declare type BaseReducer = <S extends BaseState, A extends BaseAction, T extends BaseActionType>(state: S, action: A, type: T) => S;
86
+ export declare type BaseUnsetState<A> = (dispatch: Dispatch<A>) => void;
93
87
  export interface BaseMetadata {
94
88
  [key: string]: string | undefined | null;
95
89
  }
@@ -122,9 +116,7 @@ export declare type BaseAmountComponent = {
122
116
  priceCents?: number;
123
117
  labelFree?: string;
124
118
  } & JSX.IntrinsicElements['span'];
125
- export interface FunctionChildren<P = Record<string, any>> {
126
- (props: P): JSX.Element;
127
- }
119
+ export declare type ChildrenFunction<P = Record<string, any>> = (props: P) => JSX.Element;
128
120
  export declare type ExcludeTag<T extends keyof JSX.IntrinsicElements> = Exclude<keyof JSX.IntrinsicElements, T>;
129
121
  export declare type ExtractTag<T extends keyof JSX.IntrinsicElements> = Extract<keyof JSX.IntrinsicElements, T>;
130
122
  export declare type ConditionalElement<E> = ({
@@ -1,5 +1,6 @@
1
1
  import { BaseError } from '../typings/errors';
2
- import { AddressCreate } from '@commercelayer/sdk';
2
+ import { Address, AddressCreate } from '@commercelayer/sdk';
3
+ import { TCustomerAddress } from '../reducers/CustomerReducer';
3
4
  declare type BillingAddressController = (params: {
4
5
  billing_address?: AddressCreate;
5
6
  billingAddressId?: string;
@@ -16,12 +17,12 @@ declare type ShippingAddressController = (params: {
16
17
  }) => boolean;
17
18
  export declare const shippingAddressController: ShippingAddressController;
18
19
  declare type CountryLockController = (params: {
19
- addresses?: Record<string, any>[];
20
- billing_address?: Record<string, any>;
20
+ addresses?: Address[] | null;
21
+ billing_address?: TCustomerAddress;
21
22
  billingAddressId?: string;
22
23
  countryCodeLock?: string;
23
24
  shipToDifferentAddress?: boolean;
24
- shipping_address?: Record<string, any>;
25
+ shipping_address?: AddressCreate;
25
26
  shippingAddressId?: string;
26
27
  }) => boolean;
27
28
  export declare const countryLockController: CountryLockController;
@@ -1,17 +1,6 @@
1
+ /// <reference types="react" />
1
2
  import { Price } from '@commercelayer/sdk';
2
- import { Prices } from '../reducers/PriceReducer';
3
- import { Items } from '../reducers/ItemReducer';
4
- import { ReactNode } from 'react';
5
3
  import { PTemplateProps } from '../components/utils/PriceTemplate';
6
- export interface GetPriceByCode {
7
- (skuPrices: Price[], code: string): Price | undefined;
8
- }
9
- export declare const getPriceByCode: GetPriceByCode;
10
- export interface GetPricesComponent {
11
- (skuPrices: Price[], props: PTemplateProps): ReactNode;
12
- }
13
- export declare const getPricesComponent: GetPricesComponent;
14
- export interface GetPrices {
15
- (prices: Price[] | Items): Prices;
16
- }
17
- export default function getPrices<P extends Price>(prices: P[]): Record<string, any>;
4
+ export declare function getPriceByCode(skuPrices: Price[], code?: string): Price | undefined;
5
+ export declare function getPricesComponent(skuPrices: Price[], props: PTemplateProps): JSX.Element[] | JSX.Element;
6
+ export default function getPrices<P extends Price>(prices: P[]): Record<string, P[]>;
@@ -1 +1 @@
1
- import{createElement as _createElement}from"react";import{jsx as _jsx}from"react/jsx-runtime";import{isEmpty,first,isArray,has}from"lodash";import PriceTemplate from"../components/utils/PriceTemplate";export const getPriceByCode=(skuPrices,code="")=>code?first(skuPrices.filter(p=>p.currency_code===code)):first(skuPrices),getPricesComponent=(skuPrices,props)=>isEmpty(skuPrices)?_jsx(PriceTemplate,{...props}):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return _createElement(PriceTemplate,{...props,key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount})});export default function getPrices(prices){const obj={};return isArray(prices)&&prices.forEach(p=>{const sku=p.sku_code;has(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}
1
+ import{createElement as _createElement}from"react";import{jsx as _jsx}from"react/jsx-runtime";import{isEmpty,first,isArray,has}from"lodash";import PriceTemplate from"../components/utils/PriceTemplate";export function getPriceByCode(skuPrices,code=""){return code?first(skuPrices.filter(p=>p.currency_code===code)):first(skuPrices)}export function getPricesComponent(skuPrices,props){return isEmpty(skuPrices)?_jsx(PriceTemplate,{...props}):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return _createElement(PriceTemplate,{...props,key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code})})}export default function getPrices(prices){const obj={};return isArray(prices)&&prices.forEach(p=>{const sku=p.sku_code;has(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}
@@ -1,3 +1,3 @@
1
1
  import Sdk from '@commercelayer/sdk';
2
2
  import { CommerceLayerConfig } from '../context/CommerceLayerContext';
3
- export default function getSdk({ endpoint, accessToken, }: CommerceLayerConfig): ReturnType<typeof Sdk>;
3
+ export default function getSdk({ endpoint, accessToken }: CommerceLayerConfig): ReturnType<typeof Sdk>;
@@ -1,6 +1,6 @@
1
- declare type ReturnObj = {
1
+ interface ReturnObj {
2
2
  organization: string;
3
3
  domain: string;
4
- };
4
+ }
5
5
  export default function getOrganizationSlug<E extends string>(endpoint: E): ReturnObj;
6
6
  export {};