@dropins/storefront-checkout 2.0.1 → 2.1.0-beta2

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 (97) hide show
  1. package/api/fragments.d.ts +4 -1
  2. package/{lib/network-error.d.ts → api/getNegotiableQuote/getNegotiableQuote.d.ts} +7 -7
  3. package/{signals/ServerErrorSignal.d.ts → api/getNegotiableQuote/graphql/getNegotiableQuote.graphql.d.ts} +3 -3
  4. package/{errors → api/getNegotiableQuote/graphql}/index.d.ts +2 -2
  5. package/{signals → api/getNegotiableQuote}/index.d.ts +2 -2
  6. package/api/graphql/CartAddressFragment.graphql.d.ts +1 -1
  7. package/api/graphql/NegotiableQuoteAddressFragment.graphql.d.ts +19 -0
  8. package/api/graphql/NegotiableQuoteFragment.graphql.d.ts +18 -0
  9. package/api/graphql/{CartPaymentMethodFragment.graphql.d.ts → PaymentMethodFragment.graphql.d.ts} +1 -1
  10. package/api/graphql/ShippingMethodFragment.graphql.d.ts +19 -0
  11. package/api/index.d.ts +5 -1
  12. package/api/setNegotiableQuoteBillingAddress/graphql/index.d.ts +18 -0
  13. package/api/setNegotiableQuoteBillingAddress/graphql/setNegotiableQuoteBillingAddress.graphql.d.ts +18 -0
  14. package/api/setNegotiableQuoteBillingAddress/index.d.ts +18 -0
  15. package/api/setNegotiableQuoteBillingAddress/setNegotiableQuoteBillingAddress.d.ts +6 -0
  16. package/api/setNegotiableQuotePaymentMethod/graphql/index.d.ts +18 -0
  17. package/api/setNegotiableQuotePaymentMethod/graphql/setNegotiableQuotePaymentMethod.graphql.d.ts +18 -0
  18. package/api/setNegotiableQuotePaymentMethod/index.d.ts +18 -0
  19. package/api/setNegotiableQuotePaymentMethod/setNegotiableQuotePaymentMethod.d.ts +6 -0
  20. package/api/setNegotiableQuoteShippingAddress/graphql/index.d.ts +18 -0
  21. package/api/setNegotiableQuoteShippingAddress/graphql/setNegotiableQuoteShippingAddress.graphql.d.ts +18 -0
  22. package/api/setNegotiableQuoteShippingAddress/index.d.ts +18 -0
  23. package/api/setNegotiableQuoteShippingAddress/setNegotiableQuoteShippingAddress.d.ts +6 -0
  24. package/api/setNegotiableQuoteShippingMethods/graphql/index.d.ts +18 -0
  25. package/api/setNegotiableQuoteShippingMethods/graphql/setNegotiableQuoteShippingMethods.graphql.d.ts +18 -0
  26. package/api/setNegotiableQuoteShippingMethods/index.d.ts +18 -0
  27. package/api/setNegotiableQuoteShippingMethods/setNegotiableQuoteShippingMethods.d.ts +18 -0
  28. package/api.js +78 -7
  29. package/api.js.map +1 -1
  30. package/chunks/checkout.js.map +1 -1
  31. package/chunks/fetch-graphql.js +14 -0
  32. package/chunks/fetch-graphql.js.map +1 -0
  33. package/chunks/setBillingAddress.js +2 -2
  34. package/chunks/setBillingAddress.js.map +1 -1
  35. package/chunks/setGuestEmailOnCart.js +4 -4
  36. package/chunks/setGuestEmailOnCart.js.map +1 -1
  37. package/chunks/setPaymentMethod.js +2 -2
  38. package/chunks/setPaymentMethod.js.map +1 -1
  39. package/chunks/setShippingMethods.js +3 -3
  40. package/chunks/setShippingMethods.js.map +1 -1
  41. package/chunks/synchronizeCheckout.js +3 -3
  42. package/chunks/synchronizeCheckout.js.map +1 -1
  43. package/containers/BillToShippingAddress.js +1 -1
  44. package/containers/BillToShippingAddress.js.map +1 -1
  45. package/containers/EstimateShipping.js +1 -1
  46. package/containers/EstimateShipping.js.map +1 -1
  47. package/containers/LoginForm.js +1 -1
  48. package/containers/LoginForm.js.map +1 -1
  49. package/containers/OutOfStock.js +1 -1
  50. package/containers/OutOfStock.js.map +1 -1
  51. package/containers/PaymentMethods.js +1 -1
  52. package/containers/PaymentMethods.js.map +1 -1
  53. package/containers/PlaceOrder.js +1 -1
  54. package/containers/PlaceOrder.js.map +1 -1
  55. package/containers/ServerError.js +1 -1
  56. package/containers/ServerError.js.map +1 -1
  57. package/containers/ShippingMethods.js +1 -1
  58. package/containers/ShippingMethods.js.map +1 -1
  59. package/containers/TermsAndConditions.js +1 -1
  60. package/containers/TermsAndConditions.js.map +1 -1
  61. package/data/models/address.d.ts +5 -8
  62. package/data/models/api.d.ts +3 -3
  63. package/data/models/cart.d.ts +14 -7
  64. package/data/models/checkout.d.ts +14 -0
  65. package/data/models/country.d.ts +1 -1
  66. package/data/models/index.d.ts +2 -1
  67. package/data/models/{price.d.ts → money.d.ts} +2 -2
  68. package/data/models/quote.d.ts +15 -0
  69. package/data/models/shipping-estimate.d.ts +4 -4
  70. package/data/models/shipping-method.d.ts +4 -4
  71. package/data/transforms/index.d.ts +6 -1
  72. package/data/transforms/{transform-address.d.ts → transform-cart-address.d.ts} +12 -13
  73. package/data/transforms/transform-cart.d.ts +1 -1
  74. package/data/transforms/transform-country.d.ts +8 -0
  75. package/data/transforms/transform-negotiable-quote.d.ts +7 -0
  76. package/data/transforms/transform-payment-methods.d.ts +1 -1
  77. package/data/transforms/transform-quote-address.d.ts +75 -0
  78. package/data/transforms/transform-region.d.ts +8 -0
  79. package/fragments.js +126 -43
  80. package/fragments.js.map +1 -1
  81. package/lib/enqueueRequest.d.ts +1 -0
  82. package/lib/errors/classifiers.d.ts +36 -0
  83. package/lib/errors/customErrors.d.ts +39 -0
  84. package/lib/errors/index.d.ts +20 -0
  85. package/lib/errors/mapErrorToCode.d.ts +4 -0
  86. package/lib/index.d.ts +1 -1
  87. package/lib/state.d.ts +1 -0
  88. package/package.json +1 -1
  89. package/render.js +1 -1
  90. package/render.js.map +1 -1
  91. package/tests/constants.d.ts +1 -0
  92. package/tests/fixtures/fragments/cart.d.ts +1 -2
  93. package/chunks/ServerErrorSignal.js +0 -4
  94. package/chunks/ServerErrorSignal.js.map +0 -1
  95. package/chunks/errors.js +0 -14
  96. package/chunks/errors.js.map +0 -1
  97. package/errors/errors.d.ts +0 -30
@@ -1 +1 @@
1
- {"version":3,"file":"synchronizeCheckout.js","sources":["/@dropins/storefront-checkout/src/api/authenticateCustomer/authenticateCustomer.ts","/@dropins/storefront-checkout/src/data/transforms/transform-shipping-methods.ts","/@dropins/storefront-checkout/src/data/transforms/transform-address.ts","/@dropins/storefront-checkout/src/data/transforms/transform-payment-methods.ts","/@dropins/storefront-checkout/src/data/transforms/transform-cart.ts","/@dropins/storefront-checkout/src/api/getCart/graphql/getCart.graphql.ts","/@dropins/storefront-checkout/src/api/getCart/getCart.ts","/@dropins/storefront-checkout/src/api/initialize/listeners.ts","/@dropins/storefront-checkout/src/api/initialize/initialize.ts","/@dropins/storefront-checkout/src/api/initializeCheckout/initializeCheckout.ts","/@dropins/storefront-checkout/src/api/resetCheckout/resetCheckout.ts","/@dropins/storefront-checkout/src/api/synchronizeCheckout/synchronizeCheckout.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { state } from '@/checkout/lib/state';\n\nexport const authenticateCustomer = async (authenticated = false) => {\n state.authenticated = authenticated;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { ShippingMethod } from '@/checkout/data/models/shipping-method';\nimport { GetCartQuery } from '@/checkout/__generated__/types';\n\ntype Cart = NonNullable<GetCartQuery['cart']>;\ntype ShippingAddresses = Cart['shipping_addresses'];\ntype ShippingAddress = NonNullable<NonNullable<ShippingAddresses>[number]>;\ntype AvailableShippingMethods = ShippingAddress['available_shipping_methods'];\ntype AvailableShippingMethod = NonNullable<AvailableShippingMethods>[number];\ntype SelectedShippingMethod = ShippingAddress['selected_shipping_method'];\n\ntype FilteredShippingMethod = Omit<\n NonNullable<AvailableShippingMethod>,\n | 'method_code'\n | 'method_title'\n | 'amount'\n | 'price_excl_tax'\n | 'price_incl_tax'\n> & {\n method_code: string;\n method_title: string;\n amount: {\n value: number;\n currency: string;\n };\n price_excl_tax: {\n value: number;\n currency: string;\n };\n price_incl_tax: {\n value: number;\n currency: string;\n };\n};\n\nconst byPrice = (a: ShippingMethod, b: ShippingMethod) =>\n a.amount.value - b.amount.value;\n\nexport const isNullish = (value: any): boolean =>\n value === null || value === undefined;\n\nconst isValid = (method: AvailableShippingMethod | SelectedShippingMethod) => {\n if (!method) return false;\n if (!method.method_code || !method.method_title) return false;\n if (isNullish(method.amount.value) || !method.amount.currency) return false;\n return true;\n};\n\nconst buildShippingMethod = (data: FilteredShippingMethod): ShippingMethod => {\n return {\n amount: {\n value: data.amount.value,\n currency: data.amount.currency,\n },\n title: data.method_title,\n code: data.method_code,\n carrier: {\n code: data.carrier_code,\n title: data.carrier_title,\n },\n value: `${data.carrier_code} - ${data.method_code}`,\n ...(data.price_excl_tax && {\n amountExclTax: {\n value: data.price_excl_tax.value,\n currency: data.price_excl_tax.currency,\n },\n }),\n ...(data.price_incl_tax && {\n amountInclTax: {\n value: data.price_incl_tax.value,\n currency: data.price_incl_tax.currency,\n },\n }),\n };\n};\n\nexport const transformSelectedShippingMethod = (\n data: SelectedShippingMethod\n): ShippingMethod | undefined => {\n if (!isValid(data)) return;\n return buildShippingMethod(data as FilteredShippingMethod);\n};\n\nexport const transformAvailableShippingMethod = (\n data: AvailableShippingMethod\n): ShippingMethod | undefined => {\n if (!isValid(data)) return;\n return buildShippingMethod(data as FilteredShippingMethod);\n};\n\nexport const transformShippingMethods = (\n data: AvailableShippingMethods\n): ShippingMethod[] => {\n if (!data) return [];\n\n return data\n .filter(isValid)\n .map((method) => buildShippingMethod(method as FilteredShippingMethod))\n .sort(byPrice);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { CartAddressInput, GetCartQuery } from '@/checkout/__generated__/types';\nimport {\n Address as AddressModel,\n Country as CountryModel,\n CustomAttribute as CustomAttributeModel,\n Region as RegionModel,\n ShippingAddress as ShippingAddressModel,\n CartAddress as CartAddressModel,\n} from '@/checkout/data/models';\nimport {\n transformSelectedShippingMethod,\n transformShippingMethods,\n} from '@/checkout/data/transforms/transform-shipping-methods';\n\ntype ShippingAddresses = NonNullable<\n GetCartQuery['cart']\n>['shipping_addresses'];\ntype ShippingAddress = ShippingAddresses[0];\ntype NonNullableShippingAddress = NonNullable<ShippingAddress>;\n\ntype AddressRegion = NonNullableShippingAddress['region'];\ntype NonNullableAddressRegion = NonNullable<AddressRegion>;\ntype ValidatedAddressRegion = {\n code: NonNullable<NonNullableAddressRegion['code']>;\n label: NonNullable<NonNullableAddressRegion['label']>;\n region_id: NonNullableAddressRegion['region_id'];\n};\n\ntype AddressCountry = NonNullableShippingAddress['country'];\ntype NonNullableAddressCountry = NonNullable<AddressCountry>;\ntype ValidatedAddressCountry = {\n code: NonNullable<NonNullableAddressCountry['code']>;\n label: NonNullable<NonNullableAddressCountry['label']>;\n};\n\ntype BillingAddress = NonNullable<GetCartQuery['cart']>['billing_address'];\ntype NonNullableBillingAddress = NonNullable<BillingAddress>;\n\ntype CustomAttributes =\n | NonNullableShippingAddress['custom_attributes']\n | NonNullableBillingAddress['custom_attributes'];\n\nconst isValidAddressRegion = (region: AddressRegion): boolean => {\n if (!region) return false;\n return !!region.code && !!region.label;\n};\n\nconst transformAddressRegion = (\n data: AddressRegion\n): RegionModel | undefined => {\n if (!isValidAddressRegion(data)) return;\n const { code, label, region_id } = data as ValidatedAddressRegion;\n if (!region_id) return { code, name: label };\n return { code, name: label, id: region_id };\n};\n\nconst transformAddressCountry = (data: AddressCountry): CountryModel => {\n const { code, label } = data as ValidatedAddressCountry;\n return { value: code, label };\n};\n\nconst isValidCustomAttribute = (attribute: any): boolean => {\n if (!attribute) return false;\n return 'code' in attribute && 'value' in attribute;\n};\n\nexport const transformCustomAttributes = (\n data: CustomAttributes\n): CustomAttributeModel[] => {\n return data.filter(isValidCustomAttribute).map((attribute) => {\n const { code, value } = attribute as { code: string; value: string };\n return { code, value };\n });\n};\n\nconst buildBaseAddress = (\n data: NonNullableShippingAddress | NonNullableBillingAddress\n): AddressModel => {\n const street = data.street.filter(Boolean) as string[];\n\n return {\n id: data?.id || undefined,\n city: data.city,\n company: data.company || undefined,\n country: transformAddressCountry(data.country),\n customAttributes: transformCustomAttributes(data.custom_attributes),\n firstName: data.firstname,\n lastName: data.lastname,\n postCode: data.postcode || undefined,\n region: transformAddressRegion(data.region),\n street,\n telephone: data.telephone || undefined,\n vatId: data.vat_id || undefined,\n prefix: data.prefix || undefined,\n suffix: data.suffix || undefined,\n middleName: data.middlename || undefined,\n fax: data.fax || undefined,\n };\n};\n\nconst transformBillingAddress = (\n data: BillingAddress\n): AddressModel | undefined => {\n if (!data) return;\n return buildBaseAddress(data);\n};\n\nconst transformShippingAddresses = (\n data: ShippingAddresses\n): ShippingAddressModel[] | undefined => {\n return data\n .filter((address) => !!address)\n .map((address) => {\n const {\n available_shipping_methods,\n selected_shipping_method,\n same_as_billing,\n ...baseData\n } = address as NonNullableShippingAddress;\n\n return {\n ...buildBaseAddress(baseData as NonNullableShippingAddress),\n availableShippingMethods: transformShippingMethods(\n available_shipping_methods\n ),\n selectedShippingMethod: transformSelectedShippingMethod(\n selected_shipping_method\n ),\n sameAsBilling: same_as_billing,\n };\n });\n};\n\nconst transformCartAddressModelToInput = (\n address: CartAddressModel\n): CartAddressInput => {\n return {\n city: address.city,\n company: address.company,\n country_code: address.countryCode,\n custom_attributes: address.customAttributes.map((attribute) => ({\n attribute_code: attribute.code,\n value: attribute.value,\n })),\n firstname: address.firstName,\n lastname: address.lastName,\n postcode: address.postcode,\n region: address.region,\n region_id: address.regionId,\n save_in_address_book: address.saveInAddressBook ?? true,\n street: address.street,\n telephone: address.telephone,\n vat_id: address.vatId,\n prefix: address.prefix,\n suffix: address.suffix,\n middlename: address.middleName,\n fax: address.fax,\n };\n};\n\nexport {\n BillingAddress,\n ShippingAddress,\n transformCartAddressModelToInput,\n transformBillingAddress,\n transformShippingAddresses,\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { GetCartQuery } from '@/checkout/__generated__/types';\nimport { PaymentMethod } from '@/checkout/data/models/payment-method';\n\ntype SelectedPaymentMethod = NonNullable<\n GetCartQuery['cart']\n>['selected_payment_method'];\n\ntype AvailablePaymentMethods = NonNullable<\n GetCartQuery['cart']\n>['available_payment_methods'];\n\ntype AvailablePaymentMethod = NonNullable<AvailablePaymentMethods>[number];\n\ntype NonNullabePaymentMethod = NonNullable<AvailablePaymentMethod>;\n\nconst transformSelectedPaymentMethod = (\n data: SelectedPaymentMethod\n): PaymentMethod | undefined => {\n if (!data) return;\n return { code: data.code, title: data.title };\n};\n\nconst transformAvailablePaymentMethods = (\n data: AvailablePaymentMethods\n): PaymentMethod[] | undefined => {\n if (!data) return;\n\n return data\n .filter((method) => !!method)\n .map((method) => {\n const { code, title } = method as NonNullabePaymentMethod;\n return { code, title };\n });\n};\n\nexport { transformAvailablePaymentMethods, transformSelectedPaymentMethod };\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { GetCartQuery } from '@/checkout/__generated__/types';\nimport { config } from '@/checkout/api';\nimport { Cart as CartModel } from '@/checkout/data/models';\nimport {\n transformAvailablePaymentMethods,\n transformSelectedPaymentMethod,\n} from '@/checkout/data/transforms/transform-payment-methods';\nimport { merge } from '@adobe-commerce/elsie/lib';\n\nimport {\n transformBillingAddress,\n transformShippingAddresses,\n} from '@/checkout/data/transforms/transform-address';\nimport { state } from '@/checkout/lib/state';\n\ntype Cart = GetCartQuery['cart'];\n\nconst transformCart = (data: Cart): CartModel | undefined => {\n if (!data) return;\n\n const model = {\n availablePaymentMethods: transformAvailablePaymentMethods(\n data.available_payment_methods\n ),\n billingAddress: transformBillingAddress(data.billing_address),\n email: data.email ?? undefined,\n id: data.id,\n isEmpty: data.total_quantity === 0,\n isVirtual: data.is_virtual,\n selectedPaymentMethod: transformSelectedPaymentMethod(\n data.selected_payment_method\n ),\n shippingAddresses: transformShippingAddresses(data.shipping_addresses),\n isGuest: !state.authenticated,\n };\n\n // Extend the model merging custom transformer, if provided\n return merge(\n model, // default transformer\n config.getConfig().models?.CartModel?.transformer?.(data) // custom transformer\n );\n};\n\nexport { Cart, transformCart };\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { CHECKOUT_DATA_FRAGMENT } from '@/checkout/api/graphql/CheckoutDataFragment.graphql';\n\nexport const getCartQuery = /* GraphQL */ `\n query getCart($cartId: String!) {\n cart(cart_id: $cartId) {\n ...CHECKOUT_DATA_FRAGMENT\n }\n }\n\n ${CHECKOUT_DATA_FRAGMENT}\n`;\n\nexport const getCustomerCartQuery = /* GraphQL */ `\n query getCustomerCart {\n cart: customerCart {\n ...CHECKOUT_DATA_FRAGMENT\n }\n }\n\n ${CHECKOUT_DATA_FRAGMENT}\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n getCartQuery,\n getCustomerCartQuery,\n} from '@/checkout/api/getCart/graphql';\nimport { transformCart } from '@/checkout/data/transforms';\nimport { MissingCart } from '@/checkout/errors';\nimport { dispatchApiCall } from '@/checkout/lib/dispatchApiCall';\nimport { state } from '@/checkout/lib/state';\n\nexport const getCart = async () => {\n const cartId = state.cartId;\n const isGuest = state.authenticated === false;\n const query = isGuest ? getCartQuery : getCustomerCartQuery;\n const variables = isGuest ? { cartId } : {};\n\n if (isGuest && !cartId) throw new MissingCart();\n\n return await dispatchApiCall({\n type: 'query',\n query,\n options: { method: 'POST', cache: 'no-cache', variables },\n path: 'cart',\n transformer: transformCart,\n });\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n authenticateCustomer,\n initializeCheckout,\n resetCheckout,\n synchronizeCheckout,\n} from '@/checkout/api';\nimport { events } from '@adobe-commerce/event-bus';\n\nexport const addCheckoutEventListeners = () => [\n events.on('authenticated', authenticateCustomer, { eager: true }),\n events.on('cart/initialized', initializeCheckout, { eager: true }),\n events.on('cart/reset', resetCheckout),\n events.on('cart/updated', synchronizeCheckout),\n];\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { addCheckoutEventListeners } from '@/checkout/api/initialize/listeners';\nimport {\n Cart as CartModel,\n Customer as CustomerModel,\n} from '@/checkout/data/models';\n\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { Initializer, Model } from '@adobe-commerce/elsie/lib';\n\nexport type ConfigProps = {\n langDefinitions?: Lang;\n models?: {\n CartModel?: Model<CartModel>;\n CustomerModel?: Model<CustomerModel>;\n };\n};\n\nexport const initialize = new Initializer<ConfigProps>({\n init: async (_config) => {\n const config = { ..._config };\n initialize.config.setConfig(config);\n },\n listeners: addCheckoutEventListeners,\n});\n\nexport const config = initialize.config;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getCart, getStoreConfig, synchronizeCheckout } from '@/checkout/api';\nimport { state } from '@/checkout/lib/state';\nimport { Cart, events } from '@adobe-commerce/event-bus';\n\nexport const initializeCheckout = async (cart: Cart | null): Promise<void> => {\n if (state.initialized) return synchronizeCheckout(cart);\n\n if (!state.config) {\n state.config = await getStoreConfig();\n }\n\n const cartId = cart ? cart.id : null;\n state.cartId = cartId;\n\n const initialData = cartId ? await getCart() : null;\n state.initialized = true;\n\n events.emit('checkout/initialized', initialData || null);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { state } from '@/checkout/lib/state';\nimport { events } from '@adobe-commerce/event-bus';\n\nexport const resetCheckout = () => {\n state.cartId = null;\n events.emit('checkout/updated', null);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getCart, initializeCheckout } from '@/checkout/api';\nimport { state } from '@/checkout/lib/state';\nimport { Cart, events } from '@adobe-commerce/event-bus';\n\nexport const synchronizeCheckout = async (cart: Cart | null) => {\n if (!state.initialized) return initializeCheckout(cart);\n const cartId = cart ? cart.id : null;\n state.cartId = cartId;\n const data = cartId ? await getCart() : null;\n events.emit('checkout/updated', data || null);\n};\n"],"names":["authenticateCustomer","authenticated","state","byPrice","a","b","isNullish","value","isValid","method","buildShippingMethod","data","transformSelectedShippingMethod","transformShippingMethods","isValidAddressRegion","region","transformAddressRegion","code","label","region_id","transformAddressCountry","isValidCustomAttribute","attribute","transformCustomAttributes","buildBaseAddress","street","transformBillingAddress","transformShippingAddresses","address","available_shipping_methods","selected_shipping_method","same_as_billing","baseData","transformCartAddressModelToInput","transformSelectedPaymentMethod","transformAvailablePaymentMethods","title","transformCart","model","merge","_c","_b","_a","config","getCartQuery","CHECKOUT_DATA_FRAGMENT","getCustomerCartQuery","getCart","cartId","isGuest","query","variables","MissingCart","dispatchApiCall","addCheckoutEventListeners","events","initializeCheckout","resetCheckout","synchronizeCheckout","initialize","Initializer","_config","cart","getStoreConfig","initialData"],"mappings":"kOAmBa,MAAAA,EAAuB,MAAOC,EAAgB,KAAU,CACnEC,EAAM,cAAgBD,CACxB,EC8BME,EAAU,CAACC,EAAmBC,IAClCD,EAAE,OAAO,MAAQC,EAAE,OAAO,MAEfC,EAAaC,GACxBA,GAAU,KAENC,EAAWC,GACX,GAACA,GACD,CAACA,EAAO,aAAe,CAACA,EAAO,cAC/BH,EAAUG,EAAO,OAAO,KAAK,GAAK,CAACA,EAAO,OAAO,UAIjDC,EAAuBC,IACpB,CACL,OAAQ,CACN,MAAOA,EAAK,OAAO,MACnB,SAAUA,EAAK,OAAO,QACxB,EACA,MAAOA,EAAK,aACZ,KAAMA,EAAK,YACX,QAAS,CACP,KAAMA,EAAK,aACX,MAAOA,EAAK,aACd,EACA,MAAO,GAAGA,EAAK,YA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,EACxD,KAAM,OACN,YAAad,CAAA,CACd,CACH,EChBaiB,EAA4B,IAAM,CAC7CC,EAAO,GAAG,gBAAiBvD,EAAsB,CAAE,MAAO,GAAM,EAChEuD,EAAO,GAAG,mBAAoBC,EAAoB,CAAE,MAAO,GAAM,EACjED,EAAO,GAAG,aAAcE,CAAa,EACrCF,EAAO,GAAG,eAAgBG,CAAmB,CAC/C,ECIaC,EAAa,IAAIC,EAAyB,CACrD,KAAM,MAAOC,GAAY,CACjBlB,MAAAA,EAAS,CAAE,GAAGkB,CAAQ,EACjBF,EAAA,OAAO,UAAUhB,CAAM,CACpC,EACA,UAAWW,CACb,CAAC,EAEYX,EAASgB,EAAW,OCrBpBH,EAAqB,MAAOM,GAAqC,CAC5E,GAAI5D,EAAM,YAAoB,OAAAwD,EAAoBI,CAAI,EAEjD5D,EAAM,SACHA,EAAA,OAAS,MAAM6D,EAAe,GAGhC,MAAAf,EAASc,EAAOA,EAAK,GAAK,KAChC5D,EAAM,OAAS8C,EAEf,MAAMgB,EAAchB,EAAS,MAAMD,EAAY,EAAA,KAC/C7C,EAAM,YAAc,GAEbqD,EAAA,KAAK,uBAAwBS,GAAe,IAAI,CACzD,ECfaP,EAAgB,IAAM,CACjCvD,EAAM,OAAS,KACRqD,EAAA,KAAK,mBAAoB,IAAI,CACtC,ECFaG,EAAsB,MAAOI,GAAsB,CAC9D,GAAI,CAAC5D,EAAM,YAAa,OAAOsD,EAAmBM,CAAI,EAChD,MAAAd,EAASc,EAAOA,EAAK,GAAK,KAChC5D,EAAM,OAAS8C,EACf,MAAMrC,EAAOqC,EAAS,MAAMD,EAAY,EAAA,KACjCQ,EAAA,KAAK,mBAAoB5C,GAAQ,IAAI,CAC9C"}
1
+ {"version":3,"file":"synchronizeCheckout.js","sources":["/@dropins/storefront-checkout/src/api/authenticateCustomer/authenticateCustomer.ts","/@dropins/storefront-checkout/src/data/transforms/transform-payment-methods.ts","/@dropins/storefront-checkout/src/data/transforms/transform-cart-address.ts","/@dropins/storefront-checkout/src/data/transforms/transform-cart.ts","/@dropins/storefront-checkout/src/data/transforms/transform-country.ts","/@dropins/storefront-checkout/src/data/transforms/transform-region.ts","/@dropins/storefront-checkout/src/data/transforms/transform-shipping-methods.ts","/@dropins/storefront-checkout/src/api/getCart/graphql/getCart.graphql.ts","/@dropins/storefront-checkout/src/api/getCart/getCart.ts","/@dropins/storefront-checkout/src/api/initialize/listeners.ts","/@dropins/storefront-checkout/src/api/initialize/initialize.ts","/@dropins/storefront-checkout/src/api/initializeCheckout/initializeCheckout.ts","/@dropins/storefront-checkout/src/api/resetCheckout/resetCheckout.ts","/@dropins/storefront-checkout/src/api/synchronizeCheckout/synchronizeCheckout.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { state } from '@/checkout/lib/state';\n\nexport const authenticateCustomer = async (authenticated = false) => {\n state.authenticated = authenticated;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { PaymentMethod } from '@/checkout/data/models/payment-method';\nimport { GetCartQuery } from '@/checkout/__generated__/types';\n\ntype SelectedPaymentMethod = NonNullable<\n GetCartQuery['cart']\n>['selected_payment_method'];\n\ntype AvailablePaymentMethods = NonNullable<\n GetCartQuery['cart']\n>['available_payment_methods'];\n\ntype AvailablePaymentMethod = NonNullable<AvailablePaymentMethods>[number];\n\ntype NonNullabePaymentMethod = NonNullable<AvailablePaymentMethod>;\n\nconst transformSelectedPaymentMethod = (\n data: SelectedPaymentMethod\n): PaymentMethod | undefined => {\n if (!data) return;\n return { code: data.code, title: data.title };\n};\n\nconst transformAvailablePaymentMethods = (\n data: AvailablePaymentMethods\n): PaymentMethod[] | undefined => {\n if (!data) return;\n\n return data\n .filter((method) => !!method)\n .map((method) => {\n const { code, title } = method as NonNullabePaymentMethod;\n return { code, title };\n });\n};\n\nexport { transformAvailablePaymentMethods, transformSelectedPaymentMethod };\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n CartAddress as CartAddressModel,\n CartAddressInput as CartAddressInputModel,\n CartShippingAddress as CartShippingAddressModel,\n CustomAttribute as CustomAttributeModel,\n} from '@/checkout/data/models';\n\nimport {\n transformAddressCountry,\n transformAddressRegion,\n transformSelectedShippingMethod,\n transformShippingMethods,\n} from '@/checkout/data/transforms';\n\nimport { CartAddressInput, GetCartQuery } from '@/checkout/__generated__/types';\n\ntype ShippingAddresses = NonNullable<\n GetCartQuery['cart']\n>['shipping_addresses'];\ntype CartShippingAddress = ShippingAddresses[0];\ntype NonNullableShippingAddress = NonNullable<CartShippingAddress>;\n\ntype CartBillingAddress = NonNullable<GetCartQuery['cart']>['billing_address'];\ntype NonNullableBillingAddress = NonNullable<CartBillingAddress>;\n\ntype CustomAttributes =\n | NonNullableShippingAddress['custom_attributes']\n | NonNullableBillingAddress['custom_attributes'];\n\nconst isValidCustomAttribute = (attribute: any): boolean => {\n if (!attribute) return false;\n return 'code' in attribute && 'value' in attribute;\n};\n\nexport const transformCustomAttributes = (\n data: CustomAttributes\n): CustomAttributeModel[] => {\n return data.filter(isValidCustomAttribute).map((attribute) => {\n const { code, value } = attribute as { code: string; value: string };\n return { code, value };\n });\n};\n\nconst transformBaseAddress = (\n data: NonNullableShippingAddress | NonNullableBillingAddress\n): CartAddressModel => {\n const street = data.street.filter(Boolean) as string[];\n\n return {\n id: data?.id || undefined,\n city: data.city,\n company: data.company || undefined,\n country: transformAddressCountry(data.country),\n customAttributes: transformCustomAttributes(data.custom_attributes),\n firstName: data.firstname,\n lastName: data.lastname,\n postCode: data.postcode || undefined,\n region: transformAddressRegion(data.region),\n street,\n telephone: data.telephone || undefined,\n vatId: data.vat_id || undefined,\n prefix: data.prefix || undefined,\n suffix: data.suffix || undefined,\n middleName: data.middlename || undefined,\n fax: data.fax || undefined,\n };\n};\n\nconst transformCartBillingAddress = (\n data: CartBillingAddress\n): CartAddressModel | undefined => {\n if (!data) return;\n return transformBaseAddress(data);\n};\n\nconst transformCartShippingAddress = (\n data: ShippingAddresses\n): CartShippingAddressModel[] => {\n return data\n .filter((address) => !!address)\n .map((address) => {\n const {\n available_shipping_methods,\n selected_shipping_method,\n same_as_billing,\n ...baseData\n } = address as NonNullableShippingAddress;\n\n return {\n ...transformBaseAddress(baseData as NonNullableShippingAddress),\n availableShippingMethods: transformShippingMethods(\n available_shipping_methods\n ),\n selectedShippingMethod: transformSelectedShippingMethod(\n selected_shipping_method\n ),\n sameAsBilling: same_as_billing,\n };\n });\n};\n\nconst transformCartAddressInput = (\n address: CartAddressInputModel\n): CartAddressInput => {\n return {\n city: address.city,\n company: address.company,\n country_code: address.countryCode,\n custom_attributes: address.customAttributes.map((attribute) => ({\n attribute_code: attribute.code,\n value: attribute.value,\n })),\n firstname: address.firstName,\n lastname: address.lastName,\n postcode: address.postcode,\n region: address.region,\n region_id: address.regionId,\n save_in_address_book: address.saveInAddressBook ?? true,\n street: address.street,\n telephone: address.telephone,\n vat_id: address.vatId,\n prefix: address.prefix,\n suffix: address.suffix,\n middlename: address.middleName,\n fax: address.fax,\n };\n};\n\nexport {\n CartBillingAddress,\n CartShippingAddress,\n transformCartAddressInput,\n transformCartBillingAddress,\n transformCartShippingAddress,\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { config } from '@/checkout/api';\nimport { Cart as CartModel } from '@/checkout/data/models';\nimport {\n transformAvailablePaymentMethods,\n transformSelectedPaymentMethod,\n} from '@/checkout/data/transforms/transform-payment-methods';\nimport { GetCartQuery } from '@/checkout/__generated__/types';\nimport { merge } from '@adobe-commerce/elsie/lib';\n\nimport {\n transformCartBillingAddress,\n transformCartShippingAddress,\n} from '@/checkout/data/transforms/transform-cart-address';\nimport { state } from '@/checkout/lib/state';\n\ntype Cart = GetCartQuery['cart'];\n\nconst transformCart = (data: Cart): CartModel | undefined => {\n if (!data) return;\n\n const model = {\n availablePaymentMethods: transformAvailablePaymentMethods(\n data.available_payment_methods\n ),\n billingAddress: transformCartBillingAddress(data.billing_address),\n email: data.email ?? undefined,\n id: data.id,\n isEmpty: data.total_quantity === 0,\n isVirtual: data.is_virtual,\n selectedPaymentMethod: transformSelectedPaymentMethod(\n data.selected_payment_method\n ),\n shippingAddresses: transformCartShippingAddress(data.shipping_addresses),\n isGuest: !state.authenticated,\n };\n\n // Extend the model merging custom transformer, if provided\n return merge(\n model, // default transformer\n config.getConfig().models?.CartModel?.transformer?.(data) // custom transformer\n );\n};\n\nexport { Cart, transformCart };\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n CartAddressCountry,\n NegotiableQuoteAddressCountry,\n} from '@/checkout/__generated__/types';\n\nimport { Country as CountryModel } from '@/checkout/data/models';\n\ntype AddressCountry = CartAddressCountry | NegotiableQuoteAddressCountry;\ntype OptionalAddressCountry = AddressCountry | undefined | null;\n\nexport const transformAddressCountry = (\n data: OptionalAddressCountry\n): CountryModel => ({\n code: data?.code ?? '',\n label: data?.label ?? '',\n});\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Region as RegionModel } from '@/checkout/data/models';\nimport {\n CartAddressRegion,\n NegotiableQuoteAddressRegion,\n} from '@/checkout/__generated__/types';\n\ntype AddressRegion = CartAddressRegion | NegotiableQuoteAddressRegion;\ntype OptionalAddressRegion = AddressRegion | undefined | null;\n\nexport const transformAddressRegion = (\n data: OptionalAddressRegion\n): RegionModel | undefined => {\n if (!data?.code || !data?.label) return;\n return {\n code: data.code,\n name: data.label,\n id: data.region_id ?? undefined,\n };\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { ShippingMethod } from '@/checkout/data/models/shipping-method';\nimport { GetCartQuery } from '@/checkout/__generated__/types';\n\ntype Cart = NonNullable<GetCartQuery['cart']>;\ntype ShippingAddresses = Cart['shipping_addresses'];\ntype ShippingAddress = NonNullable<NonNullable<ShippingAddresses>[number]>;\ntype AvailableShippingMethods = ShippingAddress['available_shipping_methods'];\ntype AvailableShippingMethod = NonNullable<AvailableShippingMethods>[number];\ntype SelectedShippingMethod = ShippingAddress['selected_shipping_method'];\n\ntype FilteredShippingMethod = Omit<\n NonNullable<AvailableShippingMethod>,\n | 'method_code'\n | 'method_title'\n | 'amount'\n | 'price_excl_tax'\n | 'price_incl_tax'\n> & {\n method_code: string;\n method_title: string;\n amount: {\n value: number;\n currency: string;\n };\n price_excl_tax: {\n value: number;\n currency: string;\n };\n price_incl_tax: {\n value: number;\n currency: string;\n };\n};\n\nconst byPrice = (a: ShippingMethod, b: ShippingMethod) =>\n a.amount.value - b.amount.value;\n\nexport const isNullish = (value: any): boolean =>\n value === null || value === undefined;\n\nconst isValid = (method: AvailableShippingMethod | SelectedShippingMethod) => {\n if (!method) return false;\n if (!method.method_code || !method.method_title) return false;\n if (isNullish(method.amount.value) || !method.amount.currency) return false;\n return true;\n};\n\nconst buildShippingMethod = (data: FilteredShippingMethod): ShippingMethod => {\n return {\n amount: {\n value: data.amount.value,\n currency: data.amount.currency,\n },\n title: data.method_title,\n code: data.method_code,\n carrier: {\n code: data.carrier_code,\n title: data.carrier_title,\n },\n value: `${data.carrier_code} - ${data.method_code}`,\n ...(data.price_excl_tax && {\n amountExclTax: {\n value: data.price_excl_tax.value,\n currency: data.price_excl_tax.currency,\n },\n }),\n ...(data.price_incl_tax && {\n amountInclTax: {\n value: data.price_incl_tax.value,\n currency: data.price_incl_tax.currency,\n },\n }),\n };\n};\n\nexport const transformSelectedShippingMethod = (\n data: SelectedShippingMethod\n): ShippingMethod | undefined => {\n if (!isValid(data)) return;\n return buildShippingMethod(data as FilteredShippingMethod);\n};\n\nexport const transformAvailableShippingMethod = (\n data: AvailableShippingMethod\n): ShippingMethod | undefined => {\n if (!isValid(data)) return;\n return buildShippingMethod(data as FilteredShippingMethod);\n};\n\nexport const transformShippingMethods = (\n data: AvailableShippingMethods\n): ShippingMethod[] => {\n if (!data) return [];\n\n return data\n .filter(isValid)\n .map((method) => buildShippingMethod(method as FilteredShippingMethod))\n .sort(byPrice);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { CHECKOUT_DATA_FRAGMENT } from '@/checkout/api/graphql/CheckoutDataFragment.graphql';\n\nexport const getCartQuery = /* GraphQL */ `\n query getCart($cartId: String!) {\n cart(cart_id: $cartId) {\n ...CHECKOUT_DATA_FRAGMENT\n }\n }\n\n ${CHECKOUT_DATA_FRAGMENT}\n`;\n\nexport const getCustomerCartQuery = /* GraphQL */ `\n query getCustomerCart {\n cart: customerCart {\n ...CHECKOUT_DATA_FRAGMENT\n }\n }\n\n ${CHECKOUT_DATA_FRAGMENT}\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n getCartQuery,\n getCustomerCartQuery,\n} from '@/checkout/api/getCart/graphql';\nimport { transformCart } from '@/checkout/data/transforms';\nimport { dispatchApiCall } from '@/checkout/lib/dispatchApiCall';\nimport { MissingCart } from '@/checkout/lib/errors';\nimport { state } from '@/checkout/lib/state';\n\nexport const getCart = async () => {\n const cartId = state.cartId;\n const isGuest = state.authenticated === false;\n const query = isGuest ? getCartQuery : getCustomerCartQuery;\n const variables = isGuest ? { cartId } : {};\n\n if (isGuest && !cartId) throw new MissingCart();\n\n return await dispatchApiCall({\n type: 'query',\n query,\n options: { method: 'POST', cache: 'no-cache', variables },\n path: 'cart',\n transformer: transformCart,\n });\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n authenticateCustomer,\n initializeCheckout,\n resetCheckout,\n synchronizeCheckout,\n} from '@/checkout/api';\nimport { events } from '@adobe-commerce/event-bus';\n\nexport const addCheckoutEventListeners = () => [\n events.on('authenticated', authenticateCustomer, { eager: true }),\n events.on('cart/initialized', initializeCheckout, { eager: true }),\n events.on('cart/reset', resetCheckout),\n events.on('cart/updated', synchronizeCheckout),\n];\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { addCheckoutEventListeners } from '@/checkout/api/initialize/listeners';\nimport {\n Cart as CartModel,\n Customer as CustomerModel,\n} from '@/checkout/data/models';\n\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { Initializer, Model } from '@adobe-commerce/elsie/lib';\n\nexport type ConfigProps = {\n langDefinitions?: Lang;\n models?: {\n CartModel?: Model<CartModel>;\n CustomerModel?: Model<CustomerModel>;\n };\n};\n\nexport const initialize = new Initializer<ConfigProps>({\n init: async (_config) => {\n const config = { ..._config };\n initialize.config.setConfig(config);\n },\n listeners: addCheckoutEventListeners,\n});\n\nexport const config = initialize.config;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getCart, getStoreConfig, synchronizeCheckout } from '@/checkout/api';\nimport { state } from '@/checkout/lib/state';\nimport { Cart, events } from '@adobe-commerce/event-bus';\n\nexport const initializeCheckout = async (cart: Cart | null): Promise<void> => {\n if (state.initialized) return synchronizeCheckout(cart);\n\n if (!state.config) {\n state.config = await getStoreConfig();\n }\n\n const cartId = cart ? cart.id : null;\n state.cartId = cartId;\n\n const initialData = cartId ? await getCart() : null;\n state.initialized = true;\n\n events.emit('checkout/initialized', initialData || null);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { state } from '@/checkout/lib/state';\nimport { events } from '@adobe-commerce/event-bus';\n\nexport const resetCheckout = () => {\n state.cartId = null;\n events.emit('checkout/updated', null);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getCart, initializeCheckout } from '@/checkout/api';\nimport { state } from '@/checkout/lib/state';\nimport { Cart, events } from '@adobe-commerce/event-bus';\n\nexport const synchronizeCheckout = async (cart: Cart | null) => {\n if (!state.initialized) return initializeCheckout(cart);\n const cartId = cart ? cart.id : null;\n state.cartId = cartId;\n const data = cartId ? await getCart() : null;\n events.emit('checkout/updated', data || null);\n};\n"],"names":["authenticateCustomer","authenticated","state","transformSelectedPaymentMethod","data","transformAvailablePaymentMethods","method","code","title","isValidCustomAttribute","attribute","transformCustomAttributes","value","transformBaseAddress","street","transformAddressCountry","transformAddressRegion","transformCartBillingAddress","transformCartShippingAddress","address","available_shipping_methods","selected_shipping_method","same_as_billing","baseData","transformShippingMethods","transformSelectedShippingMethod","transformCartAddressInput","transformCart","model","merge","_c","_b","_a","config","byPrice","a","b","isNullish","isValid","buildShippingMethod","getCartQuery","CHECKOUT_DATA_FRAGMENT","getCustomerCartQuery","getCart","cartId","isGuest","query","variables","MissingCart","dispatchApiCall","addCheckoutEventListeners","events","initializeCheckout","resetCheckout","synchronizeCheck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,CAACxD,EAAM,YAAa,OAAOkD,EAAmBM,CAAI,EAChD,MAAAd,EAASc,EAAOA,EAAK,GAAK,KAChCxD,EAAM,OAAS0C,EACf,MAAMxC,EAAOwC,EAAS,MAAMD,EAAY,EAAA,KACjCQ,EAAA,KAAK,mBAAoB/C,GAAQ,IAAI,CAC9C"}
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as c,jsxs as E}from"@dropins/tools/preact-jsx-runtime.js";import{h as N}from"../chunks/errors.js";import"@dropins/tools/lib.js";import{events as T}from"@dropins/tools/event-bus.js";import{W as U,h as j,g as v}from"../chunks/ConditionalWrapper.js";import{n as w,g as L}from"../chunks/values.js";import{s as P}from"../chunks/setBillingAddress.js";/* empty css */import{Skeleton as R,SkeletonRow as W,Checkbox as y,InLineAlert as C}from"@dropins/tools/components.js";import{c as $}from"../chunks/classes.js";import{useText as _}from"@dropins/tools/i18n.js";import{useState as u,useRef as q,useCallback as m,useEffect as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const F=()=>c(R,{className:"bill-to-shipping-address__skeleton","data-testid":"bill-to-shipping-skeleton",children:c(W,{size:"small",variant:"row"})}),G=({className:i,checked:r,disabled:e,error:o=null,onChange:n=()=>{},onDismissError:a=()=>{}})=>{const f=_({title:"Checkout.BillToShippingAddress.title"}),h=o!==null,g=k=>{const b=k.target;n==null||n(b.checked)};return E("div",{className:"checkout-bill-to-shipping-address",children:[c(y,{checked:r,className:$(["checkout-bill-to-shipping-address__checkbox",i]),"data-testid":"bill-to-shipping-checkbox",disabled:e,label:f.title,name:"checkout-bill-to-shipping-address__checkbox",onChange:g}),h&&c("div",{className:"checkout-bill-to-shipping-address__error","data-testid":"checkout-bill-to-shipping-address-alert",children:c(C,{heading:o,type:"error",variant:"primary",onDismiss:a})})]})},H=U(G,F);function J(i){var n;const r=(n=i.shippingAddresses)==null?void 0:n[0],e=!!i.billingAddress;return(r==null?void 0:r.sameAsBilling)??!e}const cs=({active:i=!0,autoSync:r=!0,onCartSyncError:e,onChange:o})=>{const[n,a]=u(null),[f,h]=u(!1),[g,k]=u(!1),[b,A]=u(!0),B=q(!1),V=N.value,{cartSyncError:S}=_({cartSyncError:"Checkout.BillToShippingAddress.cartSyncError"}),I=m(()=>{a(null)},[]),p=m(s=>{a(null),A(s),w({isBillToShipping:s})},[]),z=m(s=>{const t=s;p(t),o==null||o(t),!(!r||!t||!j())&&P({sameAsShipping:!0}).catch(l=>{p(!1),e==null||e({error:l}),e||a(S)})},[r,S,e,o,p]),d=m(s=>{const t=!s||(s==null?void 0:s.isEmpty),l=!!(s!=null&&s.isVirtual);if(t||l){k(l),p(!1),B.current=!1;return}if(!B.current){const D=J(s);p(D),B.current=!0}},[p]);return x(()=>{if(!i)return;const s=v();if(s){h(!0);const l=L("isBillToShipping");l!=null&&A(l),d(s);return}const t=T.on("checkout/initialized",l=>{h(!0),d(l)},{eager:!0});return()=>{t==null||t.off()}},[i,d]),x(()=>{if(!i)return;const s=T.on("checkout/updated",d,{eager:!1});return()=>{s==null||s.off()}},[i,d]),c(H,{checked:b,disabled:V,error:n,initialized:f,visible:i&&!g,onChange:z,onDismissError:I})};export{cs as BillToShippingAddress,cs as default};
3
+ import{jsx as c,jsxs as E}from"@dropins/tools/preact-jsx-runtime.js";import{h as N}from"../chunks/fetch-graphql.js";import"@dropins/tools/lib.js";import{W as U,h as j,g as v}from"../chunks/ConditionalWrapper.js";import{n as w,g as L}from"../chunks/values.js";import{events as T}from"@dropins/tools/event-bus.js";import{s as P}from"../chunks/setBillingAddress.js";/* empty css */import{Skeleton as R,SkeletonRow as W,Checkbox as y,InLineAlert as C}from"@dropins/tools/components.js";import{c as $}from"../chunks/classes.js";import{useText as _}from"@dropins/tools/i18n.js";import{useState as u,useRef as q,useCallback as m,useEffect as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const F=()=>c(R,{className:"bill-to-shipping-address__skeleton","data-testid":"bill-to-shipping-skeleton",children:c(W,{size:"small",variant:"row"})}),G=({className:i,checked:r,disabled:e,error:o=null,onChange:n=()=>{},onDismissError:a=()=>{}})=>{const f=_({title:"Checkout.BillToShippingAddress.title"}),h=o!==null,g=k=>{const b=k.target;n==null||n(b.checked)};return E("div",{className:"checkout-bill-to-shipping-address",children:[c(y,{checked:r,className:$(["checkout-bill-to-shipping-address__checkbox",i]),"data-testid":"bill-to-shipping-checkbox",disabled:e,label:f.title,name:"checkout-bill-to-shipping-address__checkbox",onChange:g}),h&&c("div",{className:"checkout-bill-to-shipping-address__error","data-testid":"checkout-bill-to-shipping-address-alert",children:c(C,{heading:o,type:"error",variant:"primary",onDismiss:a})})]})},H=U(G,F);function J(i){var n;const r=(n=i.shippingAddresses)==null?void 0:n[0],e=!!i.billingAddress;return(r==null?void 0:r.sameAsBilling)??!e}const cs=({active:i=!0,autoSync:r=!0,onCartSyncError:e,onChange:o})=>{const[n,a]=u(null),[f,h]=u(!1),[g,k]=u(!1),[b,A]=u(!0),B=q(!1),V=N.value,{cartSyncError:S}=_({cartSyncError:"Checkout.BillToShippingAddress.cartSyncError"}),I=m(()=>{a(null)},[]),p=m(s=>{a(null),A(s),w({isBillToShipping:s})},[]),z=m(s=>{const t=s;p(t),o==null||o(t),!(!r||!t||!j())&&P({sameAsShipping:!0}).catch(l=>{p(!1),e==null||e({error:l}),e||a(S)})},[r,S,e,o,p]),d=m(s=>{const t=!s||(s==null?void 0:s.isEmpty),l=!!(s!=null&&s.isVirtual);if(t||l){k(l),p(!1),B.current=!1;return}if(!B.current){const D=J(s);p(D),B.current=!0}},[p]);return x(()=>{if(!i)return;const s=v();if(s){h(!0);const l=L("isBillToShipping");l!=null&&A(l),d(s);return}const t=T.on("checkout/initialized",l=>{h(!0),d(l)},{eager:!0});return()=>{t==null||t.off()}},[i,d]),x(()=>{if(!i)return;const s=T.on("checkout/updated",d,{eager:!1});return()=>{s==null||s.off()}},[i,d]),c(H,{checked:b,disabled:V,error:n,initialized:f,visible:i&&!g,onChange:z,onDismissError:I})};export{cs as BillToShippingAddress,cs as default};
4
4
  //# sourceMappingURL=BillToShippingAddress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BillToShippingAddress.js","sources":["/@dropins/storefront-checkout/src/components/BillToShippingAddress/BillToShippingAddressSkeleton.tsx","/@dropins/storefront-checkout/src/components/BillToShippingAddress/BillToShippingAddress.tsx","/@dropins/storefront-checkout/src/containers/BillToShippingAddress/BillToShippingAddress.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const BillToShippingAddressSkeleton: FunctionComponent = () => {\n return (\n <Skeleton\n className=\"bill-to-shipping-address__skeleton\"\n data-testid=\"bill-to-shipping-skeleton\"\n >\n <SkeletonRow size=\"small\" variant=\"row\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport '@/checkout/components/BillToShippingAddress/BillToShippingAddress.css';\nimport { BillToShippingAddressSkeleton } from '@/checkout/components/BillToShippingAddress/BillToShippingAddressSkeleton';\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/ConditionalWrapper';\nimport { Checkbox, InLineAlert } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { classes } from '@adobe-commerce/elsie/lib/classes';\nimport { FunctionComponent } from 'preact';\nimport { ChangeEvent, HTMLAttributes } from 'preact/compat';\n\nexport interface BillToShippingAddressProps\n extends Omit<\n HTMLAttributes<HTMLInputElement>,\n 'loading' | 'disabled' | 'onChange'\n > {\n disabled?: boolean;\n error?: string | null;\n onChange?: (checked: boolean) => void;\n onDismissError?: () => void;\n}\n\nconst BillToShippingAddressComponent: FunctionComponent<\n BillToShippingAddressProps\n> = ({\n className,\n checked,\n disabled,\n error = null,\n onChange = () => {},\n onDismissError = () => {},\n}) => {\n const translations = useText({\n title: 'Checkout.BillToShippingAddress.title',\n });\n\n const hasError = error !== null;\n\n const handleChange = (event: Event | ChangeEvent<HTMLInputElement>) => {\n const checkbox = event.target as HTMLInputElement;\n onChange?.(checkbox.checked);\n };\n\n return (\n <div className=\"checkout-bill-to-shipping-address\">\n <Checkbox\n checked={checked}\n className={classes([\n 'checkout-bill-to-shipping-address__checkbox',\n className,\n ])}\n data-testid=\"bill-to-shipping-checkbox\"\n disabled={disabled}\n label={translations.title}\n name=\"checkout-bill-to-shipping-address__checkbox\"\n onChange={handleChange}\n />\n\n {hasError && (\n <div\n className=\"checkout-bill-to-shipping-address__error\"\n data-testid=\"checkout-bill-to-shipping-address-alert\"\n >\n <InLineAlert\n heading={error}\n type=\"error\"\n variant=\"primary\"\n onDismiss={onDismissError}\n />\n </div>\n )}\n </div>\n );\n};\n\nexport const BillToShippingAddress = WithConditionals(\n BillToShippingAddressComponent,\n BillToShippingAddressSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { setBillingAddress } from '@/checkout/api';\nimport { BillToShippingAddress as BillToShippingAddressComponent } from '@/checkout/components/BillToShippingAddress';\nimport { Cart } from '@/checkout/data/models/cart';\nimport {\n getLatestCheckoutUpdate,\n getValue,\n hasPendingCartUpdates,\n hasShippingAddress,\n notifyValues,\n} from '@/checkout/lib';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\ninterface CartSyncError {\n error: Error;\n}\n\nexport interface BillToShippingAddressProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {\n active?: boolean;\n autoSync?: boolean;\n onCartSyncError?: (error: CartSyncError) => void;\n onChange?: (checked: boolean) => void;\n}\n\nfunction isBillToShippingAddress(cart: Cart) {\n const shippingAddress = cart.shippingAddresses?.[0];\n const hasBillingAddress = !!cart.billingAddress;\n const sameAsBilling = shippingAddress?.sameAsBilling;\n return sameAsBilling ?? !hasBillingAddress;\n}\n\nexport const BillToShippingAddress: Container<BillToShippingAddressProps> = ({\n active = true,\n autoSync = true,\n onCartSyncError,\n onChange,\n}) => {\n const [error, setError] = useState<string | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [isVirtual, setIsVirtual] = useState(false);\n const [isChecked, setIsChecked] = useState(true);\n\n const hasInitialCartData = useRef(false);\n\n const hasPendingUpdates = hasPendingCartUpdates.value;\n\n const { cartSyncError } = useText({\n cartSyncError: 'Checkout.BillToShippingAddress.cartSyncError',\n });\n\n const handleDismissError = useCallback(() => {\n setError(null);\n }, []);\n\n const setBillToShipping = useCallback(\n (value: boolean) => {\n setError(null);\n setIsChecked(value);\n notifyValues({ isBillToShipping: value });\n },\n []\n );\n\n const handleChange = useCallback(\n (checked: boolean) => {\n const isBillToShipping = checked;\n\n setBillToShipping(isBillToShipping);\n\n onChange?.(isBillToShipping);\n\n if (!autoSync || !isBillToShipping || !hasShippingAddress()) {\n return;\n }\n\n setBillingAddress({ sameAsShipping: true }).catch((error: any) => {\n setBillToShipping(false);\n onCartSyncError?.({ error });\n\n if (!onCartSyncError) {\n setError(cartSyncError);\n }\n });\n },\n [autoSync, cartSyncError, onCartSyncError, onChange, setBillToShipping]\n );\n\n const handleCheckoutData = useCallback(\n (data: Cart | null) => {\n const isEmptyCart = !data || data?.isEmpty;\n const isVirtualCart = Boolean(data?.isVirtual);\n\n if (isEmptyCart || isVirtualCart) {\n setIsVirtual(isVirtualCart);\n setBillToShipping(false);\n hasInitialCartData.current = false;\n return;\n }\n\n if (!hasInitialCartData.current) {\n const billToShippingValue = isBillToShippingAddress(data);\n setBillToShipping(billToShippingValue);\n hasInitialCartData.current = true;\n }\n },\n [setBillToShipping]\n );\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n // When component becomes active, restore key state so handleCheckoutData can work properly\n const userBillToShipping = getValue('isBillToShipping');\n if (userBillToShipping != null) {\n setIsChecked(userBillToShipping);\n }\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n {\n eager: false,\n }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n return (\n <BillToShippingAddressComponent\n checked={isChecked}\n disabled={hasPendingUpdates}\n error={error}\n initialized={isInitialized}\n visible={active && !isVirtual}\n onChange={handleChange}\n onDismissError={handleDismissError}\n />\n );\n};\n"],"names":["BillToShippingAddressSkeleton","jsx","Skeleton","SkeletonRow","BillToShippingAddressComponent","className","checked","disabled","error","onChange","onDismissError","translations","useText","hasError","handleChange","event","checkbox","jsxs","Checkbox","classes","InLineAlert","BillToShippingAddress","WithConditionals","isBillToShippingAddress","cart","shippingAddress","_a","hasBillingAddress","active","autoSync","onCartSyncError","setError","useState","isInitialized","setIsInitialized","isVirtual","setIsVirtual","isChecked","setIsChecked","hasInitialCartData","useRef","hasPendingUpdates","hasPendingCartUpdates","cartSyncError","handleDismissError","useCallback","setBillToShipping","value","notifyValues","isBillToShipping","hasShippingAddress","setBillingAddress","handleCheckoutData","data","isEmptyCart","isVirtualCart","billToShippingValue","useEffect","pastUpdate","getLatestCheckoutUpdate","userBillToShipping","getValue","onCheckoutInit","events","onCheckoutUpdated"],"mappings":"k0BAoBO,MAAMA,EAAmD,IAE5DC,EAACC,EAAA,CACC,UAAU,qCACV,cAAY,4BAEZ,SAACD,EAAAE,EAAA,CAAY,KAAK,QAAQ,QAAQ,KAAM,CAAA,CAAA,CAC1C,ECUEC,EAEF,CAAC,CACH,UAAAC,EACA,QAAAC,EACA,SAAAC,EACA,MAAAC,EAAQ,KACR,SAAAC,EAAW,IAAM,CAAC,EAClB,eAAAC,EAAiB,IAAM,CAAA,CACzB,IAAM,CACJ,MAAMC,EAAeC,EAAQ,CAC3B,MAAO,sCAAA,CACR,EAEKC,EAAWL,IAAU,KAErBM,EAAgBC,GAAiD,CACrE,MAAMC,EAAWD,EAAM,OACvBN,GAAA,MAAAA,EAAWO,EAAS,QACtB,EAGE,OAAAC,EAAC,MAAI,CAAA,UAAU,oCACb,SAAA,CAAAhB,EAACiB,EAAA,CACC,QAAAZ,EACA,UAAWa,EAAQ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ACC,CAACpC,EAAQwB,CAAkB,CAAC,EAG7BnD,EAACG,EAAA,CACC,QAASiC,EACT,SAAUI,EACV,MAAAjC,EACA,YAAayB,EACb,QAASL,GAAU,CAACO,EACpB,SAAUrB,EACV,eAAgB8B,CAAA,CAClB,CAEJ"}
1
+ {"version":3,"file":"BillToShippingAddress.js","sources":["/@dropins/storefront-checkout/src/components/BillToShippingAddress/BillToShippingAddressSkeleton.tsx","/@dropins/storefront-checkout/src/components/BillToShippingAddress/BillToShippingAddress.tsx","/@dropins/storefront-checkout/src/containers/BillToShippingAddress/BillToShippingAddress.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const BillToShippingAddressSkeleton: FunctionComponent = () => {\n return (\n <Skeleton\n className=\"bill-to-shipping-address__skeleton\"\n data-testid=\"bill-to-shipping-skeleton\"\n >\n <SkeletonRow size=\"small\" variant=\"row\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport '@/checkout/components/BillToShippingAddress/BillToShippingAddress.css';\nimport { BillToShippingAddressSkeleton } from '@/checkout/components/BillToShippingAddress/BillToShippingAddressSkeleton';\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/ConditionalWrapper';\nimport { Checkbox, InLineAlert } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { classes } from '@adobe-commerce/elsie/lib/classes';\nimport { FunctionComponent } from 'preact';\nimport { ChangeEvent, HTMLAttributes } from 'preact/compat';\n\nexport interface BillToShippingAddressProps\n extends Omit<\n HTMLAttributes<HTMLInputElement>,\n 'loading' | 'disabled' | 'onChange'\n > {\n disabled?: boolean;\n error?: string | null;\n onChange?: (checked: boolean) => void;\n onDismissError?: () => void;\n}\n\nconst BillToShippingAddressComponent: FunctionComponent<\n BillToShippingAddressProps\n> = ({\n className,\n checked,\n disabled,\n error = null,\n onChange = () => {},\n onDismissError = () => {},\n}) => {\n const translations = useText({\n title: 'Checkout.BillToShippingAddress.title',\n });\n\n const hasError = error !== null;\n\n const handleChange = (event: Event | ChangeEvent<HTMLInputElement>) => {\n const checkbox = event.target as HTMLInputElement;\n onChange?.(checkbox.checked);\n };\n\n return (\n <div className=\"checkout-bill-to-shipping-address\">\n <Checkbox\n checked={checked}\n className={classes([\n 'checkout-bill-to-shipping-address__checkbox',\n className,\n ])}\n data-testid=\"bill-to-shipping-checkbox\"\n disabled={disabled}\n label={translations.title}\n name=\"checkout-bill-to-shipping-address__checkbox\"\n onChange={handleChange}\n />\n\n {hasError && (\n <div\n className=\"checkout-bill-to-shipping-address__error\"\n data-testid=\"checkout-bill-to-shipping-address-alert\"\n >\n <InLineAlert\n heading={error}\n type=\"error\"\n variant=\"primary\"\n onDismiss={onDismissError}\n />\n </div>\n )}\n </div>\n );\n};\n\nexport const BillToShippingAddress = WithConditionals(\n BillToShippingAddressComponent,\n BillToShippingAddressSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { setBillingAddress } from '@/checkout/api';\nimport { BillToShippingAddress as BillToShippingAddressComponent } from '@/checkout/components/BillToShippingAddress';\nimport { Cart } from '@/checkout/data/models/cart';\nimport {\n getLatestCheckoutUpdate,\n getValue,\n hasPendingCartUpdates,\n hasShippingAddress,\n notifyValues,\n} from '@/checkout/lib';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\ninterface CartSyncError {\n error: Error;\n}\n\nexport interface BillToShippingAddressProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {\n active?: boolean;\n autoSync?: boolean;\n onCartSyncError?: (error: CartSyncError) => void;\n onChange?: (checked: boolean) => void;\n}\n\nfunction isBillToShippingAddress(cart: Cart) {\n const shippingAddress = cart.shippingAddresses?.[0];\n const hasBillingAddress = !!cart.billingAddress;\n const sameAsBilling = shippingAddress?.sameAsBilling;\n return sameAsBilling ?? !hasBillingAddress;\n}\n\nexport const BillToShippingAddress: Container<BillToShippingAddressProps> = ({\n active = true,\n autoSync = true,\n onCartSyncError,\n onChange,\n}) => {\n const [error, setError] = useState<string | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [isVirtual, setIsVirtual] = useState(false);\n const [isChecked, setIsChecked] = useState(true);\n\n const hasInitialCartData = useRef(false);\n\n const hasPendingUpdates = hasPendingCartUpdates.value;\n\n const { cartSyncError } = useText({\n cartSyncError: 'Checkout.BillToShippingAddress.cartSyncError',\n });\n\n const handleDismissError = useCallback(() => {\n setError(null);\n }, []);\n\n const setBillToShipping = useCallback(\n (value: boolean) => {\n setError(null);\n setIsChecked(value);\n notifyValues({ isBillToShipping: value });\n },\n []\n );\n\n const handleChange = useCallback(\n (checked: boolean) => {\n const isBillToShipping = checked;\n\n setBillToShipping(isBillToShipping);\n\n onChange?.(isBillToShipping);\n\n if (!autoSync || !isBillToShipping || !hasShippingAddress()) {\n return;\n }\n\n setBillingAddress({ sameAsShipping: true }).catch((error: any) => {\n setBillToShipping(false);\n onCartSyncError?.({ error });\n\n if (!onCartSyncError) {\n setError(cartSyncError);\n }\n });\n },\n [autoSync, cartSyncError, onCartSyncError, onChange, setBillToShipping]\n );\n\n const handleCheckoutData = useCallback(\n (data: Cart | null) => {\n const isEmptyCart = !data || data?.isEmpty;\n const isVirtualCart = Boolean(data?.isVirtual);\n\n if (isEmptyCart || isVirtualCart) {\n setIsVirtual(isVirtualCart);\n setBillToShipping(false);\n hasInitialCartData.current = false;\n return;\n }\n\n if (!hasInitialCartData.current) {\n const billToShippingValue = isBillToShippingAddress(data);\n setBillToShipping(billToShippingValue);\n hasInitialCartData.current = true;\n }\n },\n [setBillToShipping]\n );\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n // When component becomes active, restore key state so handleCheckoutData can work properly\n const userBillToShipping = getValue('isBillToShipping');\n if (userBillToShipping != null) {\n setIsChecked(userBillToShipping);\n }\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n {\n eager: false,\n }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n return (\n <BillToShippingAddressComponent\n checked={isChecked}\n disabled={hasPendingUpdates}\n error={error}\n initialized={isInitialized}\n visible={active && !isVirtual}\n onChange={handleChange}\n onDismissError={handleDismissError}\n />\n );\n};\n"],"names":["BillToShippingAddressSkeleton","jsx","Skeleton","SkeletonRow","BillToShippingAddressComponent","className","checked","disabled","error","onChange","onDismissError","translations","useText","hasError","handleChange","event","checkbox","jsxs","Checkbox","classes","InLineAlert","BillToShippingAddress","WithConditionals","isBillToShippingAddress","cart","shippingAddress","_a","hasBillingAddress","active","autoSync","onCartSyncError","setError","useState","isInitialized","setIsInitialized","isVirtual","setIsVirtual","isChecked","setIsChecked","hasInitialCartData","useRef","hasPendingUpdates","hasPendingCartUpdates","cartSyncError","handleDismissError","useCallback","setBillToShipping","value","notifyValues","isBillToShipping","hasShippingAddress","setBillingAddress","handleCheckoutData","data","isEmptyCart","isVirtualCart","billToShippingValue","useEffect","pastUpdate","getLatestCheckoutUpdate","userBillToShipping","getValue","onCheckoutInit","events","onCheckoutUpdated"],"mappings":"y0BAoBO,MAAMA,EAAmD,IAE5DC,EAACC,EAAA,CACC,UAAU,qCACV,cAAY,4BAEZ,SAACD,EAAAE,EAAA,CAAY,KAAK,QAAQ,QAAQ,KAAM,CAAA,CAAA,CAC1C,ECUEC,EAEF,CAAC,CACH,UAAAC,EACA,QAAAC,EACA,SAAAC,EACA,MAAAC,EAAQ,KACR,SAAAC,EAAW,IAAM,CAAC,EAClB,eAAAC,EAAiB,IAAM,CAAA,CACzB,IAAM,CACJ,MAAMC,EAAeC,EAAQ,CAC3B,MAAO,sCAAA,CACR,EAEKC,EAAWL,IAAU,KAErBM,EAAgBC,GAAiD,CACrE,MAAMC,EAAWD,EAAM,OACvBN,GAAA,MAAAA,EAAWO,EAAS,QACtB,EAGE,OAAAC,EAAC,MAAI,CAAA,UAAU,oCACb,SAAA,CAAAhB,EAACiB,EAAA,CACC,QAAAZ,EACA,UAAWa,EAAQ,CACjB,8CACAd,CAAA,CACD,EACD,cAAY,4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nD,EAACG,EAAA,CACC,QAASiC,EACT,SAAUI,EACV,MAAAjC,EACA,YAAayB,EACb,QAASL,GAAU,CAACO,EACpB,SAAUrB,EACV,eAAgB8B,CAAA,CAClB,CAEJ"}
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as i,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Skeleton as B,SkeletonRow as U,Price as h}from"@dropins/tools/components.js";import{W as z,g as G}from"../chunks/ConditionalWrapper.js";import"../chunks/TermsAndConditions.js";import{VComponent as C,classes as D}from"@dropins/tools/lib.js";import{useText as _}from"@dropins/tools/i18n.js";/* empty css */import{s as P,T as I}from"../chunks/errors.js";import{events as d}from"@dropins/tools/event-bus.js";import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{useState as V,useCallback as b,useEffect as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const X=()=>i(B,{"data-testid":"estimate-shipping-skeleton",children:i(U,{size:"xsmall"})}),j=({label:n,price:t,priceExclTax:a,taxExcluded:o=!1,taxIncluded:c=!1})=>{const l=_({withTaxes:"Checkout.EstimateShipping.withTaxes",withoutTaxes:"Checkout.EstimateShipping.withoutTaxes"});return k("div",{className:"checkout-estimate-shipping","data-testid":"estimate-shipping",children:[i(C,{className:"checkout-estimate-shipping__label",node:n}),i(C,{className:"checkout-estimate-shipping__price",node:t}),c&&i("span",{className:D(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included",children:l.withTaxes}),o&&k("span",{className:D(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included-excluded",children:[a," ",l.withoutTaxes]})]})},v=z(j,X),st=({active:n=!0})=>{var T;const[t,a]=V(),o=(t==null?void 0:t.amount.value)===0,c=(T=P.config)==null?void 0:T.shoppingCartDisplaySetting.shipping,l=c===I.INCLUDING_EXCLUDING_TAX,g=c===I.INCLUDING_TAX,u=_({freeShipping:"Checkout.EstimateShipping.freeShipping",taxToBeDetermined:"Checkout.EstimateShipping.taxToBeDetermined",label:"Checkout.EstimateShipping.label",estimated:"Checkout.EstimateShipping.estimated"}),r=b(e=>{var S;const s=!e||e.isEmpty,p=!!(e!=null&&e.isVirtual);if(s||p){a(null);return}const m=(S=e.shippingAddresses)==null?void 0:S[0];if(!m)return;const E=m==null?void 0:m.selectedShippingMethod;if(!E){a(null);return}const{amount:w,amountExclTax:L,amountInclTax:M}=E;a({estimated:!1,amount:w,amountExclTax:L,amountInclTax:M})},[]),f=b(e=>{let s=null;if(e.shippingMethod){const p=e.shippingMethod;s={estimated:!0,amount:p.amount,amountExclTax:p.amountExclTax,amountInclTax:p.amountInclTax}}a(s)},[]);x(()=>{if(!n)return;const e=d.on("shipping/estimate",f,{eager:!0});return()=>{e==null||e.off()}},[n,f]),x(()=>{if(!n)return;const e=G();if(e){r(e);return}const s=d.on("checkout/initialized",r,{eager:!0});return()=>{s==null||s.off()}},[n,r]),x(()=>{if(!n)return;const e=d.on("checkout/updated",r,{eager:!1});return()=>{e==null||e.off()}},[n,r]);const y=()=>o?i("span",{"data-testid":"free-shipping",children:u.freeShipping}):g&&(t!=null&&t.amountInclTax)?i(h,{amount:t.amountInclTax.value,currency:t.amountInclTax.currency,"data-testid":"shipping"}):i(h,{amount:t==null?void 0:t.amount.value,currency:t==null?void 0:t.amount.currency,"data-testid":"shipping"}),N=()=>t!=null&&t.amountExclTax?i(h,{amount:t.amountExclTax.value,currency:t.amountExclTax.currency,"data-testid":"shipping-excluding-tax"}):i("span",{children:u.taxToBeDetermined});return i(v,{initialized:t!==void 0,label:(()=>{const e=t!=null&&t.estimated?u.estimated:u.label;return i("span",{"data-testid":"estimate-shipping-label",children:e})})(),price:y(),priceExclTax:N(),taxExcluded:l&&!o,taxIncluded:g&&!o,visible:n&&t!==null})};export{st as EstimateShipping,st as default};
3
+ import{jsx as i,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Skeleton as B,SkeletonRow as U,Price as h}from"@dropins/tools/components.js";import{W as z,g as G}from"../chunks/ConditionalWrapper.js";import"../chunks/TermsAndConditions.js";import{VComponent as C,classes as D}from"@dropins/tools/lib.js";import{useText as _}from"@dropins/tools/i18n.js";/* empty css */import{s as P,T as I}from"../chunks/fetch-graphql.js";import{events as d}from"@dropins/tools/event-bus.js";import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{useState as V,useCallback as b,useEffect as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const X=()=>i(B,{"data-testid":"estimate-shipping-skeleton",children:i(U,{size:"xsmall"})}),j=({label:n,price:t,priceExclTax:a,taxExcluded:o=!1,taxIncluded:c=!1})=>{const l=_({withTaxes:"Checkout.EstimateShipping.withTaxes",withoutTaxes:"Checkout.EstimateShipping.withoutTaxes"});return k("div",{className:"checkout-estimate-shipping","data-testid":"estimate-shipping",children:[i(C,{className:"checkout-estimate-shipping__label",node:n}),i(C,{className:"checkout-estimate-shipping__price",node:t}),c&&i("span",{className:D(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included",children:l.withTaxes}),o&&k("span",{className:D(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included-excluded",children:[a," ",l.withoutTaxes]})]})},v=z(j,X),st=({active:n=!0})=>{var T;const[t,a]=V(),o=(t==null?void 0:t.amount.value)===0,c=(T=P.config)==null?void 0:T.shoppingCartDisplaySetting.shipping,l=c===I.INCLUDING_EXCLUDING_TAX,g=c===I.INCLUDING_TAX,u=_({freeShipping:"Checkout.EstimateShipping.freeShipping",taxToBeDetermined:"Checkout.EstimateShipping.taxToBeDetermined",label:"Checkout.EstimateShipping.label",estimated:"Checkout.EstimateShipping.estimated"}),r=b(e=>{var S;const s=!e||e.isEmpty,p=!!(e!=null&&e.isVirtual);if(s||p){a(null);return}const m=(S=e.shippingAddresses)==null?void 0:S[0];if(!m)return;const E=m==null?void 0:m.selectedShippingMethod;if(!E){a(null);return}const{amount:w,amountExclTax:L,amountInclTax:M}=E;a({estimated:!1,amount:w,amountExclTax:L,amountInclTax:M})},[]),f=b(e=>{let s=null;if(e.shippingMethod){const p=e.shippingMethod;s={estimated:!0,amount:p.amount,amountExclTax:p.amountExclTax,amountInclTax:p.amountInclTax}}a(s)},[]);x(()=>{if(!n)return;const e=d.on("shipping/estimate",f,{eager:!0});return()=>{e==null||e.off()}},[n,f]),x(()=>{if(!n)return;const e=G();if(e){r(e);return}const s=d.on("checkout/initialized",r,{eager:!0});return()=>{s==null||s.off()}},[n,r]),x(()=>{if(!n)return;const e=d.on("checkout/updated",r,{eager:!1});return()=>{e==null||e.off()}},[n,r]);const y=()=>o?i("span",{"data-testid":"free-shipping",children:u.freeShipping}):g&&(t!=null&&t.amountInclTax)?i(h,{amount:t.amountInclTax.value,currency:t.amountInclTax.currency,"data-testid":"shipping"}):i(h,{amount:t==null?void 0:t.amount.value,currency:t==null?void 0:t.amount.currency,"data-testid":"shipping"}),N=()=>t!=null&&t.amountExclTax?i(h,{amount:t.amountExclTax.value,currency:t.amountExclTax.currency,"data-testid":"shipping-excluding-tax"}):i("span",{children:u.taxToBeDetermined});return i(v,{initialized:t!==void 0,label:(()=>{const e=t!=null&&t.estimated?u.estimated:u.label;return i("span",{"data-testid":"estimate-shipping-label",children:e})})(),price:y(),priceExclTax:N(),taxExcluded:l&&!o,taxIncluded:g&&!o,visible:n&&t!==null})};export{st as EstimateShipping,st as default};
4
4
  //# sourceMappingURL=EstimateShipping.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EstimateShipping.js","sources":["/@dropins/storefront-checkout/src/components/EstimateShipping/EstimateShippingSkeleton.tsx","/@dropins/storefront-checkout/src/components/EstimateShipping/EstimateShipping.tsx","/@dropins/storefront-checkout/src/containers/EstimateShipping/EstimateShipping.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const EstimateShippingSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"estimate-shipping-skeleton\">\n <SkeletonRow size=\"xsmall\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper';\nimport '@/checkout/components/EstimateShipping/EstimateShipping.css';\nimport { EstimateShippingSkeleton } from '@/checkout/components/EstimateShipping/EstimateShippingSkeleton';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { VComponent, classes } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, VNode } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface EstimateShippingProps {\n label: VNode<HTMLAttributes<HTMLSpanElement>>;\n price: VNode<HTMLAttributes<HTMLSpanElement>>;\n priceExclTax?: VNode<HTMLAttributes<HTMLSpanElement>>;\n taxExcluded?: boolean;\n taxIncluded?: boolean;\n}\n\nconst EstimateShippingComponent: FunctionComponent<EstimateShippingProps> = ({\n label,\n price,\n priceExclTax,\n taxExcluded = false,\n taxIncluded = false,\n}) => {\n const translations = useText({\n withTaxes: 'Checkout.EstimateShipping.withTaxes',\n withoutTaxes: 'Checkout.EstimateShipping.withoutTaxes',\n });\n\n return (\n <div className=\"checkout-estimate-shipping\" data-testid=\"estimate-shipping\">\n <VComponent className=\"checkout-estimate-shipping__label\" node={label} />\n <VComponent className=\"checkout-estimate-shipping__price\" node={price} />\n\n {taxIncluded && (\n <span\n className={classes(['checkout-estimate-shipping__caption'])}\n data-testid=\"shipping-tax-included\"\n >\n {translations.withTaxes}\n </span>\n )}\n\n {taxExcluded && (\n <span\n className={classes(['checkout-estimate-shipping__caption'])}\n data-testid=\"shipping-tax-included-excluded\"\n >\n {priceExclTax}&nbsp;\n {translations.withoutTaxes}\n </span>\n )}\n </div>\n );\n};\n\nexport const EstimateShipping = WithConditionals(\n EstimateShippingComponent,\n EstimateShippingSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { EstimateShipping as EstimateShippingComponent } from '@/checkout/components';\nimport {\n Cart,\n Price as PriceModel,\n ShippingEstimate,\n TaxDisplay,\n} from '@/checkout/data/models';\nimport { getLatestCheckoutUpdate } from '@/checkout/lib';\nimport { state } from '@/checkout/lib/state';\nimport { Price } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { useCallback, useEffect, useState } from 'preact/hooks';\n\ninterface ShippingData {\n estimated?: boolean;\n amount: PriceModel;\n amountExclTax?: PriceModel;\n amountInclTax?: PriceModel;\n}\n\nexport interface EstimateShippingProps {\n active?: boolean;\n}\n\nexport const EstimateShipping: Container<EstimateShippingProps> = ({\n active = true,\n}) => {\n const [data, setData] = useState<ShippingData | null | undefined>();\n\n const isFreeShipping = data?.amount.value === 0;\n const shippingDisplay = state.config?.shoppingCartDisplaySetting.shipping;\n const taxExcluded = shippingDisplay === TaxDisplay.INCLUDING_EXCLUDING_TAX;\n const taxIncluded = shippingDisplay === TaxDisplay.INCLUDING_TAX;\n\n const translations = useText({\n freeShipping: 'Checkout.EstimateShipping.freeShipping',\n taxToBeDetermined: 'Checkout.EstimateShipping.taxToBeDetermined',\n label: 'Checkout.EstimateShipping.label',\n estimated: 'Checkout.EstimateShipping.estimated',\n });\n\n const handleCheckoutData = useCallback((data: Cart | null) => {\n const isEmptyCart = !data || data.isEmpty;\n const isVirtualCart = Boolean(data?.isVirtual);\n\n if (isEmptyCart || isVirtualCart) {\n setData(null);\n return;\n }\n\n const primaryAddress = data.shippingAddresses?.[0];\n\n if (!primaryAddress) {\n return;\n }\n\n const shippingMethod = primaryAddress?.selectedShippingMethod;\n\n if (!shippingMethod) {\n setData(null);\n return;\n }\n\n const { amount, amountExclTax, amountInclTax } = shippingMethod;\n setData({ estimated: false, amount, amountExclTax, amountInclTax });\n }, []);\n\n const handleShippingEstimate = useCallback((estimation: ShippingEstimate) => {\n let shippingData: ShippingData | null = null;\n\n if (estimation.shippingMethod) {\n const shippingMethod = estimation.shippingMethod;\n\n shippingData = {\n estimated: true,\n amount: shippingMethod.amount,\n amountExclTax: shippingMethod.amountExclTax,\n amountInclTax: shippingMethod.amountInclTax,\n };\n }\n\n setData(shippingData);\n }, []);\n\n useEffect(() => {\n if (!active) return;\n\n const onShippingEstimate = events.on(\n 'shipping/estimate',\n handleShippingEstimate,\n { eager: true }\n );\n\n return () => {\n onShippingEstimate?.off();\n };\n }, [active, handleShippingEstimate]);\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n handleCheckoutData,\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n const renderPrice = () => {\n if (isFreeShipping) {\n return (\n <span data-testid=\"free-shipping\">{translations.freeShipping}</span>\n );\n }\n\n if (taxIncluded && data?.amountInclTax) {\n return (\n <Price\n amount={data.amountInclTax.value}\n currency={data.amountInclTax.currency}\n data-testid=\"shipping\"\n />\n );\n }\n\n return (\n <Price\n amount={data?.amount.value}\n currency={data?.amount.currency}\n data-testid=\"shipping\"\n />\n );\n };\n\n const renderPriceExclTax = () => {\n if (!data?.amountExclTax)\n return <span>{translations.taxToBeDetermined}</span>;\n\n return (\n <Price\n amount={data.amountExclTax.value}\n currency={data.amountExclTax.currency}\n data-testid=\"shipping-excluding-tax\"\n />\n );\n };\n\n const renderLabel = () => {\n const label = data?.estimated ? translations.estimated : translations.label;\n return <span data-testid=\"estimate-shipping-label\">{label}</span>;\n };\n\n return (\n <EstimateShippingComponent\n initialized={data !== undefined}\n label={renderLabel()}\n price={renderPrice()}\n priceExclTax={renderPriceExclTax()}\n taxExcluded={taxExcluded && !isFreeShipping}\n taxIncluded={taxIncluded && !isFreeShipping}\n visible={active && data !== null}\n />\n );\n};\n"],"names":["EstimateShippingSkeleton","jsx","Skeleton","SkeletonRow","EstimateShippingComponent","label","price","priceExclTax","taxExcluded","taxIncluded","translations","useText","jsxs","VComponent","classes","EstimateShipping","WithConditionals","active","data","setData","useState","isFreeShipping","shippingDisplay","_a","state","TaxDisplay","handleCheckoutData","useCallback","isEmptyCart","isVirtualCart","primaryAddress","shippingMethod","amount","amountExclTax","amountInclTax","handleShippingEstimate","estimation","shippingData","useEffect","onShippingEstimate","events","pastUpdate","getLat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OAEb,MAAM2B,EAAoBJ,EAAO,GAC/B,mBACAd,EACA,CAAE,MAAO,EAAM,CACjB,EAEA,MAAO,IAAM,CACXkB,GAAA,MAAAA,EAAmB,KACrB,CAAA,EACC,CAAC3B,EAAQS,CAAkB,CAAC,EAE/B,MAAMmB,EAAc,IACdxB,EAECpB,EAAA,OAAA,CAAK,cAAY,gBAAiB,WAAa,aAAa,EAI7DQ,IAAeS,GAAA,MAAAA,EAAM,eAErBjB,EAAC6C,EAAA,CACC,OAAQ5B,EAAK,cAAc,MAC3B,SAAUA,EAAK,cAAc,SAC7B,cAAY,UAAA,CACd,EAKFjB,EAAC6C,EAAA,CACC,OAAQ5B,GAAA,YAAAA,EAAM,OAAO,MACrB,SAAUA,GAAA,YAAAA,EAAM,OAAO,SACvB,cAAY,UAAA,CACd,EAIE6B,EAAqB,IACpB7B,GAAA,MAAAA,EAAM,cAITjB,EAAC6C,EAAA,CACC,OAAQ5B,EAAK,cAAc,MAC3B,SAAUA,EAAK,cAAc,SAC7B,cAAY,wBAAA,CACd,EAPOjB,EAAC,OAAM,CAAA,SAAAS,EAAa,iBAAkB,CAAA,EAiB/C,OAAAT,EAACG,EAAA,CACC,YAAac,IAAS,OACtB,OARgB,IAAM,CACxB,MAAMb,EAAQa,GAAA,MAAAA,EAAM,UAAYR,EAAa,UAAYA,EAAa,MACtE,OAAQT,EAAA,OAAA,CAAK,cAAY,0BAA2B,SAAMI,EAAA,CAC5D,GAKuB,EACnB,MAAOwC,EAAY,EACnB,aAAcE,EAAmB,EACjC,YAAavC,GAAe,CAACa,EAC7B,YAAaZ,GAAe,CAACY,EAC7B,QAASJ,GAAUC,IAAS,IAAA,CAC9B,CAEJ"}
1
+ {"version":3,"file":"EstimateShipping.js","sources":["/@dropins/storefront-checkout/src/components/EstimateShipping/EstimateShippingSkeleton.tsx","/@dropins/storefront-checkout/src/components/EstimateShipping/EstimateShipping.tsx","/@dropins/storefront-checkout/src/containers/EstimateShipping/EstimateShipping.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const EstimateShippingSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"estimate-shipping-skeleton\">\n <SkeletonRow size=\"xsmall\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper';\nimport '@/checkout/components/EstimateShipping/EstimateShipping.css';\nimport { EstimateShippingSkeleton } from '@/checkout/components/EstimateShipping/EstimateShippingSkeleton';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { VComponent, classes } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, VNode } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface EstimateShippingProps {\n label: VNode<HTMLAttributes<HTMLSpanElement>>;\n price: VNode<HTMLAttributes<HTMLSpanElement>>;\n priceExclTax?: VNode<HTMLAttributes<HTMLSpanElement>>;\n taxExcluded?: boolean;\n taxIncluded?: boolean;\n}\n\nconst EstimateShippingComponent: FunctionComponent<EstimateShippingProps> = ({\n label,\n price,\n priceExclTax,\n taxExcluded = false,\n taxIncluded = false,\n}) => {\n const translations = useText({\n withTaxes: 'Checkout.EstimateShipping.withTaxes',\n withoutTaxes: 'Checkout.EstimateShipping.withoutTaxes',\n });\n\n return (\n <div className=\"checkout-estimate-shipping\" data-testid=\"estimate-shipping\">\n <VComponent className=\"checkout-estimate-shipping__label\" node={label} />\n <VComponent className=\"checkout-estimate-shipping__price\" node={price} />\n\n {taxIncluded && (\n <span\n className={classes(['checkout-estimate-shipping__caption'])}\n data-testid=\"shipping-tax-included\"\n >\n {translations.withTaxes}\n </span>\n )}\n\n {taxExcluded && (\n <span\n className={classes(['checkout-estimate-shipping__caption'])}\n data-testid=\"shipping-tax-included-excluded\"\n >\n {priceExclTax}&nbsp;\n {translations.withoutTaxes}\n </span>\n )}\n </div>\n );\n};\n\nexport const EstimateShipping = WithConditionals(\n EstimateShippingComponent,\n EstimateShippingSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { EstimateShipping as EstimateShippingComponent } from '@/checkout/components';\nimport {\n Cart,\n Money as PriceModel,\n ShippingEstimate,\n TaxDisplay,\n} from '@/checkout/data/models';\nimport { getLatestCheckoutUpdate } from '@/checkout/lib';\nimport { state } from '@/checkout/lib/state';\nimport { Price } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { useCallback, useEffect, useState } from 'preact/hooks';\n\ninterface ShippingData {\n estimated?: boolean;\n amount: PriceModel;\n amountExclTax?: PriceModel;\n amountInclTax?: PriceModel;\n}\n\nexport interface EstimateShippingProps {\n active?: boolean;\n}\n\nexport const EstimateShipping: Container<EstimateShippingProps> = ({\n active = true,\n}) => {\n const [data, setData] = useState<ShippingData | null | undefined>();\n\n const isFreeShipping = data?.amount.value === 0;\n const shippingDisplay = state.config?.shoppingCartDisplaySetting.shipping;\n const taxExcluded = shippingDisplay === TaxDisplay.INCLUDING_EXCLUDING_TAX;\n const taxIncluded = shippingDisplay === TaxDisplay.INCLUDING_TAX;\n\n const translations = useText({\n freeShipping: 'Checkout.EstimateShipping.freeShipping',\n taxToBeDetermined: 'Checkout.EstimateShipping.taxToBeDetermined',\n label: 'Checkout.EstimateShipping.label',\n estimated: 'Checkout.EstimateShipping.estimated',\n });\n\n const handleCheckoutData = useCallback((data: Cart | null) => {\n const isEmptyCart = !data || data.isEmpty;\n const isVirtualCart = Boolean(data?.isVirtual);\n\n if (isEmptyCart || isVirtualCart) {\n setData(null);\n return;\n }\n\n const primaryAddress = data.shippingAddresses?.[0];\n\n if (!primaryAddress) {\n return;\n }\n\n const shippingMethod = primaryAddress?.selectedShippingMethod;\n\n if (!shippingMethod) {\n setData(null);\n return;\n }\n\n const { amount, amountExclTax, amountInclTax } = shippingMethod;\n setData({ estimated: false, amount, amountExclTax, amountInclTax });\n }, []);\n\n const handleShippingEstimate = useCallback((estimation: ShippingEstimate) => {\n let shippingData: ShippingData | null = null;\n\n if (estimation.shippingMethod) {\n const shippingMethod = estimation.shippingMethod;\n\n shippingData = {\n estimated: true,\n amount: shippingMethod.amount,\n amountExclTax: shippingMethod.amountExclTax,\n amountInclTax: shippingMethod.amountInclTax,\n };\n }\n\n setData(shippingData);\n }, []);\n\n useEffect(() => {\n if (!active) return;\n\n const onShippingEstimate = events.on(\n 'shipping/estimate',\n handleShippingEstimate,\n { eager: true }\n );\n\n return () => {\n onShippingEstimate?.off();\n };\n }, [active, handleShippingEstimate]);\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n handleCheckoutData,\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n const renderPrice = () => {\n if (isFreeShipping) {\n return (\n <span data-testid=\"free-shipping\">{translations.freeShipping}</span>\n );\n }\n\n if (taxIncluded && data?.amountInclTax) {\n return (\n <Price\n amount={data.amountInclTax.value}\n currency={data.amountInclTax.currency}\n data-testid=\"shipping\"\n />\n );\n }\n\n return (\n <Price\n amount={data?.amount.value}\n currency={data?.amount.currency}\n data-testid=\"shipping\"\n />\n );\n };\n\n const renderPriceExclTax = () => {\n if (!data?.amountExclTax)\n return <span>{translations.taxToBeDetermined}</span>;\n\n return (\n <Price\n amount={data.amountExclTax.value}\n currency={data.amountExclTax.currency}\n data-testid=\"shipping-excluding-tax\"\n />\n );\n };\n\n const renderLabel = () => {\n const label = data?.estimated ? translations.estimated : translations.label;\n return <span data-testid=\"estimate-shipping-label\">{label}</span>;\n };\n\n return (\n <EstimateShippingComponent\n initialized={data !== undefined}\n label={renderLabel()}\n price={renderPrice()}\n priceExclTax={renderPriceExclTax()}\n taxExcluded={taxExcluded && !isFreeShipping}\n taxIncluded={taxIncluded && !isFreeShipping}\n visible={active && data !== null}\n />\n );\n};\n"],"names":["EstimateShippingSkeleton","jsx","Skeleton","SkeletonRow","EstimateShippingComponent","label","price","priceExclTax","taxExcluded","taxIncluded","translations","useText","jsxs","VComponent","classes","EstimateShipping","WithConditionals","active","data","setData","useState","isFreeShipping","shippingDisplay","_a","state","TaxDisplay","handleCheckoutData","useCallback","isEmptyCart","isVirtualCart","primaryAddress","shippingMethod","amount","amountExclTax","amountInclTax","handleShippingEstimate","estimation","shippingData","useEffect","onShippingEstimate","events","pastUpdate","getLatestCheckoutUpdate","onCheckoutInit","onCheckoutUpdated","renderPrice","Price","renderPriceExclTax"],"mappings":"wzBAoBO,MAAMA,EAA8C,IAEvDC,EAACC,GAAS,cAAY,6BACpB,WAACC,EAAY,CAAA,KAAK,SAAS,CAC7B,CAAA,ECSEC,EAAsE,CAAC,CAC3E,MAAAC,EACA,MAAAC,EACA,aAAAC,EACA,YAAAC,EAAc,GACd,YAAAC,EAAc,EAChB,IAAM,CACJ,MAAMC,EAAeC,EAAQ,CAC3B,UAAW,sCACX,aAAc,wCAAA,CACf,EAED,OACGC,EAAA,MAAA,CAAI,UAAU,6BAA6B,cAAY,oBACtD,SAAA,CAAAX,EAACY,EAAW,CAAA,UAAU,oCAAoC,KAAMR,EAAO,EACtEJ,EAAAY,EAAA,CAAW,UAAU,oCAAoC,KAAMP,EAAO,EAEtEG,GACCR,EAAC,OAAA,CACC,UAAWa,EAAQ,CAAC,qCAAqC,CAAC,EAC1D,cAAY,wBAEX,SAAaJ,EAAA,SAAA,CAChB,EAGDF,GACCI,EAAC,OAAA,CACC,UAAWE,EAAQ,CAAC,qCAAqC,CAAC,EAC1D,cAAY,iCAEX,SAAA,CAAAP,EAAa,IACbG,EAAa,YAAA,CAAA,CAAA,CAChB,EAEJ,CAEJ,EAEaK,EAAmBC,EAC9BZ,EACAJ,CACF,EChCae,GAAqD,CAAC,CACjE,OAAAE,EAAS,EACX,IAAM,OACJ,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAA0C,EAE5DC,GAAiBH,GAAA,YAAAA,EAAM,OAAO,SAAU,EACxCI,GAAkBC,EAAAC,EAAM,SAAN,YAAAD,EAAc,2BAA2B,SAC3Df,EAAcc,IAAoBG,EAAW,wBAC7ChB,EAAca,IAAoBG,EAAW,cAE7Cf,EAAeC,EAAQ,CAC3B,aAAc,yCACd,kBAAmB,8CACnB,MAAO,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from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/errors.js";import{VComponent as G,classes as se,Slot as J}from"@dropins/tools/lib.js";import{events as H}from"@dropins/tools/event-bus.js";import{W as ce,a as me,g as ue}from"../chunks/ConditionalWrapper.js";import{n as M,g as K}from"../chunks/values.js";import{i as he,s as de,g as ge}from"../chunks/setGuestEmailOnCart.js";import{Field as fe,Input as pe,Skeleton as ke,SkeletonRow as Q}from"@dropins/tools/components.js";import{useText as I}from"@dropins/tools/i18n.js";/* empty css */import"../chunks/TermsAndConditions.js";/* empty css */import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{useState as k,useRef as Le,useCallback as d,useEffect as $,useMemo as B}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const ve={EMAIL:/^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i},D=n=>ve.EMAIL.test(n),Fe=({value:n,error:o,hint:a,onChange:g,onBlur:L,onInvalid:c})=>{const l=I({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return r(fe,{error:o,hint:a,children:r(pe,{"aria-label":l.LoginFormLabel,"aria-required":!0,autocomplete:"email",floatingLabel:l.LoginFormFloatingLabel,id:"customer-email",name:"customer-email",placeholder:l.LoginFormPlaceholder,required:!0,type:"email",value:n,onBlur:L,onChange:g,onInvalid:c})})},_e=({onClick:n})=>{const o=I({account:"Checkout.LoginForm.account",signIn:"Checkout.LoginForm.signIn"});return u("div",{className:"checkout-login-form__sign-in",children:[o.account,r("a",{className:"checkout-login-form__link","data-testid":"sign-in-link",href:"#",rel:"noreferrer",target:"_blank",onClick:a=>{a.preventDefault(),n(a)},children:o.signIn})]})},Ee=()=>u(ke,{"data-testid":"login-form-skeleton",children:[r(Q,{fullWidth:!0,variant:"heading"}),r(Q,{fullWidth:!0,size:"medium"})]}),be=({className:n,customer:o,email:a,error:g,headingContent:L,hint:c,name:l,onEmailBlur:f,onEmailChange:m,onEmailInvalid:s,title:F,...A})=>u("div",{className:"checkout-login-form","data-testid":"checkout-login-form",children:[u("div",{className:"checkout-login-form__heading",children:[F&&r(G,{className:"checkout-login-form__title",node:F}),L&&r(G,{className:"checkout-login-form__heading-label",node:L})]}),o?u("div",{className:"checkout-login-form__customer-details",children:[r("div",{className:"checkout-login-form__customer-name",children:`${o.firstName} ${o.lastName}`}),r("div",{className:"checkout-login-form__customer-email",children:o.email})]}):r("div",{className:"checkout-login-form__content",children:u("form",{...A,noValidate:!0,className:se(["dropin-login-form__form",n]),name:l,children:[r("button",{disabled:!0,"aria-hidden":"true",style:"display: none",type:"submit"}),r(Fe,{error:g,hint:c,value:a,onBlur:f,onChange:m,onInvalid:s})]})})]}),Ce=ce(be,Ee),Ne=({onClick:n})=>{const o=I({switch:"Checkout.LoginForm.switch",signOut:"Checkout.LoginForm.signOut"});return u("p",{className:"checkout-login-form__sign-out",children:[o.switch,r("a",{className:"checkout-login-form__link",href:"#",rel:"noreferrer",target:"_blank",onClick:a=>{a.preventDefault(),n==null||n(a)},children:o.signOut})]})},Ie=1e3,Je=({active:n=!0,autoSync:o=!0,displayHeadingContent:a=!0,displayTitle:g=!0,initialData:L,onCartSyncError:c,onSignInClick:l,onSignOutClick:f,onValidationError:m,slots:s,...F})=>{const[A,X]=k(null),[Y,y]=k(""),[Z,p]=k(""),[z,S]=k(!1),[w,_]=k(!0),[ee,V]=k(!1),h=Le(null),{alreadyHaveAccountHint:W,cartSyncError:P,defaultTitle:j,fasterCheckoutHint:q,invalidEmailError:E,missingEmailError:b,signInLabel:O}=I({alreadyHaveAccountHint:"Checkout.LoginForm.emailExists.alreadyHaveAccount",cartSyncError:"Checkout.LoginForm.cartSyncError",defaultTitle:"Checkout.LoginForm.title",fasterCheckoutHint:"Checkout.LoginForm.emailExists.forFasterCheckout",invalidEmailError:"Checkout.LoginForm.invalidEmailError",missingEmailError:"Checkout.LoginForm.missingEmailError",signInLabel:"Checkout.LoginForm.emailExists.signInButton"}),C=d(e=>{!D(e)||e===me()||(he(e).then(t=>{_(t)}).catch(t=>{console.error(t),_(!0)}),o&&de(e).catch(t=>{c==null||c({email:e,error:t}),c||p(P)}))},[o,c,P]),te=d(e=>{const i=e.target.value;y(i),_(!0),p(""),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{C(i),M({email:i}),h.current=null},Ie)},[C]),ie=d(e=>{const t=e.target,i=t.value.trim();if(D(i)){if(p(""),t.setCustomValidity(""),!h.current)return;clearTimeout(h.current),h.current=null,C(i),M({email:i});return}const U=i===""?"missing":"invalid",T=U==="missing"?b:E;if(m){m({email:i,message:T,type:U});return}p(T),t.setCustomValidity(T)},[E,b,m,C]),re=d(e=>{const t=e.target,i=t.validity,x=i.valueMissing?b:E;if(!m){p(x);return}m({email:t.value,message:x,type:i.valueMissing?"missing":"invalid"})},[b,E,m]),N=d(()=>{const e=K("email")??"",t=D(e);l==null||l(t?e:"")},[l]),R=d(()=>{f==null||f()},[f]),v=d(e=>{const t=K("email")??"",i=(e==null?void 0:e.email)??"";i!==t&&(y(i),p(""),_(!0),M({email:i}))},[]);$(()=>{if(!n)return;const e=H.on("authenticated",t=>{S(t),ge().then(i=>{X(i)}).catch(console.error)},{eager:!0});return()=>{e==null||e.off()}},[n]),$(()=>{if(!n)return;const e=ue();if(e){V(!0);const i=e.email??"";i&&y(i),v(e);return}const t=H.on("checkout/initialized",i=>{V(!0),v(i)},{eager:!0});return()=>{t==null||t.off()}},[n,v]),$(()=>{if(!n)return;const e=H.on("checkout/updated",v,{eager:!1});return()=>{e==null||e.off()}},[n,v]);const ne=B(()=>{if(g)return r(J,{name:"checkout-login-form-title",slot:s==null?void 0:s.Title,children:r("h2",{children:j})})},[g,s,j]),oe=B(()=>{if(a)return r(J,{context:{authenticated:z},name:"checkout-login-form-heading-label",slot:s==null?void 0:s.Heading,children:z?r(Ne,{onClick:R}):r(_e,{onClick:N})})},[a,z,s,N,R]),ae=B(()=>w?"":u(le,{children:[W," ",r("a",{href:"#",onClick:N,children:O})," ",q]}),[w,W,O,q,N]);return r(Ce,{...F,customer:A,email:Y,error:Z,headingContent:oe,hint:ae,initialized:ee,title:ne,visible:n,onEmailBlur:ie,onEmailChange:te,onEmailInvalid:re})};export{Je as LoginForm,Je as default};
3
+ import{jsx as r,jsxs as u,Fragment as le}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/fetch-graphql.js";import{VComponent as G,classes as se,Slot as J}from"@dropins/tools/lib.js";import{W as ce,a as me,g as ue}from"../chunks/ConditionalWrapper.js";import{n as H,g as K}from"../chunks/values.js";import{events as M}from"@dropins/tools/event-bus.js";import{i as he,s as de,g as ge}from"../chunks/setGuestEmailOnCart.js";import{Field as fe,Input as pe,Skeleton as ke,SkeletonRow as Q}from"@dropins/tools/components.js";import{useText as I}from"@dropins/tools/i18n.js";/* empty css */import"../chunks/TermsAndConditions.js";/* empty css */import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{useState as k,useRef as Le,useCallback as d,useEffect as $,useMemo as B}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const ve={EMAIL:/^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i},D=n=>ve.EMAIL.test(n),Fe=({value:n,error:o,hint:a,onChange:g,onBlur:L,onInvalid:c})=>{const l=I({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return r(fe,{error:o,hint:a,children:r(pe,{"aria-label":l.LoginFormLabel,"aria-required":!0,autocomplete:"email",floatingLabel:l.LoginFormFloatingLabel,id:"customer-email",name:"customer-email",placeholder:l.LoginFormPlaceholder,required:!0,type:"email",value:n,onBlur:L,onChange:g,onInvalid:c})})},_e=({onClick:n})=>{const o=I({account:"Checkout.LoginForm.account",signIn:"Checkout.LoginForm.signIn"});return u("div",{className:"checkout-login-form__sign-in",children:[o.account,r("a",{className:"checkout-login-form__link","data-testid":"sign-in-link",href:"#",rel:"noreferrer",target:"_blank",onClick:a=>{a.preventDefault(),n(a)},children:o.signIn})]})},Ee=()=>u(ke,{"data-testid":"login-form-skeleton",children:[r(Q,{fullWidth:!0,variant:"heading"}),r(Q,{fullWidth:!0,size:"medium"})]}),be=({className:n,customer:o,email:a,error:g,headingContent:L,hint:c,name:l,onEmailBlur:f,onEmailChange:m,onEmailInvalid:s,title:F,...A})=>u("div",{className:"checkout-login-form","data-testid":"checkout-login-form",children:[u("div",{className:"checkout-login-form__heading",children:[F&&r(G,{className:"checkout-login-form__title",node:F}),L&&r(G,{className:"checkout-login-form__heading-label",node:L})]}),o?u("div",{className:"checkout-login-form__customer-details",children:[r("div",{className:"checkout-login-form__customer-name",children:`${o.firstName} ${o.lastName}`}),r("div",{className:"checkout-login-form__customer-email",children:o.email})]}):r("div",{className:"checkout-login-form__content",children:u("form",{...A,noValidate:!0,className:se(["dropin-login-form__form",n]),name:l,children:[r("button",{disabled:!0,"aria-hidden":"true",style:"display: none",type:"submit"}),r(Fe,{error:g,hint:c,value:a,onBlur:f,onChange:m,onInvalid:s})]})})]}),Ce=ce(be,Ee),Ne=({onClick:n})=>{const o=I({switch:"Checkout.LoginForm.switch",signOut:"Checkout.LoginForm.signOut"});return u("p",{className:"checkout-login-form__sign-out",children:[o.switch,r("a",{className:"checkout-login-form__link",href:"#",rel:"noreferrer",target:"_blank",onClick:a=>{a.preventDefault(),n==null||n(a)},children:o.signOut})]})},Ie=1e3,Je=({active:n=!0,autoSync:o=!0,displayHeadingContent:a=!0,displayTitle:g=!0,initialData:L,onCartSyncError:c,onSignInClick:l,onSignOutClick:f,onValidationError:m,slots:s,...F})=>{const[A,X]=k(null),[Y,y]=k(""),[Z,p]=k(""),[z,S]=k(!1),[w,_]=k(!0),[ee,V]=k(!1),h=Le(null),{alreadyHaveAccountHint:W,cartSyncError:P,defaultTitle:j,fasterCheckoutHint:q,invalidEmailError:E,missingEmailError:b,signInLabel:O}=I({alreadyHaveAccountHint:"Checkout.LoginForm.emailExists.alreadyHaveAccount",cartSyncError:"Checkout.LoginForm.cartSyncError",defaultTitle:"Checkout.LoginForm.title",fasterCheckoutHint:"Checkout.LoginForm.emailExists.forFasterCheckout",invalidEmailError:"Checkout.LoginForm.invalidEmailError",missingEmailError:"Checkout.LoginForm.missingEmailError",signInLabel:"Checkout.LoginForm.emailExists.signInButton"}),C=d(e=>{!D(e)||e===me()||(he(e).then(t=>{_(t)}).catch(t=>{console.error(t),_(!0)}),o&&de(e).catch(t=>{c==null||c({email:e,error:t}),c||p(P)}))},[o,c,P]),te=d(e=>{const i=e.target.value;y(i),_(!0),p(""),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{C(i),H({email:i}),h.current=null},Ie)},[C]),ie=d(e=>{const t=e.target,i=t.value.trim();if(D(i)){if(p(""),t.setCustomValidity(""),!h.current)return;clearTimeout(h.current),h.current=null,C(i),H({email:i});return}const U=i===""?"missing":"invalid",T=U==="missing"?b:E;if(m){m({email:i,message:T,type:U});return}p(T),t.setCustomValidity(T)},[E,b,m,C]),re=d(e=>{const t=e.target,i=t.validity,x=i.valueMissing?b:E;if(!m){p(x);return}m({email:t.value,message:x,type:i.valueMissing?"missing":"invalid"})},[b,E,m]),N=d(()=>{const e=K("email")??"",t=D(e);l==null||l(t?e:"")},[l]),R=d(()=>{f==null||f()},[f]),v=d(e=>{const t=K("email")??"",i=(e==null?void 0:e.email)??"";i!==t&&(y(i),p(""),_(!0),H({email:i}))},[]);$(()=>{if(!n)return;const e=M.on("authenticated",t=>{S(t),ge().then(i=>{X(i)}).catch(console.error)},{eager:!0});return()=>{e==null||e.off()}},[n]),$(()=>{if(!n)return;const e=ue();if(e){V(!0);const i=e.email??"";i&&y(i),v(e);return}const t=M.on("checkout/initialized",i=>{V(!0),v(i)},{eager:!0});return()=>{t==null||t.off()}},[n,v]),$(()=>{if(!n)return;const e=M.on("checkout/updated",v,{eager:!1});return()=>{e==null||e.off()}},[n,v]);const ne=B(()=>{if(g)return r(J,{name:"checkout-login-form-title",slot:s==null?void 0:s.Title,children:r("h2",{children:j})})},[g,s,j]),oe=B(()=>{if(a)return r(J,{context:{authenticated:z},name:"checkout-login-form-heading-label",slot:s==null?void 0:s.Heading,children:z?r(Ne,{onClick:R}):r(_e,{onClick:N})})},[a,z,s,N,R]),ae=B(()=>w?"":u(le,{children:[W," ",r("a",{href:"#",onClick:N,children:O})," ",q]}),[w,W,O,q,N]);return r(Ce,{...F,customer:A,email:Y,error:Z,headingContent:oe,hint:ae,initialized:ee,title:ne,visible:n,onEmailBlur:ie,onEmailChange:te,onEmailInvalid:re})};export{Je as LoginForm,Je as default};
4
4
  //# sourceMappingURL=LoginForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LoginForm.js","sources":["/@dropins/storefront-checkout/src/lib/validation.ts","/@dropins/storefront-checkout/src/components/LoginForm/Email.tsx","/@dropins/storefront-checkout/src/components/LoginForm/SignIn.tsx","/@dropins/storefront-checkout/src/components/LoginForm/LoginFormSkeleton.tsx","/@dropins/storefront-checkout/src/components/LoginForm/LoginForm.tsx","/@dropins/storefront-checkout/src/components/LoginForm/SignOut.tsx","/@dropins/storefront-checkout/src/containers/LoginForm/LoginForm.tsx"],"sourcesContent":["export const validationPatterns = {\n EMAIL:\n /^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\\.)+[a-z]{2,}$/i,\n};\n\nexport const validateEmail = (email: string): boolean => {\n return validationPatterns.EMAIL.test(email);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Field, Input } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { FunctionComponent } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface LoginEmailProps extends HTMLAttributes<HTMLInputElement> {\n value: string;\n error: string;\n hint: string;\n onChange: (event: Event) => void;\n onBlur: (event: Event) => void;\n onInvalid: (event: Event) => void;\n}\n\nexport const Email: FunctionComponent<LoginEmailProps> = ({\n value,\n error,\n hint,\n onChange,\n onBlur,\n onInvalid,\n}) => {\n const translations = useText({\n LoginFormLabel: 'Checkout.LoginForm.ariaLabel',\n LoginFormFloatingLabel: 'Checkout.LoginForm.floatingLabel',\n LoginFormPlaceholder: 'Checkout.LoginForm.placeholder',\n });\n\n return (\n <Field error={error} hint={hint}>\n <Input\n aria-label={translations.LoginFormLabel}\n aria-required={true}\n autocomplete=\"email\"\n floatingLabel={translations.LoginFormFloatingLabel}\n id=\"customer-email\"\n name=\"customer-email\"\n placeholder={translations.LoginFormPlaceholder}\n required={true}\n type=\"email\"\n value={value}\n onBlur={onBlur}\n onChange={onChange}\n onInvalid={onInvalid}\n />\n </Field>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { FunctionComponent } from 'preact';\n\ninterface SignInProps {\n onClick: (event: Event) => void;\n}\n\nexport const SignIn: FunctionComponent<SignInProps> = ({ onClick }) => {\n const translations = useText({\n account: 'Checkout.LoginForm.account',\n signIn: 'Checkout.LoginForm.signIn'\n });\n\n return (\n <div className=\"checkout-login-form__sign-in\">\n {translations.account}\n\n <a\n className=\"checkout-login-form__link\"\n data-testid=\"sign-in-link\"\n href=\"#\"\n rel=\"noreferrer\"\n target=\"_blank\"\n onClick={(event) => {\n event.preventDefault();\n onClick(event);\n }}\n >\n {translations.signIn}\n </a>\n </div>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const LoginFormSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"login-form-skeleton\">\n <SkeletonRow fullWidth={true} variant=\"heading\" />\n <SkeletonRow fullWidth={true} size=\"medium\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Email } from '@/checkout/components';\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/ConditionalWrapper';\nimport '@/checkout/components/LoginForm/LoginForm.css';\nimport { LoginFormSkeleton } from '@/checkout/components/LoginForm/LoginFormSkeleton';\nimport { Customer } from '@/checkout/data/models';\nimport { classes, VComponent } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, VNode } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface LoginFormProps\n extends Omit<HTMLAttributes<HTMLFormElement>, 'title'> {\n customer: Customer | null;\n email: string;\n error: string;\n headingContent?: VNode;\n hint: string | VNode;\n onEmailBlur: (event: Event) => void;\n onEmailChange: (event: Event) => void;\n onEmailInvalid: (event: Event) => void;\n title?: VNode;\n}\n\nconst LoginFormComponent: FunctionComponent<LoginFormProps> = ({\n className,\n customer,\n email,\n error,\n headingContent,\n hint,\n name,\n onEmailBlur,\n onEmailChange,\n onEmailInvalid,\n title,\n ...props\n}) => {\n return (\n <div className=\"checkout-login-form\" data-testid=\"checkout-login-form\">\n <div className=\"checkout-login-form__heading\">\n {title && (\n <VComponent className=\"checkout-login-form__title\" node={title} />\n )}\n\n {headingContent && (\n <VComponent\n className=\"checkout-login-form__heading-label\"\n node={headingContent}\n />\n )}\n </div>\n\n {customer ? (\n <div className=\"checkout-login-form__customer-details\">\n <div className=\"checkout-login-form__customer-name\">\n {`${customer.firstName} ${customer.lastName}`}\n </div>\n\n <div className=\"checkout-login-form__customer-email\">\n {customer.email}\n </div>\n </div>\n ) : (\n <div className=\"checkout-login-form__content\">\n <form\n {...props}\n noValidate\n className={classes(['dropin-login-form__form', className])}\n name={name}\n >\n {/* Prevent 'Enter' key press from submitting this form. */}\n <button\n disabled\n aria-hidden=\"true\"\n style=\"display: none\"\n type=\"submit\"\n />\n <Email\n error={error}\n hint={hint as any}\n value={email}\n onBlur={onEmailBlur}\n onChange={onEmailChange}\n onInvalid={onEmailInvalid}\n />\n </form>\n </div>\n )}\n </div>\n );\n};\n\nexport const LoginForm = WithConditionals(\n LoginFormComponent,\n LoginFormSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { FunctionComponent } from 'preact';\n\ninterface SignOutProps {\n onClick: (event: Event) => void;\n}\n\nexport const SignOut: FunctionComponent<SignOutProps> = ({ onClick }) => {\n const translations = useText({\n switch: 'Checkout.LoginForm.switch',\n signOut: 'Checkout.LoginForm.signOut'\n });\n\n return (\n <p className=\"checkout-login-form__sign-out\">\n {translations.switch}\n\n <a\n className=\"checkout-login-form__link\"\n href=\"#\"\n rel=\"noreferrer\"\n target=\"_blank\"\n onClick={(event) => {\n event.preventDefault();\n onClick?.(event);\n }}\n >\n {translations.signOut}\n </a>\n </p>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n getCustomer,\n isEmailAvailable,\n setGuestEmailOnCart,\n} from '@/checkout/api';\nimport {\n LoginForm as LoginFormComponent,\n SignIn,\n SignOut,\n} from '@/checkout/components/LoginForm';\nimport { Cart, Customer } from '@/checkout/data/models';\nimport {\n getCartEmail,\n getLatestCheckoutUpdate,\n getValue,\n notifyValues,\n validateEmail,\n} from '@/checkout/lib';\nimport { TitleProps } from '@/checkout/types/TitleProps';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'preact/hooks';\n\ninterface ValidationError {\n email: string;\n message: string;\n type: 'missing' | 'invalid';\n}\n\ninterface CartSyncError {\n email: string;\n error: Error;\n}\n\nexport interface LoginFormProps\n extends HTMLAttributes<HTMLFormElement>,\n TitleProps {\n active?: boolean;\n autoSync?: boolean;\n displayHeadingContent?: boolean;\n onSignInClick?: (email: string) => void;\n onSignOutClick?: () => void;\n onCartSyncError?: (error: CartSyncError) => void;\n onValidationError?: (error: ValidationError) => void;\n slots?: {\n Heading?: SlotProps<{\n authenticated: boolean;\n }>;\n } & TitleProps['slots'];\n}\n\nconst DEBOUNCE_TIME = 1000;\n\nexport const LoginForm: Container<LoginFormProps> = ({\n active = true,\n autoSync = true,\n displayHeadingContent = true,\n displayTitle = true,\n initialData,\n onCartSyncError,\n onSignInClick,\n onSignOutClick,\n onValidationError,\n slots,\n ...props\n}) => {\n const [customer, setCustomer] = useState<Customer | null>(null);\n const [email, setEmail] = useState<string>('');\n const [error, setError] = useState<string>('');\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n const [isAvailable, setIsAvailable] = useState<boolean>(true);\n const [isInitialized, setIsInitialized] = useState<boolean>(false);\n\n const debounceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const {\n alreadyHaveAccountHint,\n cartSyncError,\n defaultTitle,\n fasterCheckoutHint,\n invalidEmailError,\n missingEmailError,\n signInLabel,\n } = useText({\n alreadyHaveAccountHint: 'Checkout.LoginForm.emailExists.alreadyHaveAccount',\n cartSyncError: 'Checkout.LoginForm.cartSyncError',\n defaultTitle: 'Checkout.LoginForm.title',\n fasterCheckoutHint: 'Checkout.LoginForm.emailExists.forFasterCheckout',\n invalidEmailError: 'Checkout.LoginForm.invalidEmailError',\n missingEmailError: 'Checkout.LoginForm.missingEmailError',\n signInLabel: 'Checkout.LoginForm.emailExists.signInButton',\n });\n\n const setEmailAndCheckAvailability = useCallback(\n (email: string) => {\n if (!validateEmail(email) || email === getCartEmail()) return;\n\n isEmailAvailable(email)\n .then((availability) => {\n setIsAvailable(availability);\n })\n .catch((error) => {\n console.error(error);\n setIsAvailable(true);\n });\n\n if (!autoSync) return;\n\n setGuestEmailOnCart(email).catch((error) => {\n onCartSyncError?.({ email, error });\n\n if (!onCartSyncError) {\n setError(cartSyncError);\n }\n });\n },\n [autoSync, onCartSyncError, cartSyncError]\n );\n\n const handleChange = useCallback(\n (event: Event) => {\n const target = event.target as HTMLInputElement;\n const email = target.value;\n\n setEmail(email);\n setIsAvailable(true);\n setError('');\n\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current);\n }\n\n debounceTimer.current = setTimeout(() => {\n setEmailAndCheckAvailability(email);\n notifyValues({ email });\n debounceTimer.current = null;\n }, DEBOUNCE_TIME);\n },\n [setEmailAndCheckAvailability]\n );\n\n const handleBlur = useCallback(\n (event: Event) => {\n const target = event.target as HTMLInputElement;\n const email = target.value.trim();\n const isValid = validateEmail(email);\n\n if (isValid) {\n setError('');\n target.setCustomValidity('');\n\n if (!debounceTimer.current) return;\n\n clearTimeout(debounceTimer.current);\n debounceTimer.current = null;\n setEmailAndCheckAvailability(email);\n notifyValues({ email });\n return;\n }\n\n const type = email === '' ? 'missing' : 'invalid';\n const message =\n type === 'missing' ? missingEmailError : invalidEmailError;\n\n if (onValidationError) {\n onValidationError({ email, message, type });\n return;\n }\n\n setError(message);\n target.setCustomValidity(message);\n },\n [\n invalidEmailError,\n missingEmailError,\n onValidationError,\n setEmailAndCheckAvailability,\n ]\n );\n\n const handleInvalid = useCallback(\n (event: Event) => {\n const target = event.target as HTMLInputElement;\n const validity = target.validity;\n\n const message = validity.valueMissing\n ? missingEmailError\n : invalidEmailError;\n\n if (!onValidationError) {\n setError(message);\n return;\n }\n\n onValidationError({\n email: target.value,\n message,\n type: validity.valueMissing ? 'missing' : 'invalid',\n });\n },\n [missingEmailError, invalidEmailError, onValidationError]\n );\n\n const handleSignIn = useCallback(() => {\n const email = getValue('email') ?? '';\n const isValid = validateEmail(email);\n onSignInClick?.(isValid ? email : '');\n }, [onSignInClick]);\n\n const handleSignOut = useCallback(() => {\n onSignOutClick?.();\n }, [onSignOutClick]);\n\n const handleCheckoutData = useCallback((data: Cart | null) => {\n const prevEmail = getValue('email') ?? '';\n const email = data?.email ?? '';\n\n if (email !== prevEmail) {\n setEmail(email);\n setError('');\n setIsAvailable(true);\n notifyValues({ email });\n }\n }, []);\n\n useEffect(() => {\n if (!active) return;\n\n const onAuthenticated = events.on(\n 'authenticated',\n (authenticated) => {\n setIsAuthenticated(authenticated);\n\n getCustomer()\n .then((customer) => {\n setCustomer(customer);\n })\n .catch(console.error);\n },\n { eager: true }\n );\n\n return () => {\n onAuthenticated?.off();\n };\n }, [active]);\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n // When component becomes active, restore local state from checkout data\n const checkoutEmail = pastUpdate.email ?? '';\n if (checkoutEmail) {\n setEmail(checkoutEmail);\n }\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n const titleContent = useMemo(() => {\n if (!displayTitle) return undefined;\n\n return (\n <Slot name=\"checkout-login-form-title\" slot={slots?.Title}>\n <h2>{defaultTitle}</h2>\n </Slot>\n );\n }, [displayTitle, slots, defaultTitle]);\n\n const headingContent = useMemo(() => {\n if (!displayHeadingContent) return undefined;\n\n return (\n <Slot\n context={{ authenticated: isAuthenticated }}\n name=\"checkout-login-form-heading-label\"\n slot={slots?.Heading}\n >\n {isAuthenticated ? (\n <SignOut onClick={handleSignOut} />\n ) : (\n <SignIn onClick={handleSignIn} />\n )}\n </Slot>\n );\n }, [\n displayHeadingContent,\n isAuthenticated,\n slots,\n handleSignIn,\n handleSignOut,\n ]);\n\n const hintContent = useMemo(() => {\n if (isAvailable) return '';\n\n return (\n <>\n {alreadyHaveAccountHint}{' '}\n <a href=\"#\" onClick={handleSignIn}>\n {signInLabel}\n </a>{' '}\n {fasterCheckoutHint}\n </>\n );\n }, [\n isAvailable,\n alreadyHaveAccountHint,\n signInLabel,\n fasterCheckoutHint,\n handleSignIn,\n ]);\n\n return (\n <LoginFormComponent\n {...props}\n customer={customer}\n email={email}\n error={error}\n headingContent={headingContent}\n hint={hintContent}\n initialized={isInitialized}\n title={titleContent}\n visible={active}\n onEmailBlur={handleBlur}\n onEmailChange={handleChange}\n onEmailInvalid={handleInvalid}\n />\n );\n};\n"],"names":["validationPatterns","validateEmail","email","Email","value","error","hint","onChange","onBlur","onInvalid","translations","useText","jsx","Field","Input","SignIn","onClick","jsxs","event","LoginFormSkeleton","Skeleton","SkeletonRow","LoginFormComponent","className","customer","headingContent","name","onEmailBlur","onEmailChange","onEmailInvalid","title","props","VComponent","classes","LoginForm","WithConditionals","SignOut","DEBOUNCE_TIME","active","autoSync","displayHeadingContent","displayTitle","initialData","onCartSyncError","onSignInClick","onSignOutClick","onValidationError","slots","setCustomer","useState","setEmail","setError","isAuthenticated","setIsAuthenticated","isAvailable","setIsAvailable","isInitialized","setIsInitialized","debounceTimer","useRef","alreadyHaveAccountHint","cartSyncError","defaultTitle","fasterCheckoutHint","invalidEmailError","missingEmailError","signInLabel","setEmailAndCheckAvailability","useCallback","getCartEmail","isEmailAvailable","availability","setGuestEmailOnCart","handleChange","notifyValues","handleBlur","target","type","message","handleInvalid","validity","handleSignIn","getValue","isValid","handleSignOut","handleCheckoutData","data","prevEmail","useEffect","onAuthenticated","events","authenticated","getCustomer","pastUpdate","getLatestCheckoutUpdate","checkoutEmail","onCheckoutInit","onCheckoutUpdated","titleContent","useMemo","Slot","hintContent","Fragment"],"mappings":"giCAAO,MAAMA,GAAqB,CAChC,MACE,6FACJ,EAEaC,EAAiBC,GACrBF,GAAmB,MAAM,KAAKE,CAAK,ECyB/BC,GAA4C,CAAC,CACxD,MAAAC,EACA,MAAAC,EACA,KAAAC,EACA,SAAAC,EACA,OAAAC,EACA,UAAAC,CACF,IAAM,CACJ,MAAMC,EAAeC,EAAQ,CAC3B,eAAgB,+BAChB,uBAAwB,mCACxB,qBAAsB,gCAAA,CACvB,EAGC,OAAAC,EAACC,GAAM,CAAA,MAAAR,EAAc,KAAAC,EACnB,SAAAM,EAACE,GAAA,CACC,aAAYJ,EAAa,eACzB,gBAAe,GACf,aAAa,QACb,cAAeA,EAAa,uBAC5B,GAAG,iBACH,KAAK,iBACL,YAAaA,EAAa,qBAC1B,SAAU,GACV,KAAK,QACL,MAAAN,EACA,OAAAI,EACA,SAAAD,EACA,UAAAE,CAAA,CAAA,EAEJ,CAEJ,ECxCaM,GAAyC,CAAC,CAAE,QAAAC,KAAc,CACrE,MAAMN,EAAeC,EAAQ,CAC3B,QAAS,6BACT,OAAQ,2BAAA,CACT,EAGC,OAAAM,EAAC,MAAI,CAAA,UAAU,+BACZ,SAAA,CAAaP,EAAA,QAEdE,EAAC,IAAA,CACC,UAAU,4BACV,cAAY,eACZ,KAAK,IACL,IAAI,aACJ,OAAO,SACP,QAAUM,GAAU,CAClBA,EAAM,eAAe,EACrBF,EAAQE,CAAK,CACf,EAEC,SAAaR,EAAA,MAAA,CAAA,CAChB,EACF,CAEJ,EC7BaS,GAAuC,IAEhDF,EAACG,GAAS,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A,EACH,EAED,CACDT,EACAM,EACAM,EACAH,EACAkB,CAAA,CACD,EAGC,OAAArE,EAACU,GAAA,CACE,GAAGS,EACJ,SAAAP,EACA,MAAAtB,EACA,MAAAG,EACA,eAAAoB,GACA,KAAM4E,GACN,YAAa7C,GACb,MAAO0C,GACP,QAAS5D,EACT,YAAaqC,GACb,cAAeF,GACf,eAAgBM,EAAA,CAClB,CAEJ"}
1
+ {"version":3,"file":"LoginForm.js","sources":["/@dropins/storefront-checkout/src/lib/validation.ts","/@dropins/storefront-checkout/src/components/LoginForm/Email.tsx","/@dropins/storefront-checkout/src/components/LoginForm/SignIn.tsx","/@dropins/storefront-checkout/src/components/LoginForm/LoginFormSkeleton.tsx","/@dropins/storefront-checkout/src/components/LoginForm/LoginForm.tsx","/@dropins/storefront-checkout/src/components/LoginForm/SignOut.tsx","/@dropins/storefront-checkout/src/containers/LoginForm/LoginForm.tsx"],"sourcesContent":["export const validationPatterns = {\n EMAIL:\n /^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\\.)+[a-z]{2,}$/i,\n};\n\nexport const validateEmail = (email: string): boolean => {\n return validationPatterns.EMAIL.test(email);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Field, Input } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { FunctionComponent } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface LoginEmailProps extends HTMLAttributes<HTMLInputElement> {\n value: string;\n error: string;\n hint: string;\n onChange: (event: Event) => void;\n onBlur: (event: Event) => void;\n onInvalid: (event: Event) => void;\n}\n\nexport const Email: FunctionComponent<LoginEmailProps> = ({\n value,\n error,\n hint,\n onChange,\n onBlur,\n onInvalid,\n}) => {\n const translations = useText({\n LoginFormLabel: 'Checkout.LoginForm.ariaLabel',\n LoginFormFloatingLabel: 'Checkout.LoginForm.floatingLabel',\n LoginFormPlaceholder: 'Checkout.LoginForm.placeholder',\n });\n\n return (\n <Field error={error} hint={hint}>\n <Input\n aria-label={translations.LoginFormLabel}\n aria-required={true}\n autocomplete=\"email\"\n floatingLabel={translations.LoginFormFloatingLabel}\n id=\"customer-email\"\n name=\"customer-email\"\n placeholder={translations.LoginFormPlaceholder}\n required={true}\n type=\"email\"\n value={value}\n onBlur={onBlur}\n onChange={onChange}\n onInvalid={onInvalid}\n />\n </Field>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { FunctionComponent } from 'preact';\n\ninterface SignInProps {\n onClick: (event: Event) => void;\n}\n\nexport const SignIn: FunctionComponent<SignInProps> = ({ onClick }) => {\n const translations = useText({\n account: 'Checkout.LoginForm.account',\n signIn: 'Checkout.LoginForm.signIn'\n });\n\n return (\n <div className=\"checkout-login-form__sign-in\">\n {translations.account}\n\n <a\n className=\"checkout-login-form__link\"\n data-testid=\"sign-in-link\"\n href=\"#\"\n rel=\"noreferrer\"\n target=\"_blank\"\n onClick={(event) => {\n event.preventDefault();\n onClick(event);\n }}\n >\n {translations.signIn}\n </a>\n </div>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const LoginFormSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"login-form-skeleton\">\n <SkeletonRow fullWidth={true} variant=\"heading\" />\n <SkeletonRow fullWidth={true} size=\"medium\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Email } from '@/checkout/components';\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/ConditionalWrapper';\nimport '@/checkout/components/LoginForm/LoginForm.css';\nimport { LoginFormSkeleton } from '@/checkout/components/LoginForm/LoginFormSkeleton';\nimport { Customer } from '@/checkout/data/models';\nimport { classes, VComponent } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, VNode } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface LoginFormProps\n extends Omit<HTMLAttributes<HTMLFormElement>, 'title'> {\n customer: Customer | null;\n email: string;\n error: string;\n headingContent?: VNode;\n hint: string | VNode;\n onEmailBlur: (event: Event) => void;\n onEmailChange: (event: Event) => void;\n onEmailInvalid: (event: Event) => void;\n title?: VNode;\n}\n\nconst LoginFormComponent: FunctionComponent<LoginFormProps> = ({\n className,\n customer,\n email,\n error,\n headingContent,\n hint,\n name,\n onEmailBlur,\n onEmailChange,\n onEmailInvalid,\n title,\n ...props\n}) => {\n return (\n <div className=\"checkout-login-form\" data-testid=\"checkout-login-form\">\n <div className=\"checkout-login-form__heading\">\n {title && (\n <VComponent className=\"checkout-login-form__title\" node={title} />\n )}\n\n {headingContent && (\n <VComponent\n className=\"checkout-login-form__heading-label\"\n node={headingContent}\n />\n )}\n </div>\n\n {customer ? (\n <div className=\"checkout-login-form__customer-details\">\n <div className=\"checkout-login-form__customer-name\">\n {`${customer.firstName} ${customer.lastName}`}\n </div>\n\n <div className=\"checkout-login-form__customer-email\">\n {customer.email}\n </div>\n </div>\n ) : (\n <div className=\"checkout-login-form__content\">\n <form\n {...props}\n noValidate\n className={classes(['dropin-login-form__form', className])}\n name={name}\n >\n {/* Prevent 'Enter' key press from submitting this form. */}\n <button\n disabled\n aria-hidden=\"true\"\n style=\"display: none\"\n type=\"submit\"\n />\n <Email\n error={error}\n hint={hint as any}\n value={email}\n onBlur={onEmailBlur}\n onChange={onEmailChange}\n onInvalid={onEmailInvalid}\n />\n </form>\n </div>\n )}\n </div>\n );\n};\n\nexport const LoginForm = WithConditionals(\n LoginFormComponent,\n LoginFormSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { FunctionComponent } from 'preact';\n\ninterface SignOutProps {\n onClick: (event: Event) => void;\n}\n\nexport const SignOut: FunctionComponent<SignOutProps> = ({ onClick }) => {\n const translations = useText({\n switch: 'Checkout.LoginForm.switch',\n signOut: 'Checkout.LoginForm.signOut'\n });\n\n return (\n <p className=\"checkout-login-form__sign-out\">\n {translations.switch}\n\n <a\n className=\"checkout-login-form__link\"\n href=\"#\"\n rel=\"noreferrer\"\n target=\"_blank\"\n onClick={(event) => {\n event.preventDefault();\n onClick?.(event);\n }}\n >\n {translations.signOut}\n </a>\n </p>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n getCustomer,\n isEmailAvailable,\n setGuestEmailOnCart,\n} from '@/checkout/api';\nimport {\n LoginForm as LoginFormComponent,\n SignIn,\n SignOut,\n} from '@/checkout/components/LoginForm';\nimport { Cart, Customer } from '@/checkout/data/models';\nimport {\n getCartEmail,\n getLatestCheckoutUpdate,\n getValue,\n notifyValues,\n validateEmail,\n} from '@/checkout/lib';\nimport { TitleProps } from '@/checkout/types/TitleProps';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'preact/hooks';\n\ninterface ValidationError {\n email: string;\n message: string;\n type: 'missing' | 'invalid';\n}\n\ninterface CartSyncError {\n email: string;\n error: Error;\n}\n\nexport interface LoginFormProps\n extends HTMLAttributes<HTMLFormElement>,\n TitleProps {\n active?: boolean;\n autoSync?: boolean;\n displayHeadingContent?: boolean;\n onSignInClick?: (email: string) => void;\n onSignOutClick?: () => void;\n onCartSyncError?: (error: CartSyncError) => void;\n onValidationError?: (error: ValidationError) => void;\n slots?: {\n Heading?: SlotProps<{\n authenticated: boolean;\n }>;\n } & TitleProps['slots'];\n}\n\nconst DEBOUNCE_TIME = 1000;\n\nexport const LoginForm: Container<LoginFormProps> = ({\n active = true,\n autoSync = true,\n displayHeadingContent = true,\n displayTitle = true,\n initialData,\n onCartSyncError,\n onSignInClick,\n onSignOutClick,\n onValidationError,\n slots,\n ...props\n}) => {\n const [customer, setCustomer] = useState<Customer | null>(null);\n const [email, setEmail] = useState<string>('');\n const [error, setError] = useState<string>('');\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n const [isAvailable, setIsAvailable] = useState<boolean>(true);\n const [isInitialized, setIsInitialized] = useState<boolean>(false);\n\n const debounceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const {\n alreadyHaveAccountHint,\n cartSyncError,\n defaultTitle,\n fasterCheckoutHint,\n invalidEmailError,\n missingEmailError,\n signInLabel,\n } = useText({\n alreadyHaveAccountHint: 'Checkout.LoginForm.emailExists.alreadyHaveAccount',\n cartSyncError: 'Checkout.LoginForm.cartSyncError',\n defaultTitle: 'Checkout.LoginForm.title',\n fasterCheckoutHint: 'Checkout.LoginForm.emailExists.forFasterCheckout',\n invalidEmailError: 'Checkout.LoginForm.invalidEmailError',\n missingEmailError: 'Checkout.LoginForm.missingEmailError',\n signInLabel: 'Checkout.LoginForm.emailExists.signInButton',\n });\n\n const setEmailAndCheckAvailability = useCallback(\n (email: string) => {\n if (!validateEmail(email) || email === getCartEmail()) return;\n\n isEmailAvailable(email)\n .then((availability) => {\n setIsAvailable(availability);\n })\n .catch((error) => {\n console.error(error);\n setIsAvailable(true);\n });\n\n if (!autoSync) return;\n\n setGuestEmailOnCart(email).catch((error) => {\n onCartSyncError?.({ email, error });\n\n if (!onCartSyncError) {\n setError(cartSyncError);\n }\n });\n },\n [autoSync, onCartSyncError, cartSyncError]\n );\n\n const handleChange = useCallback(\n (event: Event) => {\n const target = event.target as HTMLInputElement;\n const email = target.value;\n\n setEmail(email);\n setIsAvailable(true);\n setError('');\n\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current);\n }\n\n debounceTimer.current = setTimeout(() => {\n setEmailAndCheckAvailability(email);\n notifyValues({ email });\n debounceTimer.current = null;\n }, DEBOUNCE_TIME);\n },\n [setEmailAndCheckAvailability]\n );\n\n const handleBlur = useCallback(\n (event: Event) => {\n const target = event.target as HTMLInputElement;\n const email = target.value.trim();\n const isValid = validateEmail(email);\n\n if (isValid) {\n setError('');\n target.setCustomValidity('');\n\n if (!debounceTimer.current) return;\n\n clearTimeout(debounceTimer.current);\n debounceTimer.current = null;\n setEmailAndCheckAvailability(email);\n notifyValues({ email });\n return;\n }\n\n const type = email === '' ? 'missing' : 'invalid';\n const message =\n type === 'missing' ? missingEmailError : invalidEmailError;\n\n if (onValidationError) {\n onValidationError({ email, message, type });\n return;\n }\n\n setError(message);\n target.setCustomValidity(message);\n },\n [\n invalidEmailError,\n missingEmailError,\n onValidationError,\n setEmailAndCheckAvailability,\n ]\n );\n\n const handleInvalid = useCallback(\n (event: Event) => {\n const target = event.target as HTMLInputElement;\n const validity = target.validity;\n\n const message = validity.valueMissing\n ? missingEmailError\n : invalidEmailError;\n\n if (!onValidationError) {\n setError(message);\n return;\n }\n\n onValidationError({\n email: target.value,\n message,\n type: validity.valueMissing ? 'missing' : 'invalid',\n });\n },\n [missingEmailError, invalidEmailError, onValidationError]\n );\n\n const handleSignIn = useCallback(() => {\n const email = getValue('email') ?? '';\n const isValid = validateEmail(email);\n onSignInClick?.(isValid ? email : '');\n }, [onSignInClick]);\n\n const handleSignOut = useCallback(() => {\n onSignOutClick?.();\n }, [onSignOutClick]);\n\n const handleCheckoutData = useCallback((data: Cart | null) => {\n const prevEmail = getValue('email') ?? '';\n const email = data?.email ?? '';\n\n if (email !== prevEmail) {\n setEmail(email);\n setError('');\n setIsAvailable(true);\n notifyValues({ email });\n }\n }, []);\n\n useEffect(() => {\n if (!active) return;\n\n const onAuthenticated = events.on(\n 'authenticated',\n (authenticated) => {\n setIsAuthenticated(authenticated);\n\n getCustomer()\n .then((customer) => {\n setCustomer(customer);\n })\n .catch(console.error);\n },\n { eager: true }\n );\n\n return () => {\n onAuthenticated?.off();\n };\n }, [active]);\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n // When component becomes active, restore local state from checkout data\n const checkoutEmail = pastUpdate.email ?? '';\n if (checkoutEmail) {\n setEmail(checkoutEmail);\n }\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n const titleContent = useMemo(() => {\n if (!displayTitle) return undefined;\n\n return (\n <Slot name=\"checkout-login-form-title\" slot={slots?.Title}>\n <h2>{defaultTitle}</h2>\n </Slot>\n );\n }, [displayTitle, slots, defaultTitle]);\n\n const headingContent = useMemo(() => {\n if (!displayHeadingContent) return undefined;\n\n return (\n <Slot\n context={{ authenticated: isAuthenticated }}\n name=\"checkout-login-form-heading-label\"\n slot={slots?.Heading}\n >\n {isAuthenticated ? (\n <SignOut onClick={handleSignOut} />\n ) : (\n <SignIn onClick={handleSignIn} />\n )}\n </Slot>\n );\n }, [\n displayHeadingContent,\n isAuthenticated,\n slots,\n handleSignIn,\n handleSignOut,\n ]);\n\n const hintContent = useMemo(() => {\n if (isAvailable) return '';\n\n return (\n <>\n {alreadyHaveAccountHint}{' '}\n <a href=\"#\" onClick={handleSignIn}>\n {signInLabel}\n </a>{' '}\n {fasterCheckoutHint}\n </>\n );\n }, [\n isAvailable,\n alreadyHaveAccountHint,\n signInLabel,\n fasterCheckoutHint,\n handleSignIn,\n ]);\n\n return (\n <LoginFormComponent\n {...props}\n customer={customer}\n email={email}\n error={error}\n headingContent={headingContent}\n hint={hintContent}\n initialized={isInitialized}\n title={titleContent}\n visible={active}\n onEmailBlur={handleBlur}\n onEmailChange={handleChange}\n onEmailInvalid={handleInvalid}\n />\n );\n};\n"],"names":["validationPatterns","validateEmail","email","Email","value","error","hint","onChange","onBlur","onInvalid","translations","useText","jsx","Field","Input","SignIn","onClick","jsxs","event","LoginFormSkeleton","Skeleton","SkeletonRow","LoginFormComponent","className","customer","headingContent","name","onEmailBlur","onEmailChange","onEmailInvalid","title","props","VComponent","classes","LoginForm","WithConditionals","SignOut","DEBOUNCE_TIME","active","autoSync","displayHeadingContent","displayTitle","initialData","onCartSyncError","onSignInClick","onSignOutClick","onValidationError","slots","setCustomer","useState","setEmail","setError","isAuthenticated","setIsAuthenticated","isAvailable","setIsAvailable","isInitialized","setIsInitialized","debounceTimer","useRef","alreadyHaveAccountHint","cartSyncError","defaultTitle","fasterCheckoutHint","invalidEmailError","missingEmailError","signInLabel","setEmailAndCheckAvailability","useCallback","getCartEmail","isEmailAvailable","availability","setGuestEmailOnCart","handleChange","notifyValues","handleBlur","target","type","message","handleInvalid","validity","handleSignIn","getValue","isValid","handleSignOut","handleCheckoutData","data","prevEmail","useEffect","onAuthenticated","events","authenticated","getCustomer","pastUpdate","getLatestCheckoutUpdate","checkoutEmail","onCheckoutInit","onCheckoutUpdated","titleContent","useMemo","Slot","hintContent","Fragment"],"mappings":"uiCAAO,MAAMA,GAAqB,CAChC,MACE,6FACJ,EAEaC,EAAiBC,GACrBF,GAAmB,MAAM,KAAKE,CAAK,ECyB/BC,GAA4C,CAAC,CACxD,MAAAC,EACA,MAAAC,EACA,KAAAC,EACA,SAAAC,EACA,OAAAC,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AAM,CACXY,GAAA,MAAAA,EAAmB,KACrB,CAAA,EACC,CAAC3D,EAAQ+C,CAAkB,CAAC,EAEzB,MAAAa,GAAeC,EAAQ,IAAM,CAC7B,GAAC1D,EAGH,OAAA7B,EAACwF,EAAK,CAAA,KAAK,4BAA4B,KAAMrD,GAAA,YAAAA,EAAO,MAClD,SAAAnC,EAAC,KAAI,CAAA,SAAAkD,CAAa,CAAA,EACpB,CAED,EAAA,CAACrB,EAAcM,EAAOe,CAAY,CAAC,EAEhCrC,GAAiB0E,EAAQ,IAAM,CAC/B,GAAC3D,EAGH,OAAA5B,EAACwF,EAAA,CACC,QAAS,CAAE,cAAehD,CAAgB,EAC1C,KAAK,oCACL,KAAML,GAAA,YAAAA,EAAO,QAEZ,SAAAK,IACEhB,GAAQ,CAAA,QAASgD,CAAe,CAAA,EAEjCxE,EAACG,GAAO,CAAA,QAASkE,CAAc,CAAA,CAAA,CAEnC,CAAA,EAED,CACDzC,EACAY,EACAL,EACAkC,EACAG,CAAA,CACD,EAEKiB,GAAcF,EAAQ,IACtB7C,EAAoB,GAInBrC,EAAAqF,GAAA,CAAA,SAAA,CAAA1C,EAAwB,MACxB,IAAE,CAAA,KAAK,IAAI,QAASqB,EAClB,SACHf,EAAA,EAAK,IACJH,CAAA,EACH,EAED,CACDT,EACAM,EACAM,EACAH,EACAkB,CAAA,CACD,EAGC,OAAArE,EAACU,GAAA,CACE,GAAGS,EACJ,SAAAP,EACA,MAAAtB,EACA,MAAAG,EACA,eAAAoB,GACA,KAAM4E,GACN,YAAa7C,GACb,MAAO0C,GACP,QAAS5D,EACT,YAAaqC,GACb,cAAeF,GACf,eAAgBM,EAAA,CAClB,CAEJ"}
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsxs as n,jsx as o}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Card as l,Icon as h,Image as O}from"@dropins/tools/components.js";import"../chunks/TermsAndConditions.js";import{classes as d}from"@dropins/tools/lib.js";import{S as p}from"../chunks/OrderError.js";import{useText as S}from"@dropins/tools/i18n.js";/* empty css */import"../chunks/errors.js";import{events as _}from"@dropins/tools/event-bus.js";import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{useState as g,useCallback as v,useEffect as N}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const w=({className:r,items:u,onRemoveOutOfStock:s,routeCart:t,...a})=>{const i=S({title:"Checkout.OutOfStock.title",message:"Checkout.OutOfStock.message",reviewCart:"Checkout.OutOfStock.actions.reviewCart",removeOutOfStock:"Checkout.OutOfStock.actions.removeOutOfStock"});return n(l,{className:d(["checkout-out-of-stock",r]),"data-testid":"checkout-out-of-stock",variant:"secondary",...a,children:[n("h4",{className:"checkout-out-of-stock__title",children:[o(h,{size:"16",source:p,stroke:"1"}),i.title]}),o("p",{className:"checkout-out-of-stock__message",children:i.message}),o("ol",{className:"checkout-out-of-stock__items",children:u.map(m=>o("li",{className:"checkout-out-of-stock__item","data-testid":"out-of-stock-item",children:o(O,{alt:m.image.alt,height:"100",loading:"eager",params:{width:100},src:m.image.src,width:"100"})},m.sku))}),n("div",{className:"checkout-out-of-stock__actions",children:[t&&o("a",{className:"checkout-out-of-stock__action","data-testid":"review-cart",href:t,children:i.reviewCart}),s&&o("button",{className:"checkout-out-of-stock__action","data-testid":"remove-out-of-stock",type:"button",onClick:s,children:i.removeOutOfStock})]})]})},G=({onCartProductsUpdate:r,routeCart:u,active:s=!0})=>{const[t,a]=g([]),i=v(()=>{if(!r)return;const e=t.filter(c=>c.outOfStock).map(c=>({uid:c.uid,quantity:0}));r(e)},[t,r]);if(N(()=>{if(!s)return;const e=_.on("cart/data",c=>{const k=(c==null?void 0:c.items)||[];a(k.filter(f=>f.outOfStock||f.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[s]),!s||t.length===0)return null;const m=!t.some(e=>e.insufficientQuantity);return o(w,{items:t,routeCart:u==null?void 0:u(),onRemoveOutOfStock:m?i:void 0})};export{G as OutOfStock,G as default};
3
+ import{jsxs as n,jsx as o}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Card as l,Icon as h,Image as O}from"@dropins/tools/components.js";import"../chunks/TermsAndConditions.js";import{classes as d}from"@dropins/tools/lib.js";import{S as p}from"../chunks/OrderError.js";import{useText as S}from"@dropins/tools/i18n.js";/* empty css */import"../chunks/fetch-graphql.js";import{events as _}from"@dropins/tools/event-bus.js";import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{useState as g,useCallback as v,useEffect as N}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const w=({className:r,items:u,onRemoveOutOfStock:s,routeCart:t,...a})=>{const i=S({title:"Checkout.OutOfStock.title",message:"Checkout.OutOfStock.message",reviewCart:"Checkout.OutOfStock.actions.reviewCart",removeOutOfStock:"Checkout.OutOfStock.actions.removeOutOfStock"});return n(l,{className:d(["checkout-out-of-stock",r]),"data-testid":"checkout-out-of-stock",variant:"secondary",...a,children:[n("h4",{className:"checkout-out-of-stock__title",children:[o(h,{size:"16",source:p,stroke:"1"}),i.title]}),o("p",{className:"checkout-out-of-stock__message",children:i.message}),o("ol",{className:"checkout-out-of-stock__items",children:u.map(m=>o("li",{className:"checkout-out-of-stock__item","data-testid":"out-of-stock-item",children:o(O,{alt:m.image.alt,height:"100",loading:"eager",params:{width:100},src:m.image.src,width:"100"})},m.sku))}),n("div",{className:"checkout-out-of-stock__actions",children:[t&&o("a",{className:"checkout-out-of-stock__action","data-testid":"review-cart",href:t,children:i.reviewCart}),s&&o("button",{className:"checkout-out-of-stock__action","data-testid":"remove-out-of-stock",type:"button",onClick:s,children:i.removeOutOfStock})]})]})},G=({onCartProductsUpdate:r,routeCart:u,active:s=!0})=>{const[t,a]=g([]),i=v(()=>{if(!r)return;const e=t.filter(c=>c.outOfStock).map(c=>({uid:c.uid,quantity:0}));r(e)},[t,r]);if(N(()=>{if(!s)return;const e=_.on("cart/data",c=>{const k=(c==null?void 0:c.items)||[];a(k.filter(f=>f.outOfStock||f.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[s]),!s||t.length===0)return null;const m=!t.some(e=>e.insufficientQuantity);return o(w,{items:t,routeCart:u==null?void 0:u(),onRemoveOutOfStock:m?i:void 0})};export{G as OutOfStock,G as default};
4
4
  //# sourceMappingURL=OutOfStock.js.map