@commercelayer/react-components 4.0.0-alpha.8 → 4.0.0-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 (313) hide show
  1. package/lib/cjs/components/auth/CommerceLayer.d.ts +2 -2
  2. package/lib/cjs/components/line_items/LineItem.d.ts +4 -11
  3. package/lib/cjs/components/line_items/LineItem.js +1 -1
  4. package/lib/cjs/components/line_items/LineItemAmount.d.ts +0 -13
  5. package/lib/cjs/components/line_items/LineItemAmount.js +1 -1
  6. package/lib/cjs/components/line_items/LineItemCode.d.ts +6 -11
  7. package/lib/cjs/components/line_items/LineItemCode.js +1 -1
  8. package/lib/cjs/components/line_items/LineItemField.d.ts +14 -0
  9. package/lib/cjs/components/line_items/LineItemField.js +1 -0
  10. package/lib/cjs/components/line_items/LineItemImage.d.ts +4 -11
  11. package/lib/cjs/components/line_items/LineItemImage.js +1 -1
  12. package/lib/cjs/components/line_items/LineItemName.d.ts +6 -11
  13. package/lib/cjs/components/line_items/LineItemName.js +1 -1
  14. package/lib/cjs/components/line_items/LineItemOption.d.ts +5 -16
  15. package/lib/cjs/components/line_items/LineItemOption.js +1 -1
  16. package/lib/cjs/components/line_items/LineItemOptions.d.ts +2 -5
  17. package/lib/cjs/components/line_items/LineItemOptions.js +1 -1
  18. package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
  19. package/lib/cjs/components/line_items/LineItemsContainer.d.ts +2 -14
  20. package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
  21. package/lib/cjs/components/orders/AddToCartButton.d.ts +34 -9
  22. package/lib/cjs/components/orders/AddToCartButton.js +1 -1
  23. package/lib/cjs/components/orders/AdjustmentAmount.d.ts +2 -2
  24. package/lib/cjs/components/orders/AdjustmentAmount.js +1 -1
  25. package/lib/cjs/components/orders/CartLink.js +1 -1
  26. package/lib/cjs/components/orders/CheckoutLink.js +1 -1
  27. package/lib/cjs/components/orders/DiscountAmount.d.ts +0 -14
  28. package/lib/cjs/components/orders/DiscountAmount.js +1 -1
  29. package/lib/cjs/components/orders/GiftCardAmount.d.ts +0 -11
  30. package/lib/cjs/components/orders/GiftCardAmount.js +1 -1
  31. package/lib/cjs/components/orders/OrderContainer.js +1 -1
  32. package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +4 -0
  33. package/lib/cjs/components/orders/PaymentMethodAmount.js +1 -0
  34. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
  35. package/lib/cjs/components/orders/PlaceOrderContainer.d.ts +2 -8
  36. package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
  37. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -6
  38. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.js +1 -1
  39. package/lib/cjs/components/orders/ShippingAmount.d.ts +0 -11
  40. package/lib/cjs/components/orders/ShippingAmount.js +1 -1
  41. package/lib/cjs/components/orders/SubTotalAmount.d.ts +0 -14
  42. package/lib/cjs/components/orders/SubTotalAmount.js +1 -1
  43. package/lib/cjs/components/orders/TaxesAmount.d.ts +0 -14
  44. package/lib/cjs/components/orders/TaxesAmount.js +1 -1
  45. package/lib/cjs/components/orders/TotalAmount.d.ts +0 -14
  46. package/lib/cjs/components/orders/TotalAmount.js +1 -1
  47. package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +18 -0
  48. package/lib/cjs/components/parcels/ParcelLineItemsCount.js +1 -0
  49. package/lib/cjs/components/parcels/Parcels.d.ts +2 -1
  50. package/lib/cjs/components/parcels/Parcels.js +1 -1
  51. package/lib/cjs/components/parcels/ParcelsCount.d.ts +18 -0
  52. package/lib/cjs/components/parcels/ParcelsCount.js +1 -0
  53. package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +2 -2
  54. package/lib/cjs/components/payment_gateways/AdyenGateway.js +1 -1
  55. package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +2 -2
  56. package/lib/cjs/components/payment_gateways/BraintreeGateway.js +1 -1
  57. package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +2 -2
  58. package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +2 -2
  59. package/lib/cjs/components/payment_gateways/PaymentGateway.js +1 -1
  60. package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +2 -2
  61. package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +2 -2
  62. package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +2 -2
  63. package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +1 -7
  64. package/lib/cjs/components/payment_methods/PaymentMethod.js +1 -1
  65. package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +6 -11
  66. package/lib/cjs/components/payment_methods/PaymentMethodName.js +1 -1
  67. package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +2 -14
  68. package/lib/cjs/components/payment_methods/PaymentMethodPrice.js +1 -1
  69. package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.d.ts +4 -9
  70. package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.js +1 -1
  71. package/lib/cjs/components/payment_methods/PaymentMethodsContainer.d.ts +2 -8
  72. package/lib/cjs/components/payment_methods/PaymentMethodsContainer.js +1 -1
  73. package/lib/cjs/components/payment_source/AdyenPayment.d.ts +5 -5
  74. package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
  75. package/lib/cjs/components/payment_source/PaymentSource.d.ts +4 -11
  76. package/lib/cjs/components/payment_source/PaymentSource.js +1 -1
  77. package/lib/cjs/components/prices/Price.js +1 -1
  78. package/lib/cjs/components/prices/PricesContainer.js +1 -1
  79. package/lib/cjs/components/shipments/ShipmentsCount.d.ts +18 -0
  80. package/lib/cjs/components/shipments/ShipmentsCount.js +1 -0
  81. package/lib/cjs/components/skus/AvailabilityContainer.d.ts +3 -9
  82. package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
  83. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +23 -4
  84. package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
  85. package/lib/cjs/components/skus/SkuField.js +1 -1
  86. package/lib/cjs/components/skus/SkusContainer.d.ts +2 -2
  87. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +3 -4
  88. package/lib/cjs/components/utils/BaseInput.d.ts +1 -1
  89. package/lib/cjs/components/utils/BaseOrderPrice.d.ts +3 -3
  90. package/lib/cjs/components/utils/BaseOrderPrice.js +1 -1
  91. package/lib/cjs/components/utils/GenericFieldComponent.d.ts +4 -4
  92. package/lib/cjs/components/utils/GenericFieldComponent.js +1 -1
  93. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +3 -3
  94. package/lib/cjs/context/CommerceLayerContext.d.ts +2 -2
  95. package/lib/cjs/context/CommerceLayerContext.js +1 -1
  96. package/lib/cjs/context/ExternalFunctionContext.d.ts +2 -2
  97. package/lib/cjs/context/ExternalFunctionContext.js +1 -1
  98. package/lib/cjs/context/LineItemContext.d.ts +1 -1
  99. package/lib/cjs/context/OrderContext.d.ts +2 -3
  100. package/lib/cjs/context/OrderContext.js +1 -1
  101. package/lib/cjs/context/PaymentMethodContext.d.ts +2 -11
  102. package/lib/cjs/context/PaymentMethodContext.js +1 -1
  103. package/lib/cjs/index.d.ts +6 -16
  104. package/lib/cjs/index.js +1 -1
  105. package/lib/cjs/reducers/AvailabilityReducer.d.ts +13 -23
  106. package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
  107. package/lib/cjs/reducers/OrderReducer.d.ts +36 -22
  108. package/lib/cjs/reducers/OrderReducer.js +1 -1
  109. package/lib/cjs/reducers/PaymentMethodReducer.d.ts +9 -11
  110. package/lib/cjs/reducers/PaymentMethodReducer.js +1 -1
  111. package/lib/cjs/reducers/PriceReducer.d.ts +12 -19
  112. package/lib/cjs/reducers/PriceReducer.js +1 -1
  113. package/lib/cjs/reducers/SkuReducer.d.ts +3 -3
  114. package/lib/cjs/typings/errors.d.ts +4 -4
  115. package/lib/cjs/typings/index.d.ts +3 -3
  116. package/lib/cjs/utils/browserInfo.d.ts +5 -2
  117. package/lib/cjs/utils/browserInfo.js +1 -1
  118. package/lib/cjs/utils/getLineItemsCount.d.ts +3 -3
  119. package/lib/cjs/utils/getSdk.js +1 -1
  120. package/lib/cjs/utils/hooks/useCustomContext.d.ts +21 -0
  121. package/lib/cjs/utils/hooks/useCustomContext.js +1 -0
  122. package/lib/esm/components/auth/CommerceLayer.d.ts +2 -2
  123. package/lib/esm/components/line_items/LineItem.d.ts +4 -11
  124. package/lib/esm/components/line_items/LineItem.js +1 -1
  125. package/lib/esm/components/line_items/LineItemAmount.d.ts +0 -13
  126. package/lib/esm/components/line_items/LineItemAmount.js +1 -1
  127. package/lib/esm/components/line_items/LineItemCode.d.ts +6 -11
  128. package/lib/esm/components/line_items/LineItemCode.js +1 -1
  129. package/lib/esm/components/line_items/LineItemField.d.ts +14 -0
  130. package/lib/esm/components/line_items/LineItemField.js +1 -0
  131. package/lib/esm/components/line_items/LineItemImage.d.ts +4 -11
  132. package/lib/esm/components/line_items/LineItemImage.js +1 -1
  133. package/lib/esm/components/line_items/LineItemName.d.ts +6 -11
  134. package/lib/esm/components/line_items/LineItemName.js +1 -1
  135. package/lib/esm/components/line_items/LineItemOption.d.ts +5 -16
  136. package/lib/esm/components/line_items/LineItemOption.js +1 -1
  137. package/lib/esm/components/line_items/LineItemOptions.d.ts +2 -5
  138. package/lib/esm/components/line_items/LineItemOptions.js +1 -1
  139. package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -1
  140. package/lib/esm/components/line_items/LineItemsContainer.d.ts +2 -14
  141. package/lib/esm/components/line_items/LineItemsContainer.js +1 -1
  142. package/lib/esm/components/orders/AddToCartButton.d.ts +34 -9
  143. package/lib/esm/components/orders/AddToCartButton.js +1 -1
  144. package/lib/esm/components/orders/AdjustmentAmount.d.ts +2 -2
  145. package/lib/esm/components/orders/AdjustmentAmount.js +1 -1
  146. package/lib/esm/components/orders/CartLink.js +1 -1
  147. package/lib/esm/components/orders/CheckoutLink.js +1 -1
  148. package/lib/esm/components/orders/DiscountAmount.d.ts +0 -14
  149. package/lib/esm/components/orders/DiscountAmount.js +1 -1
  150. package/lib/esm/components/orders/GiftCardAmount.d.ts +0 -11
  151. package/lib/esm/components/orders/GiftCardAmount.js +1 -1
  152. package/lib/esm/components/orders/OrderContainer.js +1 -1
  153. package/lib/esm/components/orders/PaymentMethodAmount.d.ts +4 -0
  154. package/lib/esm/components/orders/PaymentMethodAmount.js +1 -0
  155. package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
  156. package/lib/esm/components/orders/PlaceOrderContainer.d.ts +2 -8
  157. package/lib/esm/components/orders/PlaceOrderContainer.js +1 -1
  158. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -6
  159. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.js +1 -1
  160. package/lib/esm/components/orders/ShippingAmount.d.ts +0 -11
  161. package/lib/esm/components/orders/ShippingAmount.js +1 -1
  162. package/lib/esm/components/orders/SubTotalAmount.d.ts +0 -14
  163. package/lib/esm/components/orders/SubTotalAmount.js +1 -1
  164. package/lib/esm/components/orders/TaxesAmount.d.ts +0 -14
  165. package/lib/esm/components/orders/TaxesAmount.js +1 -1
  166. package/lib/esm/components/orders/TotalAmount.d.ts +0 -14
  167. package/lib/esm/components/orders/TotalAmount.js +1 -1
  168. package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +18 -0
  169. package/lib/esm/components/parcels/ParcelLineItemsCount.js +1 -0
  170. package/lib/esm/components/parcels/Parcels.d.ts +2 -1
  171. package/lib/esm/components/parcels/Parcels.js +1 -1
  172. package/lib/esm/components/parcels/ParcelsCount.d.ts +18 -0
  173. package/lib/esm/components/parcels/ParcelsCount.js +1 -0
  174. package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +2 -2
  175. package/lib/esm/components/payment_gateways/AdyenGateway.js +1 -1
  176. package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +2 -2
  177. package/lib/esm/components/payment_gateways/BraintreeGateway.js +1 -1
  178. package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +2 -2
  179. package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +2 -2
  180. package/lib/esm/components/payment_gateways/PaymentGateway.js +1 -1
  181. package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +2 -2
  182. package/lib/esm/components/payment_gateways/StripeGateway.d.ts +2 -2
  183. package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +2 -2
  184. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -7
  185. package/lib/esm/components/payment_methods/PaymentMethod.js +1 -1
  186. package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +6 -11
  187. package/lib/esm/components/payment_methods/PaymentMethodName.js +1 -1
  188. package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +2 -14
  189. package/lib/esm/components/payment_methods/PaymentMethodPrice.js +1 -1
  190. package/lib/esm/components/payment_methods/PaymentMethodRadioButton.d.ts +4 -9
  191. package/lib/esm/components/payment_methods/PaymentMethodRadioButton.js +1 -1
  192. package/lib/esm/components/payment_methods/PaymentMethodsContainer.d.ts +2 -8
  193. package/lib/esm/components/payment_methods/PaymentMethodsContainer.js +1 -1
  194. package/lib/esm/components/payment_source/AdyenPayment.d.ts +5 -5
  195. package/lib/esm/components/payment_source/AdyenPayment.js +1 -1
  196. package/lib/esm/components/payment_source/PaymentSource.d.ts +4 -11
  197. package/lib/esm/components/payment_source/PaymentSource.js +1 -1
  198. package/lib/esm/components/prices/Price.js +1 -1
  199. package/lib/esm/components/prices/PricesContainer.js +1 -1
  200. package/lib/esm/components/shipments/ShipmentsCount.d.ts +18 -0
  201. package/lib/esm/components/shipments/ShipmentsCount.js +1 -0
  202. package/lib/esm/components/skus/AvailabilityContainer.d.ts +3 -9
  203. package/lib/esm/components/skus/AvailabilityContainer.js +1 -1
  204. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +23 -4
  205. package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
  206. package/lib/esm/components/skus/SkuField.js +1 -1
  207. package/lib/esm/components/skus/SkusContainer.d.ts +2 -2
  208. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +3 -4
  209. package/lib/esm/components/utils/BaseInput.d.ts +1 -1
  210. package/lib/esm/components/utils/BaseOrderPrice.d.ts +3 -3
  211. package/lib/esm/components/utils/BaseOrderPrice.js +1 -1
  212. package/lib/esm/components/utils/GenericFieldComponent.d.ts +4 -4
  213. package/lib/esm/components/utils/GenericFieldComponent.js +1 -1
  214. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +3 -3
  215. package/lib/esm/context/CommerceLayerContext.d.ts +2 -2
  216. package/lib/esm/context/CommerceLayerContext.js +1 -1
  217. package/lib/esm/context/ExternalFunctionContext.d.ts +2 -2
  218. package/lib/esm/context/ExternalFunctionContext.js +1 -1
  219. package/lib/esm/context/LineItemContext.d.ts +1 -1
  220. package/lib/esm/context/OrderContext.d.ts +2 -3
  221. package/lib/esm/context/OrderContext.js +1 -1
  222. package/lib/esm/context/PaymentMethodContext.d.ts +2 -11
  223. package/lib/esm/context/PaymentMethodContext.js +1 -1
  224. package/lib/esm/index.d.ts +6 -16
  225. package/lib/esm/index.js +1 -1
  226. package/lib/esm/reducers/AvailabilityReducer.d.ts +13 -23
  227. package/lib/esm/reducers/AvailabilityReducer.js +1 -1
  228. package/lib/esm/reducers/OrderReducer.d.ts +36 -22
  229. package/lib/esm/reducers/OrderReducer.js +1 -1
  230. package/lib/esm/reducers/PaymentMethodReducer.d.ts +9 -11
  231. package/lib/esm/reducers/PaymentMethodReducer.js +1 -1
  232. package/lib/esm/reducers/PriceReducer.d.ts +12 -19
  233. package/lib/esm/reducers/PriceReducer.js +1 -1
  234. package/lib/esm/reducers/SkuReducer.d.ts +3 -3
  235. package/lib/esm/typings/errors.d.ts +4 -4
  236. package/lib/esm/typings/index.d.ts +3 -3
  237. package/lib/esm/utils/browserInfo.d.ts +5 -2
  238. package/lib/esm/utils/browserInfo.js +1 -1
  239. package/lib/esm/utils/getLineItemsCount.d.ts +3 -3
  240. package/lib/esm/utils/getSdk.js +1 -1
  241. package/lib/esm/utils/hooks/useCustomContext.d.ts +21 -0
  242. package/lib/esm/utils/hooks/useCustomContext.js +1 -0
  243. package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
  244. package/lib/tsconfig.prod.tsbuildinfo +1 -1
  245. package/package.json +9 -15
  246. package/lib/cjs/components/orders/ItemContainer.d.ts +0 -11
  247. package/lib/cjs/components/orders/ItemContainer.js +0 -1
  248. package/lib/cjs/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
  249. package/lib/cjs/components/payment_methods/PaymentMethodAmount.js +0 -1
  250. package/lib/cjs/components/skus/QuantitySelector.d.ts +0 -17
  251. package/lib/cjs/components/skus/QuantitySelector.js +0 -1
  252. package/lib/cjs/components/skus/SkuOption.d.ts +0 -14
  253. package/lib/cjs/components/skus/SkuOption.js +0 -1
  254. package/lib/cjs/components/skus/SkuOptionInput.d.ts +0 -15
  255. package/lib/cjs/components/skus/SkuOptionInput.js +0 -1
  256. package/lib/cjs/components/skus/SkuOptionsContainer.d.ts +0 -14
  257. package/lib/cjs/components/skus/SkuOptionsContainer.js +0 -1
  258. package/lib/cjs/components/skus/VariantSelector.d.ts +0 -29
  259. package/lib/cjs/components/skus/VariantSelector.js +0 -1
  260. package/lib/cjs/components/skus/VariantsContainer.d.ts +0 -20
  261. package/lib/cjs/components/skus/VariantsContainer.js +0 -1
  262. package/lib/cjs/components/utils/VariantTemplate.d.ts +0 -36
  263. package/lib/cjs/components/utils/VariantTemplate.js +0 -1
  264. package/lib/cjs/context/ItemContext.d.ts +0 -13
  265. package/lib/cjs/context/ItemContext.js +0 -1
  266. package/lib/cjs/context/SkuOptionChildrenContext.d.ts +0 -8
  267. package/lib/cjs/context/SkuOptionChildrenContext.js +0 -1
  268. package/lib/cjs/context/SkuOptionsContext.d.ts +0 -3
  269. package/lib/cjs/context/SkuOptionsContext.js +0 -1
  270. package/lib/cjs/context/VariantsContext.d.ts +0 -3
  271. package/lib/cjs/context/VariantsContext.js +0 -1
  272. package/lib/cjs/reducers/ItemReducer.d.ts +0 -69
  273. package/lib/cjs/reducers/ItemReducer.js +0 -1
  274. package/lib/cjs/reducers/SkuOptionsReducer.d.ts +0 -26
  275. package/lib/cjs/reducers/SkuOptionsReducer.js +0 -1
  276. package/lib/cjs/reducers/VariantReducer.d.ts +0 -72
  277. package/lib/cjs/reducers/VariantReducer.js +0 -1
  278. package/lib/cjs/utils/getCurrentItemKey.d.ts +0 -6
  279. package/lib/cjs/utils/getCurrentItemKey.js +0 -1
  280. package/lib/esm/components/orders/ItemContainer.d.ts +0 -11
  281. package/lib/esm/components/orders/ItemContainer.js +0 -1
  282. package/lib/esm/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
  283. package/lib/esm/components/payment_methods/PaymentMethodAmount.js +0 -1
  284. package/lib/esm/components/skus/QuantitySelector.d.ts +0 -17
  285. package/lib/esm/components/skus/QuantitySelector.js +0 -1
  286. package/lib/esm/components/skus/SkuOption.d.ts +0 -14
  287. package/lib/esm/components/skus/SkuOption.js +0 -1
  288. package/lib/esm/components/skus/SkuOptionInput.d.ts +0 -15
  289. package/lib/esm/components/skus/SkuOptionInput.js +0 -1
  290. package/lib/esm/components/skus/SkuOptionsContainer.d.ts +0 -14
  291. package/lib/esm/components/skus/SkuOptionsContainer.js +0 -1
  292. package/lib/esm/components/skus/VariantSelector.d.ts +0 -29
  293. package/lib/esm/components/skus/VariantSelector.js +0 -1
  294. package/lib/esm/components/skus/VariantsContainer.d.ts +0 -20
  295. package/lib/esm/components/skus/VariantsContainer.js +0 -1
  296. package/lib/esm/components/utils/VariantTemplate.d.ts +0 -36
  297. package/lib/esm/components/utils/VariantTemplate.js +0 -1
  298. package/lib/esm/context/ItemContext.d.ts +0 -13
  299. package/lib/esm/context/ItemContext.js +0 -1
  300. package/lib/esm/context/SkuOptionChildrenContext.d.ts +0 -8
  301. package/lib/esm/context/SkuOptionChildrenContext.js +0 -1
  302. package/lib/esm/context/SkuOptionsContext.d.ts +0 -3
  303. package/lib/esm/context/SkuOptionsContext.js +0 -1
  304. package/lib/esm/context/VariantsContext.d.ts +0 -3
  305. package/lib/esm/context/VariantsContext.js +0 -1
  306. package/lib/esm/reducers/ItemReducer.d.ts +0 -69
  307. package/lib/esm/reducers/ItemReducer.js +0 -1
  308. package/lib/esm/reducers/SkuOptionsReducer.d.ts +0 -26
  309. package/lib/esm/reducers/SkuOptionsReducer.js +0 -1
  310. package/lib/esm/reducers/VariantReducer.d.ts +0 -72
  311. package/lib/esm/reducers/VariantReducer.js +0 -1
  312. package/lib/esm/utils/getCurrentItemKey.d.ts +0 -6
  313. package/lib/esm/utils/getCurrentItemKey.js +0 -1
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  interface Props {
3
3
  children: JSX.Element | JSX.Element[];
4
+ filterBy?: string[];
4
5
  }
5
- export declare function Parcels({ children }: Props): JSX.Element;
6
+ export declare function Parcels({ children, filterBy }: Props): JSX.Element;
6
7
  export default Parcels;
@@ -1 +1 @@
1
- import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import ParcelChildrenContext from"../../context/ParcelChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import{useContext}from"react";export function Parcels({children}){const{parcels}=useContext(ShipmentChildrenContext),components=parcels?.map((parcel,key)=>_jsx(ParcelChildrenContext.Provider,{value:{parcel},children},key));return _jsx(_Fragment,{children:components})}export default Parcels;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import ParcelChildrenContext from"../../context/ParcelChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import{useContext}from"react";export function Parcels({children,filterBy}){const{parcels}=useContext(ShipmentChildrenContext),components=parcels?.filter(parcel=>filterBy?.includes(parcel.id)??!0).map((parcel,key)=>_jsx(ParcelChildrenContext.Provider,{value:{parcel},children},key));return _jsx(_Fragment,{children:components})}export default Parcels;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import { ChildrenFunction } from '../../typings/index';
3
+ import type { Parcel } from '@commercelayer/sdk';
4
+ interface ChildrenProps extends Omit<Props, 'children'> {
5
+ /**
6
+ * Shipments of the current order
7
+ */
8
+ parcels?: Parcel[];
9
+ /**
10
+ * Quantity of the parcels
11
+ */
12
+ quantity: number;
13
+ }
14
+ interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
15
+ children?: ChildrenFunction<ChildrenProps>;
16
+ }
17
+ export declare function ParcelsCount({ children, ...p }: Props): JSX.Element;
18
+ export default ParcelsCount;
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function ParcelsCount({children,...p}){const{parcels}=useCustomContext({context:ShipmentChildrenContext,contextComponentName:"ShipmentsContainer",currentComponentName:"ParcelsCount",key:"parcels"}),quantity=parcels?.length??0,childrenProps={...p,quantity,parcels};return children?_jsx(Parent,{...childrenProps,children}):_jsx("span",{...p,children:quantity})}export default ParcelsCount;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type AdyenGateway = GatewayBaseType;
4
- export declare function AdyenGateway(props: AdyenGateway): JSX.Element | null;
3
+ declare type Props = GatewayBaseType;
4
+ export declare function AdyenGateway(props: Props): JSX.Element | null;
5
5
  export default AdyenGateway;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import{Fragment,useContext}from"react";import AdyenPayment from"../payment_source/AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import jwt from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";export function AdyenGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{accessToken}=useContext(CommerceLayerContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="adyen_payments",locale=order?.language_code,paymentMethods=paymentSource?.payment_methods;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientKey=paymentSource?.public_key,environment=jwt(accessToken).test?"test":"live",adyenConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="adyen_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?clientKey&&!loading&&paymentMethods?_jsxs(Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(AdyenPayment,{templateCustomerSaveToWallet,clientKey,locale,environment,config:adyenConfig})]}):loaderComponent:clientKey&&!loading&&paymentMethods?_jsx(AdyenPayment,{clientKey,locale,config:adyenConfig,environment}):loaderComponent}export default AdyenGateway;
1
+ import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import AdyenPayment from"../payment_source/AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import jwt from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";export function AdyenGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{accessToken}=useContext(CommerceLayerContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="adyen_payments",locale=order?.language_code,paymentMethods=paymentSource?.payment_methods;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientKey=paymentSource?.public_key,environment=accessToken&&jwt(accessToken).test?"test":"live",adyenConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="adyen_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?clientKey&&!loading&&paymentMethods?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(AdyenPayment,{templateCustomerSaveToWallet,clientKey,locale,environment,config:adyenConfig})]}):loaderComponent:clientKey&&!loading&&paymentMethods?_jsx(AdyenPayment,{clientKey,locale,config:adyenConfig,environment}):loaderComponent}export default AdyenGateway;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type BraintreeGateway = GatewayBaseType;
4
- export declare function BraintreeGateway(props: BraintreeGateway): JSX.Element | null;
3
+ declare type Props = GatewayBaseType;
4
+ export declare function BraintreeGateway(props: Props): JSX.Element | null;
5
5
  export default BraintreeGateway;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../payment_source/BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{Fragment,useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function BraintreeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="braintree_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const authorization=paymentSource?.client_token,braintreeConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="braintree_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?authorization&&!loading?_jsxs(Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(BraintreePayment,{templateCustomerSaveToWallet,authorization,locale,config:braintreeConfig})]}):loaderComponent:authorization&&!loading?_jsx(BraintreePayment,{locale,authorization,config:braintreeConfig}):loaderComponent}export default BraintreeGateway;
1
+ import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../payment_source/BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function BraintreeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="braintree_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const authorization=paymentSource?.client_token,braintreeConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="braintree_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?authorization&&!loading?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(BraintreePayment,{templateCustomerSaveToWallet,authorization,locale,config:braintreeConfig})]}):loaderComponent:authorization&&!loading?_jsx(BraintreePayment,{locale,authorization,config:braintreeConfig}):loaderComponent}export default BraintreeGateway;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type CheckoutComGateway = GatewayBaseType;
4
- export declare function CheckoutComGateway(props: CheckoutComGateway): JSX.Element | null;
3
+ declare type Props = GatewayBaseType;
4
+ export declare function CheckoutComGateway(props: Props): JSX.Element | null;
5
5
  export default CheckoutComGateway;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type KlarnaGateway = GatewayBaseType;
4
- export declare function KlarnaGateway(props: KlarnaGateway): JSX.Element | null;
3
+ declare type Props = GatewayBaseType;
4
+ export declare function KlarnaGateway(props: Props): JSX.Element | null;
5
5
  export default KlarnaGateway;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import getPaypalConfig from"../../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../../utils/getLoaderComponent";import CustomerContext from"../../context/CustomerContext";export function PaymentGateway({readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading...",...p}){const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment?.payment_source_type;useEffect(()=>{if(payment?.id===currentPaymentMethodId&&paymentResource&&order?.payment_method?.payment_source_type===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()};(!paymentSource&&order?.payment_method.id&&show||!paymentSource||paymentSource.type!==paymentResource)&&setPaymentSources(),paymentSource?.mismatched_amounts&&show&&setPaymentSources(),setLoading(!1)}return()=>{setLoading(!0)}},[order?.payment_method?.id,show,paymentSource]);const gatewayConfig={readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet,...p};switch(paymentResource){case"stripe_payments":return _jsx(StripeGateway,{...gatewayConfig,children});case"klarna_payments":return _jsx(KlarnaGateway,{...gatewayConfig,children});case"adyen_payments":return _jsx(AdyenGateway,{...gatewayConfig,children});case"braintree_payments":return _jsx(BraintreeGateway,{...gatewayConfig,children});case"wire_transfers":return _jsx(WireTransferGateway,{...gatewayConfig,children});case"paypal_payments":return _jsx(PaypalGateway,{...gatewayConfig,children});case"checkout_com_payments":return _jsx(CheckoutComGateway,{...gatewayConfig,children});default:return null}}export default PaymentGateway;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import getPaypalConfig from"../../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../../utils/getLoaderComponent";import AdyenGateway from"./AdyenGateway";import StripeGateway from"./StripeGateway";import BraintreeGateway from"./BraintreeGateway";import PaypalGateway from"./PaypalGateway";import WireTransferGateway from"./WireTransferGateway";import CustomerContext from"../../context/CustomerContext";import CheckoutComGateway from"./CheckoutComGateway";import KlarnaGateway from"./KlarnaGateway";export function PaymentGateway({readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading...",...p}){const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment?.payment_source_type;useEffect(()=>{if(payment?.id===currentPaymentMethodId&&paymentResource&&order?.payment_method?.payment_source_type===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()};(!paymentSource&&order?.payment_method.id&&show||!paymentSource||paymentSource.type!==paymentResource)&&setPaymentSources(),paymentSource?.mismatched_amounts&&show&&setPaymentSources(),setLoading(!1)}return()=>{setLoading(!0)}},[order?.payment_method?.id,show,paymentSource]);const gatewayConfig={readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet,...p};switch(paymentResource){case"stripe_payments":return _jsx(StripeGateway,{...gatewayConfig,children});case"klarna_payments":return _jsx(KlarnaGateway,{...gatewayConfig,children});case"adyen_payments":return _jsx(AdyenGateway,{...gatewayConfig,children});case"braintree_payments":return _jsx(BraintreeGateway,{...gatewayConfig,children});case"wire_transfers":return _jsx(WireTransferGateway,{...gatewayConfig,children});case"paypal_payments":return _jsx(PaypalGateway,{...gatewayConfig,children});case"checkout_com_payments":return _jsx(CheckoutComGateway,{...gatewayConfig,children});default:return null}}export default PaymentGateway;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type PaypalGateway = Partial<GatewayBaseType>;
4
- export declare function PaypalGateway(props: PaypalGateway): JSX.Element | null;
3
+ declare type Props = Partial<GatewayBaseType>;
4
+ export declare function PaypalGateway(props: Props): JSX.Element | null;
5
5
  export default PaypalGateway;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type StripeGateway = GatewayBaseType;
4
- export declare function StripeGateway(props: StripeGateway): JSX.Element | null;
3
+ declare type Props = GatewayBaseType;
4
+ export declare function StripeGateway(props: Props): JSX.Element | null;
5
5
  export default StripeGateway;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { GatewayBaseType } from '../payment_gateways/PaymentGateway';
3
- declare type WireTransferGateway = GatewayBaseType;
4
- export declare function WireTransferGateway(props: WireTransferGateway): JSX.Element | null;
3
+ declare type Props = GatewayBaseType;
4
+ export declare function WireTransferGateway(props: Props): JSX.Element | null;
5
5
  export default WireTransferGateway;
@@ -6,7 +6,7 @@ declare type Props = {
6
6
  /**
7
7
  * Hide payment methods by an array of strings
8
8
  */
9
- hide?: Array<PaymentResource>;
9
+ hide?: PaymentResource[];
10
10
  children: ReactNode;
11
11
  activeClass?: string;
12
12
  loader?: LoaderType;
@@ -18,10 +18,4 @@ declare type Props = {
18
18
  onClick?: never;
19
19
  });
20
20
  export declare function PaymentMethod({ children, className, activeClass, loader, clickableContainer, hide, onClick, ...p }: Props): JSX.Element;
21
- export declare namespace PaymentMethod {
22
- var propTypes: {
23
- children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
24
- };
25
- var displayName: string;
26
- }
27
21
  export default PaymentMethod;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import components from"../../config/components";import getLoaderComponent from"../../utils/getLoaderComponent";const propTypes=components.PaymentMethod.propTypes,displayName=components.PaymentMethod.displayName;export function PaymentMethod({children,className,activeClass,loader="Loading...",clickableContainer,hide,onClick,...p}){const[loading,setLoading]=useState(!0),[paymentSelected,setPaymentSelected]=useState(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder}=useContext(PaymentMethodContext);useEffect(()=>(paymentMethods&&setLoading(!1),currentPaymentMethodId&&setPaymentSelected(currentPaymentMethodId),()=>{setLoading(!0)}),[paymentMethods,currentPaymentMethodId]);const components2=paymentMethods&&paymentMethods.filter(payment=>{if(hide){const source=payment?.payment_source_type;return hide?.includes(source)===!1}return!0}).map((payment,k)=>{const isActive=currentPaymentMethodId===payment?.id,paymentMethodProps={payment,clickableContainer,paymentSelected,setPaymentSelected},paymentResource=payment?.payment_source_type,onClickable=clickableContainer?async e=>{e.stopPropagation(),setLoadingPlaceOrder({loading:!0}),setPaymentSelected(payment.id);const paymentMethodId=payment?.id;await setPaymentMethod({paymentResource,paymentMethodId}),onClick&&onClick(payment),setLoadingPlaceOrder({loading:!1})}:void 0;return _jsx("div",{"data-test-id":paymentResource,className:`${className} ${isActive?activeClass:""}`,onClick:onClickable,...p,children:_jsx(PaymentMethodChildrenContext.Provider,{value:paymentMethodProps,children})},k)});return loading?getLoaderComponent(loader):_jsx(Fragment,{children:components2})}PaymentMethod.propTypes=propTypes,PaymentMethod.displayName=displayName;export default PaymentMethod;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useState,useEffect}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import getLoaderComponent from"../../utils/getLoaderComponent";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethod({children,className,activeClass,loader="Loading...",clickableContainer,hide,onClick,...p}){const[loading,setLoading]=useState(!0),[paymentSelected,setPaymentSelected]=useState(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder}=useCustomContext({context:PaymentMethodContext,contextComponentName:"PaymentMethodsContainer",currentComponentName:"PaymentMethod",key:"paymentMethods"});useEffect(()=>(paymentMethods&&setLoading(!1),currentPaymentMethodId&&setPaymentSelected(currentPaymentMethodId),()=>{setLoading(!0)}),[paymentMethods,currentPaymentMethodId]);const components=paymentMethods?.filter(payment=>{if(hide){const source=payment?.payment_source_type;return!hide?.includes(source)}return!0}).map((payment,k)=>{const isActive=currentPaymentMethodId===payment?.id,paymentMethodProps={payment,clickableContainer,paymentSelected,setPaymentSelected},paymentResource=payment?.payment_source_type,onClickable=clickableContainer?async e=>{e.stopPropagation(),setLoadingPlaceOrder({loading:!0}),setPaymentSelected(payment.id);const paymentMethodId=payment?.id;await setPaymentMethod({paymentResource,paymentMethodId}),onClick&&onClick(payment),setLoadingPlaceOrder({loading:!1})}:void 0;return _jsx("div",{"data-test-id":paymentResource,className:`${className??""} ${isActive&&activeClass!=null?activeClass:""}`,onClick:onClickable,...p,children:_jsx(PaymentMethodChildrenContext.Provider,{value:paymentMethodProps,children})},k)});return loading?getLoaderComponent(loader):_jsx(_Fragment,{children:components})}export default PaymentMethod;
@@ -1,15 +1,10 @@
1
1
  /// <reference types="react" />
2
- declare type PaymentMethodNameChildrenProps = Omit<Props, 'children'> & {
2
+ import { ChildrenFunction } from '../../typings/index';
3
+ interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  labelName: string;
4
- };
5
- declare type Props = {
6
- children?: (props: PaymentMethodNameChildrenProps) => JSX.Element;
7
- } & JSX.IntrinsicElements['label'];
8
- export declare function PaymentMethodName(props: Props): JSX.Element;
9
- export declare namespace PaymentMethodName {
10
- var propTypes: {
11
- children: import("prop-types").Requireable<(...args: any[]) => any>;
12
- };
13
- var displayName: string;
14
5
  }
6
+ interface Props extends Omit<JSX.IntrinsicElements['label'], 'children'> {
7
+ children?: ChildrenFunction<ChildrenProps>;
8
+ }
9
+ export declare function PaymentMethodName(props: Props): JSX.Element;
15
10
  export default PaymentMethodName;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import components from"../../config/components";const propTypes=components.PaymentMethodName.propTypes,displayName=components.PaymentMethodName.displayName;export function PaymentMethodName(props){const{payment}=useContext(PaymentMethodChildrenContext),labelName=payment?.name,htmlFor=payment?.payment_source_type,parentProps={htmlFor,labelName,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("label",{htmlFor,...props,children:labelName})}PaymentMethodName.propTypes=propTypes,PaymentMethodName.displayName=displayName;export default PaymentMethodName;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodName(props){const{payment}=useCustomContext({context:PaymentMethodChildrenContext,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodName",key:"payment"}),labelName=payment?.name,htmlFor=payment?.payment_source_type,parentProps={htmlFor,labelName,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("label",{htmlFor,...props,children:labelName})}export default PaymentMethodName;
@@ -1,20 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { BaseAmountComponent } from '../../typings/index';
3
- declare type Props = {
3
+ interface Props extends BaseAmountComponent {
4
4
  type?: 'amount';
5
5
  labelFree?: string;
6
- } & BaseAmountComponent;
7
- export declare function PaymentMethodPrice(props: Props): JSX.Element;
8
- export declare namespace PaymentMethodPrice {
9
- var propTypes: {
10
- type: import("prop-types").Requireable<"amount">;
11
- id: import("prop-types").Requireable<string>;
12
- className: import("prop-types").Requireable<string>;
13
- style: import("prop-types").Requireable<object>;
14
- name: import("prop-types").Requireable<string>;
15
- children: import("prop-types").Requireable<(...args: any[]) => any>;
16
- format: import("prop-types").Requireable<import("../../typings/index").BaseFormatPrice>;
17
- };
18
- var displayName: string;
19
6
  }
7
+ export declare function PaymentMethodPrice(props: Props): JSX.Element;
20
8
  export default PaymentMethodPrice;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../../utils/getAmount";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import components from"../../config/components";const propTypes=components.PaymentMethodPrice.propTypes,displayName=components.PaymentMethodPrice.displayName;export function PaymentMethodPrice(props){const{format="formatted",type="amount",labelFree="Free",...p}=props,{payment}=useContext(PaymentMethodChildrenContext),[price,setPrice]=useState(""),[priceCents,setPriceCents]=useState(0);useEffect(()=>{if(payment){const p2=getAmount({base:"price",type,format,obj:payment});setPrice(p2);const c=getAmount({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps={labelFree,price,priceCents,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:priceCents===0?labelFree:price})}PaymentMethodPrice.propTypes=propTypes,PaymentMethodPrice.displayName=displayName;export default PaymentMethodPrice;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect}from"react";import getAmount from"../../utils/getAmount";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodPrice(props){const{format="formatted",type="amount",labelFree="Free",...p}=props,{payment}=useCustomContext({context:PaymentMethodChildrenContext,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodPrice",key:"payment"}),[price,setPrice]=useState(""),[priceCents,setPriceCents]=useState(0);useEffect(()=>{if(payment){const p2=getAmount({base:"price",type,format,obj:payment});setPrice(p2);const c=getAmount({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps={labelFree,price,priceCents,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:priceCents===0?labelFree:price})}export default PaymentMethodPrice;
@@ -1,18 +1,13 @@
1
1
  import { ChangeEvent } from 'react';
2
2
  import { PaymentMethod } from '@commercelayer/sdk';
3
- declare type ShippingMethodRadioButtonChildrenProps = Omit<Props, 'children'> & {
3
+ import { ChildrenFunction } from '../../typings/index';
4
+ interface ChildrenProps extends Omit<Props, 'children'> {
4
5
  checked: boolean;
5
6
  handleOnChange: (event: ChangeEvent<HTMLInputElement>) => Promise<void>;
6
- };
7
+ }
7
8
  declare type Props = {
8
- children?: (props: ShippingMethodRadioButtonChildrenProps) => JSX.Element;
9
+ children?: ChildrenFunction<ChildrenProps>;
9
10
  onChange?: (payment?: PaymentMethod | Record<string, any>) => void;
10
11
  } & JSX.IntrinsicElements['input'];
11
12
  export declare function PaymentMethodRadioButton(props: Props): JSX.Element;
12
- export declare namespace PaymentMethodRadioButton {
13
- var propTypes: {
14
- children: import("prop-types").Requireable<(...args: any[]) => any>;
15
- };
16
- var displayName: string;
17
- }
18
13
  export default PaymentMethodRadioButton;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import components from"../../config/components";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";const propTypes=components.PaymentMethodRadioButton.propTypes,displayName=components.PaymentMethodRadioButton.displayName;export function PaymentMethodRadioButton(props){const{onChange,...p}=props,{payment,paymentSelected,setPaymentSelected,clickableContainer}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=payment?.id,name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=async e=>{e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer&&await setPaymentMethod({paymentResource,paymentMethodId}),onChange&&onChange(payment),setLoading({loading:!1})},id=payment?.payment_source_type,parentProps={handleOnChange,checked,id,name,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("input",{title:name,type:"radio",id,onChange:handleOnChange,checked,...p})}PaymentMethodRadioButton.propTypes=propTypes,PaymentMethodRadioButton.displayName=displayName;export default PaymentMethodRadioButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodRadioButton(props){const{onChange,...p}=props,{payment,paymentSelected,setPaymentSelected,clickableContainer}=useCustomContext({context:PaymentMethodChildrenContext,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodRadioButton",key:"payment"}),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=payment?.id,name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=async e=>{e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer&&await setPaymentMethod({paymentResource,paymentMethodId}),onChange&&onChange(payment),setLoading({loading:!1})},id=payment?.payment_source_type,parentProps={handleOnChange,checked,id,name,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("input",{title:name,type:"radio",id,onChange:e=>{handleOnChange(e)},checked,...p})}export default PaymentMethodRadioButton;
@@ -1,14 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
3
- declare type Props = {
3
+ interface Props {
4
4
  children: ReactNode;
5
5
  config?: PaymentMethodConfig;
6
- };
7
- export declare function PaymentMethodsContainer(props: Props): JSX.Element;
8
- export declare namespace PaymentMethodsContainer {
9
- var propTypes: {
10
- children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
11
- };
12
- var displayName: string;
13
6
  }
7
+ export declare function PaymentMethodsContainer(props: Props): JSX.Element;
14
8
  export default PaymentMethodsContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig}from"../../reducers/PaymentMethodReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import components from"../../config/components";import{isEmpty}from"lodash";import{setPaymentRef}from"../../reducers/PaymentMethodReducer";const propTypes=components.PaymentMethodsContainer.propTypes,displayName=components.PaymentMethodsContainer.displayName;export function PaymentMethodsContainer(props){const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useContext(OrderContext),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{include?.includes("available_payment_methods")?includeLoaded?.available_payment_methods||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0,"line_items.line_item_options.sku_option":!0,"line_items.item":!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method","line_items.line_item_options.sku_option","line_items.item"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&(state.paymentMethods||getPayMethods()),order?.payment_source&&dispatch({type:"setPaymentSource",payload:{paymentSource:order?.payment_source}}),order?.payment_source===null&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},[order,credentials,include,includeLoaded]);const contextValue=useMemo(()=>({...state,setLoading:({loading})=>defaultPaymentMethodContext.setLoading({loading,dispatch}),setPaymentRef:({ref})=>setPaymentRef({ref,dispatch}),setPaymentMethodErrors:errors=>defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch),setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod({...args,config:credentials,updateOrder,order,dispatch,setOrderErrors}),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource({...state,...args,config:credentials,dispatch,getOrder,updateOrder,order}),updatePaymentSource:async args=>await defaultPaymentMethodContext.updatePaymentSource({...args,config:credentials,dispatch}),destroyPaymentSource:async args=>await defaultPaymentMethodContext.destroyPaymentSource({...args,dispatch,config:credentials,updateOrder,orderId:order?.id})}),[state]);return _jsx(PaymentMethodContext.Provider,{value:contextValue,children})}PaymentMethodsContainer.propTypes=propTypes,PaymentMethodsContainer.displayName=displayName;export default PaymentMethodsContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig,setPaymentRef}from"../../reducers/PaymentMethodReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import{isEmpty}from"lodash";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodsContainer(props){const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"PaymentMethodsContainer",key:"order"}),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{include?.includes("available_payment_methods")?includeLoaded?.available_payment_methods||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0,"line_items.line_item_options.sku_option":!0,"line_items.item":!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method","line_items.line_item_options.sku_option","line_items.item"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&!state.paymentMethods&&getPayMethods(),order?.payment_source&&dispatch({type:"setPaymentSource",payload:{paymentSource:order?.payment_source}}),order?.payment_source===null&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},[order,credentials,include,includeLoaded]);const contextValue=useMemo(()=>({...state,setLoading:({loading})=>defaultPaymentMethodContext.setLoading({loading,dispatch}),setPaymentRef:({ref})=>setPaymentRef({ref,dispatch}),setPaymentMethodErrors:errors=>defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch),setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod({...args,config:credentials,updateOrder,order,dispatch,setOrderErrors}),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource({...state,...args,config:credentials,dispatch,getOrder,updateOrder,order}),updatePaymentSource:async args=>await defaultPaymentMethodContext.updatePaymentSource({...args,config:credentials,dispatch}),destroyPaymentSource:async args=>await defaultPaymentMethodContext.destroyPaymentSource({...args,dispatch,config:credentials,updateOrder,orderId:order?.id})}),[state]);return _jsx(PaymentMethodContext.Provider,{value:contextValue,children})}export default PaymentMethodsContainer;
@@ -36,20 +36,20 @@ interface PaymentMethodsStyle {
36
36
  card?: Styles;
37
37
  paypal?: PaypalStyle;
38
38
  }
39
- export declare type AdyenPaymentConfig = {
39
+ export interface AdyenPaymentConfig {
40
40
  cardContainerClassName?: string;
41
41
  threeDSecureContainerClassName?: string;
42
42
  placeOrderCallback?: (response: {
43
43
  placed: boolean;
44
44
  }) => void;
45
45
  styles?: PaymentMethodsStyle;
46
- };
47
- declare type Props = {
46
+ }
47
+ interface Props {
48
48
  clientKey?: string;
49
49
  config?: AdyenPaymentConfig;
50
50
  templateCustomerSaveToWallet?: PaymentSourceProps['templateCustomerSaveToWallet'];
51
51
  locale?: string;
52
52
  environment?: string;
53
- };
54
- export declare function AdyenPayment({ clientKey, config, templateCustomerSaveToWallet, environment, locale, }: Props): JSX.Element | null;
53
+ }
54
+ export declare function AdyenPayment({ clientKey, config, templateCustomerSaveToWallet, environment, locale }: Props): JSX.Element | null;
55
55
  export default AdyenPayment;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import{setCustomerOrderParam}from"../../utils/localStorage";import Parent from"../utils/Parent";import getBrowserInfo from"../../utils/browserInfo";import PlaceOrderContext from"../../context/PlaceOrderContext";import OrderContext from"../../context/OrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};export function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState(null),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{placeOrderButtonRef}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component&&component.submit&&component.submit(),!1},handleChange=async(state,checkout2)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=()=>handleSubmit(ref.current,checkout2),setPaymentRef({ref}));const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}};paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,component)=>{const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=pSource?.payment_response?.action,resultCode=pSource?.payment_response?.resultCode;if(adyenAction&&component)return component.handleAction(adyenAction),!1;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=pSource?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return console.error("Adyen additional details error:",error),!1}},onSubmit=async(state,component)=>{const browserInfo=getBrowserInfo();let control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"});if(control?.payment_response?.resultCode==="Authorised")return!0;Object.keys(control?.payment_request_data).length>0===!1&&(control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes:{payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:window.location.href,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}}}));const attributes={payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:window.location.href,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}},_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=res?.payment_response?.action;if(component&&action)return component.handleAction(action),!1;const resultCode=res?.payment_response?.resultCode;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=res?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}if(res?.payment_response?.errorType)if(res?.payment_response?.errorCode==="14_006")onSubmit(state,component);else{const message=res?.payment_response?.message;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}};return useEffect(()=>{const paymentMethodsResponse=paymentSource?.payment_methods?.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],[firstPaymentMethod]=paymentMethodsResponse,isOnlyCard=paymentMethodsResponse?.length===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse:{paymentMethods:paymentMethodsResponse},showPayButton:!1,paymentMethodsConfiguration:{threeDS2:threeDSConfiguration,paypal:{showPayButton:!0,style:styles?.paypal},card:{styles:styles?.card,holderNameRequired:!1}},onAdditionalDetails:handleOnAdditionalDetails,onChange:handleChange,onSubmit};return!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&import("@adyen/adyen-web").then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=()=>handleSubmit(ref.current,component2):ref.current.onsubmit=null,setPaymentRef({ref}))}}).mount("#adyen-dropin");component&&(setCheckout(component),setLoadAdyen(!0))})}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",{ref,onSubmit:e=>handleSubmit(e,checkout),children:[_jsx("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}export default AdyenPayment;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import{setCustomerOrderParam}from"../../utils/localStorage";import Parent from"../utils/Parent";import getBrowserInfo,{cleanUrlBy}from"../../utils/browserInfo";import PlaceOrderContext from"../../context/PlaceOrderContext";import OrderContext from"../../context/OrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};export function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState(null),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{placeOrderButtonRef}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component?.submit&&component.submit(),!1},handleChange=async(state,checkout2)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=async()=>await handleSubmit(ref.current,checkout2),setPaymentRef({ref}));const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}};paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,component)=>{const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=pSource?.payment_response?.action,resultCode=pSource?.payment_response?.resultCode;if(adyenAction&&component)return component.handleAction(adyenAction),!1;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled","Refused"].includes(resultCode)){const message=pSource?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),component&&component.mount("#adyen-dropin")}return!1}catch(error){return console.error("Adyen additional details error:",error),!1}},onSubmit=async(state,component)=>{const browserInfo=getBrowserInfo(),url=cleanUrlBy();let control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"});if(control?.payment_response?.resultCode==="Authorised")return!0;const paymentDataAvailable=Object.keys(control?.payment_request_data).length>0,paymentMethodSelected=control?.payment_request_data?.payment_method?.type;(!paymentDataAvailable||paymentMethodSelected!==state.data.paymentMethod.type)&&(control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes:{payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}}}));const attributes={payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}},_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=res?.payment_response?.action;if(component&&action)return component.handleAction(action),!1;const resultCode=res?.payment_response?.resultCode;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=res?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}if(res?.payment_response?.errorType)if(res?.payment_response?.errorCode==="14_006")onSubmit(state,component);else{const message=res?.payment_response?.message;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}};return useEffect(()=>{const paymentMethodsResponse=paymentSource?.payment_methods?.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],[firstPaymentMethod]=paymentMethodsResponse,isOnlyCard=paymentMethodsResponse?.length===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse:{paymentMethods:paymentMethodsResponse},showPayButton:!1,paymentMethodsConfiguration:{threeDS2:threeDSConfiguration,paypal:{showPayButton:!0,style:styles?.paypal},card:{styles:styles?.card,holderNameRequired:!1}},onAdditionalDetails:handleOnAdditionalDetails,onChange:handleChange,onSubmit};return!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&import("@adyen/adyen-web").then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=async()=>await handleSubmit(ref.current,component2):ref.current.onsubmit=null,setPaymentRef({ref}))}}).mount("#adyen-dropin");component&&(setCheckout(component),setLoadAdyen(!0))})}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",{ref,onSubmit:e=>{handleSubmit(e,checkout)},children:[_jsx("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}export default AdyenPayment;
@@ -1,12 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { LoaderType } from '../../typings/index';
3
3
  import { CustomerCardsTemplateChildren } from '../utils/PaymentCardsTemplate';
4
- export declare type CustomerCardsProps = {
4
+ export interface CustomerCardsProps {
5
5
  handleClick: () => void;
6
- };
7
- export declare type CustomerSaveToWalletProps = {
6
+ }
7
+ export interface CustomerSaveToWalletProps {
8
8
  name: 'save_payment_source_to_customer_wallet';
9
- };
9
+ }
10
10
  export declare type PaymentSourceProps = {
11
11
  children?: ReactNode;
12
12
  readonly?: boolean;
@@ -16,11 +16,4 @@ export declare type PaymentSourceProps = {
16
16
  loader?: LoaderType;
17
17
  } & JSX.IntrinsicElements['div'];
18
18
  export declare function PaymentSource(props: PaymentSourceProps): JSX.Element;
19
- export declare namespace PaymentSource {
20
- var propTypes: {
21
- children: import("prop-types").Requireable<ReactNode | (() => JSX.Element)>;
22
- readonly: import("prop-types").Requireable<boolean>;
23
- };
24
- var displayName: string;
25
- }
26
19
  export default PaymentSource;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import components from"../../config/components";import PaymentMethodContext from"../../context/PaymentMethodContext";import CustomerContext from"../../context/CustomerContext";import PaymentGateway from"../payment_gateways/PaymentGateway";import getCardDetails from"../../utils/getCardDetails";import OrderContext from"../../context/OrderContext";const propTypes=components.PaymentSource.propTypes,displayName=components.PaymentSource.displayName;export function PaymentSource(props){const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>(readonly?(setShow(!0),setShowCard(!0)):payment?.id===currentPaymentMethodId?(setShow(!0),getCardDetails({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!1),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const gatewayProps={...props,show,showCard,handleEditClick:async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)},readonly};return _jsx(PaymentGateway,{...gatewayProps})}PaymentSource.propTypes=propTypes,PaymentSource.displayName=displayName;export default PaymentSource;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import CustomerContext from"../../context/CustomerContext";import PaymentGateway from"../payment_gateways/PaymentGateway";import getCardDetails from"../../utils/getCardDetails";import OrderContext from"../../context/OrderContext";export function PaymentSource(props){const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>(readonly?(setShow(!0),setShowCard(!0)):payment?.id===currentPaymentMethodId?(setShow(!0),getCardDetails({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!1),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const gatewayProps={...props,show,showCard,handleEditClick:async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)},readonly};return _jsx(PaymentGateway,{...gatewayProps})}export default PaymentSource;
@@ -1 +1 @@
1
- import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import Parent from"../utils/Parent";import PricesContext from"../../context/PricesContext";import{useState,useEffect,useContext}from"react";import{isEmpty,has,indexOf}from"lodash";import{getPricesComponent}from"../../utils/getPrices";import SkuChildrenContext from"../../context/SkuChildrenContext";export function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=useContext(PricesContext),{sku}=useContext(SkuChildrenContext),[skuPrices,setSkuPrices]=useState([]),sCode=pricesSkuCode||skuCode||sku?.code;useEffect(()=>(!isEmpty(prices)&&has(prices,`${sCode}`)?setSkuPrices(prices[sCode]):sCode&&indexOf(skuCodes,sCode)===-1&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes(skuCodes)),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps={loading,loader,prices:skuPrices,...props},pricesComponent=isEmpty(prices)||isEmpty(skuPrices)?null:getPricesComponent(skuPrices,props);return children?_jsx(Parent,{...parentProps,children}):_jsx(_Fragment,{children:loading||isEmpty(pricesComponent)?loader:pricesComponent})}export default Price;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import Parent from"../utils/Parent";import PricesContext from"../../context/PricesContext";import{useState,useEffect,useContext}from"react";import{getPricesComponent}from"../../utils/getPrices";import SkuChildrenContext from"../../context/SkuChildrenContext";export function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=useContext(PricesContext),{sku}=useContext(SkuChildrenContext),[skuPrices,setSkuPrices]=useState([]),sCode=pricesSkuCode||skuCode||sku?.code;useEffect(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps={loading,loader,prices:skuPrices,...props},pricesComponent=prices==null||skuPrices==null?null:getPricesComponent(skuPrices,props);return children?_jsx(Parent,{...parentProps,children}):_jsx(_Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}export default Price;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useContext,useReducer}from"react";import getPrices from"../../utils/getPrices";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import indexOf from"lodash/indexOf";import CommerceLayerContext from"../../context/CommerceLayerContext";import priceReducer,{unsetPriceState,priceInitialState,getSkusPrice}from"../../reducers/PriceReducer";import PricesContext from"../../context/PricesContext";import getCurrentItemKey from"../../utils/getCurrentItemKey";import ItemContext from"../../context/ItemContext";import SkuContext from"../../context/SkuContext";export function PricesContainer(props){const{children,skuCode="",loader="Loading...",perPage=10,filters={}}=props,[state,dispatch]=useReducer(priceReducer,priceInitialState),config=useContext(CommerceLayerContext),{skuCodes}=useContext(SkuContext),{setPrices,prices,items,item:currentItem,skuCode:itemSkuCode}=useContext(ItemContext);indexOf(state.skuCodes,skuCode)===-1&&skuCode&&state.skuCodes.push(skuCode);const sCode=skuCodes&&skuCodes?.length>0?"":skuCode||getCurrentItemKey(currentItem)||itemSkuCode||"",setSkuCodes=skuCodes2=>{dispatch({type:"setSkuCodes",payload:{skuCodes:skuCodes2}})};useEffect(()=>{if(state.skuCodes.length===0&&skuCodes&&skuCodes.length>0&&setSkuCodes(skuCodes),currentItem&&has(prices,sCode)&&dispatch({type:"setPrices",payload:{prices}}),!isEmpty(items)&&isEmpty(currentItem)){const p=getPrices(items);dispatch({type:"setPrices",payload:{prices:p}})}return config.accessToken&&!has(prices,itemSkuCode||sCode)&&(state.skuCodes.length>0||itemSkuCode||sCode)&&getSkusPrice(sCode&&[itemSkuCode||sCode]||state.skuCodes,{config,dispatch,setPrices,prices,perPage,filters}),config.accessToken&&isEmpty(currentItem)&&(state.skuCodes.length>0||skuCode)&&getSkusPrice(sCode&&[sCode]||state.skuCodes,{config,dispatch,setPrices,prices,perPage,filters}),()=>{isEmpty(currentItem)&&unsetPriceState(dispatch)}},[config.accessToken,currentItem,sCode,state.skuCodes.length,itemSkuCode]);const priceValue={...state,skuCode:sCode,loader,setSkuCodes};return _jsx(PricesContext.Provider,{value:priceValue,children})}export default PricesContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useContext,useReducer}from"react";import CommerceLayerContext from"../../context/CommerceLayerContext";import priceReducer,{priceInitialState,getSkusPrice,setSkuCodes}from"../../reducers/PriceReducer";import PricesContext from"../../context/PricesContext";import SkuContext from"../../context/SkuContext";export function PricesContainer(props){const{children,skuCode="",loader="Loading...",perPage=10,filters={}}=props,[state,dispatch]=useReducer(priceReducer,priceInitialState),config=useContext(CommerceLayerContext),{skuCodes}=useContext(SkuContext);!state.skuCodes.includes(skuCode)&&skuCode&&state.skuCodes.push(skuCode);const sCode=skuCodes&&skuCodes?.length>0?"":skuCode??"";useEffect(()=>{state.skuCodes.length===0&&skuCodes!=null&&skuCodes.length>0&&state.setSkuCodes!=null&&state.setSkuCodes({skuCodes,dispatch}),config.accessToken&&(state.skuCodes.length>0||sCode)&&getSkusPrice(sCode&&[sCode]||state.skuCodes,{config,dispatch,perPage,filters})},[config.accessToken,sCode,state.skuCodes.length]);const priceValue={...state,skuCode:sCode,loader,setSkuCodes:params=>setSkuCodes({...params,dispatch})};return _jsx(PricesContext.Provider,{value:priceValue,children})}export default PricesContainer;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import { ChildrenFunction } from '../../typings/index';
3
+ import type { Shipment } from '@commercelayer/sdk';
4
+ interface ChildrenProps extends Omit<Props, 'children'> {
5
+ /**
6
+ * Shipments of the current order
7
+ */
8
+ shipments?: Shipment[];
9
+ /**
10
+ * Quantity of the shipments
11
+ */
12
+ quantity: number;
13
+ }
14
+ interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
15
+ children?: ChildrenFunction<ChildrenProps>;
16
+ }
17
+ export declare function ShipmentsCount({ children, ...p }: Props): JSX.Element;
18
+ export default ShipmentsCount;
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import ShipmentContext from"../../context/ShipmentContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function ShipmentsCount({children,...p}){const{shipments}=useCustomContext({context:ShipmentContext,contextComponentName:"ShipmentsContainer",currentComponentName:"ShipmentsCount",key:"shipments"}),quantity=shipments?.length??0,childrenProps={...p,quantity,shipments};return children?_jsx(Parent,{...childrenProps,children}):_jsx("span",{...p,children:quantity})}export default ShipmentsCount;
@@ -1,14 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
- declare type Props = {
2
+ interface Props {
3
3
  children: ReactNode;
4
4
  skuCode?: string;
5
- };
6
- export declare function AvailabilityContainer(props: Props): JSX.Element;
7
- export declare namespace AvailabilityContainer {
8
- var propTypes: {
9
- children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
10
- skuCode: import("prop-types").Requireable<string>;
11
- };
12
- var displayName: string;
5
+ getQuantity?: (quantity: number) => void;
13
6
  }
7
+ export declare function AvailabilityContainer({ children, skuCode, getQuantity }: Props): JSX.Element;
14
8
  export default AvailabilityContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability,getAvailabilityByIds}from"../../reducers/AvailabilityReducer";import AvailabilityContext from"../../context/AvailabilityContext";import ItemContext from"../../context/ItemContext";import getCurrentItemKey from"../../utils/getCurrentItemKey";import components from"../../config/components";import CommerceLayerContext from"../../context/CommerceLayerContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import SkuContext from"../../context/SkuContext";import isEqual from"lodash/isEqual";const propTypes=components.AvailabilityContainer.propTypes,displayName=components.AvailabilityContainer.displayName;export function AvailabilityContainer(props){const{children,skuCode}=props,{item,skuCode:itemSkuCode,setItem}=useContext(ItemContext),{lineItem}=useContext(LineItemChildrenContext),{sku}=useContext(SkuChildrenContext),{skus}=useContext(SkuContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||getCurrentItemKey(item)||itemSkuCode||lineItem?.sku_code||sku?.code;return useEffect(()=>{if(sCode&&!skus){const available=item[sCode]?.inventory?.available,quantity=item[sCode]?.inventory?.quantity,[level]=item[sCode]?.inventory?.levels||[{quantity:null,delivery_lead_times:[]}];if(level!==void 0&&level?.delivery_lead_times?.length>0){const[delivery]=level.delivery_lead_times;dispatch({type:"setAvailability",payload:{...delivery,quantity:level?.quantity}})}else config.accessToken&&!item?.[sCode]?getAvailability({skuCode:sCode,config,dispatch,setItem,item}):available||dispatch({type:"setAvailability",payload:{quantity}})}else if(skus&&config.accessToken){const itemKeys=Object.keys(item).sort(),skuCodes=skus.map(s=>s?.code).sort();if(!isEqual(skuCodes,itemKeys)){const skusIds=skus.map(s=>s.id);getAvailabilityByIds({skusIds,config,dispatch,setItem})}}return()=>{dispatch({type:"setAvailability",payload:{}})}},[config.accessToken,item,sCode,skus]),_jsx(AvailabilityContext.Provider,{value:{...state},children})}AvailabilityContainer.propTypes=propTypes,AvailabilityContainer.displayName=displayName;export default AvailabilityContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability}from"../../reducers/AvailabilityReducer";import AvailabilityContext from"../../context/AvailabilityContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=useContext(LineItemChildrenContext),{sku}=useContext(SkuChildrenContext),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;return useEffect(()=>(accessToken!=null&&accessToken!==""&&sCode&&getAvailability({skuCode:sCode,config:{accessToken,endpoint},dispatch}),()=>{dispatch({type:"setAvailability",payload:{}})}),[accessToken,sCode]),useEffect(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]),_jsx(AvailabilityContext.Provider,{value:{...state,parent:!0},children})}export default AvailabilityContainer;
@@ -5,11 +5,30 @@ interface AvailabilityTemplateChildrenProps extends Omit<Props, 'children'>, Del
5
5
  text: string;
6
6
  quantity: number;
7
7
  }
8
- declare type Props = {
9
- children?: ChildrenFunction<AvailabilityTemplateChildrenProps>;
8
+ declare type FormatRules = {
9
+ /**
10
+ * Set time format for shipping method
11
+ */
10
12
  timeFormat?: TimeFormat;
11
- showShippingMethodName?: boolean;
13
+ /**
14
+ * Show shipping method name
15
+ */
16
+ showShippingMethodName?: false;
17
+ /**
18
+ * Show shipping method price
19
+ */
20
+ showShippingMethodPrice?: false;
21
+ } | {
22
+ timeFormat: TimeFormat;
23
+ showShippingMethodName: true;
12
24
  showShippingMethodPrice?: boolean;
13
- } & JSX.IntrinsicElements['p'];
25
+ } | {
26
+ timeFormat: TimeFormat;
27
+ showShippingMethodName?: boolean;
28
+ showShippingMethodPrice: true;
29
+ };
30
+ declare type Props = {
31
+ children?: ChildrenFunction<AvailabilityTemplateChildrenProps>;
32
+ } & Omit<JSX.IntrinsicElements['span'], 'children'> & FormatRules;
14
33
  export declare function AvailabilityTemplate(props: Props): JSX.Element;
15
34
  export default AvailabilityTemplate;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AvailabilityContext from"../../context/AvailabilityContext";import Parent from"../utils/Parent";import{isEmpty}from"lodash";import ItemContext from"../../context/ItemContext";import SkuChildrenContext from"../../context/SkuChildrenContext";export function AvailabilityTemplate(props){const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props;let{min,max,shipping_method:shippingMethod,quantity}=useContext(AvailabilityContext);const{item}=useContext(ItemContext),{sku}=useContext(SkuChildrenContext),text=[];if(item&&sku){const code=sku.code,currentItem=item[code];if(currentItem){const[level]=currentItem.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];delivery&&(min=delivery?.min,max=delivery?.max,shippingMethod=delivery?.shipping_method),quantity=currentItem.inventory.quantity}}const mn=!isEmpty(min)&&timeFormat?min?.[timeFormat]:"",mx=!isEmpty(max)&&timeFormat?max?.[timeFormat]:"",shippingMethodPrice=showShippingMethodPrice&&shippingMethod?.formatted_price_amount?`(${shippingMethod?.formatted_price_amount})`:"",name=showShippingMethodName&&shippingMethod?`with ${shippingMethod.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&text.push(`in ${mn} - ${mx} ${timeFormat??""} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps={min,max,shipping_method:shippingMethod,quantity,text:text.join(" "),...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:text.join(" ")})}export default AvailabilityTemplate;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import AvailabilityContext from"../../context/AvailabilityContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function AvailabilityTemplate(props){const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props,{min,max,shipping_method:shippingMethod,quantity}=useCustomContext({context:AvailabilityContext,contextComponentName:"AvailabilityContainer",currentComponentName:"AvailabilityTemplate",key:"parent"}),text=[],mn=min!=null&&timeFormat!=null?min?.[timeFormat]:"",mx=max!=null&&timeFormat!=null?max?.[timeFormat]:"",shippingMethodPrice=showShippingMethodPrice&&shippingMethod?.formatted_price_amount?`(${shippingMethod?.formatted_price_amount})`:"",name=showShippingMethodName&&shippingMethod?`with ${shippingMethod.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&timeFormat&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps={min,max,shipping_method:shippingMethod,quantity,text:text.join(" "),...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:text.join(" ")})}export default AvailabilityTemplate;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import SkuChildrenContext from"../../context/SkuChildrenContext";import GenericFieldComponent from"../utils/GenericFieldComponent";export function SkuField(props){const{attribute,tagElement,children,...p}=props;return _jsx(GenericFieldComponent,{resource:"skus",attribute,tagElement,context:SkuChildrenContext,...p,children})}export default SkuField;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import SkuChildrenContext from"../../context/SkuChildrenContext";import GenericFieldComponent from"../utils/GenericFieldComponent";export function SkuField(props){const{attribute,tagElement,children,...p}=props;return _jsx(GenericFieldComponent,{resource:"sku",attribute,tagElement,context:SkuChildrenContext,...p,children})}export default SkuField;
@@ -1,6 +1,6 @@
1
1
  import type { QueryParamsList } from '@commercelayer/sdk';
2
2
  import { ReactNode } from 'react';
3
- declare type Props = {
3
+ interface Props {
4
4
  /**
5
5
  * An array of skus to display.
6
6
  */
@@ -13,6 +13,6 @@ declare type Props = {
13
13
  * An object params to query the skus resource
14
14
  */
15
15
  queryParams?: QueryParamsList;
16
- };
16
+ }
17
17
  export declare function SkusContainer<P extends Props>(props: P): JSX.Element;
18
18
  export default SkusContainer;