@zonos/elements 1.3.270 → 1.3.273
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/{cart-3ff48a0e.js → cart-660e115c.js} +32 -2
- package/dist/cjs/collect-286a9d04.js +3107 -0
- package/dist/cjs/{hasInclusivePrice-aec06153.js → hasInclusivePrice-b35e81aa.js} +1 -1
- package/dist/cjs/index.cjs.js +7 -7
- package/dist/cjs/{invoice-ff716652.js → invoice-f032089f.js} +2 -2
- package/dist/cjs/isCollectMobileTablet-884d4280.js +15 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{localization-5c1c9c6a.js → localization-f4a64f6f.js} +245 -1
- package/dist/cjs/{paypal-c55b6c45.js → paypal-125259ab.js} +2 -2
- package/dist/cjs/{placeTestOrder-230f534b.js → placeTestOrder-02001a99.js} +2 -2
- package/dist/cjs/{renderCheckoutCurrency-e9d8efa8.js → renderCheckoutCurrency-cad156a7.js} +2 -2
- package/dist/cjs/zonos-address-display_8.cjs.entry.js +18 -18
- package/dist/cjs/zonos-address_4.cjs.entry.js +8 -8
- package/dist/cjs/zonos-airwallex-payment.cjs.entry.js +170 -0
- package/dist/cjs/zonos-badge.cjs.entry.js +3 -3
- package/dist/cjs/zonos-button_3.cjs.entry.js +3 -3
- package/dist/cjs/zonos-card_5.cjs.entry.js +9 -9
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +130 -20
- package/dist/cjs/zonos-checkbox_2.cjs.entry.js +5 -5
- package/dist/cjs/zonos-checkout.cjs.entry.js +3 -3
- package/dist/cjs/zonos-collapse.cjs.entry.js +2 -2
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +6 -6
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +150 -36
- package/dist/cjs/zonos-collect.cjs.entry.js +176 -38
- package/dist/cjs/zonos-component.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +3 -3
- package/dist/cjs/zonos-country-flag.cjs.entry.js +1 -1
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +10 -10
- package/dist/cjs/zonos-elements.cjs.js +1 -1
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +6 -6
- package/dist/cjs/zonos-hello.cjs.entry.js +1 -1
- package/dist/cjs/zonos-input.cjs.entry.js +4 -4
- package/dist/cjs/zonos-invoice-cart-items_2.cjs.entry.js +8 -8
- package/dist/cjs/zonos-invoice-finish_5.cjs.entry.js +14 -14
- package/dist/cjs/zonos-invoice.cjs.entry.js +4 -4
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +5 -5
- package/dist/cjs/zonos-link.cjs.entry.js +1 -1
- package/dist/cjs/zonos-logo.cjs.entry.js +2 -2
- package/dist/cjs/zonos-policy-consent_2.cjs.entry.js +3 -3
- package/dist/cjs/zonos-stripe-input.cjs.entry.js +4 -4
- package/dist/cjs/zonos-tooltip.cjs.entry.js +2 -2
- package/dist/cjs/zonos-v-stack.cjs.entry.js +2 -2
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/airwallex/zonos-airwallex-payment/zonos-airwallex-payment.css +43 -0
- package/dist/collection/components/airwallex/zonos-airwallex-payment/zonos-airwallex-payment.js +215 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-address-update-dialog/zonos-address-form/zonos-address-form.js +4 -4
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js +1 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +4 -4
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-footer/zonos-checkout-footer.js +2 -2
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.js +4 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +1 -1
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-cart-items/zonos-collect-cart-items.js +1 -1
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-finish/zonos-collect-finish.js +110 -2
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/zonos-collect-footer.js +3 -3
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-order-details/zonos-collect-order-details.js +1 -1
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-payment/zonos-collect-payment.css +1 -17
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-payment/zonos-collect-payment.js +21 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-review/zonos-collect-review.js +3 -3
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-subtotal/zonos-collect-subtotal.js +5 -5
- package/dist/collection/components/checkout/zonos-collect/zonos-collect.js +167 -29
- package/dist/collection/components/checkout/zonos-invoice/zonos-invoice-cart-items/zonos-invoice-cart-items.js +2 -2
- package/dist/collection/components/checkout/zonos-invoice/zonos-invoice-finish/zonos-invoice-finish.js +2 -2
- package/dist/collection/components/checkout/zonos-invoice/zonos-invoice-footer/zonos-invoice-footer.js +3 -3
- package/dist/collection/components/checkout/zonos-invoice/zonos-invoice-review/zonos-invoice-review.js +3 -3
- package/dist/collection/components/checkout/zonos-invoice/zonos-invoice-subtotal/zonos-invoice-subtotal.js +2 -2
- package/dist/collection/components/common/zonos-badge/zonos-badge.js +3 -3
- package/dist/collection/components/common/zonos-button/zonos-button.js +3 -3
- package/dist/collection/components/common/zonos-card/zonos-card.js +4 -4
- package/dist/collection/components/common/zonos-checkbox/zonos-checkbox.js +3 -3
- package/dist/collection/components/common/zonos-checkout-progress-tabs/zonos-checkout-progress-tabs.js +3 -3
- package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +2 -2
- package/dist/collection/components/common/zonos-confirm-dialog/zonos-confirm-dialog.js +3 -3
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +3 -3
- package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.js +2 -2
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.js +3 -3
- package/dist/collection/components/common/zonos-h-stack/zonos-h-stack.js +2 -2
- package/dist/collection/components/common/zonos-input/zonos-input.js +4 -4
- package/dist/collection/components/common/zonos-language-select/zonos-language-select.js +2 -2
- package/dist/collection/components/common/zonos-link/zonos-link.js +1 -1
- package/dist/collection/components/common/zonos-loading-overlay/zonos-loading-overlay.js +1 -1
- package/dist/collection/components/common/zonos-logo/zonos-logo.js +2 -2
- package/dist/collection/components/common/zonos-rest-state/zonos-rest-state.js +3 -3
- package/dist/collection/components/common/zonos-select-dialog-header/zonos-select-dialog-header.js +2 -2
- package/dist/collection/components/common/zonos-skeleton/zonos-skeleton.js +1 -1
- package/dist/collection/components/common/zonos-stripe-input/zonos-stripe-input.js +4 -4
- package/dist/collection/components/common/zonos-stripe-phone-input/zonos-stripe-phone-input.js +6 -6
- package/dist/collection/components/common/zonos-toggle/zonos-toggle.js +2 -2
- package/dist/collection/components/common/zonos-tooltip/zonos-tooltip.js +2 -2
- package/dist/collection/components/common/zonos-v-stack/zonos-v-stack.js +2 -2
- package/dist/collection/components/common/zonos-virtual-scroll/zonos-virtual-scroll.js +2 -2
- package/dist/collection/components/component-template/zonos-component/zonos-component.js +1 -1
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.js +2 -2
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.js +4 -4
- package/dist/collection/components/main/zonos-controller.js +2 -2
- package/dist/collection/components/paypal/zonos-paypal-payment.js +1 -1
- package/dist/collection/components/store/checkout/airwallex.js +195 -0
- package/dist/collection/components/store/checkout/collect.js +4 -1
- package/dist/collection/components/store/checkout/euWithdrawalRate.js +40 -0
- package/dist/collection/components/store/checkout/stripe.js +26 -1
- package/dist/collection/components/store/hello/localization.js +3 -1
- package/dist/collection/components/store/translationStore/strings.arabic.js +12 -0
- package/dist/collection/components/store/translationStore/strings.base.js +12 -0
- package/dist/collection/components/store/translationStore/strings.chinese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.danish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.dutch.js +12 -0
- package/dist/collection/components/store/translationStore/strings.french.js +12 -0
- package/dist/collection/components/store/translationStore/strings.german.js +12 -0
- package/dist/collection/components/store/translationStore/strings.hebrew.js +12 -0
- package/dist/collection/components/store/translationStore/strings.indonesian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.italian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.japanese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.korean.js +12 -0
- package/dist/collection/components/store/translationStore/strings.norwegian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.polish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.portuguese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.russian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.spanish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.swedish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.turkish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.vietnamese.js +12 -0
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +2 -2
- package/dist/collection/components/stripe/zonos-custom-address/zonos-address-suggestions/zonos-address-suggestions.js +2 -2
- package/dist/collection/components/stripe/zonos-custom-address/zonos-custom-address.js +2 -2
- package/dist/collection/components/stripe/zonos-payment/zonos-payment.js +1 -1
- package/dist/collection/components/utils/checkout/euWithdrawalNotice.js +74 -0
- package/dist/collection/types/generated/graphql.internal.types.js +318 -182
- package/dist/esm/{cart-44fa77ef.js → cart-23e29950.js} +32 -2
- package/dist/esm/collect-a235299d.js +3092 -0
- package/dist/esm/{hasInclusivePrice-f0440925.js → hasInclusivePrice-5e106f84.js} +1 -1
- package/dist/esm/index.js +7 -7
- package/dist/esm/{invoice-89e71796.js → invoice-78f069c7.js} +2 -2
- package/dist/esm/isCollectMobileTablet-111b0dd7.js +12 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{localization-066586b6.js → localization-17546792.js} +244 -2
- package/dist/esm/{paypal-8725008c.js → paypal-5bc6b0d0.js} +2 -2
- package/dist/esm/{placeTestOrder-38be871e.js → placeTestOrder-e842854a.js} +2 -2
- package/dist/esm/{renderCheckoutCurrency-802f4481.js → renderCheckoutCurrency-e3953f67.js} +2 -2
- package/dist/esm/zonos-address-display_8.entry.js +18 -18
- package/dist/esm/zonos-address_4.entry.js +8 -8
- package/dist/esm/zonos-airwallex-payment.entry.js +166 -0
- package/dist/esm/zonos-badge.entry.js +3 -3
- package/dist/esm/zonos-button_3.entry.js +3 -3
- package/dist/esm/zonos-card_5.entry.js +9 -9
- package/dist/esm/zonos-cart-items_12.entry.js +131 -21
- package/dist/esm/zonos-checkbox_2.entry.js +5 -5
- package/dist/esm/zonos-checkout.entry.js +3 -3
- package/dist/esm/zonos-collapse.entry.js +2 -2
- package/dist/esm/zonos-collect-cart-items_3.entry.js +6 -6
- package/dist/esm/zonos-collect-finish_6.entry.js +135 -21
- package/dist/esm/zonos-collect.entry.js +171 -33
- package/dist/esm/zonos-component.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +3 -3
- package/dist/esm/zonos-country-flag.entry.js +1 -1
- package/dist/esm/zonos-country-select_4.entry.js +10 -10
- package/dist/esm/zonos-elements.js +1 -1
- package/dist/esm/zonos-hello-dialog.entry.js +6 -6
- package/dist/esm/zonos-hello.entry.js +1 -1
- package/dist/esm/zonos-input.entry.js +4 -4
- package/dist/esm/zonos-invoice-cart-items_2.entry.js +8 -8
- package/dist/esm/zonos-invoice-finish_5.entry.js +14 -14
- package/dist/esm/zonos-invoice.entry.js +4 -4
- package/dist/esm/zonos-language-select_2.entry.js +5 -5
- package/dist/esm/zonos-link.entry.js +1 -1
- package/dist/esm/zonos-logo.entry.js +2 -2
- package/dist/esm/zonos-policy-consent_2.entry.js +3 -3
- package/dist/esm/zonos-stripe-input.entry.js +4 -4
- package/dist/esm/zonos-tooltip.entry.js +2 -2
- package/dist/esm/zonos-v-stack.entry.js +2 -2
- package/dist/esm-es5/cart-23e29950.js +1 -0
- package/dist/esm-es5/collect-a235299d.js +1 -0
- package/dist/esm-es5/{hasInclusivePrice-f0440925.js → hasInclusivePrice-5e106f84.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{invoice-89e71796.js → invoice-78f069c7.js} +1 -1
- package/dist/esm-es5/isCollectMobileTablet-111b0dd7.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/localization-17546792.js +1 -0
- package/dist/esm-es5/{paypal-8725008c.js → paypal-5bc6b0d0.js} +1 -1
- package/dist/esm-es5/{placeTestOrder-38be871e.js → placeTestOrder-e842854a.js} +1 -1
- package/dist/esm-es5/{renderCheckoutCurrency-802f4481.js → renderCheckoutCurrency-e3953f67.js} +1 -1
- package/dist/esm-es5/zonos-address-display_8.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 -0
- package/dist/esm-es5/zonos-badge.entry.js +1 -1
- package/dist/esm-es5/zonos-button_3.entry.js +1 -1
- package/dist/esm-es5/zonos-card_5.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -1
- package/dist/esm-es5/zonos-checkbox_2.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collapse.entry.js +1 -1
- 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-component.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- 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-elements.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-input.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 +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-link.entry.js +1 -1
- package/dist/esm-es5/zonos-logo.entry.js +1 -1
- package/dist/esm-es5/zonos-policy-consent_2.entry.js +1 -1
- package/dist/esm-es5/zonos-stripe-input.entry.js +1 -1
- package/dist/esm-es5/zonos-tooltip.entry.js +1 -1
- package/dist/esm-es5/zonos-v-stack.entry.js +1 -1
- package/dist/scripts/index.d.ts +99 -3
- 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/airwallex/zonos-airwallex-payment/zonos-airwallex-payment.d.ts +46 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-finish/zonos-collect-finish.d.ts +7 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-payment/zonos-collect-payment.d.ts +4 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect.d.ts +29 -0
- package/dist/types/components/store/checkout/airwallex.d.ts +83 -0
- package/dist/types/components/store/checkout/collect.d.ts +12 -1
- package/dist/types/components/store/checkout/euWithdrawalRate.d.ts +19 -0
- package/dist/types/components/store/checkout/stripe.d.ts +1 -1
- package/dist/types/components/store/translationStore/strings.arabic.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.base.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.chinese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.danish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.dutch.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.french.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.german.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.hebrew.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.indonesian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.italian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.japanese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.korean.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.norwegian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.polish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.portuguese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.russian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.spanish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.swedish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.turkish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +12 -0
- package/dist/types/components/utils/checkout/euWithdrawalNotice.d.ts +9 -0
- package/dist/types/components.d.ts +42 -0
- package/dist/types/scripts/cart/_setupCartDataWithSettings.d.ts +8 -3
- package/dist/types/types/checkout/CheckoutConfig.d.ts +10 -0
- package/dist/types/types/checkout/api/CheckoutSession.d.ts +11 -1
- package/dist/types/types/checkout/api/PartyInfo.d.ts +6 -0
- package/dist/types/types/generated/graphql.internal.types.d.ts +416 -218
- package/dist/types/types/generated/graphql.internal.types.ts +537 -258
- package/dist/types/types/utils/ZonosSettings.d.ts +15 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-013575f2.entry.js +1 -0
- package/dist/zonos-elements/{p-344a1fee.entry.js → p-055ef910.entry.js} +1 -1
- package/dist/zonos-elements/{p-d29dbeb3.entry.js → p-08b48608.entry.js} +1 -1
- package/dist/zonos-elements/{p-26ae4ee7.system.entry.js → p-0a54dae6.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-6ac77d9f.system.entry.js → p-0b59076d.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-c92a5ae5.system.entry.js → p-10571f94.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-658ab5e2.entry.js → p-12a05647.entry.js} +1 -1
- package/dist/zonos-elements/{p-703f2737.system.js → p-14018649.system.js} +2 -2
- package/dist/zonos-elements/{p-acd7009a.system.entry.js → p-1678d8b4.system.entry.js} +1 -1
- package/dist/zonos-elements/p-171d0f9f.system.js +1 -0
- package/dist/zonos-elements/{p-7e03bd33.system.entry.js → p-1a105d6e.system.entry.js} +1 -1
- package/dist/zonos-elements/p-1a4083be.system.js +1 -0
- package/dist/zonos-elements/{p-72666536.system.entry.js → p-1f31f5a0.system.entry.js} +1 -1
- package/dist/zonos-elements/p-2197d6ab.js +1 -0
- package/dist/zonos-elements/{p-536cbab5.system.entry.js → p-27e50593.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0b4ba025.entry.js → p-2825431d.entry.js} +1 -1
- package/dist/zonos-elements/p-29b60bf3.system.js +1 -1
- package/dist/zonos-elements/{p-ccd0fa8f.system.entry.js → p-2a1247f4.system.entry.js} +1 -1
- package/dist/zonos-elements/p-2adbbce7.system.js +1 -0
- package/dist/zonos-elements/{p-553ca694.system.entry.js → p-306e5499.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-b15ceaff.entry.js → p-31577ebd.entry.js} +1 -1
- package/dist/zonos-elements/{p-889a44fc.entry.js → p-328fd90e.entry.js} +1 -1
- package/dist/zonos-elements/p-33910e8b.js +1 -0
- package/dist/zonos-elements/{p-fb684748.system.entry.js → p-36b311f9.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-5b4e5608.system.entry.js → p-3eba657b.system.entry.js} +1 -1
- package/dist/zonos-elements/p-41619f29.js +1 -0
- package/dist/zonos-elements/{p-7792f4c2.js → p-42948a52.js} +1 -1
- package/dist/zonos-elements/p-46e72a90.entry.js +1 -0
- package/dist/zonos-elements/p-49d8a10f.entry.js +1 -0
- package/dist/zonos-elements/{p-fc651784.system.entry.js → p-4a960329.system.entry.js} +1 -1
- package/dist/zonos-elements/p-4b371b65.entry.js +1 -0
- package/dist/zonos-elements/p-539bc46c.js +1 -0
- package/dist/zonos-elements/p-579932a7.js +1 -0
- package/dist/zonos-elements/{p-2afecda7.entry.js → p-59b10526.entry.js} +1 -1
- package/dist/zonos-elements/{p-98bea13e.system.entry.js → p-5aa35d1c.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-238370ad.system.js → p-62c68aee.system.js} +1 -1
- package/dist/zonos-elements/{p-5df77315.system.entry.js → p-6c19310e.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-16948eea.system.entry.js → p-732e7373.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0e8c4a29.entry.js → p-734d646b.entry.js} +1 -1
- package/dist/zonos-elements/{p-2f61dc3c.entry.js → p-7eb47eb0.entry.js} +1 -1
- package/dist/zonos-elements/{p-a2885536.system.entry.js → p-86a9f048.system.entry.js} +1 -1
- package/dist/zonos-elements/p-8af57c2a.js +1 -0
- package/dist/zonos-elements/{p-fb83134b.system.entry.js → p-8c4761d1.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-5812b323.system.entry.js → p-8e77a3cd.system.entry.js} +1 -1
- package/dist/zonos-elements/p-919c5500.entry.js +1 -0
- package/dist/zonos-elements/{p-c76ec587.system.js → p-91b921a4.system.js} +1 -1
- package/dist/zonos-elements/p-9574695a.system.js +1 -0
- package/dist/zonos-elements/p-97917371.system.entry.js +1 -0
- package/dist/zonos-elements/p-9b003a15.system.entry.js +1 -0
- package/dist/zonos-elements/{p-e11c3410.entry.js → p-9c3276c8.entry.js} +1 -1
- package/dist/zonos-elements/p-9cd41234.system.entry.js +1 -0
- package/dist/zonos-elements/{p-5f92db80.system.entry.js → p-a1a05de4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-6704b83e.entry.js → p-a968ccba.entry.js} +1 -1
- package/dist/zonos-elements/{p-91702715.entry.js → p-abd485df.entry.js} +1 -1
- package/dist/zonos-elements/{p-69ad7325.entry.js → p-ad961f5d.entry.js} +1 -1
- package/dist/zonos-elements/{p-ad4c8167.system.entry.js → p-b5c01288.system.entry.js} +1 -1
- package/dist/zonos-elements/p-bf8c98ab.system.js +1 -0
- package/dist/zonos-elements/{p-eb96d62f.entry.js → p-c13d2e3f.entry.js} +1 -1
- package/dist/zonos-elements/{p-0b46f3bd.system.entry.js → p-c15476a1.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0e36a7cf.system.entry.js → p-c6823974.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-dae881f2.entry.js → p-c83bc4b3.entry.js} +1 -1
- package/dist/zonos-elements/{p-134c5010.system.entry.js → p-c846a5f3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-7aca66cd.entry.js → p-cc508de8.entry.js} +1 -1
- package/dist/zonos-elements/{p-d4c966cb.entry.js → p-ccd14aa5.entry.js} +1 -1
- package/dist/zonos-elements/{p-801dd8d8.system.js → p-d25759fb.system.js} +1 -1
- package/dist/zonos-elements/{p-fcf3ed5c.entry.js → p-d5e66ea6.entry.js} +1 -1
- package/dist/zonos-elements/{p-2df84888.system.entry.js → p-daf57db3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-b35a0b1e.entry.js → p-dcef2202.entry.js} +1 -1
- package/dist/zonos-elements/{p-283ffaad.entry.js → p-dd6da3de.entry.js} +1 -1
- package/dist/zonos-elements/{p-30e819ed.entry.js → p-df6fbf3f.entry.js} +1 -1
- package/dist/zonos-elements/{p-0d251428.entry.js → p-e643346a.entry.js} +1 -1
- package/dist/zonos-elements/{p-a977cddd.entry.js → p-e8cb382e.entry.js} +1 -1
- package/dist/zonos-elements/{p-2651ca93.system.entry.js → p-e8ec88a9.system.entry.js} +1 -1
- package/dist/zonos-elements/p-e9afd736.system.entry.js +1 -0
- package/dist/zonos-elements/{p-208b270a.js → p-e9c8a235.js} +1 -1
- package/dist/zonos-elements/{p-b1a4f385.system.entry.js → p-f0eb6317.system.entry.js} +1 -1
- package/dist/zonos-elements/p-f1cc659c.js +1 -0
- package/dist/zonos-elements/{p-9abfb6b0.entry.js → p-f53c8a9f.entry.js} +1 -1
- package/dist/zonos-elements/{p-777d396e.entry.js → p-f72642de.entry.js} +1 -1
- package/dist/zonos-elements/{p-0d2d7fc4.system.js → p-fcaec700.system.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +2 -1
- package/dist/cjs/isCollectMobileTablet-3ac53cab.js +0 -176
- package/dist/esm/isCollectMobileTablet-323d2ba1.js +0 -169
- package/dist/esm-es5/cart-44fa77ef.js +0 -1
- package/dist/esm-es5/isCollectMobileTablet-323d2ba1.js +0 -1
- package/dist/esm-es5/localization-066586b6.js +0 -1
- package/dist/zonos-elements/p-08c7dc07.system.entry.js +0 -1
- package/dist/zonos-elements/p-0e9c0eff.entry.js +0 -1
- package/dist/zonos-elements/p-0fb8b711.system.entry.js +0 -1
- package/dist/zonos-elements/p-225f19b6.entry.js +0 -1
- package/dist/zonos-elements/p-260a5b57.js +0 -1
- package/dist/zonos-elements/p-27beefda.system.js +0 -1
- package/dist/zonos-elements/p-31a3b070.system.js +0 -1
- package/dist/zonos-elements/p-5ab4bc26.system.entry.js +0 -1
- package/dist/zonos-elements/p-9e414000.js +0 -1
- package/dist/zonos-elements/p-b1125711.system.js +0 -1
- package/dist/zonos-elements/p-bea9d128.js +0 -1
- package/dist/zonos-elements/p-bfcc1432.js +0 -1
- package/dist/zonos-elements/p-c049c527.js +0 -1
- package/dist/zonos-elements/p-d659153c.entry.js +0 -1
- package/dist/zonos-elements/p-debd2e30.js +0 -1
- package/dist/zonos-elements/p-ebc966d8.entry.js +0 -1
- package/dist/zonos-elements/p-f5d4775a.system.js +0 -1
|
@@ -0,0 +1,3092 @@
|
|
|
1
|
+
import { c as createStore, z as zonosStore } from './zonosStore-8e19daff.js';
|
|
2
|
+
import { t as translate, l as localizationStore, s as storageStore } from './localization-17546792.js';
|
|
3
|
+
import { l as logError$1, h as handleFetch, s as sendErrorLog } from './handleFetch-a844cac1.js';
|
|
4
|
+
import { l as log, b as allLogs } from './VarianceTest-572cecf5.js';
|
|
5
|
+
import { b as stripeStore, K as stripeStoreBuildAddressForPartyCreate, d as cartStore, L as cartStoreUpdateSelectedShippingOption } from './cart-23e29950.js';
|
|
6
|
+
|
|
7
|
+
// src/constant/common.ts
|
|
8
|
+
function _array_like_to_array(arr, len) {
|
|
9
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
10
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
11
|
+
return arr2;
|
|
12
|
+
}
|
|
13
|
+
function _array_with_holes(arr) {
|
|
14
|
+
if (Array.isArray(arr)) return arr;
|
|
15
|
+
}
|
|
16
|
+
function _array_without_holes(arr) {
|
|
17
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
18
|
+
}
|
|
19
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
20
|
+
try {
|
|
21
|
+
var info = gen[key](arg);
|
|
22
|
+
var value = info.value;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
reject(error);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (info.done) {
|
|
28
|
+
resolve(value);
|
|
29
|
+
} else {
|
|
30
|
+
Promise.resolve(value).then(_next, _throw);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _async_to_generator(fn) {
|
|
34
|
+
return function() {
|
|
35
|
+
var self = this, args = arguments;
|
|
36
|
+
return new Promise(function(resolve, reject) {
|
|
37
|
+
var gen = fn.apply(self, args);
|
|
38
|
+
function _next(value) {
|
|
39
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
40
|
+
}
|
|
41
|
+
function _throw(err) {
|
|
42
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
43
|
+
}
|
|
44
|
+
_next(undefined);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function _class_call_check(instance, Constructor) {
|
|
49
|
+
if (!(instance instanceof Constructor)) {
|
|
50
|
+
throw new TypeError("Cannot call a class as a function");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function _defineProperties(target, props) {
|
|
54
|
+
for(var i = 0; i < props.length; i++){
|
|
55
|
+
var descriptor = props[i];
|
|
56
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
57
|
+
descriptor.configurable = true;
|
|
58
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
59
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
63
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
64
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
65
|
+
return Constructor;
|
|
66
|
+
}
|
|
67
|
+
function _define_property(obj, key, value) {
|
|
68
|
+
if (key in obj) {
|
|
69
|
+
Object.defineProperty(obj, key, {
|
|
70
|
+
value: value,
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
obj[key] = value;
|
|
77
|
+
}
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
function _instanceof(left, right) {
|
|
81
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
82
|
+
return !!right[Symbol.hasInstance](left);
|
|
83
|
+
} else {
|
|
84
|
+
return left instanceof right;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function _iterable_to_array(iter) {
|
|
88
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
89
|
+
}
|
|
90
|
+
function _iterable_to_array_limit(arr, i) {
|
|
91
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
92
|
+
if (_i == null) return;
|
|
93
|
+
var _arr = [];
|
|
94
|
+
var _n = true;
|
|
95
|
+
var _d = false;
|
|
96
|
+
var _s, _e;
|
|
97
|
+
try {
|
|
98
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
99
|
+
_arr.push(_s.value);
|
|
100
|
+
if (i && _arr.length === i) break;
|
|
101
|
+
}
|
|
102
|
+
} catch (err) {
|
|
103
|
+
_d = true;
|
|
104
|
+
_e = err;
|
|
105
|
+
} finally{
|
|
106
|
+
try {
|
|
107
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
108
|
+
} finally{
|
|
109
|
+
if (_d) throw _e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return _arr;
|
|
113
|
+
}
|
|
114
|
+
function _non_iterable_rest() {
|
|
115
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
116
|
+
}
|
|
117
|
+
function _non_iterable_spread() {
|
|
118
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
119
|
+
}
|
|
120
|
+
function _object_spread(target) {
|
|
121
|
+
for(var i = 1; i < arguments.length; i++){
|
|
122
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
123
|
+
var ownKeys = Object.keys(source);
|
|
124
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
125
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
126
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
ownKeys.forEach(function(key) {
|
|
130
|
+
_define_property(target, key, source[key]);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return target;
|
|
134
|
+
}
|
|
135
|
+
function ownKeys(object, enumerableOnly) {
|
|
136
|
+
var keys = Object.keys(object);
|
|
137
|
+
if (Object.getOwnPropertySymbols) {
|
|
138
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
139
|
+
if (enumerableOnly) {
|
|
140
|
+
symbols = symbols.filter(function(sym) {
|
|
141
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
keys.push.apply(keys, symbols);
|
|
145
|
+
}
|
|
146
|
+
return keys;
|
|
147
|
+
}
|
|
148
|
+
function _object_spread_props(target, source) {
|
|
149
|
+
source = source != null ? source : {};
|
|
150
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
151
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
152
|
+
} else {
|
|
153
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
154
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return target;
|
|
158
|
+
}
|
|
159
|
+
function _sliced_to_array(arr, i) {
|
|
160
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
161
|
+
}
|
|
162
|
+
function _to_consumable_array(arr) {
|
|
163
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
164
|
+
}
|
|
165
|
+
function _type_of(obj) {
|
|
166
|
+
"@swc/helpers - typeof";
|
|
167
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
168
|
+
}
|
|
169
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
170
|
+
if (!o) return;
|
|
171
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
172
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
173
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
174
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
175
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
176
|
+
}
|
|
177
|
+
function _ts_generator(thisArg, body) {
|
|
178
|
+
var f, y, t, g, _ = {
|
|
179
|
+
label: 0,
|
|
180
|
+
sent: function() {
|
|
181
|
+
if (t[0] & 1) throw t[1];
|
|
182
|
+
return t[1];
|
|
183
|
+
},
|
|
184
|
+
trys: [],
|
|
185
|
+
ops: []
|
|
186
|
+
};
|
|
187
|
+
return g = {
|
|
188
|
+
next: verb(0),
|
|
189
|
+
"throw": verb(1),
|
|
190
|
+
"return": verb(2)
|
|
191
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
192
|
+
return this;
|
|
193
|
+
}), g;
|
|
194
|
+
function verb(n) {
|
|
195
|
+
return function(v) {
|
|
196
|
+
return step([
|
|
197
|
+
n,
|
|
198
|
+
v
|
|
199
|
+
]);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function step(op) {
|
|
203
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
204
|
+
while(_)try {
|
|
205
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
206
|
+
if (y = 0, t) op = [
|
|
207
|
+
op[0] & 2,
|
|
208
|
+
t.value
|
|
209
|
+
];
|
|
210
|
+
switch(op[0]){
|
|
211
|
+
case 0:
|
|
212
|
+
case 1:
|
|
213
|
+
t = op;
|
|
214
|
+
break;
|
|
215
|
+
case 4:
|
|
216
|
+
_.label++;
|
|
217
|
+
return {
|
|
218
|
+
value: op[1],
|
|
219
|
+
done: false
|
|
220
|
+
};
|
|
221
|
+
case 5:
|
|
222
|
+
_.label++;
|
|
223
|
+
y = op[1];
|
|
224
|
+
op = [
|
|
225
|
+
0
|
|
226
|
+
];
|
|
227
|
+
continue;
|
|
228
|
+
case 7:
|
|
229
|
+
op = _.ops.pop();
|
|
230
|
+
_.trys.pop();
|
|
231
|
+
continue;
|
|
232
|
+
default:
|
|
233
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
234
|
+
_ = 0;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
238
|
+
_.label = op[1];
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
242
|
+
_.label = t[1];
|
|
243
|
+
t = op;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
if (t && _.label < t[2]) {
|
|
247
|
+
_.label = t[2];
|
|
248
|
+
_.ops.push(op);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
if (t[2]) _.ops.pop();
|
|
252
|
+
_.trys.pop();
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
op = body.call(thisArg, _);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
op = [
|
|
258
|
+
6,
|
|
259
|
+
e
|
|
260
|
+
];
|
|
261
|
+
y = 0;
|
|
262
|
+
} finally{
|
|
263
|
+
f = t = 0;
|
|
264
|
+
}
|
|
265
|
+
if (op[0] & 5) throw op[1];
|
|
266
|
+
return {
|
|
267
|
+
value: op[0] ? op[1] : void 0,
|
|
268
|
+
done: true
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
var Environment = /* @__PURE__ */ function(Environment2) {
|
|
273
|
+
Environment2["production"] = "prod";
|
|
274
|
+
Environment2["demo"] = "demo";
|
|
275
|
+
Environment2["staging"] = "staging";
|
|
276
|
+
return Environment2;
|
|
277
|
+
}(Environment || {});
|
|
278
|
+
// src/constant/config.ts
|
|
279
|
+
var UNKNOWN_VALUE = "airTracker_unknown";
|
|
280
|
+
var DEFAULT_CONFIG = {
|
|
281
|
+
appName: UNKNOWN_VALUE,
|
|
282
|
+
appVersion: UNKNOWN_VALUE,
|
|
283
|
+
env: "staging" /* staging */ ,
|
|
284
|
+
isWebappContainer: false,
|
|
285
|
+
delay: 2e3,
|
|
286
|
+
errorRepeatTime: 3,
|
|
287
|
+
enableErrorMonitoring: false,
|
|
288
|
+
assetSpeedMonitoringWhiteList: [],
|
|
289
|
+
enableDetectPageChange: false,
|
|
290
|
+
enableRecordPageRetention: false,
|
|
291
|
+
hideSearchParams: false,
|
|
292
|
+
useSessionStorageForSessionId: false,
|
|
293
|
+
assetSpeedMonitoringWhiteListByMFE: {}
|
|
294
|
+
};
|
|
295
|
+
var DEFAULT_COMMON_DATA = {
|
|
296
|
+
appName: UNKNOWN_VALUE,
|
|
297
|
+
env: "staging" /* staging */ ,
|
|
298
|
+
sessionId: UNKNOWN_VALUE,
|
|
299
|
+
deviceId: UNKNOWN_VALUE
|
|
300
|
+
};
|
|
301
|
+
// src/util/jsonHelper.ts
|
|
302
|
+
var isJSON = function(str) {
|
|
303
|
+
if (!str) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
if (/^\s*$/.test(str)) return false;
|
|
307
|
+
str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@");
|
|
308
|
+
str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]");
|
|
309
|
+
str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, "");
|
|
310
|
+
return /^[\],:{}\s]*$/.test(str);
|
|
311
|
+
};
|
|
312
|
+
var safeReplacer = function() {
|
|
313
|
+
var seen = /* @__PURE__ */ new WeakSet();
|
|
314
|
+
return function(key, value) {
|
|
315
|
+
if (_instanceof(value, Error)) {
|
|
316
|
+
return "Error.message: ".concat(value.message, " \n Error.stack: ").concat(value.stack);
|
|
317
|
+
}
|
|
318
|
+
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && value !== null) {
|
|
319
|
+
if (seen.has(value)) {
|
|
320
|
+
return "[Circular ".concat(key || "root", "]");
|
|
321
|
+
}
|
|
322
|
+
seen.add(value);
|
|
323
|
+
}
|
|
324
|
+
if (typeof value === "function") {
|
|
325
|
+
return "function";
|
|
326
|
+
}
|
|
327
|
+
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "symbol") {
|
|
328
|
+
return "symbol";
|
|
329
|
+
}
|
|
330
|
+
if (typeof value === "undefined") {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
return value;
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
var safeStringify = function(obj) {
|
|
337
|
+
if (typeof obj === "string") {
|
|
338
|
+
return obj;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
if (_instanceof(obj, Error)) {
|
|
342
|
+
return (JSON.stringify(obj, safeReplacer()) || "undefined").replace(/"/gim, "");
|
|
343
|
+
}
|
|
344
|
+
return JSON.stringify(obj, safeReplacer());
|
|
345
|
+
} catch (e) {
|
|
346
|
+
return '{"error":"error happen when airTracker stringify"}';
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
// src/util/http.ts
|
|
350
|
+
var request = function(param) {
|
|
351
|
+
var _param_method = param.method, method = _param_method === void 0 ? "post" : _param_method, url = param.url, data = param.data, success = param.success, fail = param.fail;
|
|
352
|
+
if (!isJSON(data)) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
var xhr = new XMLHttpRequest();
|
|
356
|
+
xhr.addEventListener("readystatechange", function() {
|
|
357
|
+
if (xhr.readyState === 4) {
|
|
358
|
+
if (xhr.status >= 400 || xhr.status === 0) {
|
|
359
|
+
fail === null || fail === void 0 ? void 0 : fail(xhr.response);
|
|
360
|
+
} else {
|
|
361
|
+
success === null || success === void 0 ? void 0 : success(xhr.response);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
xhr.open(method, url);
|
|
366
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
367
|
+
xhr.send(data);
|
|
368
|
+
};
|
|
369
|
+
// src/constant/lifeCycleEventName.ts
|
|
370
|
+
var lifeCycleEventName = {
|
|
371
|
+
onInit: "onInit",
|
|
372
|
+
onConfigInit: "onConfigInit",
|
|
373
|
+
onConfigUpdated: "onConfigUpdated",
|
|
374
|
+
onCommonDataInit: "onCommonDataInit",
|
|
375
|
+
onCommonUpdated: "onCommonUpdated",
|
|
376
|
+
onPageChange: "onPageChange",
|
|
377
|
+
onDestroy: "onDestroy,"
|
|
378
|
+
};
|
|
379
|
+
// src/constant/index.ts
|
|
380
|
+
var DEVICE_ID_STORAGE_KEY = "AIR_ANALYTICS_DEVICE_ID";
|
|
381
|
+
var SESSION_ID_STORAGE_KEY = "AIR_ANALYTICS_SESSION_ID";
|
|
382
|
+
var RISK_DEVICE_ID_STORAGE_KEY = "AWX_RISK_ID";
|
|
383
|
+
var loggingServiceUrl = function(env) {
|
|
384
|
+
if (env == "prod" /* production */ ) {
|
|
385
|
+
return "https://o11y.airwallex.com/airtracker/logs";
|
|
386
|
+
}
|
|
387
|
+
if (env == "demo" /* demo */ ) {
|
|
388
|
+
return "https://o11y-demo.airwallex.com/airtracker/logs";
|
|
389
|
+
}
|
|
390
|
+
return "https://o11y-staging.airwallex.com/airtracker/logs";
|
|
391
|
+
};
|
|
392
|
+
var loggingServiceMetricsUrl = function(env) {
|
|
393
|
+
if (env == "prod" /* production */ ) {
|
|
394
|
+
return "https://o11y.airwallex.com/airtracker/metrics";
|
|
395
|
+
}
|
|
396
|
+
if (env == "demo" /* demo */ ) {
|
|
397
|
+
return "https://o11y-demo.airwallex.com/airtracker/metrics";
|
|
398
|
+
}
|
|
399
|
+
return "https://o11y-staging.airwallex.com/airtracker/metrics";
|
|
400
|
+
};
|
|
401
|
+
// src/util/index.ts
|
|
402
|
+
var generateUId = function() {
|
|
403
|
+
var deviceId = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
404
|
+
var r = Math.random() * 16 | 0;
|
|
405
|
+
var v = c === "x" ? r : r & 3 | 8;
|
|
406
|
+
return v.toString(16);
|
|
407
|
+
});
|
|
408
|
+
return deviceId;
|
|
409
|
+
};
|
|
410
|
+
var getMFEName = function(airTracker2) {
|
|
411
|
+
var _location_pathname_split, _location_pathname, _location;
|
|
412
|
+
if (airTracker2.config.getMFEName) {
|
|
413
|
+
return airTracker2.config.getMFEName();
|
|
414
|
+
}
|
|
415
|
+
return ((_location = location) === null || _location === void 0 ? void 0 : (_location_pathname = _location.pathname) === null || _location_pathname === void 0 ? void 0 : (_location_pathname_split = _location_pathname.split("/")) === null || _location_pathname_split === void 0 ? void 0 : _location_pathname_split[2]) || "unknown";
|
|
416
|
+
};
|
|
417
|
+
var getSessionId = function() {
|
|
418
|
+
try {
|
|
419
|
+
var sessionId = window.sessionStorage.getItem(SESSION_ID_STORAGE_KEY);
|
|
420
|
+
if (!sessionId) {
|
|
421
|
+
sessionId = generateUId();
|
|
422
|
+
window.sessionStorage.setItem(SESSION_ID_STORAGE_KEY, sessionId);
|
|
423
|
+
}
|
|
424
|
+
return sessionId;
|
|
425
|
+
} catch (e) {
|
|
426
|
+
return generateUId();
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
var getDeviceId = function() {
|
|
430
|
+
try {
|
|
431
|
+
var deviceId = window.localStorage.getItem(DEVICE_ID_STORAGE_KEY);
|
|
432
|
+
if (!deviceId) {
|
|
433
|
+
deviceId = generateUId();
|
|
434
|
+
window.localStorage.setItem(DEVICE_ID_STORAGE_KEY, deviceId);
|
|
435
|
+
}
|
|
436
|
+
return deviceId;
|
|
437
|
+
} catch (e) {}
|
|
438
|
+
};
|
|
439
|
+
var getRiskDeviceId = function() {
|
|
440
|
+
try {
|
|
441
|
+
var deviceId = window.localStorage.getItem(RISK_DEVICE_ID_STORAGE_KEY);
|
|
442
|
+
return deviceId || void 0;
|
|
443
|
+
} catch (e) {}
|
|
444
|
+
};
|
|
445
|
+
var getNetworkType = function() {
|
|
446
|
+
var _navigator;
|
|
447
|
+
var netType = "";
|
|
448
|
+
var arr = navigator.userAgent.match(/NetType\/(\w+)/);
|
|
449
|
+
if (arr) {
|
|
450
|
+
var ref;
|
|
451
|
+
ref = _sliced_to_array(arr, 2), netType = ref[1];
|
|
452
|
+
} else if ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.connection) {
|
|
453
|
+
var _navigator_connection, _navigator1, _navigator_connection1, _navigator2;
|
|
454
|
+
netType = ((_navigator1 = navigator) === null || _navigator1 === void 0 ? void 0 : (_navigator_connection = _navigator1.connection) === null || _navigator_connection === void 0 ? void 0 : _navigator_connection.effectiveType) || ((_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : (_navigator_connection1 = _navigator2.connection) === null || _navigator_connection1 === void 0 ? void 0 : _navigator_connection1.type);
|
|
455
|
+
}
|
|
456
|
+
if (!netType) {
|
|
457
|
+
netType = "unknown";
|
|
458
|
+
}
|
|
459
|
+
return parseNetType(netType);
|
|
460
|
+
};
|
|
461
|
+
var parseNetType = function(net) {
|
|
462
|
+
net = String(net).toLowerCase();
|
|
463
|
+
if (net.indexOf("4g") >= 0) return "net4g" /* net4g */ ;
|
|
464
|
+
if (net.indexOf("wifi") >= 0) return "wifi" /* wifi */ ;
|
|
465
|
+
if (net.indexOf("5g") >= 0) return "net5g" /* net5g */ ;
|
|
466
|
+
if (net.indexOf("3g") >= 0) return "net3g" /* net3g */ ;
|
|
467
|
+
if (net.indexOf("2g") >= 0) return "net2g" /* net2g */ ;
|
|
468
|
+
return "unknown" /* unknown */ ;
|
|
469
|
+
};
|
|
470
|
+
var canUseResourceTiming = function canUseResourceTiming() {
|
|
471
|
+
return typeof window.performance !== "undefined" && typeof window.performance.clearResourceTimings === "function" && typeof window.performance.getEntriesByType === "function" && typeof window.performance.now === "function";
|
|
472
|
+
};
|
|
473
|
+
var formatUrl = function(url) {
|
|
474
|
+
if (typeof url === "string") {
|
|
475
|
+
var hostUrl = url.split("?")[0] || "";
|
|
476
|
+
return hostUrl.slice(0, 200);
|
|
477
|
+
}
|
|
478
|
+
return url;
|
|
479
|
+
};
|
|
480
|
+
var getQueryString = function(url) {
|
|
481
|
+
if (typeof url === "string") {
|
|
482
|
+
return url.split("?")[1] || "";
|
|
483
|
+
}
|
|
484
|
+
return url;
|
|
485
|
+
};
|
|
486
|
+
var urlIsHttps = function(url) {
|
|
487
|
+
var isHostProtocol = typeof url === "string" && url.startsWith("//");
|
|
488
|
+
return isHostProtocol ? typeof location !== "undefined" && location.protocol === "https:" : /^https/.test(url);
|
|
489
|
+
};
|
|
490
|
+
var getReportVal = function(rawVal, isDefaultByString) {
|
|
491
|
+
if (typeof rawVal === "number") {
|
|
492
|
+
return rawVal;
|
|
493
|
+
}
|
|
494
|
+
if (typeof rawVal === "string") {
|
|
495
|
+
return rawVal;
|
|
496
|
+
}
|
|
497
|
+
return isDefaultByString ? "" /* string */ : -1 /* number */ ;
|
|
498
|
+
};
|
|
499
|
+
var checkIfInWhiteList = function(url, airTracker2) {
|
|
500
|
+
var _airTracker2_config_assetSpeedMonitoringWhiteListByMFE;
|
|
501
|
+
var isInWhiteList = false;
|
|
502
|
+
if (!airTracker2.config.isWebappContainer) {
|
|
503
|
+
isInWhiteList = checkIfInWhiteListHelper(url, airTracker2.config.assetSpeedMonitoringWhiteList);
|
|
504
|
+
return isInWhiteList;
|
|
505
|
+
}
|
|
506
|
+
var MFEName = getMFEName(airTracker2);
|
|
507
|
+
return isInWhiteList || checkIfInWhiteListHelper(url, (_airTracker2_config_assetSpeedMonitoringWhiteListByMFE = airTracker2.config.assetSpeedMonitoringWhiteListByMFE) === null || _airTracker2_config_assetSpeedMonitoringWhiteListByMFE === void 0 ? void 0 : _airTracker2_config_assetSpeedMonitoringWhiteListByMFE[MFEName]);
|
|
508
|
+
};
|
|
509
|
+
var checkIfInWhiteListHelper = function(url, whiteList) {
|
|
510
|
+
if (!(whiteList === null || whiteList === void 0 ? void 0 : whiteList.length)) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
for(var i = 0; i < whiteList.length; i++){
|
|
514
|
+
var cur = whiteList[i];
|
|
515
|
+
if (_instanceof(cur, RegExp) && cur.test(url)) {
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
if (typeof cur == "string" && url.includes(cur)) {
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return false;
|
|
523
|
+
};
|
|
524
|
+
var roundSubtract = function(a, b) {
|
|
525
|
+
var precision = 100;
|
|
526
|
+
return Math.round((a - b) * precision) / precision;
|
|
527
|
+
};
|
|
528
|
+
// src/pipes/send.ts
|
|
529
|
+
var sendNormalLogPipe = function(airTracker2) {
|
|
530
|
+
return function(logs) {
|
|
531
|
+
var _airTracker2_MFECommonDataMap, _navigator;
|
|
532
|
+
var MFEName = getMFEName(airTracker2);
|
|
533
|
+
var commonData = airTracker2.config.isWebappContainer ? _object_spread({}, airTracker2.commonData || {}, ((_airTracker2_MFECommonDataMap = airTracker2.MFECommonDataMap) === null || _airTracker2_MFECommonDataMap === void 0 ? void 0 : _airTracker2_MFECommonDataMap[MFEName]) || {}) : airTracker2.commonData;
|
|
534
|
+
var data = Array.isArray(logs) ? logs : [
|
|
535
|
+
logs
|
|
536
|
+
];
|
|
537
|
+
if (data.length === 0) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
var finalLog = {
|
|
541
|
+
commonData: commonData,
|
|
542
|
+
data: data
|
|
543
|
+
};
|
|
544
|
+
var dataBody = safeStringify(finalLog);
|
|
545
|
+
var sendOptions = {
|
|
546
|
+
method: "post",
|
|
547
|
+
url: loggingServiceUrl(airTracker2.commonData.env),
|
|
548
|
+
data: dataBody
|
|
549
|
+
};
|
|
550
|
+
if (typeof ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.sendBeacon) === "function") {
|
|
551
|
+
var success = navigator.sendBeacon(sendOptions.url, dataBody);
|
|
552
|
+
if (!success) {
|
|
553
|
+
request(sendOptions);
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
request(sendOptions);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
var sendMetricsLogPipe = function(airTracker2) {
|
|
561
|
+
return function(logs) {
|
|
562
|
+
var _airTracker2_MFECommonDataMap, _navigator;
|
|
563
|
+
var MFEName = getMFEName(airTracker2);
|
|
564
|
+
var commonData = airTracker2.config.isWebappContainer ? _object_spread({}, airTracker2.commonData || {}, ((_airTracker2_MFECommonDataMap = airTracker2.MFECommonDataMap) === null || _airTracker2_MFECommonDataMap === void 0 ? void 0 : _airTracker2_MFECommonDataMap[MFEName]) || {}) : airTracker2.commonData;
|
|
565
|
+
var finalLog = {
|
|
566
|
+
commonData: commonData,
|
|
567
|
+
data: Array.isArray(logs) ? logs : [
|
|
568
|
+
logs
|
|
569
|
+
]
|
|
570
|
+
};
|
|
571
|
+
var dataBody = safeStringify(finalLog);
|
|
572
|
+
var sendOptions = {
|
|
573
|
+
method: "post",
|
|
574
|
+
url: loggingServiceMetricsUrl(airTracker2.commonData.env),
|
|
575
|
+
data: dataBody
|
|
576
|
+
};
|
|
577
|
+
if (typeof ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.sendBeacon) === "function") {
|
|
578
|
+
var success = navigator.sendBeacon(sendOptions.url, dataBody);
|
|
579
|
+
if (!success) {
|
|
580
|
+
request(sendOptions);
|
|
581
|
+
}
|
|
582
|
+
} else {
|
|
583
|
+
request(sendOptions);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
};
|
|
587
|
+
// src/pipes/throttle.ts
|
|
588
|
+
var throttlePipe = function(airTracker2, maxLength) {
|
|
589
|
+
var timer;
|
|
590
|
+
var retainedLogs = [];
|
|
591
|
+
var config = airTracker2.config;
|
|
592
|
+
window.addEventListener("beforeunload", function() {
|
|
593
|
+
if (retainedLogs.length > 0) {
|
|
594
|
+
airTracker2.immediateSendPipe(retainedLogs.splice(0, retainedLogs.length));
|
|
595
|
+
timer && clearTimeout(timer);
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
return function(log, resolve) {
|
|
599
|
+
retainedLogs.push(log);
|
|
600
|
+
airTracker2.lifeCycle.on(lifeCycleEventName.onCommonUpdated, function() {
|
|
601
|
+
if (retainedLogs.length > 0) {
|
|
602
|
+
resolve === null || resolve === void 0 ? void 0 : resolve(retainedLogs.splice(0, retainedLogs.length));
|
|
603
|
+
airTracker2.lifeCycle.remove(lifeCycleEventName.onCommonUpdated);
|
|
604
|
+
timer && clearTimeout(timer);
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
if (maxLength && retainedLogs.length >= maxLength) {
|
|
608
|
+
resolve === null || resolve === void 0 ? void 0 : resolve(retainedLogs.splice(0, retainedLogs.length));
|
|
609
|
+
timer && clearTimeout(timer);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
timer && clearTimeout(timer);
|
|
613
|
+
timer = setTimeout(function() {
|
|
614
|
+
timer = null;
|
|
615
|
+
if (retainedLogs.length > 0) {
|
|
616
|
+
resolve === null || resolve === void 0 ? void 0 : resolve(retainedLogs.splice(0, retainedLogs.length));
|
|
617
|
+
airTracker2.lifeCycle.remove(lifeCycleEventName.onCommonUpdated);
|
|
618
|
+
}
|
|
619
|
+
}, config.delay);
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
// src/pipes/errorRepeatLimit.ts
|
|
623
|
+
var errorLogLimitPipe = function(airTracker2) {
|
|
624
|
+
var errorLogMap = {};
|
|
625
|
+
return function(logs, resolve) {
|
|
626
|
+
var maxNum = typeof airTracker2.config.errorRepeatTime === "number" ? airTracker2.config.errorRepeatTime : 5;
|
|
627
|
+
if (maxNum === 0) {
|
|
628
|
+
return resolve === null || resolve === void 0 ? void 0 : resolve(logs);
|
|
629
|
+
}
|
|
630
|
+
resolve === null || resolve === void 0 ? void 0 : resolve(logs.filter(function(log) {
|
|
631
|
+
if (log.severity == "autoDetectError" /* AUTO_DETECT_ERROR */ ) {
|
|
632
|
+
errorLogMap[log.error] = errorLogMap[log.error] || 0;
|
|
633
|
+
errorLogMap[log.error] += 1;
|
|
634
|
+
if (errorLogMap[log.error] > maxNum) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
return true;
|
|
640
|
+
}));
|
|
641
|
+
};
|
|
642
|
+
};
|
|
643
|
+
// src/pipes/index.ts
|
|
644
|
+
var noop = function() {};
|
|
645
|
+
var createPipeline = function(pipeArr) {
|
|
646
|
+
if (!pipeArr || !pipeArr.reduce || !pipeArr.length) {
|
|
647
|
+
throw new TypeError("createPipeline need at least one function param");
|
|
648
|
+
}
|
|
649
|
+
if (pipeArr.length === 1) {
|
|
650
|
+
return function(msg, resolve) {
|
|
651
|
+
pipeArr[0](msg, resolve || noop);
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
return pipeArr.reduce(function(prePipe, pipe) {
|
|
655
|
+
return function(msg) {
|
|
656
|
+
var nextPipe = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
657
|
+
return prePipe(msg, function(msg2) {
|
|
658
|
+
return pipe === null || pipe === void 0 ? void 0 : pipe(msg2, nextPipe);
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
// src/util/eventEmitter.ts
|
|
664
|
+
var EventEmitter = /*#__PURE__*/ function() {
|
|
665
|
+
function EventEmitter() {
|
|
666
|
+
var _this = this;
|
|
667
|
+
_class_call_check(this, EventEmitter);
|
|
668
|
+
this.emit = function(name, data) {
|
|
669
|
+
if (!_this) return;
|
|
670
|
+
var events = _this.eventsList[name];
|
|
671
|
+
var handler;
|
|
672
|
+
if (events === null || events === void 0 ? void 0 : events.length) {
|
|
673
|
+
events = events.slice();
|
|
674
|
+
for(var i = 0; i < events.length; i++){
|
|
675
|
+
handler = events[i];
|
|
676
|
+
try {
|
|
677
|
+
var result = handler.callback.apply(_this, [
|
|
678
|
+
data
|
|
679
|
+
]);
|
|
680
|
+
if (1 === handler.type) {
|
|
681
|
+
_this.remove(name, handler.callback);
|
|
682
|
+
}
|
|
683
|
+
if (false === result) {
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
} catch (e) {
|
|
687
|
+
throw e;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return _this;
|
|
692
|
+
};
|
|
693
|
+
this.eventsList = {};
|
|
694
|
+
}
|
|
695
|
+
_create_class(EventEmitter, [
|
|
696
|
+
{
|
|
697
|
+
key: "indexOf",
|
|
698
|
+
value: function indexOf(array, value) {
|
|
699
|
+
for(var i = 0; i < array.length; i++){
|
|
700
|
+
if (array[i].callback === value) {
|
|
701
|
+
return i;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return -1;
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
key: "on",
|
|
709
|
+
value: function on(name, callback) {
|
|
710
|
+
var type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
|
|
711
|
+
if (!this) return;
|
|
712
|
+
var events = this.eventsList[name];
|
|
713
|
+
if (!events) {
|
|
714
|
+
this.eventsList[name] = [];
|
|
715
|
+
events = this.eventsList[name];
|
|
716
|
+
}
|
|
717
|
+
if (this.indexOf(events, callback) === -1) {
|
|
718
|
+
var handler = {
|
|
719
|
+
name: name,
|
|
720
|
+
type: type || 0,
|
|
721
|
+
callback: callback
|
|
722
|
+
};
|
|
723
|
+
events.push(handler);
|
|
724
|
+
return this;
|
|
725
|
+
}
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
key: "one",
|
|
731
|
+
value: function one(name, callback) {
|
|
732
|
+
this.on(name, callback, 1);
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
key: "remove",
|
|
737
|
+
value: function remove(name, callback) {
|
|
738
|
+
if (!this) return;
|
|
739
|
+
var events = this.eventsList[name];
|
|
740
|
+
if (!events) {
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
if (!callback) {
|
|
744
|
+
try {
|
|
745
|
+
delete this.eventsList[name];
|
|
746
|
+
} catch (e) {}
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
if (events.length) {
|
|
750
|
+
var index = this.indexOf(events, callback);
|
|
751
|
+
events.splice(index, 1);
|
|
752
|
+
}
|
|
753
|
+
return this;
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
key: "clear",
|
|
758
|
+
value: function clear() {
|
|
759
|
+
this.eventsList = {};
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
]);
|
|
763
|
+
return EventEmitter;
|
|
764
|
+
}();
|
|
765
|
+
// src/interface/plugins.ts
|
|
766
|
+
var AirTrackerPlugin = /*#__PURE__*/ function() {
|
|
767
|
+
function AirTrackerPlugin(pluginOption) {
|
|
768
|
+
_class_call_check(this, AirTrackerPlugin);
|
|
769
|
+
this.name = "";
|
|
770
|
+
// initiation flag
|
|
771
|
+
this.isInit = false;
|
|
772
|
+
this.name = pluginOption.name;
|
|
773
|
+
this.option = pluginOption;
|
|
774
|
+
}
|
|
775
|
+
_create_class(AirTrackerPlugin, [
|
|
776
|
+
{
|
|
777
|
+
key: "patch",
|
|
778
|
+
value: function patch(airTracker2) {
|
|
779
|
+
if (!this.isInit) {
|
|
780
|
+
var _this_option_setUp, _this_option;
|
|
781
|
+
this.isInit = true;
|
|
782
|
+
(_this_option = this.option) === null || _this_option === void 0 ? void 0 : (_this_option_setUp = _this_option.setUp) === null || _this_option_setUp === void 0 ? void 0 : _this_option_setUp.call(this.option, airTracker2);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
key: "uninstall",
|
|
788
|
+
value: function uninstall() {
|
|
789
|
+
var _this_option_destroy, _this_option;
|
|
790
|
+
(_this_option = this.option) === null || _this_option === void 0 ? void 0 : (_this_option_destroy = _this_option.destroy) === null || _this_option_destroy === void 0 ? void 0 : _this_option_destroy.apply(this);
|
|
791
|
+
this.isInit = false;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
]);
|
|
795
|
+
return AirTrackerPlugin;
|
|
796
|
+
}();
|
|
797
|
+
// src/plugins/onErrorPlugin.ts
|
|
798
|
+
var airTracker;
|
|
799
|
+
var onError = function(event) {
|
|
800
|
+
var errString = "".concat(safeStringify(event.message) || "", " @ (").concat(safeStringify(event.filename) || "", ":").concat(event.lineno || 0, ":").concat(event.colno || 0, ")\n").concat(safeStringify(event.error || ""));
|
|
801
|
+
airTracker.normalLogPipeLine({
|
|
802
|
+
severity: "autoDetectError" /* AUTO_DETECT_ERROR */ ,
|
|
803
|
+
eventName: "windowOnError" /* windowOnError */ ,
|
|
804
|
+
extraInfo: {
|
|
805
|
+
error: errString
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
var unhandledrejectionHandler = function(event) {
|
|
810
|
+
var reason = event && safeStringify(event.reason);
|
|
811
|
+
airTracker.normalLogPipeLine({
|
|
812
|
+
severity: "autoDetectError" /* AUTO_DETECT_ERROR */ ,
|
|
813
|
+
eventName: "promiseError" /* promiseError */ ,
|
|
814
|
+
extraInfo: {
|
|
815
|
+
error: reason
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
};
|
|
819
|
+
var errorHandler = function(event) {
|
|
820
|
+
var target = (event === null || event === void 0 ? void 0 : event.target) || (event === null || event === void 0 ? void 0 : event.srcElement);
|
|
821
|
+
if (!target) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
var url = (target === null || target === void 0 ? void 0 : target.src) || (target === null || target === void 0 ? void 0 : target.href);
|
|
825
|
+
var tagName = target.tagName;
|
|
826
|
+
var staticFileType = "unknown" /* unknown */ ;
|
|
827
|
+
if (typeof url === "string" && tagName) {
|
|
828
|
+
if (window.location.href.indexOf(url) > -1) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (/\.js$/.test(url)) {
|
|
832
|
+
staticFileType = "script" /* script */ ;
|
|
833
|
+
} else if (/\.css$/.test(url)) {
|
|
834
|
+
staticFileType = "css" /* css */ ;
|
|
835
|
+
} else {
|
|
836
|
+
switch(tagName.toLowerCase()){
|
|
837
|
+
case "script":
|
|
838
|
+
staticFileType = "script" /* script */ ;
|
|
839
|
+
break;
|
|
840
|
+
case "link":
|
|
841
|
+
staticFileType = "css" /* css */ ;
|
|
842
|
+
break;
|
|
843
|
+
case "img":
|
|
844
|
+
staticFileType = "image" /* img */ ;
|
|
845
|
+
break;
|
|
846
|
+
case "audio":
|
|
847
|
+
case "video":
|
|
848
|
+
staticFileType = "media" /* media */ ;
|
|
849
|
+
break;
|
|
850
|
+
default:
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
airTracker.normalLogPipeLine({
|
|
855
|
+
severity: "autoDetectError" /* AUTO_DETECT_ERROR */ ,
|
|
856
|
+
eventName: "staticFileLoadError" /* staticFileLoadError */ ,
|
|
857
|
+
extraInfo: {
|
|
858
|
+
staticFileType: staticFileType,
|
|
859
|
+
error: "".concat(tagName, " load fail: ").concat(url)
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var errorDetectionPlugin = new AirTrackerPlugin({
|
|
865
|
+
name: "errorDetectionPlugin",
|
|
866
|
+
setUp: function(airTrackerInst) {
|
|
867
|
+
airTracker = airTrackerInst;
|
|
868
|
+
window.addEventListener("error", onError);
|
|
869
|
+
window.addEventListener("unhandledrejection", unhandledrejectionHandler);
|
|
870
|
+
window.document.addEventListener("error", errorHandler, true);
|
|
871
|
+
},
|
|
872
|
+
destroy: function() {
|
|
873
|
+
window.removeEventListener("unhandledrejection", unhandledrejectionHandler);
|
|
874
|
+
window.document.removeEventListener("error", errorHandler, true);
|
|
875
|
+
window.removeEventListener("error", onError);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
// src/plugins/assetsSpeedPlugin.ts
|
|
879
|
+
var ASSETS_INITIATOR_TYPE = [
|
|
880
|
+
"img",
|
|
881
|
+
"css",
|
|
882
|
+
"script",
|
|
883
|
+
"link",
|
|
884
|
+
"audio",
|
|
885
|
+
"video",
|
|
886
|
+
"iframe"
|
|
887
|
+
];
|
|
888
|
+
var COLLECTED_ENTRY_TYPE = "resource";
|
|
889
|
+
var generateSpeedLog = function(entry) {
|
|
890
|
+
var resourceURl = entry.name;
|
|
891
|
+
return {
|
|
892
|
+
url: formatUrl(resourceURl),
|
|
893
|
+
method: "get",
|
|
894
|
+
// duration = redirect + DNS + CONNECTION + request + response
|
|
895
|
+
duration: Number(entry.duration.toFixed(2)),
|
|
896
|
+
// time it takes to load
|
|
897
|
+
type: "static",
|
|
898
|
+
isHttps: urlIsHttps(resourceURl),
|
|
899
|
+
urlQuery: getQueryString(resourceURl),
|
|
900
|
+
domainLookup: getReportVal(entry.domainLookupEnd - entry.domainLookupStart),
|
|
901
|
+
connectTime: getReportVal(entry.connectEnd - entry.connectStart)
|
|
902
|
+
};
|
|
903
|
+
};
|
|
904
|
+
var publishSpeedLogs = function(entries, airTracker2) {
|
|
905
|
+
for(var i = 0, l = entries.length; i < l; i++){
|
|
906
|
+
var entry = entries[i];
|
|
907
|
+
if (ASSETS_INITIATOR_TYPE.indexOf(entry.initiatorType) !== -1 && checkIfInWhiteList(entry.name, airTracker2)) {
|
|
908
|
+
airTracker2.normalLogPipeLine({
|
|
909
|
+
severity: "performance" /* PERFORMANCE */ ,
|
|
910
|
+
eventName: "assets_speed" /* ASSETS_SPEED */ ,
|
|
911
|
+
extraInfo: {
|
|
912
|
+
log: generateSpeedLog(entry)
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
var interval;
|
|
919
|
+
var observer;
|
|
920
|
+
var assetSpeedPlugin = new AirTrackerPlugin({
|
|
921
|
+
name: "assetsSpeedPlugin",
|
|
922
|
+
setUp: function(airTracker2) {
|
|
923
|
+
if (!canUseResourceTiming()) return;
|
|
924
|
+
var collectCur = 0;
|
|
925
|
+
window.performance.onresourcetimingbufferfull = function() {
|
|
926
|
+
collectCur = 0;
|
|
927
|
+
window.performance.clearResourceTimings();
|
|
928
|
+
};
|
|
929
|
+
if (typeof window.PerformanceObserver === "function") {
|
|
930
|
+
publishSpeedLogs(window.performance.getEntriesByType(COLLECTED_ENTRY_TYPE), airTracker2);
|
|
931
|
+
observer = new window.PerformanceObserver(function(list) {
|
|
932
|
+
publishSpeedLogs(list.getEntries(), airTracker2);
|
|
933
|
+
});
|
|
934
|
+
observer.observe({
|
|
935
|
+
entryTypes: [
|
|
936
|
+
COLLECTED_ENTRY_TYPE
|
|
937
|
+
]
|
|
938
|
+
});
|
|
939
|
+
} else {
|
|
940
|
+
interval = setInterval(function() {
|
|
941
|
+
var allEntries = window.performance.getEntriesByType(COLLECTED_ENTRY_TYPE);
|
|
942
|
+
var collectEntries = allEntries.slice(collectCur);
|
|
943
|
+
collectCur = allEntries.length;
|
|
944
|
+
publishSpeedLogs(collectEntries, airTracker2);
|
|
945
|
+
}, 3e3);
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
destroy: function() {
|
|
949
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
950
|
+
interval && clearInterval(interval);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
// src/plugins/onPageChangePlugin.ts
|
|
954
|
+
var observer2;
|
|
955
|
+
var onPageChangePlugin = new AirTrackerPlugin({
|
|
956
|
+
name: "onPageChangePlugin",
|
|
957
|
+
setUp: /*#__PURE__*/ function() {
|
|
958
|
+
var _ref = _async_to_generator(function(airTracker2) {
|
|
959
|
+
var _location, previousUrl, body, sendOnPageChangeEvent, config;
|
|
960
|
+
return _ts_generator(this, function(_state) {
|
|
961
|
+
previousUrl = (_location = location) === null || _location === void 0 ? void 0 : _location.href;
|
|
962
|
+
body = document.querySelector("body");
|
|
963
|
+
sendOnPageChangeEvent = function(param) {
|
|
964
|
+
var prevHref = param.prevHref;
|
|
965
|
+
var _location, _location1, _location2, _location3, _location4;
|
|
966
|
+
airTracker2.normalLogPipeLine({
|
|
967
|
+
severity: "autoDetectEvent" /* AUTO_DETECT_EVENT */ ,
|
|
968
|
+
eventName: "onPageChange" /* onPageChange */ ,
|
|
969
|
+
extraInfo: {
|
|
970
|
+
prevHref: prevHref,
|
|
971
|
+
href: ((_location = location) === null || _location === void 0 ? void 0 : _location.href) || "",
|
|
972
|
+
hostname: (_location1 = location) === null || _location1 === void 0 ? void 0 : _location1.hostname,
|
|
973
|
+
pathName: (_location2 = location) === null || _location2 === void 0 ? void 0 : _location2.pathname,
|
|
974
|
+
protocol: (_location3 = location) === null || _location3 === void 0 ? void 0 : _location3.protocol,
|
|
975
|
+
search: (_location4 = location) === null || _location4 === void 0 ? void 0 : _location4.search
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
};
|
|
979
|
+
sendOnPageChangeEvent({
|
|
980
|
+
prevHref: ""
|
|
981
|
+
});
|
|
982
|
+
observer2 = new MutationObserver(function() {
|
|
983
|
+
if (location.href !== previousUrl) {
|
|
984
|
+
var tempPreviousUrl = previousUrl;
|
|
985
|
+
previousUrl = location.href;
|
|
986
|
+
sendOnPageChangeEvent({
|
|
987
|
+
prevHref: tempPreviousUrl
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
config = {
|
|
992
|
+
subtree: true,
|
|
993
|
+
childList: true
|
|
994
|
+
};
|
|
995
|
+
observer2.observe(body || document, config);
|
|
996
|
+
return [
|
|
997
|
+
2
|
|
998
|
+
];
|
|
999
|
+
});
|
|
1000
|
+
});
|
|
1001
|
+
return function(airTracker2) {
|
|
1002
|
+
return _ref.apply(this, arguments);
|
|
1003
|
+
};
|
|
1004
|
+
}(),
|
|
1005
|
+
destroy: function() {
|
|
1006
|
+
observer2 === null || observer2 === void 0 ? void 0 : observer2.disconnect();
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
// src/plugins/pageRetentionPlugin.ts
|
|
1010
|
+
var observer3;
|
|
1011
|
+
var onPageRetentionPlugin = new AirTrackerPlugin({
|
|
1012
|
+
name: "onPageRetentionPlugin",
|
|
1013
|
+
setUp: /*#__PURE__*/ function() {
|
|
1014
|
+
var _ref = _async_to_generator(function(airTracker2) {
|
|
1015
|
+
var _location, previousUrl, body, enterPageTimeStamp, startRecording, sendPageRetentionEvent, config;
|
|
1016
|
+
return _ts_generator(this, function(_state) {
|
|
1017
|
+
if (typeof document.visibilityState === "undefined") {
|
|
1018
|
+
return [
|
|
1019
|
+
2
|
|
1020
|
+
];
|
|
1021
|
+
}
|
|
1022
|
+
previousUrl = (_location = location) === null || _location === void 0 ? void 0 : _location.href;
|
|
1023
|
+
body = document.querySelector("body");
|
|
1024
|
+
startRecording = function() {
|
|
1025
|
+
enterPageTimeStamp = Date.now();
|
|
1026
|
+
};
|
|
1027
|
+
startRecording();
|
|
1028
|
+
document.addEventListener("visibilitychange", function() {
|
|
1029
|
+
if (document.visibilityState === "hidden") {
|
|
1030
|
+
sendPageRetentionEvent({
|
|
1031
|
+
href: location.href,
|
|
1032
|
+
leftReason: "visibilityChange" /* visibilityChange */
|
|
1033
|
+
});
|
|
1034
|
+
} else if (document.visibilityState === "visible") {
|
|
1035
|
+
startRecording();
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
window.addEventListener("beforeunload", function() {
|
|
1039
|
+
sendPageRetentionEvent({
|
|
1040
|
+
href: location.href,
|
|
1041
|
+
sendImmediate: true,
|
|
1042
|
+
leftReason: "pageClose" /* pageClose */
|
|
1043
|
+
});
|
|
1044
|
+
});
|
|
1045
|
+
sendPageRetentionEvent = function(param) {
|
|
1046
|
+
var href = param.href, sendImmediate = param.sendImmediate, leftReason = param.leftReason;
|
|
1047
|
+
if (!enterPageTimeStamp) {
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
var duration = Date.now() - enterPageTimeStamp;
|
|
1051
|
+
if (duration === 0) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
enterPageTimeStamp = void 0;
|
|
1055
|
+
var payload = {
|
|
1056
|
+
severity: "autoDetectEvent" /* AUTO_DETECT_EVENT */ ,
|
|
1057
|
+
eventName: "onPageRetention" /* onPageRetention */ ,
|
|
1058
|
+
extraInfo: {
|
|
1059
|
+
href: href,
|
|
1060
|
+
duration: duration,
|
|
1061
|
+
leftReason: leftReason
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
if (sendImmediate) {
|
|
1065
|
+
airTracker2.ImmediatePipeline(payload);
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
airTracker2.normalLogPipeLine(payload);
|
|
1069
|
+
};
|
|
1070
|
+
observer3 = new MutationObserver(function() {
|
|
1071
|
+
if (location.href !== previousUrl) {
|
|
1072
|
+
var tempPreviousUrl = previousUrl;
|
|
1073
|
+
previousUrl = location.href;
|
|
1074
|
+
sendPageRetentionEvent({
|
|
1075
|
+
href: tempPreviousUrl,
|
|
1076
|
+
leftReason: "nextPage" /* nextPage */
|
|
1077
|
+
});
|
|
1078
|
+
startRecording();
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
config = {
|
|
1082
|
+
subtree: true,
|
|
1083
|
+
childList: true
|
|
1084
|
+
};
|
|
1085
|
+
observer3.observe(body || document, config);
|
|
1086
|
+
return [
|
|
1087
|
+
2
|
|
1088
|
+
];
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
return function(airTracker2) {
|
|
1092
|
+
return _ref.apply(this, arguments);
|
|
1093
|
+
};
|
|
1094
|
+
}(),
|
|
1095
|
+
destroy: function() {
|
|
1096
|
+
observer3 === null || observer3 === void 0 ? void 0 : observer3.disconnect();
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
// src/plugins/apiPerformancePlugin/utils.ts
|
|
1100
|
+
var generateRandomId = function() {
|
|
1101
|
+
return Date.now().toString(36) + Math.random().toString(36).substring(2, 15);
|
|
1102
|
+
};
|
|
1103
|
+
var checkIfInWhiteList2 = function(url, whiteList) {
|
|
1104
|
+
var defaultWhiteList = [
|
|
1105
|
+
/^https?:\/\/[^\/]*\.airwallex\.com($|\/)/
|
|
1106
|
+
];
|
|
1107
|
+
var defaultExclusionList = [
|
|
1108
|
+
/authenticate\/heartbeat/,
|
|
1109
|
+
/papluginlogs\/.*/,
|
|
1110
|
+
/airtracker\/.*/,
|
|
1111
|
+
/o11y(-staging|-demo)?\.airwallex\.com/,
|
|
1112
|
+
/\.(png|jpe?g|gif|svg|ico|webp|avif|css|js|json|woff2?|ttf|eot|map|txt|csv|xml)(\?.*)?(#.*)?$/i
|
|
1113
|
+
];
|
|
1114
|
+
if (defaultExclusionList.some(function(item) {
|
|
1115
|
+
return item.test(url);
|
|
1116
|
+
})) {
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
return checkIfInWhiteListHelper(url, whiteList || defaultWhiteList);
|
|
1120
|
+
};
|
|
1121
|
+
var findMainEntry = function(performanceItem) {
|
|
1122
|
+
var startTime = performanceItem.startTime, endTime = performanceItem.endTime, entries = performanceItem.entries;
|
|
1123
|
+
if (entries.length === 0) {
|
|
1124
|
+
return void 0;
|
|
1125
|
+
}
|
|
1126
|
+
if (entries.length === 1) {
|
|
1127
|
+
return entries[0];
|
|
1128
|
+
}
|
|
1129
|
+
var filteredEntries = entries.filter(function(entry) {
|
|
1130
|
+
return entry.startTime >= startTime && endTime && entry.responseEnd <= endTime;
|
|
1131
|
+
}).sort(function(a, b) {
|
|
1132
|
+
return a.startTime - b.startTime;
|
|
1133
|
+
});
|
|
1134
|
+
return filteredEntries === null || filteredEntries === void 0 ? void 0 : filteredEntries[0];
|
|
1135
|
+
};
|
|
1136
|
+
var round2Decimal = function(value) {
|
|
1137
|
+
return Math.round(value * 100) / 100;
|
|
1138
|
+
};
|
|
1139
|
+
var processPerformanceEntry = function(entry) {
|
|
1140
|
+
var startTime = entry.startTime, duration = entry.duration, responseStart = entry.responseStart, connectEnd = entry.connectEnd, connectStart = entry.connectStart, domainLookupEnd = entry.domainLookupEnd, domainLookupStart = entry.domainLookupStart, requestStart = entry.requestStart, secureConnectionStart = entry.secureConnectionStart, redirectEnd = entry.redirectEnd, redirectStart = entry.redirectStart, responseStatus = entry.responseStatus, responseEnd = entry.responseEnd, encodedBodySize = entry.encodedBodySize, decodedBodySize = entry.decodedBodySize, transferSize = entry.transferSize, deliveryType = entry.deliveryType, initiatorType = entry.initiatorType;
|
|
1141
|
+
return {
|
|
1142
|
+
startTime: round2Decimal(startTime),
|
|
1143
|
+
totalDuration: round2Decimal(duration),
|
|
1144
|
+
timeToFirstByte: roundSubtract(responseStart, startTime),
|
|
1145
|
+
tcpDuration: roundSubtract(connectEnd, connectStart),
|
|
1146
|
+
dnsDuration: roundSubtract(domainLookupEnd, domainLookupStart),
|
|
1147
|
+
tlsDuration: roundSubtract(requestStart, secureConnectionStart),
|
|
1148
|
+
redirectDuration: roundSubtract(redirectEnd, redirectStart),
|
|
1149
|
+
responseDuration: roundSubtract(responseEnd, responseStart),
|
|
1150
|
+
encodeResponseSize: encodedBodySize,
|
|
1151
|
+
decodeResponseSize: decodedBodySize,
|
|
1152
|
+
transferSize: transferSize,
|
|
1153
|
+
deliveryType: deliveryType,
|
|
1154
|
+
statusCode: responseStatus,
|
|
1155
|
+
initiatorType: initiatorType
|
|
1156
|
+
};
|
|
1157
|
+
};
|
|
1158
|
+
var getPayload = function(performanceItem, extraInfo) {
|
|
1159
|
+
var url = performanceItem.url, method = performanceItem.method, errorType = performanceItem.errorType, errorDetail = performanceItem.errorDetail;
|
|
1160
|
+
var mainEntry = findMainEntry(performanceItem);
|
|
1161
|
+
var _ref = new URL(url, window.location.href), href = _ref.href, protocol = _ref.protocol;
|
|
1162
|
+
var payloadFromPerformanceEntry = mainEntry ? processPerformanceEntry(mainEntry) : {};
|
|
1163
|
+
var payload = {
|
|
1164
|
+
severity: "autoDetectEvent" /* AUTO_DETECT_EVENT */ ,
|
|
1165
|
+
eventName: "httpClientMetrics" /* httpClientMetrics */ ,
|
|
1166
|
+
extraInfo: _object_spread(_object_spread_props(_object_spread({
|
|
1167
|
+
httpUrl: href,
|
|
1168
|
+
method: method,
|
|
1169
|
+
scheme: protocol
|
|
1170
|
+
}, errorType && {
|
|
1171
|
+
errorType: errorType
|
|
1172
|
+
}, errorDetail && {
|
|
1173
|
+
errorDetail: errorDetail
|
|
1174
|
+
}, payloadFromPerformanceEntry), {
|
|
1175
|
+
// use injected response as fallback
|
|
1176
|
+
statusCode: (payloadFromPerformanceEntry === null || payloadFromPerformanceEntry === void 0 ? void 0 : payloadFromPerformanceEntry.statusCode) || (performanceItem === null || performanceItem === void 0 ? void 0 : performanceItem.responseStatus),
|
|
1177
|
+
startTime: (payloadFromPerformanceEntry === null || payloadFromPerformanceEntry === void 0 ? void 0 : payloadFromPerformanceEntry.startTime) || (performanceItem === null || performanceItem === void 0 ? void 0 : performanceItem.startTime),
|
|
1178
|
+
initiatorType: (payloadFromPerformanceEntry === null || payloadFromPerformanceEntry === void 0 ? void 0 : payloadFromPerformanceEntry.initiatorType) || (performanceItem === null || performanceItem === void 0 ? void 0 : performanceItem.initiatorType)
|
|
1179
|
+
}), extraInfo)
|
|
1180
|
+
};
|
|
1181
|
+
return payload;
|
|
1182
|
+
};
|
|
1183
|
+
var isGraphQLError = function(responseBody) {
|
|
1184
|
+
return(// Has data or errors at root level
|
|
1185
|
+
responseBody && (typeof responseBody === "undefined" ? "undefined" : _type_of(responseBody)) === "object" && "errors" in responseBody && // If errors exist, they should be an array with proper GraphQL error shape
|
|
1186
|
+
Array.isArray(responseBody.errors) && responseBody.errors.every(function(error) {
|
|
1187
|
+
return error && (typeof error === "undefined" ? "undefined" : _type_of(error)) === "object" && "message" in error;
|
|
1188
|
+
}));
|
|
1189
|
+
};
|
|
1190
|
+
// src/plugins/apiPerformancePlugin/type.ts
|
|
1191
|
+
var API_PERFORMANCE_QUEUE = "awx_airtracker_api_performance_queue";
|
|
1192
|
+
var API_PERFORMANCE_PLUGIN_LOADED = "awx_airtracker_api_performance_plugin_loaded";
|
|
1193
|
+
// src/plugins/apiPerformancePlugin/index.ts
|
|
1194
|
+
var OBSERVER_WAIT_TIME_MS = 300;
|
|
1195
|
+
var TIMEOUT_WAIT_TIME_MS = 1e4;
|
|
1196
|
+
var globalObject = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
1197
|
+
globalObject[API_PERFORMANCE_QUEUE] = globalObject[API_PERFORMANCE_QUEUE] || [];
|
|
1198
|
+
var handlePayloadAndSendLog = function(apiPerformanceItem, airTracker2, extraInfo) {
|
|
1199
|
+
setTimeout(function() {
|
|
1200
|
+
var payload = getPayload(apiPerformanceItem, extraInfo);
|
|
1201
|
+
airTracker2.observerPipeline(payload);
|
|
1202
|
+
globalObject[API_PERFORMANCE_QUEUE] = globalObject[API_PERFORMANCE_QUEUE].filter(function(item) {
|
|
1203
|
+
return item.id !== apiPerformanceItem.id;
|
|
1204
|
+
});
|
|
1205
|
+
}, OBSERVER_WAIT_TIME_MS);
|
|
1206
|
+
};
|
|
1207
|
+
var handleTimeout = function(requestId, airTracker2) {
|
|
1208
|
+
setTimeout(function() {
|
|
1209
|
+
var matchedApiPerformanceItem = globalObject[API_PERFORMANCE_QUEUE].find(function(item) {
|
|
1210
|
+
return item.id === requestId;
|
|
1211
|
+
});
|
|
1212
|
+
if (!matchedApiPerformanceItem) {
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
var payload = getPayload(matchedApiPerformanceItem, {
|
|
1216
|
+
exceptionType: "timeout-without-response"
|
|
1217
|
+
});
|
|
1218
|
+
airTracker2.observerPipeline(payload);
|
|
1219
|
+
globalObject[API_PERFORMANCE_QUEUE] = globalObject[API_PERFORMANCE_QUEUE].filter(function(item) {
|
|
1220
|
+
return item.id !== requestId;
|
|
1221
|
+
});
|
|
1222
|
+
}, TIMEOUT_WAIT_TIME_MS);
|
|
1223
|
+
};
|
|
1224
|
+
var injectXMLHttpRequest = function(airTracker2) {
|
|
1225
|
+
var originalOpen = XMLHttpRequest.prototype.open;
|
|
1226
|
+
var originalSend = XMLHttpRequest.prototype.send;
|
|
1227
|
+
XMLHttpRequest.prototype.open = function injectXMLHttpRequest(method, url, async, username, password) {
|
|
1228
|
+
try {
|
|
1229
|
+
var _airTracker2_config;
|
|
1230
|
+
var requestId = generateRandomId();
|
|
1231
|
+
this.__requestId = requestId;
|
|
1232
|
+
var urlString = _instanceof(url, URL) ? url.href : new URL(url, window.location.href).href;
|
|
1233
|
+
if (!checkIfInWhiteList2(urlString, (_airTracker2_config = airTracker2.config) === null || _airTracker2_config === void 0 ? void 0 : _airTracker2_config.enableRecordAPIPerformanceWhitelist)) {
|
|
1234
|
+
return originalOpen.call(this, method, url, async !== null && async !== void 0 ? async : true, username, password);
|
|
1235
|
+
}
|
|
1236
|
+
var apiPerformanceItem = {
|
|
1237
|
+
id: requestId,
|
|
1238
|
+
startTime: performance.now(),
|
|
1239
|
+
method: method,
|
|
1240
|
+
url: urlString,
|
|
1241
|
+
entries: [],
|
|
1242
|
+
initiatorType: "xmlhttprequest"
|
|
1243
|
+
};
|
|
1244
|
+
globalObject[API_PERFORMANCE_QUEUE].push(apiPerformanceItem);
|
|
1245
|
+
handleTimeout(requestId, airTracker2);
|
|
1246
|
+
return originalOpen.call(this, method, url, async !== null && async !== void 0 ? async : true, username, password);
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
airTracker2.normalLogPipeLine({
|
|
1249
|
+
severity: "warn" /* WARN */ ,
|
|
1250
|
+
eventName: "apiPerformancePluginError",
|
|
1251
|
+
extraInfo: {
|
|
1252
|
+
message: "Inject XHR open error",
|
|
1253
|
+
error: error
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
return originalOpen.call(this, method, url, async !== null && async !== void 0 ? async : true, username, password);
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
XMLHttpRequest.prototype.send = function sendXHRRequest() {
|
|
1260
|
+
var _this = this;
|
|
1261
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1262
|
+
args[_key] = arguments[_key];
|
|
1263
|
+
}
|
|
1264
|
+
try {
|
|
1265
|
+
var matchedApiPerformanceItem = globalObject[API_PERFORMANCE_QUEUE].find(function(item) {
|
|
1266
|
+
return item.id === _this.__requestId;
|
|
1267
|
+
});
|
|
1268
|
+
if (!matchedApiPerformanceItem) {
|
|
1269
|
+
return originalSend.apply(this, args);
|
|
1270
|
+
}
|
|
1271
|
+
var _this1 = this;
|
|
1272
|
+
this.addEventListener("loadend", /*#__PURE__*/ _async_to_generator(function() {
|
|
1273
|
+
var endTime, duration, status, responseBody, blob, parsedBody, e;
|
|
1274
|
+
return _ts_generator(this, function(_state) {
|
|
1275
|
+
switch(_state.label){
|
|
1276
|
+
case 0:
|
|
1277
|
+
endTime = performance.now();
|
|
1278
|
+
duration = endTime - matchedApiPerformanceItem.startTime;
|
|
1279
|
+
status = _this1.status;
|
|
1280
|
+
if (status === 0) {
|
|
1281
|
+
return [
|
|
1282
|
+
2
|
|
1283
|
+
];
|
|
1284
|
+
}
|
|
1285
|
+
matchedApiPerformanceItem.endTime = endTime;
|
|
1286
|
+
matchedApiPerformanceItem.duration = duration;
|
|
1287
|
+
matchedApiPerformanceItem.responseStatus = status;
|
|
1288
|
+
_state.label = 1;
|
|
1289
|
+
case 1:
|
|
1290
|
+
_state.trys.push([
|
|
1291
|
+
1,
|
|
1292
|
+
6,
|
|
1293
|
+
,
|
|
1294
|
+
7
|
|
1295
|
+
]);
|
|
1296
|
+
if (!(_this1.responseType === "" || _this1.responseType === "text")) return [
|
|
1297
|
+
3,
|
|
1298
|
+
2
|
|
1299
|
+
];
|
|
1300
|
+
responseBody = _this1.responseText;
|
|
1301
|
+
return [
|
|
1302
|
+
3,
|
|
1303
|
+
5
|
|
1304
|
+
];
|
|
1305
|
+
case 2:
|
|
1306
|
+
if (!(_this1.responseType === "json")) return [
|
|
1307
|
+
3,
|
|
1308
|
+
3
|
|
1309
|
+
];
|
|
1310
|
+
responseBody = _this1.response;
|
|
1311
|
+
return [
|
|
1312
|
+
3,
|
|
1313
|
+
5
|
|
1314
|
+
];
|
|
1315
|
+
case 3:
|
|
1316
|
+
if (!(_this1.responseType === "blob")) return [
|
|
1317
|
+
3,
|
|
1318
|
+
5
|
|
1319
|
+
];
|
|
1320
|
+
blob = _this1.response;
|
|
1321
|
+
if (!((blob === null || blob === void 0 ? void 0 : blob.type) === "application/json")) return [
|
|
1322
|
+
3,
|
|
1323
|
+
5
|
|
1324
|
+
];
|
|
1325
|
+
return [
|
|
1326
|
+
4,
|
|
1327
|
+
blob.text()
|
|
1328
|
+
];
|
|
1329
|
+
case 4:
|
|
1330
|
+
responseBody = _state.sent();
|
|
1331
|
+
_state.label = 5;
|
|
1332
|
+
case 5:
|
|
1333
|
+
parsedBody = responseBody && typeof responseBody === "string" ? JSON.parse(responseBody) : responseBody;
|
|
1334
|
+
if (parsedBody && isGraphQLError(parsedBody)) {
|
|
1335
|
+
matchedApiPerformanceItem.errorType = "graphqlError";
|
|
1336
|
+
matchedApiPerformanceItem.errorDetail = parsedBody.errors;
|
|
1337
|
+
}
|
|
1338
|
+
return [
|
|
1339
|
+
3,
|
|
1340
|
+
7
|
|
1341
|
+
];
|
|
1342
|
+
case 6:
|
|
1343
|
+
e = _state.sent();
|
|
1344
|
+
airTracker2.normalLogPipeLine({
|
|
1345
|
+
severity: "warn" /* WARN */ ,
|
|
1346
|
+
eventName: "apiPerformancePluginError",
|
|
1347
|
+
extraInfo: {
|
|
1348
|
+
message: "Parse response body error in XHR",
|
|
1349
|
+
url: matchedApiPerformanceItem === null || matchedApiPerformanceItem === void 0 ? void 0 : matchedApiPerformanceItem.url,
|
|
1350
|
+
error: e
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
return [
|
|
1354
|
+
3,
|
|
1355
|
+
7
|
|
1356
|
+
];
|
|
1357
|
+
case 7:
|
|
1358
|
+
handlePayloadAndSendLog(matchedApiPerformanceItem, airTracker2);
|
|
1359
|
+
return [
|
|
1360
|
+
2
|
|
1361
|
+
];
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
}));
|
|
1365
|
+
this.addEventListener("error", function() {
|
|
1366
|
+
handlePayloadAndSendLog(matchedApiPerformanceItem, airTracker2, {
|
|
1367
|
+
exceptionType: "network-error"
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
this.addEventListener("abort", function() {
|
|
1371
|
+
handlePayloadAndSendLog(matchedApiPerformanceItem, airTracker2, {
|
|
1372
|
+
exceptionType: "abort-error"
|
|
1373
|
+
});
|
|
1374
|
+
});
|
|
1375
|
+
this.addEventListener("timeout", function() {
|
|
1376
|
+
handlePayloadAndSendLog(matchedApiPerformanceItem, airTracker2, {
|
|
1377
|
+
exceptionType: "timeout-error"
|
|
1378
|
+
});
|
|
1379
|
+
});
|
|
1380
|
+
return originalSend.apply(this, args);
|
|
1381
|
+
} catch (error) {
|
|
1382
|
+
airTracker2.normalLogPipeLine({
|
|
1383
|
+
severity: "warn" /* WARN */ ,
|
|
1384
|
+
eventName: "apiPerformancePluginError",
|
|
1385
|
+
extraInfo: {
|
|
1386
|
+
message: "InjectXHR send error",
|
|
1387
|
+
error: error
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
throw error;
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
};
|
|
1394
|
+
var injectFetch = function(airTracker2) {
|
|
1395
|
+
var originalFetch = window.fetch;
|
|
1396
|
+
window.fetch = /*#__PURE__*/ _async_to_generator(function() {
|
|
1397
|
+
var _len, args, _key, _airTracker2_config, apiPerformanceItem, url, _this, startTime, id, response, endTime, clonedResponse, responseBody, error, error1, exceptionType;
|
|
1398
|
+
var _arguments = arguments;
|
|
1399
|
+
return _ts_generator(this, function(_state) {
|
|
1400
|
+
switch(_state.label){
|
|
1401
|
+
case 0:
|
|
1402
|
+
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1403
|
+
args[_key] = _arguments[_key];
|
|
1404
|
+
}
|
|
1405
|
+
url = new URL(_instanceof(args[0], Request) ? args[0].url : String(args[0]), window.location.href).href;
|
|
1406
|
+
if (!!checkIfInWhiteList2(url, (_airTracker2_config = airTracker2.config) === null || _airTracker2_config === void 0 ? void 0 : _airTracker2_config.enableRecordAPIPerformanceWhitelist)) return [
|
|
1407
|
+
3,
|
|
1408
|
+
2
|
|
1409
|
+
];
|
|
1410
|
+
return [
|
|
1411
|
+
4,
|
|
1412
|
+
originalFetch.apply(this, args)
|
|
1413
|
+
];
|
|
1414
|
+
case 1:
|
|
1415
|
+
return [
|
|
1416
|
+
2,
|
|
1417
|
+
_state.sent()
|
|
1418
|
+
];
|
|
1419
|
+
case 2:
|
|
1420
|
+
_state.trys.push([
|
|
1421
|
+
2,
|
|
1422
|
+
9,
|
|
1423
|
+
,
|
|
1424
|
+
10
|
|
1425
|
+
]);
|
|
1426
|
+
startTime = performance.now();
|
|
1427
|
+
id = generateRandomId();
|
|
1428
|
+
apiPerformanceItem = {
|
|
1429
|
+
id: id,
|
|
1430
|
+
startTime: startTime,
|
|
1431
|
+
method: ((_this = _instanceof(args[0], Request) ? args[0] : args[1]) === null || _this === void 0 ? void 0 : _this.method) || "GET",
|
|
1432
|
+
url: url,
|
|
1433
|
+
entries: [],
|
|
1434
|
+
initiatorType: "fetch"
|
|
1435
|
+
};
|
|
1436
|
+
globalObject[API_PERFORMANCE_QUEUE].push(apiPerformanceItem);
|
|
1437
|
+
handleTimeout(id, airTracker2);
|
|
1438
|
+
return [
|
|
1439
|
+
4,
|
|
1440
|
+
originalFetch.apply(this, args)
|
|
1441
|
+
];
|
|
1442
|
+
case 3:
|
|
1443
|
+
response = _state.sent();
|
|
1444
|
+
endTime = performance.now();
|
|
1445
|
+
apiPerformanceItem.endTime = endTime;
|
|
1446
|
+
apiPerformanceItem.duration = endTime - startTime;
|
|
1447
|
+
apiPerformanceItem.responseStatus = response.status;
|
|
1448
|
+
clonedResponse = response.clone();
|
|
1449
|
+
_state.label = 4;
|
|
1450
|
+
case 4:
|
|
1451
|
+
_state.trys.push([
|
|
1452
|
+
4,
|
|
1453
|
+
7,
|
|
1454
|
+
,
|
|
1455
|
+
8
|
|
1456
|
+
]);
|
|
1457
|
+
if (!clonedResponse.ok) return [
|
|
1458
|
+
3,
|
|
1459
|
+
6
|
|
1460
|
+
];
|
|
1461
|
+
return [
|
|
1462
|
+
4,
|
|
1463
|
+
clonedResponse.json()
|
|
1464
|
+
];
|
|
1465
|
+
case 5:
|
|
1466
|
+
responseBody = _state.sent();
|
|
1467
|
+
if (responseBody && isGraphQLError(responseBody)) {
|
|
1468
|
+
apiPerformanceItem.errorType = "graphqlError";
|
|
1469
|
+
apiPerformanceItem.errorDetail = responseBody.errors;
|
|
1470
|
+
}
|
|
1471
|
+
_state.label = 6;
|
|
1472
|
+
case 6:
|
|
1473
|
+
return [
|
|
1474
|
+
3,
|
|
1475
|
+
8
|
|
1476
|
+
];
|
|
1477
|
+
case 7:
|
|
1478
|
+
error = _state.sent();
|
|
1479
|
+
airTracker2.normalLogPipeLine({
|
|
1480
|
+
severity: "warn" /* WARN */ ,
|
|
1481
|
+
eventName: "apiPerformancePluginError",
|
|
1482
|
+
extraInfo: {
|
|
1483
|
+
message: "Parse response body error in fetch",
|
|
1484
|
+
url: apiPerformanceItem === null || apiPerformanceItem === void 0 ? void 0 : apiPerformanceItem.url,
|
|
1485
|
+
error: error
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
return [
|
|
1489
|
+
3,
|
|
1490
|
+
8
|
|
1491
|
+
];
|
|
1492
|
+
case 8:
|
|
1493
|
+
handlePayloadAndSendLog(apiPerformanceItem, airTracker2);
|
|
1494
|
+
return [
|
|
1495
|
+
2,
|
|
1496
|
+
response
|
|
1497
|
+
];
|
|
1498
|
+
case 9:
|
|
1499
|
+
error1 = _state.sent();
|
|
1500
|
+
if (apiPerformanceItem && apiPerformanceItem.id && globalObject[API_PERFORMANCE_QUEUE].find(function(item) {
|
|
1501
|
+
return item.id === (apiPerformanceItem === null || apiPerformanceItem === void 0 ? void 0 : apiPerformanceItem.id);
|
|
1502
|
+
})) {
|
|
1503
|
+
exceptionType = "fetch-error";
|
|
1504
|
+
if (_instanceof(error1, TypeError)) {
|
|
1505
|
+
exceptionType = "network-error";
|
|
1506
|
+
} else if (_instanceof(error1, DOMException) && error1.name === "AbortError") {
|
|
1507
|
+
exceptionType = "abort-error";
|
|
1508
|
+
}
|
|
1509
|
+
handlePayloadAndSendLog(apiPerformanceItem, airTracker2, {
|
|
1510
|
+
exceptionType: exceptionType
|
|
1511
|
+
});
|
|
1512
|
+
} else {
|
|
1513
|
+
airTracker2.normalLogPipeLine({
|
|
1514
|
+
severity: "warn" /* WARN */ ,
|
|
1515
|
+
eventName: "apiPerformancePluginError",
|
|
1516
|
+
extraInfo: {
|
|
1517
|
+
message: "Inject fetch error",
|
|
1518
|
+
error: error1
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
throw error1;
|
|
1523
|
+
case 10:
|
|
1524
|
+
return [
|
|
1525
|
+
2
|
|
1526
|
+
];
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
});
|
|
1530
|
+
};
|
|
1531
|
+
var setUpAPIPerformancePlugin = function(airTracker2) {
|
|
1532
|
+
var _window;
|
|
1533
|
+
injectXMLHttpRequest(airTracker2);
|
|
1534
|
+
injectFetch(airTracker2);
|
|
1535
|
+
if ((_window = window) === null || _window === void 0 ? void 0 : _window.PerformanceObserver) {
|
|
1536
|
+
var observer4 = new window.PerformanceObserver(function(list) {
|
|
1537
|
+
var entries = list.getEntries();
|
|
1538
|
+
entries.forEach(function(entry) {
|
|
1539
|
+
var resourceEntry = entry;
|
|
1540
|
+
if (resourceEntry.initiatorType === "fetch" || resourceEntry.initiatorType === "xmlhttprequest") {
|
|
1541
|
+
var items = globalObject[API_PERFORMANCE_QUEUE].filter(function(item) {
|
|
1542
|
+
return item.url === resourceEntry.name;
|
|
1543
|
+
});
|
|
1544
|
+
items.forEach(function(item) {
|
|
1545
|
+
item.entries.push(resourceEntry);
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
});
|
|
1550
|
+
observer4.observe({
|
|
1551
|
+
entryTypes: [
|
|
1552
|
+
"resource"
|
|
1553
|
+
],
|
|
1554
|
+
buffered: true
|
|
1555
|
+
});
|
|
1556
|
+
} else {
|
|
1557
|
+
airTracker2.normalLogPipeLine({
|
|
1558
|
+
severity: "warn" /* WARN */ ,
|
|
1559
|
+
eventName: "apiPerformancePluginError",
|
|
1560
|
+
extraInfo: {
|
|
1561
|
+
error: "PerformanceObserver Not Supported"
|
|
1562
|
+
}
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
var apiPerformancePlugin = new AirTrackerPlugin({
|
|
1567
|
+
name: "apiPerformancePlugin",
|
|
1568
|
+
setUp: /*#__PURE__*/ function() {
|
|
1569
|
+
var _ref = _async_to_generator(function(airTracker2) {
|
|
1570
|
+
var _airTracker2_config, _airTracker2_config1;
|
|
1571
|
+
return _ts_generator(this, function(_state) {
|
|
1572
|
+
if (globalObject[API_PERFORMANCE_PLUGIN_LOADED]) {
|
|
1573
|
+
return [
|
|
1574
|
+
2
|
|
1575
|
+
];
|
|
1576
|
+
}
|
|
1577
|
+
if (((_airTracker2_config = airTracker2.config) === null || _airTracker2_config === void 0 ? void 0 : _airTracker2_config.enableRecordAPIPerformance) && Math.random() < (((_airTracker2_config1 = airTracker2.config) === null || _airTracker2_config1 === void 0 ? void 0 : _airTracker2_config1.enableRecordAPIPerformancePercentage) || 0)) {
|
|
1578
|
+
globalObject[API_PERFORMANCE_PLUGIN_LOADED] = true;
|
|
1579
|
+
setUpAPIPerformancePlugin(airTracker2);
|
|
1580
|
+
}
|
|
1581
|
+
return [
|
|
1582
|
+
2
|
|
1583
|
+
];
|
|
1584
|
+
});
|
|
1585
|
+
});
|
|
1586
|
+
return function(airTracker2) {
|
|
1587
|
+
return _ref.apply(this, arguments);
|
|
1588
|
+
};
|
|
1589
|
+
}()
|
|
1590
|
+
});
|
|
1591
|
+
// src/util/version.ts
|
|
1592
|
+
var SDK_VERSION = "3.1.0";
|
|
1593
|
+
// src/airTracker.ts
|
|
1594
|
+
var AirTracker = /*#__PURE__*/ function() {
|
|
1595
|
+
function AirTracker(param) {
|
|
1596
|
+
var _this = this;
|
|
1597
|
+
var config = param.config, _param_plugins = param.plugins, plugins = _param_plugins === void 0 ? [] : _param_plugins;
|
|
1598
|
+
_class_call_check(this, AirTracker);
|
|
1599
|
+
this.config = DEFAULT_CONFIG;
|
|
1600
|
+
this.lifeCycle = new EventEmitter();
|
|
1601
|
+
this.plugins = [];
|
|
1602
|
+
this._commonData = DEFAULT_COMMON_DATA;
|
|
1603
|
+
this._MFECommonDataMap = {};
|
|
1604
|
+
// customized speed log
|
|
1605
|
+
this.timeMap = {};
|
|
1606
|
+
this.packedDataConvert = function(param) {
|
|
1607
|
+
var severity = param.severity, eventName = param.eventName, extraInfo = param.extraInfo;
|
|
1608
|
+
var _location, _location1;
|
|
1609
|
+
var packedData = _object_spread({
|
|
1610
|
+
severity: severity,
|
|
1611
|
+
eventName: eventName,
|
|
1612
|
+
currentHref: _this.config.hideSearchParams ? (((_location = location) === null || _location === void 0 ? void 0 : _location.href) || "").split("?")[0] || "" : ((_location1 = location) === null || _location1 === void 0 ? void 0 : _location1.href) || ""
|
|
1613
|
+
}, extraInfo);
|
|
1614
|
+
if (_this.config.isWebappContainer) {
|
|
1615
|
+
packedData.MFEName = getMFEName(_this);
|
|
1616
|
+
}
|
|
1617
|
+
return packedData;
|
|
1618
|
+
};
|
|
1619
|
+
this.normalPipelineObj = createPipeline([
|
|
1620
|
+
throttlePipe(this, 8),
|
|
1621
|
+
errorLogLimitPipe(this),
|
|
1622
|
+
sendNormalLogPipe(this)
|
|
1623
|
+
]);
|
|
1624
|
+
this.observerPipelineObj = createPipeline([
|
|
1625
|
+
throttlePipe(this, 8),
|
|
1626
|
+
sendMetricsLogPipe(this)
|
|
1627
|
+
]);
|
|
1628
|
+
this.immediateSendPipe = sendNormalLogPipe(this);
|
|
1629
|
+
this.observerPipeline = function(param) {
|
|
1630
|
+
var severity = param.severity, eventName = param.eventName, extraInfo = param.extraInfo;
|
|
1631
|
+
var packedData = _this.packedDataConvert({
|
|
1632
|
+
severity: severity,
|
|
1633
|
+
eventName: eventName,
|
|
1634
|
+
extraInfo: extraInfo
|
|
1635
|
+
});
|
|
1636
|
+
return _this.observerPipelineObj(packedData);
|
|
1637
|
+
};
|
|
1638
|
+
this.normalLogPipeLine = function(param) {
|
|
1639
|
+
var severity = param.severity, eventName = param.eventName, extraInfo = param.extraInfo;
|
|
1640
|
+
var packedData = _this.packedDataConvert({
|
|
1641
|
+
severity: severity,
|
|
1642
|
+
eventName: eventName,
|
|
1643
|
+
extraInfo: extraInfo
|
|
1644
|
+
});
|
|
1645
|
+
if (_this.config.disableThrottle) {
|
|
1646
|
+
return _this.immediateSendPipe(packedData);
|
|
1647
|
+
} else {
|
|
1648
|
+
return _this.normalPipelineObj(packedData);
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
this.ImmediatePipeline = function(param) {
|
|
1652
|
+
var severity = param.severity, eventName = param.eventName, extraInfo = param.extraInfo;
|
|
1653
|
+
var packedData = _this.packedDataConvert({
|
|
1654
|
+
severity: severity,
|
|
1655
|
+
eventName: eventName,
|
|
1656
|
+
extraInfo: extraInfo
|
|
1657
|
+
});
|
|
1658
|
+
return _this.immediateSendPipe(packedData);
|
|
1659
|
+
};
|
|
1660
|
+
this.plugins = _to_consumable_array(plugins);
|
|
1661
|
+
this.setConfig(config);
|
|
1662
|
+
this.initCommonData(config);
|
|
1663
|
+
this.lifeCycle.emit(lifeCycleEventName.onInit);
|
|
1664
|
+
if (config.enableErrorMonitoring) {
|
|
1665
|
+
this.plugins.push(errorDetectionPlugin);
|
|
1666
|
+
}
|
|
1667
|
+
if ((config === null || config === void 0 ? void 0 : config.assetSpeedMonitoringWhiteList) && config.assetSpeedMonitoringWhiteList.length > 0 || config.isWebappContainer) {
|
|
1668
|
+
this.plugins.push(assetSpeedPlugin);
|
|
1669
|
+
}
|
|
1670
|
+
if (config === null || config === void 0 ? void 0 : config.enableDetectPageChange) {
|
|
1671
|
+
this.plugins.push(onPageChangePlugin);
|
|
1672
|
+
}
|
|
1673
|
+
if (config === null || config === void 0 ? void 0 : config.enableRecordPageRetention) {
|
|
1674
|
+
this.plugins.push(onPageRetentionPlugin);
|
|
1675
|
+
}
|
|
1676
|
+
if ((config === null || config === void 0 ? void 0 : config.enableRecordAPIPerformance) && (config === null || config === void 0 ? void 0 : config.enableRecordAPIPerformancePercentage) && config.enableRecordAPIPerformancePercentage > 0 && config.enableRecordAPIPerformancePercentage <= 1) {
|
|
1677
|
+
this.plugins.push(apiPerformancePlugin);
|
|
1678
|
+
}
|
|
1679
|
+
this.installPlugins();
|
|
1680
|
+
}
|
|
1681
|
+
_create_class(AirTracker, [
|
|
1682
|
+
{
|
|
1683
|
+
key: "installPlugins",
|
|
1684
|
+
value: function installPlugins() {
|
|
1685
|
+
var _this = this;
|
|
1686
|
+
this.plugins.forEach(function(item) {
|
|
1687
|
+
item.patch(_this);
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
},
|
|
1691
|
+
{
|
|
1692
|
+
key: "commonData",
|
|
1693
|
+
get: function get() {
|
|
1694
|
+
return this._commonData;
|
|
1695
|
+
}
|
|
1696
|
+
},
|
|
1697
|
+
{
|
|
1698
|
+
key: "MFECommonDataMap",
|
|
1699
|
+
get: function get() {
|
|
1700
|
+
return this._MFECommonDataMap;
|
|
1701
|
+
}
|
|
1702
|
+
},
|
|
1703
|
+
{
|
|
1704
|
+
key: "initCommonData",
|
|
1705
|
+
value: function initCommonData(config) {
|
|
1706
|
+
this._commonData.sessionId = config.useSessionStorageForSessionId ? getSessionId() : generateUId();
|
|
1707
|
+
this._commonData.deviceId = getDeviceId() || UNKNOWN_VALUE;
|
|
1708
|
+
this._commonData.riskDeviceId = getRiskDeviceId();
|
|
1709
|
+
this._commonData.networkType = getNetworkType() || "unknown" /* unknown */ ;
|
|
1710
|
+
this._commonData.env = config.env || this._commonData.env;
|
|
1711
|
+
this._commonData.accountId = config.accountId || UNKNOWN_VALUE;
|
|
1712
|
+
this._commonData.appVersion = config.appVersion;
|
|
1713
|
+
this._commonData.appName = config.appName;
|
|
1714
|
+
this._commonData.sdkVersion = SDK_VERSION;
|
|
1715
|
+
this.lifeCycle.emit(lifeCycleEventName.onCommonDataInit, this.commonData);
|
|
1716
|
+
}
|
|
1717
|
+
},
|
|
1718
|
+
{
|
|
1719
|
+
key: "updateCommonDataBasedOnConfig",
|
|
1720
|
+
value: function updateCommonDataBasedOnConfig(config) {
|
|
1721
|
+
this.lifeCycle.emit(lifeCycleEventName.onCommonUpdated, this._commonData);
|
|
1722
|
+
this._commonData.env = config.env || this._commonData.env;
|
|
1723
|
+
this._commonData.appName = config.appName || this._commonData.appName;
|
|
1724
|
+
this._commonData.env = config.env || this._commonData.env;
|
|
1725
|
+
this._commonData.accountId = config.accountId || this._commonData.accountId;
|
|
1726
|
+
this._commonData.appVersion = config.appVersion || this._commonData.appVersion;
|
|
1727
|
+
}
|
|
1728
|
+
},
|
|
1729
|
+
{
|
|
1730
|
+
// Can add extra common data based on developers' needs
|
|
1731
|
+
key: "updateCommonData",
|
|
1732
|
+
value: function updateCommonData(extraData) {
|
|
1733
|
+
this.lifeCycle.emit(lifeCycleEventName.onCommonUpdated, this._commonData);
|
|
1734
|
+
this._commonData = _object_spread({}, this._commonData, extraData);
|
|
1735
|
+
}
|
|
1736
|
+
},
|
|
1737
|
+
{
|
|
1738
|
+
key: "removeCommonDataByKey",
|
|
1739
|
+
value: function removeCommonDataByKey(keys) {
|
|
1740
|
+
var _this = this;
|
|
1741
|
+
this.lifeCycle.emit(lifeCycleEventName.onCommonUpdated, this._commonData);
|
|
1742
|
+
setTimeout(function() {
|
|
1743
|
+
keys.forEach(function(item) {
|
|
1744
|
+
delete _this._commonData[item];
|
|
1745
|
+
});
|
|
1746
|
+
}, 1e3);
|
|
1747
|
+
}
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
// only worked if isWebappContainer is true
|
|
1751
|
+
key: "addToMFECommonData",
|
|
1752
|
+
value: function addToMFECommonData(param) {
|
|
1753
|
+
var MFEName = param.MFEName, MFECommonData = param.MFECommonData;
|
|
1754
|
+
var _this__MFECommonDataMap;
|
|
1755
|
+
if (!this.config.isWebappContainer) {
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
if (!MFEName || !MFECommonData) {
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
this._MFECommonDataMap = _object_spread_props(_object_spread({}, this._MFECommonDataMap || {}), _define_property({}, MFEName, _object_spread({}, ((_this__MFECommonDataMap = this._MFECommonDataMap) === null || _this__MFECommonDataMap === void 0 ? void 0 : _this__MFECommonDataMap[MFEName]) || {}, MFECommonData)));
|
|
1762
|
+
}
|
|
1763
|
+
},
|
|
1764
|
+
{
|
|
1765
|
+
// support set config later
|
|
1766
|
+
key: "setConfig",
|
|
1767
|
+
value: function setConfig(config) {
|
|
1768
|
+
var _this = this;
|
|
1769
|
+
if (this.config.isWebappContainer) {
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
var setValue = function(key, value) {
|
|
1773
|
+
_this.config[key] = value;
|
|
1774
|
+
};
|
|
1775
|
+
Object.entries(config).forEach(function(item) {
|
|
1776
|
+
var _item = _sliced_to_array(item, 2), key = _item[0], val = _item[1];
|
|
1777
|
+
if ((typeof val === "undefined" ? "undefined" : _type_of(val)) !== void 0) {
|
|
1778
|
+
setValue(key, val);
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
this.lifeCycle.emit(lifeCycleEventName.onConfigInit, this.config);
|
|
1782
|
+
this.updateCommonDataBasedOnConfig(config);
|
|
1783
|
+
}
|
|
1784
|
+
},
|
|
1785
|
+
{
|
|
1786
|
+
// send verbose level log
|
|
1787
|
+
key: "verbose",
|
|
1788
|
+
value: function verbose(eventName, extraInfo) {
|
|
1789
|
+
this.normalLogPipeLine({
|
|
1790
|
+
severity: "verbose" /* VERBOSE */ ,
|
|
1791
|
+
eventName: eventName,
|
|
1792
|
+
extraInfo: extraInfo
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
1796
|
+
{
|
|
1797
|
+
// send HTTP request log
|
|
1798
|
+
key: "httpLog",
|
|
1799
|
+
value: function httpLog(eventName, extraInfo) {
|
|
1800
|
+
this.normalLogPipeLine({
|
|
1801
|
+
severity: "http" /* HTTP */ ,
|
|
1802
|
+
eventName: eventName,
|
|
1803
|
+
extraInfo: extraInfo
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
},
|
|
1807
|
+
{
|
|
1808
|
+
// send info level log
|
|
1809
|
+
key: "info",
|
|
1810
|
+
value: function info(eventName, extraInfo) {
|
|
1811
|
+
this.normalLogPipeLine({
|
|
1812
|
+
severity: "info" /* INFO */ ,
|
|
1813
|
+
eventName: eventName,
|
|
1814
|
+
extraInfo: extraInfo
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
},
|
|
1818
|
+
{
|
|
1819
|
+
// send warn level log
|
|
1820
|
+
key: "warn",
|
|
1821
|
+
value: function warn(eventName, extraInfo) {
|
|
1822
|
+
this.normalLogPipeLine({
|
|
1823
|
+
severity: "warn" /* WARN */ ,
|
|
1824
|
+
eventName: eventName,
|
|
1825
|
+
extraInfo: extraInfo
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
},
|
|
1829
|
+
{
|
|
1830
|
+
// send error level log
|
|
1831
|
+
key: "error",
|
|
1832
|
+
value: function error(eventName, extraInfo) {
|
|
1833
|
+
console.error("error", eventName);
|
|
1834
|
+
this.normalLogPipeLine({
|
|
1835
|
+
severity: "error" /* ERROR */ ,
|
|
1836
|
+
eventName: eventName,
|
|
1837
|
+
extraInfo: extraInfo
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
},
|
|
1841
|
+
{
|
|
1842
|
+
// send business related log, usually used for data analysis
|
|
1843
|
+
// all the logs with isBusinessData == true, will be sync to bigQuery / looker
|
|
1844
|
+
key: "businessLog",
|
|
1845
|
+
value: function businessLog(eventName, extraInfo) {
|
|
1846
|
+
this.normalLogPipeLine({
|
|
1847
|
+
severity: "info" /* INFO */ ,
|
|
1848
|
+
eventName: eventName,
|
|
1849
|
+
extraInfo: _object_spread_props(_object_spread({}, extraInfo), {
|
|
1850
|
+
isBusinessLog: true
|
|
1851
|
+
})
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
},
|
|
1855
|
+
{
|
|
1856
|
+
// duration: milliseconds
|
|
1857
|
+
key: "reportDuration",
|
|
1858
|
+
value: function reportDuration(eventName, duration, extraInfo) {
|
|
1859
|
+
if (typeof eventName !== "string") {
|
|
1860
|
+
console.warn("reportDuration: eventName (first param) must be a string");
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
if (typeof duration !== "number") {
|
|
1864
|
+
console.warn("reportDuration: duration (second param) must be number");
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
if (duration < 0 || duration > 6e4) {
|
|
1868
|
+
console.warn("reportDuration: duration (second param) must between 0 and 60000");
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
this.normalLogPipeLine({
|
|
1872
|
+
severity: "speed" /* SPEED */ ,
|
|
1873
|
+
eventName: eventName,
|
|
1874
|
+
extraInfo: _object_spread({
|
|
1875
|
+
duration: duration
|
|
1876
|
+
}, extraInfo)
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1880
|
+
{
|
|
1881
|
+
key: "getTimerKey",
|
|
1882
|
+
value: function getTimerKey(eventName) {
|
|
1883
|
+
var MFEName = getMFEName(this);
|
|
1884
|
+
return this.config.isWebappContainer ? "".concat(MFEName, "_").concat(eventName) : eventName;
|
|
1885
|
+
}
|
|
1886
|
+
},
|
|
1887
|
+
{
|
|
1888
|
+
key: "timeStart",
|
|
1889
|
+
value: function timeStart(eventName) {
|
|
1890
|
+
if (typeof eventName !== "string") {
|
|
1891
|
+
console.warn("time: first param must be a string");
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
if (this.timeMap[this.getTimerKey(eventName)]) {
|
|
1895
|
+
console.warn("Timer ".concat(eventName, " already exists"));
|
|
1896
|
+
}
|
|
1897
|
+
this.timeMap[this.getTimerKey(eventName)] = Date.now();
|
|
1898
|
+
}
|
|
1899
|
+
},
|
|
1900
|
+
{
|
|
1901
|
+
key: "timeEnd",
|
|
1902
|
+
value: function timeEnd(eventName, delta) {
|
|
1903
|
+
if (typeof eventName !== "string") {
|
|
1904
|
+
console.warn("timeEnd: first param must be a string");
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
if (this.timeMap[this.getTimerKey(eventName)]) {
|
|
1908
|
+
var duration = Date.now() - this.timeMap[this.getTimerKey(eventName)] + (delta || 0);
|
|
1909
|
+
this.normalLogPipeLine({
|
|
1910
|
+
severity: "speed" /* SPEED */ ,
|
|
1911
|
+
eventName: eventName,
|
|
1912
|
+
extraInfo: {
|
|
1913
|
+
duration: duration
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
delete this.timeMap[this.getTimerKey(eventName)];
|
|
1917
|
+
} else {
|
|
1918
|
+
console.warn("Timer key :".concat(eventName, " does not exist"));
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
},
|
|
1922
|
+
{
|
|
1923
|
+
// only worked if isWebappContainer is true
|
|
1924
|
+
key: "addToAssetSpeedWhiteListByMFE",
|
|
1925
|
+
value: function addToAssetSpeedWhiteListByMFE(param) {
|
|
1926
|
+
var MFEName = param.MFEName, whiteList = param.whiteList;
|
|
1927
|
+
var _this_config_assetSpeedMonitoringWhiteListByMFE;
|
|
1928
|
+
if (!this.config.isWebappContainer) {
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
if (!MFEName || !(whiteList === null || whiteList === void 0 ? void 0 : whiteList.length)) {
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1934
|
+
if (!this.config.assetSpeedMonitoringWhiteListByMFE) {
|
|
1935
|
+
this.config.assetSpeedMonitoringWhiteListByMFE = {};
|
|
1936
|
+
}
|
|
1937
|
+
if (!((_this_config_assetSpeedMonitoringWhiteListByMFE = this.config.assetSpeedMonitoringWhiteListByMFE) === null || _this_config_assetSpeedMonitoringWhiteListByMFE === void 0 ? void 0 : _this_config_assetSpeedMonitoringWhiteListByMFE[MFEName])) {
|
|
1938
|
+
this.config.assetSpeedMonitoringWhiteListByMFE = _object_spread_props(_object_spread({}, this.config.assetSpeedMonitoringWhiteListByMFE), _define_property({}, MFEName, whiteList));
|
|
1939
|
+
} else {
|
|
1940
|
+
var _this_config_assetSpeedMonitoringWhiteListByMFE_MFEName;
|
|
1941
|
+
var _this_config_assetSpeedMonitoringWhiteListByMFE_MFEName1, _this_config_assetSpeedMonitoringWhiteListByMFE1;
|
|
1942
|
+
(_this_config_assetSpeedMonitoringWhiteListByMFE1 = this.config.assetSpeedMonitoringWhiteListByMFE) === null || _this_config_assetSpeedMonitoringWhiteListByMFE1 === void 0 ? void 0 : (_this_config_assetSpeedMonitoringWhiteListByMFE_MFEName1 = _this_config_assetSpeedMonitoringWhiteListByMFE1[MFEName]) === null || _this_config_assetSpeedMonitoringWhiteListByMFE_MFEName1 === void 0 ? void 0 : (_this_config_assetSpeedMonitoringWhiteListByMFE_MFEName = _this_config_assetSpeedMonitoringWhiteListByMFE_MFEName1).push.apply(_this_config_assetSpeedMonitoringWhiteListByMFE_MFEName, _to_consumable_array(whiteList));
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
// please call destroy from your app root component when your app unmount
|
|
1948
|
+
key: "destroy",
|
|
1949
|
+
value: function destroy() {
|
|
1950
|
+
if (this.config.isWebappContainer) {
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
this.plugins.forEach(function(item) {
|
|
1954
|
+
item.uninstall();
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
]);
|
|
1959
|
+
return AirTracker;
|
|
1960
|
+
}();
|
|
1961
|
+
// src/index.ts
|
|
1962
|
+
var src_default = AirTracker;
|
|
1963
|
+
|
|
1964
|
+
/******************************************************************************
|
|
1965
|
+
Copyright (c) Microsoft Corporation.
|
|
1966
|
+
|
|
1967
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1968
|
+
purpose with or without fee is hereby granted.
|
|
1969
|
+
|
|
1970
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1971
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1972
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1973
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1974
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1975
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1976
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1977
|
+
***************************************************************************** */
|
|
1978
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
1979
|
+
|
|
1980
|
+
var extendStatics = function(d, b) {
|
|
1981
|
+
extendStatics = Object.setPrototypeOf ||
|
|
1982
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
1983
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
1984
|
+
return extendStatics(d, b);
|
|
1985
|
+
};
|
|
1986
|
+
|
|
1987
|
+
function __extends(d, b) {
|
|
1988
|
+
if (typeof b !== "function" && b !== null)
|
|
1989
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
1990
|
+
extendStatics(d, b);
|
|
1991
|
+
function __() { this.constructor = d; }
|
|
1992
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
var __assign = function() {
|
|
1996
|
+
__assign = Object.assign || function __assign(t) {
|
|
1997
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1998
|
+
s = arguments[i];
|
|
1999
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
2000
|
+
}
|
|
2001
|
+
return t;
|
|
2002
|
+
};
|
|
2003
|
+
return __assign.apply(this, arguments);
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
2007
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2008
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2009
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2010
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2011
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2012
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
function __generator(thisArg, body) {
|
|
2017
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2018
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2019
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2020
|
+
function step(op) {
|
|
2021
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2022
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
2023
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
2024
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2025
|
+
switch (op[0]) {
|
|
2026
|
+
case 0: case 1: t = op; break;
|
|
2027
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2028
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2029
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2030
|
+
default:
|
|
2031
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2032
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2033
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2034
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2035
|
+
if (t[2]) _.ops.pop();
|
|
2036
|
+
_.trys.pop(); continue;
|
|
2037
|
+
}
|
|
2038
|
+
op = body.call(thisArg, _);
|
|
2039
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2040
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
function __spreadArray(to, from, pack) {
|
|
2045
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
2046
|
+
if (ar || !(i in from)) {
|
|
2047
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
2048
|
+
ar[i] = from[i];
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
2055
|
+
var e = new Error(message);
|
|
2056
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2059
|
+
var name = "@airwallex/components-sdk";
|
|
2060
|
+
var version = "1.30.2";
|
|
2061
|
+
var main = "./lib/index.js";
|
|
2062
|
+
var module = "./lib/index.mjs";
|
|
2063
|
+
var types = "./lib/index.d.ts";
|
|
2064
|
+
var files = [
|
|
2065
|
+
"lib/**"
|
|
2066
|
+
];
|
|
2067
|
+
var license = "MIT";
|
|
2068
|
+
var scripts = {
|
|
2069
|
+
"load-types": "node ./load-types.js && yarn prettier -w src/types/*d.ts",
|
|
2070
|
+
prebuild: "yarn clean",
|
|
2071
|
+
build: "yarn rollup --config",
|
|
2072
|
+
postbuild: "yarn bundle-types",
|
|
2073
|
+
"bundle-types": "dts-bundle-generator -o ./lib/index.d.ts ./src/index.ts",
|
|
2074
|
+
clean: "rm -rf dist lib",
|
|
2075
|
+
lint: "eslint \"src/**/*.ts*\"",
|
|
2076
|
+
test: "jest",
|
|
2077
|
+
sonar: "sonar-scanner",
|
|
2078
|
+
release: "semantic-release",
|
|
2079
|
+
"lint-stage": "lint-staged",
|
|
2080
|
+
prepare: "husky"
|
|
2081
|
+
};
|
|
2082
|
+
var prettier = {
|
|
2083
|
+
semi: true,
|
|
2084
|
+
singleQuote: true,
|
|
2085
|
+
printWidth: 80,
|
|
2086
|
+
trailingComma: "all"
|
|
2087
|
+
};
|
|
2088
|
+
var publishConfig = {
|
|
2089
|
+
access: "public"
|
|
2090
|
+
};
|
|
2091
|
+
var devDependencies = {
|
|
2092
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
2093
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
2094
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
2095
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
2096
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
2097
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
2098
|
+
"@semantic-release/changelog": "^5.0.1",
|
|
2099
|
+
"@semantic-release/commit-analyzer": "^8.0.1",
|
|
2100
|
+
"@semantic-release/git": "^9.0.0",
|
|
2101
|
+
"@semantic-release/gitlab": "^6.1.0",
|
|
2102
|
+
"@semantic-release/release-notes-generator": "^9.0.0",
|
|
2103
|
+
"@swc/core": "^1.3.46",
|
|
2104
|
+
"@types/jest": "^29.5.0",
|
|
2105
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
2106
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
2107
|
+
"dts-bundle-generator": "^9.0.0",
|
|
2108
|
+
eslint: "^7.23.0",
|
|
2109
|
+
"eslint-config-prettier": "^8.3.0",
|
|
2110
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
2111
|
+
husky: "^9.0.11",
|
|
2112
|
+
jest: "^29.5.0",
|
|
2113
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
2114
|
+
"lint-staged": "^15.2.7",
|
|
2115
|
+
prettier: "^3.3.2",
|
|
2116
|
+
rollup: "^4.9.6",
|
|
2117
|
+
"semantic-release": "^17.3.8",
|
|
2118
|
+
"sonarqube-scanner": "^3.0.1",
|
|
2119
|
+
"ts-jest": "^29.0.5",
|
|
2120
|
+
"ts-loader": "^9.5.1",
|
|
2121
|
+
tslib: "^2.6.2",
|
|
2122
|
+
typescript: "^4.5.2"
|
|
2123
|
+
};
|
|
2124
|
+
var dependencies = {
|
|
2125
|
+
"@airwallex/airtracker": "^3.0.0"
|
|
2126
|
+
};
|
|
2127
|
+
var packageJson = {
|
|
2128
|
+
name: name,
|
|
2129
|
+
version: version,
|
|
2130
|
+
main: main,
|
|
2131
|
+
module: module,
|
|
2132
|
+
types: types,
|
|
2133
|
+
files: files,
|
|
2134
|
+
license: license,
|
|
2135
|
+
scripts: scripts,
|
|
2136
|
+
prettier: prettier,
|
|
2137
|
+
"lint-staged": {
|
|
2138
|
+
"src/**/*.{ts,tsx}": [
|
|
2139
|
+
"yarn lint"
|
|
2140
|
+
],
|
|
2141
|
+
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": "prettier --write"
|
|
2142
|
+
},
|
|
2143
|
+
publishConfig: publishConfig,
|
|
2144
|
+
devDependencies: devDependencies,
|
|
2145
|
+
dependencies: dependencies
|
|
2146
|
+
};
|
|
2147
|
+
|
|
2148
|
+
var airTrackerENV = {
|
|
2149
|
+
dev: Environment.staging,
|
|
2150
|
+
staging: Environment.staging,
|
|
2151
|
+
demo: Environment.demo,
|
|
2152
|
+
prod: Environment.production
|
|
2153
|
+
};
|
|
2154
|
+
var initializeAirTracker = function (env, clientId) {
|
|
2155
|
+
if (env === void 0) { env = Environment.production; }
|
|
2156
|
+
if (!window._AirwallexSDKs.airTracker) {
|
|
2157
|
+
window._AirwallexSDKs.airTracker = new src_default({
|
|
2158
|
+
config: {
|
|
2159
|
+
appName: 'components-sdk',
|
|
2160
|
+
appVersion: packageJson.version,
|
|
2161
|
+
env: airTrackerENV[env] || Environment.production
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
window._AirwallexSDKs.airTracker.updateCommonData({ clientId: clientId });
|
|
2165
|
+
}
|
|
2166
|
+
return window._AirwallexSDKs.airTracker;
|
|
2167
|
+
};
|
|
2168
|
+
var maskPII = function (data) {
|
|
2169
|
+
if (typeof data !== 'object') {
|
|
2170
|
+
return data;
|
|
2171
|
+
}
|
|
2172
|
+
try {
|
|
2173
|
+
var result_1 = JSON.parse(JSON.stringify(data));
|
|
2174
|
+
Object.keys(result_1).forEach(function (key) {
|
|
2175
|
+
if (typeof key === 'string' &&
|
|
2176
|
+
['auth', 'code'].some(function (sens) { return key.includes(sens); })) {
|
|
2177
|
+
result_1[key] = '***';
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
2180
|
+
return result_1;
|
|
2181
|
+
}
|
|
2182
|
+
catch (_a) {
|
|
2183
|
+
return data;
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
var logError = function (eventName, data) {
|
|
2187
|
+
var _a, _b;
|
|
2188
|
+
(_b = (_a = window._AirwallexSDKs) === null || _a === void 0 ? void 0 : _a.airTracker) === null || _b === void 0 ? void 0 : _b.error(eventName, __assign(__assign({}, data), { context: 'components-sdk' }));
|
|
2189
|
+
};
|
|
2190
|
+
var logWarning = function (eventName, data) {
|
|
2191
|
+
var _a;
|
|
2192
|
+
(_a = window._AirwallexSDKs.airTracker) === null || _a === void 0 ? void 0 : _a.warn(eventName, __assign(__assign({}, data), { context: 'components-sdk' }));
|
|
2193
|
+
};
|
|
2194
|
+
var logInfo = function (eventName, data) {
|
|
2195
|
+
var _a;
|
|
2196
|
+
(_a = window._AirwallexSDKs.airTracker) === null || _a === void 0 ? void 0 : _a.info(eventName, __assign(__assign({}, data), { context: 'components-sdk' }));
|
|
2197
|
+
};
|
|
2198
|
+
|
|
2199
|
+
var LoadScriptError = /** @class */ (function (_super) {
|
|
2200
|
+
__extends(LoadScriptError, _super);
|
|
2201
|
+
function LoadScriptError(message) {
|
|
2202
|
+
var _this = _super.call(this, message) || this;
|
|
2203
|
+
_this.code = 'LOAD_SCRIPT_ERROR';
|
|
2204
|
+
return _this;
|
|
2205
|
+
}
|
|
2206
|
+
return LoadScriptError;
|
|
2207
|
+
}(Error));
|
|
2208
|
+
|
|
2209
|
+
var _a, _b;
|
|
2210
|
+
var ENV;
|
|
2211
|
+
(function (ENV) {
|
|
2212
|
+
ENV["dev"] = "dev";
|
|
2213
|
+
ENV["staging"] = "staging";
|
|
2214
|
+
ENV["demo"] = "demo";
|
|
2215
|
+
ENV["prod"] = "prod";
|
|
2216
|
+
ENV["sandbox"] = "sandbox";
|
|
2217
|
+
})(ENV || (ENV = {}));
|
|
2218
|
+
var PA_STATIC_HOST = (_a = {},
|
|
2219
|
+
_a[ENV.dev] = 'https://checkout-staging.airwallex.com',
|
|
2220
|
+
_a[ENV.staging] = 'https://checkout-staging.airwallex.com',
|
|
2221
|
+
_a[ENV.demo] = 'https://checkout-demo.airwallex.com',
|
|
2222
|
+
_a[ENV.prod] = 'https://checkout.airwallex.com',
|
|
2223
|
+
_a[ENV.sandbox] = 'https://checkout.sandbox.airwallex.com',
|
|
2224
|
+
_a);
|
|
2225
|
+
var STATIC_HOST = (_b = {},
|
|
2226
|
+
_b[ENV.dev] = 'https://static-staging.airwallex.com',
|
|
2227
|
+
_b[ENV.staging] = 'https://static-staging.airwallex.com',
|
|
2228
|
+
_b[ENV.demo] = 'https://static-demo.airwallex.com',
|
|
2229
|
+
_b[ENV.prod] = 'https://static.airwallex.com',
|
|
2230
|
+
_b[ENV.sandbox] = 'https://static.sandbox.airwallex.com',
|
|
2231
|
+
_b);
|
|
2232
|
+
var SDK_CONTROLLER = 'sdkController';
|
|
2233
|
+
var PAYMENTS = 'payments';
|
|
2234
|
+
var SDK_URL_MAPPING = {
|
|
2235
|
+
kyc: '/widgets/kyc/sdk/v1/index.js',
|
|
2236
|
+
rfi: '/widgets/kycRfi/sdk/v1/index.js',
|
|
2237
|
+
paymentsKyb: '/widgets/paymentsKyb/sdk/v1/index.js',
|
|
2238
|
+
sdkController: '/widgets/sdk-controller/sdk/v1/index.js',
|
|
2239
|
+
payouts: '/widgets/payouts/sdk/v1/index.js',
|
|
2240
|
+
payments: '/assets/elements.bundle.min.js',
|
|
2241
|
+
sca: '/hosted-sca/sdk/v1/index.js',
|
|
2242
|
+
taxForm: '/widgets/taxForm/sdk/v1/index.js',
|
|
2243
|
+
billing: '/widgets/checkout/sdk/v1/index.js'
|
|
2244
|
+
};
|
|
2245
|
+
var ELEMENT_TO_SDK = {
|
|
2246
|
+
// legacy
|
|
2247
|
+
kyc: 'kyc',
|
|
2248
|
+
paymentsKyb: 'paymentsKyb',
|
|
2249
|
+
// rfi elements
|
|
2250
|
+
kycRfi: 'rfi',
|
|
2251
|
+
transactionRfi: 'rfi',
|
|
2252
|
+
paymentEnablementRfi: 'rfi',
|
|
2253
|
+
lendingRfi: 'rfi',
|
|
2254
|
+
mrmRfi: 'rfi',
|
|
2255
|
+
// payouts elements
|
|
2256
|
+
payoutForm: 'payouts',
|
|
2257
|
+
beneficiaryForm: 'payouts',
|
|
2258
|
+
// payment elements
|
|
2259
|
+
hpp: 'payments',
|
|
2260
|
+
cvc: 'payments',
|
|
2261
|
+
card: 'payments',
|
|
2262
|
+
expiry: 'payments',
|
|
2263
|
+
dropIn: 'payments',
|
|
2264
|
+
cardNumber: 'payments',
|
|
2265
|
+
applePayButton: 'payments',
|
|
2266
|
+
googlePayButton: 'payments',
|
|
2267
|
+
krCardNumber: 'payments',
|
|
2268
|
+
krCardIdentifier: 'payments',
|
|
2269
|
+
krCardExpiry: 'payments',
|
|
2270
|
+
krCardPswFirstTwo: 'payments',
|
|
2271
|
+
// sca elements
|
|
2272
|
+
scaSetup: 'sca',
|
|
2273
|
+
scaVerify: 'sca',
|
|
2274
|
+
scaManagement: 'sca',
|
|
2275
|
+
taxForm: 'taxForm',
|
|
2276
|
+
// billing elements
|
|
2277
|
+
embeddedCheckout: 'billing'
|
|
2278
|
+
};
|
|
2279
|
+
var ELEMENT_GROUP_TO_ELEMENT = {
|
|
2280
|
+
payments: [
|
|
2281
|
+
'hpp',
|
|
2282
|
+
'cvc',
|
|
2283
|
+
'card',
|
|
2284
|
+
'expiry',
|
|
2285
|
+
'dropIn',
|
|
2286
|
+
'cardNumber',
|
|
2287
|
+
'applePayButton',
|
|
2288
|
+
'googlePayButton',
|
|
2289
|
+
'krCardNumber',
|
|
2290
|
+
'krCardIdentifier',
|
|
2291
|
+
'krCardExpiry',
|
|
2292
|
+
'krCardPswFirstTwo',
|
|
2293
|
+
],
|
|
2294
|
+
payouts: ['payoutForm', 'beneficiaryForm'],
|
|
2295
|
+
onboarding: ['kyc', 'paymentsKyb'],
|
|
2296
|
+
risk: [
|
|
2297
|
+
'scaSetup',
|
|
2298
|
+
'scaVerify',
|
|
2299
|
+
'scaManagement',
|
|
2300
|
+
'transactionRfi',
|
|
2301
|
+
'kycRfi',
|
|
2302
|
+
'paymentEnablementRfi',
|
|
2303
|
+
'lendingRfi',
|
|
2304
|
+
'mrmRfi',
|
|
2305
|
+
],
|
|
2306
|
+
billing: ['embeddedCheckout']
|
|
2307
|
+
};
|
|
2308
|
+
var SDK_DEPENDENCIES = {
|
|
2309
|
+
billing: ['payments']
|
|
2310
|
+
};
|
|
2311
|
+
var DOMAIN_FUNCTIONS_NAMESPACES = ['payments', 'sca'];
|
|
2312
|
+
|
|
2313
|
+
var InvalidStaticResourceError = /** @class */ (function (_super) {
|
|
2314
|
+
__extends(InvalidStaticResourceError, _super);
|
|
2315
|
+
function InvalidStaticResourceError(message) {
|
|
2316
|
+
var _this = _super.call(this, message) || this;
|
|
2317
|
+
_this.code = 'INVALID_STATIC_RESOURCE_ERROR';
|
|
2318
|
+
return _this;
|
|
2319
|
+
}
|
|
2320
|
+
return InvalidStaticResourceError;
|
|
2321
|
+
}(Error));
|
|
2322
|
+
|
|
2323
|
+
var timestamp = Date.now();
|
|
2324
|
+
var isElementGroup = function (name) { return Object.keys(ELEMENT_GROUP_TO_ELEMENT).includes(name); };
|
|
2325
|
+
var sleep = function (delay) {
|
|
2326
|
+
if (delay === void 0) { delay = 500; }
|
|
2327
|
+
return new Promise(function (resolve) { return window.setTimeout(resolve, delay); });
|
|
2328
|
+
};
|
|
2329
|
+
var getSDKByElementName = function (elementName) {
|
|
2330
|
+
return ELEMENT_TO_SDK[elementName];
|
|
2331
|
+
};
|
|
2332
|
+
var getHost = function (name, env) {
|
|
2333
|
+
var host = name === PAYMENTS ? PA_STATIC_HOST : STATIC_HOST;
|
|
2334
|
+
return host[env] || host.prod;
|
|
2335
|
+
};
|
|
2336
|
+
/**
|
|
2337
|
+
* get the elements and sdks that need registry by controller
|
|
2338
|
+
* @param enabledElements the enabledElements passed in init params
|
|
2339
|
+
* @returns array of deduplicated elementName pair with sdkName
|
|
2340
|
+
*/
|
|
2341
|
+
var getSDKsByEnabledElements = function (enabledElements) {
|
|
2342
|
+
// e.g., ['hpp', 'payoutForm', 'kyc', 'kyc']
|
|
2343
|
+
var usedElements = enabledElements.reduce(function (elementArr, enabledEle) {
|
|
2344
|
+
return elementArr.concat(isElementGroup(enabledEle)
|
|
2345
|
+
? ELEMENT_GROUP_TO_ELEMENT[enabledEle]
|
|
2346
|
+
: enabledEle);
|
|
2347
|
+
}, []);
|
|
2348
|
+
return Array.from(new Set(usedElements)).map(function (elementName) { return ({
|
|
2349
|
+
elementName: elementName,
|
|
2350
|
+
sdkName: getSDKByElementName(elementName)
|
|
2351
|
+
}); });
|
|
2352
|
+
};
|
|
2353
|
+
var getFunctionsByEnabledElements = function (enabledElements) {
|
|
2354
|
+
return Array.from(new Set(getSDKsByEnabledElements(enabledElements)
|
|
2355
|
+
.map(function (_a) {
|
|
2356
|
+
var sdkName = _a.sdkName;
|
|
2357
|
+
return sdkName;
|
|
2358
|
+
})
|
|
2359
|
+
.filter(function (usedSdkName) {
|
|
2360
|
+
return DOMAIN_FUNCTIONS_NAMESPACES.includes(usedSdkName);
|
|
2361
|
+
})));
|
|
2362
|
+
};
|
|
2363
|
+
var getWindowSDKInstanceName = function (name) {
|
|
2364
|
+
return name === 'payments' ? 'payment' : name;
|
|
2365
|
+
};
|
|
2366
|
+
/**
|
|
2367
|
+
* get the CDN url of a specific package
|
|
2368
|
+
* @param name declare the element name
|
|
2369
|
+
* @param env the environment of package
|
|
2370
|
+
* @returns string the CDN url
|
|
2371
|
+
*/
|
|
2372
|
+
var getSDKUrl = function (_a) {
|
|
2373
|
+
var name = _a.name, _b = _a.env, env = _b === void 0 ? ENV.prod : _b;
|
|
2374
|
+
var staticHost = getHost(name, env);
|
|
2375
|
+
var elementUri = SDK_URL_MAPPING[name];
|
|
2376
|
+
if (!elementUri) {
|
|
2377
|
+
logError('[components-sdk] Element static resource not found', {
|
|
2378
|
+
sdkName: name
|
|
2379
|
+
});
|
|
2380
|
+
throw new InvalidStaticResourceError("Element ".concat(name, " static resource URL is invalid."));
|
|
2381
|
+
}
|
|
2382
|
+
return "".concat(staticHost).concat(elementUri, "?ts=").concat(timestamp);
|
|
2383
|
+
};
|
|
2384
|
+
var getFunctionsInstanceWithNamespace = function () {
|
|
2385
|
+
return DOMAIN_FUNCTIONS_NAMESPACES.reduce(function (result, namespace) {
|
|
2386
|
+
var _a;
|
|
2387
|
+
return (__assign(__assign({}, result), (_a = {}, _a[namespace] = window._AirwallexSDKs.__controller__.internalSDKs[namespace], _a)));
|
|
2388
|
+
}, {});
|
|
2389
|
+
};
|
|
2390
|
+
var getSDKDependencies = function (sdkName) {
|
|
2391
|
+
return SDK_DEPENDENCIES[sdkName] || [];
|
|
2392
|
+
};
|
|
2393
|
+
var now = function () { return Math.floor(performance.now()); };
|
|
2394
|
+
|
|
2395
|
+
var createScript = function (url) {
|
|
2396
|
+
var script = document.createElement('script');
|
|
2397
|
+
script.src = url;
|
|
2398
|
+
script.type = 'module';
|
|
2399
|
+
var parentDom = document.head || document.body;
|
|
2400
|
+
parentDom.appendChild(script);
|
|
2401
|
+
return script;
|
|
2402
|
+
};
|
|
2403
|
+
var MAX_RETRY_COUNT = 3;
|
|
2404
|
+
var loadScript = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2405
|
+
var retryCount, tryToResolve;
|
|
2406
|
+
return __generator(this, function (_a) {
|
|
2407
|
+
switch (_a.label) {
|
|
2408
|
+
case 0:
|
|
2409
|
+
if (typeof window === 'undefined') {
|
|
2410
|
+
throw new Error('Please load script in browser environment');
|
|
2411
|
+
}
|
|
2412
|
+
retryCount = 0;
|
|
2413
|
+
tryToResolve = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2414
|
+
var start, urlObj, script;
|
|
2415
|
+
return __generator(this, function (_a) {
|
|
2416
|
+
start = now();
|
|
2417
|
+
if (retryCount > 0 && url.includes('?ts=')) {
|
|
2418
|
+
urlObj = new URL(url, window.location.href);
|
|
2419
|
+
urlObj.searchParams.set('ts', "".concat(Date.now()));
|
|
2420
|
+
url = urlObj.toString();
|
|
2421
|
+
}
|
|
2422
|
+
script = createScript(url);
|
|
2423
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
2424
|
+
script.addEventListener('load', function () {
|
|
2425
|
+
var end = now();
|
|
2426
|
+
logInfo('[components-sdk] SDK script loaded', {
|
|
2427
|
+
scriptUrl: url,
|
|
2428
|
+
start: start,
|
|
2429
|
+
latency: end - start,
|
|
2430
|
+
end: end,
|
|
2431
|
+
retryCount: retryCount
|
|
2432
|
+
});
|
|
2433
|
+
resolve(true);
|
|
2434
|
+
});
|
|
2435
|
+
script.addEventListener('error', function (err) {
|
|
2436
|
+
script.remove();
|
|
2437
|
+
console.error(err);
|
|
2438
|
+
var end = now();
|
|
2439
|
+
logError('[components-sdk] Failed to load script', {
|
|
2440
|
+
scriptUrl: url,
|
|
2441
|
+
error: err,
|
|
2442
|
+
start: start,
|
|
2443
|
+
latency: end - start,
|
|
2444
|
+
end: end,
|
|
2445
|
+
retryCount: retryCount
|
|
2446
|
+
});
|
|
2447
|
+
reject(new LoadScriptError("Failed to load Airwallex SDK scripts: ".concat(url)));
|
|
2448
|
+
});
|
|
2449
|
+
})];
|
|
2450
|
+
});
|
|
2451
|
+
}); };
|
|
2452
|
+
_a.label = 1;
|
|
2453
|
+
case 1:
|
|
2454
|
+
if (!(retryCount < MAX_RETRY_COUNT)) return [3 /*break*/, 7];
|
|
2455
|
+
_a.label = 2;
|
|
2456
|
+
case 2:
|
|
2457
|
+
_a.trys.push([2, 4, , 6]);
|
|
2458
|
+
return [4 /*yield*/, tryToResolve()];
|
|
2459
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
2460
|
+
case 4:
|
|
2461
|
+
_a.sent();
|
|
2462
|
+
retryCount++;
|
|
2463
|
+
return [4 /*yield*/, sleep()];
|
|
2464
|
+
case 5:
|
|
2465
|
+
_a.sent();
|
|
2466
|
+
return [3 /*break*/, 6];
|
|
2467
|
+
case 6: return [3 /*break*/, 1];
|
|
2468
|
+
case 7:
|
|
2469
|
+
logError('[components-sdk] Failed to load script after retry', {
|
|
2470
|
+
scriptUrl: url,
|
|
2471
|
+
retryCount: retryCount
|
|
2472
|
+
});
|
|
2473
|
+
throw new LoadScriptError("Failed to load Airwallex SDK scripts: ".concat(url));
|
|
2474
|
+
}
|
|
2475
|
+
});
|
|
2476
|
+
}); };
|
|
2477
|
+
|
|
2478
|
+
var InstanceNotFoundError = /** @class */ (function (_super) {
|
|
2479
|
+
__extends(InstanceNotFoundError, _super);
|
|
2480
|
+
function InstanceNotFoundError(message) {
|
|
2481
|
+
var _this = _super.call(this, message) || this;
|
|
2482
|
+
_this.code = 'INSTANCE_NOT_FOUND_ERROR';
|
|
2483
|
+
return _this;
|
|
2484
|
+
}
|
|
2485
|
+
return InstanceNotFoundError;
|
|
2486
|
+
}(Error));
|
|
2487
|
+
|
|
2488
|
+
var initPromise$1;
|
|
2489
|
+
/**
|
|
2490
|
+
* ensure one script one promise
|
|
2491
|
+
*/
|
|
2492
|
+
var promiseMap = new Map();
|
|
2493
|
+
/**
|
|
2494
|
+
* get the Promise to load the element script
|
|
2495
|
+
* @param scriptName declare the SDK or Functions namespace
|
|
2496
|
+
* @param env the resource url
|
|
2497
|
+
* @returns Promise to load the script
|
|
2498
|
+
*/
|
|
2499
|
+
var getLoadScriptPromise = function (_a) {
|
|
2500
|
+
var env = _a.env, scriptName = _a.scriptName;
|
|
2501
|
+
var url = getSDKUrl({ name: scriptName, env: env });
|
|
2502
|
+
// if promise was made
|
|
2503
|
+
var sdkPromise = promiseMap.get(scriptName);
|
|
2504
|
+
if (sdkPromise) {
|
|
2505
|
+
return sdkPromise;
|
|
2506
|
+
}
|
|
2507
|
+
var loadScriptPromise = loadScript(url);
|
|
2508
|
+
promiseMap.set(scriptName, loadScriptPromise);
|
|
2509
|
+
return loadScriptPromise;
|
|
2510
|
+
};
|
|
2511
|
+
/**
|
|
2512
|
+
* Load an SDK script along with its dependencies
|
|
2513
|
+
* @param scriptName the SDK name to load
|
|
2514
|
+
* @param env the environment
|
|
2515
|
+
* @returns Promise that resolves when the SDK and all its dependencies are loaded
|
|
2516
|
+
*/
|
|
2517
|
+
var loadSDKWithDependencies = function (_a) {
|
|
2518
|
+
var env = _a.env, scriptName = _a.scriptName;
|
|
2519
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
2520
|
+
var dependencies;
|
|
2521
|
+
return __generator(this, function (_b) {
|
|
2522
|
+
switch (_b.label) {
|
|
2523
|
+
case 0:
|
|
2524
|
+
dependencies = getSDKDependencies(scriptName);
|
|
2525
|
+
if (!(dependencies.length > 0)) return [3 /*break*/, 2];
|
|
2526
|
+
return [4 /*yield*/, Promise.all(dependencies.map(function (dep) { return getLoadScriptPromise({ env: env, scriptName: dep }); }))];
|
|
2527
|
+
case 1:
|
|
2528
|
+
_b.sent();
|
|
2529
|
+
_b.label = 2;
|
|
2530
|
+
case 2: return [2 /*return*/, getLoadScriptPromise({ env: env, scriptName: scriptName })];
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
});
|
|
2534
|
+
};
|
|
2535
|
+
/**
|
|
2536
|
+
* SDK init, load controller script
|
|
2537
|
+
* @param options SDK init options
|
|
2538
|
+
* @returns Promise to load the script
|
|
2539
|
+
*/
|
|
2540
|
+
var init = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2541
|
+
return __generator(this, function (_a) {
|
|
2542
|
+
if (typeof window === 'undefined') {
|
|
2543
|
+
throw new Error('Please call the `init()` function in a browser environment.');
|
|
2544
|
+
}
|
|
2545
|
+
// initialize airTracker
|
|
2546
|
+
initializeAirTracker(options.env, options.clientId);
|
|
2547
|
+
logInfo('[components-sdk] SDK init start', {
|
|
2548
|
+
options: maskPII(options),
|
|
2549
|
+
start: now()
|
|
2550
|
+
});
|
|
2551
|
+
initPromise$1 = new Promise(function (resolve, reject) {
|
|
2552
|
+
var _a;
|
|
2553
|
+
var initOptions = __assign(__assign({}, options), { env: options.env && ENV[options.env] ? options.env : ENV.prod });
|
|
2554
|
+
window.AirwallexComponentsSDK.__env__ = initOptions.env;
|
|
2555
|
+
// load SDK controller script
|
|
2556
|
+
var controllerPromise = getLoadScriptPromise({
|
|
2557
|
+
env: initOptions.env,
|
|
2558
|
+
scriptName: SDK_CONTROLLER
|
|
2559
|
+
}).then(function () { return window._AirwallexSDKs.__controller__.init(initOptions); });
|
|
2560
|
+
// For old version backward compatibility
|
|
2561
|
+
var enabledElements = (_a = options.enabledElements) !== null && _a !== void 0 ? _a : [];
|
|
2562
|
+
var functionsNamespaces = getFunctionsByEnabledElements(enabledElements);
|
|
2563
|
+
// load SDK functions scripts
|
|
2564
|
+
var functionsPromises = functionsNamespaces.map(function (functionsNamespace) {
|
|
2565
|
+
return getLoadScriptPromise({
|
|
2566
|
+
env: initOptions.env,
|
|
2567
|
+
scriptName: functionsNamespace
|
|
2568
|
+
})
|
|
2569
|
+
.then(function () { return controllerPromise; })
|
|
2570
|
+
.then(function () {
|
|
2571
|
+
var instance = window._AirwallexSDKs[getWindowSDKInstanceName(functionsNamespace)];
|
|
2572
|
+
if (!instance) {
|
|
2573
|
+
logError('[components-sdk] SDK instance not found', {
|
|
2574
|
+
functionsNamespace: functionsNamespace,
|
|
2575
|
+
windowSDKInstanceName: getWindowSDKInstanceName(functionsNamespace)
|
|
2576
|
+
});
|
|
2577
|
+
throw new InstanceNotFoundError("SDK instance not found");
|
|
2578
|
+
}
|
|
2579
|
+
return window._AirwallexSDKs.__controller__.registerFunctions({
|
|
2580
|
+
functionsNamespace: functionsNamespace,
|
|
2581
|
+
instance: instance
|
|
2582
|
+
});
|
|
2583
|
+
});
|
|
2584
|
+
});
|
|
2585
|
+
// load SDK elements scripts
|
|
2586
|
+
var enabledSDKs = getSDKsByEnabledElements(enabledElements);
|
|
2587
|
+
var elementsPromises = enabledSDKs.map(function (_a) {
|
|
2588
|
+
var sdkNamespace = _a.sdkName, elementName = _a.elementName;
|
|
2589
|
+
return loadSDKWithDependencies({
|
|
2590
|
+
scriptName: sdkNamespace,
|
|
2591
|
+
env: initOptions.env
|
|
2592
|
+
})
|
|
2593
|
+
.then(function () { return controllerPromise; })
|
|
2594
|
+
.then(function () {
|
|
2595
|
+
var instance = window._AirwallexSDKs[getWindowSDKInstanceName(sdkNamespace)];
|
|
2596
|
+
if (!instance) {
|
|
2597
|
+
logError('[components-sdk] SDK instance not found', {
|
|
2598
|
+
sdkName: sdkNamespace,
|
|
2599
|
+
windowSDKInstanceName: getWindowSDKInstanceName(sdkNamespace)
|
|
2600
|
+
});
|
|
2601
|
+
throw new InstanceNotFoundError("SDK instance not found");
|
|
2602
|
+
}
|
|
2603
|
+
return window._AirwallexSDKs.__controller__.registerElement({
|
|
2604
|
+
sdkName: sdkNamespace,
|
|
2605
|
+
elementName: elementName,
|
|
2606
|
+
instance: instance
|
|
2607
|
+
});
|
|
2608
|
+
});
|
|
2609
|
+
});
|
|
2610
|
+
Promise.all(__spreadArray(__spreadArray([controllerPromise], functionsPromises, true), elementsPromises, true))
|
|
2611
|
+
.then(function () {
|
|
2612
|
+
logInfo('[components-sdk] SDK initialized', {
|
|
2613
|
+
options: maskPII(options),
|
|
2614
|
+
start: now()
|
|
2615
|
+
});
|
|
2616
|
+
resolve(getFunctionsInstanceWithNamespace());
|
|
2617
|
+
})["catch"](function (error) {
|
|
2618
|
+
if (!error.code) {
|
|
2619
|
+
logError('[components-sdk] Unexpected errors when init', { error: error });
|
|
2620
|
+
}
|
|
2621
|
+
reject(error);
|
|
2622
|
+
});
|
|
2623
|
+
});
|
|
2624
|
+
return [2 /*return*/, initPromise$1];
|
|
2625
|
+
});
|
|
2626
|
+
}); };
|
|
2627
|
+
/**
|
|
2628
|
+
* load SDK element script and call SDK instance.createElement.
|
|
2629
|
+
* @param elementName the element name to create
|
|
2630
|
+
* @param options createElement options
|
|
2631
|
+
* @returns return type of SDK instance.createElement
|
|
2632
|
+
*/
|
|
2633
|
+
var createElement = function (elementName, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2634
|
+
var sdkName, start, elementInstance, end, error_1;
|
|
2635
|
+
return __generator(this, function (_a) {
|
|
2636
|
+
switch (_a.label) {
|
|
2637
|
+
case 0:
|
|
2638
|
+
if (!elementName) {
|
|
2639
|
+
throw new Error('Element type is missing. Please specify a valid element.');
|
|
2640
|
+
}
|
|
2641
|
+
logInfo('[components-sdk] SDK createElement start', {
|
|
2642
|
+
elementName: elementName,
|
|
2643
|
+
options: maskPII(options),
|
|
2644
|
+
timestamp: now()
|
|
2645
|
+
});
|
|
2646
|
+
if (!initPromise$1) {
|
|
2647
|
+
logWarning('[components-sdk] Did not call init before createElement');
|
|
2648
|
+
throw new Error('Please initialize the Element before creating it.');
|
|
2649
|
+
}
|
|
2650
|
+
return [4 /*yield*/, initPromise$1];
|
|
2651
|
+
case 1:
|
|
2652
|
+
_a.sent();
|
|
2653
|
+
sdkName = getSDKByElementName(elementName);
|
|
2654
|
+
if (!sdkName) {
|
|
2655
|
+
throw new Error("`createElement()` with type `".concat(elementName, "` is not supported. Please specify a valid Element type."));
|
|
2656
|
+
}
|
|
2657
|
+
start = now();
|
|
2658
|
+
_a.label = 2;
|
|
2659
|
+
case 2:
|
|
2660
|
+
_a.trys.push([2, 6, , 7]);
|
|
2661
|
+
return [4 /*yield*/, loadSDKWithDependencies({
|
|
2662
|
+
scriptName: sdkName,
|
|
2663
|
+
env: window.AirwallexComponentsSDK.__env__ || ENV.prod
|
|
2664
|
+
})];
|
|
2665
|
+
case 3:
|
|
2666
|
+
_a.sent();
|
|
2667
|
+
return [4 /*yield*/, window._AirwallexSDKs.__controller__.registerElement({
|
|
2668
|
+
sdkName: sdkName,
|
|
2669
|
+
elementName: elementName,
|
|
2670
|
+
instance: window._AirwallexSDKs[getWindowSDKInstanceName(sdkName)]
|
|
2671
|
+
})];
|
|
2672
|
+
case 4:
|
|
2673
|
+
_a.sent();
|
|
2674
|
+
return [4 /*yield*/, window._AirwallexSDKs.__controller__.createElement(elementName, options)];
|
|
2675
|
+
case 5:
|
|
2676
|
+
elementInstance = _a.sent();
|
|
2677
|
+
end = now();
|
|
2678
|
+
logInfo('[components-sdk] SDK createElement being called', {
|
|
2679
|
+
elementName: elementName,
|
|
2680
|
+
options: maskPII(options),
|
|
2681
|
+
start: start,
|
|
2682
|
+
latency: end - start,
|
|
2683
|
+
end: end
|
|
2684
|
+
});
|
|
2685
|
+
return [3 /*break*/, 7];
|
|
2686
|
+
case 6:
|
|
2687
|
+
error_1 = _a.sent();
|
|
2688
|
+
if (!error_1.code) {
|
|
2689
|
+
logError('[components-sdk] Unexpected errors when createElement', {
|
|
2690
|
+
error: error_1
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
else {
|
|
2694
|
+
throw error_1;
|
|
2695
|
+
}
|
|
2696
|
+
return [3 /*break*/, 7];
|
|
2697
|
+
case 7: return [2 /*return*/, elementInstance];
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
}); };
|
|
2701
|
+
|
|
2702
|
+
/**
|
|
2703
|
+
* List of scripts to prefetch
|
|
2704
|
+
*/
|
|
2705
|
+
var PREFETCH_SCRIPT_LIST = [SDK_CONTROLLER, PAYMENTS];
|
|
2706
|
+
/**
|
|
2707
|
+
* Prefetch scripts by preload link, only for production as there's no environment context before SDK init
|
|
2708
|
+
*/
|
|
2709
|
+
var prefetchScripts = function () {
|
|
2710
|
+
PREFETCH_SCRIPT_LIST.forEach(function (scriptName) {
|
|
2711
|
+
var url = getSDKUrl({ name: scriptName, env: ENV.prod });
|
|
2712
|
+
var preloadLink = document.createElement('link');
|
|
2713
|
+
preloadLink.href = url;
|
|
2714
|
+
preloadLink.rel = 'modulepreload';
|
|
2715
|
+
preloadLink.as = 'script';
|
|
2716
|
+
var parentDom = document.head || document.body;
|
|
2717
|
+
parentDom.appendChild(preloadLink);
|
|
2718
|
+
});
|
|
2719
|
+
};
|
|
2720
|
+
/**
|
|
2721
|
+
* @airwallex/components-sdk may run in node environment, e.g., in Next.js
|
|
2722
|
+
* Prefetch scripts only in browser environment
|
|
2723
|
+
*/
|
|
2724
|
+
var isNode = typeof document === 'undefined' || typeof window === 'undefined';
|
|
2725
|
+
if (!isNode) {
|
|
2726
|
+
if (document.readyState === 'loading') {
|
|
2727
|
+
document.addEventListener('DOMContentLoaded', prefetchScripts);
|
|
2728
|
+
}
|
|
2729
|
+
else {
|
|
2730
|
+
prefetchScripts();
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
if (typeof window !== 'undefined') {
|
|
2735
|
+
if (!window.AirwallexComponentsSDK) {
|
|
2736
|
+
Object.defineProperties(window, {
|
|
2737
|
+
AirwallexComponentsSDK: {
|
|
2738
|
+
value: {},
|
|
2739
|
+
writable: false
|
|
2740
|
+
},
|
|
2741
|
+
_AirwallexSDKs: {
|
|
2742
|
+
value: {},
|
|
2743
|
+
writable: false
|
|
2744
|
+
}
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
window.AirwallexComponentsSDK.init = init;
|
|
2748
|
+
window.AirwallexComponentsSDK.createElement = createElement;
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
const { onChange: airwallexStoreOnChange, reset: airwallexStoreReset, state: airwallexStore, } = createStore(() => ({
|
|
2752
|
+
clientSecret: null,
|
|
2753
|
+
currency: null,
|
|
2754
|
+
hasPaymentError: false,
|
|
2755
|
+
isReady: false,
|
|
2756
|
+
paymentConfirmed: false,
|
|
2757
|
+
paymentIntentId: null,
|
|
2758
|
+
}));
|
|
2759
|
+
/**
|
|
2760
|
+
* Populate the store from a collect checkout session response.
|
|
2761
|
+
*
|
|
2762
|
+
* @returns `true` when the session uses Airwallex and has the data required to
|
|
2763
|
+
* render the payment element.
|
|
2764
|
+
*/
|
|
2765
|
+
const airwallexStoreSetFromSession = (checkoutSession) => {
|
|
2766
|
+
if (checkoutSession.paymentProcessor !== 'AIRWALLEX') {
|
|
2767
|
+
return false;
|
|
2768
|
+
}
|
|
2769
|
+
// Only overwrite when the session provides a value — the client secret /
|
|
2770
|
+
// payment intent id may already have been seeded from the payment-intent
|
|
2771
|
+
// create response, which is more reliable than a follow-up session fetch.
|
|
2772
|
+
if (checkoutSession.clientSecret) {
|
|
2773
|
+
airwallexStore.clientSecret = checkoutSession.clientSecret;
|
|
2774
|
+
}
|
|
2775
|
+
if (checkoutSession.paymentIntentId) {
|
|
2776
|
+
airwallexStore.paymentIntentId = checkoutSession.paymentIntentId;
|
|
2777
|
+
}
|
|
2778
|
+
if (!airwallexStore.clientSecret) {
|
|
2779
|
+
logError$1('Airwallex checkout session is missing the client secret');
|
|
2780
|
+
return false;
|
|
2781
|
+
}
|
|
2782
|
+
return true;
|
|
2783
|
+
};
|
|
2784
|
+
/**
|
|
2785
|
+
* Map a Zonos locale to an Airwallex-supported locale. Locales without an
|
|
2786
|
+
* Airwallex equivalent (e.g. Norwegian, Vietnamese, Turkish, Hebrew) fall back
|
|
2787
|
+
* to English.
|
|
2788
|
+
*/
|
|
2789
|
+
const airwallexLocaleByCode = {
|
|
2790
|
+
ar: 'ar',
|
|
2791
|
+
da: 'da',
|
|
2792
|
+
de: 'de',
|
|
2793
|
+
en: 'en',
|
|
2794
|
+
es: 'es',
|
|
2795
|
+
fr: 'fr',
|
|
2796
|
+
id: 'id',
|
|
2797
|
+
it: 'it',
|
|
2798
|
+
ja: 'ja',
|
|
2799
|
+
ko: 'ko',
|
|
2800
|
+
nl: 'nl',
|
|
2801
|
+
pl: 'pl',
|
|
2802
|
+
pt: 'pt',
|
|
2803
|
+
ru: 'ru',
|
|
2804
|
+
sv: 'sv',
|
|
2805
|
+
zh: 'zh',
|
|
2806
|
+
};
|
|
2807
|
+
const airwallexStoreGetLocale = (locale) => airwallexLocaleByCode[locale] || 'en';
|
|
2808
|
+
// Ensure the SDK is only initialized once, even across re-renders/components.
|
|
2809
|
+
let initPromise = null;
|
|
2810
|
+
/**
|
|
2811
|
+
* Load and initialize the Airwallex components SDK (idempotent). Uses the `prod`
|
|
2812
|
+
* environment only when the API is in production and the checkout mode is `LIVE`
|
|
2813
|
+
* (mirrors how PayPal decides production vs. sandbox), otherwise `demo`, so the
|
|
2814
|
+
* SDK environment matches the payment intents created by the checkout backend.
|
|
2815
|
+
* Also uses the shopper's selected locale from localization.
|
|
2816
|
+
*
|
|
2817
|
+
* @returns `true` once the SDK is ready to create elements.
|
|
2818
|
+
*/
|
|
2819
|
+
const airwallexStoreInitSdk = async () => {
|
|
2820
|
+
if (airwallexStore.isReady) {
|
|
2821
|
+
return true;
|
|
2822
|
+
}
|
|
2823
|
+
if (!initPromise) {
|
|
2824
|
+
// Production only when the API is in production environment and the checkout
|
|
2825
|
+
// mode is `LIVE` (not sandbox) — same rule as the PayPal integration.
|
|
2826
|
+
const isProduction = (!zonosStore.zonosMode || zonosStore.zonosMode === 'production') &&
|
|
2827
|
+
zonosStore.checkoutSettings.mode === 'LIVE';
|
|
2828
|
+
initPromise = init({
|
|
2829
|
+
enabledElements: ['payments'],
|
|
2830
|
+
env: isProduction ? 'prod' : 'demo',
|
|
2831
|
+
locale: airwallexStoreGetLocale(localizationStore.selectedLocale),
|
|
2832
|
+
})
|
|
2833
|
+
.then(() => {
|
|
2834
|
+
airwallexStore.isReady = true;
|
|
2835
|
+
log('Airwallex SDK initialized');
|
|
2836
|
+
return true;
|
|
2837
|
+
})
|
|
2838
|
+
.catch((err) => {
|
|
2839
|
+
logError$1(err);
|
|
2840
|
+
// Allow a later retry by clearing the cached promise.
|
|
2841
|
+
initPromise = null;
|
|
2842
|
+
return false;
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
return initPromise;
|
|
2846
|
+
};
|
|
2847
|
+
/**
|
|
2848
|
+
* Statuses that mean the payment has gone through (or is on its way with no
|
|
2849
|
+
* further action required from the customer) — i.e. the order should move to the
|
|
2850
|
+
* finish step rather than render the payment form.
|
|
2851
|
+
*/
|
|
2852
|
+
const airwallexPaidStatuses = [
|
|
2853
|
+
'SUCCEEDED',
|
|
2854
|
+
'REQUIRES_CAPTURE',
|
|
2855
|
+
'PENDING_REVIEW',
|
|
2856
|
+
'PENDING',
|
|
2857
|
+
];
|
|
2858
|
+
/**
|
|
2859
|
+
* Whether the given status means the payment is settled or in progress (no
|
|
2860
|
+
* further customer action required).
|
|
2861
|
+
*/
|
|
2862
|
+
const airwallexStoreIsPaidStatus = (status) => !!status && airwallexPaidStatuses.includes(status);
|
|
2863
|
+
/**
|
|
2864
|
+
* Map an Airwallex payment intent status to a customer-facing message and an
|
|
2865
|
+
* error flag — the Airwallex equivalent of `stripeStoreMessageBasedOnStatus`.
|
|
2866
|
+
* @see https://www.airwallex.com/docs/payments/reference/payment-statuses
|
|
2867
|
+
*/
|
|
2868
|
+
const airwallexStoreMessageBasedOnStatus = (status) => {
|
|
2869
|
+
switch (status) {
|
|
2870
|
+
// The payment is complete.
|
|
2871
|
+
case 'SUCCEEDED': {
|
|
2872
|
+
return {
|
|
2873
|
+
isError: false,
|
|
2874
|
+
messages: [
|
|
2875
|
+
translate('Thank you for submitting your payment. We appreciate your prompt attention.'),
|
|
2876
|
+
'',
|
|
2877
|
+
translate('A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.'),
|
|
2878
|
+
],
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
// Authorized / pending the final result — no further action required.
|
|
2882
|
+
case 'PENDING':
|
|
2883
|
+
case 'PENDING_REVIEW':
|
|
2884
|
+
case 'REQUIRES_CAPTURE': {
|
|
2885
|
+
return {
|
|
2886
|
+
isError: false,
|
|
2887
|
+
messages: [
|
|
2888
|
+
translate("Payment processing. We'll update you when payment is received."),
|
|
2889
|
+
],
|
|
2890
|
+
};
|
|
2891
|
+
}
|
|
2892
|
+
// Waiting for further customer action (e.g. 3DS verification).
|
|
2893
|
+
case 'REQUIRES_CUSTOMER_ACTION': {
|
|
2894
|
+
return {
|
|
2895
|
+
isError: false,
|
|
2896
|
+
messages: [
|
|
2897
|
+
translate('Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.'),
|
|
2898
|
+
],
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
// Not paid (awaiting a payment method) or canceled.
|
|
2902
|
+
case 'CANCELLED':
|
|
2903
|
+
case 'REQUIRES_PAYMENT_METHOD': {
|
|
2904
|
+
return {
|
|
2905
|
+
isError: true,
|
|
2906
|
+
messages: [
|
|
2907
|
+
translate('Payment failed. Please reload the page and try another payment method.'),
|
|
2908
|
+
],
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
default: {
|
|
2912
|
+
return {
|
|
2913
|
+
isError: true,
|
|
2914
|
+
messages: [translate('Something went wrong.')],
|
|
2915
|
+
};
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
};
|
|
2919
|
+
/**
|
|
2920
|
+
* Retrieve the latest Airwallex payment intent status by id.
|
|
2921
|
+
*
|
|
2922
|
+
* @returns the status, or `null` when the lookup failed.
|
|
2923
|
+
*/
|
|
2924
|
+
const airwallexStoreRetrievePaymentIntent = async (paymentIntentId) => {
|
|
2925
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/collect/airwallex-payment-intent', {
|
|
2926
|
+
body: {
|
|
2927
|
+
paymentIntentId,
|
|
2928
|
+
},
|
|
2929
|
+
method: 'POST',
|
|
2930
|
+
});
|
|
2931
|
+
if (errors.length || !json) {
|
|
2932
|
+
logError$1('Failed to retrieve Airwallex payment intent', errors);
|
|
2933
|
+
return { status: null };
|
|
2934
|
+
}
|
|
2935
|
+
return { status: json.airwallexPaymentIntent.status };
|
|
2936
|
+
};
|
|
2937
|
+
|
|
2938
|
+
const { reset: collectStoreReset, state: collectStore } = createStore(() => ({
|
|
2939
|
+
amountDutyTaxFeeTotal: null,
|
|
2940
|
+
amountTotalPaid: null,
|
|
2941
|
+
collectLogoUrl: null,
|
|
2942
|
+
isFetchingShippingInfo: true,
|
|
2943
|
+
landedCostShortId: null,
|
|
2944
|
+
originCompanyName: null,
|
|
2945
|
+
partyBillingId: null,
|
|
2946
|
+
paymentProcessor: null,
|
|
2947
|
+
shippingAddress: null,
|
|
2948
|
+
}));
|
|
2949
|
+
const collectStoreInitShippingInfo = async ({ landedCostId, retries = 5, }) => {
|
|
2950
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2951
|
+
collectStore.isFetchingShippingInfo = true;
|
|
2952
|
+
const response = await handleFetch('/api/zonos-elements/collect/get-shipping-info-by-lc-id', {
|
|
2953
|
+
body: {
|
|
2954
|
+
landedCostId,
|
|
2955
|
+
},
|
|
2956
|
+
method: 'POST',
|
|
2957
|
+
});
|
|
2958
|
+
if (response.errors.length) {
|
|
2959
|
+
if (retries > 0) {
|
|
2960
|
+
// Wait for 1 second before retrying
|
|
2961
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
2962
|
+
// Keep retrying until we get the shipping address or we run out of retries
|
|
2963
|
+
return collectStoreInitShippingInfo({
|
|
2964
|
+
landedCostId,
|
|
2965
|
+
retries: retries - 1,
|
|
2966
|
+
});
|
|
2967
|
+
}
|
|
2968
|
+
return null;
|
|
2969
|
+
}
|
|
2970
|
+
collectStore.landedCostShortId = ((_a = response.json) === null || _a === void 0 ? void 0 : _a.landedCostShortId) || null;
|
|
2971
|
+
collectStore.isFetchingShippingInfo = false;
|
|
2972
|
+
collectStore.shippingAddress = ((_b = response.json) === null || _b === void 0 ? void 0 : _b.shipping) || null;
|
|
2973
|
+
const landedCost = (_c = cartStore.checkoutSession) === null || _c === void 0 ? void 0 : _c.landedCost;
|
|
2974
|
+
const checkoutSessionSubtotals = (_d = cartStore.checkoutSession) === null || _d === void 0 ? void 0 : _d.subtotals;
|
|
2975
|
+
const amountTotalPaid = (((_e = landedCost === null || landedCost === void 0 ? void 0 : landedCost.amountSubtotals) === null || _e === void 0 ? void 0 : _e.shipping) || 0) +
|
|
2976
|
+
(((_f = landedCost === null || landedCost === void 0 ? void 0 : landedCost.amountSubtotals) === null || _f === void 0 ? void 0 : _f.items) || 0);
|
|
2977
|
+
// Convert the amount to the presentment currency
|
|
2978
|
+
collectStore.amountTotalPaid =
|
|
2979
|
+
amountTotalPaid * (((_g = checkoutSessionSubtotals === null || checkoutSessionSubtotals === void 0 ? void 0 : checkoutSessionSubtotals.exchangeRate) === null || _g === void 0 ? void 0 : _g.rate) || 1);
|
|
2980
|
+
collectStore.amountDutyTaxFeeTotal =
|
|
2981
|
+
((checkoutSessionSubtotals === null || checkoutSessionSubtotals === void 0 ? void 0 : checkoutSessionSubtotals.duties) || 0) +
|
|
2982
|
+
((checkoutSessionSubtotals === null || checkoutSessionSubtotals === void 0 ? void 0 : checkoutSessionSubtotals.taxes) || 0) +
|
|
2983
|
+
((checkoutSessionSubtotals === null || checkoutSessionSubtotals === void 0 ? void 0 : checkoutSessionSubtotals.fees) || 0);
|
|
2984
|
+
collectStore.originCompanyName = ((_j = (_h = response.json) === null || _h === void 0 ? void 0 : _h.origin) === null || _j === void 0 ? void 0 : _j.companyName) || null;
|
|
2985
|
+
collectStore.collectLogoUrl = ((_k = response.json) === null || _k === void 0 ? void 0 : _k.collectLogoUrl) || null;
|
|
2986
|
+
if (collectStore.amountTotalPaid === 0) {
|
|
2987
|
+
void sendErrorLog({
|
|
2988
|
+
endpoint: 'COLLECT_NO_TOTAL_PAID',
|
|
2989
|
+
errors: [],
|
|
2990
|
+
metadata: {
|
|
2991
|
+
landedCostId,
|
|
2992
|
+
organizationId: zonosStore.organizationId,
|
|
2993
|
+
},
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
};
|
|
2997
|
+
const collectStoreAsyncAddressUpdate = async () => {
|
|
2998
|
+
var _a, _b, _c, _d;
|
|
2999
|
+
if (!((_a = stripeStore.stripeBillingAddressEventData) === null || _a === void 0 ? void 0 : _a.complete)) {
|
|
3000
|
+
return {
|
|
3001
|
+
partiesCreated: false,
|
|
3002
|
+
};
|
|
3003
|
+
}
|
|
3004
|
+
const landedCostRootId = (_c = (_b = cartStore.checkoutSession) === null || _b === void 0 ? void 0 : _b.landedCost) === null || _c === void 0 ? void 0 : _c.rootId;
|
|
3005
|
+
if (!landedCostRootId) {
|
|
3006
|
+
// do nothing if we don't have selected landed cost
|
|
3007
|
+
void sendErrorLog({
|
|
3008
|
+
endpoint: 'PF_NO_SELECTED_LANDED_COST',
|
|
3009
|
+
errors: ['No selected landed cost'],
|
|
3010
|
+
metadata: {
|
|
3011
|
+
allLogs,
|
|
3012
|
+
cartId: window.Zonos.cartId,
|
|
3013
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
3014
|
+
},
|
|
3015
|
+
});
|
|
3016
|
+
return {
|
|
3017
|
+
partiesCreated: false,
|
|
3018
|
+
};
|
|
3019
|
+
}
|
|
3020
|
+
if (!storageStore.checkoutSessionId) {
|
|
3021
|
+
void sendErrorLog({
|
|
3022
|
+
endpoint: 'COLLECT_NO_CHECKOUT_SESSION_ID',
|
|
3023
|
+
errors: ['No checkout session id'],
|
|
3024
|
+
metadata: {
|
|
3025
|
+
allLogs,
|
|
3026
|
+
cartId: window.Zonos.cartId,
|
|
3027
|
+
landedCostRootId,
|
|
3028
|
+
},
|
|
3029
|
+
});
|
|
3030
|
+
return {
|
|
3031
|
+
partiesCreated: false,
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
const billingAddress = stripeStoreBuildAddressForPartyCreate({
|
|
3035
|
+
address: stripeStore.stripeBillingAddressEventData.value.address,
|
|
3036
|
+
firstName: stripeStore.stripeBillingAddressEventData.value.firstName,
|
|
3037
|
+
lastName: stripeStore.stripeBillingAddressEventData.value.lastName,
|
|
3038
|
+
name: stripeStore.stripeBillingAddressEventData.value.name,
|
|
3039
|
+
phone: stripeStore.stripeBillingAddressEventData.value.phone,
|
|
3040
|
+
});
|
|
3041
|
+
const isE2ETest = new URLSearchParams(window.location.search).get('zonosE2ETest') === '1';
|
|
3042
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-billing-party', {
|
|
3043
|
+
body: {
|
|
3044
|
+
billingAddress,
|
|
3045
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
3046
|
+
companyName: stripeStore.companyName,
|
|
3047
|
+
email: ((_d = stripeStore.stripeLinkEventData) === null || _d === void 0 ? void 0 : _d.value.email) || '',
|
|
3048
|
+
isTest: isE2ETest,
|
|
3049
|
+
rootId: landedCostRootId,
|
|
3050
|
+
},
|
|
3051
|
+
method: 'POST',
|
|
3052
|
+
});
|
|
3053
|
+
if (errors.length || !json) {
|
|
3054
|
+
logError$1('Error occurs when creating billing party', JSON.stringify(errors, null, 2));
|
|
3055
|
+
void sendErrorLog({
|
|
3056
|
+
endpoint: 'COLLECT_BILLING_PARTY_CREATE_FAILED',
|
|
3057
|
+
errors: ['[COLLECT] Failed to create billing party'],
|
|
3058
|
+
metadata: {
|
|
3059
|
+
allLogs,
|
|
3060
|
+
cartId: window.Zonos.cartId,
|
|
3061
|
+
checkoutSessionId: storageStore.checkoutSessionId,
|
|
3062
|
+
errors,
|
|
3063
|
+
json,
|
|
3064
|
+
},
|
|
3065
|
+
});
|
|
3066
|
+
return {
|
|
3067
|
+
partiesCreated: false,
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
collectStore.partyBillingId = json.billToPartyId;
|
|
3071
|
+
return {
|
|
3072
|
+
partiesCreated: true,
|
|
3073
|
+
};
|
|
3074
|
+
};
|
|
3075
|
+
const collectStoreUpdateSelectedShippingOption = async (checkoutSession) => {
|
|
3076
|
+
const landedCost = checkoutSession.landedCost;
|
|
3077
|
+
if (!landedCost) {
|
|
3078
|
+
return false;
|
|
3079
|
+
}
|
|
3080
|
+
// Convert the landed cost to the format that cartStore expects
|
|
3081
|
+
cartStore.landedCostData = [
|
|
3082
|
+
Object.assign(Object.assign({}, checkoutSession), { landedCost: Object.assign({}, landedCost), landedCostId: landedCost.id }),
|
|
3083
|
+
];
|
|
3084
|
+
return cartStoreUpdateSelectedShippingOption({
|
|
3085
|
+
// No need to update checkout session again, we already called it when starting collect, only need to apply subtotals here to utilize the cart store
|
|
3086
|
+
applySubtotalsOnly: true,
|
|
3087
|
+
landedCostId: landedCost.id,
|
|
3088
|
+
selectedShippingOption: landedCost.shipmentRating,
|
|
3089
|
+
});
|
|
3090
|
+
};
|
|
3091
|
+
|
|
3092
|
+
export { airwallexStoreSetFromSession as a, airwallexStore as b, collectStore as c, airwallexStoreRetrievePaymentIntent as d, airwallexStoreIsPaidStatus as e, airwallexStoreInitSdk as f, collectStoreUpdateSelectedShippingOption as g, collectStoreInitShippingInfo as h, collectStoreAsyncAddressUpdate as i, airwallexStoreMessageBasedOnStatus as j, airwallexStoreReset as k, createElement as l, airwallexStoreGetLocale as m, airwallexStoreOnChange as n };
|