@commercelayer/react-components 4.0.0-alpha.11 → 4.0.0-alpha.13

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 (263) hide show
  1. package/lib/cjs/components/line_items/LineItem.d.ts +4 -11
  2. package/lib/cjs/components/line_items/LineItem.js +1 -1
  3. package/lib/cjs/components/line_items/LineItemAmount.d.ts +0 -13
  4. package/lib/cjs/components/line_items/LineItemAmount.js +1 -1
  5. package/lib/cjs/components/line_items/LineItemCode.d.ts +6 -11
  6. package/lib/cjs/components/line_items/LineItemCode.js +1 -1
  7. package/lib/cjs/components/line_items/LineItemField.d.ts +14 -0
  8. package/lib/cjs/components/line_items/LineItemField.js +1 -0
  9. package/lib/cjs/components/line_items/LineItemImage.d.ts +4 -11
  10. package/lib/cjs/components/line_items/LineItemImage.js +1 -1
  11. package/lib/cjs/components/line_items/LineItemName.d.ts +6 -11
  12. package/lib/cjs/components/line_items/LineItemName.js +1 -1
  13. package/lib/cjs/components/line_items/LineItemOption.d.ts +5 -16
  14. package/lib/cjs/components/line_items/LineItemOption.js +1 -1
  15. package/lib/cjs/components/line_items/LineItemOptions.d.ts +2 -5
  16. package/lib/cjs/components/line_items/LineItemOptions.js +1 -1
  17. package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
  18. package/lib/cjs/components/line_items/LineItemsContainer.d.ts +2 -14
  19. package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
  20. package/lib/cjs/components/orders/AddToCartButton.d.ts +29 -6
  21. package/lib/cjs/components/orders/AddToCartButton.js +1 -1
  22. package/lib/cjs/components/orders/AdjustmentAmount.d.ts +2 -2
  23. package/lib/cjs/components/orders/AdjustmentAmount.js +1 -1
  24. package/lib/cjs/components/orders/DiscountAmount.d.ts +0 -14
  25. package/lib/cjs/components/orders/DiscountAmount.js +1 -1
  26. package/lib/cjs/components/orders/GiftCardAmount.d.ts +0 -11
  27. package/lib/cjs/components/orders/GiftCardAmount.js +1 -1
  28. package/lib/cjs/components/orders/OrderContainer.d.ts +0 -1
  29. package/lib/cjs/components/orders/OrderContainer.js +1 -1
  30. package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +4 -0
  31. package/lib/cjs/components/orders/PaymentMethodAmount.js +1 -0
  32. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
  33. package/lib/cjs/components/orders/PlaceOrderContainer.d.ts +2 -8
  34. package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
  35. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -6
  36. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.js +1 -1
  37. package/lib/cjs/components/orders/ShippingAmount.d.ts +0 -11
  38. package/lib/cjs/components/orders/ShippingAmount.js +1 -1
  39. package/lib/cjs/components/orders/SubTotalAmount.d.ts +0 -14
  40. package/lib/cjs/components/orders/SubTotalAmount.js +1 -1
  41. package/lib/cjs/components/orders/TaxesAmount.d.ts +0 -14
  42. package/lib/cjs/components/orders/TaxesAmount.js +1 -1
  43. package/lib/cjs/components/orders/TotalAmount.d.ts +0 -14
  44. package/lib/cjs/components/orders/TotalAmount.js +1 -1
  45. package/lib/cjs/components/parcels/ParcelLineItemsCount.js +1 -1
  46. package/lib/cjs/components/parcels/ParcelsCount.js +1 -1
  47. package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +1 -7
  48. package/lib/cjs/components/payment_methods/PaymentMethod.js +1 -1
  49. package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +6 -11
  50. package/lib/cjs/components/payment_methods/PaymentMethodName.js +1 -1
  51. package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +2 -14
  52. package/lib/cjs/components/payment_methods/PaymentMethodPrice.js +1 -1
  53. package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.d.ts +4 -9
  54. package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.js +1 -1
  55. package/lib/cjs/components/payment_methods/PaymentMethodsContainer.js +1 -1
  56. package/lib/cjs/components/payment_source/AdyenPayment.d.ts +5 -5
  57. package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
  58. package/lib/cjs/components/prices/Price.js +1 -1
  59. package/lib/cjs/components/prices/PricesContainer.js +1 -1
  60. package/lib/cjs/components/shipments/ShipmentsCount.js +1 -1
  61. package/lib/cjs/components/skus/AvailabilityContainer.d.ts +3 -9
  62. package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
  63. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +23 -4
  64. package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
  65. package/lib/cjs/components/skus/SkuField.js +1 -1
  66. package/lib/cjs/components/skus/SkusContainer.d.ts +2 -2
  67. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +3 -4
  68. package/lib/cjs/components/utils/BaseInput.d.ts +1 -1
  69. package/lib/cjs/components/utils/BaseOrderPrice.d.ts +3 -3
  70. package/lib/cjs/components/utils/BaseOrderPrice.js +1 -1
  71. package/lib/cjs/components/utils/GenericFieldComponent.d.ts +4 -4
  72. package/lib/cjs/components/utils/GenericFieldComponent.js +1 -1
  73. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +3 -3
  74. package/lib/cjs/context/ExternalFunctionContext.d.ts +2 -2
  75. package/lib/cjs/context/ExternalFunctionContext.js +1 -1
  76. package/lib/cjs/context/LineItemContext.d.ts +1 -1
  77. package/lib/cjs/context/OrderContext.d.ts +2 -2
  78. package/lib/cjs/context/PaymentMethodContext.d.ts +2 -11
  79. package/lib/cjs/context/PaymentMethodContext.js +1 -1
  80. package/lib/cjs/index.d.ts +3 -16
  81. package/lib/cjs/index.js +1 -1
  82. package/lib/cjs/reducers/AvailabilityReducer.d.ts +4 -14
  83. package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
  84. package/lib/cjs/reducers/OrderReducer.d.ts +36 -22
  85. package/lib/cjs/reducers/OrderReducer.js +1 -1
  86. package/lib/cjs/reducers/PaymentMethodReducer.d.ts +9 -11
  87. package/lib/cjs/reducers/PaymentMethodReducer.js +1 -1
  88. package/lib/cjs/reducers/PriceReducer.d.ts +12 -19
  89. package/lib/cjs/reducers/PriceReducer.js +1 -1
  90. package/lib/cjs/reducers/SkuReducer.d.ts +3 -3
  91. package/lib/cjs/typings/errors.d.ts +4 -4
  92. package/lib/cjs/typings/index.d.ts +3 -3
  93. package/lib/cjs/utils/browserInfo.d.ts +5 -2
  94. package/lib/cjs/utils/browserInfo.js +1 -1
  95. package/lib/cjs/utils/hooks/useCustomContext.d.ts +21 -0
  96. package/lib/cjs/utils/hooks/useCustomContext.js +1 -0
  97. package/lib/esm/components/line_items/LineItem.d.ts +4 -11
  98. package/lib/esm/components/line_items/LineItem.js +1 -1
  99. package/lib/esm/components/line_items/LineItemAmount.d.ts +0 -13
  100. package/lib/esm/components/line_items/LineItemAmount.js +1 -1
  101. package/lib/esm/components/line_items/LineItemCode.d.ts +6 -11
  102. package/lib/esm/components/line_items/LineItemCode.js +1 -1
  103. package/lib/esm/components/line_items/LineItemField.d.ts +14 -0
  104. package/lib/esm/components/line_items/LineItemField.js +1 -0
  105. package/lib/esm/components/line_items/LineItemImage.d.ts +4 -11
  106. package/lib/esm/components/line_items/LineItemImage.js +1 -1
  107. package/lib/esm/components/line_items/LineItemName.d.ts +6 -11
  108. package/lib/esm/components/line_items/LineItemName.js +1 -1
  109. package/lib/esm/components/line_items/LineItemOption.d.ts +5 -16
  110. package/lib/esm/components/line_items/LineItemOption.js +1 -1
  111. package/lib/esm/components/line_items/LineItemOptions.d.ts +2 -5
  112. package/lib/esm/components/line_items/LineItemOptions.js +1 -1
  113. package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -1
  114. package/lib/esm/components/line_items/LineItemsContainer.d.ts +2 -14
  115. package/lib/esm/components/line_items/LineItemsContainer.js +1 -1
  116. package/lib/esm/components/orders/AddToCartButton.d.ts +29 -6
  117. package/lib/esm/components/orders/AddToCartButton.js +1 -1
  118. package/lib/esm/components/orders/AdjustmentAmount.d.ts +2 -2
  119. package/lib/esm/components/orders/AdjustmentAmount.js +1 -1
  120. package/lib/esm/components/orders/DiscountAmount.d.ts +0 -14
  121. package/lib/esm/components/orders/DiscountAmount.js +1 -1
  122. package/lib/esm/components/orders/GiftCardAmount.d.ts +0 -11
  123. package/lib/esm/components/orders/GiftCardAmount.js +1 -1
  124. package/lib/esm/components/orders/OrderContainer.d.ts +0 -1
  125. package/lib/esm/components/orders/OrderContainer.js +1 -1
  126. package/lib/esm/components/orders/PaymentMethodAmount.d.ts +4 -0
  127. package/lib/esm/components/orders/PaymentMethodAmount.js +1 -0
  128. package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
  129. package/lib/esm/components/orders/PlaceOrderContainer.d.ts +2 -8
  130. package/lib/esm/components/orders/PlaceOrderContainer.js +1 -1
  131. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -6
  132. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.js +1 -1
  133. package/lib/esm/components/orders/ShippingAmount.d.ts +0 -11
  134. package/lib/esm/components/orders/ShippingAmount.js +1 -1
  135. package/lib/esm/components/orders/SubTotalAmount.d.ts +0 -14
  136. package/lib/esm/components/orders/SubTotalAmount.js +1 -1
  137. package/lib/esm/components/orders/TaxesAmount.d.ts +0 -14
  138. package/lib/esm/components/orders/TaxesAmount.js +1 -1
  139. package/lib/esm/components/orders/TotalAmount.d.ts +0 -14
  140. package/lib/esm/components/orders/TotalAmount.js +1 -1
  141. package/lib/esm/components/parcels/ParcelLineItemsCount.js +1 -1
  142. package/lib/esm/components/parcels/ParcelsCount.js +1 -1
  143. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -7
  144. package/lib/esm/components/payment_methods/PaymentMethod.js +1 -1
  145. package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +6 -11
  146. package/lib/esm/components/payment_methods/PaymentMethodName.js +1 -1
  147. package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +2 -14
  148. package/lib/esm/components/payment_methods/PaymentMethodPrice.js +1 -1
  149. package/lib/esm/components/payment_methods/PaymentMethodRadioButton.d.ts +4 -9
  150. package/lib/esm/components/payment_methods/PaymentMethodRadioButton.js +1 -1
  151. package/lib/esm/components/payment_methods/PaymentMethodsContainer.js +1 -1
  152. package/lib/esm/components/payment_source/AdyenPayment.d.ts +5 -5
  153. package/lib/esm/components/payment_source/AdyenPayment.js +1 -1
  154. package/lib/esm/components/prices/Price.js +1 -1
  155. package/lib/esm/components/prices/PricesContainer.js +1 -1
  156. package/lib/esm/components/shipments/ShipmentsCount.js +1 -1
  157. package/lib/esm/components/skus/AvailabilityContainer.d.ts +3 -9
  158. package/lib/esm/components/skus/AvailabilityContainer.js +1 -1
  159. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +23 -4
  160. package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
  161. package/lib/esm/components/skus/SkuField.js +1 -1
  162. package/lib/esm/components/skus/SkusContainer.d.ts +2 -2
  163. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +3 -4
  164. package/lib/esm/components/utils/BaseInput.d.ts +1 -1
  165. package/lib/esm/components/utils/BaseOrderPrice.d.ts +3 -3
  166. package/lib/esm/components/utils/BaseOrderPrice.js +1 -1
  167. package/lib/esm/components/utils/GenericFieldComponent.d.ts +4 -4
  168. package/lib/esm/components/utils/GenericFieldComponent.js +1 -1
  169. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +3 -3
  170. package/lib/esm/context/ExternalFunctionContext.d.ts +2 -2
  171. package/lib/esm/context/ExternalFunctionContext.js +1 -1
  172. package/lib/esm/context/LineItemContext.d.ts +1 -1
  173. package/lib/esm/context/OrderContext.d.ts +2 -2
  174. package/lib/esm/context/PaymentMethodContext.d.ts +2 -11
  175. package/lib/esm/context/PaymentMethodContext.js +1 -1
  176. package/lib/esm/index.d.ts +3 -16
  177. package/lib/esm/index.js +1 -1
  178. package/lib/esm/reducers/AvailabilityReducer.d.ts +4 -14
  179. package/lib/esm/reducers/AvailabilityReducer.js +1 -1
  180. package/lib/esm/reducers/OrderReducer.d.ts +36 -22
  181. package/lib/esm/reducers/OrderReducer.js +1 -1
  182. package/lib/esm/reducers/PaymentMethodReducer.d.ts +9 -11
  183. package/lib/esm/reducers/PaymentMethodReducer.js +1 -1
  184. package/lib/esm/reducers/PriceReducer.d.ts +12 -19
  185. package/lib/esm/reducers/PriceReducer.js +1 -1
  186. package/lib/esm/reducers/SkuReducer.d.ts +3 -3
  187. package/lib/esm/typings/errors.d.ts +4 -4
  188. package/lib/esm/typings/index.d.ts +3 -3
  189. package/lib/esm/utils/browserInfo.d.ts +5 -2
  190. package/lib/esm/utils/browserInfo.js +1 -1
  191. package/lib/esm/utils/hooks/useCustomContext.d.ts +21 -0
  192. package/lib/esm/utils/hooks/useCustomContext.js +1 -0
  193. package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
  194. package/lib/tsconfig.prod.tsbuildinfo +1 -1
  195. package/package.json +2 -2
  196. package/lib/cjs/components/orders/ItemContainer.d.ts +0 -11
  197. package/lib/cjs/components/orders/ItemContainer.js +0 -1
  198. package/lib/cjs/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
  199. package/lib/cjs/components/payment_methods/PaymentMethodAmount.js +0 -1
  200. package/lib/cjs/components/skus/QuantitySelector.d.ts +0 -17
  201. package/lib/cjs/components/skus/QuantitySelector.js +0 -1
  202. package/lib/cjs/components/skus/SkuOption.d.ts +0 -14
  203. package/lib/cjs/components/skus/SkuOption.js +0 -1
  204. package/lib/cjs/components/skus/SkuOptionInput.d.ts +0 -15
  205. package/lib/cjs/components/skus/SkuOptionInput.js +0 -1
  206. package/lib/cjs/components/skus/SkuOptionsContainer.d.ts +0 -14
  207. package/lib/cjs/components/skus/SkuOptionsContainer.js +0 -1
  208. package/lib/cjs/components/skus/VariantSelector.d.ts +0 -29
  209. package/lib/cjs/components/skus/VariantSelector.js +0 -1
  210. package/lib/cjs/components/skus/VariantsContainer.d.ts +0 -20
  211. package/lib/cjs/components/skus/VariantsContainer.js +0 -1
  212. package/lib/cjs/components/utils/VariantTemplate.d.ts +0 -36
  213. package/lib/cjs/components/utils/VariantTemplate.js +0 -1
  214. package/lib/cjs/context/ItemContext.d.ts +0 -13
  215. package/lib/cjs/context/ItemContext.js +0 -1
  216. package/lib/cjs/context/SkuOptionChildrenContext.d.ts +0 -8
  217. package/lib/cjs/context/SkuOptionChildrenContext.js +0 -1
  218. package/lib/cjs/context/SkuOptionsContext.d.ts +0 -3
  219. package/lib/cjs/context/SkuOptionsContext.js +0 -1
  220. package/lib/cjs/context/VariantsContext.d.ts +0 -3
  221. package/lib/cjs/context/VariantsContext.js +0 -1
  222. package/lib/cjs/reducers/ItemReducer.d.ts +0 -69
  223. package/lib/cjs/reducers/ItemReducer.js +0 -1
  224. package/lib/cjs/reducers/SkuOptionsReducer.d.ts +0 -26
  225. package/lib/cjs/reducers/SkuOptionsReducer.js +0 -1
  226. package/lib/cjs/reducers/VariantReducer.d.ts +0 -72
  227. package/lib/cjs/reducers/VariantReducer.js +0 -1
  228. package/lib/cjs/utils/getCurrentItemKey.d.ts +0 -6
  229. package/lib/cjs/utils/getCurrentItemKey.js +0 -1
  230. package/lib/esm/components/orders/ItemContainer.d.ts +0 -11
  231. package/lib/esm/components/orders/ItemContainer.js +0 -1
  232. package/lib/esm/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
  233. package/lib/esm/components/payment_methods/PaymentMethodAmount.js +0 -1
  234. package/lib/esm/components/skus/QuantitySelector.d.ts +0 -17
  235. package/lib/esm/components/skus/QuantitySelector.js +0 -1
  236. package/lib/esm/components/skus/SkuOption.d.ts +0 -14
  237. package/lib/esm/components/skus/SkuOption.js +0 -1
  238. package/lib/esm/components/skus/SkuOptionInput.d.ts +0 -15
  239. package/lib/esm/components/skus/SkuOptionInput.js +0 -1
  240. package/lib/esm/components/skus/SkuOptionsContainer.d.ts +0 -14
  241. package/lib/esm/components/skus/SkuOptionsContainer.js +0 -1
  242. package/lib/esm/components/skus/VariantSelector.d.ts +0 -29
  243. package/lib/esm/components/skus/VariantSelector.js +0 -1
  244. package/lib/esm/components/skus/VariantsContainer.d.ts +0 -20
  245. package/lib/esm/components/skus/VariantsContainer.js +0 -1
  246. package/lib/esm/components/utils/VariantTemplate.d.ts +0 -36
  247. package/lib/esm/components/utils/VariantTemplate.js +0 -1
  248. package/lib/esm/context/ItemContext.d.ts +0 -13
  249. package/lib/esm/context/ItemContext.js +0 -1
  250. package/lib/esm/context/SkuOptionChildrenContext.d.ts +0 -8
  251. package/lib/esm/context/SkuOptionChildrenContext.js +0 -1
  252. package/lib/esm/context/SkuOptionsContext.d.ts +0 -3
  253. package/lib/esm/context/SkuOptionsContext.js +0 -1
  254. package/lib/esm/context/VariantsContext.d.ts +0 -3
  255. package/lib/esm/context/VariantsContext.js +0 -1
  256. package/lib/esm/reducers/ItemReducer.d.ts +0 -69
  257. package/lib/esm/reducers/ItemReducer.js +0 -1
  258. package/lib/esm/reducers/SkuOptionsReducer.d.ts +0 -26
  259. package/lib/esm/reducers/SkuOptionsReducer.js +0 -1
  260. package/lib/esm/reducers/VariantReducer.d.ts +0 -72
  261. package/lib/esm/reducers/VariantReducer.js +0 -1
  262. package/lib/esm/utils/getCurrentItemKey.d.ts +0 -6
  263. package/lib/esm/utils/getCurrentItemKey.js +0 -1
@@ -27,7 +27,7 @@ export declare const ErrorPropTypes: {
27
27
  declare type ErrorChildrenComponentProps = ChildrenFunction<Omit<ErrorComponentProps, 'children'> & {
28
28
  errors: string[];
29
29
  }>;
30
- export declare type ErrorComponentProps = {
30
+ export interface ErrorComponentProps {
31
31
  /**
32
32
  * Resource which caused the error
33
33
  */
@@ -40,12 +40,12 @@ export declare type ErrorComponentProps = {
40
40
  /**
41
41
  * Error message which you can translate
42
42
  */
43
- messages?: {
43
+ messages?: Array<{
44
44
  code: CodeErrorType;
45
45
  message: string;
46
46
  resource?: ResourceErrorType;
47
47
  field?: string;
48
48
  id?: string;
49
- }[];
50
- };
49
+ }>;
50
+ }
51
51
  export {};
@@ -109,13 +109,13 @@ export declare const baseOrderComponentPricePropTypes: {
109
109
  export declare type BasePriceType = 'total' | 'option' | 'unit';
110
110
  export declare type BaseSelectorType = 'select' | 'radio';
111
111
  export declare type BaseAmountComponentChildren = Omit<BaseAmountComponent, 'children'>;
112
- export declare type BaseAmountComponent = {
113
- children?: (props: BaseAmountComponentChildren) => JSX.Element;
112
+ export interface BaseAmountComponent extends Omit<JSX.IntrinsicElements['span'], 'children'> {
113
+ children?: ChildrenFunction<BaseAmountComponentChildren>;
114
114
  format?: BaseFormatPrice;
115
115
  price?: string;
116
116
  priceCents?: number;
117
117
  labelFree?: string;
118
- } & JSX.IntrinsicElements['span'];
118
+ }
119
119
  export declare type ChildrenFunction<P = Record<string, any>> = (props: P) => JSX.Element;
120
120
  export declare type ExcludeTag<T extends keyof JSX.IntrinsicElements> = Exclude<keyof JSX.IntrinsicElements, T>;
121
121
  export declare type ExtractTag<T extends keyof JSX.IntrinsicElements> = Extract<keyof JSX.IntrinsicElements, T>;
@@ -1,4 +1,4 @@
1
- export default function getBrowserInfo(): {
1
+ interface TReturn {
2
2
  screenWidth: string | number;
3
3
  screenHeight: string | number;
4
4
  colorDepth: string | number;
@@ -6,4 +6,7 @@ export default function getBrowserInfo(): {
6
6
  timeZoneOffset: number;
7
7
  language: string;
8
8
  javaEnabled: boolean;
9
- };
9
+ }
10
+ export default function getBrowserInfo(): TReturn;
11
+ export declare function cleanUrlBy(symbol?: string): string;
12
+ export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function getBrowserInfo(){const screenWidth=window&&window.screen?window.screen.width:"",screenHeight=window&&window.screen?window.screen.height:"",colorDepth=window&&window.screen?window.screen.colorDepth:"",userAgent=window&&window.navigator?window.navigator.userAgent:"",javaEnabled=window&&window.navigator?navigator.javaEnabled():!1;let language="";window&&window.navigator&&(language=window.navigator.language);const timeZoneOffset=new Date().getTimezoneOffset();return{screenWidth,screenHeight,colorDepth,userAgent,timeZoneOffset,language,javaEnabled}}exports.default=getBrowserInfo;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.cleanUrlBy=void 0;function getBrowserInfo(){const screenWidth=window?.screen?window.screen.width:"",screenHeight=window?.screen?window.screen.height:"",colorDepth=window?.screen?window.screen.colorDepth:"",userAgent=window?.navigator?window.navigator.userAgent:"",javaEnabled=window?.navigator?navigator.javaEnabled():!1;let language="";window?.navigator&&(language=window.navigator.language);const timeZoneOffset=new Date().getTimezoneOffset();return{screenWidth,screenHeight,colorDepth,userAgent,timeZoneOffset,language,javaEnabled}}exports.default=getBrowserInfo;function cleanUrlBy(symbol="&"){const currentLocation=window?.location.href,[splitLocation]=currentLocation.split(symbol);return splitLocation??currentLocation}exports.cleanUrlBy=cleanUrlBy;
@@ -0,0 +1,21 @@
1
+ import { Context } from 'react';
2
+ interface TParams<C> {
3
+ /**
4
+ * Context to check
5
+ */
6
+ context: Context<C>;
7
+ /**
8
+ * Name of the component has the context
9
+ */
10
+ contextComponentName: string;
11
+ /**
12
+ * Name of the current component
13
+ */
14
+ currentComponentName: string;
15
+ /**
16
+ * Key of the context to check
17
+ */
18
+ key?: string;
19
+ }
20
+ export default function useCustomContext<T>({ context, key, currentComponentName, contextComponentName }: TParams<T>): T;
21
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const react_1=require("react");function useCustomContext({context,key,currentComponentName,contextComponentName}){const currentContext=(0,react_1.useContext)(context),isProduction=process.env.NODE_ENV==="production",msg=`Cannot use <${currentComponentName}/> outside of <${contextComponentName}/>`;if(key!=null&&key in currentContext||key==null&&currentContext!=null)return currentContext;if(isProduction)console.error(msg);else throw new Error(msg);return currentContext}exports.default=useCustomContext;
@@ -1,15 +1,8 @@
1
- import { ReactNode } from 'react';
1
+ /// <reference types="react" />
2
2
  import { LineItemType } from '../../typings/index';
3
- declare type Props = {
4
- children: ReactNode;
3
+ interface Props {
4
+ children: JSX.Element | JSX.Element[];
5
5
  type?: LineItemType;
6
- };
7
- export declare function LineItem(props: Props): JSX.Element;
8
- export declare namespace LineItem {
9
- var propTypes: {
10
- children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
11
- type: import("prop-types").Requireable<LineItemType>;
12
- };
13
- var displayName: string;
14
6
  }
7
+ export declare function LineItem(props: Props): JSX.Element;
15
8
  export default LineItem;
@@ -1 +1 @@
1
- import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemContext from"../../context/LineItemContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import components from"../../config/components";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";const propTypes=components.LineItem.propTypes,displayName=components.LineItem.displayName;export function LineItem(props){const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),items=shipmentLineItems&&shipmentLineItems?.length>0?shipmentLineItems:lineItems,components2=items&&items.filter(l=>l.item_type===type).map((lineItem,k,check)=>{if(lineItem.item_type==="bundles"&&k>0&&check[k-1]?.bundle_code===lineItem.bundle_code||lineItem.item_type==="gift_cards"&&lineItem?.total_amount_cents&&lineItem?.total_amount_cents<=0)return null;const lineProps={lineItem};return _jsx(LineItemChildrenContext.Provider,{value:lineProps,children},k)});return _jsx(_Fragment,{children:components2})}LineItem.propTypes=propTypes,LineItem.displayName=displayName;export default LineItem;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemContext from"../../context/LineItemContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";export function LineItem(props){const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),components=(shipmentLineItems&&shipmentLineItems?.length>0?shipmentLineItems:lineItems)?.filter(l=>l.item_type===type).map((lineItem,k,check)=>{if(lineItem.item_type==="bundles"&&k>0&&check[k-1]?.bundle_code===lineItem.bundle_code||lineItem.item_type==="gift_cards"&&lineItem?.total_amount_cents&&lineItem?.total_amount_cents<=0)return null;const lineProps={lineItem};return _jsx(LineItemChildrenContext.Provider,{value:lineProps,children},k)});return _jsx(_Fragment,{children:components})}export default LineItem;
@@ -4,17 +4,4 @@ declare type Props = BaseAmountComponent & {
4
4
  type?: BasePriceType;
5
5
  };
6
6
  export declare function LineItemAmount(props: Props): JSX.Element;
7
- export declare namespace LineItemAmount {
8
- var propTypes: {
9
- type: import("prop-types").Requireable<BasePriceType>;
10
- id: import("prop-types").Requireable<string>;
11
- className: import("prop-types").Requireable<string>;
12
- style: import("prop-types").Requireable<object>;
13
- name: import("prop-types").Requireable<string>;
14
- children: import("prop-types").Requireable<(...args: any[]) => any>;
15
- format: import("prop-types").Requireable<import("../../typings/index").BaseFormatPrice>;
16
- };
17
- var defaultProps: Props;
18
- var displayName: string;
19
- }
20
7
  export default LineItemAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../../utils/getAmount";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";import components from"../../config/components";const propTypes=components.LineItemAmount.propTypes,defaultProps=components.LineItemAmount.defaultProps,displayName=components.LineItemAmount.displayName;export function LineItemAmount(props){const{format="formatted",type="total",...p}=props,{lineItem}=useContext(LineItemChildrenContext),[price,setPrice]=useState("");useEffect(()=>{if(lineItem){const p2=getAmount({base:"amount",type,format,obj:lineItem});setPrice(p2)}return()=>{setPrice("")}},[lineItem]);const parentProps={price,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:price})}LineItemAmount.propTypes=propTypes,LineItemAmount.defaultProps=defaultProps,LineItemAmount.displayName=displayName;export default LineItemAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../../utils/getAmount";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemAmount(props){const{format="formatted",type="total",...p}=props,{lineItem}=useContext(LineItemChildrenContext),[price,setPrice]=useState("");useEffect(()=>{if(lineItem){const p2=getAmount({base:"amount",type,format,obj:lineItem});setPrice(p2)}return()=>{setPrice("")}},[lineItem]);const parentProps={price,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:price})}export default LineItemAmount;
@@ -1,18 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { LineItem } from '@commercelayer/sdk';
3
- export declare type LineItemCodeType = Omit<Props, 'children'> & {
3
+ import { ChildrenFunction } from '../../typings/index';
4
+ export interface TLineItemCode extends Omit<Props, 'children'> {
4
5
  lineItem: LineItem;
5
6
  skuCode: string;
6
- };
7
- declare type Props = {
8
- children?: (props: LineItemCodeType) => JSX.Element;
7
+ }
8
+ interface Props extends Omit<JSX.IntrinsicElements['p'], 'children'> {
9
+ children?: ChildrenFunction<TLineItemCode>;
9
10
  type?: 'sku_code' | 'bundle_code';
10
- } & JSX.IntrinsicElements['p'];
11
- export declare function LineItemCode({ type, children, ...p }: Props): JSX.Element;
12
- export declare namespace LineItemCode {
13
- var propTypes: {
14
- children: import("prop-types").Requireable<(...args: any[]) => any>;
15
- };
16
- var displayName: string;
17
11
  }
12
+ export declare function LineItemCode({ type, children, ...p }: Props): JSX.Element;
18
13
  export default LineItemCode;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";import components from"../../config/components";const propTypes=components.LineItemCode.propTypes,displayName=components.LineItemCode.displayName;export function LineItemCode({type="sku_code",children,...p}){const{lineItem}=useContext(LineItemChildrenContext),labelName=lineItem?.[type],parentProps={lineItem,skuCode:labelName,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:labelName})}LineItemCode.propTypes=propTypes,LineItemCode.displayName=displayName;export default LineItemCode;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemCode({type="sku_code",children,...p}){const{lineItem}=useContext(LineItemChildrenContext),labelName=lineItem?.[type],parentProps={lineItem,skuCode:labelName,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:labelName})}export default LineItemCode;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { ConditionalElement } from '../../typings/index';
3
+ import { TGenericChildrenProps, TResources } from '../utils/GenericFieldComponent';
4
+ declare type LineItemFieldChildrenProps = TGenericChildrenProps<TResources['LineItem']>;
5
+ declare type TCondition = ConditionalElement<Exclude<TResources['LineItem'], 'resource'>>;
6
+ declare type Props = {
7
+ children?: (props: LineItemFieldChildrenProps) => JSX.Element;
8
+ } & TCondition;
9
+ /**
10
+ * @param props {@link Props}
11
+ * @returns
12
+ */
13
+ export declare function LineItemField<P extends Props>(props: P): JSX.Element;
14
+ export default LineItemField;
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import GenericFieldComponent from"../utils/GenericFieldComponent";export function LineItemField(props){const{attribute,tagElement,children,...p}=props;return _jsx(GenericFieldComponent,{resource:"lineItem",attribute,tagElement,context:LineItemChildrenContext,...p,children})}export default LineItemField;
@@ -1,23 +1,16 @@
1
1
  /// <reference types="react" />
2
2
  import { LineItem } from '@commercelayer/sdk';
3
- import { LineItemType } from '../../typings/index';
4
- export declare type LineItemImageType = Omit<Props, 'children'> & {
3
+ import { ChildrenFunction, LineItemType } from '../../typings/index';
4
+ export interface TLineItemImage extends Omit<Props, 'children'> {
5
5
  src: string;
6
6
  lineItem: LineItem;
7
- };
7
+ }
8
8
  declare type Props = {
9
- children?: (props: LineItemImageType) => JSX.Element;
9
+ children?: ChildrenFunction<TLineItemImage>;
10
10
  width?: number;
11
11
  placeholder?: {
12
12
  [K in LineItemType]?: string;
13
13
  };
14
14
  } & Omit<JSX.IntrinsicElements['img'], 'src' | 'srcSet' | 'placeholder'>;
15
15
  export declare function LineItemImage(props: Props): JSX.Element | null;
16
- export declare namespace LineItemImage {
17
- var propTypes: {
18
- width: import("prop-types").Requireable<number>;
19
- children: import("prop-types").Requireable<(...args: any[]) => any>;
20
- };
21
- var displayName: string;
22
- }
23
16
  export default LineItemImage;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import components from"../../config/components";import{defaultGiftCardImgUrl,defaultImgUrl}from"../../utils/placeholderImages";const propTypes=components.LineItemImage.propTypes,displayName=components.LineItemImage.displayName;export function LineItemImage(props){const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),itemType=lineItem?.item_type;let src=lineItem?.image_url;src||(placeholder?.[itemType]?src=placeholder?.[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps={lineItem,src,placeholder,...p};return children?_jsx(Parent,{...parenProps,children}):src?_jsx("img",{alt:"",src,...p}):null}LineItemImage.propTypes=propTypes,LineItemImage.displayName=displayName;export default LineItemImage;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import{defaultGiftCardImgUrl,defaultImgUrl}from"../../utils/placeholderImages";import Parent from"../utils/Parent";export function LineItemImage(props){const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),itemType=lineItem?.item_type;let src=lineItem?.image_url;src||(placeholder?.[itemType]?src=placeholder?.[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps={lineItem,src,placeholder,...p};return children?_jsx(Parent,{...parenProps,children}):src?_jsx("img",{"data-testid":`line-item-image-${lineItem?.sku_code??""}`,alt:lineItem?.name,src,...p}):null}export default LineItemImage;
@@ -1,17 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { LineItem } from '@commercelayer/sdk';
3
- export declare type LineItemNameType = Omit<Props, 'children'> & {
3
+ import { ChildrenFunction } from '../../typings/index';
4
+ export interface TLineItemName extends Omit<Props, 'children'> {
4
5
  label: string;
5
6
  lineItem: LineItem;
6
- };
7
- declare type Props = {
8
- children?: (props: LineItemNameType) => JSX.Element;
9
- } & JSX.IntrinsicElements['p'];
10
- export declare function LineItemName(props: Props): JSX.Element;
11
- export declare namespace LineItemName {
12
- var propTypes: {
13
- children: import("prop-types").Requireable<(...args: any[]) => any>;
14
- };
15
- var displayName: string;
16
7
  }
8
+ interface Props extends Omit<JSX.IntrinsicElements['p'], 'children'> {
9
+ children?: ChildrenFunction<TLineItemName>;
10
+ }
11
+ export declare function LineItemName(props: Props): JSX.Element;
17
12
  export default LineItemName;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";import components from"../../config/components";const propTypes=components.LineItemName.propTypes,displayName=components.LineItemName.displayName;export function LineItemName(props){const{lineItem}=useContext(LineItemChildrenContext),label=lineItem?.name,parentProps={label,lineItem,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("p",{...props,children:label})}LineItemName.propTypes=propTypes,LineItemName.displayName=displayName;export default LineItemName;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemName(props){const{lineItem}=useContext(LineItemChildrenContext),label=lineItem?.name,parentProps={label,lineItem,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("p",{"data-testid":`line-item-name-${lineItem?.sku_code??""}`,...props,children:label})}export default LineItemName;
@@ -1,30 +1,19 @@
1
1
  import { CSSProperties } from 'react';
2
2
  import { LineItemOption as LineItemOptionType } from '@commercelayer/sdk';
3
3
  import { ChildrenFunction } from '../../typings/index';
4
- declare type LineItemOptionChildrenProps = ChildrenFunction<Omit<Props, 'children'> & {
4
+ export interface TLineItemOption extends Omit<Props, 'children'> {
5
5
  lineItemOption: LineItemOptionType;
6
- }>;
7
- declare type Props = {
6
+ }
7
+ interface Props {
8
8
  id?: string;
9
9
  className?: string;
10
10
  key?: string;
11
11
  style?: CSSProperties;
12
- children?: LineItemOptionChildrenProps;
12
+ children?: ChildrenFunction<TLineItemOption>;
13
13
  name?: string;
14
14
  valueClassName?: string;
15
15
  tagElement?: keyof JSX.IntrinsicElements;
16
16
  tagContainer?: keyof JSX.IntrinsicElements;
17
- };
18
- export declare function LineItemOption(props: Props): JSX.Element;
19
- export declare namespace LineItemOption {
20
- var propTypes: {
21
- name: import("prop-types").Requireable<string>;
22
- children: import("prop-types").Requireable<(...args: any[]) => any>;
23
- valueClassName: import("prop-types").Requireable<string>;
24
- className: import("prop-types").Requireable<string>;
25
- id: import("prop-types").Requireable<string>;
26
- style: import("prop-types").Requireable<object>;
27
- };
28
- var displayName: string;
29
17
  }
18
+ export declare function LineItemOption(props: Props): JSX.Element;
30
19
  export default LineItemOption;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import LineItemOptionChildrenContext from"../../context/LineItemOptionChildrenContext";import get from"lodash/get";import has from"lodash/has";import map from"lodash/map";import Parent from"../utils/Parent";import components from"../../config/components";import isJSON from"../../utils/isJSON";const propTypes=components.LineItemOption.propTypes,displayName=components.LineItemOption.displayName;export function LineItemOption(props){const{name,children,valueClassName,key,tagElement="li",tagContainer="ul",...p}=props,{lineItemOption,showAll}=useContext(LineItemOptionChildrenContext),parentProps={...props,lineItemOption},TagElement=tagElement,TagContainer=tagContainer,components2=showAll&&isJSON(JSON.stringify(lineItemOption?.options))?map(lineItemOption?.options,(value,key2)=>_jsxs(TagElement,{...p,children:[`${key2}:`,_jsx("span",{className:valueClassName,children:`${value}`})]},key2)):has(lineItemOption,`options.${name}`)?_jsxs(TagElement,{...p,children:[`${name}:`,_jsx("span",{className:valueClassName,...p,children:`${get(lineItemOption,`options.${name}`)}`})]},key):null;return children?_jsx(Parent,{...parentProps,children:props.children}):_jsx(TagContainer,{children:components2})}LineItemOption.propTypes=propTypes,LineItemOption.displayName=displayName;export default LineItemOption;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import LineItemOptionChildrenContext from"../../context/LineItemOptionChildrenContext";import get from"lodash/get";import has from"lodash/has";import map from"lodash/map";import Parent from"../utils/Parent";import isJSON from"../../utils/isJSON";export function LineItemOption(props){const{name,children,valueClassName,key,tagElement="li",tagContainer="ul",...p}=props,{lineItemOption,showAll}=useContext(LineItemOptionChildrenContext),parentProps={...props,lineItemOption},TagElement=tagElement,TagContainer=tagContainer,components=showAll&&isJSON(JSON.stringify(lineItemOption?.options))?map(lineItemOption?.options,(value,key2)=>_jsxs(TagElement,{...p,children:[`${key2}:`,_jsx("span",{className:valueClassName,children:`${value}`})]},key2)):has(lineItemOption,`options.${name}`)?_jsxs(TagElement,{...p,children:[`${name}:`,_jsx("span",{className:valueClassName,...p,children:`${get(lineItemOption,`options.${name}`)}`})]},key):null;return children?_jsx(Parent,{...parentProps,children:props.children}):_jsx(TagContainer,{children:components})}export default LineItemOption;
@@ -1,11 +1,11 @@
1
1
  import { ReactNode } from 'react';
2
- declare type Props = JSX.IntrinsicElements['div'] & {
2
+ declare type Props = {
3
3
  children: ReactNode;
4
4
  title?: string;
5
5
  showName?: boolean;
6
6
  titleTagElement?: keyof JSX.IntrinsicElements;
7
7
  titleClassName?: string;
8
- } & ({
8
+ } & Omit<JSX.IntrinsicElements['div'], 'children'> & ({
9
9
  skuOptionId: string;
10
10
  showAll?: never;
11
11
  } | {
@@ -13,7 +13,4 @@ declare type Props = JSX.IntrinsicElements['div'] & {
13
13
  showAll: true;
14
14
  });
15
15
  export declare function LineItemOptions(props: Props): JSX.Element;
16
- export declare namespace LineItemOptions {
17
- var displayName: string;
18
- }
19
16
  export default LineItemOptions;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemOptionChildrenContext from"../../context/LineItemOptionChildrenContext";import{isEmpty}from"lodash";import components from"../../config/components";const displayName=components.LineItemOptions.displayName;export function LineItemOptions(props){const{skuOptionId,title,children,showName=!0,showAll,className,titleTagElement="h6",titleClassName,...p}=props,{lineItem}=useContext(LineItemChildrenContext),lineItemOptions=isEmpty(lineItem)?[]:lineItem?.line_item_options||[],TitleTagElement=titleTagElement,options=lineItemOptions.filter(o=>showAll?!0:o.skuOption().id===skuOptionId).map((o,k)=>{const showTitle=showName?_jsx(TitleTagElement,{className:titleClassName,children:title||o.name}):null,valueProps={lineItemOption:o,showAll};return _jsxs("div",{className,...p,children:[showTitle,_jsx(LineItemOptionChildrenContext.Provider,{value:valueProps,children})]},k)});return _jsx(_Fragment,{children:options})}LineItemOptions.displayName=displayName;export default LineItemOptions;
1
+ import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemOptionChildrenContext from"../../context/LineItemOptionChildrenContext";export function LineItemOptions(props){const{skuOptionId,title,children,showName=!0,showAll,className,titleTagElement="h6",titleClassName,...p}=props,{lineItem}=useContext(LineItemChildrenContext),lineItemOptions=lineItem!=null?lineItem?.line_item_options||[]:[],TitleTagElement=titleTagElement,options=lineItemOptions.filter(o=>showAll?!0:o.skuOption().id===skuOptionId).map((o,k)=>{const showTitle=showName?_jsx(TitleTagElement,{className:titleClassName,children:title||o.name}):null,valueProps={lineItemOption:o,showAll};return _jsxs("div",{className,...p,children:[showTitle,_jsx(LineItemOptionChildrenContext.Provider,{value:valueProps,children})]},k)});return _jsx(_Fragment,{children:options})}export default LineItemOptions;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";export function LineItemRemoveLink(props){const{label="Remove"}=props,{lineItem}=useContext(LineItemChildrenContext),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem&&lineItem&&deleteLineItem(lineItem.id)},parentProps={handleRemove,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("a",{...props,href:"#",onClick:handleRemove,children:label})}export default LineItemRemoveLink;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function LineItemRemoveLink(props){const{label="Remove",onClick}=props,{lineItem}=useCustomContext({context:LineItemChildrenContext,contextComponentName:"LineItem",currentComponentName:"LineItemRemoveLink",key:"lineItem"}),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem!=null&&lineItem!=null&&deleteLineItem(lineItem.id),onClick?.(e)},parentProps={handleRemove,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("a",{"data-testid":`line-item-remove-link-${lineItem?.sku_code??""}`,...props,href:"#",onClick:handleRemove,children:label})}export default LineItemRemoveLink;
@@ -1,20 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
- declare type Props = {
2
+ interface Props {
3
3
  children: ReactNode;
4
4
  filters?: Record<string, any>;
5
5
  loader?: ReactNode;
6
- };
7
- export declare function LineItemsContainer(props: Props): JSX.Element;
8
- export declare namespace LineItemsContainer {
9
- var propTypes: {
10
- children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
11
- filters: import("prop-types").Requireable<object>;
12
- loader: import("prop-types").Requireable<NonNullable<string | import("prop-types").ReactElementLike | null | undefined>>;
13
- };
14
- var defaultProps: {
15
- filters: {};
16
- loader: string;
17
- };
18
- var displayName: string;
19
6
  }
7
+ export declare function LineItemsContainer(props: Props): JSX.Element;
20
8
  export default LineItemsContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext}from"react";import lineItemReducer,{lineItemInitialState,updateLineItem,deleteLineItem}from"../../reducers/LineItemReducer";import OrderContext from"../../context/OrderContext";import LineItemContext from"../../context/LineItemContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import components from"../../config/components";const propTypes=components.LineItemsContainer.propTypes,defaultProps=components.LineItemsContainer.defaultProps,displayName=components.LineItemsContainer.displayName;export function LineItemsContainer(props){const{children,loader="Loading..."}=props,{order,addResourceToInclude,include,orderId,getOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(lineItemReducer,lineItemInitialState);useEffect(()=>{include?.includes("line_items.line_item_options.sku_option")?includeLoaded?.["line_items.line_item_options.sku_option"]||addResourceToInclude({newResourceLoaded:{"line_items.line_item_options.sku_option":!0}}):addResourceToInclude({newResource:["line_items.line_item_options.sku_option"]}),include?.includes("line_items.item")?includeLoaded?.["line_items.item"]||addResourceToInclude({newResourceLoaded:{"line_items.item":!0}}):addResourceToInclude({newResource:["line_items.item"]})},[include,includeLoaded]),useEffect(()=>{order?.line_items&&dispatch({type:"setLineItems",payload:{lineItems:order.line_items}})},[order?.line_items]);const lineItemValue={...state,loader,updateLineItem:(lineItemId,quantity=1)=>updateLineItem({lineItemId,quantity,dispatch,config,getOrder,orderId,errors:state.errors}),deleteLineItem:lineItemId=>deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})};return _jsx(LineItemContext.Provider,{value:lineItemValue,children:state.loading?loader:children})}LineItemsContainer.propTypes=propTypes,LineItemsContainer.defaultProps=defaultProps,LineItemsContainer.displayName=displayName;export default LineItemsContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext}from"react";import lineItemReducer,{lineItemInitialState,updateLineItem,deleteLineItem}from"../../reducers/LineItemReducer";import OrderContext from"../../context/OrderContext";import LineItemContext from"../../context/LineItemContext";import CommerceLayerContext from"../../context/CommerceLayerContext";export function LineItemsContainer(props){const{children,loader="Loading..."}=props,{order,addResourceToInclude,include,orderId,getOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(lineItemReducer,lineItemInitialState);useEffect(()=>{include?.includes("line_items.line_item_options.sku_option")?includeLoaded?.["line_items.line_item_options.sku_option"]||addResourceToInclude({newResourceLoaded:{"line_items.line_item_options.sku_option":!0}}):addResourceToInclude({newResource:["line_items.line_item_options.sku_option"]}),include?.includes("line_items.item")?includeLoaded?.["line_items.item"]||addResourceToInclude({newResourceLoaded:{"line_items.item":!0}}):addResourceToInclude({newResource:["line_items.item"]})},[include,includeLoaded]),useEffect(()=>{order?.line_items&&dispatch({type:"setLineItems",payload:{lineItems:order.line_items}})},[order?.line_items]);const lineItemValue={...state,loader,updateLineItem:(lineItemId,quantity=1)=>updateLineItem({lineItemId,quantity,dispatch,config,getOrder,orderId,errors:state.errors}),deleteLineItem:lineItemId=>deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})};return _jsx(LineItemContext.Provider,{value:lineItemValue,children:state.loading?loader:children})}export default LineItemsContainer;
@@ -1,11 +1,9 @@
1
1
  import { PropsWithoutRef } from 'react';
2
2
  import { ChildrenFunction } from '../../typings/index';
3
- import { AddToCartReturn } from '../../reducers/OrderReducer';
4
- import { VariantOption } from '../skus/VariantSelector';
5
- interface ChildrenProps extends Omit<Props, 'children'> {
3
+ import { AddToCartReturn, CustomLineItem, LineItemOption } from '../../reducers/OrderReducer';
4
+ interface TAddToCartButton extends Omit<Props, 'children'> {
6
5
  handleClick: () => AddToCartReturn;
7
6
  }
8
- export declare type AddToCartButtonType = ChildrenProps;
9
7
  declare type BuyNowMode = {
10
8
  buyNowMode: true;
11
9
  checkoutUrl?: string;
@@ -22,13 +20,38 @@ declare type THostedCart = {
22
20
  };
23
21
  declare type TButton = PropsWithoutRef<Omit<JSX.IntrinsicElements['button'], 'children'>>;
24
22
  declare type Props = {
23
+ /**
24
+ * Code of a bundle
25
+ */
25
26
  bundleCode?: string;
26
- children?: ChildrenFunction<ChildrenProps>;
27
+ children?: ChildrenFunction<TAddToCartButton>;
28
+ /**
29
+ * Disable the cart button
30
+ */
27
31
  disabled?: boolean;
32
+ /**
33
+ * Label to display
34
+ */
28
35
  label?: string | JSX.Element;
29
- lineItem?: VariantOption['lineItem'];
36
+ /**
37
+ * Line item which allow you customize the cart item
38
+ */
39
+ lineItem?: CustomLineItem;
40
+ /**
41
+ * Line item option to add to cart
42
+ */
43
+ lineItemOption?: LineItemOption;
44
+ /**
45
+ * Quantity of the item
46
+ */
30
47
  quantity?: string;
48
+ /**
49
+ * SKU code to add to cart
50
+ */
31
51
  skuCode?: string;
52
+ /**
53
+ * SKU list to add to cart
54
+ */
32
55
  skuListId?: string;
33
56
  } & TButton & BuyNowMode & THostedCart;
34
57
  export declare function AddToCartButton(props: Props): JSX.Element;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import ItemContext from"../../context/ItemContext";import getCurrentItemKey from"../../utils/getCurrentItemKey";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import getCartLink from"../../utils/getCartLink";import CommerceLayerContext from"../../context/CommerceLayerContext";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,quantity,...p}=props,{accessToken,endpoint}=useContext(CommerceLayerContext),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity:quantityCtx,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext);if(accessToken===void 0)throw new Error("Cannot use `AddToCartButton` outside of `CommerceLayer`");if(addToCart===void 0)throw new Error("Cannot use `AddToCartButton` outside of `OrderContainer`");const{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),[slug]=endpoint?endpoint.split(".commercelayer"):[""],sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:sku?.code||skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=item[sCode]?.inventory?.quantity,handleClick=async()=>{const qty=quantity!=null?parseInt(quantity):quantityCtx[sCode]??1,opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity??quantityCtx[skuListId]??1;if(has(skuLists,skuListId)){const lineItems2=skuLists?.[skuListId]?.map(skuCode2=>({skuCode:skuCode2,quantity:slQty,_update_quantity:1}));return await callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems:lineItems2}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}}if(url){if(url)return await callExternalFunction({url,data:{bundleCode,skuCode:sCode,skuId:item[sCode]?.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}else{const res=await addToCart({bundleCode,skuCode:sCode,skuId:item[sCode]?.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart){const orderId2=res.orderId;hostedCartUrl&&orderId2?location.href=`https://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getCartLink({orderId:orderId2,slug,accessToken}))}return res}},disableByCtx=!isEmpty(prices)&&!prices[sCode]||availabilityQuantity===0,autoDisabled=!isEmpty(skuLists)||skuListId?!1:(disabled||disableByCtx)??(!quantity||!sCode),parentProps={handleClick,disabled:disabled||autoDisabled,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,disabled:autoDisabled,onClick:()=>{handleClick()},children:label})}export default AddToCartButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import getCartLink from"../../utils/getCartLink";import CommerceLayerContext from"../../context/CommerceLayerContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,quantity,lineItemOption,...p}=props,{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AddToCartButton",key:"accessToken"}),{addToCart,orderId,getOrder,setOrderErrors}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"AddToCartButton",key:"addToCart"}),{url,callExternalFunction}=useContext(ExternalFunctionContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),[slug]=endpoint?endpoint.split(".commercelayer"):[""],sCode=sku?.code??skuCode,handleClick=async()=>{const qty=quantity!=null?parseInt(quantity):1;if(skuLists!=null&&skuListId&&url&&skuListId in skuLists){const lineItems=skuLists?.[skuListId]?.map(skuCode2=>({skuCode:skuCode2,quantity:qty,_update_quantity:1}));return await callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}if(!url&&addToCart!=null){const res=await addToCart({bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart&&accessToken!=null){const orderId2=res?.orderId;hostedCartUrl&&orderId2?location.href=`https://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getCartLink({orderId:orderId2,slug,accessToken}))}return res}else if(url)return await callExternalFunction({url,data:{bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},parentProps={handleClick,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,onClick:()=>{handleClick()},children:label})}export default AddToCartButton;
@@ -1,4 +1,4 @@
1
- import { FunctionComponent } from 'react';
1
+ /// <reference types="react" />
2
2
  import { BaseAmountComponent } from '../../typings/index';
3
- declare const AdjustmentAmount: FunctionComponent<BaseAmountComponent>;
3
+ export declare function AdjustmentAmount(props: BaseAmountComponent): JSX.Element;
4
4
  export default AdjustmentAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";const AdjustmentAmount=props=>_jsx(BaseOrderPrice,{base:"amount",type:"adjustment",...props});export default AdjustmentAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function AdjustmentAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"adjustment",...props})}export default AdjustmentAmount;
@@ -1,18 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { BaseAmountComponent } from '../../typings/index';
3
3
  export declare function DiscountAmount(props: BaseAmountComponent): JSX.Element;
4
- export declare namespace DiscountAmount {
5
- var propTypes: {
6
- id: import("prop-types").Requireable<string>;
7
- className: import("prop-types").Requireable<string>;
8
- style: import("prop-types").Requireable<object>;
9
- name: import("prop-types").Requireable<string>;
10
- children: import("prop-types").Requireable<(...args: any[]) => any>;
11
- format: import("prop-types").Requireable<import("../../typings/index").BaseFormatPrice>;
12
- };
13
- var defaultProps: {
14
- format: import("../../typings/index").BaseFormatPrice;
15
- };
16
- var displayName: string;
17
- }
18
4
  export default DiscountAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";import components from"../../config/components";const propTypes=components.DiscountAmount.propTypes,defaultProps=components.DiscountAmount.defaultProps,displayName=components.DiscountAmount.displayName;export function DiscountAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"discount",...props})}DiscountAmount.propTypes=propTypes,DiscountAmount.defaultProps=defaultProps,DiscountAmount.displayName=displayName;export default DiscountAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function DiscountAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"discount",...props})}export default DiscountAmount;
@@ -1,15 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { BaseAmountComponent } from '../../typings/index';
3
3
  export declare function GiftCardAmount(props: BaseAmountComponent): JSX.Element;
4
- export declare namespace GiftCardAmount {
5
- var propTypes: {
6
- id: import("prop-types").Requireable<string>;
7
- className: import("prop-types").Requireable<string>;
8
- style: import("prop-types").Requireable<object>;
9
- name: import("prop-types").Requireable<string>;
10
- children: import("prop-types").Requireable<(...args: any[]) => any>;
11
- format: import("prop-types").Requireable<import("../../typings/index").BaseFormatPrice>;
12
- };
13
- var displayName: string;
14
- }
15
4
  export default GiftCardAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";import components from"../../config/components";const propTypes=components.GiftCardAmount.propTypes,displayName=components.GiftCardAmount.displayName;export function GiftCardAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"gift_card",...props})}GiftCardAmount.propTypes=propTypes,GiftCardAmount.displayName=displayName;export default GiftCardAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function GiftCardAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"gift_card",...props})}export default GiftCardAmount;
@@ -7,7 +7,6 @@ interface Props {
7
7
  attributes?: OrderCreate;
8
8
  orderId?: string;
9
9
  fetchOrder?: (order: Order) => void;
10
- loader?: string | JSX.Element;
11
10
  }
12
11
  export declare function OrderContainer(props: Props): JSX.Element;
13
12
  export default OrderContainer;
@@ -1 +1 @@
1
- import{Fragment as _Fragment,jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder,addToCart}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import compareObjAttribute from"../../utils/compareObjAttribute";export function OrderContainer(props){const{orderId,children,metadata,attributes,fetchOrder,loader}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useContext(CommerceLayerContext);if(config.accessToken==null)throw new Error("Cannot use `OrderContainer` outside of `CommerceLayer`");const{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext);useEffect(()=>{state.withoutIncludes||dispatch({type:"setLoading",payload:{loading:!0}})},[state.withoutIncludes]),useEffect(()=>{if(attributes&&state?.order&&!lock){const updateAttributes=compareObjAttribute({attributes,object:state.order});Object.keys(updateAttributes).length>0&&(updateOrder({id:state.order.id,attributes:updateAttributes,dispatch,config,include:state.include,state}),setLock(!0))}return()=>{if(attributes&&state?.order){const updateAttributes=compareObjAttribute({attributes,object:state.order});state.order&&Object.keys(updateAttributes).length===0&&setLock(!1)}}},[attributes,state?.order,lock]),useEffect(()=>{const localOrder=persistKey?getLocalOrder(persistKey):orderId,startRequest=Object.keys(state?.includeLoaded||{}).filter(key=>state?.includeLoaded?.[key]===!0),getOrder=async()=>{localOrder&&await getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state})};return config.accessToken&&!state.loading?localOrder&&!state.order&&state.include?.length===startRequest.length&&!state.withoutIncludes&&!lockOrder?getOrder():state?.order&&fetchOrder?fetchOrder(state.order):state.withoutIncludes&&!state.include?.length&&startRequest.length===0&&getOrder():[config.accessToken,!state.order,state.loading,state.withoutIncludes].every(Boolean)?dispatch({type:"setLoading",payload:{loading:!1}}):[config.accessToken,!state.order,state.loading,!state.withoutIncludes].every(Boolean)&&dispatch({type:"setLoading",payload:{loading:!1}}),()=>{!state.order&&state.loading&&!state.withoutIncludes&&(state.include?.length===0&&startRequest.length>0?dispatch({type:"setLoading",payload:{loading:!1}}):state.include&&state.include?.length>0&&(dispatch({type:"setIncludesResource",payload:{include:[]}}),setLockOrder(!1)))}},[config.accessToken,state.includeLoaded,state.include,orderId,state.order,state.loading,state.withoutIncludes,lockOrder]);const orderValue=useMemo(()=>({...state,setOrder:order=>setOrder(order,dispatch),getOrder:async id=>await getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:async()=>await createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:async values=>await addToCart({...values,persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder}),saveAddressToCustomerAddressBook:args=>defaultOrderContext.saveAddressToCustomerAddressBook({...args,dispatch}),setGiftCardOrCouponCode:async({code,codeType})=>await defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:async({codeType})=>await defaultOrderContext.removeGiftCardOrCouponCode({codeType,dispatch,order:state.order,config,include:state.include,state}),addResourceToInclude:args=>defaultOrderContext.addResourceToInclude({...args,dispatch,resourcesIncluded:state.include,resourceIncludedLoaded:state.includeLoaded}),updateOrder:async args=>await defaultOrderContext.updateOrder({...args,dispatch,config,include:state.include,state})}),[state,config.accessToken]);return state.loading&&loader!=null?_jsx(_Fragment,{children:loader}):_jsx(OrderContext.Provider,{value:orderValue,children})}export default OrderContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder,addToCart}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import compareObjAttribute from"../../utils/compareObjAttribute";import useCustomContext from"../../utils/hooks/useCustomContext";export function OrderContainer(props){const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"OrderContainer"});if(config.accessToken==null)throw new Error("Cannot use `OrderContainer` outside of `CommerceLayer`");const{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext);useEffect(()=>{state.withoutIncludes||dispatch({type:"setLoading",payload:{loading:!0}})},[state.withoutIncludes]),useEffect(()=>{if(attributes&&state?.order&&!lock){const updateAttributes=compareObjAttribute({attributes,object:state.order});Object.keys(updateAttributes).length>0&&(updateOrder({id:state.order.id,attributes:updateAttributes,dispatch,config,include:state.include,state}),setLock(!0))}return()=>{if(attributes&&state?.order){const updateAttributes=compareObjAttribute({attributes,object:state.order});state.order&&Object.keys(updateAttributes).length===0&&setLock(!1)}}},[attributes,state?.order,lock]),useEffect(()=>{const localOrder=persistKey?getLocalOrder(persistKey):orderId,startRequest=Object.keys(state?.includeLoaded||{}).filter(key=>state?.includeLoaded?.[key]===!0),getOrder=async()=>{localOrder&&await getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state})};return config.accessToken&&!state.loading?localOrder&&!state.order&&state.include?.length===startRequest.length&&!state.withoutIncludes&&!lockOrder?getOrder():state?.order&&fetchOrder?fetchOrder(state.order):state.withoutIncludes&&!state.include?.length&&startRequest.length===0&&getOrder():[config.accessToken,!state.order,state.loading,state.withoutIncludes].every(Boolean)?dispatch({type:"setLoading",payload:{loading:!1}}):[config.accessToken,!state.order,state.loading,!state.withoutIncludes].every(Boolean)&&dispatch({type:"setLoading",payload:{loading:!1}}),()=>{!state.order&&state.loading&&!state.withoutIncludes&&(state.include?.length===0&&startRequest.length>0?dispatch({type:"setLoading",payload:{loading:!1}}):state.include&&state.include?.length>0&&(dispatch({type:"setIncludesResource",payload:{include:[]}}),setLockOrder(!1)))}},[config.accessToken,state.includeLoaded,state.include,orderId,state.order,state.loading,state.withoutIncludes,lockOrder]);const orderValue=useMemo(()=>({...state,setOrder:order=>setOrder(order,dispatch),getOrder:async id=>await getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:async()=>await createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:async params=>await addToCart({...params,persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder}),saveAddressToCustomerAddressBook:args=>defaultOrderContext.saveAddressToCustomerAddressBook({...args,dispatch}),setGiftCardOrCouponCode:async({code,codeType})=>await defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:async({codeType})=>await defaultOrderContext.removeGiftCardOrCouponCode({codeType,dispatch,order:state.order,config,include:state.include,state}),addResourceToInclude:args=>defaultOrderContext.addResourceToInclude({...args,dispatch,resourcesIncluded:state.include,resourceIncludedLoaded:state.includeLoaded}),updateOrder:async args=>await defaultOrderContext.updateOrder({...args,dispatch,config,include:state.include,state})}),[state,config.accessToken]);return _jsx(OrderContext.Provider,{value:orderValue,children})}export default OrderContainer;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { BaseAmountComponent } from '../../typings/index';
3
+ export declare function PaymentMethodAmount(props: BaseAmountComponent): JSX.Element;
4
+ export default PaymentMethodAmount;
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function PaymentMethodAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"payment_method",...props})}export default PaymentMethodAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import PlaceOrderContext from"../../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import getCardDetails from"../../utils/getCardDetails";export function PlaceOrderButton(props){const ref=useRef(null),{children,label="Place order",disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&order?.status&&["draft","pending"].includes(order?.status)){const attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult},paymentData:paymentSource.payment_response.paymentData},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode;["Authorised","Pending","Received"].includes(resultCode)&&handleClick()})}paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.adyen,paymentType]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async()=>{let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit(paymentSource),!isValid&&paymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps={...p,label,disabled:disabledButton,handleClick,ref};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:()=>{handleClick()},...p,children:isFunction(label)?label():label})}export default PlaceOrderButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import PlaceOrderContext from"../../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import getCardDetails from"../../utils/getCardDetails";export function PlaceOrderButton(props){const ref=useRef(null),{children,label="Place order",disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&order?.status&&["draft","pending"].includes(order?.status)&&paymentSource!=null){const paymentData=paymentSource?.payment_response?.paymentData,attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult},paymentData},_details:1};paymentData!=null&&setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode,errorCode=res?.payment_response?.errorCode,message=res?.payment_response?.message;["Authorised","Pending","Received"].includes(resultCode)?handleClick():errorCode!=null&&setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])})}paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.adyen,paymentType]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async()=>{let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit(paymentSource),!isValid&&paymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps={...p,label,disabled:disabledButton,handleClick,ref};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:()=>{handleClick()},...p,children:isFunction(label)?label():label})}export default PlaceOrderButton;