@zonos/elements 1.5.1 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_isBigCommerceNativeCheckout-3-xbKbAO.js +133 -0
- package/dist/cjs/{cart-CiXlehwQ.js → cart-C39TMSgB.js} +27 -13
- package/dist/cjs/{collect-Drr8fY-q.js → collect-lF9DenLk.js} +4 -4
- package/dist/cjs/{getMissingRequiredShippingFields-DI6qF1z3.js → getMissingRequiredShippingFields-svcnpumn.js} +1 -1
- package/dist/cjs/{handleFetch-DQLhurnE.js → handleFetch-DVfjFTYO.js} +181 -71
- package/dist/cjs/{hasInclusivePrice-84KS94yH.js → hasInclusivePrice-CEPf3_FG.js} +1 -1
- package/dist/cjs/index.cjs.js +158 -47
- package/dist/cjs/{invoice-5hVfSXpb.js → invoice-BD3pCr8P.js} +3 -3
- package/dist/cjs/{localization-B2mjW0Xa.js → localization-BhNVhLZs.js} +24 -48
- package/dist/cjs/{paypal-pd8Nz_R_.js → paypal-Bd1qmwiv.js} +4 -4
- package/dist/cjs/{placeTestOrder-DrI8rD9o.js → placeTestOrder-BMQRvX2q.js} +3 -3
- package/dist/cjs/{renderCheckoutCurrency-u5q8YdUb.js → renderCheckoutCurrency-DE2p8CT8.js} +2 -2
- package/dist/cjs/{shouldShowLanguageSelect-gBg4KeTQ.js → shouldShowLanguageSelect-NOVWOU53.js} +1 -1
- package/dist/cjs/{submitGtag-Rc-S3PnH.js → submitGtag-D4sB7w4z.js} +1 -1
- package/dist/cjs/{taxIdFields-BrIaPTcd.js → taxIdFields-BKbk2bhi.js} +2 -2
- package/dist/cjs/{updateCheckoutSessionAttributes-d0IKpwW8.js → updateCheckoutSessionAttributes-KxwcsKhM.js} +1 -1
- package/dist/cjs/zonos-address-completion-dialog_7.cjs.entry.js +6 -6
- package/dist/cjs/zonos-address-display_2.cjs.entry.js +2 -2
- package/dist/cjs/zonos-address_4.cjs.entry.js +4 -4
- package/dist/cjs/zonos-airwallex-payment.cjs.entry.js +4 -4
- package/dist/cjs/zonos-card_5.cjs.entry.js +5 -5
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +18 -18
- package/dist/cjs/zonos-checkout.cjs.entry.js +48 -22
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +3 -3
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +9 -9
- package/dist/cjs/zonos-collect.cjs.entry.js +6 -6
- package/dist/cjs/zonos-controller.cjs.entry.js +65 -40
- package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +3 -3
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +3 -3
- package/dist/cjs/zonos-hello.cjs.entry.js +2 -2
- package/dist/cjs/zonos-invoice-cart-items_2.cjs.entry.js +5 -5
- package/dist/cjs/zonos-invoice-finish_5.cjs.entry.js +9 -9
- package/dist/cjs/zonos-invoice.cjs.entry.js +6 -6
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
- package/dist/cjs/zonos-policy-consent_2.cjs.entry.js +4 -4
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +8 -7
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +14 -4
- package/dist/collection/components/main/mountCheckoutWithoutStripe.js +12 -0
- package/dist/collection/components/main/zonos-controller.js +26 -10
- package/dist/collection/components/store/checkout/cart.js +3 -2
- package/dist/collection/components/store/checkout/stripe.js +23 -10
- package/dist/collection/components/store/storageStore.js +7 -6
- package/dist/collection/components/utils/__tests__/helpers/blockStorage.js +24 -0
- package/dist/collection/components/utils/api/getExchangeRate.js +2 -1
- package/dist/collection/components/utils/checkout/isBigCommerceCheckoutBypassEnabled.js +2 -1
- package/dist/collection/components/utils/checkout/watchImmediateBigcommerceDomesticCheckoutRedirect.js +32 -12
- package/dist/collection/components/utils/handleFetch.js +19 -9
- package/dist/collection/components/utils/hello/countryOverrideStorage.js +17 -40
- package/dist/collection/components/utils/logging/installConstructorCapture.js +58 -0
- package/dist/collection/components/utils/logging/reportBlockedStorage.js +34 -0
- package/dist/collection/components/utils/logging/sendErrorLog.js +8 -1
- package/dist/collection/components/utils/logging/startZonosInit.js +35 -0
- package/dist/collection/components/utils/logging/thrownMessage.js +16 -0
- package/dist/collection/components/utils/safeStorage.js +39 -0
- package/dist/collection/scripts/_bigcommerceCheckoutPath.js +16 -0
- package/dist/collection/scripts/_detectBigCommerceHost.js +12 -0
- package/dist/collection/scripts/_getZonosQaUrl.js +3 -2
- package/dist/collection/scripts/_isBigCommerceNativeCheckout.js +107 -0
- package/dist/collection/scripts/_loadStripe.js +15 -4
- package/dist/collection/scripts/_zonosBase.js +46 -33
- package/dist/collection/types/generated/graphql.frontend.types.js +0 -16
- package/dist/collection/types/generated/graphql.internal.types.js +215 -1
- package/dist/esm/_isBigCommerceNativeCheckout-Bb90IMVt.js +128 -0
- package/dist/esm/{cart-DmJkjiDE.js → cart-b84n0nhi.js} +26 -14
- package/dist/esm/{collect-BV5GTPmh.js → collect-B_AEVONL.js} +4 -4
- package/dist/esm/{getMissingRequiredShippingFields-DljgpDZe.js → getMissingRequiredShippingFields-EY10c34-.js} +1 -1
- package/dist/esm/{handleFetch-D5GYDF-O.js → handleFetch-BFVO7oAR.js} +178 -72
- package/dist/esm/{hasInclusivePrice-DhGXpH2D.js → hasInclusivePrice-DfEiyzw7.js} +1 -1
- package/dist/esm/index.js +158 -47
- package/dist/esm/{invoice-CO-iqlni.js → invoice-dQ0ONK5Q.js} +3 -3
- package/dist/esm/{localization-DHM91diu.js → localization-B5CRzthT.js} +25 -49
- package/dist/esm/{paypal-BfW5aLJw.js → paypal-CF_oM0B6.js} +4 -4
- package/dist/esm/{placeTestOrder-CyWUFhxD.js → placeTestOrder-BTpfyqPL.js} +3 -3
- package/dist/esm/{renderCheckoutCurrency-B31ZNkUv.js → renderCheckoutCurrency-CpeuDWx-.js} +2 -2
- package/dist/esm/{shouldShowLanguageSelect-DwSfSHar.js → shouldShowLanguageSelect-CJinx9-m.js} +1 -1
- package/dist/esm/{submitGtag-BEFrutel.js → submitGtag-C5xzFHjG.js} +1 -1
- package/dist/esm/{taxIdFields-ByEYfsO5.js → taxIdFields-BCyXnc9O.js} +2 -2
- package/dist/esm/{updateCheckoutSessionAttributes-B0bQH0uw.js → updateCheckoutSessionAttributes-C9bMKTjz.js} +1 -1
- package/dist/esm/zonos-address-completion-dialog_7.entry.js +6 -6
- package/dist/esm/zonos-address-display_2.entry.js +2 -2
- package/dist/esm/zonos-address_4.entry.js +4 -4
- package/dist/esm/zonos-airwallex-payment.entry.js +4 -4
- package/dist/esm/zonos-card_5.entry.js +5 -5
- package/dist/esm/zonos-cart-items_12.entry.js +18 -18
- package/dist/esm/zonos-checkout.entry.js +48 -22
- package/dist/esm/zonos-collect-cart-items_3.entry.js +3 -3
- package/dist/esm/zonos-collect-finish_6.entry.js +9 -9
- package/dist/esm/zonos-collect.entry.js +6 -6
- package/dist/esm/zonos-controller.entry.js +65 -40
- package/dist/esm/zonos-country-flag.entry.js +2 -2
- package/dist/esm/zonos-country-select_4.entry.js +3 -3
- package/dist/esm/zonos-hello-dialog.entry.js +3 -3
- package/dist/esm/zonos-hello.entry.js +2 -2
- package/dist/esm/zonos-invoice-cart-items_2.entry.js +5 -5
- package/dist/esm/zonos-invoice-finish_5.entry.js +9 -9
- package/dist/esm/zonos-invoice.entry.js +6 -6
- package/dist/esm/zonos-language-select_2.entry.js +2 -2
- package/dist/esm/zonos-policy-consent_2.entry.js +4 -4
- package/dist/esm-es5/_isBigCommerceNativeCheckout-Bb90IMVt.js +40 -0
- package/dist/esm-es5/{cart-DmJkjiDE.js → cart-b84n0nhi.js} +59 -59
- package/dist/esm-es5/{collect-BV5GTPmh.js → collect-B_AEVONL.js} +2 -2
- package/dist/esm-es5/{getMissingRequiredShippingFields-DljgpDZe.js → getMissingRequiredShippingFields-EY10c34-.js} +3 -3
- package/dist/esm-es5/handleFetch-BFVO7oAR.js +73 -0
- package/dist/esm-es5/{hasInclusivePrice-DhGXpH2D.js → hasInclusivePrice-DfEiyzw7.js} +1 -1
- package/dist/esm-es5/index.js +94 -65
- package/dist/esm-es5/{invoice-CO-iqlni.js → invoice-dQ0ONK5Q.js} +1 -1
- package/dist/esm-es5/{localization-DHM91diu.js → localization-B5CRzthT.js} +7 -10
- package/dist/esm-es5/{paypal-BfW5aLJw.js → paypal-CF_oM0B6.js} +1 -1
- package/dist/esm-es5/{placeTestOrder-CyWUFhxD.js → placeTestOrder-BTpfyqPL.js} +1 -1
- package/dist/esm-es5/{renderCheckoutCurrency-B31ZNkUv.js → renderCheckoutCurrency-CpeuDWx-.js} +5 -5
- package/dist/esm-es5/{shouldShowLanguageSelect-DwSfSHar.js → shouldShowLanguageSelect-CJinx9-m.js} +1 -1
- package/dist/esm-es5/{submitGtag-BEFrutel.js → submitGtag-C5xzFHjG.js} +1 -1
- package/dist/esm-es5/{taxIdFields-ByEYfsO5.js → taxIdFields-BCyXnc9O.js} +1 -1
- package/dist/esm-es5/{updateCheckoutSessionAttributes-B0bQH0uw.js → updateCheckoutSessionAttributes-C9bMKTjz.js} +1 -1
- package/dist/esm-es5/zonos-address-completion-dialog_7.entry.js +2 -2
- package/dist/esm-es5/zonos-address-display_2.entry.js +1 -1
- package/dist/esm-es5/zonos-address_4.entry.js +1 -1
- package/dist/esm-es5/zonos-airwallex-payment.entry.js +1 -1
- package/dist/esm-es5/zonos-card_5.entry.js +6 -6
- package/dist/esm-es5/zonos-cart-items_12.entry.js +127 -127
- package/dist/esm-es5/zonos-checkout.entry.js +22 -11
- package/dist/esm-es5/zonos-collect-cart-items_3.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -1
- package/dist/esm-es5/zonos-collect.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +21 -12
- package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-cart-items_2.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-finish_5.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice.entry.js +3 -3
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-policy-consent_2.entry.js +1 -1
- package/dist/scripts/index.d.ts +22 -0
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/components/main/mountCheckoutWithoutStripe.d.ts +8 -0
- package/dist/types/components/store/checkout/stripe.d.ts +4 -1
- package/dist/types/components/utils/__tests__/helpers/blockStorage.d.ts +3 -0
- package/dist/types/components/utils/logging/installConstructorCapture.d.ts +20 -0
- package/dist/types/components/utils/logging/reportBlockedStorage.d.ts +16 -0
- package/dist/types/components/utils/logging/startZonosInit.d.ts +5 -0
- package/dist/types/components/utils/logging/thrownMessage.d.ts +1 -0
- package/dist/types/components/utils/safeStorage.d.ts +4 -0
- package/dist/types/scripts/_bigcommerceCheckoutPath.d.ts +12 -0
- package/dist/types/scripts/_detectBigCommerceHost.d.ts +5 -0
- package/dist/types/scripts/_isBigCommerceNativeCheckout.d.ts +21 -0
- package/dist/types/scripts/_zonosBase.d.ts +16 -0
- package/dist/types/scripts/cart/_setupCartDataWithSettings.d.ts +5 -0
- package/dist/types/types/generated/graphql.frontend.types.d.ts +0 -22
- package/dist/types/types/generated/graphql.frontend.types.ts +0 -51
- package/dist/types/types/generated/graphql.internal.types.d.ts +270 -1
- package/dist/types/types/generated/graphql.internal.types.ts +341 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-8fa6cfff.entry.js → p-02faff47.entry.js} +1 -1
- package/dist/zonos-elements/{p-216a908d.system.entry.js → p-0c68cbbb.system.entry.js} +2 -2
- package/dist/zonos-elements/{p-vTIygnHq.system.js → p-1OG3IJgY.system.js} +1 -1
- package/dist/zonos-elements/{p-960070d0.system.entry.js → p-1cd2d097.system.entry.js} +3 -3
- package/dist/zonos-elements/{p-1e6db427.entry.js → p-255e411a.entry.js} +1 -1
- package/dist/zonos-elements/p-2c_UqKJL.system.js +7 -0
- package/dist/zonos-elements/{p-DprOoI2W.system.js → p-3AUMK-5E.system.js} +154 -154
- package/dist/zonos-elements/{p-d3345b2c.entry.js → p-3ee87d8b.entry.js} +1 -1
- package/dist/zonos-elements/{p-cccaad60.system.entry.js → p-42fa5694.system.entry.js} +10 -10
- package/dist/zonos-elements/p-49eaaab8.entry.js +1 -0
- package/dist/zonos-elements/{p-fda89981.system.entry.js → p-4ce4c49f.system.entry.js} +3 -3
- package/dist/zonos-elements/{p-f3d9a380.system.entry.js → p-5622fc50.system.entry.js} +263 -252
- package/dist/zonos-elements/{p-5585db86.system.entry.js → p-59457fd9.system.entry.js} +73 -64
- package/dist/zonos-elements/{p-65817880.entry.js → p-66398133.entry.js} +1 -1
- package/dist/zonos-elements/{p-d8f375da.system.entry.js → p-674323ac.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-678b9214.entry.js → p-71d9a5b7.entry.js} +1 -1
- package/dist/zonos-elements/{p-189cc594.system.entry.js → p-81780f8f.system.entry.js} +2 -2
- package/dist/zonos-elements/{p-6e691736.entry.js → p-821b83a2.entry.js} +1 -1
- package/dist/zonos-elements/{p-1fda4aec.system.entry.js → p-877a82d2.system.entry.js} +94 -94
- package/dist/zonos-elements/p-8daec112.entry.js +1 -0
- package/dist/zonos-elements/{p-46a839d2.system.entry.js → p-93bc75fd.system.entry.js} +13 -13
- package/dist/zonos-elements/{p-2ca826b9.system.entry.js → p-976b3bf3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-84e76348.entry.js → p-9a4947a5.entry.js} +1 -1
- package/dist/zonos-elements/p-9f7693bf.entry.js +1 -0
- package/dist/zonos-elements/p-BIJM2Kj-.js +1 -0
- package/dist/zonos-elements/p-BJFa5RwX.js +1 -0
- package/dist/zonos-elements/{p-6vSUiBfr.system.js → p-BOh4ifdL.system.js} +51 -54
- package/dist/zonos-elements/p-BZAX-HmS.js +1 -0
- package/dist/zonos-elements/p-Bb90IMVt.js +1 -0
- package/dist/zonos-elements/p-Bu9WCfUC.system.js +1 -1
- package/dist/zonos-elements/{p-CbhN65lj.system.js → p-BvoPE_nb.system.js} +1 -1
- package/dist/zonos-elements/{p-iAIzUA4k.js → p-C3E55OqH.js} +1 -1
- package/dist/zonos-elements/{p-CBUz18kA.system.js → p-C3gF3UV5.system.js} +23 -23
- package/dist/zonos-elements/{p-XoQH3S7Z.system.js → p-CD2ahEZn.system.js} +1 -1
- package/dist/zonos-elements/p-CEBBLbvF.js +1 -0
- package/dist/zonos-elements/{p-CGNVm52g.system.js → p-CEV0O_IQ.system.js} +5 -5
- package/dist/zonos-elements/{p-D1e9zNDA.js → p-CJmWr75U.js} +1 -1
- package/dist/zonos-elements/{p-DgUrB-1a.system.js → p-CZ-uYiCo.system.js} +1 -1
- package/dist/zonos-elements/p-Cn2xE-9t.system.js +256 -0
- package/dist/zonos-elements/p-CtvXi9wL.system.js +41 -0
- package/dist/zonos-elements/{p-BrQ8n8NS.system.js → p-Cw_Qnyow.system.js} +3 -3
- package/dist/zonos-elements/p-CzXNXgyI.js +1 -0
- package/dist/zonos-elements/p-D0DkOoAw.system.js +73 -0
- package/dist/zonos-elements/p-D9OPKqLg.js +1 -0
- package/dist/zonos-elements/{p-ojtNq-r5.system.js → p-DXlojp_Y.system.js} +1 -1
- package/dist/zonos-elements/{p-DpwmHU8R.js → p-Df62LRNs.js} +2 -2
- package/dist/zonos-elements/{p-CHKKvuiz.js → p-Lsqrpzc5.js} +1 -1
- package/dist/zonos-elements/{p-C9XLkmmb.system.js → p-YQFbWtjn.system.js} +1 -1
- package/dist/zonos-elements/p-a27f48e4.entry.js +1 -0
- package/dist/zonos-elements/{p-941a95a1.system.entry.js → p-a6bb296c.system.entry.js} +7 -7
- package/dist/zonos-elements/{p-2b63865a.system.entry.js → p-abb85879.system.entry.js} +3 -3
- package/dist/zonos-elements/{p-12b24ebb.entry.js → p-b8653024.entry.js} +1 -1
- package/dist/zonos-elements/p-b9d7a3b6.entry.js +1 -0
- package/dist/zonos-elements/{p-f5f95990.system.entry.js → p-be067e12.system.entry.js} +15 -15
- package/dist/zonos-elements/p-bmrOH9oh.js +1 -0
- package/dist/zonos-elements/p-c185bc23.entry.js +1 -0
- package/dist/zonos-elements/{p-2d513aa3.entry.js → p-c6e78de2.entry.js} +1 -1
- package/dist/zonos-elements/{p-55813e9f.system.entry.js → p-ca97a1cd.system.entry.js} +3 -3
- package/dist/zonos-elements/{p-3e705c9b.entry.js → p-cbb96382.entry.js} +1 -1
- package/dist/zonos-elements/{p-53eac12f.system.entry.js → p-dbf4d156.system.entry.js} +14 -14
- package/dist/zonos-elements/{p-6410fa11.system.entry.js → p-df240119.system.entry.js} +16 -16
- package/dist/zonos-elements/{p-1cc42a98.system.entry.js → p-e16e4db6.system.entry.js} +17 -17
- package/dist/zonos-elements/{p-064d8829.system.entry.js → p-eb016dd8.system.entry.js} +20 -20
- package/dist/zonos-elements/{p-1199baef.system.entry.js → p-eb5c67a0.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-ef5344ea.entry.js → p-ed8a7a7f.entry.js} +1 -1
- package/dist/zonos-elements/{p-4917b74d.entry.js → p-ef932fda.entry.js} +1 -1
- package/dist/zonos-elements/{p-e7fdb2c9.entry.js → p-f792ba5f.entry.js} +1 -1
- package/dist/zonos-elements/{p-DiMEP3mh.js → p-fZcKMzE-.js} +1 -1
- package/dist/zonos-elements/{p-CMo3ZweU.js → p-fdritVtG.js} +1 -1
- package/dist/zonos-elements/p-fffe6376.entry.js +1 -0
- package/dist/zonos-elements/p-gEViRqvf.js +1 -0
- package/dist/zonos-elements/{p-Dtu_Japy.system.js → p-v8IEjQ2z.system.js} +39 -39
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +10 -10
- package/dist/esm-es5/handleFetch-D5GYDF-O.js +0 -60
- package/dist/zonos-elements/p-107f287b.entry.js +0 -1
- package/dist/zonos-elements/p-25eb99d4.entry.js +0 -1
- package/dist/zonos-elements/p-46b9f0cf.entry.js +0 -1
- package/dist/zonos-elements/p-636b71d4.entry.js +0 -1
- package/dist/zonos-elements/p-7dc7f328.entry.js +0 -1
- package/dist/zonos-elements/p-8f9d8795.entry.js +0 -1
- package/dist/zonos-elements/p-BMPYH-LT.js +0 -1
- package/dist/zonos-elements/p-C70h5mKA.js +0 -1
- package/dist/zonos-elements/p-CTiqplrr.js +0 -1
- package/dist/zonos-elements/p-Ch1w0Lr7.js +0 -1
- package/dist/zonos-elements/p-D1SmY_fZ.js +0 -1
- package/dist/zonos-elements/p-D6xXnsM_.js +0 -1
- package/dist/zonos-elements/p-DE4a-QD5.js +0 -1
- package/dist/zonos-elements/p-DQrMfUzi.system.js +0 -227
- package/dist/zonos-elements/p-DZdkJHK9.system.js +0 -7
- package/dist/zonos-elements/p-U33isUJG.js +0 -1
- package/dist/zonos-elements/p-ebe157b5.entry.js +0 -1
- package/dist/zonos-elements/p-zVLAvre1.system.js +0 -60
|
@@ -17,6 +17,7 @@ import { jsonParse } from "./jsonParse";
|
|
|
17
17
|
import { log } from "./logging/log";
|
|
18
18
|
import { prepLoadTimeApiLog } from "./logging/prepLoadTimeApiLog";
|
|
19
19
|
import { sendErrorLog } from "./logging/sendErrorLog";
|
|
20
|
+
const isGatewayStatus = (status) => status === 502 || status === 503 || status === 504;
|
|
20
21
|
const getResponseBody = async ({ response, shouldLog = true, shouldThrow = false, }) => {
|
|
21
22
|
try {
|
|
22
23
|
const text = await response.text();
|
|
@@ -137,28 +138,31 @@ const handleRequest = async ({ basePathType, options, path, }) => {
|
|
|
137
138
|
}
|
|
138
139
|
catch (_a) {
|
|
139
140
|
const message = 'Unknown error';
|
|
141
|
+
// A gateway HTML or empty body still carries a status a GET can fail over
|
|
142
|
+
// on. Other non-JSON statuses, including 404 and 500, keep the previous
|
|
143
|
+
// null response so they do not fail over.
|
|
140
144
|
return {
|
|
141
145
|
baseUrl,
|
|
142
146
|
errors: [{ message: `${status}: ${message}`, type: status }],
|
|
143
147
|
json: null,
|
|
144
|
-
response: null,
|
|
148
|
+
response: isGatewayStatus(response.status) ? response : null,
|
|
145
149
|
zonosMode,
|
|
146
150
|
};
|
|
147
151
|
}
|
|
148
152
|
};
|
|
149
153
|
const handleRequestWithFallback = async ({ basePathType: _basePathType, options, path, }) => {
|
|
150
|
-
var _a, _b;
|
|
154
|
+
var _a, _b, _c;
|
|
151
155
|
// use vercel API if the path is `/api/bigcommerce`
|
|
152
156
|
const isBigcommerceEndpoint = path.startsWith('/api/bigcommerce');
|
|
153
157
|
const basePathType = isBigcommerceEndpoint
|
|
154
158
|
? 'vercel'
|
|
155
159
|
: _basePathType;
|
|
156
160
|
const startTime = performance.now();
|
|
157
|
-
const
|
|
161
|
+
const _d = await handleRequest({
|
|
158
162
|
basePathType,
|
|
159
163
|
options,
|
|
160
164
|
path,
|
|
161
|
-
}), { errors, response } =
|
|
165
|
+
}), { errors, response } = _d, rest = __rest(_d, ["errors", "response"]);
|
|
162
166
|
const endTime = performance.now();
|
|
163
167
|
const duration = endTime - startTime;
|
|
164
168
|
// Send the load time api log
|
|
@@ -180,10 +184,16 @@ const handleRequestWithFallback = async ({ basePathType: _basePathType, options,
|
|
|
180
184
|
(message.includes('signal is aborted') ||
|
|
181
185
|
message.includes('The operation was aborted') ||
|
|
182
186
|
message.includes('Fetch is aborted')));
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
+
const statusCode = response === null || response === void 0 ? void 0 : response.status;
|
|
188
|
+
const gateway = statusCode !== undefined && isGatewayStatus(statusCode);
|
|
189
|
+
// handleFetch sets method, and a missing method is a GET.
|
|
190
|
+
const isIdempotentGet = ((_a = options === null || options === void 0 ? void 0 : options.method) !== null && _a !== void 0 ? _a : 'GET').toUpperCase() === 'GET';
|
|
191
|
+
const failedWithoutGateway = !!unknownError || statusCode === 404 || statusCode === 500;
|
|
192
|
+
const isUnknownError = failedWithoutGateway || gateway;
|
|
193
|
+
// Replay 502, 503, and 504 only for GET. A gateway timeout on a POST can
|
|
194
|
+
// mean the first host is still finishing a payment or order write.
|
|
195
|
+
const shouldCallFallback = nextFallbackApiType &&
|
|
196
|
+
(failedWithoutGateway || (gateway && isIdempotentGet));
|
|
187
197
|
// Should log the error if it's unknown error
|
|
188
198
|
if (isUnknownError && !isAbortError) {
|
|
189
199
|
void sendErrorLog({
|
|
@@ -193,7 +203,7 @@ const handleRequestWithFallback = async ({ basePathType: _basePathType, options,
|
|
|
193
203
|
currentBasePath: basePathType,
|
|
194
204
|
nextFallbackApiType,
|
|
195
205
|
requestHeaders: options === null || options === void 0 ? void 0 : options.headers,
|
|
196
|
-
requestPayload: jsonParse((
|
|
206
|
+
requestPayload: jsonParse((_b = options === null || options === void 0 ? void 0 : options.body) === null || _b === void 0 ? void 0 : _b.toString()) || ((_c = options === null || options === void 0 ? void 0 : options.body) === null || _c === void 0 ? void 0 : _c.toString()),
|
|
197
207
|
shouldCallFallback,
|
|
198
208
|
status: response === null || response === void 0 ? void 0 : response.status,
|
|
199
209
|
statusText: response === null || response === void 0 ? void 0 : response.statusText,
|
|
@@ -1,55 +1,32 @@
|
|
|
1
1
|
import { isCountryCode } from "./isCountryCode";
|
|
2
|
+
import { safeGetItem, safeRemoveItem, safeSetItem, } from "../safeStorage";
|
|
2
3
|
const COUNTRY_OVERRIDE_KEY = 'zonos--country';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
catch (_a) {
|
|
8
|
-
// localStorage/sessionStorage can throw in blocked-storage contexts
|
|
9
|
-
// (Safari private mode, cross-origin iframes).
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const readStoredCountry = (storage) => {
|
|
13
|
-
try {
|
|
14
|
-
const value = storage.getItem(COUNTRY_OVERRIDE_KEY);
|
|
15
|
-
if (!value || !isCountryCode(value)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
catch (_a) {
|
|
4
|
+
const readStoredCountry = (area) => {
|
|
5
|
+
const value = safeGetItem(area, COUNTRY_OVERRIDE_KEY);
|
|
6
|
+
if (!value || !isCountryCode(value)) {
|
|
21
7
|
return null;
|
|
22
8
|
}
|
|
9
|
+
return value;
|
|
23
10
|
};
|
|
24
|
-
const
|
|
25
|
-
storage.setItem(COUNTRY_OVERRIDE_KEY, countryCode);
|
|
26
|
-
};
|
|
27
|
-
const withEachStorage = (run) => {
|
|
28
|
-
withBlockedStorage(() => run(window.localStorage));
|
|
29
|
-
withBlockedStorage(() => run(window.sessionStorage));
|
|
30
|
-
};
|
|
31
|
-
export const getCountryOverrideStorage = () => {
|
|
32
|
-
var _a;
|
|
33
|
-
return (_a = readStoredCountry(window.localStorage)) !== null && _a !== void 0 ? _a : readStoredCountry(window.sessionStorage);
|
|
34
|
-
};
|
|
11
|
+
export const getCountryOverrideStorage = () => { var _a; return (_a = readStoredCountry('local')) !== null && _a !== void 0 ? _a : readStoredCountry('session'); };
|
|
35
12
|
export const migrateCountryOverrideStorage = (selectedCountryCode) => {
|
|
36
13
|
if (!selectedCountryCode) {
|
|
37
14
|
return;
|
|
38
15
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
});
|
|
16
|
+
const localCountry = readStoredCountry('local');
|
|
17
|
+
// Only mirror the country Hello actually kept. A failed localStorage
|
|
18
|
+
// clear can leave a discarded country in local; never copy that to
|
|
19
|
+
// session for older Elements. Never copy session → local.
|
|
20
|
+
if (localCountry === selectedCountryCode) {
|
|
21
|
+
safeSetItem('session', COUNTRY_OVERRIDE_KEY, localCountry);
|
|
22
|
+
}
|
|
48
23
|
};
|
|
49
24
|
export const setCountryOverrideStorage = (countryCode) => {
|
|
50
25
|
// Dual-write so older Elements that only read sessionStorage see the pick.
|
|
51
|
-
|
|
26
|
+
safeSetItem('local', COUNTRY_OVERRIDE_KEY, countryCode);
|
|
27
|
+
safeSetItem('session', COUNTRY_OVERRIDE_KEY, countryCode);
|
|
52
28
|
};
|
|
53
29
|
export const clearCountryOverrideStorage = () => {
|
|
54
|
-
|
|
30
|
+
safeRemoveItem('local', COUNTRY_OVERRIDE_KEY);
|
|
31
|
+
safeRemoveItem('session', COUNTRY_OVERRIDE_KEY);
|
|
55
32
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { sendErrorLog } from "./sendErrorLog";
|
|
2
|
+
import { thrownMessage } from "./thrownMessage";
|
|
3
|
+
const constructorNotFound = /^Constructor for .+ was not found/;
|
|
4
|
+
const constructorTag = /^Constructor for "?([^#"]+)#/;
|
|
5
|
+
const recordConstructorFailure = (value) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const message = thrownMessage(value, '');
|
|
8
|
+
if (!message || !constructorNotFound.test(message)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (typeof window.Zonos === 'undefined') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const capture = window.__zonosConstructorCapture;
|
|
15
|
+
if (!capture) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const tagMatch = constructorTag.exec(message);
|
|
19
|
+
const tag = (_a = tagMatch === null || tagMatch === void 0 ? void 0 : tagMatch[1]) !== null && _a !== void 0 ? _a : '';
|
|
20
|
+
if (capture.reported.has(tag)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
capture.reported.add(tag);
|
|
24
|
+
void sendErrorLog({
|
|
25
|
+
endpoint: 'stencil://constructor',
|
|
26
|
+
errors: [message],
|
|
27
|
+
metadata: {
|
|
28
|
+
shape: 'constructor-not-found',
|
|
29
|
+
tag,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Copy a missing-constructor failure onto the existing error log.
|
|
35
|
+
* Stencil catches `Constructor for "tag#mode" was not found` and passes that
|
|
36
|
+
* Error to `console.error`. One report is sent per tag, then the original
|
|
37
|
+
* console.error still runs. This does not request the chunk again.
|
|
38
|
+
*/
|
|
39
|
+
export const installConstructorCapture = () => {
|
|
40
|
+
if (window.__zonosConstructorCapture) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const listener = (event) => {
|
|
44
|
+
recordConstructorFailure(event.reason);
|
|
45
|
+
};
|
|
46
|
+
window.__zonosConstructorCapture = {
|
|
47
|
+
listener,
|
|
48
|
+
reported: new Set(),
|
|
49
|
+
};
|
|
50
|
+
window.addEventListener('unhandledrejection', listener);
|
|
51
|
+
// eslint-disable-next-line no-console -- Stencil reports the missing constructor here
|
|
52
|
+
const originalError = console.error.bind(console);
|
|
53
|
+
// eslint-disable-next-line no-console -- record the Stencil diagnostic, then forward it
|
|
54
|
+
console.error = (...data) => {
|
|
55
|
+
recordConstructorFailure(data[0]);
|
|
56
|
+
originalError(...data);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { sendErrorLog } from "./sendErrorLog";
|
|
2
|
+
import { thrownMessage } from "./thrownMessage";
|
|
3
|
+
const reportedIds = () => {
|
|
4
|
+
if (!window.__zonosReportedBlockedStorage) {
|
|
5
|
+
window.__zonosReportedBlockedStorage = new Set();
|
|
6
|
+
}
|
|
7
|
+
return window.__zonosReportedBlockedStorage;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Record a blocked storage read or write on the existing error log.
|
|
11
|
+
* A throw before `window.Zonos` exists is swallowed and does not use up
|
|
12
|
+
* the per-page dedupe slot, so the later startup read can still report it.
|
|
13
|
+
*/
|
|
14
|
+
export const reportBlockedStorage = (area, operation, key, error) => {
|
|
15
|
+
if (typeof window.Zonos === 'undefined') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const dedupeId = `${area}\u0000${operation}\u0000${key}`;
|
|
19
|
+
const reported = reportedIds();
|
|
20
|
+
if (reported.has(dedupeId)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
reported.add(dedupeId);
|
|
24
|
+
void sendErrorLog({
|
|
25
|
+
endpoint: `storage://${area}/${key}`,
|
|
26
|
+
errors: [thrownMessage(error, 'SecurityError')],
|
|
27
|
+
metadata: {
|
|
28
|
+
area,
|
|
29
|
+
key,
|
|
30
|
+
operation,
|
|
31
|
+
shape: 'blocked-storage',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
@@ -5,6 +5,13 @@ import { log } from "./log";
|
|
|
5
5
|
* @default 1 hour
|
|
6
6
|
*/
|
|
7
7
|
const postReleaseReportingDuration = 1 * 3600 * 1000; // 1 hour
|
|
8
|
+
const loggedHref = () => {
|
|
9
|
+
const url = new URL(window.location.href);
|
|
10
|
+
url.searchParams.delete('payment_intent');
|
|
11
|
+
url.searchParams.delete('payment_intent_client_secret');
|
|
12
|
+
url.searchParams.delete('redirect_status');
|
|
13
|
+
return url.toString();
|
|
14
|
+
};
|
|
8
15
|
export const sendErrorLog = async ({ endpoint, errors, metadata, shouldPostReleaseErrorReporting, }) => {
|
|
9
16
|
log('sendErrorLog', 'warn', endpoint, metadata, errors);
|
|
10
17
|
if (shouldPostReleaseErrorReporting) {
|
|
@@ -22,7 +29,7 @@ export const sendErrorLog = async ({ endpoint, errors, metadata, shouldPostRelea
|
|
|
22
29
|
const errorObject = {
|
|
23
30
|
endpoint,
|
|
24
31
|
errors,
|
|
25
|
-
href:
|
|
32
|
+
href: loggedHref(),
|
|
26
33
|
metadata: Object.assign({ appVersion: window.Zonos.version, domain: window.Zonos.domain, publicCredential: window.Zonos.zonosApiKey, userAgent: userAgentData && userAgentData.brands.length > 0
|
|
27
34
|
? userAgentData
|
|
28
35
|
: window.navigator.userAgent }, metadata),
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { sendErrorLog } from "./sendErrorLog";
|
|
2
|
+
import { thrownMessage } from "./thrownMessage";
|
|
3
|
+
const reportInitRejection = (error) => {
|
|
4
|
+
// sendErrorLog prints only when zonosDebug is on. Keep the failure in the
|
|
5
|
+
// merchant console without leaving an unhandled rejection.
|
|
6
|
+
// eslint-disable-next-line no-console -- the page console is the support signal
|
|
7
|
+
console.error(error);
|
|
8
|
+
if (typeof window.Zonos === 'undefined') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
void sendErrorLog({
|
|
12
|
+
endpoint: 'zonos://init',
|
|
13
|
+
errors: [thrownMessage(error, 'Unknown init rejection')],
|
|
14
|
+
metadata: {
|
|
15
|
+
shape: 'init-rejection',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Run an init that the caller is not waiting on. The rejection is recorded
|
|
21
|
+
* and not rethrown, so startup does not become an unhandled rejection.
|
|
22
|
+
*/
|
|
23
|
+
export const startZonosInit = (start) => {
|
|
24
|
+
let pending;
|
|
25
|
+
try {
|
|
26
|
+
pending = start();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
reportInitRejection(error);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
void pending.catch((error) => {
|
|
33
|
+
reportInitRejection(error);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const thrownMessage = (error, fallback) => {
|
|
2
|
+
if (typeof error === 'string' && error) {
|
|
3
|
+
return error;
|
|
4
|
+
}
|
|
5
|
+
if (error instanceof Error && error.message) {
|
|
6
|
+
return error.message;
|
|
7
|
+
}
|
|
8
|
+
if (typeof error === 'object' &&
|
|
9
|
+
error !== null &&
|
|
10
|
+
'message' in error &&
|
|
11
|
+
typeof error.message === 'string' &&
|
|
12
|
+
error.message) {
|
|
13
|
+
return error.message;
|
|
14
|
+
}
|
|
15
|
+
return fallback;
|
|
16
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { reportBlockedStorage, } from "./logging/reportBlockedStorage";
|
|
2
|
+
/**
|
|
3
|
+
* Touch `window.localStorage` / `window.sessionStorage` inside the try.
|
|
4
|
+
* Safari throws SecurityError on the getter itself when storage is blocked.
|
|
5
|
+
* A missing storage object is the same failure: calling `getItem` on it
|
|
6
|
+
* would report a TypeError instead of blocked storage.
|
|
7
|
+
*/
|
|
8
|
+
const storageFor = (area) => {
|
|
9
|
+
const storage = area === 'local' ? window.localStorage : window.sessionStorage;
|
|
10
|
+
if (!storage) {
|
|
11
|
+
throw new DOMException('', 'SecurityError');
|
|
12
|
+
}
|
|
13
|
+
return storage;
|
|
14
|
+
};
|
|
15
|
+
export const safeGetItem = (area, key) => {
|
|
16
|
+
try {
|
|
17
|
+
return storageFor(area).getItem(key);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
reportBlockedStorage(area, 'getItem', key, error);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const safeRemoveItem = (area, key) => {
|
|
25
|
+
try {
|
|
26
|
+
storageFor(area).removeItem(key);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
reportBlockedStorage(area, 'removeItem', key, error);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const safeSetItem = (area, key, value) => {
|
|
33
|
+
try {
|
|
34
|
+
storageFor(area).setItem(key, value);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
reportBlockedStorage(area, 'setItem', key, error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two checkout-path rules, kept together so they cannot drift in separate files.
|
|
3
|
+
*
|
|
4
|
+
* `pathContainsCheckout` is the broad rule for zBypass and address detection.
|
|
5
|
+
* It still matches paths such as `checkout-page`.
|
|
6
|
+
*
|
|
7
|
+
* `hasExactCheckoutSegment` is the strict rule for the Stripe.js skip. Only a
|
|
8
|
+
* segment exactly equal to `checkout` counts, so a slug does not drop the
|
|
9
|
+
* payment script.
|
|
10
|
+
*/
|
|
11
|
+
export const pathContainsCheckout = (pathname) => {
|
|
12
|
+
return pathname.includes('/checkout');
|
|
13
|
+
};
|
|
14
|
+
export const hasExactCheckoutSegment = (pathname) => {
|
|
15
|
+
return pathname.split('/').some(segment => segment === 'checkout');
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storefront signals BigCommerce sets before Zonos copies `isBigCommerce`.
|
|
3
|
+
* Shared by the loader script and the Stripe skip so the two cannot drift.
|
|
4
|
+
*/
|
|
5
|
+
export const detectBigCommerceHost = () => {
|
|
6
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return (!!window.stencilBootstrap ||
|
|
10
|
+
!!window.bcConfig ||
|
|
11
|
+
!!document.querySelector('script[src*="bigcommerce.com"]'));
|
|
12
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { log } from "../components/utils/logging/log";
|
|
2
|
+
import { safeRemoveItem } from "../components/utils/safeStorage";
|
|
2
3
|
import { extractZonosQaUrl, extractZonosQaUrlApi, } from "./_extractZonosQaUrl";
|
|
3
4
|
/**
|
|
4
5
|
* Get the Zonos QA URL and return it. Will remove `zonosQaUrl` from the url query if it doesn't exists.
|
|
@@ -49,8 +50,8 @@ export const getZonosQaUrl = () => {
|
|
|
49
50
|
void fetch(fullUrl)
|
|
50
51
|
.then(() => {
|
|
51
52
|
// cleanup checkout session to avoid using the prod session in preview domain
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
safeRemoveItem('session', 'zonos--checkout-session-id');
|
|
54
|
+
safeRemoveItem('session', 'zonos--client-secret');
|
|
54
55
|
})
|
|
55
56
|
.catch(() => {
|
|
56
57
|
alert(`[ZONOS-WARNING] '${fullUrl}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { hasExactCheckoutSegment } from "./_bigcommerceCheckoutPath";
|
|
2
|
+
import { detectBigCommerceHost } from "./_detectBigCommerceHost";
|
|
3
|
+
const hasCheckoutSegment = () => hasExactCheckoutSegment(window.location.pathname);
|
|
4
|
+
const sharedZonos = () => {
|
|
5
|
+
if (typeof window === 'undefined' || !('Zonos' in window)) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return window.Zonos;
|
|
9
|
+
};
|
|
10
|
+
const isFlaggedBigCommerce = () => {
|
|
11
|
+
var _a;
|
|
12
|
+
return ((_a = sharedZonos()) === null || _a === void 0 ? void 0 : _a.isBigCommerce) === true;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The settled answer lives on `window.Zonos`, the object loadZonos.js,
|
|
16
|
+
* zonos.js, and the component bundle already share.
|
|
17
|
+
*
|
|
18
|
+
* A `true` result sticks for that pathname. A `false` result sticks once
|
|
19
|
+
* the path is not checkout, or once host detection has finished. A checkout
|
|
20
|
+
* path whose BigCommerce signals are not in the page yet stays unset, so a
|
|
21
|
+
* later signal can still settle it.
|
|
22
|
+
*/
|
|
23
|
+
const readSettled = () => {
|
|
24
|
+
const zonos = sharedZonos();
|
|
25
|
+
if (zonos === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (zonos.isBigCommerceNativeCheckoutPath !== window.location.pathname) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const value = zonos.isBigCommerceNativeCheckout;
|
|
32
|
+
if (value === true || value === false) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
const writeSettled = (value) => {
|
|
38
|
+
const zonos = sharedZonos();
|
|
39
|
+
if (zonos !== undefined) {
|
|
40
|
+
zonos.isBigCommerceNativeCheckout = value;
|
|
41
|
+
zonos.isBigCommerceNativeCheckoutPath = window.location.pathname;
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Call after `isBigCommerce` has been copied from host detection. Writes the
|
|
47
|
+
* settled boolean onto `window.Zonos` for this pathname.
|
|
48
|
+
*/
|
|
49
|
+
export const markBigCommerceHostChecked = () => {
|
|
50
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const zonos = sharedZonos();
|
|
54
|
+
if (zonos === undefined) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const native = hasCheckoutSegment() && (detectBigCommerceHost() || isFlaggedBigCommerce());
|
|
58
|
+
zonos.isBigCommerceNativeCheckout = native;
|
|
59
|
+
zonos.isBigCommerceNativeCheckoutPath = window.location.pathname;
|
|
60
|
+
};
|
|
61
|
+
/** Test helper. Production pages keep the answer for the document. */
|
|
62
|
+
export const resetBigCommerceNativeCheckoutCache = () => {
|
|
63
|
+
const zonos = sharedZonos();
|
|
64
|
+
if (zonos === undefined) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
Reflect.deleteProperty(zonos, 'isBigCommerceNativeCheckout');
|
|
68
|
+
Reflect.deleteProperty(zonos, 'isBigCommerceNativeCheckoutPath');
|
|
69
|
+
};
|
|
70
|
+
const decide = () => {
|
|
71
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const settled = readSettled();
|
|
75
|
+
if (settled !== undefined) {
|
|
76
|
+
return settled;
|
|
77
|
+
}
|
|
78
|
+
if (!hasCheckoutSegment()) {
|
|
79
|
+
return writeSettled(false);
|
|
80
|
+
}
|
|
81
|
+
if (detectBigCommerceHost() || isFlaggedBigCommerce()) {
|
|
82
|
+
return writeSettled(true);
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* True when this document is BigCommerce native checkout.
|
|
88
|
+
* Stripe.js injection is owned by `loadStripeScript` in `_loadStripe.ts`.
|
|
89
|
+
* Other callers use this for a different job: skip `attachCheckout`, leave
|
|
90
|
+
* the store's buttons enabled, or hand a leftover domestic session to `/`.
|
|
91
|
+
* An undecided checkout path returns false and is not stored.
|
|
92
|
+
*/
|
|
93
|
+
export const isBigCommerceNativeCheckout = () => {
|
|
94
|
+
return decide() === true;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* True when Stripe.js must not be injected. An undecided checkout path
|
|
98
|
+
* holds the script until host detection finishes, instead of storing "not
|
|
99
|
+
* native checkout" and injecting v3 early.
|
|
100
|
+
*/
|
|
101
|
+
export const holdStripeForNativeCheckout = () => {
|
|
102
|
+
const decision = decide();
|
|
103
|
+
if (decision === undefined) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return decision;
|
|
107
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Execute our own script injection after a tick to give users time to do their
|
|
2
|
+
import { holdStripeForNativeCheckout } from "./_isBigCommerceNativeCheckout";
|
|
2
3
|
import { initStripe, zonosStripeLoadScript, } from "./_stripe";
|
|
3
4
|
// own script injection.
|
|
4
5
|
const hasCheckoutCartCallback = () => {
|
|
@@ -7,13 +8,23 @@ const hasCheckoutCartCallback = () => {
|
|
|
7
8
|
(typeof ((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.createCartId) === 'function' ||
|
|
8
9
|
typeof ((_b = window.Zonos) === null || _b === void 0 ? void 0 : _b.buildCartDetail) === 'function');
|
|
9
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* The only function that may inject Stripe.js. Native BigCommerce checkout
|
|
13
|
+
* returns null before `window.Stripe` is read or `js.stripe.com/v3` is added.
|
|
14
|
+
* Callers decide whether to ask for Stripe. They do not load it themselves.
|
|
15
|
+
*/
|
|
16
|
+
const loadStripeScript = () => {
|
|
17
|
+
if (holdStripeForNativeCheckout()) {
|
|
18
|
+
return Promise.resolve(null);
|
|
19
|
+
}
|
|
20
|
+
return zonosStripeLoadScript(null);
|
|
21
|
+
};
|
|
10
22
|
const stripePromise = Promise.resolve().then(() => {
|
|
11
|
-
//
|
|
12
|
-
// (e.g. a Hello-only integration). Stripe is loaded on demand instead.
|
|
23
|
+
// Hello-only pages have no cart callback, so they skip the eager preload.
|
|
13
24
|
if (!hasCheckoutCartCallback()) {
|
|
14
25
|
return null;
|
|
15
26
|
}
|
|
16
|
-
return
|
|
27
|
+
return loadStripeScript();
|
|
17
28
|
});
|
|
18
29
|
let loadCalled = false;
|
|
19
30
|
stripePromise.catch((err) => {
|
|
@@ -29,6 +40,6 @@ export const zonosLoadStripe = async (...args) => {
|
|
|
29
40
|
// Fall back to loading Stripe on demand if the eager preload was skipped
|
|
30
41
|
// (callbacks set after the microtask, or Collect/Invoice flows that don't
|
|
31
42
|
// use cart callbacks). `zonosStripeLoadScript` is idempotent.
|
|
32
|
-
const maybeStripe = (_a = (await stripePromise)) !== null && _a !== void 0 ? _a : (await
|
|
43
|
+
const maybeStripe = (_a = (await stripePromise)) !== null && _a !== void 0 ? _a : (await loadStripeScript());
|
|
33
44
|
return initStripe(maybeStripe, args, startTime);
|
|
34
45
|
};
|