diff --git a/blocks/commerce-checkout/commerce-checkout.js b/blocks/commerce-checkout/commerce-checkout.js index de1bafe8df..bf3c334867 100644 --- a/blocks/commerce-checkout/commerce-checkout.js +++ b/blocks/commerce-checkout/commerce-checkout.js @@ -65,6 +65,8 @@ import createModal from '../modal/modal.js'; import { estimateShippingCost, getCartAddress, + isCartEmpty, + isCheckoutEmpty, scrollToElement, setAddressOnCart, } from '../../scripts/checkout.js'; @@ -122,8 +124,8 @@ export default async function decorate(block) { const SHIPPING_ADDRESS_DATA_KEY = `${SHIPPING_FORM_NAME}_addressData`; const BILLING_ADDRESS_DATA_KEY = `${BILLING_FORM_NAME}_addressData`; - // Pre-fetch checkout store configuration - const storeConfig = await checkoutApi.getStoreConfig(); + // Check cart cache + const cart = cartApi.getCartDataFromCache(); // Define the Layout for the Checkout const checkoutFragment = document.createRange().createContextualFragment(` @@ -188,11 +190,53 @@ export default async function decorate(block) { block.appendChild(checkoutFragment); - // Render main containers + // Global state + let loader; + let modal; + let emptyCart; + let shippingFormSkeleton; + let billingFormSkeleton; let shippingFormRef = { current: null }; let billingFormRef = { current: null }; + let shippingForm; + let billingForm; + let shippingAddresses; + let billingAddresses; + let placeOrder; + let initialzed = false; + + // Dynamic containers and components + const showModal = async (content) => { + modal = await createModal([content]); + modal.showModal(); + }; + + const removeModal = () => { + if (!modal) return; + modal.removeModal(); + modal = null; + }; + + const displayEmptyCart = async () => { + if (emptyCart) return; + + emptyCart = await CartProvider.render(EmptyCart, { + routeCTA: () => '/', + })($emptyCart); + + $content.classList.add('checkout__content--empty'); + }; + + const removeEmptyCart = () => { + if (!emptyCart) return; + + emptyCart.remove(); + emptyCart = null; + $emptyCart.innerHTML = ''; + + $content.classList.remove('checkout__content--empty'); + }; - let loader; const displayOverlaySpinner = async () => { if (loader) return; @@ -209,58 +253,34 @@ export default async function decorate(block) { $loader.innerHTML = ''; }; - let modal; - const showModal = async (content) => { - modal = await createModal([content]); - modal.showModal(); - }; + const initializeCheckout = async () => { + if (initialzed) return; - const removeModal = () => { - if (!modal) return; - modal.removeModal(); - modal = null; - }; + await CheckoutProvider.render(MergedCartBanner)($mergedCartBanner); - const [ - _mergedCartBanner, - _heading, - _serverError, - _outOfStock, - _login, - shippingFormSkeleton, - _billToShipping, - _delivery, - _paymentMethods, - billingFormSkeleton, - _orderSummary, - _cartSummary, - placeOrder, - ] = await Promise.all([ - CheckoutProvider.render(MergedCartBanner)($mergedCartBanner), - - UI.render(Header, { + await UI.render(Header, { title: 'Checkout', size: 'large', divider: true, - })($heading), + })($heading); - CheckoutProvider.render(ServerError, { + await CheckoutProvider.render(ServerError, { onRetry: () => { $content.classList.remove('checkout__content--error'); }, onServerError: () => { $content.classList.add('checkout__content--error'); }, - })($serverError), + })($serverError); - CheckoutProvider.render(OutOfStock, { + await CheckoutProvider.render(OutOfStock, { routeCart: () => '/cart', onCartProductsUpdate: (items) => { cartApi.updateProductsFromCart(items).catch(console.error); }, - })($outOfStock), + })($outOfStock); - CheckoutProvider.render(LoginForm, { + await CheckoutProvider.render(LoginForm, { name: LOGIN_FORM_NAME, onSignInClick: async (initialEmailValue) => { const signInForm = document.createElement('div'); @@ -282,14 +302,14 @@ export default async function decorate(block) { onSignOutClick: () => { authApi.revokeCustomerToken(); }, - })($login), + })($login); - AccountProvider.render(AddressForm, { + shippingFormSkeleton = await AccountProvider.render(AddressForm, { isOpen: true, showFormLoader: true, - })($shippingForm), + })($shippingForm); - CheckoutProvider.render(BillToShippingAddress, { + await CheckoutProvider.render(BillToShippingAddress, { hideOnVirtualCart: true, onChange: (checked) => { $billingForm.style.display = checked ? 'none' : 'block'; @@ -303,20 +323,23 @@ export default async function decorate(block) { })({ data: formData, isDataValid }); } }, - })($billToShipping), + })($billToShipping); - CheckoutProvider.render(ShippingMethods, { + await CheckoutProvider.render(ShippingMethods, { hideOnVirtualCart: true, - })($delivery), + onCheckoutDataUpdate: () => { + cartApi.refreshCart().catch(console.error); + }, + })($delivery); - CheckoutProvider.render(PaymentMethods)($paymentMethods), + await CheckoutProvider.render(PaymentMethods)($paymentMethods); - AccountProvider.render(AddressForm, { + billingFormSkeleton = await AccountProvider.render(AddressForm, { isOpen: true, showFormLoader: true, - })($billingForm), + })($billingForm); - CartProvider.render(OrderSummary, { + await CartProvider.render(OrderSummary, { slots: { EstimateShipping: (esCtx) => { const estimateShippingForm = document.createElement('div'); @@ -331,9 +354,9 @@ export default async function decorate(block) { ctx.appendChild(coupons); }, }, - })($orderSummary), + })($orderSummary); - CartProvider.render(CartSummaryList, { + await CartProvider.render(CartSummaryList, { variant: 'secondary', slots: { Heading: (headingCtx) => { @@ -369,9 +392,9 @@ export default async function decorate(block) { }); }, }, - })($cartSummary), + })($cartSummary); - CheckoutProvider.render(PlaceOrder, { + placeOrder = await CheckoutProvider.render(PlaceOrder, { handleValidation: () => { let success = true; const { forms } = document; @@ -416,32 +439,11 @@ export default async function decorate(block) { removeOverlaySpinner(); }); }, - })($placeOrder), - ]); + })($placeOrder); - let emptyCart; - const displayEmptyCart = async () => { - if (emptyCart) return; - - emptyCart = await CartProvider.render(EmptyCart, { - routeCTA: () => '/', - })($emptyCart); - - $content.classList.add('checkout__content--empty'); + initialzed = true; }; - const removeEmptyCart = () => { - if (!emptyCart) return; - - emptyCart.remove(); - emptyCart = null; - $emptyCart.innerHTML = ''; - - $content.classList.remove('checkout__content--empty'); - }; - - let shippingForm; - let billingForm; const displayGuestAddressForms = async (data) => { if (data.isVirtual) { shippingForm?.remove(); @@ -474,6 +476,8 @@ export default async function decorate(block) { debounceMs: DEBOUNCE_TIME, }); + const storeConfig = checkoutApi.getStoreConfigCache(); + shippingForm = await AccountProvider.render(AddressForm, { addressesFormTitle: 'Shipping address', className: 'checkout-shipping-form__address-form', @@ -518,6 +522,8 @@ export default async function decorate(block) { placeOrderBtn: placeOrder, }); + const storeConfig = checkoutApi.getStoreConfigCache(); + billingForm = await AccountProvider.render(AddressForm, { addressesFormTitle: 'Billing address', className: 'checkout-billing-form__address-form', @@ -540,8 +546,6 @@ export default async function decorate(block) { } }; - let shippingAddresses; - let billingAddresses; const displayCustomerAddressForms = async (data) => { if (data.isVirtual) { shippingAddresses?.remove(); @@ -576,6 +580,8 @@ export default async function decorate(block) { }); } + const storeConfig = checkoutApi.getStoreConfigCache(); + const inputsDefaultValueSet = cartShippingAddress && cartShippingAddress.id === undefined ? cartShippingAddress : { countryCode: storeConfig.defaultCountry }; @@ -630,6 +636,8 @@ export default async function decorate(block) { sessionStorage.removeItem(BILLING_ADDRESS_DATA_KEY); } + const storeConfig = checkoutApi.getStoreConfigCache(); + const inputsDefaultValueSet = cartBillingAddress && cartBillingAddress.id === undefined ? cartBillingAddress : { countryCode: storeConfig.defaultCountry }; @@ -772,13 +780,19 @@ export default async function decorate(block) { })($orderConfirmationFooterContinueBtn); }; + // Display the inital view based on the cart cache + if (isCartEmpty(cart)) await displayEmptyCart(); + else await initializeCheckout(); + // Event handlers const handleCheckoutInitialized = async (data) => { - if (data === null || data.isEmpty) { + if (isCheckoutEmpty(data)) { await displayEmptyCart(); return; } + await initializeCheckout(); + if (data.isGuest) { await displayGuestAddressForms(data); } else { @@ -787,17 +801,18 @@ export default async function decorate(block) { }; const handleCheckoutUpdated = async (data) => { - if (data === null || data.isEmpty) { + if (isCheckoutEmpty(data)) { await displayEmptyCart(); return; } removeEmptyCart(); + await initializeCheckout(); if (data.isGuest) { await displayGuestAddressForms(data); } else { - await removeOverlaySpinner(); + removeOverlaySpinner(); await displayCustomerAddressForms(data); } }; diff --git a/package-lock.json b/package-lock.json index 672144dc47..f33c941661 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@dropins/storefront-account": "1.0.0-beta3", "@dropins/storefront-auth": "1.0.0-beta2", "@dropins/storefront-cart": "1.0.0-beta2", - "@dropins/storefront-checkout": "1.0.0-beta1", + "@dropins/storefront-checkout": "1.0.0-beta3", "@dropins/storefront-order": "1.0.0-beta4", "@dropins/storefront-pdp": "1.0.0-beta3", "@dropins/tools": "^0.37.0" @@ -780,9 +780,10 @@ "integrity": "sha512-zB/CXZNQ9gazZJjTEgWbLPwxFvP+AzaM0Khk28gxWi67syJhwqHQTS+aTB84zFvZ2ARkPXg+nKrMPQl3rP3UyA==" }, "node_modules/@dropins/storefront-checkout": { - "version": "1.0.0-beta1", - "resolved": "https://registry.npmjs.org/@dropins/storefront-checkout/-/storefront-checkout-1.0.0-beta1.tgz", - "integrity": "sha512-pnPfRfhOtjjd+W+W3ftO7un+j9nJ8Rk29uaVo/rkB5ubF8FELIfexqzE+0PW48xRVPZhC8RkJyEGNKi/tNtUiA==" + "version": "1.0.0-beta3", + "resolved": "https://registry.npmjs.org/@dropins/storefront-checkout/-/storefront-checkout-1.0.0-beta3.tgz", + "integrity": "sha512-qce4nWMof0yu25ZQayrpTEzroJ1lCx4M0wrtplBTtpN8ydoUmNrYhWTujnOLCqlUHSIwJVmg7LgBIlrKB6XKsw==", + "license": "SEE LICENSE IN LICENSE.md" }, "node_modules/@dropins/storefront-order": { "version": "1.0.0-beta4", diff --git a/package.json b/package.json index 9c83aa0509..42cf79d138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@dropins/storefront-account": "1.0.0-beta3", "@dropins/storefront-auth": "1.0.0-beta2", "@dropins/storefront-cart": "1.0.0-beta2", - "@dropins/storefront-checkout": "1.0.0-beta1", + "@dropins/storefront-checkout": "1.0.0-beta3", "@dropins/storefront-order": "1.0.0-beta4", "@dropins/storefront-pdp": "1.0.0-beta3", "@dropins/tools": "^0.37.0" diff --git a/scripts/__dropins__/storefront-checkout/LICENSE.md b/scripts/__dropins__/storefront-checkout/LICENSE.md new file mode 100644 index 0000000000..f1ee7eb99b --- /dev/null +++ b/scripts/__dropins__/storefront-checkout/LICENSE.md @@ -0,0 +1,127 @@ +Last Updated: 28 October 2024 + +ADOBE COMMERCE DROP-IN LICENSE AGREEMENT + +applicable to Adobe Commerce Customers + +**Effective Date:** first date you download or use the Drop-in + +NOTICE TO USER: The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the terms and conditions below which form a binding agreement between you and Adobe. **By downloading, installing, or making use of any portion of the Drop-in, you are agreeing to the following terms and conditions. If you do not agree to the terms and conditions below, do not use the Drop-in**. If you agree to be bound by this agreement on behalf of your employer or other entity, you must have the legal authority to do so. If you are not authorized to so bind your employer or such entity, do not download and do not use the Drop-in. + +Your access to and use of the Drop-in is governed by the Adobe Enterprise Licensing Terms previously agreed to by you and Adobe or an authorized Adobe Reseller in a separate agreement. If you have not previously agreed to licensing terms then your installation and use of the Drop-in is subject to the current applicable Adobe Enterprise Licensing Terms available at . You agree that this agreement will have the same effect as any written negotiated agreement signed by you. + +By downloading, installing or making use of any portion of the Drop-in, you accept and agree to be bound by all the terms and conditions of this agreement including all terms incorporated herein by reference. + +This agreement is enforceable against any person or entity that installs and uses the Drop-in and any person or entity (e.g., system integrator, consultant or contractor) that installs or uses the drop-in on another person's or entity's behalf (e.g., Adobe Customer). + +Notice to U.S. Government End Users: Products and services are “Commercial Product(s),” and “Commercial Service(s)” as those terms are defined at 48 C.F.R. section 2.101, consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation,” as the terms are used in 48 C.F.R. section 12.212 or 48 C.F.R. section 227.7202, as applicable. Customer agrees, consistent with 48 C.F.R. section 12.212 or 48 C.F.R. sections 227.7202-1 through 227.72024, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (A) only as Commercial Products and Services; and (B) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished rights are reserved under the copyright laws of the United States. + +**ADOBE COMMERCE DROP-IN LICENSE AGREEMENT** + +applicable to Developers + +**Effective Date:** first date you download or use the Drop-in + +The Adobe Commerce Drop-in (“Drop-in”) is licensed to you subject to the terms and conditions below which form a binding agreement between you and Adobe. **By downloading, installing, or making use of any portion of the Drop-in, you are agreeing to the following terms and conditions. If you do not agree to the terms and conditions below, do not use the Drop-in**. If you agree to be bound by this agreement on behalf of your employer or other entity, you must have the legal authority to do so. If you are not authorized to so bind your employer or such entity, do not download and do not use the Drop-in. + +**AGREED TERMS AND CONDITIONS** + +1. **DEFINITIONS**. + + 1.1 “**Adobe**” means collectively, Adobe Inc., a company incorporated in Delaware, U.S.A., having a place of business at 345 Park Avenue, San Jose, California USA 95110-2704, U.S.A. (“**Adobe US**”) and Adobe Systems Software Ireland, company incorporated in Ireland, having a place of business 4-6 Riverwalk, City West Business Campus, Saggart, Dublin 24, Ireland (“**Adobe Ireland**”).__ + + 1.2 “**Adobe Product(s)**” means software applications, programs and other technologies not included in or with the Drop-in which are or may be made available by Adobe for licensing to the general public. This agreement does not govern use of Adobe Products. See the end user license agreement accompanying an Adobe Product for terms governing its use. + + 1.3 “**Developer Product(s)**” means any software application(s), program(s) and other teconolog(y/ies) you develop with use of the Drop-in to function or interoperate with Adobe Products. + + 1.4 “**Intellectual Property Rights**” means copyright, moral rights, trademark, trade dress, patent, trade secret, unfair competition, and any other intellectual and proprietary rights. + + 1.5 “**Adobe Commerce Drop-in**” or “Drop-in” means all items comprising the application and all associated materials licensed to you by Adobe as part of the Drop-in, including all Drop-in system files, tools, programs and utilities, as well as any plug-ins or other application programming interfaces, header or JAR files (“**API**”), sample images, sounds, or similar assets (“**Content** **Files**”), software code samples, runtimes and libraries, including any portion(s) that is modified by you, or merged or incorporated with your Developer Products (“**Sample Code**”), and any related documentation, technical specifications, notes and explanatory materials, as well any modifications, updates, upgrades, or copies of, any of the foregoing items, that may be made available by Adobe, whether online or recorded on media, or manually downloaded by you. + +2. **LICENSES GRANTED TO YOU**. + + 2.1 **Drop-in**. Subject to your compliance with terms of this agreement, Adobe grants to you a non-exclusive, non-sublicensable, non-transferable license to install and use the Drop-in solely for your internal design, development and testing of your Developer Products, subject further to the requirements and limitations below. + + 2.2 **API.** Subject to your compliance with terms of this agreement, Adobe grants to you a non-exclusive, non-sublicensable, non-transferable license to use the API only as provided in or by the applicable specification and to distribute the API solely in, with, and on the same media as, your Developer Products. For clarification, you may not modify the API. + + 2.3 **Content Files**. You may not use, modify, reproduce or distribute any of the Content Files. For the avoidance of doubt, the Content Files are included as examples only. You acquire no rights to the Content Files. + + 2.4 **Sample Code.** Subject to your compliance with terms of this agreement, Adobe grants to you a non-exclusive, non-sublicensable, non-transferable license to use, modify, merge, and redistribute (in object code form only) all or any portions of the Sample Code solely as part of, and as necessary to properly implement, the Drop-in in your Developer Products. All and any portion of the Sample Code that is modified or merged by you in your Developer Products is subject to the terms of this agreement. + +3. **SCOPE OF LICENSE; LIMITATIONS AND RESTRICTIONS** + + 3.1 You may not distribute the Drop-ins or any of its component parts to interoperate with or to run on a platform other than the Adobe-approved platform. + + 3.2 Third-Party Software. The Drop-ins may contain third-party software, subject to additional terms and conditions, available at ; and + + 3.3 You may not modify, port, adapt, creative derivate works, redistribute, or translate any portion of this Drop-in; or add or delete any Drop-in program files that would in any way result in modifying the functionality or appearance of any element of the Adobe Products. + + 3.4 You may not reverse engineer, decompile, disassemble, or otherwise attempt to discover the source code of, any portion of the Drop-in, except and only to the extent that applicable laws of the jurisdiction where you are located grant you the right to decompile the Drop-in in order to obtain information necessary to render the Drop-in interoperable with other software; in which case you must first request the information from Adobe in writing and Adobe may, in its discretion, either provide such information to you or impose reasonable conditions, including reasonable fees, on your use of the Drop-in to ensure that Adobe’s and its licensors’ Intellectual Proprietary Rights in the Drop-in are protected. + + 3.5 You may not unbundle, repackage, distribute, rent, lease, offer, sell, resale, sublicense, assign or transfer all, or any component parts of the Drop-in, or any of your rights in the Drop-in, nor authorize any portion of the Drop-in to be copied onto another’s device, computer or platform, including on a service bureau basis to other providers (i.e., volume printing, banking, payroll service providers, etc) who provide you free or fee-based business services. + +4. **VIRAL OPEN SOURCE SOFTWARE AND SERVICES** + + You are not license to (and you agree that you will not) merge, integrate or use the Drop-in with any Viral Open Source Software or Viral Service, or otherwise take any action that could require disclosure, distribution, or licensing of all or any part of the Drop-in in source code form for any purpose whatsoever. For purposes of this Section, “**Viral Open Source Software**” means software licensed under the GNU General Public License, the GNU Affero General Public License (AGPL), the GNU Lesser General Public License (LGPL), or any other license terms that would require, or condition your use, modification, or distribution of such licensed software on the disclosure, distribution, or licensing of any other software in source code form, for the purpose of making derivative works, or at no charge, and “**Viral Service**” means any service that contains any viruses, Trojan horses, worms, time bombs, cancelbots or other computer programming routines that are intended to damage, detrimentally interfere with, surreptitiously intercept, expropriate or deprive owners’ possession of any system, data or personal information, or that in any way violates any law, statute, ordinance, regulation or rights (including any law, regulations or rights respecting intellectual property, computer spyware, privacy, export control, unfair competition, antidiscrimination or false advertising), or otherwise interferes with the operability of Adobe Products or third-party programs or software. + +5. **NON-BLOCKING OF ADOBE DEVELOPMENT** + + You acknowledge that Adobe is currently developing or may develop technologies and Adobe Products in the future that have, or may have, design or functionality similar to Developer Products that you may develop based on the license granted to you in this agreement. Nothing in this agreement will impair, limit or curtail Adobe’s right to continue with its development, maintenance or distribution of Adobe Products. You agree that you will not assert in any way any patent owned by you arising out of or in connection with your use of the Drop-in, or any Drop-in modifications made by you, against Adobe, its customers, subsidiaries or affiliates, or any of their customers, direct or indirect, agents and contractors for the manufacture, use, import, license, offer for sale, or sale of any Adobe Products. + +6. **OWNERSHIP; INTELLECTUAL PROPERTY RIGHTS** + + 6.1 The items contained in the Drop-in are the Intellectual Property of Adobe and its licensors and are protected by United States copyright and patent law, international treaty provisions and applicable laws of the country in which it is being used. Adobe and its licensors reserve all rights not expressly granted to you under this agreement, and retain all right, title, and interest in the Drop-in, including all Intellectual Property Rights. + + 6.2 The Drop-in, or any of its component parts, may be supplied to you with certain accompanying proprietary notices, including patent, copyright and trademark notices. You agree to protect all copyright and other ownership interests of Adobe and its licensors in the Drop-in supplied to you under this agreement; to preserve exactly (and not remove or alter) all proprietary notices displayed in or on the Drop-in; to reproduce the same proprietary notices in all copies you make of any portion of the Drop-in. + + 6.3 You agree to include in your Developer Products Adobe’s copyright notices, wherever such notices are customarily posted, in substantially the following form: _Portions of software used to develop this product copyrighted by Adobe and its licensors. All Rights Reserved_. + + 6.4 Nothing in this agreement gives you a right to use the name, logo or trademarks of Adobe or its licensors to market your Developer Products. + +7. **CONFIDENTIAL INFORMATION** + + With respect to the API, and any portion, included in the Drop-in (for purposes of this Section, “**Adobe Confidential Information**”), you will treat the Adobe Confidential Information, and exercise the same degree of care to protect it, as you afford to your own confidential information. Your obligations under this Section will terminate when you can document that (a) the Adobe Confidential Information was in the public domain at or subsequent to the time Adobe communicated or provided it to you with no fault of your own; (b) your employees or agents developed independently without reference to any Adobe Confidential Information Adobe communicated or provided to you; or (c) your communication of Adobe Confidential Information was in response to a valid order by a court or other governmental body, was otherwise required by law, or was necessary to establish the rights of a party under this agreement. + +8. **TERM; TERMINATION** + + This agreement will commence on the Effective Date and will continue unless terminated. Adobe may terminate this agreement immediately upon notice to you, and without judicial intervention, if you fail to comply with any term of its terms. You may terminate this agreement at any time by discontinuing all your use(s) of the Drop-in and you agree to destroying or removing all full and partial copies of the Drop-in from your computer. If requested by Adobe, you must demonstrate proof of your compliance with the terms of this Section. In the event of termination, the terms of this agreement that, by their nature, are meant to survive termination, including all terms relating to viral open source software and services, ownership, confidential information, indemnity obligations and procedures, disclaimers of warranty, limitations on and exclusions of remedies and damages, dispute resolution, and waiver, will survive termination of this agreement. + +9. **DISCLAIMER OF WARRANTY; LIMITATION OF LIABILITY** + + You expressly understand and agree that, to the maximum extent permitted by applicable law: + + 9.1 **Use OF THE DROP-IN is entirely at your own risk. The Drop-in is provided by Adobe “AS-IS” and with all faults. Adobe and its licensors are not liable to you or anyone else for any special, incidental, indirect, consequential, or punitive damages whatsoever (even if Adobe has been advised of the possibility of such damages), including (a) damages resulting from loss of use, data, or profits, whether or not foreseeable, (b) damages based on any theory of liability, including breach of contract or warranty, negligence or other tortious action, or (c) damages arising from any other claim arising out of or in connection with your use of the Drop-in.** + + 9.2 **Adobe’s total liability in any matter arising out of or related to these terms is limited to US $100. This limitation will apply even if Adobe has been advised of the possibility of such damages and regardless of any failure of the essential purpose of any limited remedy.** + +10. **INDEMNIFICATION** + + To the maximum extent permitted by law, you agree to indemnify Adobe, its subsidiaries, affiliates, officers, agents, employees, partners, licensors, or suppliers from any claim or demand, including reasonable attorneys’ fees, that arise from the use and distribution of your Developer Products that contain or are based upon any portion of the Drop-in, or from your violation of the terms of this agreement. + +11. **DISPUTE RESOLUTION** + + 11.1 **Choice of Law.** If you are a resident of North America (or if your organization is headquartered in North America), your relationship is with Adobe Systems Incorporated, a United States company, and the Drop-in is governed by the law of California, U.S.A. If you reside outside of North America, your relationship is with Adobe Systems Software Ireland Limited, and the Drop-in is governed by the law of Ireland. + + 11.2 **Venue.** You agree that any claim or dispute you may have against Adobe must be resolved by a court located in Santa Clara County, California, United States of America. You agree to submit to the personal jurisdiction of the courts located in Santa Clara County, California, United States of America when the laws of California apply, and the courts of Dublin, Ireland, when the laws of Ireland applies, for the purpose of litigating such claims or disputes. The parties specifically disclaim the U.N. Convention on Contracts for the International Sale of Goods. + + 11.3 **Injunctive Relief.** Notwithstanding the foregoing, in the event of your or others’ unauthorized access to or use of the Drop-in in violation of this Agreement, you agree that Adobe is entitled to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction. + +12. **EXPORT RULES** + + The Drop-in and your use of the Drop-in are subject to U.S. and international laws, restrictions, and regulations that may govern the import, export, and use of the Drop-in. You agree to comply with all such laws, restrictions, and regulations. + +13. **NOTICE TO U.S. GOVERNMENT END USERS** + + Products and services are “Commercial Product(s),” and “Commercial Service(s)” as those terms are defined at 48 C.F.R. section 2.101, consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation,” as the terms are used in 48 C.F.R. section 12.212 or 48 C.F.R. section 227.7202, as applicable. Customer agrees, consistent with 48 C.F.R. section 12.212 or 48 C.F.R. sections 227.7202-1 through 227.72024, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (A) only as Commercial Products and Services; and (B) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished rights are reserved under the copyright laws of the United States. + +14. **GENERAL PROVISIONS** + + 14.1 **Severability.** If it turns out that a particular term is not enforceable, the unenforceability of that term will not affect any other terms. + + 14.2 **Modification; Waiver.** No provision of this agreement will be deemed to have been modified or waived by any act or acquiescence on the part of Adobe, its agents, or employees, but only by any instrument in writing, signed by an authorized officer of Adobe. + + 14.3 **English Version.** The English language version of this agreement will be the version used when interpreting or construing its terms. + + 14.4 **Entire Agreement.** This Agreement is the entire agreement, superseding any prior written or oral agreements, between you and Adobe relating to the Drop-in. + +Adobe Commerce Drop-in License Agreement_en_US-20241028_v1 diff --git a/scripts/__dropins__/storefront-checkout/api.js b/scripts/__dropins__/storefront-checkout/api.js index 7d0063f0f2..0b54e3b465 100644 --- a/scripts/__dropins__/storefront-checkout/api.js +++ b/scripts/__dropins__/storefront-checkout/api.js @@ -1,6 +1,6 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{t as _,a as f,b as h}from"./chunks/synchronizeCheckout.js";import{d as k,c as z,g as Q,e as R,i as K,f as P,r as j,s as L}from"./chunks/synchronizeCheckout.js";import{s as l,M as m,a as A,d as p,b as C}from"./chunks/fetch-graphql.js";import{D as J,F as V,I as W,f as X,c as Z,e as tt,S as st,U as et,j as it,k as at,l as rt,r as nt,g as ot,h as pt,i as dt}from"./chunks/fetch-graphql.js";import{d as S,i as y}from"./chunks/store-config.js";import"./chunks/ServerErrorSignal.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import{i as gt,s as ht}from"./chunks/setGuestEmailOnCart.js";import{a as M}from"./chunks/setBillingAddress.js";import{s as mt}from"./chunks/setBillingAddress.js";import{s as _t}from"./chunks/setPaymentMethod.js";import{CHECKOUT_DATA_FRAGMENT as I}from"./fragments.js";import{s as At}from"./chunks/setShippingMethods.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";const T=` +import{d as p,t as f,a as _,b as m}from"./chunks/synchronizeCheckout.js";import{e as k,c as z,g as Q,f as R,i as K,h as P,r as j,s as L}from"./chunks/synchronizeCheckout.js";import{M as l,a as A,b as C}from"./chunks/errors.js";import{F as J,I as V,e as W,c as X,d as Z,U as tt}from"./chunks/errors.js";import{s as d}from"./chunks/store-config.js";import{g as et}from"./chunks/store-config.js";import{i as S}from"./chunks/transform-store-config.js";import{D as rt,S as at,h as nt,j as ot,k as pt,r as dt,d as ct,f as gt,g as ht}from"./chunks/transform-store-config.js";import"./chunks/ServerErrorSignal.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import{i as lt,s as ut}from"./chunks/setGuestEmailOnCart.js";import{a as y}from"./chunks/setBillingAddress.js";import{s as _t}from"./chunks/setBillingAddress.js";import{s as Ct}from"./chunks/setPaymentMethod.js";import{CHECKOUT_DATA_FRAGMENT as M}from"./fragments.js";import{s as yt}from"./chunks/setShippingMethods.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const I=` mutation estimateShippingMethods( $cartId: String! $address: EstimateAddressInput! @@ -26,7 +26,7 @@ import{t as _,a as f,b as h}from"./chunks/synchronizeCheckout.js";import{d as k, error_message } } -`,N=async a=>{var g;const s=l.cartId,{criteria:r}=a||{},{country_code:e,region_id:t,region_name:i,zip:n}=r||{},o=e||((g=S.value.data)==null?void 0:g.defaultCountry);if(!s)throw new m;if(!o)throw new A;const d=typeof t=="string"?parseInt(t,10):t,c=t||i?{...d&&{region_id:d},...i&&{region_code:i}}:void 0,u={country_code:o,...n&&{postcode:n},...c&&{region:c}};return await p({type:"mutation",query:T,options:{variables:{cartId:s,address:u}},path:"estimateShippingMethods",signalType:"estimateShippingMethods",transformer:_})},E=` +`,N=async r=>{var h;const s=d.cartId,{criteria:a}=r||{},{country_code:e,region_id:t,region_name:i,zip:n}=a||{},o=e||((h=d.config)==null?void 0:h.defaultCountry);if(!s)throw new l;if(!o)throw new A;const c=typeof t=="string"?parseInt(t,10):t,g=t||i?{...c&&{region_id:c},...i&&{region_code:i}}:void 0,u={country_code:o,...n&&{postcode:n},...g&&{region:g}};return await p({type:"mutation",query:I,options:{variables:{cartId:s,address:u}},path:"estimateShippingMethods",signalType:"estimateShippingMethods",transformer:f})},T=` mutation setShippingAddress($input: SetShippingAddressesOnCartInput!) { setShippingAddressesOnCart(input: $input) { cart { @@ -35,5 +35,5 @@ import{t as _,a as f,b as h}from"./chunks/synchronizeCheckout.js";import{d as k, } } - ${I} -`,q=async({address:a,customerAddressId:s,pickupLocationCode:r})=>{const e=l.cartId;if(!e)throw new m;const t={cart_id:e,shipping_addresses:[]};if(s)t.shipping_addresses.push({customer_address_id:s});else if(r)t.shipping_addresses.push({pickup_location_code:r});else{if(!a)throw new C;t.shipping_addresses.push({address:f(a)})}const i=await p({type:"mutation",query:E,options:{variables:{input:t}},path:"setShippingAddressesOnCart.cart",queueName:"cartUpdate",signalType:"cart",transformer:h});return y.value?await p({type:"mutation",query:M,options:{variables:{input:{cart_id:e,billing_address:{same_as_shipping:!0}}}},path:"setBillingAddressOnCart.cart",queueName:"cartUpdate",signalType:"cart",transformer:h}):i};export{J as DEFAULT_COUNTRY,V as FetchError,W as InvalidArgument,X as MissingBillingAddress,m as MissingCart,A as MissingCountry,Z as MissingEmail,tt as MissingPaymentMethod,C as MissingShippinghAddress,st as STORE_CONFIG_DEFAULTS,et as UnexpectedError,k as authenticateCustomer,z as config,N as estimateShippingMethods,it as fetchGraphQl,Q as getCart,at as getConfig,R as getCustomer,rt as getStoreConfig,K as initialize,P as initializeCheckout,gt as isEmailAvailable,nt as removeFetchGraphQlHeader,j as resetCheckout,mt as setBillingAddress,ot as setEndpoint,pt as setFetchGraphQlHeader,dt as setFetchGraphQlHeaders,ht as setGuestEmailOnCart,_t as setPaymentMethod,q as setShippingAddress,At as setShippingMethodsOnCart,L as synchronizeCheckout}; + ${M} +`,q=async({address:r,customerAddressId:s,pickupLocationCode:a})=>{const e=d.cartId;if(!e)throw new l;const t={cart_id:e,shipping_addresses:[]};if(s)t.shipping_addresses.push({customer_address_id:s});else if(a)t.shipping_addresses.push({pickup_location_code:a});else{if(!r)throw new C;t.shipping_addresses.push({address:_(r)})}const i=await p({type:"mutation",query:T,options:{variables:{input:t}},path:"setShippingAddressesOnCart.cart",queueName:"cartUpdate",signalType:"cart",transformer:m});return S.value?await p({type:"mutation",query:y,options:{variables:{input:{cart_id:e,billing_address:{same_as_shipping:!0}}}},path:"setBillingAddressOnCart.cart",queueName:"cartUpdate",signalType:"cart",transformer:m}):i};export{rt as DEFAULT_COUNTRY,J as FetchError,V as InvalidArgument,W as MissingBillingAddress,l as MissingCart,A as MissingCountry,X as MissingEmail,Z as MissingPaymentMethod,C as MissingShippinghAddress,at as STORE_CONFIG_DEFAULTS,tt as UnexpectedError,k as authenticateCustomer,z as config,N as estimateShippingMethods,nt as fetchGraphQl,Q as getCart,ot as getConfig,R as getCustomer,pt as getStoreConfig,et as getStoreConfigCache,K as initialize,P as initializeCheckout,lt as isEmailAvailable,dt as removeFetchGraphQlHeader,j as resetCheckout,_t as setBillingAddress,ct as setEndpoint,gt as setFetchGraphQlHeader,ht as setFetchGraphQlHeaders,ut as setGuestEmailOnCart,Ct as setPaymentMethod,q as setShippingAddress,yt as setShippingMethodsOnCart,L as synchronizeCheckout}; diff --git a/scripts/__dropins__/storefront-checkout/api/getStoreConfig/getStoreConfig.d.ts b/scripts/__dropins__/storefront-checkout/api/getStoreConfig/getStoreConfig.d.ts index b03470a87a..2f0b09fd8e 100644 --- a/scripts/__dropins__/storefront-checkout/api/getStoreConfig/getStoreConfig.d.ts +++ b/scripts/__dropins__/storefront-checkout/api/getStoreConfig/getStoreConfig.d.ts @@ -2,5 +2,5 @@ import { StoreConfig } from '../../data/models'; export declare const DEFAULT_COUNTRY = "US"; export declare const STORE_CONFIG_DEFAULTS: StoreConfig; -export declare const getStoreConfig: () => Promise; +export declare const getStoreConfig: () => Promise; //# sourceMappingURL=getStoreConfig.d.ts.map \ No newline at end of file diff --git a/scripts/__dropins__/storefront-checkout/api/index.d.ts b/scripts/__dropins__/storefront-checkout/api/index.d.ts index 903db33730..31550f6939 100644 --- a/scripts/__dropins__/storefront-checkout/api/index.d.ts +++ b/scripts/__dropins__/storefront-checkout/api/index.d.ts @@ -31,4 +31,5 @@ export * from './setPaymentMethod'; export * from './setShippingAddress'; export * from './setShippingMethods'; export * from './synchronizeCheckout'; +export { getStoreConfigCache } from '../lib/state'; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/scripts/__dropins__/storefront-checkout/api/utils/dispatchApiCall.d.ts b/scripts/__dropins__/storefront-checkout/api/utils/dispatchApiCall.d.ts index bfeb150b10..9219f835bf 100644 --- a/scripts/__dropins__/storefront-checkout/api/utils/dispatchApiCall.d.ts +++ b/scripts/__dropins__/storefront-checkout/api/utils/dispatchApiCall.d.ts @@ -14,10 +14,6 @@ declare const signalTypes: { pending: boolean; data?: import('../../data/models/shipping-method').ShippingMethod[] | undefined; }>; - storeConfig: import('@preact/signals-core').Signal<{ - data?: import('../../data/models/store-config').StoreConfig | undefined; - pending: boolean; - }>; }; type SignalTypesType = typeof signalTypes; type SignalTypesKeys = keyof SignalTypesType; diff --git a/scripts/__dropins__/storefront-checkout/chunks/errors.js b/scripts/__dropins__/storefront-checkout/chunks/errors.js new file mode 100644 index 0000000000..cfbf26830a --- /dev/null +++ b/scripts/__dropins__/storefront-checkout/chunks/errors.js @@ -0,0 +1,3 @@ +/*! Copyright 2024 Adobe +All Rights Reserved. */ +class n extends Error{constructor(e){super(e.map(t=>t.message).join(" ")),this.name="FetchError"}}class r extends Error{constructor(e){super(e),this.name="InvalidArgument"}}class i extends Error{constructor(e){super(e),this.name="UnexpectedError"}}class a extends r{constructor(){super("Cart ID is required")}}class c extends r{constructor(){super("Email is required")}}class o extends r{constructor(){super("Payment method code is required")}}class d extends r{constructor(){super("Shipping address is required")}}class u extends r{constructor(){super("Billing address is required")}}class l extends r{constructor(){super("Country Code is required")}}export{n as F,r as I,a as M,i as U,l as a,d as b,c,o as d,u as e}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/fetch-graphql.js b/scripts/__dropins__/storefront-checkout/chunks/fetch-graphql.js deleted file mode 100644 index cd44d62bbf..0000000000 --- a/scripts/__dropins__/storefront-checkout/chunks/fetch-graphql.js +++ /dev/null @@ -1,12 +0,0 @@ -/*! Copyright 2024 Adobe -All Rights Reserved. */ -import{c as T,b as q,e as b,d as v,T as l}from"./store-config.js";import"./ServerErrorSignal.js";import{events as A}from"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";import{FetchGraphQL as G}from"@dropins/tools/fetch-graphql.js";const x={authenticated:!1,cartId:null,initialized:!1},j=new Proxy(x,{set(e,t,s){return e[t]=s,!0},get(e,t){return e[t]}});class D extends Error{constructor(t){super(t.map(s=>s.message).join(" ")),this.name="FetchError"}}class i extends Error{constructor(t){super(t),this.name="InvalidArgument"}}class B extends Error{constructor(t){super(t),this.name="UnexpectedError"}}class z extends i{constructor(){super("Cart ID is required")}}class Y extends i{constructor(){super("Email is required")}}class $ extends i{constructor(){super("Payment method code is required")}}class J extends i{constructor(){super("Shipping address is required")}}class K extends i{constructor(){super("Billing address is required")}}class W extends i{constructor(){super("Country Code is required")}}const y={cartUpdate:{requests:[]},default:{requests:[]}};function k(e,t="default"){const s=y[t];return new Promise((r,a)=>{s.requests.push(e);const u=()=>{s.requests[0]===e?e().then(r).catch(a).finally(()=>{var o;s.requests.shift(),s.requests.length===0?(o=s.onComplete)==null||o.call(s):u()}):setTimeout(u,100)};u()})}function Z(e,t){const s=y[e];s.onComplete=t}const w=["sender_email","recipient_email"];function I(e){return e.filter(t=>!t.path||!w.some(s=>{var r;return((r=t.path)==null?void 0:r.at(-1))===s}))}const C=e=>{throw e instanceof DOMException&&e.name==="AbortError"||A.emit("error",{source:"checkout",type:"network",error:e}),e},U={cart:T,customer:q,estimateShippingMethods:b,storeConfig:v};function M(e,t){return t.split(".").reduce((s,r)=>s&&s[r]!==void 0?s[r]:void 0,e)}const E={cart:null,customer:null,estimateShippingMethods:null,storeConfig:null};async function N(e){const{defaultValueOnFail:t,options:s,path:r,query:a,queueName:u,signalType:o,transformer:h,type:S}=e,n=U[o],g=Symbol();E[o]=g,n.value={...n.value,pending:!0};try{const{data:p,errors:f}=await(S==="mutation"?k(()=>_(a,s).catch(C),u):_(a,{method:"GET",cache:"no-cache",...s}).catch(C));if(f){const m=I(f);if(m.length>0)throw new D(m)}let c=M(p,r);if(c===void 0)throw new Error(`No data found at path: ${r}`);return h&&(c=h(c)),n.value={...n.value,data:c},setTimeout(()=>{n.value={...n.value,pending:E[o]===g?!1:n.value.pending}},0),c}catch(p){if(t)return n.value={pending:!1,data:t},t;if(p.name==="AbortError")return;throw n.value={...n.value,pending:!1},p}}const F=` - query getStoreConfig { - storeConfig { - default_country - is_guest_checkout_enabled - is_one_page_checkout_enabled - shopping_cart_display_shipping - } - } -`,L="US",d={defaultCountry:L,isGuestCheckoutEnabled:!1,isOnePageCheckoutEnabled:!1,shoppingCartDisplaySetting:{shipping:l.EXCLUDING_TAX}},ee=async()=>await N({type:"query",query:F,options:{method:"GET",cache:"no-cache"},path:"storeConfig",signalType:"storeConfig",transformer:P,defaultValueOnFail:d});function O(e){switch(e){case 1:return l.EXCLUDING_TAX;case 2:return l.INCLUDING_TAX;case 3:return l.INCLUDING_EXCLUDING_TAX;default:return l.EXCLUDING_TAX}}function P(e){if(!e)return d;const{default_country:t,is_guest_checkout_enabled:s,is_one_page_checkout_enabled:r,shopping_cart_display_shipping:a}=e;return{defaultCountry:t||d.defaultCountry,isGuestCheckoutEnabled:s||d.isGuestCheckoutEnabled,isOnePageCheckoutEnabled:r||d.isOnePageCheckoutEnabled,shoppingCartDisplaySetting:{shipping:O(a)}}}const{setEndpoint:te,setFetchGraphQlHeader:se,removeFetchGraphQlHeader:re,setFetchGraphQlHeaders:ne,fetchGraphQl:_,getConfig:ae}=new G().getMethods();export{L as D,D as F,i as I,z as M,d as S,B as U,W as a,J as b,Y as c,N as d,$ as e,K as f,te as g,se as h,ne as i,_ as j,ae as k,ee as l,C as m,Z as n,re as r,j as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/setBillingAddress.js b/scripts/__dropins__/storefront-checkout/chunks/setBillingAddress.js index db54752e7a..68e5fa7413 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/setBillingAddress.js +++ b/scripts/__dropins__/storefront-checkout/chunks/setBillingAddress.js @@ -1,6 +1,6 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{s as e,M as d,f as o,d as l}from"./fetch-graphql.js";import{CHECKOUT_DATA_FRAGMENT as p}from"../fragments.js";import{a as u,b as c}from"./synchronizeCheckout.js";import"./store-config.js";import"./ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const f=` +import{M as e,e as o}from"./errors.js";import{CHECKOUT_DATA_FRAGMENT as d}from"../fragments.js";import{a as l,d as p,b as u}from"./synchronizeCheckout.js";import{s as m}from"./store-config.js";import"./transform-store-config.js";import"./ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const c=` mutation setBillingAddress($input: SetBillingAddressOnCartInput!) { setBillingAddressOnCart(input: $input) { cart { @@ -9,5 +9,5 @@ import{s as e,M as d,f as o,d as l}from"./fetch-graphql.js";import{CHECKOUT_DATA } } - ${p} -`,h=async({address:i,customerAddressId:t,sameAsShipping:s=!1,useForShipping:n=!1})=>{const r=e.cartId;if(!r)throw new d;const a={cart_id:r,billing_address:{same_as_shipping:s,use_for_shipping:n}};if(!s&&t&&(a.billing_address.customer_address_id=t),!s&&!t){if(!i)throw new o;a.billing_address.address=u(i)}return await l({options:{variables:{input:a}},path:"setBillingAddressOnCart.cart",query:f,queueName:"cartUpdate",signalType:"cart",transformer:c,type:"mutation"})};export{f as a,h as s}; + ${d} +`,b=async({address:i,customerAddressId:t,sameAsShipping:s=!1,useForShipping:n=!1})=>{const r=m.cartId;if(!r)throw new e;const a={cart_id:r,billing_address:{same_as_shipping:s,use_for_shipping:n}};if(!s&&t&&(a.billing_address.customer_address_id=t),!s&&!t){if(!i)throw new o;a.billing_address.address=l(i)}return await p({options:{variables:{input:a}},path:"setBillingAddressOnCart.cart",query:c,queueName:"cartUpdate",signalType:"cart",transformer:u,type:"mutation"})};export{c as a,b as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/setGuestEmailOnCart.js b/scripts/__dropins__/storefront-checkout/chunks/setGuestEmailOnCart.js index c251eb674c..068082e010 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/setGuestEmailOnCart.js +++ b/scripts/__dropins__/storefront-checkout/chunks/setGuestEmailOnCart.js @@ -1,12 +1,12 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{c as e,j as r,m as s,s as l,M as o,d as n}from"./fetch-graphql.js";import"./store-config.js";import"./ServerErrorSignal.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import{CHECKOUT_DATA_FRAGMENT as m}from"../fragments.js";import{b as c}from"./synchronizeCheckout.js";const u=a=>!!(a!=null&&a.is_email_available),p=` +import{s as r}from"./store-config.js";import{h as e}from"./transform-store-config.js";import"./ServerErrorSignal.js";import{c as s,M as l}from"./errors.js";import{j as o,d as m,b as n}from"./synchronizeCheckout.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import{CHECKOUT_DATA_FRAGMENT as c}from"../fragments.js";const u=a=>!!(a!=null&&a.is_email_available),p=` query isEmailAvailable($email: String!) { isEmailAvailable(email: $email) { is_email_available } } -`,E=a=>{if(!(!a||a.length===0))throw Error(a.map(t=>t.message).join(" "))},_=async a=>{if(!a)throw new e;const{data:t,errors:i}=await r(p,{method:"GET",cache:"no-cache",variables:{email:a}}).catch(s);return i&&E(i),u(t.isEmailAvailable)},h=` +`,E=a=>{if(!(!a||a.length===0))throw Error(a.map(t=>t.message).join(" "))},g=async a=>{if(!a)throw new s;const{data:t,errors:i}=await e(p,{method:"GET",cache:"no-cache",variables:{email:a}}).catch(o);return i&&E(i),u(t.isEmailAvailable)},h=` mutation setGuestEmail($cartId: String!, $email: String!) { setGuestEmailOnCart(input: { cart_id: $cartId, email: $email }) { cart { @@ -15,5 +15,5 @@ import{c as e,j as r,m as s,s as l,M as o,d as n}from"./fetch-graphql.js";import } } - ${m} -`,g=async a=>{const t=l.cartId;if(!t)throw new o;return await n({options:{variables:{cartId:t,email:a}},path:"setGuestEmailOnCart.cart",query:h,queueName:"cartUpdate",signalType:"cart",transformer:c,type:"mutation"})};export{_ as i,g as s}; + ${c} +`,w=async a=>{const t=r.cartId;if(!t)throw new l;return await m({options:{variables:{cartId:t,email:a}},path:"setGuestEmailOnCart.cart",query:h,queueName:"cartUpdate",signalType:"cart",transformer:n,type:"mutation"})};export{g as i,w as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/setPaymentMethod.js b/scripts/__dropins__/storefront-checkout/chunks/setPaymentMethod.js index 6467bc1a1e..3040b1f5b9 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/setPaymentMethod.js +++ b/scripts/__dropins__/storefront-checkout/chunks/setPaymentMethod.js @@ -1,6 +1,6 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{s as e,M as r,e as o,d as n}from"./fetch-graphql.js";import{CHECKOUT_DATA_FRAGMENT as s}from"../fragments.js";import{b as i}from"./synchronizeCheckout.js";import"./store-config.js";import"./ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const m=` +import{M as e,d as r}from"./errors.js";import{CHECKOUT_DATA_FRAGMENT as o}from"../fragments.js";import{d as n,b as s}from"./synchronizeCheckout.js";import{s as m}from"./store-config.js";import"./transform-store-config.js";import"./ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const i=` mutation setPaymentMethod( $cartId: String! $paymentMethod: PaymentMethodInput! @@ -14,5 +14,5 @@ import{s as e,M as r,e as o,d as n}from"./fetch-graphql.js";import{CHECKOUT_DATA } } - ${s} -`,f=async t=>{const a=e.cartId;if(!a)throw new r;if(!t)throw new o;return await n({options:{variables:{cartId:a,paymentMethod:t}},path:"setPaymentMethodOnCart.cart",query:m,queueName:"cartUpdate",signalType:"cart",transformer:i,type:"mutation"})};export{f as s}; + ${o} +`,A=async t=>{const a=m.cartId;if(!a)throw new e;if(!t)throw new r;return await n({options:{variables:{cartId:a,paymentMethod:t}},path:"setPaymentMethodOnCart.cart",query:i,queueName:"cartUpdate",signalType:"cart",transformer:s,type:"mutation"})};export{A as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/setShippingMethods.js b/scripts/__dropins__/storefront-checkout/chunks/setShippingMethods.js index 6c876afc0e..d2675ee4db 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/setShippingMethods.js +++ b/scripts/__dropins__/storefront-checkout/chunks/setShippingMethods.js @@ -1,6 +1,6 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{s as i,M as p,d as s}from"./fetch-graphql.js";import"./store-config.js";import"./ServerErrorSignal.js";import{b as r}from"./synchronizeCheckout.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import{CHECKOUT_DATA_FRAGMENT as o}from"../fragments.js";const e=` +import{s as i}from"./store-config.js";import"./transform-store-config.js";import"./ServerErrorSignal.js";import{M as p}from"./errors.js";import{d as r,b as s}from"./synchronizeCheckout.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import{CHECKOUT_DATA_FRAGMENT as o}from"../fragments.js";const e=` mutation setShippingMethods( $cartId: String! $shippingMethods: [ShippingMethodInput]! @@ -15,4 +15,4 @@ import{s as i,M as p,d as s}from"./fetch-graphql.js";import"./store-config.js";i } ${o} -`,C=async a=>{const t=i.cartId;if(!t)throw new p;return await s({type:"mutation",query:e,queueName:"cartUpdate",options:{variables:{cartId:t,shippingMethods:a}},path:"setShippingMethodsOnCart.cart",signalType:"cart",transformer:r})};export{C as s}; +`,f=async a=>{const t=i.cartId;if(!t)throw new p;return await r({type:"mutation",query:e,queueName:"cartUpdate",options:{variables:{cartId:t,shippingMethods:a}},path:"setShippingMethodsOnCart.cart",signalType:"cart",transformer:s})};export{f as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/store-config.js b/scripts/__dropins__/storefront-checkout/chunks/store-config.js index bafbd3c79a..3bc07587f1 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/store-config.js +++ b/scripts/__dropins__/storefront-checkout/chunks/store-config.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{signal as e,effect as i}from"@dropins/tools/signals.js";const n=e(!0),t=e({pending:!1,data:void 0});i(()=>{var a;(a=t.value.data)!=null&&a.isVirtual&&(n.value=!1)});const d=e({pending:!1,data:void 0}),l=e({pending:!1,data:void 0}),g=e(),c=e(void 0),N=e({data:void 0,pending:!1});var s=(a=>(a.EXCLUDING_TAX="EXCLUDING_TAX",a.INCLUDING_EXCLUDING_TAX="INCLUDING_AND_EXCLUDING_TAX",a.INCLUDING_TAX="INCLUDING_TAX",a))(s||{});export{s as T,g as a,d as b,t as c,N as d,l as e,n as i,c as s}; +const I={authenticated:!1,cartId:null,initialized:!1,config:null},N=new Proxy(I,{set(t,e,n){return t[e]=n,!0},get(t,e){return t[e]}}),s=()=>N.config;var r=(t=>(t.EXCLUDING_TAX="EXCLUDING_TAX",t.INCLUDING_EXCLUDING_TAX="INCLUDING_AND_EXCLUDING_TAX",t.INCLUDING_TAX="INCLUDING_TAX",t))(r||{});export{r as T,s as g,N as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/synchronizeCheckout.js b/scripts/__dropins__/storefront-checkout/chunks/synchronizeCheckout.js index 00e65766d8..2841ae5a25 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/synchronizeCheckout.js +++ b/scripts/__dropins__/storefront-checkout/chunks/synchronizeCheckout.js @@ -1,27 +1,27 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{s as i,M as C,d as l,l as A,n as x}from"./fetch-graphql.js";import{b,d as M,c}from"./store-config.js";import"./ServerErrorSignal.js";import{events as o}from"@dropins/tools/event-bus.js";import{merge as u,Initializer as T}from"@dropins/tools/lib.js";import{CHECKOUT_DATA_FRAGMENT as a,CUSTOMER_FRAGMENT as S}from"../fragments.js";const I=async(e=!1)=>{i.authenticated=e,e?await K():b.value={pending:!1,data:null}},N=e=>e==null,E=(e,t)=>e.amount.value-t.amount.value,m=e=>!(!e||!e.method_code||!e.method_title||N(e.amount.value)||!e.amount.currency),f=e=>({amount:{value:e.amount.value,currency:e.amount.currency},title:e.method_title,code:e.method_code,carrier:{code:e.carrier_code,title:e.carrier_title},value:`${e.carrier_code} - ${e.method_code}`,...e.price_excl_tax&&{amountExclTax:{value:e.price_excl_tax.value,currency:e.price_excl_tax.currency}},...e.price_incl_tax&&{amountInclTax:{value:e.price_incl_tax.value,currency:e.price_incl_tax.currency}}}),k=e=>{if(m(e))return f(e)},w=e=>{if(e)return e.filter(m).map(t=>f(t)).sort(E)},z=e=>e?!!e.code&&!!e.label:!1,R=e=>{if(!z(e))return;const{code:t,label:r,region_id:n}=e;return n?{code:t,name:r,id:n}:{code:t,name:r}},q=e=>{const{code:t,label:r}=e;return{value:t,label:r}},P=e=>e?"code"in e&&"value"in e:!1,G=e=>e.filter(P).map(t=>{const{code:r,value:n}=t;return{code:r,value:n}}),d=e=>{const t=e.street.filter(Boolean);return{id:(e==null?void 0:e.id)||void 0,city:e.city,company:e.company||void 0,country:q(e.country),customAttributes:G(e.custom_attributes),firstName:e.firstname,lastName:e.lastname,postCode:e.postcode||void 0,region:R(e.region),street:t,telephone:e.telephone||void 0,vatId:e.vat_id||void 0,prefix:e.prefix||void 0,suffix:e.suffix||void 0,middleName:e.middlename||void 0,fax:e.fax||void 0}},O=e=>{if(e)return d(e)},$=e=>e.filter(t=>!!t).map(t=>{const{available_shipping_methods:r,selected_shipping_method:n,same_as_billing:s,...v}=t;return{...d(v),availableShippingMethods:w(r),selectedShippingMethod:k(n),sameAsBilling:s}}),te=e=>({city:e.city,company:e.company,country_code:e.countryCode,custom_attributes:e.customAttributes.map(t=>({attribute_code:t.code,value:t.value})),firstname:e.firstName,lastname:e.lastName,postcode:e.postcode,region:e.region,region_id:e.regionId,save_in_address_book:e.saveInAddressBook??!0,street:e.street,telephone:e.telephone,vat_id:e.vatId,prefix:e.prefix,suffix:e.suffix,middlename:e.middleName,fax:e.fax}),U=e=>{if(e)return{code:e.code,title:e.title}},B=e=>{if(e)return e.filter(t=>!!t).map(t=>{const{code:r,title:n}=t;return{code:r,title:n}})},D=e=>{var r,n,s;if(!e)return;const t={availablePaymentMethods:B(e.available_payment_methods),billingAddress:O(e.billing_address),email:e.email??void 0,id:e.id,isEmpty:e.total_quantity===0,isVirtual:e.is_virtual,selectedPaymentMethod:U(e.selected_payment_method),shippingAddresses:$(e.shipping_addresses),isGuest:!i.authenticated};return u(t,(s=(n=(r=_.getConfig().models)==null?void 0:r.CartModel)==null?void 0:n.transformer)==null?void 0:s.call(n,e))},F=e=>{var r,n,s;if(!e)return;const t={firstName:e.firstname||"",lastName:e.lastname||"",email:e.email||""};return u(t,(s=(n=(r=_.getConfig().models)==null?void 0:r.CustomerModel)==null?void 0:n.transformer)==null?void 0:s.call(n,e))},H=` +import{s as i}from"./store-config.js";import{b as C,h as y,c as m,e as R,k as z}from"./transform-store-config.js";import"./ServerErrorSignal.js";import{events as c}from"@dropins/tools/event-bus.js";import{merge as A,Initializer as G}from"@dropins/tools/lib.js";import{CHECKOUT_DATA_FRAGMENT as b,CUSTOMER_FRAGMENT as O}from"../fragments.js";import{F as $,M as U}from"./errors.js";const D=async(e=!1)=>{i.authenticated=e,e?await me():C.value={pending:!1,data:null}},x={cartUpdate:{requests:[]},default:{requests:[]}};function F(e,t="default"){const r=x[t];return new Promise((n,o)=>{r.requests.push(e);const a=()=>{r.requests[0]===e?e().then(n).catch(o).finally(()=>{var l;r.requests.shift(),r.requests.length===0?(l=r.onComplete)==null||l.call(r):a()}):setTimeout(a,100)};a()})}function Q(e,t){const r=x[e];r.onComplete=t}const V=["sender_email","recipient_email"];function B(e){return e.filter(t=>!t.path||!V.some(r=>{var n;return((n=t.path)==null?void 0:n.at(-1))===r}))}const v=e=>{throw e instanceof DOMException&&e.name==="AbortError"||c.emit("error",{source:"checkout",type:"network",error:e}),e},H={cart:m,customer:C,estimateShippingMethods:R};function K(e,t){return t.split(".").reduce((r,n)=>r&&r[n]!==void 0?r[n]:void 0,e)}const _={cart:null,customer:null,estimateShippingMethods:null};async function E(e){const{defaultValueOnFail:t,options:r,path:n,query:o,queueName:a,signalType:l,transformer:p,type:P}=e,s=H[l],d=Symbol();_[l]=d,s.value={...s.value,pending:!0};try{const{data:f,errors:h}=await(P==="mutation"?F(()=>y(o,r).catch(v),a):y(o,{method:"GET",cache:"no-cache",...r}).catch(v));if(h){const g=B(h);if(g.length>0)throw new $(g)}let u=K(f,n);if(u===void 0)throw new Error(`No data found at path: ${n}`);return p&&(u=p(u)),s.value={...s.value,data:u},setTimeout(()=>{s.value={...s.value,pending:_[l]===d?!1:s.value.pending}},0),u}catch(f){if(t)return s.value={pending:!1,data:t},t;if(f.name==="AbortError")return;throw s.value={...s.value,pending:!1},f}}const j=e=>e==null,L=(e,t)=>e.amount.value-t.amount.value,M=e=>!(!e||!e.method_code||!e.method_title||j(e.amount.value)||!e.amount.currency),T=e=>({amount:{value:e.amount.value,currency:e.amount.currency},title:e.method_title,code:e.method_code,carrier:{code:e.carrier_code,title:e.carrier_title},value:`${e.carrier_code} - ${e.method_code}`,...e.price_excl_tax&&{amountExclTax:{value:e.price_excl_tax.value,currency:e.price_excl_tax.currency}},...e.price_incl_tax&&{amountInclTax:{value:e.price_incl_tax.value,currency:e.price_incl_tax.currency}}}),J=e=>{if(M(e))return T(e)},W=e=>{if(e)return e.filter(M).map(t=>T(t)).sort(L)},X=e=>e?!!e.code&&!!e.label:!1,Y=e=>{if(!X(e))return;const{code:t,label:r,region_id:n}=e;return n?{code:t,name:r,id:n}:{code:t,name:r}},Z=e=>{const{code:t,label:r}=e;return{value:t,label:r}},ee=e=>e?"code"in e&&"value"in e:!1,te=e=>e.filter(ee).map(t=>{const{code:r,value:n}=t;return{code:r,value:n}}),S=e=>{const t=e.street.filter(Boolean);return{id:(e==null?void 0:e.id)||void 0,city:e.city,company:e.company||void 0,country:Z(e.country),customAttributes:te(e.custom_attributes),firstName:e.firstname,lastName:e.lastname,postCode:e.postcode||void 0,region:Y(e.region),street:t,telephone:e.telephone||void 0,vatId:e.vat_id||void 0,prefix:e.prefix||void 0,suffix:e.suffix||void 0,middleName:e.middlename||void 0,fax:e.fax||void 0}},re=e=>{if(e)return S(e)},ne=e=>e.filter(t=>!!t).map(t=>{const{available_shipping_methods:r,selected_shipping_method:n,same_as_billing:o,...a}=t;return{...S(a),availableShippingMethods:W(r),selectedShippingMethod:J(n),sameAsBilling:o}}),Ae=e=>({city:e.city,company:e.company,country_code:e.countryCode,custom_attributes:e.customAttributes.map(t=>({attribute_code:t.code,value:t.value})),firstname:e.firstName,lastname:e.lastName,postcode:e.postcode,region:e.region,region_id:e.regionId,save_in_address_book:e.saveInAddressBook??!0,street:e.street,telephone:e.telephone,vat_id:e.vatId,prefix:e.prefix,suffix:e.suffix,middlename:e.middleName,fax:e.fax}),ie=e=>{if(e)return{code:e.code,title:e.title}},oe=e=>{if(e)return e.filter(t=>!!t).map(t=>{const{code:r,title:n}=t;return{code:r,title:n}})},se=e=>{var r,n,o;if(!e)return;const t={availablePaymentMethods:oe(e.available_payment_methods),billingAddress:re(e.billing_address),email:e.email??void 0,id:e.id,isEmpty:e.total_quantity===0,isVirtual:e.is_virtual,selectedPaymentMethod:ie(e.selected_payment_method),shippingAddresses:ne(e.shipping_addresses),isGuest:!i.authenticated};return A(t,(o=(n=(r=N.getConfig().models)==null?void 0:r.CartModel)==null?void 0:n.transformer)==null?void 0:o.call(n,e))},ce=e=>{var r,n,o;if(!e)return;const t={firstName:e.firstname||"",lastName:e.lastname||"",email:e.email||""};return A(t,(o=(n=(r=N.getConfig().models)==null?void 0:r.CustomerModel)==null?void 0:n.transformer)==null?void 0:o.call(n,e))},ae=` query getCart($cartId: String!) { cart(cart_id: $cartId) { ...CHECKOUT_DATA_FRAGMENT } } - ${a} -`,Q=` + ${b} +`,le=` query getCustomerCart { cart: customerCart { ...CHECKOUT_DATA_FRAGMENT } } - ${a} -`,p=async()=>{const e=i.cartId,t=i.authenticated===!1,r=t?H:Q,n=t?{cartId:e}:{};if(t&&!e)throw new C;return await l({type:"query",query:r,options:{method:"POST",cache:"no-cache",variables:n},path:"cart",signalType:"cart",transformer:D})},V=` + ${b} +`,w=async()=>{const e=i.cartId,t=i.authenticated===!1,r=t?ae:le,n=t?{cartId:e}:{};if(t&&!e)throw new U;return await E({type:"query",query:r,options:{method:"POST",cache:"no-cache",variables:n},path:"cart",signalType:"cart",transformer:se})},ue=` query getCustomer { customer { ...CUSTOMER_FRAGMENT } } - ${S} -`,K=async()=>{if(i.authenticated)return await l({type:"query",query:V,options:{method:"POST",cache:"no-cache"},path:"customer",signalType:"customer",transformer:F})},L=()=>[o.on("authenticated",I,{eager:!0}),o.on("cart/initialized",h,{eager:!0}),o.on("cart/reset",j),o.on("cart/updated",y)],g=new T({init:async e=>{const t=e||{};g.config.setConfig(t);const{data:r,pending:n}=M.value;!r&&!n&&await A()},listeners:L}),_=g.config;x("cartUpdate",()=>{o.emit("checkout/updated",c.value.data)});const h=async e=>{if(i.initialized)return y(e);const t=e?e.id:null;i.cartId=t;const r=t?await p():null;c.value={pending:!1,data:r},i.initialized=!0,o.emit("checkout/initialized",r||null)},j=()=>{i.cartId=null,c.value={pending:!1,data:null},o.emit("checkout/updated",null)},y=async e=>{if(!i.initialized)return h(e);const t=e?e.id:null;i.cartId=t;const r=t?await p():null;c.value={pending:!1,data:r},o.emit("checkout/updated",r||null)};export{te as a,D as b,_ as c,I as d,K as e,h as f,p as g,g as i,j as r,y as s,w as t}; + ${O} +`,me=async()=>{if(i.authenticated)return await E({type:"query",query:ue,options:{method:"POST",cache:"no-cache"},path:"customer",signalType:"customer",transformer:ce})},fe=()=>[c.on("authenticated",D,{eager:!0}),c.on("cart/initialized",I,{eager:!0}),c.on("cart/reset",pe),c.on("cart/updated",k)],q=new G({init:async e=>{const t=e||{};q.config.setConfig(t)},listeners:fe}),N=q.config;Q("cartUpdate",()=>{c.emit("checkout/updated",m.value.data)});const I=async e=>{if(i.initialized)return k(e);i.config||(i.config=await z());const t=e?e.id:null;i.cartId=t;const r=t?await w():null;m.value={pending:!1,data:r},i.initialized=!0,c.emit("checkout/initialized",r||null)},pe=()=>{i.cartId=null,m.value={pending:!1,data:null},c.emit("checkout/updated",null)},k=async e=>{if(!i.initialized)return I(e);const t=e?e.id:null;i.cartId=t;const r=t?await w():null;m.value={pending:!1,data:r},c.emit("checkout/updated",r||null)};export{Ae as a,se as b,N as c,E as d,D as e,me as f,w as g,I as h,q as i,v as j,pe as r,k as s,W as t}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/transform-store-config.js b/scripts/__dropins__/storefront-checkout/chunks/transform-store-config.js new file mode 100644 index 0000000000..914dfcf868 --- /dev/null +++ b/scripts/__dropins__/storefront-checkout/chunks/transform-store-config.js @@ -0,0 +1,12 @@ +/*! Copyright 2024 Adobe +All Rights Reserved. */ +import{T as a}from"./store-config.js";import{signal as t,effect as c}from"@dropins/tools/signals.js";import"./ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import{FetchGraphQL as l}from"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const p=t(!0),u=t({pending:!1,data:void 0});c(()=>{var e;(e=u.value.data)!=null&&e.isVirtual&&(p.value=!1)});const T=t({pending:!1,data:void 0}),D=t({pending:!1,data:void 0}),b=t(),k=t(void 0),g=` + query getStoreConfig { + storeConfig { + default_country + is_guest_checkout_enabled + is_one_page_checkout_enabled + shopping_cart_display_shipping + } + } +`,{setEndpoint:N,setFetchGraphQlHeader:U,removeFetchGraphQlHeader:I,setFetchGraphQlHeaders:L,fetchGraphQl:h,getConfig:X}=new l().getMethods(),d="US",n={defaultCountry:d,isGuestCheckoutEnabled:!1,isOnePageCheckoutEnabled:!1,shoppingCartDisplaySetting:{shipping:a.EXCLUDING_TAX}},v=async()=>h(g,{method:"GET",cache:"no-cache"}).then(({errors:e,data:s})=>e?n:_(s.storeConfig));function f(e){switch(e){case 1:return a.EXCLUDING_TAX;case 2:return a.INCLUDING_TAX;case 3:return a.INCLUDING_EXCLUDING_TAX;default:return a.EXCLUDING_TAX}}function _(e){if(!e)return n;const{default_country:s,is_guest_checkout_enabled:i,is_one_page_checkout_enabled:o,shopping_cart_display_shipping:r}=e;return{defaultCountry:s||n.defaultCountry,isGuestCheckoutEnabled:i||n.isGuestCheckoutEnabled,isOnePageCheckoutEnabled:o||n.isOnePageCheckoutEnabled,shoppingCartDisplaySetting:{shipping:f(r)}}}export{d as D,n as S,b as a,T as b,u as c,N as d,D as e,U as f,L as g,h,p as i,X as j,v as k,I as r,k as s}; diff --git a/scripts/__dropins__/storefront-checkout/chunks/withConditionalRendering.js b/scripts/__dropins__/storefront-checkout/chunks/withConditionalRendering.js index 0b1174afa9..54d93de7f6 100644 --- a/scripts/__dropins__/storefront-checkout/chunks/withConditionalRendering.js +++ b/scripts/__dropins__/storefront-checkout/chunks/withConditionalRendering.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{c as d}from"./store-config.js";import"./ServerErrorSignal.js";import"./fetch-graphql.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";function u(i){return i.displayName||i.name||"Component"}const h=i=>{const o=u(i),a=({hideOnEmptyCart:s=!0,hideOnVirtualCart:r=!1,...e})=>{const t=d.value.data,l=t!==void 0&&(t===null||t.isEmpty),m=!!(t!=null&&t.isVirtual),c=s&&l||r&&m,p=`conditional-${o.toLowerCase()}`;return n("div",{className:p,children:!c&&n(i,{...e})})};return a.displayName=`Conditional(${o})`,a};export{h as w}; +import{jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{c as d}from"./transform-store-config.js";import"./ServerErrorSignal.js";import"./store-config.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";function u(i){return i.displayName||i.name||"Component"}const h=i=>{const o=u(i),a=({hideOnEmptyCart:s=!0,hideOnVirtualCart:r=!1,...e})=>{const t=d.value.data,l=t!==void 0&&(t===null||t.isEmpty),m=!!(t!=null&&t.isVirtual),c=s&&l||r&&m,p=`conditional-${o.toLowerCase()}`;return n("div",{className:p,children:!c&&n(i,{...e})})};return a.displayName=`Conditional(${o})`,a};export{h as w}; diff --git a/scripts/__dropins__/storefront-checkout/containers/BillToShippingAddress.js b/scripts/__dropins__/storefront-checkout/containers/BillToShippingAddress.js index 15010b59b6..6835c961e8 100644 --- a/scripts/__dropins__/storefront-checkout/containers/BillToShippingAddress.js +++ b/scripts/__dropins__/storefront-checkout/containers/BillToShippingAddress.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as t}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/fetch-graphql.js";import{i as d,c as u}from"../chunks/store-config.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";import{s as S}from"../chunks/setBillingAddress.js";/* empty css */import{Checkbox as b,Skeleton as f,SkeletonRow as A}from"@dropins/tools/components.js";import{c as B}from"../chunks/classes.js";import{useText as x}from"@dropins/tools/i18n.js";import{w as T}from"../chunks/withConditionalRendering.js";import{useState as v,useEffect as _}from"@dropins/tools/preact-compat.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const w=({className:i,checked:e,loading:r,onChange:n,disabled:s})=>{const c=x({title:"Checkout.BillToShippingAddress.title"});return r?t(y,{}):t("div",{className:"checkout-bill-to-shipping-address",children:t(b,{checked:e,className:B(["checkout-bill-to-shipping-address__checkbox",i]),"data-testid":"bill-to-shipping-checkbox",disabled:s,label:c.title,name:"checkout-bill-to-shipping-address__checkbox",onChange:n})})},y=()=>t(f,{className:"bill-to-shipping-address__skeleton",children:t(A,{variant:"row",size:"small"})}),k=({onChange:i})=>{var g;const[e,r]=v(!0),n=d.value,s=u.value.data,c=u.value.pending,p=!!s,m=!!(s==null?void 0:s.billingAddress),l=(g=s==null?void 0:s.shippingAddresses)==null?void 0:g[0],h=l==null?void 0:l.sameAsBilling;return _(()=>{if(!e||!p)return;r(!1);const o=h??!m;d.value=o,i==null||i(o)},[p,m,h,e,i]),t(w,{checked:n,disabled:c,loading:e,onChange:async o=>{const a=o.target.checked;d.value=a,i==null||i(a),!e&&l&&a&&await S({sameAsShipping:!0}).catch(console.error)}})};k.displayName="BillToShippingAddressContainer";const U=T(k);export{U as BillToShippingAddress,U as default}; +import{jsx as t}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/store-config.js";import{i as d,c as u}from"../chunks/transform-store-config.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";import{s as S}from"../chunks/setBillingAddress.js";/* empty css */import{Checkbox as b,Skeleton as f,SkeletonRow as A}from"@dropins/tools/components.js";import{c as B}from"../chunks/classes.js";import{useText as x}from"@dropins/tools/i18n.js";import{w as T}from"../chunks/withConditionalRendering.js";import{useState as v,useEffect as _}from"@dropins/tools/preact-compat.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/errors.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const w=({className:i,checked:e,loading:r,onChange:n,disabled:s})=>{const c=x({title:"Checkout.BillToShippingAddress.title"});return r?t(y,{}):t("div",{className:"checkout-bill-to-shipping-address",children:t(b,{checked:e,className:B(["checkout-bill-to-shipping-address__checkbox",i]),"data-testid":"bill-to-shipping-checkbox",disabled:s,label:c.title,name:"checkout-bill-to-shipping-address__checkbox",onChange:n})})},y=()=>t(f,{className:"bill-to-shipping-address__skeleton",children:t(A,{variant:"row",size:"small"})}),k=({onChange:i})=>{var g;const[e,r]=v(!0),n=d.value,s=u.value.data,c=u.value.pending,p=!!s,m=!!(s==null?void 0:s.billingAddress),l=(g=s==null?void 0:s.shippingAddresses)==null?void 0:g[0],h=l==null?void 0:l.sameAsBilling;return _(()=>{if(!e||!p)return;r(!1);const o=h??!m;d.value=o,i==null||i(o)},[p,m,h,e,i]),t(w,{checked:n,disabled:c,loading:e,onChange:async o=>{const a=o.target.checked;d.value=a,i==null||i(a),!e&&l&&a&&await S({sameAsShipping:!0}).catch(console.error)}})};k.displayName="BillToShippingAddressContainer";const V=T(k);export{V as BillToShippingAddress,V as default}; diff --git a/scripts/__dropins__/storefront-checkout/containers/EstimateShipping.js b/scripts/__dropins__/storefront-checkout/containers/EstimateShipping.js index b708c2a9e5..3a35d798e7 100644 --- a/scripts/__dropins__/storefront-checkout/containers/EstimateShipping.js +++ b/scripts/__dropins__/storefront-checkout/containers/EstimateShipping.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsxs as k,Fragment as M,jsx as t}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Skeleton as A,SkeletonRow as L,Price as g}from"@dropins/tools/components.js";/* empty css */import{VComponent as w,classes as I}from"@dropins/tools/lib.js";import{Text as l,useText as z}from"@dropins/tools/i18n.js";/* empty css *//* empty css *//* empty css */import{d as B,T as C}from"../chunks/store-config.js";import"../chunks/ServerErrorSignal.js";import{events as x}from"@dropins/tools/event-bus.js";import{useState as G,useEffect as f}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";const P=({estimated:e=!1,price:a,priceExclTax:d,taxExcluded:p=!1,taxIncluded:o=!1})=>k(M,{children:[t("span",{className:"checkout-estimate-shipping__label",children:e?t(l,{id:"Checkout.EstimateShipping.estimated"}):t(l,{id:"Checkout.EstimateShipping.label"})}),t(w,{node:a,className:"checkout-estimate-shipping__price"}),o&&t("span",{"data-testid":"shipping-tax-included",className:I(["checkout-estimate-shipping__caption"]),children:t(l,{id:"Checkout.EstimateShipping.withTaxes"})}),p&&k("span",{"data-testid":"shipping-tax-included-excluded",className:I(["checkout-estimate-shipping__caption"]),children:[d," ",t(l,{id:"Checkout.EstimateShipping.withoutTaxes"})]})]}),U=()=>t(A,{"data-testid":"estimate-shipping-skeleton",children:t(L,{size:"xsmall"})}),Z=()=>{const[e,a]=G(),d=e!==void 0,p=(e==null?void 0:e.amount.value)===0,{data:o,pending:_}=B.value,D=_||o===void 0,T=o==null?void 0:o.shoppingCartDisplaySetting.shipping,N=T===C.INCLUDING_EXCLUDING_TAX,E=T===C.INCLUDING_TAX,S=z({freeShipping:"Checkout.EstimateShipping.freeShipping",taxToBeDetermined:"Checkout.EstimateShipping.taxToBeDetermined"});f(()=>{const i=x.on("shipping/estimate",n=>{const s=n.shippingMethod,{amount:c,amountExclTax:r,amountInclTax:m}=s;a({estimated:!0,amount:c,amountExclTax:r,amountInclTax:m})},{eager:!0});return()=>{i==null||i.off()}},[]),f(()=>{const i=x.on("checkout/initialized",n=>{var u,h;const s=(h=(u=n==null?void 0:n.shippingAddresses)==null?void 0:u[0])==null?void 0:h.selectedShippingMethod;if(!s)return;const{amount:c,amountExclTax:r,amountInclTax:m}=s;a({estimated:!1,amount:c,amountExclTax:r,amountInclTax:m})},{eager:!0});return()=>{i==null||i.off()}},[]),f(()=>{const i=x.on("checkout/updated",n=>{var u,h;const s=(h=(u=n==null?void 0:n.shippingAddresses)==null?void 0:u[0])==null?void 0:h.selectedShippingMethod;if(!s)return;const{amount:c,amountExclTax:r,amountInclTax:m}=s;a({estimated:!1,amount:c,amountExclTax:r,amountInclTax:m})},{eager:!0});return()=>{i==null||i.off()}},[]);const v=()=>p?t("span",{"data-testId":"free-shipping",children:S.freeShipping}):E&&(e!=null&&e.amountInclTax)?t(g,{"data-testid":"shipping",amount:e.amountInclTax.value,currency:e.amountInclTax.currency}):t(g,{"data-testid":"shipping",amount:e==null?void 0:e.amount.value,currency:e==null?void 0:e.amount.currency}),y=()=>e!=null&&e.amountExclTax?t(g,{"data-testid":"shipping-excluding-tax",amount:e.amountExclTax.value,currency:e.amountExclTax.currency}):t("span",{children:S.taxToBeDetermined});return t("div",{"data-testid":"estimate-shipping",className:"checkout-estimate-shipping",children:!d||D?t(U,{}):t(P,{estimated:e.estimated,price:v(),taxExcluded:N&&!p,taxIncluded:E&&!p,priceExclTax:y()})})};export{Z as EstimateShipping,Z as default}; +import{jsxs as k,Fragment as y,jsx as t}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Skeleton as v,SkeletonRow as M,Price as x}from"@dropins/tools/components.js";/* empty css */import{VComponent as A,classes as I}from"@dropins/tools/lib.js";import{Text as l,useText as w}from"@dropins/tools/i18n.js";/* empty css *//* empty css *//* empty css */import{s as z,T as C}from"../chunks/store-config.js";import{events as g}from"@dropins/tools/event-bus.js";import{useState as B,useEffect as f}from"@dropins/tools/preact-hooks.js";const G=({estimated:e=!1,price:a,priceExclTax:d,taxExcluded:o=!1,taxIncluded:p=!1})=>k(y,{children:[t("span",{className:"checkout-estimate-shipping__label",children:e?t(l,{id:"Checkout.EstimateShipping.estimated"}):t(l,{id:"Checkout.EstimateShipping.label"})}),t(A,{node:a,className:"checkout-estimate-shipping__price"}),p&&t("span",{"data-testid":"shipping-tax-included",className:I(["checkout-estimate-shipping__caption"]),children:t(l,{id:"Checkout.EstimateShipping.withTaxes"})}),o&&k("span",{"data-testid":"shipping-tax-included-excluded",className:I(["checkout-estimate-shipping__caption"]),children:[d," ",t(l,{id:"Checkout.EstimateShipping.withoutTaxes"})]})]}),L=()=>t(v,{"data-testid":"estimate-shipping-skeleton",children:t(M,{size:"xsmall"})}),O=()=>{const[e,a]=B(),d=e!==void 0,o=(e==null?void 0:e.amount.value)===0,p=z.config,T=p==null?void 0:p.shoppingCartDisplaySetting.shipping,_=T===C.INCLUDING_EXCLUDING_TAX,E=T===C.INCLUDING_TAX,S=w({freeShipping:"Checkout.EstimateShipping.freeShipping",taxToBeDetermined:"Checkout.EstimateShipping.taxToBeDetermined"});f(()=>{const i=g.on("shipping/estimate",n=>{const s=n.shippingMethod,{amount:c,amountExclTax:r,amountInclTax:m}=s;a({estimated:!0,amount:c,amountExclTax:r,amountInclTax:m})},{eager:!0});return()=>{i==null||i.off()}},[]),f(()=>{const i=g.on("checkout/initialized",n=>{var u,h;const s=(h=(u=n==null?void 0:n.shippingAddresses)==null?void 0:u[0])==null?void 0:h.selectedShippingMethod;if(!s)return;const{amount:c,amountExclTax:r,amountInclTax:m}=s;a({estimated:!1,amount:c,amountExclTax:r,amountInclTax:m})},{eager:!0});return()=>{i==null||i.off()}},[]),f(()=>{const i=g.on("checkout/updated",n=>{var u,h;const s=(h=(u=n==null?void 0:n.shippingAddresses)==null?void 0:u[0])==null?void 0:h.selectedShippingMethod;if(!s)return;const{amount:c,amountExclTax:r,amountInclTax:m}=s;a({estimated:!1,amount:c,amountExclTax:r,amountInclTax:m})},{eager:!0});return()=>{i==null||i.off()}},[]);const D=()=>o?t("span",{"data-testId":"free-shipping",children:S.freeShipping}):E&&(e!=null&&e.amountInclTax)?t(x,{"data-testid":"shipping",amount:e.amountInclTax.value,currency:e.amountInclTax.currency}):t(x,{"data-testid":"shipping",amount:e==null?void 0:e.amount.value,currency:e==null?void 0:e.amount.currency}),N=()=>e!=null&&e.amountExclTax?t(x,{"data-testid":"shipping-excluding-tax",amount:e.amountExclTax.value,currency:e.amountExclTax.currency}):t("span",{children:S.taxToBeDetermined});return t("div",{"data-testid":"estimate-shipping",className:"checkout-estimate-shipping",children:d?t(G,{estimated:e.estimated,price:D(),taxExcluded:_&&!o,taxIncluded:E&&!o,priceExclTax:N()}):t(L,{})})};export{O as EstimateShipping,O as default}; diff --git a/scripts/__dropins__/storefront-checkout/containers/LoginForm.js b/scripts/__dropins__/storefront-checkout/containers/LoginForm.js index 504f37c6b7..baa727fcc5 100644 --- a/scripts/__dropins__/storefront-checkout/containers/LoginForm.js +++ b/scripts/__dropins__/storefront-checkout/containers/LoginForm.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as e,jsxs as s,Fragment as w}from"@dropins/tools/preact-jsx-runtime.js";import{s as H}from"../chunks/fetch-graphql.js";import{c as R,b as V}from"../chunks/store-config.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import{classes as j}from"@dropins/tools/lib.js";import{i as q,s as D}from"../chunks/setGuestEmailOnCart.js";import{Field as W,Input as G,Skeleton as U,SkeletonRow as x}from"@dropins/tools/components.js";/* empty css *//* empty css */import{useText as b,Text as _}from"@dropins/tools/i18n.js";/* empty css *//* empty css *//* empty css */import{w as J}from"../chunks/withConditionalRendering.js";import{useState as v,useRef as K,useEffect as C}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const O=({value:t,error:i,hint:g,onChange:h,onBlur:o,onInvalid:u})=>{const m=b({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return e(W,{size:"medium",error:i,hint:g,children:e(G,{"aria-label":m.LoginFormLabel,"aria-required":!0,autocomplete:"email",floatingLabel:m.LoginFormFloatingLabel,id:"customer-email",name:"customer-email",onBlur:o,onChange:h,onInvalid:u,placeholder:m.LoginFormPlaceholder,required:!0,type:"email",value:t})})},Q=({onClick:t})=>s("div",{className:"checkout-login-form__sign-in",children:[e(_,{id:"Checkout.LoginForm.account"}),e("a",{"data-testid":"sign-in-link",className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:t,children:e(_,{id:"Checkout.LoginForm.signIn"})})]}),X=({className:t,customerDetails:i,email:g,error:h,hint:o,loading:u=!1,name:m,onEmailBlur:f,onEmailChange:k,onEmailInvalid:E,onSignInClick:a,onSignOutClick:F,...L})=>{const l=b({Title:"Checkout.LoginForm.title"});return u?e(Y,{}):s("div",{className:"checkout-login-form","data-testid":"checkout-login-form",children:[s("div",{className:"checkout-login-form__heading",children:[e("h2",{className:"checkout-login-form__title",children:l.Title}),i?e(Z,{onClick:d=>{d.preventDefault(),F==null||F()}}):e(Q,{onClick:d=>{d.preventDefault(),a==null||a(g)}})]}),i?s("div",{className:"checkout-login-form__customer-details",children:[e("div",{className:"checkout-login-form__customer-name",children:`${i.firstName} ${i.lastName}`}),e("div",{className:"checkout-login-form__customer-email",children:i.email})]}):e("div",{className:"checkout-login-form__content",children:s("form",{...L,className:j(["dropin-login-form__form",t]),name:m,noValidate:!0,children:[e("button",{type:"submit",disabled:!0,style:"display: none","aria-hidden":"true"}),e(O,{value:g,error:h,hint:o,onChange:k,onBlur:f,onInvalid:E})]})})]})},Y=()=>s(U,{"data-testid":"login-form-skeleton",children:[e(x,{variant:"heading",fullWidth:!0}),e(x,{size:"medium",fullWidth:!0})]}),Z=({onClick:t})=>s("p",{className:"checkout-login-form__sign-out",children:[e(_,{id:"Checkout.LoginForm.switch"}),e("a",{className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:t,children:e(_,{id:"Checkout.LoginForm.signOut"})})]}),S={EMAIL:/^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i},N=t=>S.EMAIL.test(t),ee=1e3,y=({onSignInClick:t,onSignOutClick:i,initialData:g,...h})=>{const[o,u]=v(""),[m,f]=v(""),[k,E]=v(!0),[a,F]=v(!0),L=K(""),l=R.value.data,d=(l==null?void 0:l.email)||"",p=V.value.data,c=b({LoginFormInvalidEmailError:"Checkout.LoginForm.invalidEmailError",LoginFormMissingEmailError:"Checkout.LoginForm.missingEmailError",LoginFormEmailExistsAlreadyHaveAccount:"Checkout.LoginForm.emailExists.alreadyHaveAccount",LoginFormEmailExistsSignInButton:"Checkout.LoginForm.emailExists.signInButton",LoginFormEmailExistsForFasterCheckout:"Checkout.LoginForm.emailExists.forFasterCheckout"}),A=r=>r.valid?"":r.valueMissing?c.LoginFormMissingEmailError:c.LoginFormInvalidEmailError,B=r=>N(r)?"":r===""?c.LoginFormMissingEmailError:c.LoginFormInvalidEmailError,M=r=>{const n=r.target;u(n.value),f(""),E(!0)},T=r=>{const n=r.target;f(B(n.value))},z=r=>{const n=r.target;f(A(n.validity))};C(()=>{!a||!l||(F(!1),u(l.email||""))},[l,a]),C(()=>{if(a||H.authenticated)return;const r=setTimeout(()=>{!N(o)||o===L.current||(L.current=o,q(o).then(n=>{E(n),d!==o&&D(o).catch(console.error)}).catch(n=>{console.error(n),E(!0)}))},ee);return()=>{r&&clearTimeout(r)}},[d,o,a]);const I=k?"":s(w,{children:[c.LoginFormEmailExistsAlreadyHaveAccount," ",e("a",{href:"#",onClick:r=>{r.preventDefault(),t==null||t(o)},children:c.LoginFormEmailExistsSignInButton})," ",c.LoginFormEmailExistsForFasterCheckout]}),$=r=>{t==null||t(N(r)?r:"")},P=p?{firstName:p.firstName,lastName:p.lastName,email:p.email}:void 0;return e(X,{...h,customerDetails:P,email:o,error:m,hint:I,loading:a,onEmailBlur:T,onEmailChange:M,onEmailInvalid:z,onSignInClick:$,onSignOutClick:i})};y.displayName="LoginFormContainer";const _e=J(y);export{_e as LoginForm,_e as default}; +import{jsx as e,jsxs as s,Fragment as w}from"@dropins/tools/preact-jsx-runtime.js";import{s as H}from"../chunks/store-config.js";import{c as R,b as V}from"../chunks/transform-store-config.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import{classes as j}from"@dropins/tools/lib.js";import{i as q,s as D}from"../chunks/setGuestEmailOnCart.js";import{Field as W,Input as G,Skeleton as U,SkeletonRow as x}from"@dropins/tools/components.js";/* empty css *//* empty css */import{useText as b,Text as _}from"@dropins/tools/i18n.js";/* empty css *//* empty css *//* empty css */import{w as J}from"../chunks/withConditionalRendering.js";import{useState as v,useRef as K,useEffect as C}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/errors.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const O=({value:t,error:i,hint:g,onChange:h,onBlur:o,onInvalid:u})=>{const m=b({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return e(W,{size:"medium",error:i,hint:g,children:e(G,{"aria-label":m.LoginFormLabel,"aria-required":!0,autocomplete:"email",floatingLabel:m.LoginFormFloatingLabel,id:"customer-email",name:"customer-email",onBlur:o,onChange:h,onInvalid:u,placeholder:m.LoginFormPlaceholder,required:!0,type:"email",value:t})})},Q=({onClick:t})=>s("div",{className:"checkout-login-form__sign-in",children:[e(_,{id:"Checkout.LoginForm.account"}),e("a",{"data-testid":"sign-in-link",className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:t,children:e(_,{id:"Checkout.LoginForm.signIn"})})]}),X=({className:t,customerDetails:i,email:g,error:h,hint:o,loading:u=!1,name:m,onEmailBlur:f,onEmailChange:k,onEmailInvalid:E,onSignInClick:a,onSignOutClick:F,...L})=>{const l=b({Title:"Checkout.LoginForm.title"});return u?e(Y,{}):s("div",{className:"checkout-login-form","data-testid":"checkout-login-form",children:[s("div",{className:"checkout-login-form__heading",children:[e("h2",{className:"checkout-login-form__title",children:l.Title}),i?e(Z,{onClick:d=>{d.preventDefault(),F==null||F()}}):e(Q,{onClick:d=>{d.preventDefault(),a==null||a(g)}})]}),i?s("div",{className:"checkout-login-form__customer-details",children:[e("div",{className:"checkout-login-form__customer-name",children:`${i.firstName} ${i.lastName}`}),e("div",{className:"checkout-login-form__customer-email",children:i.email})]}):e("div",{className:"checkout-login-form__content",children:s("form",{...L,className:j(["dropin-login-form__form",t]),name:m,noValidate:!0,children:[e("button",{type:"submit",disabled:!0,style:"display: none","aria-hidden":"true"}),e(O,{value:g,error:h,hint:o,onChange:k,onBlur:f,onInvalid:E})]})})]})},Y=()=>s(U,{"data-testid":"login-form-skeleton",children:[e(x,{variant:"heading",fullWidth:!0}),e(x,{size:"medium",fullWidth:!0})]}),Z=({onClick:t})=>s("p",{className:"checkout-login-form__sign-out",children:[e(_,{id:"Checkout.LoginForm.switch"}),e("a",{className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:t,children:e(_,{id:"Checkout.LoginForm.signOut"})})]}),S={EMAIL:/^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i},N=t=>S.EMAIL.test(t),ee=1e3,y=({onSignInClick:t,onSignOutClick:i,initialData:g,...h})=>{const[o,u]=v(""),[m,f]=v(""),[k,E]=v(!0),[a,F]=v(!0),L=K(""),l=R.value.data,d=(l==null?void 0:l.email)||"",p=V.value.data,c=b({LoginFormInvalidEmailError:"Checkout.LoginForm.invalidEmailError",LoginFormMissingEmailError:"Checkout.LoginForm.missingEmailError",LoginFormEmailExistsAlreadyHaveAccount:"Checkout.LoginForm.emailExists.alreadyHaveAccount",LoginFormEmailExistsSignInButton:"Checkout.LoginForm.emailExists.signInButton",LoginFormEmailExistsForFasterCheckout:"Checkout.LoginForm.emailExists.forFasterCheckout"}),A=r=>r.valid?"":r.valueMissing?c.LoginFormMissingEmailError:c.LoginFormInvalidEmailError,B=r=>N(r)?"":r===""?c.LoginFormMissingEmailError:c.LoginFormInvalidEmailError,M=r=>{const n=r.target;u(n.value),f(""),E(!0)},T=r=>{const n=r.target;f(B(n.value))},z=r=>{const n=r.target;f(A(n.validity))};C(()=>{!a||!l||(F(!1),u(l.email||""))},[l,a]),C(()=>{if(a||H.authenticated)return;const r=setTimeout(()=>{!N(o)||o===L.current||(L.current=o,q(o).then(n=>{E(n),d!==o&&D(o).catch(console.error)}).catch(n=>{console.error(n),E(!0)}))},ee);return()=>{r&&clearTimeout(r)}},[d,o,a]);const I=k?"":s(w,{children:[c.LoginFormEmailExistsAlreadyHaveAccount," ",e("a",{href:"#",onClick:r=>{r.preventDefault(),t==null||t(o)},children:c.LoginFormEmailExistsSignInButton})," ",c.LoginFormEmailExistsForFasterCheckout]}),$=r=>{t==null||t(N(r)?r:"")},P=p?{firstName:p.firstName,lastName:p.lastName,email:p.email}:void 0;return e(X,{...h,customerDetails:P,email:o,error:m,hint:I,loading:a,onEmailBlur:T,onEmailChange:M,onEmailInvalid:z,onSignInClick:$,onSignOutClick:i})};y.displayName="LoginFormContainer";const ke=J(y);export{ke as LoginForm,ke as default}; diff --git a/scripts/__dropins__/storefront-checkout/containers/MergedCartBanner.js b/scripts/__dropins__/storefront-checkout/containers/MergedCartBanner.js index 915e96391d..3b42df2d3a 100644 --- a/scripts/__dropins__/storefront-checkout/containers/MergedCartBanner.js +++ b/scripts/__dropins__/storefront-checkout/containers/MergedCartBanner.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as e}from"@dropins/tools/preact-jsx-runtime.js";import{AlertBanner as g,Icon as u}from"@dropins/tools/components.js";import{c as h}from"../chunks/classes.js";import{events as B}from"@dropins/tools/event-bus.js";import*as l from"@dropins/tools/preact-compat.js";import{useState as I,useEffect as M}from"@dropins/tools/preact-compat.js";import{w as v}from"../chunks/withConditionalRendering.js";import{useText as w,Text as x}from"@dropins/tools/i18n.js";import"../chunks/store-config.js";import"@dropins/tools/signals.js";import"../chunks/ServerErrorSignal.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/lib.js";import"@dropins/tools/fetch-graphql.js";const H=t=>l.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},l.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0 12C0 5.37931 5.37931 0 12 0C18.6207 0 24 5.37931 24 12C24 18.6207 18.6207 24 12 24C5.37931 24 0 18.6207 0 12ZM11.8885 5.06101C11.1405 5.06101 10.5357 5.66579 10.5357 6.4138V6.57295C10.5835 7.27321 11.1882 7.81433 11.8885 7.76658H12.0795C12.7797 7.70292 13.289 7.09815 13.2413 6.4138C13.2413 5.66579 12.6365 5.06101 11.8885 5.06101ZM13.1935 16.8223H14.1007C14.2599 16.8223 14.4031 16.9655 14.4031 17.1247V17.7294C14.4031 17.9045 14.2599 18.0318 14.1007 18.0318H9.8832C9.70813 18.0318 9.58081 17.8886 9.58081 17.7294V17.1247C9.58081 16.9496 9.72405 16.8223 9.8832 16.8223H10.7904V10.7905H9.8832C9.70813 10.7905 9.58081 10.6472 9.58081 10.4881V9.88329C9.58081 9.70823 9.72405 9.58091 9.8832 9.58091H12.5888C12.923 9.58091 13.1935 9.85146 13.1935 10.1857V16.8223Z",fill:"currentColor"})),C=({className:t,initialData:V,...c})=>{const[r,a]=I(0),i=w({mergedCartBannerItems:e(x,{id:"Checkout.MergedCartBanner.items",fields:{count:r},plural:r})});M(()=>{const n=B.on("cart/merged",o=>{var m;const s=(m=o==null?void 0:o.oldCartItems)==null?void 0:m.reduce((f,p)=>f+p.quantity,0);s>0&&a(s)});return()=>{n==null||n.off()}},[]);const d=()=>{a(0)};return r?e(g,{...c,"aria-label":i.mergedCartBannerItems,className:h(["checkout__banner",t]),"data-testid":"merged-cart-banner",icon:e(u,{source:H}),message:e("span",{children:i.mergedCartBannerItems}),onDismiss:d,variant:"neutral"}):null};C.displayName="MergedCartBannerContainer";const A=v(C);export{A as MergedCartBanner,A as default}; +import{jsx as e}from"@dropins/tools/preact-jsx-runtime.js";import{AlertBanner as g,Icon as u}from"@dropins/tools/components.js";import{c as h}from"../chunks/classes.js";import{events as B}from"@dropins/tools/event-bus.js";import*as l from"@dropins/tools/preact-compat.js";import{useState as I,useEffect as M}from"@dropins/tools/preact-compat.js";import{w as v}from"../chunks/withConditionalRendering.js";import{useText as w,Text as x}from"@dropins/tools/i18n.js";import"../chunks/transform-store-config.js";import"../chunks/store-config.js";import"@dropins/tools/signals.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const H=t=>l.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},l.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0 12C0 5.37931 5.37931 0 12 0C18.6207 0 24 5.37931 24 12C24 18.6207 18.6207 24 12 24C5.37931 24 0 18.6207 0 12ZM11.8885 5.06101C11.1405 5.06101 10.5357 5.66579 10.5357 6.4138V6.57295C10.5835 7.27321 11.1882 7.81433 11.8885 7.76658H12.0795C12.7797 7.70292 13.289 7.09815 13.2413 6.4138C13.2413 5.66579 12.6365 5.06101 11.8885 5.06101ZM13.1935 16.8223H14.1007C14.2599 16.8223 14.4031 16.9655 14.4031 17.1247V17.7294C14.4031 17.9045 14.2599 18.0318 14.1007 18.0318H9.8832C9.70813 18.0318 9.58081 17.8886 9.58081 17.7294V17.1247C9.58081 16.9496 9.72405 16.8223 9.8832 16.8223H10.7904V10.7905H9.8832C9.70813 10.7905 9.58081 10.6472 9.58081 10.4881V9.88329C9.58081 9.70823 9.72405 9.58091 9.8832 9.58091H12.5888C12.923 9.58091 13.1935 9.85146 13.1935 10.1857V16.8223Z",fill:"currentColor"})),C=({className:t,initialData:V,...c})=>{const[r,a]=I(0),i=w({mergedCartBannerItems:e(x,{id:"Checkout.MergedCartBanner.items",fields:{count:r},plural:r})});M(()=>{const n=B.on("cart/merged",o=>{var m;const s=(m=o==null?void 0:o.oldCartItems)==null?void 0:m.reduce((f,p)=>f+p.quantity,0);s>0&&a(s)});return()=>{n==null||n.off()}},[]);const d=()=>{a(0)};return r?e(g,{...c,"aria-label":i.mergedCartBannerItems,className:h(["checkout__banner",t]),"data-testid":"merged-cart-banner",icon:e(u,{source:H}),message:e("span",{children:i.mergedCartBannerItems}),onDismiss:d,variant:"neutral"}):null};C.displayName="MergedCartBannerContainer";const A=v(C);export{A as MergedCartBanner,A as default}; diff --git a/scripts/__dropins__/storefront-checkout/containers/PaymentMethods.js b/scripts/__dropins__/storefront-checkout/containers/PaymentMethods.js index c0e4068009..a366d72cee 100644 --- a/scripts/__dropins__/storefront-checkout/containers/PaymentMethods.js +++ b/scripts/__dropins__/storefront-checkout/containers/PaymentMethods.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as n,jsxs as v,Fragment as D}from"@dropins/tools/preact-jsx-runtime.js";import{s as $}from"../chunks/fetch-graphql.js";import{c as H,a as y}from"../chunks/store-config.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import{classes as S,Slot as T}from"@dropins/tools/lib.js";import{s as B}from"../chunks/setPaymentMethod.js";/* empty css */import{IllustratedMessage as U,Icon as Z,ProgressSpinner as F,ToggleButton as q,Skeleton as G,SkeletonRow as g}from"@dropins/tools/components.js";import*as k from"@dropins/tools/preact-compat.js";import{useState as w,useCallback as N,useEffect as E}from"@dropins/tools/preact-compat.js";import{useText as J}from"@dropins/tools/i18n.js";import{w as K}from"../chunks/withConditionalRendering.js";import{useRef as Q}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const X=e=>k.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},k.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),k.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),k.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),Y=({code:e,loading:r,selected:o,onChange:d,title:h})=>n(q,{className:"checkout-payment-methods__method",label:h,name:"payment-method",value:e,selected:o,onChange:d,busy:r}),ee=({className:e,paymentMethodContent:r,loading:o=!1,initializing:d=!1,onChange:h=()=>{},options:c,selection:M})=>{const a=J({Title:"Checkout.PaymentMethods.title",EmptyState:"Checkout.PaymentMethods.emptyState"});return d?n(te,{}):v("div",{className:S(["checkout-payment-methods",e]),children:[n("h2",{className:"checkout-payment-methods__title",children:a.Title}),!o&&c.length===0&&n(U,{icon:n(Z,{source:X}),message:n("p",{children:a.EmptyState})}),v("div",{className:S(["checkout-payment-methods__wrapper"]),children:[o&&n(F,{className:"checkout-payment-methods__spinner"}),n("div",{className:S(["checkout-payment-methods__methods",["checkout-payment-methods--loading",o],["checkout-payment-methods--full-width",c.length%2!==0]]),children:c==null?void 0:c.map(i=>n(Y,{code:i.code,onChange:h,selected:i.code===M,title:i.title},i.code))}),r&&n("div",{className:"checkout-payment-methods__content",children:r})]})]})},te=()=>v(G,{"data-testid":"payment-methods-skeleton",children:[n(g,{variant:"heading",size:"medium"}),n(g,{variant:"empty",size:"medium"}),n(g,{size:"xlarge",fullWidth:!0}),n(g,{size:"xlarge",fullWidth:!0})]}),V={free:e=>{const r=document.createElement("div");r.innerText="",e.replaceHTML(r)},checkmo:e=>{const r=document.createElement("div");r.innerText="",e.replaceHTML(r)}},ne=(e,r)=>{const o=Q(e);return r(o.current,e)||(o.current=e),o.current},W=({slots:e,setOnChange:r={}})=>{var _,L;const[o]=w(r),[d,h]=w(V),[c,M]=w(!0),a=H.value.data,i=!!H.value.data,O=H.value.pending,j=(a==null?void 0:a.isVirtual)??!1,z=(_=a==null?void 0:a.shippingAddresses)==null?void 0:_[0],A=(a==null?void 0:a.availablePaymentMethods)||[],m=(L=a==null?void 0:a.selectedPaymentMethod)==null?void 0:L.code,b=j?!0:!!z,l=ne(A,(t,s)=>t.length!==s.length?!1:t.every((p,C)=>p.code===s[C].code)),u=N(t=>{y.value=t,!(!t||!b)&&t!==m&&o[t]!==!1&&B({code:t}).catch(console.error)},[b,m,o]);E(()=>{if(!i)return;if(!!!(l!=null&&l.length)){u(void 0);return}const s=l[0].code;if(!m){u(s);return}const p=l.some(C=>C.code===m);u(p?m:s)},[l,i,m,u]);const I=t=>{u(t)},x=N((t,s)=>{if(!t){console.warn("Payment method handler is ignored because it has no code");return}if(!s){console.warn("Payment method handler is ignored because it is empty");return}h(p=>({...p,[t]:s}))},[]);E(()=>{e!=null&&e.Handlers&&Object.entries(e.Handlers).forEach(([t,s])=>{x(t,s)})},[x,e==null?void 0:e.Handlers]);const f=e!=null&&e.Main?n(T,{name:"PaymentMethods",slot:e==null?void 0:e.Main,context:{replaceHTML(t){this.replaceWith(t),M(!1)}}}):null,P=y.value?d[y.value]:null,R=P?n(T,{name:"PaymentMethodContent",slot:P,context:{cartId:$.cartId||"",replaceHTML(t){this.replaceWith(t)}}},P):void 0;return E(()=>{!c&&d!=V&&console.warn("Payment method handlers you have added are ignored because the default content has been replaced")},[c,d]),v(D,{children:[f&&n(f.type,{ref:f.ref,...f.props}),c&&n(ee,{initializing:i===!1,loading:i&&O,onChange:I,options:l,paymentMethodContent:R,selection:y.value})]})};W.displayName="PaymentMethodsContainer";const Me=K(W);export{Me as PaymentMethods,Me as default}; +import{jsx as n,jsxs as v,Fragment as D}from"@dropins/tools/preact-jsx-runtime.js";import{s as $}from"../chunks/store-config.js";import{c as H,a as y}from"../chunks/transform-store-config.js";import"../chunks/ServerErrorSignal.js";import"@dropins/tools/event-bus.js";import{classes as S,Slot as T}from"@dropins/tools/lib.js";import{s as B}from"../chunks/setPaymentMethod.js";/* empty css */import{IllustratedMessage as U,Icon as Z,ProgressSpinner as F,ToggleButton as q,Skeleton as G,SkeletonRow as g}from"@dropins/tools/components.js";import*as k from"@dropins/tools/preact-compat.js";import{useState as w,useCallback as N,useEffect as E}from"@dropins/tools/preact-compat.js";import{useText as J}from"@dropins/tools/i18n.js";import{w as K}from"../chunks/withConditionalRendering.js";import{useRef as Q}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/errors.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const X=e=>k.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},k.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),k.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),k.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),Y=({code:e,loading:r,selected:o,onChange:d,title:h})=>n(q,{className:"checkout-payment-methods__method",label:h,name:"payment-method",value:e,selected:o,onChange:d,busy:r}),ee=({className:e,paymentMethodContent:r,loading:o=!1,initializing:d=!1,onChange:h=()=>{},options:c,selection:M})=>{const a=J({Title:"Checkout.PaymentMethods.title",EmptyState:"Checkout.PaymentMethods.emptyState"});return d?n(te,{}):v("div",{className:S(["checkout-payment-methods",e]),children:[n("h2",{className:"checkout-payment-methods__title",children:a.Title}),!o&&c.length===0&&n(U,{icon:n(Z,{source:X}),message:n("p",{children:a.EmptyState})}),v("div",{className:S(["checkout-payment-methods__wrapper"]),children:[o&&n(F,{className:"checkout-payment-methods__spinner"}),n("div",{className:S(["checkout-payment-methods__methods",["checkout-payment-methods--loading",o],["checkout-payment-methods--full-width",c.length%2!==0]]),children:c==null?void 0:c.map(i=>n(Y,{code:i.code,onChange:h,selected:i.code===M,title:i.title},i.code))}),r&&n("div",{className:"checkout-payment-methods__content",children:r})]})]})},te=()=>v(G,{"data-testid":"payment-methods-skeleton",children:[n(g,{variant:"heading",size:"medium"}),n(g,{variant:"empty",size:"medium"}),n(g,{size:"xlarge",fullWidth:!0}),n(g,{size:"xlarge",fullWidth:!0})]}),V={free:e=>{const r=document.createElement("div");r.innerText="",e.replaceHTML(r)},checkmo:e=>{const r=document.createElement("div");r.innerText="",e.replaceHTML(r)}},ne=(e,r)=>{const o=Q(e);return r(o.current,e)||(o.current=e),o.current},W=({slots:e,setOnChange:r={}})=>{var _,L;const[o]=w(r),[d,h]=w(V),[c,M]=w(!0),a=H.value.data,i=!!H.value.data,O=H.value.pending,j=(a==null?void 0:a.isVirtual)??!1,z=(_=a==null?void 0:a.shippingAddresses)==null?void 0:_[0],A=(a==null?void 0:a.availablePaymentMethods)||[],m=(L=a==null?void 0:a.selectedPaymentMethod)==null?void 0:L.code,b=j?!0:!!z,l=ne(A,(t,s)=>t.length!==s.length?!1:t.every((p,C)=>p.code===s[C].code)),u=N(t=>{y.value=t,!(!t||!b)&&t!==m&&o[t]!==!1&&B({code:t}).catch(console.error)},[b,m,o]);E(()=>{if(!i)return;if(!!!(l!=null&&l.length)){u(void 0);return}const s=l[0].code;if(!m){u(s);return}const p=l.some(C=>C.code===m);u(p?m:s)},[l,i,m,u]);const I=t=>{u(t)},x=N((t,s)=>{if(!t){console.warn("Payment method handler is ignored because it has no code");return}if(!s){console.warn("Payment method handler is ignored because it is empty");return}h(p=>({...p,[t]:s}))},[]);E(()=>{e!=null&&e.Handlers&&Object.entries(e.Handlers).forEach(([t,s])=>{x(t,s)})},[x,e==null?void 0:e.Handlers]);const f=e!=null&&e.Main?n(T,{name:"PaymentMethods",slot:e==null?void 0:e.Main,context:{replaceHTML(t){this.replaceWith(t),M(!1)}}}):null,P=y.value?d[y.value]:null,R=P?n(T,{name:"PaymentMethodContent",slot:P,context:{cartId:$.cartId||"",replaceHTML(t){this.replaceWith(t)}}},P):void 0;return E(()=>{!c&&d!=V&&console.warn("Payment method handlers you have added are ignored because the default content has been replaced")},[c,d]),v(D,{children:[f&&n(f.type,{ref:f.ref,...f.props}),c&&n(ee,{initializing:i===!1,loading:i&&O,onChange:I,options:l,paymentMethodContent:R,selection:y.value})]})};W.displayName="PaymentMethodsContainer";const Pe=K(W);export{Pe as PaymentMethods,Pe as default}; diff --git a/scripts/__dropins__/storefront-checkout/containers/PlaceOrder.js b/scripts/__dropins__/storefront-checkout/containers/PlaceOrder.js index 151f12a449..1d185eafc8 100644 --- a/scripts/__dropins__/storefront-checkout/containers/PlaceOrder.js +++ b/scripts/__dropins__/storefront-checkout/containers/PlaceOrder.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as a}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Button as x}from"@dropins/tools/components.js";import{classes as E}from"@dropins/tools/lib.js";import{Text as g,useText as v}from"@dropins/tools/i18n.js";import{w as y}from"../chunks/withConditionalRendering.js";import{U as P,s as S}from"../chunks/fetch-graphql.js";import{c as b,a as U}from"../chunks/store-config.js";import{s as I}from"../chunks/ServerErrorSignal.js";import{events as w}from"@dropins/tools/event-bus.js";import{useState as N,useCallback as m,useEffect as T}from"@dropins/tools/preact-compat.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";const z=r=>r instanceof TypeError||r instanceof P,D=({className:r,disabled:t=!1,onClick:o})=>a("div",{className:E(["checkout-place-order",r]),children:a(x,{className:"checkout-place-order__button","data-testid":"place-order-button",disabled:t,onClick:o,size:"medium",type:"submit",variant:"primary",children:a(g,{id:"Checkout.PlaceOrder.button"})},"placeOrder")}),l=({disabled:r=!1,handleValidation:t,handlePlaceOrder:o,...u})=>{const[d,p]=N(!1),{data:f,pending:O}=b.value,k=!!f,s=v({CheckoutUnexpectedError:"Checkout.ServerError.unexpected"}),n=m(e=>{I.value=z(e)?s.CheckoutUnexpectedError:e.message},[s]),h=m(async()=>{try{if(!(t?t():!0))return;await o({cartId:S.cartId||"",code:U.value||""})}catch(e){n(e)}},[t,o,n]);return T(()=>{const e=w.on("cart/initialized",c=>{const C=(c==null?void 0:c.items)||[];p(C.some(i=>i.outOfStock||i.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[]),a(D,{...u,onClick:h,disabled:r||!k||O||d})};l.displayName="PlaceOrderContainer";const J=y(l);export{J as PlaceOrder,J as default}; +import{jsx as a}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Button as x}from"@dropins/tools/components.js";import{classes as E}from"@dropins/tools/lib.js";import{Text as g,useText as v}from"@dropins/tools/i18n.js";import{w as y}from"../chunks/withConditionalRendering.js";import{s as P}from"../chunks/store-config.js";import{c as S,a as b}from"../chunks/transform-store-config.js";import{s as U}from"../chunks/ServerErrorSignal.js";import{U as I}from"../chunks/errors.js";import{events as w}from"@dropins/tools/event-bus.js";import{useState as N,useCallback as m,useEffect as T}from"@dropins/tools/preact-compat.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const z=r=>r instanceof TypeError||r instanceof I,D=({className:r,disabled:t=!1,onClick:o})=>a("div",{className:E(["checkout-place-order",r]),children:a(x,{className:"checkout-place-order__button","data-testid":"place-order-button",disabled:t,onClick:o,size:"medium",type:"submit",variant:"primary",children:a(g,{id:"Checkout.PlaceOrder.button"})},"placeOrder")}),l=({disabled:r=!1,handleValidation:t,handlePlaceOrder:o,...u})=>{const[d,p]=N(!1),{data:f,pending:O}=S.value,k=!!f,s=v({CheckoutUnexpectedError:"Checkout.ServerError.unexpected"}),n=m(e=>{U.value=z(e)?s.CheckoutUnexpectedError:e.message},[s]),h=m(async()=>{try{if(!(t?t():!0))return;await o({cartId:P.cartId||"",code:b.value||""})}catch(e){n(e)}},[t,o,n]);return T(()=>{const e=w.on("cart/initialized",c=>{const C=(c==null?void 0:c.items)||[];p(C.some(i=>i.outOfStock||i.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[]),a(D,{...u,onClick:h,disabled:r||!k||O||d})};l.displayName="PlaceOrderContainer";const K=y(l);export{K as PlaceOrder,K as default}; diff --git a/scripts/__dropins__/storefront-checkout/containers/ShippingMethods.js b/scripts/__dropins__/storefront-checkout/containers/ShippingMethods.js index 0fd3a34d9d..da3bcedd95 100644 --- a/scripts/__dropins__/storefront-checkout/containers/ShippingMethods.js +++ b/scripts/__dropins__/storefront-checkout/containers/ShippingMethods.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as n,jsxs as v,Fragment as T}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/fetch-graphql.js";import{s as k,e as S,c as W}from"../chunks/store-config.js";import"../chunks/ServerErrorSignal.js";import{events as H}from"@dropins/tools/event-bus.js";import{classes as x,Slot as z}from"@dropins/tools/lib.js";import{s as B}from"../chunks/setShippingMethods.js";/* empty css */import{IllustratedMessage as R,Icon as V,ProgressSpinner as A,RadioButton as O,Price as P,Skeleton as D,SkeletonRow as L}from"@dropins/tools/components.js";import*as u from"@dropins/tools/preact-compat.js";import{useCallback as Z,useMemo as $,useEffect as q}from"@dropins/tools/preact-compat.js";import{useText as F}from"@dropins/tools/i18n.js";import{useState as N,useEffect as _}from"@dropins/tools/preact-hooks.js";import{w as G}from"../chunks/withConditionalRendering.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const J=e=>({countryCode:e.country_id,postCode:e.postcode||"",...e.region_id?{regionId:Number(e.region_id)}:{...e.region?{region:e.region}:{}}}),K=e=>({carrierCode:e.carrier.code||"",methodCode:e.code||"",amount:e.amount,amountExclTax:e.amountExclTax,amountInclTax:e.amountInclTax}),Q=e=>u.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.47266 4.90002H15.1851V10.9645H21.2495L23 12.715V17.6124H20.073",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76151 16.7898C9.76151 18.0525 8.72845 19.076 7.46582 19.076C6.20318 19.076 5.17969 18.0429 5.17969 16.7803C5.17969 15.5176 6.20318 14.4941 7.46582 14.4941C8.72845 14.4941 9.75195 15.5176 9.76151 16.7803C9.76151 16.7803 9.76151 16.7803 9.76151 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8726 16.7898C19.8726 18.062 18.8491 19.0855 17.5769 19.0855C16.3047 19.0855 15.2812 18.062 15.2812 16.7898C15.2812 15.5176 16.3047 14.4941 17.5769 14.4941C18.8491 14.4941 19.8726 15.5176 19.8726 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),U=({className:e,isLoading:t=!1,onSelectionChange:s=()=>{},options:c,selection:l,...p})=>{const i=F({Title:"Checkout.ShippingMethods.title",EmptyState:"Checkout.ShippingMethods.emptyState"});return c===void 0?n(X,{}):v("div",{...p,className:x(["checkout-shipping-methods",e]),children:[n("h3",{className:"checkout-shipping-methods__title",children:i.Title}),!t&&c.length===0&&n(R,{icon:n(V,{source:Q}),message:n("p",{children:i.EmptyState})}),v("div",{className:x(["checkout-shipping-methods__content"]),children:[t&&n(A,{className:"checkout-shipping-methods__spinner"}),n("div",{className:x(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",t]]),children:c.map(o=>n(O,{"data-testid":"shipping-method-radiobutton","aria-busy":t,id:o.value,name:"shipping-method",className:"checkout-shipping-methods__method",label:v(T,{children:[n(P,{amount:o.amount.value,currency:o.amount.currency})," ",n("span",{children:o.carrier.title})]}),description:o.title,value:o.value,checked:(l==null?void 0:l.value)===o.value,onChange:()=>s(o)},o.value))})]})]})},X=()=>v(D,{"data-testid":"shipping-methods-skeleton",children:[n(L,{variant:"heading",size:"small"}),n(L,{variant:"empty",size:"small"}),n(L,{size:"medium",fullWidth:!0}),n(L,{size:"medium",fullWidth:!0})]});function Y(){var a;const[e,t]=N(),[s,c]=N();_(()=>{H.on("checkout/estimate-shipping-address",({address:E,isValid:M})=>{t({address:E,isValid:M})})},[]),_(()=>{c(k.value)},[k.value]),_(()=>{S.value.pending?c(void 0):c(k.value)},[S.value.pending]);const{country_id:l,region_id:p,region:i,postcode:o}=(e==null?void 0:e.address)||{},r=!!e,g=W.value.data,C=!!((a=g==null?void 0:g.shippingAddresses)!=null&&a[0]),d=e==null?void 0:e.isValid;_(()=>{C||d||!s||!r||H.emit("shipping/estimate",{address:J({country_id:l,region_id:p,region:i,postcode:o}),shippingMethod:K(s)})},[s,l,p,i,o,r,C,d])}const j=(e,t)=>e.code===t.code&&e.carrier.code===t.carrier.code;function ee({preSelectedMethod:e,onShippingMethodSelect:t}){const s=W.value.data,c=W.value.pending,l=S.value.data,p=S.value.pending,i=k.value,o=s==null?void 0:s.shippingAddresses,r=o==null?void 0:o[0],g=!!r,C=r==null?void 0:r.availableShippingMethods,d=r==null?void 0:r.selectedShippingMethod,a=C||l,E=Z(m=>{if(!g)return;const f={method_code:m.code,carrier_code:m.carrier.code};B([f]).catch(b=>{console.error("Setting shipping methods on cart failed:",b)})},[g]),M=m=>{k.value=m,t==null||t(m)},h=$(()=>{if(!(a!=null&&a.length))return;const m=a[0],f=i||d;return f?a.some(w=>j(w,f))?f:m:a.find(y=>y.carrier.code===(e==null?void 0:e.carrierCode)&&y.code===(e==null?void 0:e.methodCode))||m},[i,d,a,e]);return q(()=>{h&&((!i||!j(h,i))&&(k.value=h,t==null||t(h)),(!d||!j(h,d))&&E(h))},[h,i,d,E,t]),{isLoading:c||p,options:a,selection:h,onSelectionChange:M}}const I=({preSelectedMethod:e,shippingMethodsSlot:t,onShippingMethodSelect:s,initialData:c,...l})=>{const{isLoading:p,options:i,selection:o,onSelectionChange:r}=ee({preSelectedMethod:e,onShippingMethodSelect:s});return Y(),v(T,{children:[n(U,{...l,isLoading:p,onSelectionChange:r,options:i,selection:o}),!p&&t&&n(z,{name:"ShippingMethods",slot:t})]})};I.displayName="ShippingMethodsContainer";const ve=G(I);export{ve as ShippingMethods,ve as default}; +import{jsx as n,jsxs as v,Fragment as T}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/store-config.js";import{s as k,e as S,c as W}from"../chunks/transform-store-config.js";import"../chunks/ServerErrorSignal.js";import{events as H}from"@dropins/tools/event-bus.js";import{classes as x,Slot as z}from"@dropins/tools/lib.js";import{s as B}from"../chunks/setShippingMethods.js";/* empty css */import{IllustratedMessage as R,Icon as V,ProgressSpinner as A,RadioButton as O,Price as P,Skeleton as D,SkeletonRow as L}from"@dropins/tools/components.js";import*as p from"@dropins/tools/preact-compat.js";import{useCallback as Z,useMemo as $,useEffect as q}from"@dropins/tools/preact-compat.js";import{useText as F}from"@dropins/tools/i18n.js";import{useState as N,useEffect as _}from"@dropins/tools/preact-hooks.js";import{w as G}from"../chunks/withConditionalRendering.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/errors.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const J=e=>({countryCode:e.country_id,postCode:e.postcode||"",...e.region_id?{regionId:Number(e.region_id)}:{...e.region?{region:e.region}:{}}}),K=e=>({carrierCode:e.carrier.code||"",methodCode:e.code||"",amount:e.amount,amountExclTax:e.amountExclTax,amountInclTax:e.amountInclTax}),Q=e=>p.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.47266 4.90002H15.1851V10.9645H21.2495L23 12.715V17.6124H20.073",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76151 16.7898C9.76151 18.0525 8.72845 19.076 7.46582 19.076C6.20318 19.076 5.17969 18.0429 5.17969 16.7803C5.17969 15.5176 6.20318 14.4941 7.46582 14.4941C8.72845 14.4941 9.75195 15.5176 9.76151 16.7803C9.76151 16.7803 9.76151 16.7803 9.76151 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8726 16.7898C19.8726 18.062 18.8491 19.0855 17.5769 19.0855C16.3047 19.0855 15.2812 18.062 15.2812 16.7898C15.2812 15.5176 16.3047 14.4941 17.5769 14.4941C18.8491 14.4941 19.8726 15.5176 19.8726 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),U=({className:e,isLoading:t=!1,onSelectionChange:s=()=>{},options:c,selection:l,...u})=>{const i=F({Title:"Checkout.ShippingMethods.title",EmptyState:"Checkout.ShippingMethods.emptyState"});return c===void 0?n(X,{}):v("div",{...u,className:x(["checkout-shipping-methods",e]),children:[n("h3",{className:"checkout-shipping-methods__title",children:i.Title}),!t&&c.length===0&&n(R,{icon:n(V,{source:Q}),message:n("p",{children:i.EmptyState})}),v("div",{className:x(["checkout-shipping-methods__content"]),children:[t&&n(A,{className:"checkout-shipping-methods__spinner"}),n("div",{className:x(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",t]]),children:c.map(o=>n(O,{"data-testid":"shipping-method-radiobutton","aria-busy":t,id:o.value,name:"shipping-method",className:"checkout-shipping-methods__method",label:v(T,{children:[n(P,{amount:o.amount.value,currency:o.amount.currency})," ",n("span",{children:o.carrier.title})]}),description:o.title,value:o.value,checked:(l==null?void 0:l.value)===o.value,onChange:()=>s(o)},o.value))})]})]})},X=()=>v(D,{"data-testid":"shipping-methods-skeleton",children:[n(L,{variant:"heading",size:"small"}),n(L,{variant:"empty",size:"small"}),n(L,{size:"medium",fullWidth:!0}),n(L,{size:"medium",fullWidth:!0})]});function Y(){var a;const[e,t]=N(),[s,c]=N();_(()=>{H.on("checkout/estimate-shipping-address",({address:E,isValid:M})=>{t({address:E,isValid:M})})},[]),_(()=>{c(k.value)},[k.value]),_(()=>{S.value.pending?c(void 0):c(k.value)},[S.value.pending]);const{country_id:l,region_id:u,region:i,postcode:o}=(e==null?void 0:e.address)||{},r=!!e,g=W.value.data,C=!!((a=g==null?void 0:g.shippingAddresses)!=null&&a[0]),d=e==null?void 0:e.isValid;_(()=>{C||d||!s||!r||H.emit("shipping/estimate",{address:J({country_id:l,region_id:u,region:i,postcode:o}),shippingMethod:K(s)})},[s,l,u,i,o,r,C,d])}const j=(e,t)=>e.code===t.code&&e.carrier.code===t.carrier.code;function ee({preSelectedMethod:e,onShippingMethodSelect:t}){const s=W.value.data,c=W.value.pending,l=S.value.data,u=S.value.pending,i=k.value,o=s==null?void 0:s.shippingAddresses,r=o==null?void 0:o[0],g=!!r,C=r==null?void 0:r.availableShippingMethods,d=r==null?void 0:r.selectedShippingMethod,a=C||l,E=Z(m=>{if(!g)return;const f={method_code:m.code,carrier_code:m.carrier.code};B([f]).catch(b=>{console.error("Setting shipping methods on cart failed:",b)})},[g]),M=m=>{k.value=m,t==null||t(m)},h=$(()=>{if(!(a!=null&&a.length))return;const m=a[0],f=i||d;return f?a.some(w=>j(w,f))?f:m:a.find(y=>y.carrier.code===(e==null?void 0:e.carrierCode)&&y.code===(e==null?void 0:e.methodCode))||m},[i,d,a,e]);return q(()=>{h&&((!i||!j(h,i))&&(k.value=h,t==null||t(h)),(!d||!j(h,d))&&E(h))},[h,i,d,E,t]),{isLoading:c||u,options:a,selection:h,onSelectionChange:M}}const I=({preSelectedMethod:e,shippingMethodsSlot:t,onShippingMethodSelect:s,initialData:c,...l})=>{const{isLoading:u,options:i,selection:o,onSelectionChange:r}=ee({preSelectedMethod:e,onShippingMethodSelect:s});return Y(),v(T,{children:[n(U,{...l,isLoading:u,onSelectionChange:r,options:i,selection:o}),!u&&t&&n(z,{name:"ShippingMethods",slot:t})]})};I.displayName="ShippingMethodsContainer";const Ce=G(I);export{Ce as ShippingMethods,Ce as default}; diff --git a/scripts/__dropins__/storefront-checkout/lib/state.d.ts b/scripts/__dropins__/storefront-checkout/lib/state.d.ts index 869f98c89c..7d2b319233 100644 --- a/scripts/__dropins__/storefront-checkout/lib/state.d.ts +++ b/scripts/__dropins__/storefront-checkout/lib/state.d.ts @@ -1,24 +1,12 @@ -/******************************************************************** - * ADOBE CONFIDENTIAL - * __________________ - * - * Copyright 2024 Adobe - * All Rights Reserved. - * - * NOTICE: All information contained herein is, and remains - * the property of Adobe and its suppliers, if any. The intellectual - * and technical concepts contained herein are proprietary to Adobe - * and its suppliers and are protected by all applicable intellectual - * property laws, including trade secret and copyright laws. - * Dissemination of this information or reproduction of this material - * is strictly forbidden unless prior written permission is obtained - * from Adobe. - *******************************************************************/ +import { StoreConfig } from '../data/models'; + type State = { authenticated: boolean; cartId: string | null; initialized: boolean; + config: StoreConfig | null; }; export declare const state: State; +export declare const getStoreConfigCache: () => StoreConfig | null; export {}; //# sourceMappingURL=state.d.ts.map \ No newline at end of file diff --git a/scripts/__dropins__/storefront-checkout/render.js b/scripts/__dropins__/storefront-checkout/render.js index c4982a36fe..c5a587aa24 100644 --- a/scripts/__dropins__/storefront-checkout/render.js +++ b/scripts/__dropins__/storefront-checkout/render.js @@ -6,4 +6,4 @@ All Rights Reserved. */ .checkout-place-order{display:grid;padding-bottom:var(--spacing-big)}.checkout-place-order__button{align-self:flex-end;justify-self:flex-end}@media only screen and (min-width:320px) and (max-width: 768px){.checkout-place-order{background-color:var(--color-neutral-200);padding:var(--spacing-medium) var(--spacing-medium) var(--spacing-big) var(--spacing-medium)}.checkout-place-order__button{align-self:center;justify-self:stretch}} .checkout-payment-methods__title{color:var(--color-neutral-800);font:var(--type-headline-2-default-font);letter-spacing:var(--type-headline-2-default-letter-spacing);margin:0 0 var(--spacing-medium) 0}.checkout-payment-methods__wrapper{position:relative;display:grid}.checkout-payment-methods__methods{display:grid;grid-template-columns:1fr 1fr;gap:var(--spacing-medium)}.checkout-payment-methods__content>div[data-slot=PaymentMethodSlot]:not(:empty){margin-top:var(--spacing-medium)}.checkout-payment-methods--full-width{grid-template-columns:1fr}.checkout-payment-methods--loading{opacity:.4;pointer-events:none}.checkout-payment-methods__spinner{margin:0 auto;position:absolute;z-index:999;left:0;right:0;top:calc(50% - (var(--size) / 2));bottom:0}.checkout__content [data-slot=PaymentMethods]:empty{display:none}@media only screen and (min-width: 320px) and (max-width: 768px){.checkout-payment-methods__methods{grid-template-columns:1fr}} .checkout-bill-to-shipping-address label{font:var(--type-body-2-default-font);letter-spacing:var(--type-body-2-default-letter-spacing);gap:0}`,{styleId:"checkout"}); -import{jsx as f}from"@dropins/tools/preact-jsx-runtime.js";import{Render as d}from"@dropins/tools/lib.js";import"./chunks/fetch-graphql.js";import"./chunks/store-config.js";import"./chunks/ServerErrorSignal.js";import{events as p}from"@dropins/tools/event-bus.js";import{c as g}from"./chunks/synchronizeCheckout.js";import{UIProvider as y}from"@dropins/tools/components.js";import{useState as b,useEffect as h}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/signals.js";import"./fragments.js";function O(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var S=function(r){return E(r)&&!w(r)};function E(e){return!!e&&typeof e=="object"}function w(e){var r=Object.prototype.toString.call(e);return r==="[object RegExp]"||r==="[object Date]"||M(e)}var v=typeof Symbol=="function"&&Symbol.for,j=v?Symbol.for("react.element"):60103;function M(e){return e.$$typeof===j}function A(e){return Array.isArray(e)?[]:{}}function i(e,r){return r.clone!==!1&&r.isMergeableObject(e)?a(A(e),e,r):e}function P(e,r,t){return e.concat(r).map(function(o){return i(o,t)})}function I(e,r){if(!r.customMerge)return a;var t=r.customMerge(e);return typeof t=="function"?t:a}function T(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(r){return Object.propertyIsEnumerable.call(e,r)}):[]}function l(e){return Object.keys(e).concat(T(e))}function m(e,r){try{return r in e}catch{return!1}}function C(e,r){return m(e,r)&&!(Object.hasOwnProperty.call(e,r)&&Object.propertyIsEnumerable.call(e,r))}function x(e,r,t){var o={};return t.isMergeableObject(e)&&l(e).forEach(function(n){o[n]=i(e[n],t)}),l(r).forEach(function(n){C(e,n)||(m(e,n)&&t.isMergeableObject(r[n])?o[n]=I(n,t)(e[n],r[n],t):o[n]=i(r[n],t))}),o}function a(e,r,t){t=t||{},t.arrayMerge=t.arrayMerge||P,t.isMergeableObject=t.isMergeableObject||S,t.cloneUnlessOtherwiseSpecified=i;var o=Array.isArray(r),n=Array.isArray(e),c=o===n;return c?o?t.arrayMerge(e,r,t):x(e,r,t):i(r,t)}a.all=function(r,t){if(!Array.isArray(r))throw new Error("first argument should be an array");return r.reduce(function(o,n){return a(o,n,t)},{})};var D=a,B=D;const L=O(B),_={title:"Checkout",LoginForm:{title:"Contact details",account:"Already have an account?",ariaLabel:"Email",invalidEmailError:"Please enter a valid email address.",missingEmailError:"Enter an email address.",emailExists:{alreadyHaveAccount:"It looks like you already have an account.",signInButton:"Sign in",forFasterCheckout:"for a faster checkout."},floatingLabel:"Email *",placeholder:"Enter your email address",signIn:"Sign In",switch:"Do you want to switch account?",signOut:"Sign Out"},ShippingMethods:{title:"Shipping options",emptyState:"This order can't be shipped to the address provided. Please review the address details you entered and make sure they're correct."},BillToShippingAddress:{title:"Bill to shipping address"},PaymentMethods:{title:"Payment",emptyState:"No payment methods available"},OutOfStock:{title:"Your cart contains items that are out of stock",message:"The following items are out of stock:",actions:{reviewCart:"Review cart",removeOutOfStock:"Remove out of stock items"},lowInventory:{one:"Last item!",many:"Only {{count}} left!"},alert:"Out of stock!"},PlaceOrder:{button:"Place Order"},ServerError:{title:"We were unable to process your order",contactSupport:"If you continue to have issues, please contact support.",unexpected:"An unexpected error occurred while processing your order. Please try again later.",button:"Try again"},EmptyCart:{title:"Your cart is empty",button:"Start shopping"},ErrorBanner:{genericMessage:"Server error detected. Please check your connection and try again."},MergedCartBanner:{items:{one:"1 item from a previous session was added to your cart. Please review your new subtotal.",many:"{{count}} items from a previous session were added to your cart. Please review your new subtotal."}},EstimateShipping:{estimated:"Estimated Shipping",freeShipping:"Free",label:"Shipping",taxToBeDetermined:"TBD",withTaxes:"Including taxes",withoutTaxes:"Excluding taxes"}},R={Checkout:_},U={default:R},k=({children:e})=>{var c;const[r,t]=b(),o=(c=g.getConfig())==null?void 0:c.langDefinitions;h(()=>{const s=p.on("locale",u=>{u!==r&&t(u)},{eager:!0});return()=>{s==null||s.off()}},[r]);const n=L(U,o??{});return f(y,{lang:r,langDefinitions:n,children:e})},Q=new d(f(k,{}));export{k as Provider,Q as render}; +import{jsx as f}from"@dropins/tools/preact-jsx-runtime.js";import{Render as d}from"@dropins/tools/lib.js";import"./chunks/store-config.js";import"./chunks/transform-store-config.js";import"./chunks/ServerErrorSignal.js";import{events as p}from"@dropins/tools/event-bus.js";import{c as g}from"./chunks/synchronizeCheckout.js";import{UIProvider as y}from"@dropins/tools/components.js";import{useState as b,useEffect as h}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"./fragments.js";import"./chunks/errors.js";function O(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var S=function(r){return E(r)&&!w(r)};function E(e){return!!e&&typeof e=="object"}function w(e){var r=Object.prototype.toString.call(e);return r==="[object RegExp]"||r==="[object Date]"||M(e)}var v=typeof Symbol=="function"&&Symbol.for,j=v?Symbol.for("react.element"):60103;function M(e){return e.$$typeof===j}function A(e){return Array.isArray(e)?[]:{}}function i(e,r){return r.clone!==!1&&r.isMergeableObject(e)?a(A(e),e,r):e}function P(e,r,t){return e.concat(r).map(function(o){return i(o,t)})}function I(e,r){if(!r.customMerge)return a;var t=r.customMerge(e);return typeof t=="function"?t:a}function T(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(r){return Object.propertyIsEnumerable.call(e,r)}):[]}function l(e){return Object.keys(e).concat(T(e))}function m(e,r){try{return r in e}catch{return!1}}function C(e,r){return m(e,r)&&!(Object.hasOwnProperty.call(e,r)&&Object.propertyIsEnumerable.call(e,r))}function x(e,r,t){var o={};return t.isMergeableObject(e)&&l(e).forEach(function(n){o[n]=i(e[n],t)}),l(r).forEach(function(n){C(e,n)||(m(e,n)&&t.isMergeableObject(r[n])?o[n]=I(n,t)(e[n],r[n],t):o[n]=i(r[n],t))}),o}function a(e,r,t){t=t||{},t.arrayMerge=t.arrayMerge||P,t.isMergeableObject=t.isMergeableObject||S,t.cloneUnlessOtherwiseSpecified=i;var o=Array.isArray(r),n=Array.isArray(e),c=o===n;return c?o?t.arrayMerge(e,r,t):x(e,r,t):i(r,t)}a.all=function(r,t){if(!Array.isArray(r))throw new Error("first argument should be an array");return r.reduce(function(o,n){return a(o,n,t)},{})};var D=a,B=D;const L=O(B),_={title:"Checkout",LoginForm:{title:"Contact details",account:"Already have an account?",ariaLabel:"Email",invalidEmailError:"Please enter a valid email address.",missingEmailError:"Enter an email address.",emailExists:{alreadyHaveAccount:"It looks like you already have an account.",signInButton:"Sign in",forFasterCheckout:"for a faster checkout."},floatingLabel:"Email *",placeholder:"Enter your email address",signIn:"Sign In",switch:"Do you want to switch account?",signOut:"Sign Out"},ShippingMethods:{title:"Shipping options",emptyState:"This order can't be shipped to the address provided. Please review the address details you entered and make sure they're correct."},BillToShippingAddress:{title:"Bill to shipping address"},PaymentMethods:{title:"Payment",emptyState:"No payment methods available"},OutOfStock:{title:"Your cart contains items that are out of stock",message:"The following items are out of stock:",actions:{reviewCart:"Review cart",removeOutOfStock:"Remove out of stock items"},lowInventory:{one:"Last item!",many:"Only {{count}} left!"},alert:"Out of stock!"},PlaceOrder:{button:"Place Order"},ServerError:{title:"We were unable to process your order",contactSupport:"If you continue to have issues, please contact support.",unexpected:"An unexpected error occurred while processing your order. Please try again later.",button:"Try again"},EmptyCart:{title:"Your cart is empty",button:"Start shopping"},ErrorBanner:{genericMessage:"Server error detected. Please check your connection and try again."},MergedCartBanner:{items:{one:"1 item from a previous session was added to your cart. Please review your new subtotal.",many:"{{count}} items from a previous session were added to your cart. Please review your new subtotal."}},EstimateShipping:{estimated:"Estimated Shipping",freeShipping:"Free",label:"Shipping",taxToBeDetermined:"TBD",withTaxes:"Including taxes",withoutTaxes:"Excluding taxes"}},R={Checkout:_},U={default:R},k=({children:e})=>{var c;const[r,t]=b(),o=(c=g.getConfig())==null?void 0:c.langDefinitions;h(()=>{const s=p.on("locale",u=>{u!==r&&t(u)},{eager:!0});return()=>{s==null||s.off()}},[r]);const n=L(U,o??{});return f(y,{lang:r,langDefinitions:n,children:e})},X=new d(f(k,{}));export{k as Provider,X as render}; diff --git a/scripts/__dropins__/storefront-checkout/signals/StoreConfigSignal.d.ts b/scripts/__dropins__/storefront-checkout/signals/StoreConfigSignal.d.ts deleted file mode 100644 index e931687684..0000000000 --- a/scripts/__dropins__/storefront-checkout/signals/StoreConfigSignal.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { StoreConfig } from '../data/models'; - -export declare const storeConfigSignal: import('@preact/signals-core').Signal<{ - data?: StoreConfig | undefined; - pending: boolean; -}>; -//# sourceMappingURL=StoreConfigSignal.d.ts.map \ No newline at end of file diff --git a/scripts/__dropins__/storefront-checkout/signals/index.d.ts b/scripts/__dropins__/storefront-checkout/signals/index.d.ts index 13ba0ea9ee..60215f145e 100644 --- a/scripts/__dropins__/storefront-checkout/signals/index.d.ts +++ b/scripts/__dropins__/storefront-checkout/signals/index.d.ts @@ -21,5 +21,4 @@ export * from './IsBillToShippingSignal'; export * from './SelectedPaymentMethodSignal'; export * from './SelectedShippingMethodSignal'; export * from './ServerErrorSignal'; -export * from './StoreConfigSignal'; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/scripts/checkout.js b/scripts/checkout.js index 5e84b8b514..dd5a8eb9f0 100644 --- a/scripts/checkout.js +++ b/scripts/checkout.js @@ -7,6 +7,14 @@ export function scrollToElement(element) { element.focus(); } +export function isCartEmpty(cart) { + return cart ? cart.totalQuantity < 1 : true; +} + +export function isCheckoutEmpty(data) { + return data ? data.isEmpty : true; +} + export function getCartAddress(checkoutData, type) { if (!checkoutData) return null;