@commercelayer/react-components 4.5.2-beta.2 → 4.6.0-beta.0

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 (223) hide show
  1. package/lib/cjs/components/MetadataInput.d.ts +0 -1
  2. package/lib/cjs/components/addresses/Address.d.ts +0 -1
  3. package/lib/cjs/components/addresses/AddressCountrySelector.d.ts +0 -1
  4. package/lib/cjs/components/addresses/AddressInput.d.ts +0 -1
  5. package/lib/cjs/components/addresses/AddressStateSelector.d.ts +0 -1
  6. package/lib/cjs/components/addresses/AddressesEmpty.d.ts +0 -1
  7. package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +0 -1
  8. package/lib/cjs/components/auth/CommerceLayer.d.ts +0 -1
  9. package/lib/cjs/components/customers/CustomerContainer.d.ts +3 -1
  10. package/lib/cjs/components/customers/CustomerContainer.js +1 -1
  11. package/lib/cjs/components/customers/CustomerField.d.ts +0 -1
  12. package/lib/cjs/components/customers/CustomerInput.d.ts +0 -1
  13. package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +0 -1
  14. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +0 -1
  15. package/lib/cjs/components/customers/MyAccountLink.d.ts +0 -1
  16. package/lib/cjs/components/customers/MyIdentityLink.d.ts +0 -1
  17. package/lib/cjs/components/errors/Errors.d.ts +0 -1
  18. package/lib/cjs/components/gift_cards/GiftCard.d.ts +0 -1
  19. package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +0 -1
  20. package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +0 -1
  21. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +0 -1
  22. package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +0 -1
  23. package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +0 -1
  24. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +0 -1
  25. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +0 -1
  26. package/lib/cjs/components/line_items/LineItem.d.ts +0 -1
  27. package/lib/cjs/components/line_items/LineItemAmount.d.ts +0 -1
  28. package/lib/cjs/components/line_items/LineItemCode.d.ts +0 -1
  29. package/lib/cjs/components/line_items/LineItemField.d.ts +0 -1
  30. package/lib/cjs/components/line_items/LineItemImage.d.ts +0 -1
  31. package/lib/cjs/components/line_items/LineItemName.d.ts +0 -1
  32. package/lib/cjs/components/line_items/LineItemsContainer.d.ts +0 -1
  33. package/lib/cjs/components/line_items/LineItemsCount.d.ts +0 -1
  34. package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +0 -1
  35. package/lib/cjs/components/orders/AdjustmentAmount.d.ts +0 -1
  36. package/lib/cjs/components/orders/CheckoutLink.d.ts +0 -1
  37. package/lib/cjs/components/orders/DiscountAmount.d.ts +0 -1
  38. package/lib/cjs/components/orders/GiftCardAmount.d.ts +0 -1
  39. package/lib/cjs/components/orders/OrderContainer.d.ts +0 -1
  40. package/lib/cjs/components/orders/OrderList.d.ts +0 -1
  41. package/lib/cjs/components/orders/OrderListEmpty.d.ts +0 -1
  42. package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +0 -1
  43. package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +0 -1
  44. package/lib/cjs/components/orders/OrderListRow.d.ts +0 -1
  45. package/lib/cjs/components/orders/OrderNumber.d.ts +0 -1
  46. package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +0 -1
  47. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -1
  48. package/lib/cjs/components/orders/ShippingAmount.d.ts +0 -1
  49. package/lib/cjs/components/orders/SubTotalAmount.d.ts +0 -1
  50. package/lib/cjs/components/orders/TaxesAmount.d.ts +0 -1
  51. package/lib/cjs/components/orders/TotalAmount.d.ts +0 -1
  52. package/lib/cjs/components/parcels/ParcelField.d.ts +0 -1
  53. package/lib/cjs/components/parcels/ParcelLineItem.d.ts +0 -1
  54. package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +0 -1
  55. package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +0 -1
  56. package/lib/cjs/components/parcels/Parcels.d.ts +0 -1
  57. package/lib/cjs/components/parcels/ParcelsCount.d.ts +0 -1
  58. package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +0 -1
  59. package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +0 -1
  60. package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +0 -1
  61. package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +0 -1
  62. package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +0 -1
  63. package/lib/cjs/components/payment_gateways/PaymentGateway.d.ts +0 -1
  64. package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +0 -1
  65. package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +0 -1
  66. package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +0 -1
  67. package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +0 -1
  68. package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +0 -1
  69. package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +0 -1
  70. package/lib/cjs/components/payment_source/BraintreePayment.d.ts +0 -1
  71. package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +0 -1
  72. package/lib/cjs/components/payment_source/ExternalPayment.d.ts +0 -1
  73. package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +0 -1
  74. package/lib/cjs/components/payment_source/PaymentSource.d.ts +0 -1
  75. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +0 -1
  76. package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +0 -1
  77. package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +0 -1
  78. package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +0 -1
  79. package/lib/cjs/components/payment_source/StripePayment.d.ts +0 -1
  80. package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +0 -1
  81. package/lib/cjs/components/prices/Price.d.ts +0 -1
  82. package/lib/cjs/components/prices/PricesContainer.d.ts +0 -1
  83. package/lib/cjs/components/shipments/ShipmentField.d.ts +0 -1
  84. package/lib/cjs/components/shipments/ShipmentsCount.d.ts +0 -1
  85. package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +0 -1
  86. package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +0 -1
  87. package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +0 -1
  88. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +0 -1
  89. package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +0 -1
  90. package/lib/cjs/components/skus/SkuField.d.ts +0 -1
  91. package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +0 -1
  92. package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +0 -1
  93. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +0 -1
  94. package/lib/cjs/components/utils/BaseOrderPrice.d.ts +0 -1
  95. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +0 -1
  96. package/lib/cjs/components/utils/PriceTemplate.d.ts +0 -1
  97. package/lib/cjs/components/utils/getAllErrors.d.ts +0 -1
  98. package/lib/cjs/context/BillingAddressFormContext.d.ts +1 -1
  99. package/lib/cjs/reducers/AddressReducer.d.ts +1 -1
  100. package/lib/cjs/reducers/AddressReducer.js +1 -1
  101. package/lib/cjs/reducers/CustomerReducer.d.ts +3 -2
  102. package/lib/cjs/reducers/CustomerReducer.js +1 -1
  103. package/lib/cjs/typings/globals.d.ts +0 -1
  104. package/lib/cjs/typings/index.d.ts +1 -1
  105. package/lib/cjs/utils/filterChildren.d.ts +0 -1
  106. package/lib/cjs/utils/getCustomerIdByToken.d.ts +6 -0
  107. package/lib/cjs/utils/getCustomerIdByToken.js +2 -0
  108. package/lib/cjs/utils/getLoaderComponent.d.ts +0 -1
  109. package/lib/cjs/utils/getPrices.d.ts +0 -1
  110. package/lib/cjs/utils/isGuestToken.d.ts +6 -0
  111. package/lib/cjs/utils/isGuestToken.js +2 -0
  112. package/lib/esm/components/MetadataInput.d.ts +0 -1
  113. package/lib/esm/components/addresses/Address.d.ts +0 -1
  114. package/lib/esm/components/addresses/AddressCountrySelector.d.ts +0 -1
  115. package/lib/esm/components/addresses/AddressInput.d.ts +0 -1
  116. package/lib/esm/components/addresses/AddressStateSelector.d.ts +0 -1
  117. package/lib/esm/components/addresses/AddressesEmpty.d.ts +0 -1
  118. package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +0 -1
  119. package/lib/esm/components/auth/CommerceLayer.d.ts +0 -1
  120. package/lib/esm/components/customers/CustomerContainer.d.ts +3 -1
  121. package/lib/esm/components/customers/CustomerContainer.js +1 -1
  122. package/lib/esm/components/customers/CustomerField.d.ts +0 -1
  123. package/lib/esm/components/customers/CustomerInput.d.ts +0 -1
  124. package/lib/esm/components/customers/CustomerPaymentSource.d.ts +0 -1
  125. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +0 -1
  126. package/lib/esm/components/customers/MyAccountLink.d.ts +0 -1
  127. package/lib/esm/components/customers/MyIdentityLink.d.ts +0 -1
  128. package/lib/esm/components/errors/Errors.d.ts +0 -1
  129. package/lib/esm/components/gift_cards/GiftCard.d.ts +0 -1
  130. package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +0 -1
  131. package/lib/esm/components/gift_cards/GiftCardInput.d.ts +0 -1
  132. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +0 -1
  133. package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +0 -1
  134. package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +0 -1
  135. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +0 -1
  136. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +0 -1
  137. package/lib/esm/components/line_items/LineItem.d.ts +0 -1
  138. package/lib/esm/components/line_items/LineItemAmount.d.ts +0 -1
  139. package/lib/esm/components/line_items/LineItemCode.d.ts +0 -1
  140. package/lib/esm/components/line_items/LineItemField.d.ts +0 -1
  141. package/lib/esm/components/line_items/LineItemImage.d.ts +0 -1
  142. package/lib/esm/components/line_items/LineItemName.d.ts +0 -1
  143. package/lib/esm/components/line_items/LineItemsContainer.d.ts +0 -1
  144. package/lib/esm/components/line_items/LineItemsCount.d.ts +0 -1
  145. package/lib/esm/components/line_items/LineItemsEmpty.d.ts +0 -1
  146. package/lib/esm/components/orders/AdjustmentAmount.d.ts +0 -1
  147. package/lib/esm/components/orders/CheckoutLink.d.ts +0 -1
  148. package/lib/esm/components/orders/DiscountAmount.d.ts +0 -1
  149. package/lib/esm/components/orders/GiftCardAmount.d.ts +0 -1
  150. package/lib/esm/components/orders/OrderContainer.d.ts +0 -1
  151. package/lib/esm/components/orders/OrderList.d.ts +0 -1
  152. package/lib/esm/components/orders/OrderListEmpty.d.ts +0 -1
  153. package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +0 -1
  154. package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +0 -1
  155. package/lib/esm/components/orders/OrderListRow.d.ts +0 -1
  156. package/lib/esm/components/orders/OrderNumber.d.ts +0 -1
  157. package/lib/esm/components/orders/PaymentMethodAmount.d.ts +0 -1
  158. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -1
  159. package/lib/esm/components/orders/ShippingAmount.d.ts +0 -1
  160. package/lib/esm/components/orders/SubTotalAmount.d.ts +0 -1
  161. package/lib/esm/components/orders/TaxesAmount.d.ts +0 -1
  162. package/lib/esm/components/orders/TotalAmount.d.ts +0 -1
  163. package/lib/esm/components/parcels/ParcelField.d.ts +0 -1
  164. package/lib/esm/components/parcels/ParcelLineItem.d.ts +0 -1
  165. package/lib/esm/components/parcels/ParcelLineItemField.d.ts +0 -1
  166. package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +0 -1
  167. package/lib/esm/components/parcels/Parcels.d.ts +0 -1
  168. package/lib/esm/components/parcels/ParcelsCount.d.ts +0 -1
  169. package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +0 -1
  170. package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +0 -1
  171. package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +0 -1
  172. package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +0 -1
  173. package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +0 -1
  174. package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +0 -1
  175. package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +0 -1
  176. package/lib/esm/components/payment_gateways/StripeGateway.d.ts +0 -1
  177. package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +0 -1
  178. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +0 -1
  179. package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +0 -1
  180. package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +0 -1
  181. package/lib/esm/components/payment_source/BraintreePayment.d.ts +0 -1
  182. package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +0 -1
  183. package/lib/esm/components/payment_source/ExternalPayment.d.ts +0 -1
  184. package/lib/esm/components/payment_source/KlarnaPayment.d.ts +0 -1
  185. package/lib/esm/components/payment_source/PaymentSource.d.ts +0 -1
  186. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +0 -1
  187. package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +0 -1
  188. package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +0 -1
  189. package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +0 -1
  190. package/lib/esm/components/payment_source/StripePayment.d.ts +0 -1
  191. package/lib/esm/components/payment_source/WireTransferPayment.d.ts +0 -1
  192. package/lib/esm/components/prices/Price.d.ts +0 -1
  193. package/lib/esm/components/prices/PricesContainer.d.ts +0 -1
  194. package/lib/esm/components/shipments/ShipmentField.d.ts +0 -1
  195. package/lib/esm/components/shipments/ShipmentsCount.d.ts +0 -1
  196. package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +0 -1
  197. package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +0 -1
  198. package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +0 -1
  199. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +0 -1
  200. package/lib/esm/components/skus/DeliveryLeadTime.d.ts +0 -1
  201. package/lib/esm/components/skus/SkuField.d.ts +0 -1
  202. package/lib/esm/components/stock_transfers/StockTransfer.d.ts +0 -1
  203. package/lib/esm/components/stock_transfers/StockTransferField.d.ts +0 -1
  204. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +0 -1
  205. package/lib/esm/components/utils/BaseOrderPrice.d.ts +0 -1
  206. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +0 -1
  207. package/lib/esm/components/utils/PriceTemplate.d.ts +0 -1
  208. package/lib/esm/components/utils/getAllErrors.d.ts +0 -1
  209. package/lib/esm/context/BillingAddressFormContext.d.ts +1 -1
  210. package/lib/esm/reducers/AddressReducer.d.ts +1 -1
  211. package/lib/esm/reducers/AddressReducer.js +1 -1
  212. package/lib/esm/reducers/CustomerReducer.d.ts +3 -2
  213. package/lib/esm/reducers/CustomerReducer.js +1 -1
  214. package/lib/esm/typings/globals.d.ts +0 -1
  215. package/lib/esm/typings/index.d.ts +1 -1
  216. package/lib/esm/utils/filterChildren.d.ts +0 -1
  217. package/lib/esm/utils/getCustomerIdByToken.d.ts +6 -0
  218. package/lib/esm/utils/getCustomerIdByToken.js +2 -0
  219. package/lib/esm/utils/getLoaderComponent.d.ts +0 -1
  220. package/lib/esm/utils/getPrices.d.ts +0 -1
  221. package/lib/esm/utils/isGuestToken.d.ts +6 -0
  222. package/lib/esm/utils/isGuestToken.js +2 -0
  223. package/package.json +21 -21
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children: DefaultChildrenType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ConditionalElement } from '../../typings/index';
3
2
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
4
3
  type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['StockTransfer']>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { Address } from '@commercelayer/sdk';
3
2
  import AddressChildrenContext from '../../context/AddressChildrenContext';
4
3
  import { type ChildrenFunction } from '../../typings/index';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type PropsType } from '../../utils/PropsType';
3
2
  import { type baseOrderPricePropTypes } from '../../typings/index';
4
3
  export type BaseOrderPriceProps = PropsType<typeof baseOrderPricePropTypes, unknown> & Omit<JSX.IntrinsicElements['span'], 'children'>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type PaymentResource } from '../../reducers/PaymentMethodReducer';
3
2
  import PaymentSourceContext, { type IconBrand } from '../../context/PaymentSourceContext';
4
3
  import { type ChildrenFunction } from '../../typings/index';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type PriceProps } from '../prices/Price';
3
2
  export type PTemplateProps = {
4
3
  formattedAmount?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type LineItem } from '@commercelayer/sdk';
3
2
  import { type BaseError } from '../../typings/errors';
4
3
  import { type TResourceError } from '../errors/Errors';
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { Address } from '@commercelayer/sdk';
3
- export type AddressValuesKeys = `${keyof Address}` | `billing_address_${keyof Address}` | `shipping_address_${keyof Address}`;
3
+ export type AddressValuesKeys = `${keyof Address}` | `billing_address_${keyof Address}` | `shipping_address_${keyof Address}` | `billing_address_${`metadata_${string}`}`;
4
4
  export interface DefaultContextAddress {
5
5
  validation?: void;
6
6
  setValue?: (name: AddressValuesKeys, value: string | number | readonly string[]) => void;
@@ -14,7 +14,7 @@ export type AddressSchema = Omit<Address, 'created_at' | 'updated_at' | 'id' | '
14
14
  export interface AddressActionPayload {
15
15
  errors: BaseError[];
16
16
  billing_address: TCustomerAddress;
17
- shipping_address: AddressCreate;
17
+ shipping_address: AddressCreate & Record<string, string | null | undefined>;
18
18
  shipToDifferentAddress: boolean;
19
19
  billingAddressId: string;
20
20
  shippingAddressId: string;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveAddresses=exports.setCloneAddress=exports.setAddress=exports.setAddressErrors=exports.addressInitialState=exports.addressFields=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),camelCase_1=tslib_1.__importDefault(require("lodash/camelCase"));exports.addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],exports.addressInitialState={errors:[]};const setAddressErrors=({errors,dispatch,currentErrors=[],resource})=>{const billingErrors=resource==="billing_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="billing_address"),shippingErrors=resource==="shipping_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="shipping_address"),finalErrors=[...billingErrors,...shippingErrors];dispatch&&dispatch({type:"setErrors",payload:{errors:finalErrors}})};exports.setAddressErrors=setAddressErrors;const setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})};exports.setAddress=setAddress;const setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${(0,camelCase_1.default)(resource)}Id`]:id}})};exports.setCloneAddress=setCloneAddress;function saveAddresses({config,updateOrder,order,state,customerEmail}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){const{shipToDifferentAddress,billing_address:billingAddress,shipping_address:shippingAddress,billingAddressId,shippingAddressId}=state;try{const sdk=(0,getSdk_1.default)(config);if(order){const currentBillingAddressRef=(_a=order?.billing_address)===null||_a===void 0?void 0:_a.reference;console.log("billingAddress",billingAddress),console.log("shippingAddress",shippingAddress);const orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId,customer_email:customerEmail};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=(_b=order?.billing_address)===null||_b===void 0?void 0:_b.id,orderAttributes._shipping_address_clone_id=(_c=order?.shipping_address)===null||_c===void 0?void 0:_c.id),!(0,isEmpty_1.default)(billingAddress)&&billingAddress){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._shipping_address_same_as_billing=!0;const address=yield sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._shipping_address_same_as_billing,shippingAddressId&&(orderAttributes._shipping_address_clone_id=shippingAddressId),!(0,isEmpty_1.default)(shippingAddress)&&shippingAddress)){delete orderAttributes._shipping_address_clone_id;const address=yield sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(!(0,isEmpty_1.default)(orderAttributes)&&updateOrder){const orderUpdated=yield updateOrder({id:order.id,attributes:orderAttributes});return{success:!0,order:orderUpdated?.order}}}return{success:!1}}catch(error){return console.error(error),{success:!1,error}}})}exports.saveAddresses=saveAddresses;const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"],addressReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=addressReducer;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveAddresses=exports.setCloneAddress=exports.setAddress=exports.setAddressErrors=exports.addressInitialState=exports.addressFields=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),camelCase_1=tslib_1.__importDefault(require("lodash/camelCase"));exports.addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],exports.addressInitialState={errors:[]};const setAddressErrors=({errors,dispatch,currentErrors=[],resource})=>{const billingErrors=resource==="billing_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="billing_address"),shippingErrors=resource==="shipping_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="shipping_address"),finalErrors=[...billingErrors,...shippingErrors];dispatch&&dispatch({type:"setErrors",payload:{errors:finalErrors}})};exports.setAddressErrors=setAddressErrors;const setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})};exports.setAddress=setAddress;const setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${(0,camelCase_1.default)(resource)}Id`]:id}})};exports.setCloneAddress=setCloneAddress;function saveAddresses({config,updateOrder,order,state,customerEmail}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){const{shipToDifferentAddress,billing_address:billingAddress,shipping_address:shippingAddress,billingAddressId,shippingAddressId}=state;try{const sdk=(0,getSdk_1.default)(config);if(order){const currentBillingAddressRef=(_a=order?.billing_address)===null||_a===void 0?void 0:_a.reference,orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId,customer_email:customerEmail};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=(_b=order?.billing_address)===null||_b===void 0?void 0:_b.id,orderAttributes._shipping_address_clone_id=(_c=order?.shipping_address)===null||_c===void 0?void 0:_c.id),billingAddress!=null&&Object.keys(billingAddress).length>0){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._shipping_address_same_as_billing=!0;const hasMetadata=Object.keys(billingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");billingAddress.metadata=Object.assign(Object.assign({},billingAddress.metadata||{}),{[metadataKey]:billingAddress[key]}),delete billingAddress[key]});const address=yield sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._shipping_address_same_as_billing,shippingAddressId&&(orderAttributes._shipping_address_clone_id=shippingAddressId),shippingAddress!=null&&Object.keys(shippingAddress).length>0)){delete orderAttributes._shipping_address_clone_id;const hasMetadata=Object.keys(shippingAddress).filter(key=>!!key.startsWith("metadata_"));hasMetadata?.length>0&&hasMetadata.forEach(key=>{const metadataKey=key.replace("metadata_","");shippingAddress.metadata=Object.assign(Object.assign({},shippingAddress.metadata||{}),{[metadataKey]:shippingAddress[key]}),delete shippingAddress[key]});const address=yield sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}if(orderAttributes!=null&&updateOrder){const orderUpdated=yield updateOrder({id:order.id,attributes:orderAttributes});return{success:!0,order:orderUpdated?.order}}}return{success:!1}}catch(error){return console.error(error),{success:!1,error}}})}exports.saveAddresses=saveAddresses;const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"],addressReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=addressReducer;
@@ -4,7 +4,7 @@ import type { Address, AddressCreate, AddressUpdate, Customer, CustomerPaymentSo
4
4
  import { type CommerceLayerConfig } from '../context/CommerceLayerContext';
5
5
  import { type updateOrder } from './OrderReducer';
6
6
  import { type ListResponse } from '@commercelayer/sdk/lib/cjs/resource';
7
- export type CustomerActionType = 'setErrors' | 'setCustomerEmail' | 'setAddresses' | 'setPayments' | 'setOrders' | 'setSubscriptions';
7
+ export type CustomerActionType = 'setErrors' | 'setCustomerEmail' | 'setAddresses' | 'setPayments' | 'setOrders' | 'setSubscriptions' | 'setCustomers';
8
8
  export interface CustomerActionPayload {
9
9
  addresses: Address[] | null;
10
10
  payments: CustomerPaymentSource[] | null;
@@ -119,7 +119,7 @@ interface GetCustomerOrdersProps {
119
119
  }
120
120
  export declare function getCustomerOrders({ config, dispatch, pageSize, pageNumber }: GetCustomerOrdersProps): Promise<void>;
121
121
  export declare function getCustomerSubscriptions({ config, dispatch, pageSize, pageNumber }: GetCustomerOrdersProps): Promise<void>;
122
- export type TCustomerAddress = AddressCreate & AddressUpdate;
122
+ export type TCustomerAddress = AddressCreate & AddressUpdate & Record<string, string | null | undefined>;
123
123
  interface TCreateCustomerAddress {
124
124
  /**
125
125
  * Customer address dispatch function
@@ -142,6 +142,7 @@ export declare function createCustomerAddress({ address, config, dispatch, state
142
142
  interface GetCustomerPaymentsParams extends GetCustomerOrdersProps {
143
143
  }
144
144
  export declare function getCustomerPayments({ config, dispatch }: GetCustomerPaymentsParams): Promise<void>;
145
+ export declare function getCustomerInfo({ config, dispatch }: GetCustomerPaymentsParams): Promise<void>;
145
146
  export declare const customerInitialState: CustomerState;
146
147
  declare const customerReducer: (state: CustomerState, reducer: CustomerAction) => CustomerState;
147
148
  export default customerReducer;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.getCustomerPayments=exports.createCustomerAddress=exports.getCustomerSubscriptions=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=tslib_1.__importDefault(require("../utils/jwt"));function saveCustomerUser({customerEmail,order,updateOrder}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(order){const attributes={customer_email:customerEmail,id:order.id};yield updateOrder({id:order.id,attributes})}})}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;function getCustomerAddresses({config,dispatch,isOrderAvailable}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const addresses=[];(yield(0,getSdk_1.default)(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&(customerAddress.id!==customerAddress.address.reference&&!isOrderAvailable&&(customerAddress.address.reference=customerAddress.id),addresses.push(customerAddress.address))}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=(0,getErrors_1.default)({error,resource:"addresses"});dispatch({type:"setErrors",payload:{errors}})}})}exports.getCustomerAddresses=getCustomerAddresses;function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config&&addresses&&dispatch&&config)try{yield(0,getSdk_1.default)(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}})}exports.deleteCustomerAddress=deleteCustomerAddress;function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;function getCustomerOrders({config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const orders=yield(0,getSdk_1.default)(config).customers.orders(owner.id,{filters:{status_not_in:"draft,pending"},pageSize,pageNumber});dispatch({type:"setOrders",payload:{orders}})}}})}exports.getCustomerOrders=getCustomerOrders;function getCustomerSubscriptions({config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const subscriptions=yield(0,getSdk_1.default)(config).customers.order_subscriptions(owner.id,{pageSize,pageNumber});dispatch({type:"setSubscriptions",payload:{subscriptions}})}}})}exports.getCustomerSubscriptions=getCustomerSubscriptions;function createCustomerAddress({address,config,dispatch,state}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config&&address){const sdk=(0,getSdk_1.default)(config),{id}=address;try{if(id){const upAddress=yield sdk.addresses.update(address),updatedAddresses=(_a=state?.addresses)===null||_a===void 0?void 0:_a.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=yield sdk.addresses.create(address);if(!((_b=state?.customers)===null||_b===void 0)&&_b.id&&newAddress?.id){const newCustomerAddress=yield sdk.customer_addresses.create({customer:sdk.customers.relationship((_c=state?.customers)===null||_c===void 0?void 0:_c.id),address:sdk.addresses.relationship(newAddress.id)});yield sdk.addresses.update({id:newAddress.id,reference:newCustomerAddress.id}),dispatch&&state?.addresses&&(newAddress.reference=newCustomerAddress.id,dispatch({type:"setAddresses",payload:{addresses:[...state.addresses,newAddress]}}))}}}catch{throw new Error("Couldn't create customer address")}}})}exports.createCustomerAddress=createCustomerAddress;function getCustomerPayments({config,dispatch}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config!=null&&dispatch!=null){const payments=yield(0,getSdk_1.default)(config).customer_payment_sources.list({include:["payment_source"]});dispatch({type:"setPayments",payload:{payments}})}})}exports.getCustomerPayments=getCustomerPayments,exports.customerInitialState={errors:[],addresses:null,payments:null};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders","setSubscriptions"],customerReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=customerReducer;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.getCustomerInfo=exports.getCustomerPayments=exports.createCustomerAddress=exports.getCustomerSubscriptions=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=tslib_1.__importDefault(require("../utils/jwt")),getCustomerIdByToken_1=require("../utils/getCustomerIdByToken");function saveCustomerUser({customerEmail,order,updateOrder}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(order){const attributes={customer_email:customerEmail,id:order.id};yield updateOrder({id:order.id,attributes})}})}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;function getCustomerAddresses({config,dispatch,isOrderAvailable}){return tslib_1.__awaiter(this,void 0,void 0,function*(){try{const addresses=[];(yield(0,getSdk_1.default)(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&(customerAddress.id!==customerAddress.address.reference&&!isOrderAvailable&&(customerAddress.address.reference=customerAddress.id),addresses.push(customerAddress.address))}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=(0,getErrors_1.default)({error,resource:"addresses"});dispatch({type:"setErrors",payload:{errors}})}})}exports.getCustomerAddresses=getCustomerAddresses;function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config&&addresses&&dispatch&&config)try{yield(0,getSdk_1.default)(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}})}exports.deleteCustomerAddress=deleteCustomerAddress;function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;function getCustomerOrders({config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const orders=yield(0,getSdk_1.default)(config).customers.orders(owner.id,{filters:{status_not_in:"draft,pending"},pageSize,pageNumber});dispatch({type:"setOrders",payload:{orders}})}}})}exports.getCustomerOrders=getCustomerOrders;function getCustomerSubscriptions({config,dispatch,pageSize=10,pageNumber=1}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const subscriptions=yield(0,getSdk_1.default)(config).customers.order_subscriptions(owner.id,{pageSize,pageNumber});dispatch({type:"setSubscriptions",payload:{subscriptions}})}}})}exports.getCustomerSubscriptions=getCustomerSubscriptions;function createCustomerAddress({address,config,dispatch,state}){var _a,_b,_c;return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config&&address){const sdk=(0,getSdk_1.default)(config),{id}=address;try{if(id){const upAddress=yield sdk.addresses.update(address),updatedAddresses=(_a=state?.addresses)===null||_a===void 0?void 0:_a.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=yield sdk.addresses.create(address);if(!((_b=state?.customers)===null||_b===void 0)&&_b.id&&newAddress?.id){const newCustomerAddress=yield sdk.customer_addresses.create({customer:sdk.customers.relationship((_c=state?.customers)===null||_c===void 0?void 0:_c.id),address:sdk.addresses.relationship(newAddress.id)});yield sdk.addresses.update({id:newAddress.id,reference:newCustomerAddress.id}),dispatch&&state?.addresses&&(newAddress.reference=newCustomerAddress.id,dispatch({type:"setAddresses",payload:{addresses:[...state.addresses,newAddress]}}))}}}catch{throw new Error("Couldn't create customer address")}}})}exports.createCustomerAddress=createCustomerAddress;function getCustomerPayments({config,dispatch}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config!=null&&dispatch!=null){const payments=yield(0,getSdk_1.default)(config).customer_payment_sources.list({include:["payment_source"]});dispatch({type:"setPayments",payload:{payments}})}})}exports.getCustomerPayments=getCustomerPayments;function getCustomerInfo({config,dispatch}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(config.accessToken&&dispatch!=null){const sdk=(0,getSdk_1.default)(config),customerId=(0,getCustomerIdByToken_1.getCustomerIdByToken)(config.accessToken);if(customerId){const customers=yield sdk.customers.retrieve(customerId);dispatch({type:"setCustomers",payload:{customers}})}}})}exports.getCustomerInfo=getCustomerInfo,exports.customerInitialState={errors:[],addresses:null,payments:null};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders","setSubscriptions","setCustomers"],customerReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=customerReducer;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type DefaultChildrenType = JSX.Element[] | JSX.Element | null;
3
2
  type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
4
3
  export type TRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
@@ -51,7 +51,7 @@ export interface BaseInputComponentProps {
51
51
  placeholder?: string;
52
52
  }
53
53
  export type GiftCardInputName = 'balanceCents' | 'balanceMaxCents' | 'singleUse' | 'rechargeable' | 'imageUrl' | 'expiresAt' | 'referenceOrigin' | 'email' | 'firstName' | 'lastName' | 'reference';
54
- export type AddressInputName = 'billing_address_city' | 'billing_address_company' | 'billing_address_first_name' | 'billing_address_email' | 'billing_address_last_name' | 'billing_address_line_1' | 'billing_address_line_2' | 'billing_address_phone' | 'billing_address_state_code' | 'billing_address_zip_code' | 'billing_address_billing_info' | 'billing_address_save_to_customer_book' | 'shipping_address_city' | 'shipping_address_company' | 'shipping_address_email' | 'shipping_address_first_name' | 'shipping_address_last_name' | 'shipping_address_line_1' | 'shipping_address_line_2' | 'shipping_address_phone' | 'shipping_address_state_code' | 'shipping_address_zip_code' | 'shipping_address_save_to_customer_book';
54
+ export type AddressInputName = 'billing_address_city' | 'billing_address_company' | 'billing_address_first_name' | 'billing_address_email' | 'billing_address_last_name' | 'billing_address_line_1' | 'billing_address_line_2' | 'billing_address_phone' | 'billing_address_state_code' | 'billing_address_zip_code' | 'billing_address_billing_info' | 'billing_address_save_to_customer_book' | `billing_address_${`metadata_${string}`}` | 'shipping_address_city' | 'shipping_address_company' | 'shipping_address_email' | 'shipping_address_first_name' | 'shipping_address_last_name' | 'shipping_address_line_1' | 'shipping_address_line_2' | 'shipping_address_phone' | 'shipping_address_state_code' | 'shipping_address_zip_code' | 'shipping_address_save_to_customer_book';
55
55
  export type AddressCountrySelectName = 'billing_address_country_code' | 'shipping_address_country_code';
56
56
  export type AddressStateSelectName = 'billing_address_state_code' | 'shipping_address_state_code';
57
57
  export type LoaderType = string | JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type DefaultChildrenType } from '../typings/globals';
3
2
  interface Props<T> {
4
3
  children: DefaultChildrenType;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get the customer id from the token
3
+ * @param accessToken The access token
4
+ * @returns string
5
+ */
6
+ export declare function getCustomerIdByToken(accessToken: string): string | undefined;
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCustomerIdByToken=void 0;const tslib_1=require("tslib"),jwt_1=tslib_1.__importDefault(require("./jwt"));function getCustomerIdByToken(accessToken){var _a,_b;return(_b=(_a=(0,jwt_1.default)(accessToken))===null||_a===void 0?void 0:_a.owner)===null||_b===void 0?void 0:_b.id}exports.getCustomerIdByToken=getCustomerIdByToken;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import { type LoaderType } from '../typings/index';
3
2
  export default function getLoaderComponent(loader: LoaderType): JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type Price } from '@commercelayer/sdk';
3
2
  import { type PTemplateProps } from '../components/utils/PriceTemplate';
4
3
  export declare function getPriceByCode(skuPrices: Price[], code?: string): Price | undefined;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Check if the token is a sales channel token
3
+ * @param accessToken The access token
4
+ * @returns boolean
5
+ */
6
+ export declare function isGuestToken(accessToken: string): boolean;
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isGuestToken=void 0;const tslib_1=require("tslib"),jwt_1=tslib_1.__importDefault(require("./jwt"));function isGuestToken(accessToken){return(0,jwt_1.default)(accessToken).owner==null}exports.isGuestToken=isGuestToken;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseInputComponentProps } from '../typings/index';
3
2
  type Props = BaseInputComponentProps & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
4
3
  export declare function MetadataInput(props: Props): JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type Address as AddressType } from '@commercelayer/sdk';
3
2
  import { type AddressCardsTemplateChildren } from '../utils/AddressCardsTemplate';
4
3
  import type { DefaultChildrenType } from '../../typings/globals';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseSelectComponentProps } from '../../typings/index';
3
2
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
4
3
  type TCountryFieldName = 'billing_address_country_code' | 'shipping_address_country_code' | 'customer_address_country_code';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseInputComponentProps, type AddressInputName } from '../../typings/index';
3
2
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
4
3
  type Props = {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type AddressStateSelectName, type BaseSelectComponentProps } from '../../typings/index';
3
2
  type Props = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
4
3
  name: AddressStateSelectName;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children: DefaultChildrenType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children: DefaultChildrenType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children: DefaultChildrenType;
@@ -7,5 +6,8 @@ interface Props {
7
6
  */
8
7
  isGuest?: boolean;
9
8
  }
9
+ /**
10
+ * The CustomerContainer component manages the customer state.
11
+ */
10
12
  export declare function CustomerContainer(props: Props): JSX.Element;
11
13
  export default CustomerContainer;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useReducer,useMemo}from"react";import customerReducer,{customerInitialState,getCustomerAddresses,getCustomerOrders,getCustomerPaymentSources,setCustomerEmail,setCustomerErrors,deleteCustomerAddress,createCustomerAddress,saveCustomerUser,getCustomerPayments,getCustomerSubscriptions}from"../../reducers/CustomerReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";export function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=useReducer(customerReducer,customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded,withoutIncludes}=useContext(OrderContext),config=useContext(CommerceLayerContext);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]),useEffect(()=>{if(config.accessToken&&state.addresses==null&&!isGuest&&getCustomerAddresses({config,dispatch,isOrderAvailable:withoutIncludes!=null}),order?.available_customer_payment_sources&&!isGuest&&getCustomerPaymentSources({dispatch,order}),config.accessToken&&order==null&&include==null&&includeLoaded==null&&withoutIncludes===void 0&&!isGuest){async function getCustomerData(){await getCustomerOrders({config,dispatch}),await getCustomerSubscriptions({config,dispatch}),await getCustomerPayments({config,dispatch})}getCustomerData()}},[config.accessToken,order?.payment_source!=null,isGuest]);const contextValue=useMemo(()=>({isGuest,...state,saveCustomerUser:async customerEmail=>{await saveCustomerUser({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>{setCustomerErrors(errors,dispatch)},setCustomerEmail:customerEmail=>{setCustomerEmail(customerEmail,dispatch)},getCustomerPaymentSources:()=>{getCustomerPaymentSources({dispatch,order})},deleteCustomerAddress:async({customerAddressId})=>{await deleteCustomerAddress({customerAddressId,dispatch,config,addresses:state.addresses})},createCustomerAddress:async address=>{await createCustomerAddress({address,config,dispatch,state})},getCustomerOrders:async({pageNumber,pageSize})=>{await getCustomerOrders({config,dispatch,pageNumber,pageSize})}}),[state,isGuest]);return _jsx(CustomerContext.Provider,{value:contextValue,children})}export default CustomerContainer;
2
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useReducer,useMemo}from"react";import customerReducer,{customerInitialState,getCustomerAddresses,getCustomerOrders,getCustomerPaymentSources,setCustomerEmail,setCustomerErrors,deleteCustomerAddress,createCustomerAddress,saveCustomerUser,getCustomerPayments,getCustomerSubscriptions,getCustomerInfo}from"../../reducers/CustomerReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import{isGuestToken}from"../../utils/isGuestToken";export function CustomerContainer(props){const{children,isGuest}=props,[state,dispatch]=useReducer(customerReducer,customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded,withoutIncludes}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{if(config.accessToken){if(isGuest??isGuestToken(config.accessToken))return;include?.includes("available_customer_payment_sources.payment_source")?includeLoaded?.["available_customer_payment_sources.payment_source"]||addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}}):addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"})}},[config.accessToken,include?.length,Object.keys(includeLoaded??{}).length]),useEffect(()=>{if(config.accessToken){if(isGuest??isGuestToken(config.accessToken))return;if(state.customers==null&&getCustomerInfo({config,dispatch}),state.addresses==null&&getCustomerAddresses({config,dispatch,isOrderAvailable:withoutIncludes!=null}),order?.available_customer_payment_sources&&getCustomerPaymentSources({dispatch,order}),config.accessToken&&order==null&&include==null&&includeLoaded==null&&withoutIncludes===void 0){async function getCustomerData(){await getCustomerOrders({config,dispatch}),await getCustomerSubscriptions({config,dispatch}),await getCustomerPayments({config,dispatch})}getCustomerData()}}},[config.accessToken,order?.payment_source!=null,isGuest]);const contextValue=useMemo(()=>({isGuest,...state,saveCustomerUser:async customerEmail=>{await saveCustomerUser({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>{setCustomerErrors(errors,dispatch)},setCustomerEmail:customerEmail=>{setCustomerEmail(customerEmail,dispatch)},getCustomerPaymentSources:()=>{getCustomerPaymentSources({dispatch,order})},deleteCustomerAddress:async({customerAddressId})=>{await deleteCustomerAddress({customerAddressId,dispatch,config,addresses:state.addresses})},createCustomerAddress:async address=>{await createCustomerAddress({address,config,dispatch,state})},getCustomerOrders:async({pageNumber,pageSize})=>{await getCustomerOrders({config,dispatch,pageNumber,pageSize})}}),[state,isGuest]);return _jsx(CustomerContext.Provider,{value:contextValue,children})}export default CustomerContainer;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ConditionalElement } from '../../typings/index';
3
2
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
4
3
  type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['Customer']>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseInputComponentProps } from '../../typings/index';
3
2
  type Props = {
4
3
  name?: 'customer_email' | string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children?: DefaultChildrenType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface ChildrenProps extends Omit<Props, 'children'> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface ChildrenProps extends Omit<Props, 'children'> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { CodeErrorType } from '../../typings/errors';
3
2
  import { type ChildrenFunction } from '../../typings/index';
4
3
  export type TResourceError = 'addresses' | 'billing_address' | 'gift_cards' | 'gift_card_or_coupon_code' | 'line_items' | 'orders' | 'payment_methods' | 'prices' | 'shipments' | 'shipping_address' | 'customer_address' | 'sku_options' | 'variant' | 'in_stock_subscriptions';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseState } from '../../typings/index';
3
2
  import type { DefaultChildrenType } from '../../typings/globals';
4
3
  interface Props extends Omit<JSX.IntrinsicElements['form'], 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseSelectComponentProps } from '../../typings/index';
3
2
  type Props = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
4
3
  required?: boolean;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseInputComponentProps, type GiftCardInputName } from '../../typings/index';
3
2
  type Props = {
4
3
  name: GiftCardInputName;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  import type { CodeType } from '../../reducers/OrderReducer';
4
3
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { Order } from '@commercelayer/sdk';
3
2
  import type { DefaultChildrenType } from '../../typings/globals';
4
3
  interface Props extends Omit<JSX.IntrinsicElements['form'], 'onSubmit'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseInputComponentProps } from '../../typings/index';
3
2
  import { type OrderCodeType } from '../../reducers/OrderReducer';
4
3
  type Props = {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface Props extends Omit<JSX.IntrinsicElements['button'], 'children' | 'onClick'> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type TLineItem = 'gift_cards' | 'payment_methods' | 'promotions' | 'shipments' | 'skus' | 'bundles' | 'adjustments';
3
2
  interface Props {
4
3
  children: JSX.Element | JSX.Element[];
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent, type BasePriceType } from '../../typings/index';
3
2
  type Props = BaseAmountComponent & {
4
3
  type?: BasePriceType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type LineItem } from '@commercelayer/sdk';
3
2
  import { type ChildrenFunction } from '../../typings/index';
4
3
  export interface TLineItemCode extends Omit<Props, 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ConditionalElement } from '../../typings/index';
3
2
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
4
3
  type LineItemFieldChildrenProps = TGenericChildrenProps<TResources['LineItem']>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type LineItem } from '@commercelayer/sdk';
3
2
  import type { ChildrenFunction } from '../../typings/index';
4
3
  import { type TLineItem } from './LineItem';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { LineItem } from '@commercelayer/sdk';
3
2
  import { type ChildrenFunction } from '../../typings/index';
4
3
  export interface TLineItemName extends Omit<Props, 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children: DefaultChildrenType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type TypeAccepted } from '../../utils/getLineItemsCount';
3
2
  import { type ChildrenFunction } from '../../typings/index';
4
3
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface ChildrenProps extends Omit<Props, 'children'> {
4
3
  quantity: number;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function AdjustmentAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default AdjustmentAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface ChildrenProps extends Omit<Props, 'children'> {
4
3
  checkoutUrl: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function DiscountAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default DiscountAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function GiftCardAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default GiftCardAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseMetadataObject } from '../../typings/index';
3
2
  import type { OrderCreate, Order } from '@commercelayer/sdk';
4
3
  import type { DefaultChildrenType } from '../../typings/globals';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type TOrderList, type InitialOrderListContext, type OrderListContent } from '../../context/OrderListChildrenContext';
3
2
  import { type ColumnDef, type SortingState } from '@tanstack/react-table';
4
3
  import type { DefaultChildrenType, TRange } from '../../typings/globals';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type OrderListPaginationContext as TOrderListPaginationContext } from '../../context/OrderListPaginationContext';
3
2
  import { type ChildrenFunction } from '../../typings/index';
4
3
  interface PaginationButton extends Omit<JSX.IntrinsicElements['button'], 'children' | 'disabled'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  type TAsComponent = keyof Pick<JSX.IntrinsicElements, 'p' | 'span' | 'div'>;
4
3
  type ChildrenProps<A extends TAsComponent> = Omit<Props<A>, 'children'> & {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type TOrderList, type OrderListContent, type TableAccessor } from '../../context/OrderListChildrenContext';
3
2
  import { type Row } from '@tanstack/react-table';
4
3
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseFieldProps } from '../utils/BaseField';
3
2
  type Props = Omit<BaseFieldProps, 'attribute'>;
4
3
  export declare function OrderNumber(props: Props): JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function PaymentMethodAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default PaymentMethodAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseInputProps } from '../utils/BaseInput';
3
2
  export declare function PrivacyAndTermsCheckbox(props: Partial<BaseInputProps>): JSX.Element;
4
3
  export default PrivacyAndTermsCheckbox;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function ShippingAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default ShippingAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function SubTotalAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default SubTotalAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function TaxesAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default TaxesAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type BaseAmountComponent } from '../../typings/index';
3
2
  export declare function TotalAmount(props: BaseAmountComponent): JSX.Element;
4
3
  export default TotalAmount;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ConditionalElement } from '../../typings/index';
3
2
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
4
3
  type ParcelFieldChildrenProps = TGenericChildrenProps<TResources['Parcel']>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { DefaultChildrenType } from '../../typings/globals';
3
2
  interface Props {
4
3
  children: DefaultChildrenType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ConditionalElement } from '../../typings/index';
3
2
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
4
3
  type ParcelLineItemFieldChildrenProps = TGenericChildrenProps<TResources['ParcelLineItem']>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type ChildrenFunction } from '../../typings/index';
3
2
  import type { Parcel } from '@commercelayer/sdk';
4
3
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  interface Props {
3
2
  children: JSX.Element | JSX.Element[];
4
3
  filterBy?: string[];