@commercelayer/react-components 4.2.2 → 4.2.3-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 (139) hide show
  1. package/lib/cjs/components/addresses/BillingAddressContainer.d.ts +2 -2
  2. package/lib/cjs/components/customers/CustomerContainer.d.ts +2 -2
  3. package/lib/cjs/components/customers/CustomerContainer.js +1 -1
  4. package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +10 -0
  5. package/lib/cjs/components/customers/CustomerPaymentSource.js +1 -0
  6. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +13 -0
  7. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.js +1 -0
  8. package/lib/cjs/components/line_items/LineItemOption.js +1 -1
  9. package/lib/cjs/components/line_items/LineItemQuantity.js +1 -1
  10. package/lib/cjs/components/orders/OrderList.js +1 -1
  11. package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
  12. package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +2 -2
  13. package/lib/cjs/components/payment_source/CheckoutComPayment.js +1 -1
  14. package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +1 -1
  15. package/lib/cjs/components/payment_source/KlarnaPayment.js +1 -1
  16. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.js +1 -1
  17. package/lib/cjs/components/payment_source/PaymentSourceBrandName.js +1 -1
  18. package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +4 -1
  19. package/lib/cjs/components/payment_source/PaymentSourceDetail.js +1 -1
  20. package/lib/cjs/components/payment_source/PaypalPayment.d.ts +3 -3
  21. package/lib/cjs/components/payment_source/PaypalPayment.js +1 -1
  22. package/lib/cjs/components/shipments/Shipment.js +1 -1
  23. package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -1
  24. package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
  25. package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
  26. package/lib/cjs/components/utils/BaseInput.d.ts +1 -1
  27. package/lib/cjs/components/utils/GenericFieldComponent.js +1 -1
  28. package/lib/cjs/components/utils/getAllErrors.d.ts +2 -4
  29. package/lib/cjs/components/utils/getAllErrors.js +1 -1
  30. package/lib/cjs/context/CouponAndGiftCardFormContext.d.ts +2 -2
  31. package/lib/cjs/context/CustomerAddressFormContext.d.ts +2 -2
  32. package/lib/cjs/context/CustomerContext.d.ts +5 -5
  33. package/lib/cjs/context/CustomerPaymentSourceContext.d.ts +11 -0
  34. package/lib/cjs/context/CustomerPaymentSourceContext.js +1 -0
  35. package/lib/cjs/context/PaymentSourceContext.d.ts +2 -2
  36. package/lib/cjs/reducers/AvailabilityReducer.d.ts +1 -0
  37. package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
  38. package/lib/cjs/reducers/BillingAddressReducer.d.ts +3 -3
  39. package/lib/cjs/reducers/BillingAddressReducer.js +1 -1
  40. package/lib/cjs/reducers/CustomerReducer.d.ts +7 -4
  41. package/lib/cjs/reducers/CustomerReducer.js +1 -1
  42. package/lib/cjs/reducers/GiftCardReducer.js +1 -1
  43. package/lib/cjs/reducers/LineItemReducer.d.ts +3 -3
  44. package/lib/cjs/reducers/LineItemReducer.js +1 -1
  45. package/lib/cjs/reducers/OrderReducer.d.ts +2 -1
  46. package/lib/cjs/reducers/OrderReducer.js +1 -1
  47. package/lib/cjs/reducers/PaymentMethodReducer.d.ts +1 -1
  48. package/lib/cjs/reducers/PaymentMethodReducer.js +1 -1
  49. package/lib/cjs/reducers/PlaceOrderReducer.js +1 -1
  50. package/lib/cjs/reducers/PriceReducer.js +1 -1
  51. package/lib/cjs/reducers/ShippingAddressReducer.d.ts +4 -4
  52. package/lib/cjs/reducers/ShippingAddressReducer.js +1 -1
  53. package/lib/cjs/typings/errors.d.ts +4 -1
  54. package/lib/cjs/utils/baseReducer.js +1 -1
  55. package/lib/cjs/utils/checkIncludeResource.d.ts +3 -3
  56. package/lib/cjs/utils/compareObjAttribute.d.ts +3 -3
  57. package/lib/cjs/utils/countryStateCity.d.ts +5 -6
  58. package/lib/cjs/utils/customMessages.d.ts +1 -1
  59. package/lib/cjs/utils/filterChildren.d.ts +1 -1
  60. package/lib/cjs/utils/getAmount.d.ts +1 -3
  61. package/lib/cjs/utils/getAmount.js +1 -1
  62. package/lib/cjs/utils/getCardDetails.d.ts +5 -5
  63. package/lib/cjs/utils/getCartLink.d.ts +2 -2
  64. package/lib/cjs/utils/getErrors.d.ts +11 -5
  65. package/lib/cjs/utils/getErrors.js +1 -1
  66. package/lib/cjs/utils/jwt.d.ts +2 -2
  67. package/lib/cjs/utils/promisify.js +1 -1
  68. package/lib/cjs/utils/shipments.js +1 -1
  69. package/lib/esm/components/addresses/BillingAddressContainer.d.ts +2 -2
  70. package/lib/esm/components/customers/CustomerContainer.d.ts +2 -2
  71. package/lib/esm/components/customers/CustomerContainer.js +1 -1
  72. package/lib/esm/components/customers/CustomerPaymentSource.d.ts +10 -0
  73. package/lib/esm/components/customers/CustomerPaymentSource.js +1 -0
  74. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +13 -0
  75. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.js +1 -0
  76. package/lib/esm/components/line_items/LineItemOption.js +1 -1
  77. package/lib/esm/components/line_items/LineItemQuantity.js +1 -1
  78. package/lib/esm/components/orders/OrderList.js +1 -1
  79. package/lib/esm/components/orders/PlaceOrderContainer.js +1 -1
  80. package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +2 -2
  81. package/lib/esm/components/payment_source/CheckoutComPayment.js +1 -1
  82. package/lib/esm/components/payment_source/KlarnaPayment.d.ts +1 -1
  83. package/lib/esm/components/payment_source/KlarnaPayment.js +1 -1
  84. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.js +1 -1
  85. package/lib/esm/components/payment_source/PaymentSourceBrandName.js +1 -1
  86. package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +4 -1
  87. package/lib/esm/components/payment_source/PaymentSourceDetail.js +1 -1
  88. package/lib/esm/components/payment_source/PaypalPayment.d.ts +3 -3
  89. package/lib/esm/components/payment_source/PaypalPayment.js +1 -1
  90. package/lib/esm/components/shipments/Shipment.js +1 -1
  91. package/lib/esm/components/shipments/ShipmentsContainer.js +1 -1
  92. package/lib/esm/components/skus/AvailabilityContainer.js +1 -1
  93. package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
  94. package/lib/esm/components/utils/BaseInput.d.ts +1 -1
  95. package/lib/esm/components/utils/GenericFieldComponent.js +1 -1
  96. package/lib/esm/components/utils/getAllErrors.d.ts +2 -4
  97. package/lib/esm/components/utils/getAllErrors.js +1 -1
  98. package/lib/esm/context/CouponAndGiftCardFormContext.d.ts +2 -2
  99. package/lib/esm/context/CustomerAddressFormContext.d.ts +2 -2
  100. package/lib/esm/context/CustomerContext.d.ts +5 -5
  101. package/lib/esm/context/CustomerPaymentSourceContext.d.ts +11 -0
  102. package/lib/esm/context/CustomerPaymentSourceContext.js +1 -0
  103. package/lib/esm/context/PaymentSourceContext.d.ts +2 -2
  104. package/lib/esm/reducers/AvailabilityReducer.d.ts +1 -0
  105. package/lib/esm/reducers/AvailabilityReducer.js +1 -1
  106. package/lib/esm/reducers/BillingAddressReducer.d.ts +3 -3
  107. package/lib/esm/reducers/BillingAddressReducer.js +1 -1
  108. package/lib/esm/reducers/CustomerReducer.d.ts +7 -4
  109. package/lib/esm/reducers/CustomerReducer.js +1 -1
  110. package/lib/esm/reducers/GiftCardReducer.js +1 -1
  111. package/lib/esm/reducers/LineItemReducer.d.ts +3 -3
  112. package/lib/esm/reducers/LineItemReducer.js +1 -1
  113. package/lib/esm/reducers/OrderReducer.d.ts +2 -1
  114. package/lib/esm/reducers/OrderReducer.js +1 -1
  115. package/lib/esm/reducers/PaymentMethodReducer.d.ts +1 -1
  116. package/lib/esm/reducers/PaymentMethodReducer.js +1 -1
  117. package/lib/esm/reducers/PlaceOrderReducer.js +1 -1
  118. package/lib/esm/reducers/PriceReducer.js +1 -1
  119. package/lib/esm/reducers/ShippingAddressReducer.d.ts +4 -4
  120. package/lib/esm/reducers/ShippingAddressReducer.js +1 -1
  121. package/lib/esm/typings/errors.d.ts +4 -1
  122. package/lib/esm/utils/baseReducer.js +1 -1
  123. package/lib/esm/utils/checkIncludeResource.d.ts +3 -3
  124. package/lib/esm/utils/compareObjAttribute.d.ts +3 -3
  125. package/lib/esm/utils/countryStateCity.d.ts +5 -6
  126. package/lib/esm/utils/customMessages.d.ts +1 -1
  127. package/lib/esm/utils/filterChildren.d.ts +1 -1
  128. package/lib/esm/utils/getAmount.d.ts +1 -3
  129. package/lib/esm/utils/getAmount.js +1 -1
  130. package/lib/esm/utils/getCardDetails.d.ts +5 -5
  131. package/lib/esm/utils/getCartLink.d.ts +2 -2
  132. package/lib/esm/utils/getErrors.d.ts +11 -5
  133. package/lib/esm/utils/getErrors.js +1 -1
  134. package/lib/esm/utils/jwt.d.ts +2 -2
  135. package/lib/esm/utils/promisify.js +1 -1
  136. package/lib/esm/utils/shipments.js +1 -1
  137. package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
  138. package/lib/tsconfig.prod.tsbuildinfo +1 -1
  139. package/package.json +17 -16
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- type Props = {
2
+ interface Props {
3
3
  children: ReactNode;
4
- };
4
+ }
5
5
  export declare function BillingAddressContainer(props: Props): JSX.Element;
6
6
  export default BillingAddressContainer;
@@ -1,6 +1,6 @@
1
- import { ReactNode } from 'react';
1
+ import type { DefaultChildrenType } from '../../typings/globals';
2
2
  interface Props {
3
- children: ReactNode;
3
+ children: DefaultChildrenType;
4
4
  /**
5
5
  * Customer type
6
6
  */
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),CustomerReducer_1=tslib_1.__importStar(require("../../reducers/CustomerReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext"));function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=(0,react_1.useReducer)(CustomerReducer_1.default,CustomerReducer_1.customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include,includeLoaded]),(0,react_1.useEffect)(()=>{config.accessToken&&state.addresses==null&&!isGuest&&(0,CustomerReducer_1.getCustomerAddresses)({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),config.accessToken&&!order&&!include&&!includeLoaded&&(0,CustomerReducer_1.getCustomerOrders)({config,dispatch})},[config.accessToken,order,isGuest]);const contextValue={isGuest,...state,saveCustomerUser:async customerEmail=>{await(0,CustomerReducer_1.saveCustomerUser)({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>(0,CustomerReducer_1.setCustomerErrors)(errors,dispatch),setCustomerEmail:customerEmail=>(0,CustomerReducer_1.setCustomerEmail)(customerEmail,dispatch),getCustomerPaymentSources:()=>(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),deleteCustomerAddress:async({customerAddressId})=>await(0,CustomerReducer_1.deleteCustomerAddress)({customerAddressId,dispatch,config,addresses:state.addresses}),createCustomerAddress:async address=>await(0,CustomerReducer_1.createCustomerAddress)({address,config,dispatch,state})};return(0,jsx_runtime_1.jsx)(CustomerContext_1.default.Provider,{value:contextValue,children})}exports.CustomerContainer=CustomerContainer,exports.default=CustomerContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),CustomerReducer_1=tslib_1.__importStar(require("../../reducers/CustomerReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext"));function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=(0,react_1.useReducer)(CustomerReducer_1.default,CustomerReducer_1.customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include?.length,Object.keys(includeLoaded??{}).length]),(0,react_1.useEffect)(()=>{config.accessToken&&state.addresses==null&&!isGuest&&(0,CustomerReducer_1.getCustomerAddresses)({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),config.accessToken&&order==null&&include==null&&includeLoaded==null&&!isGuest&&((0,CustomerReducer_1.getCustomerOrders)({config,dispatch}),(0,CustomerReducer_1.getCustomerPayments)({config,dispatch}))},[config.accessToken,order,isGuest]);const contextValue=(0,react_1.useMemo)(()=>({isGuest,...state,saveCustomerUser:async customerEmail=>{await(0,CustomerReducer_1.saveCustomerUser)({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>(0,CustomerReducer_1.setCustomerErrors)(errors,dispatch),setCustomerEmail:customerEmail=>(0,CustomerReducer_1.setCustomerEmail)(customerEmail,dispatch),getCustomerPaymentSources:()=>(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),deleteCustomerAddress:async({customerAddressId})=>await(0,CustomerReducer_1.deleteCustomerAddress)({customerAddressId,dispatch,config,addresses:state.addresses}),createCustomerAddress:async address=>await(0,CustomerReducer_1.createCustomerAddress)({address,config,dispatch,state})}),[state,isGuest]);return(0,jsx_runtime_1.jsx)(CustomerContext_1.default.Provider,{value:contextValue,children})}exports.CustomerContainer=CustomerContainer,exports.default=CustomerContainer;
@@ -0,0 +1,10 @@
1
+ import { DefaultChildrenType } from '../../typings/globals';
2
+ interface Props {
3
+ children?: DefaultChildrenType;
4
+ /**
5
+ * Customize the loader content.
6
+ */
7
+ loader?: string | JSX.Element;
8
+ }
9
+ export declare function CustomerPaymentSource({ children, loader }: Props): JSX.Element;
10
+ export default CustomerPaymentSource;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerPaymentSource=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext")),react_1=require("react");function CustomerPaymentSource({children,loader="Loading..."}){const[loading,setLoading]=(0,react_1.useState)(!0),{payments}=(0,useCustomContext_1.default)({context:CustomerContext_1.default,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSource",key:"payments"});(0,react_1.useEffect)(()=>(payments!=null&&setLoading(!1),()=>{setLoading(!0)}),[payments!=null]);const provider=payments?.filter(p=>p?.payment_source!=null).map(p=>{const paymentType=p.payment_source?.type,customerPayment=p,value={...(0,getCardDetails_1.default)({paymentType,customerPayment})};return(0,jsx_runtime_1.jsx)(CustomerPaymentSourceContext_1.default.Provider,{value,children},p.id)});return loading?(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loader}):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:provider})}exports.CustomerPaymentSource=CustomerPaymentSource,exports.default=CustomerPaymentSource;
@@ -0,0 +1,13 @@
1
+ import { ChildrenFunction } from '../../typings/index';
2
+ interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
3
+ /**
4
+ * Function allow you to customize the component
5
+ */
6
+ children?: ChildrenFunction<Omit<Props, 'children'>>;
7
+ /**
8
+ * Label to show. Default: 'No payments available.'
9
+ */
10
+ emptyText?: string;
11
+ }
12
+ export declare function CustomerPaymentSourceEmpty({ children, emptyText, ...p }: Props): JSX.Element | null;
13
+ export default CustomerPaymentSourceEmpty;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerPaymentSourceEmpty=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function CustomerPaymentSourceEmpty({children,emptyText="No payments available",...p}){const{payments}=(0,useCustomContext_1.default)({context:CustomerContext_1.default,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSourceEmpty",key:"payments"}),parentProps={emptyText,...p};return payments!=null&&payments.length>0||payments===null?null:children!==void 0?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:emptyText})}exports.CustomerPaymentSourceEmpty=CustomerPaymentSourceEmpty,exports.default=CustomerPaymentSourceEmpty;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LineItemOption=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),LineItemOptionChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemOptionChildrenContext")),get_1=tslib_1.__importDefault(require("lodash/get")),has_1=tslib_1.__importDefault(require("lodash/has")),map_1=tslib_1.__importDefault(require("lodash/map")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),isJSON_1=tslib_1.__importDefault(require("../../utils/isJSON"));function LineItemOption(props){const{name,children,valueClassName,key,tagElement="li",tagContainer="ul",...p}=props,{lineItemOption,showAll}=(0,react_1.useContext)(LineItemOptionChildrenContext_1.default),parentProps={...props,lineItemOption},TagElement=tagElement,TagContainer=tagContainer,components=showAll&&(0,isJSON_1.default)(JSON.stringify(lineItemOption?.options))?(0,map_1.default)(lineItemOption?.options,(value,key2)=>(0,jsx_runtime_1.jsxs)(TagElement,{...p,children:[`${key2}:`,(0,jsx_runtime_1.jsx)("span",{className:valueClassName,children:`${value}`})]},key2)):(0,has_1.default)(lineItemOption,`options.${name}`)?(0,jsx_runtime_1.jsxs)(TagElement,{...p,children:[`${name}:`,(0,jsx_runtime_1.jsx)("span",{className:valueClassName,...p,children:`${(0,get_1.default)(lineItemOption,`options.${name}`)}`})]},key):null;return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)(TagContainer,{children:components})}exports.LineItemOption=LineItemOption,exports.default=LineItemOption;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LineItemOption=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),LineItemOptionChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemOptionChildrenContext")),get_1=tslib_1.__importDefault(require("lodash/get")),has_1=tslib_1.__importDefault(require("lodash/has")),map_1=tslib_1.__importDefault(require("lodash/map")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),isJSON_1=tslib_1.__importDefault(require("../../utils/isJSON"));function LineItemOption(props){const{name,children,valueClassName,key,tagElement="li",tagContainer="ul",...p}=props,{lineItemOption,showAll}=(0,react_1.useContext)(LineItemOptionChildrenContext_1.default),parentProps={...props,lineItemOption},TagElement=tagElement,TagContainer=tagContainer,components=showAll&&(0,isJSON_1.default)(JSON.stringify(lineItemOption?.options))?(0,map_1.default)(lineItemOption?.options,(value,key2)=>(0,jsx_runtime_1.jsxs)(TagElement,{...p,children:[`${key2}:`,(0,jsx_runtime_1.jsx)("span",{className:valueClassName,children:`${value}`})]},key2)):name!=null&&(0,has_1.default)(lineItemOption,`options.${name}`)?(0,jsx_runtime_1.jsxs)(TagElement,{...p,children:[`${name}:`,(0,jsx_runtime_1.jsx)("span",{className:valueClassName,...p,children:`${(0,get_1.default)(lineItemOption,`options.${name}`)??""}`})]},key):null;return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)(TagContainer,{children:components})}exports.LineItemOption=LineItemOption,exports.default=LineItemOption;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LineItemQuantity=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),LineItemContext_1=tslib_1.__importDefault(require("../../context/LineItemContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function LineItemQuantity(props){const{max=50,readonly=!1,...p}=props,{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{updateLineItem}=(0,react_1.useContext)(LineItemContext_1.default),options=[];for(let i=1;i<=max;i++)options.push((0,jsx_runtime_1.jsx)("option",{value:`${i}`,children:i},i));const handleChange=e=>{const quantity2=Number(e.target.value);updateLineItem&&lineItem&&updateLineItem(lineItem.id,quantity2)},quantity=lineItem?.quantity,parentProps={handleChange,quantity,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):readonly?(0,jsx_runtime_1.jsx)("span",{...p,children:quantity}):(0,jsx_runtime_1.jsx)("select",{title:lineItem?.name,value:quantity,onChange:handleChange,...p,children:options})}exports.LineItemQuantity=LineItemQuantity,exports.default=LineItemQuantity;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LineItemQuantity=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),LineItemContext_1=tslib_1.__importDefault(require("../../context/LineItemContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function LineItemQuantity(props){const{max=50,readonly=!1,...p}=props,{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{updateLineItem}=(0,react_1.useContext)(LineItemContext_1.default),options=[];for(let i=1;i<=max;i++)options.push((0,jsx_runtime_1.jsx)("option",{value:`${i}`,children:i},i));const handleChange=e=>{const quantity2=Number(e.target.value);updateLineItem&&lineItem&&updateLineItem(lineItem.id,quantity2)},quantity=lineItem?.quantity,parentProps={handleChange,quantity,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):readonly?(0,jsx_runtime_1.jsx)("span",{...p,children:quantity}):(0,jsx_runtime_1.jsx)("select",{"data-testid":lineItem?.sku_code,title:lineItem?.name,value:quantity,onChange:handleChange,...p,children:options})}exports.LineItemQuantity=LineItemQuantity,exports.default=LineItemQuantity;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OrderList=void 0;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),react_2=require("react"),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),OrderListChildrenContext_1=tslib_1.__importDefault(require("../../context/OrderListChildrenContext")),OrderListPaginationContext_1=tslib_1.__importDefault(require("../../context/OrderListPaginationContext")),react_table_1=require("react-table"),react_window_1=require("react-window"),scrollbarWidth_1=tslib_1.__importDefault(require("../../utils/scrollbarWidth")),icons_1=require("../../utils/icons"),filterChildren_1=tslib_1.__importDefault(require("../../utils/filterChildren")),rowComponents=["OrderListRow","OrderListEmpty"],paginationComponents=["OrderListPaginationInfo","OrderListPaginationButtons"];function OrderList({children,columns,loadingElement,showActions=!1,showPagination=!1,sortBy=[{id:"number",desc:!0}],pageSize=10,paginationContainerClassName,actionsComponent,actionsContainerClassName,infiniteScroll,windowOptions,theadClassName,rowTrClassName,...p}){const[loading,setLoading]=(0,react_2.useState)(!0),{orders}=(0,react_2.useContext)(CustomerContext_1.default),data=(0,react_2.useMemo)(()=>orders??[],[orders]),cols=(0,react_2.useMemo)(()=>columns,[columns]),tablePlugins=[react_table_1.useSortBy];infiniteScroll&&tablePlugins.push(react_table_1.useBlockLayout),showPagination&&tablePlugins.push(react_table_1.usePagination);const defaultColumn=(0,react_2.useMemo)(()=>({width:windowOptions?.column||150}),[windowOptions?.column]),initialState=(0,react_2.useMemo)(()=>({...showPagination&&{pageSize},sortBy}),[showPagination,pageSize]),table=(0,react_table_1.useTable)({data,columns:cols,...infiniteScroll&&{defaultColumn},initialState},...tablePlugins),TableHtmlElement=infiniteScroll?"div":"table",TheadHtmlElement=infiniteScroll?"div":"thead",TbodyHtmlElement=infiniteScroll?"div":"tbody",ThHtmlElement=infiniteScroll?"div":"th",TrHtmlElement=infiniteScroll?"div":"tr";(0,react_2.useEffect)(()=>(orders!==void 0&&setLoading(!1),()=>{setLoading(!0)}),[orders]);const scrollBarSize=infiniteScroll?(0,react_2.useMemo)(()=>(0,scrollbarWidth_1.default)(),[]):0,LoadingComponent=loadingElement||(0,jsx_runtime_1.jsx)("div",{children:"Loading..."}),headerComponent=table.headerGroups.map((headerGroup,i)=>{const columns2=headerGroup.headers.map((column,k)=>{const sortLabel=column.isSorted?column.isSortedDesc?"desc":"asc":"";return(0,react_1.createElement)(ThHtmlElement,{"data-testid":`thead-${k}`,"data-sort":`${sortLabel}`,className:column?.className,...column.getHeaderProps(column?.getSortByToggleProps&&column?.getSortByToggleProps()),key:k},(0,jsx_runtime_1.jsxs)("span",{className:column?.titleClassName,children:[column.render("Header"),column.isSorted?column.isSortedDesc?icons_1.sortDescIcon:icons_1.sortAscIcon:""]}))});return(0,react_1.createElement)(TrHtmlElement,{...headerGroup.getHeaderGroupProps(),key:i},columns2)}),rows=showPagination?table.page:table.rows,rowsComponents=(0,filterChildren_1.default)({children,filterBy:rowComponents,componentName:"OrderList"}),components=infiniteScroll?(0,react_2.useCallback)(({index,style})=>{const row=rows[index];row&&table.prepareRow(row);const childProps={orders,order:row.original,row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll};return(0,jsx_runtime_1.jsx)(TrHtmlElement,{...row?.getRowProps({style}),className:rowTrClassName,children:(0,jsx_runtime_1.jsx)(OrderListChildrenContext_1.default.Provider,{value:childProps,children:rowsComponents})})},[table.prepareRow,table.rows]):rows.map((row,i)=>{table.prepareRow(row);const childProps={orders,order:row.original,row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll};return(0,react_1.createElement)(TrHtmlElement,{...row.getRowProps(),className:rowTrClassName,key:i},(0,jsx_runtime_1.jsx)(OrderListChildrenContext_1.default.Provider,{value:childProps,children:rowsComponents}))}),pagComponents=(0,filterChildren_1.default)({children,filterBy:paginationComponents,componentName:"OrderList"}),Pagination=()=>showPagination?(0,jsx_runtime_1.jsx)(OrderListPaginationContext_1.default.Provider,{value:{canNextPage:table.canNextPage,canPreviousPage:table.canPreviousPage,gotoPage:table.gotoPage,nextPage:table.nextPage,page:table.page,pageCount:table.pageCount,pageIndex:table.state.pageIndex,pageNumber:table.pageNumber,pageOptions:table.pageOptions,pageSize:table.state.pageSize,previousPage:table.previousPage,setPageSize:table.setPageSize,totalRows:orders?.length??0},children:pagComponents}):null;return loading&&orders==null?(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:LoadingComponent}):orders?.length===0?(0,jsx_runtime_1.jsxs)(OrderListChildrenContext_1.default.Provider,{value:{orders},children:[rowsComponents,(0,jsx_runtime_1.jsx)(Pagination,{})]}):(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsxs)(TableHtmlElement,{...p,...table.getTableProps(),children:[(0,jsx_runtime_1.jsx)(TheadHtmlElement,{className:theadClassName,children:headerComponent}),(0,jsx_runtime_1.jsx)(TbodyHtmlElement,{...table.getTableBodyProps(),children:infiniteScroll?(0,jsx_runtime_1.jsx)(react_window_1.FixedSizeList,{height:windowOptions?.height||400,itemCount:table.rows.length,itemSize:windowOptions?.itemSize||100,width:windowOptions?.width||table.totalColumnsWidth+scrollBarSize,children:components}):components})]}),table.rows.length<pageSize?null:(0,jsx_runtime_1.jsx)("div",{className:paginationContainerClassName,children:(0,jsx_runtime_1.jsx)(Pagination,{})})]})}exports.OrderList=OrderList,exports.default=OrderList;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OrderList=void 0;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),react_2=require("react"),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),OrderListChildrenContext_1=tslib_1.__importDefault(require("../../context/OrderListChildrenContext")),OrderListPaginationContext_1=tslib_1.__importDefault(require("../../context/OrderListPaginationContext")),react_table_1=require("react-table"),react_window_1=require("react-window"),scrollbarWidth_1=tslib_1.__importDefault(require("../../utils/scrollbarWidth")),icons_1=require("../../utils/icons"),filterChildren_1=tslib_1.__importDefault(require("../../utils/filterChildren")),rowComponents=["OrderListRow","OrderListEmpty"],paginationComponents=["OrderListPaginationInfo","OrderListPaginationButtons"];function OrderList({children,columns,loadingElement,showActions=!1,showPagination=!1,sortBy=[{id:"number",desc:!0}],pageSize=10,paginationContainerClassName,actionsComponent,actionsContainerClassName,infiniteScroll,windowOptions,theadClassName,rowTrClassName,...p}){const[loading,setLoading]=(0,react_2.useState)(!0),{orders}=(0,react_2.useContext)(CustomerContext_1.default),data=(0,react_2.useMemo)(()=>orders??[],[orders]),cols=(0,react_2.useMemo)(()=>columns,[columns]),tablePlugins=[react_table_1.useSortBy];infiniteScroll&&tablePlugins.push(react_table_1.useBlockLayout),showPagination&&tablePlugins.push(react_table_1.usePagination);const defaultColumn=(0,react_2.useMemo)(()=>({width:windowOptions?.column||150}),[windowOptions?.column]),initialState=(0,react_2.useMemo)(()=>({...showPagination&&{pageSize},sortBy}),[showPagination,pageSize]),table=(0,react_table_1.useTable)({data,columns:cols,...infiniteScroll&&{defaultColumn},initialState},...tablePlugins),TableHtmlElement=infiniteScroll?"div":"table",TheadHtmlElement=infiniteScroll?"div":"thead",TbodyHtmlElement=infiniteScroll?"div":"tbody",ThHtmlElement=infiniteScroll?"div":"th",TrHtmlElement=infiniteScroll?"div":"tr";(0,react_2.useEffect)(()=>(orders!==void 0&&setLoading(!1),()=>{setLoading(!0)}),[orders]);const scrollBarSize=infiniteScroll?(0,react_2.useMemo)(()=>(0,scrollbarWidth_1.default)(),[]):0,LoadingComponent=loadingElement||(0,jsx_runtime_1.jsx)("div",{children:"Loading..."}),headerComponent=table.headerGroups.map((headerGroup,i)=>{const columns2=headerGroup.headers.map((column,k)=>{const sortLabel=column.isSorted?column.isSortedDesc?"desc":"asc":"";return(0,react_1.createElement)(ThHtmlElement,{"data-testid":`thead-${k}`,"data-sort":`${sortLabel}`,className:column?.className,...column.getHeaderProps(column?.getSortByToggleProps&&column?.getSortByToggleProps()),key:k},(0,jsx_runtime_1.jsxs)("span",{className:column?.titleClassName,children:[column.render("Header"),column.isSorted?column.isSortedDesc?icons_1.sortDescIcon:icons_1.sortAscIcon:""]}))});return(0,react_1.createElement)(TrHtmlElement,{...headerGroup.getHeaderGroupProps(),key:i},columns2)}),rows=showPagination?table.page:table.rows,rowsComponents=(0,filterChildren_1.default)({children,filterBy:rowComponents,componentName:"OrderList"}),components=infiniteScroll?(0,react_2.useCallback)(({index,style})=>{const row=rows[index];row&&table.prepareRow(row);const childProps={orders,order:row?.original,row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll};return(0,jsx_runtime_1.jsx)(TrHtmlElement,{...row?.getRowProps({style}),className:rowTrClassName,children:(0,jsx_runtime_1.jsx)(OrderListChildrenContext_1.default.Provider,{value:childProps,children:rowsComponents})})},[table.prepareRow,table.rows]):rows.map((row,i)=>{table.prepareRow(row);const childProps={orders,order:row.original,row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll};return(0,react_1.createElement)(TrHtmlElement,{...row.getRowProps(),className:rowTrClassName,key:i},(0,jsx_runtime_1.jsx)(OrderListChildrenContext_1.default.Provider,{value:childProps,children:rowsComponents}))}),pagComponents=(0,filterChildren_1.default)({children,filterBy:paginationComponents,componentName:"OrderList"}),Pagination=()=>showPagination?(0,jsx_runtime_1.jsx)(OrderListPaginationContext_1.default.Provider,{value:{canNextPage:table.canNextPage,canPreviousPage:table.canPreviousPage,gotoPage:table.gotoPage,nextPage:table.nextPage,page:table.page,pageCount:table.pageCount,pageIndex:table.state.pageIndex,pageNumber:table.pageNumber,pageOptions:table.pageOptions,pageSize:table.state.pageSize,previousPage:table.previousPage,setPageSize:table.setPageSize,totalRows:orders?.length??0},children:pagComponents}):null;return loading&&orders==null?(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:LoadingComponent}):orders?.length===0?(0,jsx_runtime_1.jsxs)(OrderListChildrenContext_1.default.Provider,{value:{orders},children:[rowsComponents,(0,jsx_runtime_1.jsx)(Pagination,{})]}):(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsxs)(TableHtmlElement,{...p,...table.getTableProps(),children:[(0,jsx_runtime_1.jsx)(TheadHtmlElement,{className:theadClassName,children:headerComponent}),(0,jsx_runtime_1.jsx)(TbodyHtmlElement,{...table.getTableBodyProps(),children:infiniteScroll?(0,jsx_runtime_1.jsx)(react_window_1.FixedSizeList,{height:windowOptions?.height||400,itemCount:table.rows.length,itemSize:windowOptions?.itemSize||100,width:windowOptions?.width||table.totalColumnsWidth+scrollBarSize,children:components}):components})]}),table.rows.length<pageSize?null:(0,jsx_runtime_1.jsx)("div",{className:paginationContainerClassName,children:(0,jsx_runtime_1.jsx)(Pagination,{})})]})}exports.OrderList=OrderList,exports.default=OrderList;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlaceOrderContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),react_1=require("react"),PlaceOrderReducer_1=tslib_1.__importStar(require("../../reducers/PlaceOrderReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),PlaceOrderReducer_2=require("../../reducers/PlaceOrderReducer"),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=(0,react_1.useReducer)(PlaceOrderReducer_1.default,PlaceOrderReducer_1.placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=(0,useCustomContext_1.default)({context:OrderContext_1.default,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.shipment_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.shipment_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&(0,PlaceOrderReducer_1.placeOrderPermitted)({config,dispatch,order,options:{...options}})},[order,include,includeLoaded]);const contextValue={...state,setPlaceOrder:async({paymentSource})=>await(0,PlaceOrderReducer_2.setPlaceOrder)({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>(0,PlaceOrderReducer_1.placeOrderPermitted)({config,dispatch,order,options:{...options}}),setButtonRef:ref=>(0,PlaceOrderReducer_1.setButtonRef)(ref,dispatch)};return(0,jsx_runtime_1.jsx)(PlaceOrderContext_1.default.Provider,{value:contextValue,children})}exports.PlaceOrderContainer=PlaceOrderContainer,exports.default=PlaceOrderContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlaceOrderContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),react_1=require("react"),PlaceOrderReducer_1=tslib_1.__importStar(require("../../reducers/PlaceOrderReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),PlaceOrderReducer_2=require("../../reducers/PlaceOrderReducer"),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=(0,react_1.useReducer)(PlaceOrderReducer_1.default,PlaceOrderReducer_1.placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=(0,useCustomContext_1.default)({context:OrderContext_1.default,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&(0,PlaceOrderReducer_1.placeOrderPermitted)({config,dispatch,order,options:{...options}})},[order,include,includeLoaded]);const contextValue={...state,setPlaceOrder:async({paymentSource})=>await(0,PlaceOrderReducer_2.setPlaceOrder)({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>(0,PlaceOrderReducer_1.placeOrderPermitted)({config,dispatch,order,options:{...options}}),setButtonRef:ref=>(0,PlaceOrderReducer_1.setButtonRef)(ref,dispatch)};return(0,jsx_runtime_1.jsx)(PlaceOrderContext_1.default.Provider,{value:contextValue,children})}exports.PlaceOrderContainer=PlaceOrderContainer,exports.default=PlaceOrderContainer;
@@ -1,7 +1,7 @@
1
1
  import { PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
2
2
  import { PaymentSourceProps } from './PaymentSource';
3
3
  import { FramesStyle } from 'frames-react';
4
- export type CheckoutComConfig = {
4
+ export interface CheckoutComConfig {
5
5
  containerClassName?: string;
6
6
  hintLabel?: string;
7
7
  name?: string;
@@ -11,7 +11,7 @@ export type CheckoutComConfig = {
11
11
  style: FramesStyle;
12
12
  };
13
13
  [key: string]: unknown;
14
- };
14
+ }
15
15
  type Props = PaymentMethodConfig['checkoutComPayment'] & JSX.IntrinsicElements['div'] & {
16
16
  show?: boolean;
17
17
  publicKey: string;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutComPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),frames_react_1=require("frames-react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),scriptUrl="https://cdn.checkout.com/js/framesv2.min.js",systemLanguages=["DE-DE","EN-GB","ES-ES","FR-FR","IT-IT","KR-KR","NL-NL"],defaultOptions={style:{base:{color:"black",fontSize:"18px"},autofill:{backgroundColor:"yellow"},hover:{color:"blue"},focus:{color:"blue"},valid:{color:"green"},invalid:{color:"red"},placeholder:{base:{color:"gray"},focus:{border:"solid 1px blue"}}}};function CheckoutComPayment({publicKey,options=defaultOptions,locale="EN-GB",...p}){const ref=(0,react_1.useRef)(null),loaded=(0,useExternalScript_1.default)(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{containerClassName,templateCustomerSaveToWallet,success_url=window.location.href,failure_url=window.location.href,show,...divProps}=p,handleSubmit=async()=>{const savePaymentSourceToCustomerWallet=ref?.current?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:order?.billing_address?.full_name,billingAddress:{addressLine1:order?.billing_address?.line_1,addressLine2:order?.billing_address?.line_2,zip:order?.billing_address?.zip_code,city:order?.billing_address?.city,state:order?.billing_address?.state_code,country:order?.billing_address?.country_code},phone:order?.billing_address?.phone};try{const data=await window.Frames.submitCard();if(data.token&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{token:data.token,payment_type:"token",success_url,failure_url,_authorize:!0}});ps&&ps.redirect_uri&&(window.location.href=ps.redirect_uri)}}catch(error){console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error?.message}])}}return!1},lang=`${locale.toUpperCase()}-${locale.toUpperCase()}`,localization=systemLanguages.includes(lang)?lang:"EN-GB";return loaded&&show?(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsxs)(frames_react_1.Frames,{config:{debug:!0,publicKey,localization,...options},cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=()=>handleSubmit(),setPaymentRef({ref}))},cardTokenized:data=>data,children:[(0,jsx_runtime_1.jsx)(frames_react_1.CardNumber,{}),(0,jsx_runtime_1.jsx)(frames_react_1.ExpiryDate,{}),(0,jsx_runtime_1.jsx)(frames_react_1.Cvv,{})]})}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]}):null}exports.CheckoutComPayment=CheckoutComPayment,exports.default=CheckoutComPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutComPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),frames_react_1=require("frames-react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),scriptUrl="https://cdn.checkout.com/js/framesv2.min.js",systemLanguages=["DE-DE","EN-GB","ES-ES","FR-FR","IT-IT","KR-KR","NL-NL"],defaultOptions={style:{base:{color:"black",fontSize:"18px"},autofill:{backgroundColor:"yellow"},hover:{color:"blue"},focus:{color:"blue"},valid:{color:"green"},invalid:{color:"red"},placeholder:{base:{color:"gray"},focus:{border:"solid 1px blue"}}}};function CheckoutComPayment({publicKey,options=defaultOptions,locale="EN-GB",...p}){const ref=(0,react_1.useRef)(null),loaded=(0,useExternalScript_1.default)(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{containerClassName,templateCustomerSaveToWallet,successUrl=window.location.href,failureUrl=window.location.href,show,...divProps}=p,handleSubmit=async()=>{const savePaymentSourceToCustomerWallet=ref?.current?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:order?.billing_address?.full_name,billingAddress:{addressLine1:order?.billing_address?.line_1,addressLine2:order?.billing_address?.line_2,zip:order?.billing_address?.zip_code,city:order?.billing_address?.city,state:order?.billing_address?.state_code,country:order?.billing_address?.country_code},phone:order?.billing_address?.phone};try{const data=await window.Frames.submitCard();if(data.token&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{token:data.token,payment_type:"token",success_url:successUrl,failure_url:failureUrl,_authorize:!0}});ps?.redirect_uri&&(window.location.href=ps.redirect_uri)}}catch(error){console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error?.message}])}}return!1},lang=`${locale.toUpperCase()}-${locale.toUpperCase()}`,localization=systemLanguages.includes(lang)?lang:"EN-GB";return loaded&&show?(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsxs)(frames_react_1.Frames,{config:{debug:!0,publicKey,localization,...options},cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=async()=>await handleSubmit(),setPaymentRef({ref}))},cardTokenized:data=>data,children:[(0,jsx_runtime_1.jsx)(frames_react_1.CardNumber,{}),(0,jsx_runtime_1.jsx)(frames_react_1.ExpiryDate,{}),(0,jsx_runtime_1.jsx)(frames_react_1.Cvv,{})]})}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]}):null}exports.CheckoutComPayment=CheckoutComPayment,exports.default=CheckoutComPayment;
@@ -5,5 +5,5 @@ type KlarnaPaymentProps = PaymentMethodConfig['klarnaPayment'] & JSX.IntrinsicEl
5
5
  clientToken: string;
6
6
  locale?: string;
7
7
  };
8
- export default function KlarnaPayment({ clientToken, placeOrderCallback, locale, ...p }: KlarnaPaymentProps): JSX.Element;
8
+ export default function KlarnaPayment({ clientToken, placeOrderCallback, locale, ...p }: KlarnaPaymentProps): JSX.Element | null;
9
9
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext"));function typeOfLine(lineItemType){switch(lineItemType){case"payment_methods":default:return null;case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical"}}function klarnaOrderLines(lineItems){return lineItems?lineItems.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{name:item.name,quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}function KlarnaPayment({clientToken,placeOrderCallback,locale="EN",...p}){const ref=(0,react_1.useRef)(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPlaceOrder}=(0,react_1.useContext)(PlaceOrderContext_1.default),loaded=(0,useExternalScript_1.default)("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=(0,react_1.useState)(),{containerClassName,...divProps}=p;(0,react_1.useEffect)(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=()=>handleClick(klarna),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=async kl=>{const[first]=paymentSource?.payment_methods||void 0,payment_method_category=first?.identifier,billing_address={given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:null,organization_name:null,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shipping_address={given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,email:order?.customer_email,street_address:order?.shipping_address?.line_1,street_address2:null,postal_code:order?.shipping_address?.zip_code,organization_name:null,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address,billing_address,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category},{billing_address,shipping_address},async function({show_form}){if(show_form)try{await kl.Payments.authorize({payment_method_category},klarnaData,async function(res){if(res.approved&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}}),{placed}=setPlaceOrder&&ps&&await setPlaceOrder({paymentSource:ps})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})}catch(e){console.error("Load Klarna libray",e)}};if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier},{billing_address:{given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:order?.billing_address?.line_2,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shipping_address:{given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,street_address:order?.shipping_address?.line_1,street_address2:order?.shipping_address?.line_2,postal_code:order?.shipping_address?.zip_code,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code}})}return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsx)("div",{id:"klarna-payments-container"})})})}exports.default=KlarnaPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext"));function typeOfLine(lineItemType){switch(lineItemType){case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical";case"payment_methods":default:return null}}function klarnaOrderLines(lineItems){return lineItems?lineItems.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{name:item.name,quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}function KlarnaPayment({clientToken,placeOrderCallback,locale="EN",...p}){const ref=(0,react_1.useRef)(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPlaceOrder}=(0,react_1.useContext)(PlaceOrderContext_1.default),loaded=(0,useExternalScript_1.default)("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=(0,react_1.useState)(),{containerClassName,...divProps}=p;(0,react_1.useEffect)(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=async()=>await handleClick(klarna),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=async kl=>{const[first]=paymentSource?.payment_methods||void 0,paymentMethodCategory=first?.identifier,billingAddress={given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:null,organization_name:null,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shippingAddress={given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,email:order?.customer_email,street_address:order?.shipping_address?.line_1,street_address2:null,postal_code:order?.shipping_address?.zip_code,organization_name:null,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address:shippingAddress,billing_address:billingAddress,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category:paymentMethodCategory},{billing_address:billingAddress,shipping_address:shippingAddress},async function({show_form}){if(show_form)try{await kl.Payments.authorize({payment_method_category:paymentMethodCategory},klarnaData,async function(res){if(res.approved&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}}),{placed}=setPlaceOrder&&ps&&await setPlaceOrder({paymentSource:ps})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})}catch(e){console.error("Load Klarna libray",e)}};if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier},{billing_address:{given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:order?.billing_address?.line_2,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shipping_address:{given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,street_address:order?.shipping_address?.line_1,street_address2:order?.shipping_address?.line_2,postal_code:order?.shipping_address?.zip_code,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code}})}return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsx)("div",{id:"klarna-payments-container"})})})}exports.default=KlarnaPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${brand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand,defaultSrc,url,width,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("img",{ref,src:url,onError:handleError,width,...p})}exports.PaymentSourceBrandIcon=PaymentSourceBrandIcon,exports.default=PaymentSourceBrandIcon;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${cardBrand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand:cardBrand,defaultSrc,url,width,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("img",{ref,src:url,onError:handleError,width,...p})}exports.PaymentSourceBrandIcon=PaymentSourceBrandIcon,exports.default=PaymentSourceBrandIcon;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),lodash_1=require("lodash"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function PaymentSourceBrandName({children,label,...props}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),brandName=brand&&(0,lodash_1.capitalize)(brand.replaceAll(/_|-/gm," ")),parentProps={brand:brandName,label,...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...props,children:label||(0,lodash_1.capitalize)(brandName)})}exports.PaymentSourceBrandName=PaymentSourceBrandName,exports.default=PaymentSourceBrandName;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),capitalize_1=tslib_1.__importDefault(require("lodash/capitalize")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandName({children,label,...props}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,brandName=cardBrand&&(0,capitalize_1.default)(cardBrand.replaceAll(/_|-/gm," ")),parentProps={brand:brandName,label,...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...props,children:label||(0,capitalize_1.default)(brandName)})}exports.PaymentSourceBrandName=PaymentSourceBrandName,exports.default=PaymentSourceBrandName;
@@ -1,10 +1,13 @@
1
- import { ChildrenFunction } from '../../typings/index';
1
+ import type { ChildrenFunction } from '../../typings/index';
2
2
  export type PaymentSourceDetailType = 'last4' | 'exp_year' | 'exp_month';
3
3
  interface ChildrenProps extends Omit<Props, 'children'> {
4
4
  text: string;
5
5
  }
6
6
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
7
7
  children?: ChildrenFunction<ChildrenProps>;
8
+ /**
9
+ * Type of detail to display
10
+ */
8
11
  type: PaymentSourceDetailType;
9
12
  }
10
13
  export declare function PaymentSourceDetail({ type, children, ...p }: Props): JSX.Element;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceDetail=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),lodash_1=require("lodash"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function PaymentSourceDetail({type,children,...p}){const card=(0,react_1.useContext)(PaymentSourceContext_1.default),text=(0,lodash_1.has)(card,type)?card[type]:type==="last4"?"****":"**",parentProps={type,text,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:text})}exports.PaymentSourceDetail=PaymentSourceDetail,exports.default=PaymentSourceDetail;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceDetail=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceDetail({type,children,...p}){const card=(0,react_1.useContext)(PaymentSourceContext_1.default),customerCard=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardObj=Object.keys(card).length>0?card:customerCard,text=type in cardObj?cardObj[type]:type==="last4"?"****":"**",parentProps={type,text,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:text})}exports.PaymentSourceDetail=PaymentSourceDetail,exports.default=PaymentSourceDetail;
@@ -1,12 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
- export type PaypalConfig = {
2
+ export interface PaypalConfig {
3
3
  return_url: string;
4
4
  cancel_url: string;
5
5
  infoMessage?: {
6
6
  text?: string | ReactNode;
7
7
  className?: string;
8
8
  };
9
- };
9
+ }
10
10
  type Props = Omit<PaypalConfig, 'return_url' | 'cancel_url'> & JSX.IntrinsicElements['div'];
11
- export declare function PaypalPayment({ infoMessage, ...p }: Props): JSX.Element;
11
+ export declare function PaypalPayment({ infoMessage, ...p }: Props): JSX.Element | null;
12
12
  export default PaypalPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaypalPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),react_1=require("react"),defaultMessage="by placing the order, you will be redirected to the PayPal website to sign in and authorize the payment";function PaypalPayment({infoMessage,...p}){const ref=(0,react_1.useRef)(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default);(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&paymentSource?.approval_url&&(ref.current.onsubmit=()=>handleClick(),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=async()=>{if(paymentSource&&currentPaymentMethodType)try{return await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"paypal",last4:""}}}}),!0}catch{return!1}return!1};return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{...p,children:(0,jsx_runtime_1.jsx)("span",{className:infoMessage?.className,children:(0,isFunction_1.default)(infoMessage?.text)?infoMessage?.text():infoMessage?.text||defaultMessage})})})}exports.PaypalPayment=PaypalPayment,exports.default=PaypalPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaypalPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),react_1=require("react"),defaultMessage="by placing the order, you will be redirected to the PayPal website to sign in and authorize the payment";function PaypalPayment({infoMessage,...p}){const ref=(0,react_1.useRef)(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default);(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&paymentSource?.approval_url&&(ref.current.onsubmit=async()=>await handleClick(),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=async()=>{if(paymentSource&&currentPaymentMethodType)try{return await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"paypal",last4:""}}}}),!0}catch{return!1}return!1};return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{...p,children:(0,jsx_runtime_1.jsx)("span",{className:infoMessage?.className,children:(0,isFunction_1.default)(infoMessage?.text)?infoMessage?.text():infoMessage?.text||defaultMessage})})})}exports.PaypalPayment=PaypalPayment,exports.default=PaypalPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.shipment_line_items?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0]?.id:shipment.shipping_method?.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>time.stock_location?.id===shipment.stock_location?.id),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,{value:shipmentProps,children},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.stock_line_items?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0]?.id:shipment.shipping_method?.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>time.stock_location?.id===shipment.stock_location?.id),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,{value:shipmentProps,children},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.shipment_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.shipment_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order!=null,order?.shipments?.length]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>!!(lineItem.item?.do_not_ship||lineItem.item?.do_not_track||lineItem.item?.inventory?.quantity>=lineItem?.quantity)).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>({...state,setShipmentErrors:errors=>ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch),setShippingMethod:async(shipmentId,shippingMethodId)=>await(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,{value:contextValue,children})}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order!=null,order?.shipments?.length]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>!!(lineItem.item?.do_not_ship||lineItem.item?.do_not_track||lineItem.item?.inventory?.quantity>=lineItem?.quantity)).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>({...state,setShipmentErrors:errors=>ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch),setShippingMethod:async(shipmentId,shippingMethodId)=>await(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,{value:contextValue,children})}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),AvailabilityReducer_1=tslib_1.__importStar(require("../../reducers/AvailabilityReducer")),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),{accessToken,endpoint}=(0,useCustomContext_1.default)({context:CommerceLayerContext_1.default,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=(0,react_1.useReducer)(AvailabilityReducer_1.default,AvailabilityReducer_1.availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;return(0,react_1.useEffect)(()=>{if(accessToken!=null&&accessToken!==""){const config={accessToken,endpoint};sCode&&(0,AvailabilityReducer_1.getAvailability)({skuCode:sCode,config,dispatch})}return()=>{dispatch({type:"setAvailability",payload:{}})}},[accessToken,sCode]),(0,react_1.useEffect)(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]),(0,jsx_runtime_1.jsx)(AvailabilityContext_1.default.Provider,{value:{...state,parent:!0},children})}exports.AvailabilityContainer=AvailabilityContainer,exports.default=AvailabilityContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),AvailabilityReducer_1=tslib_1.__importStar(require("../../reducers/AvailabilityReducer")),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),{accessToken,endpoint}=(0,useCustomContext_1.default)({context:CommerceLayerContext_1.default,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=(0,react_1.useReducer)(AvailabilityReducer_1.default,AvailabilityReducer_1.availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;(0,react_1.useEffect)(()=>{if(accessToken!=null&&accessToken!==""){const config={accessToken,endpoint};sCode&&(0,AvailabilityReducer_1.getAvailability)({skuCode:sCode,config,dispatch})}return()=>{dispatch({type:"setAvailability",payload:{}})}},[accessToken,sCode]),(0,react_1.useEffect)(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]);const memoized=(0,react_1.useMemo)(()=>({...state,parent:!0}),[state]);return(0,jsx_runtime_1.jsx)(AvailabilityContext_1.default.Provider,{value:memoized,children})}exports.AvailabilityContainer=AvailabilityContainer,exports.default=AvailabilityContainer;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityTemplate=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityTemplate(props){const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props,{min,max,shipping_method:shippingMethod,quantity}=(0,useCustomContext_1.default)({context:AvailabilityContext_1.default,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?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:text.join(" ")})}exports.AvailabilityTemplate=AvailabilityTemplate,exports.default=AvailabilityTemplate;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityTemplate=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityTemplate(props){const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props,{min,max,shipping_method:shippingMethod,quantity,skuCode}=(0,useCustomContext_1.default)({context:AvailabilityContext_1.default,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?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{"data-testid":skuCode?`availability-${skuCode}`:"",...p,children:text.join(" ")})}exports.AvailabilityTemplate=AvailabilityTemplate,exports.default=AvailabilityTemplate;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
  import { BaseInputComponentProps } from '../../typings/index';
3
3
  export type BaseInputProps = BaseInputComponentProps & Omit<JSX.IntrinsicElements['input'], 'children'> & Omit<JSX.IntrinsicElements['textarea'], 'children'>;
4
- declare const _default: React.ForwardRefExoticComponent<Pick<BaseInputProps, "children" | "form" | "slot" | "style" | "title" | "pattern" | "value" | "placeholder" | "className" | "required" | "name" | "onChange" | "id" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "lang" | "nonce" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "height" | "max" | "min" | "type" | "width" | "crossOrigin" | "alt" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "autoComplete" | "accept" | "capture" | "checked" | "enterKeyHint" | "list" | "maxLength" | "minLength" | "multiple" | "readOnly" | "size" | "step" | "cols" | "dirName" | "rows" | "wrap"> & React.RefAttributes<any>>;
4
+ declare const _default: React.ForwardRefExoticComponent<Omit<BaseInputProps, "ref"> & React.RefAttributes<any>>;
5
5
  export default _default;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("./Parent")),react_1=require("react"),placeholderImages_1=require("../../utils/placeholderImages");function GenericFieldComponent(props){const{children,tagElement,attribute,context,...p}=props,resourceContext=(0,react_1.useContext)(context);let attributeValue="";const keysContext=Object.keys(resourceContext).filter(key=>key===p.resource);if(keysContext.length===1){const[keyResource]=keysContext;keyResource&&attribute&&(attributeValue=resourceContext[keyResource][attribute])}const Tag=tagElement||"span";if(Tag==="img"&&!children){const src=attributeValue||placeholderImages_1.defaultImgUrl,name="";return(0,jsx_runtime_1.jsx)("img",{alt:name,src,...p})}const parentProps={attributeValue,tagElement,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)(Tag,{...p,children:attributeValue})}exports.default=GenericFieldComponent;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("./Parent")),react_1=require("react"),placeholderImages_1=require("../../utils/placeholderImages");function GenericFieldComponent(props){const{children,tagElement,attribute,context,resource,...p}=props,resourceContext=(0,react_1.useContext)(context);let attributeValue="";const keysContext=Object.keys(resourceContext).filter(key=>key===resource);if(keysContext.length===1){const[keyResource]=keysContext;keyResource&&attribute&&(attributeValue=resourceContext[keyResource][attribute])}const Tag=tagElement||"span";if(Tag==="img"&&!children){const src=attributeValue||placeholderImages_1.defaultImgUrl,name="";return(0,jsx_runtime_1.jsx)("img",{alt:name,src,...p})}const parentProps={attributeValue,tagElement,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)(Tag,{"data-testid":attributeValue,...p,children:attributeValue},attributeValue)}exports.default=GenericFieldComponent;
@@ -1,7 +1,7 @@
1
1
  import { LineItem } from '@commercelayer/sdk';
2
2
  import { BaseError } from '../../typings/errors';
3
3
  import { TResourceError } from '../errors/Errors';
4
- export type AllErrorsParams = {
4
+ export interface AllErrorsParams {
5
5
  allErrors: BaseError[];
6
6
  messages: BaseError[];
7
7
  field?: string;
@@ -9,9 +9,7 @@ export type AllErrorsParams = {
9
9
  lineItem?: LineItem;
10
10
  resource?: TResourceError;
11
11
  returnHtml?: boolean;
12
- };
13
- export interface GetAllErrors {
14
- <P extends AllErrorsParams>(params: P): Array<JSX.Element | string | undefined>;
15
12
  }
13
+ export type GetAllErrors = <P extends AllErrorsParams>(params: P) => Array<JSX.Element | string | undefined>;
16
14
  declare const getAllErrors: GetAllErrors;
17
15
  export default getAllErrors;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),customMessages_1=tslib_1.__importDefault(require("../../utils/customMessages")),getAllErrors=params=>{const{allErrors,messages,field,props,lineItem,resource,returnHtml=!0}=params;return allErrors.map((v,k)=>{const objMsg=(0,customMessages_1.default)(messages,v);let text=v?.title&&!v.detail?.includes(v.title)?`${v.title} - ${v.detail}`:`${v?.detail||v.message}`;if(objMsg?.message&&(text=objMsg?.message),field){if(v.resource==="line_items"&&lineItem&&v.id===lineItem.id)return returnHtml?(0,jsx_runtime_1.jsx)("span",{...props,children:text},k):text;if(field===v.field&&resource===v.resource)return returnHtml?(0,jsx_runtime_1.jsx)("span",{...props,children:text},k):text}if(resource===v.resource&&!field)return returnHtml?(0,jsx_runtime_1.jsx)("span",{...props,children:text},k):text}).filter(v=>v!==void 0)};exports.default=getAllErrors;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),customMessages_1=tslib_1.__importDefault(require("../../utils/customMessages")),getAllErrors=params=>{const{allErrors,messages,field,props,lineItem,resource,returnHtml=!0}=params;return allErrors.map((v,k)=>{const objMsg=(0,customMessages_1.default)(messages,v);let text=v?.title&&v?.detail!=null&&!v.detail?.includes(v.title)?`${v.title} - ${v.detail}`:`${v?.detail||v.message}`;if(objMsg?.message&&(text=objMsg?.message),field){if(v.resource==="line_items"&&lineItem&&v.id===lineItem.id)return returnHtml?(0,jsx_runtime_1.jsx)("span",{...props,children:text},k):text;if(field===v.field&&resource===v.resource)return returnHtml?(0,jsx_runtime_1.jsx)("span",{...props,children:text},k):text}if(resource===v.resource&&!field)return returnHtml?(0,jsx_runtime_1.jsx)("span",{...props,children:text},k):text}).filter(v=>v!==void 0)};exports.default=getAllErrors;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { OrderCodeType } from '../reducers/OrderReducer';
3
- type DefaultContext = {
3
+ interface DefaultContext {
4
4
  validation?: void;
5
5
  setValue?: (name: string, value: string) => void;
6
6
  codeType?: OrderCodeType;
7
- };
7
+ }
8
8
  declare const CouponAndGiftCardFormContext: import("react").Context<DefaultContext>;
9
9
  export default CouponAndGiftCardFormContext;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { AddressCountrySelectName, AddressInputName } from '../typings/index';
3
3
  import { AddressField } from '../reducers/AddressReducer';
4
- export type DefaultContextAddress = {
4
+ export interface DefaultContextAddress {
5
5
  validation?: void;
6
6
  setValue?: (name: AddressField | AddressInputName | AddressCountrySelectName, value: any) => void;
7
7
  errors?: {
@@ -15,6 +15,6 @@ export type DefaultContextAddress = {
15
15
  requiresBillingInfo?: boolean;
16
16
  resetField?: (name: string) => void;
17
17
  values?: Record<string, any>;
18
- };
18
+ }
19
19
  declare const CustomerAddressFormContext: import("react").Context<DefaultContextAddress>;
20
20
  export default CustomerAddressFormContext;
@@ -1,12 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { SetCustomerErrors, deleteCustomerAddress, CustomerState, GetCustomerAddresses, getCustomerPaymentSources, setCustomerEmail, TCustomerAddress } from '../reducers/CustomerReducer';
2
+ import { SetCustomerErrors, deleteCustomerAddress, CustomerState, getCustomerPaymentSources, setCustomerEmail, TCustomerAddress, getCustomerAddresses } from '../reducers/CustomerReducer';
3
3
  export type InitialCustomerContext = Partial<{
4
4
  saveCustomerUser: (customerEmail: string) => Promise<void>;
5
5
  setCustomerErrors: SetCustomerErrors;
6
6
  setCustomerEmail: typeof setCustomerEmail;
7
7
  getCustomerPaymentSources: typeof getCustomerPaymentSources;
8
- deleteCustomerAddress: typeof deleteCustomerAddress | undefined;
9
- getCustomerAddresses: GetCustomerAddresses;
8
+ deleteCustomerAddress: typeof deleteCustomerAddress;
9
+ getCustomerAddresses: typeof getCustomerAddresses;
10
10
  createCustomerAddress: (address: TCustomerAddress) => Promise<void>;
11
11
  } & CustomerState>;
12
12
  export declare const defaultCustomerContext: {};
@@ -15,8 +15,8 @@ declare const CustomerContext: import("react").Context<Partial<{
15
15
  setCustomerErrors: SetCustomerErrors;
16
16
  setCustomerEmail: typeof setCustomerEmail;
17
17
  getCustomerPaymentSources: typeof getCustomerPaymentSources;
18
- deleteCustomerAddress: typeof deleteCustomerAddress | undefined;
19
- getCustomerAddresses: GetCustomerAddresses;
18
+ deleteCustomerAddress: typeof deleteCustomerAddress;
19
+ getCustomerAddresses: typeof getCustomerAddresses;
20
20
  createCustomerAddress: (address: TCustomerAddress) => Promise<void>;
21
21
  } & Partial<import("../reducers/CustomerReducer").CustomerActionPayload>>>;
22
22
  export default CustomerContext;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { IconBrand } from './PaymentSourceContext';
3
+ interface DefaultContext {
4
+ brand?: IconBrand | string;
5
+ exp_month?: number | string;
6
+ exp_year?: number | string;
7
+ last4?: string;
8
+ }
9
+ export declare const defaultCustomerPaymentSourceContext: {};
10
+ declare const CustomerPaymentSourceContext: import("react").Context<DefaultContext>;
11
+ export default CustomerPaymentSourceContext;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.defaultCustomerPaymentSourceContext=void 0;const react_1=require("react");exports.defaultCustomerPaymentSourceContext={};const CustomerPaymentSourceContext=(0,react_1.createContext)(exports.defaultCustomerPaymentSourceContext);exports.default=CustomerPaymentSourceContext;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export type IconBrand = 'visa' | 'credit-card' | 'amex' | 'mastercard' | 'jcb' | 'wire-transfer' | 'maestro' | 'cirrus' | 'paypal';
3
- type DefaultContext = {
3
+ interface DefaultContext {
4
4
  brand?: IconBrand | string;
5
5
  exp_month?: number | string;
6
6
  exp_year?: number | string;
@@ -8,7 +8,7 @@ type DefaultContext = {
8
8
  showCard?: boolean;
9
9
  readonly?: boolean;
10
10
  handleEditClick?: (e: MouseEvent) => void;
11
- };
11
+ }
12
12
  export declare const defaultPaymentSourceContext: {};
13
13
  declare const PaymentSourceContext: import("react").Context<DefaultContext>;
14
14
  export default PaymentSourceContext;
@@ -31,6 +31,7 @@ export interface LeadTimes {
31
31
  days: number;
32
32
  }
33
33
  export type AvailabilityPayload = {
34
+ skuCode?: string;
34
35
  quantity?: number;
35
36
  errors?: BaseError[];
36
37
  parent?: boolean;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAvailability=exports.availabilityInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.availabilityInitialState={};async function getAvailability({skuCode,dispatch,config}){const sdk=(0,getSdk_1.default)(config);try{const[sku]=await sdk.skus.list({fields:{skus:["id"]},filters:{code_in:skuCode}});if(sku){const skuInventory=await sdk.skus.retrieve(sku.id,{fields:{skus:["inventory"]}}),[level]=skuInventory.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];dispatch({type:"setAvailability",payload:{...delivery,quantity:skuInventory.inventory.quantity}})}}catch(error){console.error("Get SKU availability",error)}}exports.getAvailability=getAvailability;const typeAction=["setAvailability","setErrors"],availabilityReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,typeAction);exports.default=availabilityReducer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAvailability=exports.availabilityInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.availabilityInitialState={};async function getAvailability({skuCode,dispatch,config}){const sdk=(0,getSdk_1.default)(config);try{const[sku]=await sdk.skus.list({fields:{skus:["id"]},filters:{code_in:skuCode}});if(sku){const skuInventory=await sdk.skus.retrieve(sku.id,{fields:{skus:["inventory"]}}),[level]=skuInventory.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];dispatch({type:"setAvailability",payload:{...delivery,quantity:skuInventory.inventory.quantity,skuCode}})}}catch(error){console.error("Get SKU availability",error)}}exports.getAvailability=getAvailability;const typeAction=["setAvailability","setErrors"],availabilityReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,typeAction);exports.default=availabilityReducer;
@@ -21,11 +21,11 @@ export type SetBillingAddress = (id: string, options?: {
21
21
  customerAddressId?: string;
22
22
  }) => Promise<void>;
23
23
  export declare const setBillingAddress: SetBillingAddress;
24
- type SetBillingCustomerAddressId = (args: {
24
+ interface SetBillingCustomerAddressIdParams {
25
25
  dispatch: Dispatch<BillingAddressAction>;
26
26
  order: Order;
27
27
  setCloneAddress: (id: string, resource: AddressResource) => void;
28
- }) => void;
29
- export declare const setBillingCustomerAddressId: SetBillingCustomerAddressId;
28
+ }
29
+ export declare function setBillingCustomerAddressId({ dispatch, order, setCloneAddress }: SetBillingCustomerAddressIdParams): void;
30
30
  declare const billingAddressReducer: (state: BillingAddressState, reducer: BillingAddressAction) => BillingAddressState;
31
31
  export default billingAddressReducer;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setBillingCustomerAddressId=exports.setBillingAddress=exports.billingAddressInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.billingAddressInitialState={_billing_address_clone_id:""};const setBillingAddress=async(id,options)=>{try{if(options?.order){if(options.customerAddressId){const sdk=(0,getSdk_1.default)(options.config),attributes={id,reference:options.customerAddressId};await sdk.addresses.update(attributes)}options.dispatch({type:"setBillingAddress",payload:{_billing_address_clone_id:id}})}}catch(error){console.error("Set billing address",error)}};exports.setBillingAddress=setBillingAddress;const setBillingCustomerAddressId=async({dispatch,order,setCloneAddress})=>{const customerAddressId=order?.billing_address?.reference;try{customerAddressId&&(dispatch({type:"setBillingCustomerAddressId",payload:{billingCustomerAddressId:customerAddressId}}),setCloneAddress(customerAddressId,"billing_address"))}catch(error){console.error("error",error)}};exports.setBillingCustomerAddressId=setBillingCustomerAddressId;const type=["setBillingAddress","setBillingCustomerAddressId","cleanup"],billingAddressReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=billingAddressReducer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setBillingCustomerAddressId=exports.setBillingAddress=exports.billingAddressInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.billingAddressInitialState={_billing_address_clone_id:""};const setBillingAddress=async(id,options)=>{try{if(options?.order){if(options.customerAddressId){const sdk=(0,getSdk_1.default)(options.config),attributes={id,reference:options.customerAddressId};await sdk.addresses.update(attributes)}options.dispatch({type:"setBillingAddress",payload:{_billing_address_clone_id:id}})}}catch(error){console.error("Set billing address",error)}};exports.setBillingAddress=setBillingAddress;function setBillingCustomerAddressId({dispatch,order,setCloneAddress}){const customerAddressId=order?.billing_address?.reference;try{customerAddressId&&(dispatch({type:"setBillingCustomerAddressId",payload:{billingCustomerAddressId:customerAddressId}}),setCloneAddress(customerAddressId,"billing_address"))}catch(error){console.error("error",error)}}exports.setBillingCustomerAddressId=setBillingCustomerAddressId;const type=["setBillingAddress","setBillingCustomerAddressId","cleanup"],billingAddressReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=billingAddressReducer;