@ikas/storefront 2.0.20 → 2.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/build/__generated__/global-types.d.ts +5 -0
  2. package/build/_virtual/index.js_commonjs-proxy2.js +1 -1
  3. package/build/_virtual/index.js_commonjs-proxy4.js +1 -1
  4. package/build/api/blog/__generated__/getBlog.d.ts +5 -1
  5. package/build/api/blog/__generated__/listBlog.d.ts +5 -1
  6. package/build/api/blog/__generated__/listBlogCategory.d.ts +5 -1
  7. package/build/api/blog/__generated__/listBlogMetaData.d.ts +5 -1
  8. package/build/api/cart/__generated__/getCart.d.ts +4 -2
  9. package/build/api/cart/__generated__/saveItemToCart.d.ts +4 -2
  10. package/build/api/checkout/__generated__/getCheckoutById.d.ts +4 -2
  11. package/build/api/checkout/__generated__/getOrder.d.ts +11 -5
  12. package/build/api/customer/__generated__/createOrderRefundRequest.d.ts +11 -5
  13. package/build/api/customer/__generated__/customerLogin.d.ts +2 -1
  14. package/build/api/customer/__generated__/customerSocialLogin.d.ts +2 -1
  15. package/build/api/customer/__generated__/getCustomerOrders.d.ts +11 -5
  16. package/build/api/customer/__generated__/getMyCustomer.d.ts +2 -1
  17. package/build/api/customer/__generated__/registerCustomer.d.ts +2 -1
  18. package/build/api/customer/__generated__/saveMyCustomer.d.ts +2 -1
  19. package/build/api/customer-review/__generated__/listCustomerReviews.d.ts +5 -1
  20. package/build/api/html-meta-data/__generated__/listHTMLMetaData.d.ts +10 -0
  21. package/build/api/html-meta-data/index.js +1 -1
  22. package/build/api/index.d.ts +1 -1
  23. package/build/api/{product-campanign → product-campaign}/__generated__/getProductCampaigns.d.ts +1 -0
  24. package/build/api/{product-campanign → product-campaign}/index.d.ts +0 -0
  25. package/build/api/product-campaign/index.js +1 -0
  26. package/build/api/raffle/__generated__/listRaffle.d.ts +5 -1
  27. package/build/api/variant-type/__generated__/listVariantType.d.ts +6 -2
  28. package/build/components/checkout/components/address-form/model.js +1 -1
  29. package/build/components/checkout/model.js +1 -1
  30. package/build/components/page-editor/model.js +1 -1
  31. package/build/ikas.js +1 -1
  32. package/build/models/data/product/variant/index.js +1 -1
  33. package/build/models/data/product-campaing/campaign/index.d.ts +1 -1
  34. package/build/models/data/product-campaing/campaign/index.js +1 -1
  35. package/build/models/ui/blog-category-list/index.js +1 -1
  36. package/build/models/ui/blog-list/index.js +1 -1
  37. package/build/models/ui/brand-list/index.js +1 -1
  38. package/build/models/ui/category-list/index.js +1 -1
  39. package/build/models/ui/customer-review-list/index.js +1 -1
  40. package/build/models/ui/product-detail/index.js +1 -1
  41. package/build/models/ui/product-list/index.js +1 -1
  42. package/build/models/ui/raffle-list/index.js +1 -1
  43. package/build/models/ui/validator/form/address.js +1 -1
  44. package/build/pages/checkout.js +1 -1
  45. package/build/providers/helpers/raffles.js +1 -1
  46. package/build/providers/page-data-get.js +1 -1
  47. package/build/providers/page-data-next.js +1 -1
  48. package/build/providers/prop-value/attribute-list.js +1 -1
  49. package/build/providers/prop-value/attribute.js +1 -1
  50. package/build/providers/prop-value/blog-category.js +1 -1
  51. package/build/providers/prop-value/blog.js +1 -1
  52. package/build/providers/prop-value/brand.js +1 -1
  53. package/build/providers/prop-value/category.js +1 -1
  54. package/build/providers/prop-value/product-detail.js +1 -1
  55. package/build/providers/prop-value/raffle.js +1 -1
  56. package/build/store/base.js +1 -1
  57. package/build/store/cart.js +1 -1
  58. package/build/store/customer.js +1 -1
  59. package/package.json +1 -1
  60. package/build/api/product-campanign/index.js +0 -1
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as i}from'../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from'../../ext/lodash/cloneDeep.js';import r from'../../ext/lodash/sortBy.js';import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import"../../models/data/category/index.js";import{IkasCheckout as o,IkasCheckoutCustomer as a}from"../../models/data/checkout/index.js";import{IkasCustomerAddress as c}from"../../models/data/customer/address/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-review/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/installment-info/index.js";import"../../models/data/order/index.js";import"../../models/data/order/line-item/index.js";import"../../api/product-option-file/index.js";import"../../models/data/product/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product-attribute/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product-filter/index.js";import"../../models/data/variant-type/variant-value/index.js";import{IkasTransactionStatusEnum as d}from"../../models/data/order-transaction/index.js";import"../../models/data/product-option-set/index.js";import"../../models/data/raffle/index.js";import"../../models/data/product-campaing/campaign/index.js";import"../../models/theme/theme.js";import"../../models/theme/page/index.js";import"../../models/theme/component/prop/index.js";import"../../models/theme/page/component/prop-value/link.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-detail/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import"../../models/theme/settings/index.js";import"../../models/theme/custom-data/index.js";import{IkasOrderAddress as u}from"../../models/data/order/address/index.js";import{IkasPaymentMethodType as h,IkasPaymentGatewayType as l}from"../../models/data/payment-gateway/index.js";import"../../api/blog/index.js";import"../../api/brand/index.js";import"../../api/cart/index.js";import"../../api/category/index.js";import{IkasCheckoutAPI as p}from"../../api/checkout/index.js";import"../../api/city/index.js";import{IkasCountryAPI as m}from"../../api/country/index.js";import{IkasCustomerAPI as f}from"../../api/customer/index.js";import"../../api/customer-review/index.js";import"../../api/district/index.js";import"../../api/html-meta-data/index.js";import{IkasMerchantAPI as g}from"../../api/merchant/index.js";import"../../api/product-search/index.js";import"../../api/apollo.js";import"../../api/favorite-product/index.js";import"../../api/contact-form/index.js";import"../../api/state/index.js";import"../../api/product-option-set/index.js";import"../../api/raffle/index.js";import"../../api/back-in-stock-reminder/index.js";import"../../api/product-campanign/index.js";import v from"./components/credit-card-form/model.js";import{IkasStorefrontConfig as S}from"../../storefront/index.js";import{IkasCheckoutSettings as k}from"../../models/data/checkout-settings/index.js";import{Analytics as y}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import C from'../../ext/uuid/dist/esm-browser/v4.js';var b,I,P=/^\d+$/,A="undefined"==typeof localStorage,j=function(){function P(P,j,w,x,E,O,T,D){var G=this;this.checkout=new o,this.checkoutSettings=new k,this.storefront=null,this.store=S.store,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.step=b.INFO,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!1,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.policyModalTitle="",this.policyModalText="",this.error=null,this.init=function(){return t(G,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.store.customerStore.waitUntilInitialized()];case 1:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getMerchantSettings()];case 2:return t.sent(),[4,this.initStep()];case 3:return t.sent(),[2]}}))}))},this.initStep=function(){return t(G,void 0,void 0,(function(){var t,i,s,n,r,o,a;return e(this,(function(e){switch(e.label){case 0:if(S.isEditor)return this.step=b.INFO,this.isCheckoutLoaded=!0,[2];if(t=new URLSearchParams(window.location.search),i=t.get("step"),s=t.get("failed"),n=t.get("error"),i){if(this.step=i,this.step===b.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(b.INFO)];if(this.step===b.PAYMENT&&!this.canProceedToPayment)return[2,this.changeStep(b.INFO)];if(![b.INFO,b.SUCCESS,b.SHIPPING,b.PAYMENT].includes(this.step))return[2,this.changeStep(b.INFO)]}return s&&(this.error={type:I.PAYMENT_ERROR,data:n||null}),this.step!==b.INFO?[3,2]:[4,this.getShippingCountries()];case 1:e.sent(),this.checkShippingCountries(),e.label=2;case 2:return this.step!==b.SHIPPING||1!==this.checkout.availableShippingMethods.length||this.checkoutSettings.isGiftPackageEnabled||(this.step=b.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==b.SHIPPING||this.checkout.availableShippingMethods.length?this.step!==b.PAYMENT&&this.step!==b.SUCCESS?[3,4]:[4,this.listPaymentGateways()]:(this.error={type:I.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 3:if(e.sent(),!this.paymentGateways.length)return this.error={type:I.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];e.label=4;case 4:return this.step===b.SUCCESS?[3,8]:this.checkout.isComplete?[2,this.changeStep(b.SUCCESS)]:[3,5];case 5:return[4,this.initialStockCheck()];case 6:e.sent(),e.label=7;case 7:return[3,11];case 8:return r=this,[4,p.getOrder(this.checkout.orderId)];case 9:return r.order=e.sent(),[4,f.getOrderTransactions({orderId:this.checkout.orderId})];case 10:o=e.sent(),this.successTransaction=o.length?o[0]:void 0,this.successTransaction&&(a=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(t){return t.id===a}))),e.label=11;case 11:return this.isCheckoutLoaded=!0,y.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getMerchantSettings=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.merchantSettings?[3,2]:(t=this,[4,g.listMerchantSettings()]);case 1:t.merchantSettings=e.sent(),e.label=2;case 2:return[2]}}))}))},this.saveCheckout=function(){return t(G,void 0,void 0,(function(){var t,i,s;return e(this,(function(e){switch(e.label){case 0:return[4,p.saveCheckout(this.checkout)];case 1:if((null==(t=e.sent())?void 0:t.errors)&&t.errors.length)throw i=t.errors[0],"CUSTOMER_LOGIN_REQUIRED"===(null===(s=i.extensions)||void 0===s?void 0:s.code)?{type:I.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:I.API_ERROR};return[2]}}))}))},this.checkStocks=function(){return t(G,void 0,void 0,(function(){var t,i,s,n,r,o,a,c,d,u,h;return e(this,(function(e){switch(e.label){case 0:return t=this.cart.items.map((function(t){return{quantity:t.quantity,variantId:t.variant.id,productId:t.variant.productId}})),[4,p.checkStocks(t,S.stockLocationIds||[])];case 1:if(!(i=e.sent()))throw{type:I.API_ERROR};if(null==(s=null===(u=i.lines)||void 0===u?void 0:u.filter((function(t){return!t.isAvailable})))?void 0:s.length){for(n=[],r=function(t){var e=null===(h=o.store.cartStore.cart)||void 0===h?void 0:h.items.find((function(e){return e.variant.id===t.variantId}));e&&n.push(e)},o=this,a=0,c=s;a<c.length;a++)d=c[a],r(d);throw{type:I.STOCK_ERROR,data:n}}return[2]}}))}))},this.removeUnavailableItems=function(i){return t(G,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:t=0,s=i,e.label=1;case 1:return t<s.length?(n=s[t],[4,this.store.cartStore.removeItem(n)]):[3,4];case 2:e.sent(),e.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=this,[4,m.listShippingCountries(S.salesChannelId)];case 1:return t.shippingCountryIds=e.sent(),[2]}}))}))},this.checkShippingCountries=function(){var t;(null===(t=G.shippingCountryIds)||void 0===t?void 0:t.length)||(G.error={type:I.NO_SHIPPING_ERROR})},this.initialStockCheck=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return e.sent(),[3,3];case 2:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:I.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return t(G,void 0,void 0,(function(){var t,i,s,n,o,a,c=this;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,i=S.paymentGateways.map((function(t){return t.id})),[4,p.listPaymentGateway(t?void 0:i)];case 1:return(s=e.sent())&&s.length?(this.step===b.PAYMENT&&(s=s.filter((function(t){return!t.supportedCurrencies.length||t.supportedCurrencies.includes(c.checkout.cart.currencyCode)})),(n=null===(a=this.checkout.shippingAddress)||void 0===a?void 0:a.country)&&n.iso2&&(s=s.filter((function(t){return!t.availableCountries.length||t.availableCountries.includes(n.iso2||"")})))),o=[],r(S.paymentGateways,"order").forEach((function(t){var e=null==s?void 0:s.find((function(e){return e.id===t.id}));e&&o.push(e)})),this.paymentGateways=t?s:o,this.checkout.selectedPaymentGateway||this.setPaymentGateway(0),[2]):(this.error={type:I.API_ERROR},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,p.retrieveInstallmentInfo(i)];case 1:return null==(t=e.sent())||t.installmentPrices.sort((function(t,e){return(t.installmentCount||-1)>(e.installmentCount||-1)?1:-1})),this.installmentInfo=t,[2]}}))}))},this.createCustomer=function(){G.store.customerStore.customer?(G.store.customerStore.customer.addresses.forEach((function(t){return t.checkoutSettings=G.checkoutSettings})),G.checkout.customer=new a(G.store.customerStore.customer)):G.checkout.customer||(G.checkout.customer=new a({}))},this.createShippingAddress=function(){var t;if(G.checkout.shippingAddress)G.selectedShippingAddressId=G.checkout.shippingAddress.id||"-1",G.checkout.shippingAddress.checkoutSettings=G.checkoutSettings;else{var e=null===(t=G.store.customerStore.customer)||void 0===t?void 0:t.addresses;G.onSelectedShippingAddressIdChange((null==e?void 0:e.length)?e[0].id:"-1")}},this.createBillingAddress=function(){"undefined"!=typeof localStorage&&(G.useDifferentAddress=!!localStorage.getItem("sAddr"),G.useDifferentAddress?(G.checkout.billingAddress&&(G.selectedBillingAddressId=G.checkout.billingAddress.id||"-1"),G.checkout.billingAddress=G.checkout.billingAddress||new u):G.checkout.billingAddress=new u(n(G.checkout.shippingAddress)||{}),G.checkout.billingAddress.checkoutSettings=G.checkoutSettings)},this.onShippingMethodChange=function(i){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.isChangingShippingMethod?[2]:(this.isChangingShippingMethod=!0,this.checkout.shippingSettingsId=i.shippingSettingsId,this.checkout.shippingZoneRateId=i.shippingZoneRateId,[4,this.saveCheckout()]);case 1:return e.sent(),[4,p.getCheckoutById(this.checkout.id)];case 2:return(t=e.sent())&&(this.checkout=t),this.isChangingShippingMethod=!1,[2]}}))}))},this.onCouponCodeApply=function(){return t(G,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:if(!this.checkout.couponCode)return[2];e.label=1;case 1:return e.trys.push([1,5,,6]),[4,p.addCouponCodeToCheckout(this.checkout.id,this.checkout.couponCode)];case 2:return e.sent()?[4,p.getCheckoutById(this.checkout.id)]:[3,4];case 3:(t=e.sent())&&(s=this.checkout,this.checkout=new o(i(i({},t),{shippingAddress:s.shippingAddress,billingAddress:s.billingAddress,customer:s.customer}))),e.label=4;case 4:return[3,6];case 5:return e.sent(),[3,6];case 6:return[2]}}))}))},this.onCouponCodeDelete=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,this.saveCheckout()];case 1:return e.sent(),[4,p.getCheckoutById(this.checkout.id)];case 2:return(t=e.sent())&&(this.checkout=t),[3,4];case 3:return e.sent(),[3,4];case 4:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(t){var e;if(G.selectedShippingAddressId=t,"-1"===t)G.checkout.shippingAddress=new u;else{var i=null===(e=G.store.customerStore.customer)||void 0===e?void 0:e.addresses.find((function(e){return e.id===t}));i&&(G.checkout.shippingAddress=new u(i))}G.checkout.shippingAddress&&(G.checkout.shippingAddress.checkoutSettings=G.checkoutSettings)},this.onSelectedBillingAddressIdChange=function(t){var e;if(G.selectedBillingAddressId=t,"-1"===t)G.checkout.billingAddress=new u;else{var i=null===(e=G.store.customerStore.customer)||void 0===e?void 0:e.addresses.find((function(e){return e.id===t}));i&&(G.checkout.billingAddress=new u(i))}G.checkout.billingAddress&&(G.checkout.billingAddress.checkoutSettings=G.checkoutSettings)},this.onTermsAndConditionsCheckedChange=function(t){G.isTermsAndConditionsChecked=t},this.onCardNumberChange=function(t){if(G.cardData&&(!(t.length>G.cardData.cardNumber.length)||N(t))){var e=(G.cardData.cardNumber||"").split(" ").join(""),i=t.split(" ").join("");i.length>16||(e.length<6&&i.length>=6&&!G.installmentInfo?G.retrieveInstallmentInfo({binNumber:i.slice(0,6),paymentGatewayId:G.checkout.selectedPaymentGateway.id,price:G.checkout.totalFinalPrice}):i.length<6&&e.length>i.length&&(G.cardData.installmentCount=1,G.installmentInfo=void 0),G.cardData.cardNumber=R(i,4).join(" "))}},this.onCardHolderNameChange=function(t){G.cardData&&(G.cardData.cardHolderName=t)},this.onExpirationDateChange=function(t){var e;if(G.cardData&&(!(t.length>G.cardData.expirationDate.length)||N(t))){if(0===(null===(e=G.cardData.expirationDate)||void 0===e?void 0:e.length)){var i=t.split("/");if(2===i.length){var s=i[0].trim(),n=i[1].trim();if(4===s.length&&2===n.length){var r=parseInt(s.slice(2)),o=parseInt(n);if(!isNaN(r)&&!isNaN(o))return void(G.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&4===n.length){o=parseInt(s),r=parseInt(n.slice(2));if(!isNaN(r)&&!isNaN(o))return void(G.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var a=t.split(" / ").join("");a.length>4||(G.cardData.expirationDate=R(a,2).join(" / "))}},this.onCvcChange=function(t){G.cardData&&(t.length>G.cardData.cvv.length&&!N(t)||t.length>4||(G.cardData.cvv=t))},this.saveAddress=function(s){return t(G,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return this.shouldSaveAddress?(t=new c(i(i({},"shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress),{title:this.addressTitle||this.t("checkout-page:newAddress"),id:C()})),(r=n(this.store.customerStore.customer)).addresses.push(t),[4,this.store.customerStore.saveCustomer(r)]):[3,2];case 1:e.sent(),"shipping"===s?(this.checkout.shippingAddress.id=t.id,this.selectedShippingAddressId=t.id||"-1"):(this.checkout.billingAddress.id=t.id,this.selectedBillingAddressId=t.id||"-1"),e.label=2;case 2:return[2]}}))}))},this.onGoToCartClick=function(){G.router.push("/cart")},this.onBackToShoppingClick=function(){G.router.push("/")},this.onProceedToShippingClick=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canProceedToShipping)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,e.label=1;case 1:return e.trys.push([1,5,,6]),this.isStepLoading=!0,[4,this.saveAddress("shipping")];case 2:return e.sent(),[4,this.checkStocks()];case 3:return e.sent(),[4,this.saveCheckout()];case 4:return e.sent(),this.changeStep(b.SHIPPING),[3,6];case 5:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:I.UNKNOWN}),this.isStepLoading=!1,[3,6];case 6:return[2]}}))}))},this.onProceedToPaymentClick=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,e.label=1;case 1:return e.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),[4,this.saveCheckout()];case 3:return e.sent(),this.error=void 0,this.changeStep(b.PAYMENT),[3,5];case 4:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:I.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onCompletePaymentClick=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canPerformPayment)return this.isErrorsVisible=!0,[2];this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),e.label=1;case 1:return e.trys.push([1,6,,7]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),[4,this.saveAddress("billing")];case 3:return e.sent(),[4,this.saveCheckout()];case 4:return e.sent(),[4,this.createSaleTransaction()];case 5:return e.sent(),[3,7];case 6:return(t=e.sent()).type?this.error=t:this.error={type:I.UNKNOWN},this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.createSaleTransaction=function(){return t(G,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?[4,p.createSaleTransactionWithCheckout(this.checkout.id,this.checkout.selectedPaymentGateway.id,this.checkout.selectedPaymentGateway.paymentMethodType===h.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===l.INTERNAL&&this.cardData?this.cardData.toInput():void 0)]:[2];case 1:return t=e.sent(),i=null==t?void 0:t.transactionStatus,s=i&&[d.SUCCESS,d.AUTHORIZED].includes(i),n=i===d.PENDING,s?[4,this.onCheckoutTransactionSuccess()]:[3,3];case 2:return e.sent(),[3,4];case 3:if(!n||!(null==t?void 0:t.returnSlug))throw{type:I.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+t.returnSlug,e.label=4;case 4:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return t(G,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return localStorage.removeItem("sAddr"),(null===(t=this.checkout.customer)||void 0===t?void 0:t.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(i=this.checkout.customer)||void 0===i?void 0:i.email)||"")]:[3,2];case 1:e.sent(),e.label=2;case 2:return this.changeStep(b.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){G.changeStep(b.INFO)},this.onBackToShippingClick=function(){G.changeStep(b.SHIPPING)},this.setCustomerConsentGranted=function(t){G.checkout.customer&&(G.checkout.customer.notificationsAccepted=t)},this.setUseDifferentAddress=function(t){G.useDifferentAddress=t,G.useDifferentAddress?(localStorage.setItem("sAddr","1"),G.checkout.billingAddress=G.checkout.billingAddress||new u):(localStorage.removeItem("sAddr"),G.checkout.billingAddress=G.checkout.shippingAddress)},this.setShouldSaveAddress=function(t){G.shouldSaveAddress=t},this.setAddressTitle=function(t){G.addressTitle=t},this.setPaymentGateway=function(t){if(G.paymentGateways.length){var e=G.paymentGateways[t];G.checkout.selectedPaymentGateway=e,G.step!==b.SUCCESS&&(e.paymentMethodType===h.CREDIT_CARD&&e.type===l.INTERNAL&&(G.cardData=new v),G.installmentInfo=void 0)}},this.setInstallmentCount=function(t){G.cardData&&(G.cardData.installmentCount=t)},this.changeStep=function(i){return t(G,void 0,void 0,(function(){return e(this,(function(t){return A||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return t(G,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:this.checkout.customer=void 0,this.store.customerStore.logout(),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.saveCheckout()];case 2:case 3:return t.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(t){G.isContactModalVisible=t},this.checkout=P,this.checkoutSettings=j,this.router=x,this.returnPolicy=E,this.privacyPolicy=O,this.termsOfService=T,this.t=D,w&&(this.merchantSettings=w),this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked,this.store.cartStore.cart=this.checkout.cart,this.init(),s(this)}return Object.defineProperty(P.prototype,"cart",{get:function(){return this.checkout.cart},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"selectedPaymentGatewayIndex",{get:function(){var t=this;return this.paymentGateways.findIndex((function(e){var i;return e.id===(null===(i=t.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"selectedInstallmentIndex",{get:function(){var t,e=this;return(null===(t=this.installmentInfo)||void 0===t?void 0:t.installmentPrices.findIndex((function(t){var i;return t.installmentCount===(null===(i=e.cardData)||void 0===i?void 0:i.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"customerAddressOptions",{get:function(){var t,e={label:this.t("checkout-page:newAddress"),value:"-1"},i=(null===(t=this.store.customerStore.customer)||void 0===t?void 0:t.addresses.map((function(t){return{label:t.title+" - "+t.addressText,value:t.id}})))||[];return[e].concat(i)},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"installmentPrice",{get:function(){var t,e,i=this;if(this.installmentInfo&&(null===(t=this.cardData)||void 0===t?void 0:t.installmentCount))return null===(e=this.installmentInfo.installmentPrices.find((function(t){var e;return t.installmentCount===(null===(e=i.cardData)||void 0===e?void 0:e.installmentCount)})))||void 0===e?void 0:e.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"finalPrice",{get:function(){return this.step===b.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"hasStockError",{get:function(){var t;return(null===(t=this.error)||void 0===t?void 0:t.type)===I.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"canProceedToShipping",{get:function(){var t,e;return(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValid)&&this.checkout.hasValidCustomer&&(null===(e=this.error)||void 0===e?void 0:e.type)!==I.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"canPerformPayment",{get:function(){var t,e;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway;return this.canProceedToShipping&&!!(null===(t=this.checkout.billingAddress)||void 0===t?void 0:t.isValid)&&((null==i?void 0:i.paymentMethodType)!==h.CREDIT_CARD||i.type!==l.INTERNAL||(null===(e=this.cardData)||void 0===e?void 0:e.isValid))},enumerable:!1,configurable:!0}),P}();function R(t,e){return t.match(new RegExp(".{1,"+e+"}","g"))||[]}function N(t){return t&&P.test(t.charAt(t.length-1))}!function(t){t.INFO="info",t.SHIPPING="shipping",t.PAYMENT="payment",t.SUCCESS="success"}(b||(b={})),function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.API_ERROR=1]="API_ERROR",t[t.STOCK_ERROR=2]="STOCK_ERROR",t[t.PAYMENT_ERROR=3]="PAYMENT_ERROR",t[t.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",t[t.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR"}(I||(I={}));export{b as CheckoutStep,I as ErrorType,j as default};
1
+ import{__awaiter as t,__generator as e,__assign as i}from'../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from'../../ext/lodash/cloneDeep.js';import r from'../../ext/lodash/sortBy.js';import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import"../../models/data/category/index.js";import{IkasCheckout as o,IkasCheckoutCustomer as a}from"../../models/data/checkout/index.js";import{IkasCustomerAddress as c}from"../../models/data/customer/address/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-review/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/installment-info/index.js";import"../../models/data/order/index.js";import"../../models/data/order/line-item/index.js";import"../../api/product-option-file/index.js";import"../../models/data/product/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product-attribute/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product-filter/index.js";import"../../models/data/variant-type/variant-value/index.js";import{IkasTransactionStatusEnum as d}from"../../models/data/order-transaction/index.js";import"../../models/data/product-option-set/index.js";import"../../models/data/raffle/index.js";import"../../models/data/product-campaing/campaign/index.js";import"../../models/theme/theme.js";import"../../models/theme/page/index.js";import"../../models/theme/component/prop/index.js";import"../../models/theme/page/component/prop-value/link.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-detail/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import"../../models/theme/settings/index.js";import"../../models/theme/custom-data/index.js";import{IkasOrderAddress as u}from"../../models/data/order/address/index.js";import{IkasPaymentMethodType as h,IkasPaymentGatewayType as l}from"../../models/data/payment-gateway/index.js";import"../../api/blog/index.js";import"../../api/brand/index.js";import"../../api/cart/index.js";import"../../api/category/index.js";import{IkasCheckoutAPI as p}from"../../api/checkout/index.js";import"../../api/city/index.js";import{IkasCountryAPI as m}from"../../api/country/index.js";import{IkasCustomerAPI as f}from"../../api/customer/index.js";import"../../api/customer-review/index.js";import"../../api/district/index.js";import"../../api/html-meta-data/index.js";import{IkasMerchantAPI as g}from"../../api/merchant/index.js";import"../../api/product-search/index.js";import"../../api/apollo.js";import"../../api/favorite-product/index.js";import"../../api/contact-form/index.js";import"../../api/state/index.js";import"../../api/product-option-set/index.js";import"../../api/raffle/index.js";import"../../api/back-in-stock-reminder/index.js";import"../../api/product-campaign/index.js";import v from"./components/credit-card-form/model.js";import{IkasStorefrontConfig as S}from"../../storefront/index.js";import{IkasCheckoutSettings as k}from"../../models/data/checkout-settings/index.js";import{Analytics as y}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import C from'../../ext/uuid/dist/esm-browser/v4.js';var b,I,P=/^\d+$/,A="undefined"==typeof localStorage,j=function(){function P(P,j,w,x,E,O,T,D){var G=this;this.checkout=new o,this.checkoutSettings=new k,this.storefront=null,this.store=S.store,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.step=b.INFO,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!1,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.policyModalTitle="",this.policyModalText="",this.error=null,this.init=function(){return t(G,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.store.customerStore.waitUntilInitialized()];case 1:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getMerchantSettings()];case 2:return t.sent(),[4,this.initStep()];case 3:return t.sent(),[2]}}))}))},this.initStep=function(){return t(G,void 0,void 0,(function(){var t,i,s,n,r,o,a;return e(this,(function(e){switch(e.label){case 0:if(S.isEditor)return this.step=b.INFO,this.isCheckoutLoaded=!0,[2];if(t=new URLSearchParams(window.location.search),i=t.get("step"),s=t.get("failed"),n=t.get("error"),i){if(this.step=i,this.step===b.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(b.INFO)];if(this.step===b.PAYMENT&&!this.canProceedToPayment)return[2,this.changeStep(b.INFO)];if(![b.INFO,b.SUCCESS,b.SHIPPING,b.PAYMENT].includes(this.step))return[2,this.changeStep(b.INFO)]}return s&&(this.error={type:I.PAYMENT_ERROR,data:n||null}),this.step!==b.INFO?[3,2]:[4,this.getShippingCountries()];case 1:e.sent(),this.checkShippingCountries(),e.label=2;case 2:return this.step!==b.SHIPPING||1!==this.checkout.availableShippingMethods.length||this.checkoutSettings.isGiftPackageEnabled||(this.step=b.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==b.SHIPPING||this.checkout.availableShippingMethods.length?this.step!==b.PAYMENT&&this.step!==b.SUCCESS?[3,4]:[4,this.listPaymentGateways()]:(this.error={type:I.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 3:if(e.sent(),!this.paymentGateways.length)return this.error={type:I.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];e.label=4;case 4:return this.step===b.SUCCESS?[3,8]:this.checkout.isComplete?[2,this.changeStep(b.SUCCESS)]:[3,5];case 5:return[4,this.initialStockCheck()];case 6:e.sent(),e.label=7;case 7:return[3,11];case 8:return r=this,[4,p.getOrder(this.checkout.orderId)];case 9:return r.order=e.sent(),[4,f.getOrderTransactions({orderId:this.checkout.orderId})];case 10:o=e.sent(),this.successTransaction=o.length?o[0]:void 0,this.successTransaction&&(a=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(t){return t.id===a}))),e.label=11;case 11:return this.isCheckoutLoaded=!0,y.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getMerchantSettings=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.merchantSettings?[3,2]:(t=this,[4,g.listMerchantSettings()]);case 1:t.merchantSettings=e.sent(),e.label=2;case 2:return[2]}}))}))},this.saveCheckout=function(){return t(G,void 0,void 0,(function(){var t,i,s;return e(this,(function(e){switch(e.label){case 0:return[4,p.saveCheckout(this.checkout)];case 1:if((null==(t=e.sent())?void 0:t.errors)&&t.errors.length)throw i=t.errors[0],"CUSTOMER_LOGIN_REQUIRED"===(null===(s=i.extensions)||void 0===s?void 0:s.code)?{type:I.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:I.API_ERROR};return[2]}}))}))},this.checkStocks=function(){return t(G,void 0,void 0,(function(){var t,i,s,n,r,o,a,c,d,u,h;return e(this,(function(e){switch(e.label){case 0:return t=this.cart.items.map((function(t){return{quantity:t.quantity,variantId:t.variant.id,productId:t.variant.productId}})),[4,p.checkStocks(t,S.stockLocationIds||[])];case 1:if(!(i=e.sent()))throw{type:I.API_ERROR};if(null==(s=null===(u=i.lines)||void 0===u?void 0:u.filter((function(t){return!t.isAvailable})))?void 0:s.length){for(n=[],r=function(t){var e=null===(h=o.store.cartStore.cart)||void 0===h?void 0:h.items.find((function(e){return e.variant.id===t.variantId}));e&&n.push(e)},o=this,a=0,c=s;a<c.length;a++)d=c[a],r(d);throw{type:I.STOCK_ERROR,data:n}}return[2]}}))}))},this.removeUnavailableItems=function(i){return t(G,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:t=0,s=i,e.label=1;case 1:return t<s.length?(n=s[t],[4,this.store.cartStore.removeItem(n)]):[3,4];case 2:e.sent(),e.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=this,[4,m.listShippingCountries(S.salesChannelId)];case 1:return t.shippingCountryIds=e.sent(),[2]}}))}))},this.checkShippingCountries=function(){var t;(null===(t=G.shippingCountryIds)||void 0===t?void 0:t.length)||(G.error={type:I.NO_SHIPPING_ERROR})},this.initialStockCheck=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return e.sent(),[3,3];case 2:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:I.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return t(G,void 0,void 0,(function(){var t,i,s,n,o,a,c=this;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,i=S.paymentGateways.map((function(t){return t.id})),[4,p.listPaymentGateway(t?void 0:i)];case 1:return(s=e.sent())&&s.length?(this.step===b.PAYMENT&&(s=s.filter((function(t){return!t.supportedCurrencies.length||t.supportedCurrencies.includes(c.checkout.cart.currencyCode)})),(n=null===(a=this.checkout.shippingAddress)||void 0===a?void 0:a.country)&&n.iso2&&(s=s.filter((function(t){return!t.availableCountries.length||t.availableCountries.includes(n.iso2||"")})))),o=[],r(S.paymentGateways,"order").forEach((function(t){var e=null==s?void 0:s.find((function(e){return e.id===t.id}));e&&o.push(e)})),this.paymentGateways=t?s:o,this.checkout.selectedPaymentGateway||this.setPaymentGateway(0),[2]):(this.error={type:I.API_ERROR},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,p.retrieveInstallmentInfo(i)];case 1:return null==(t=e.sent())||t.installmentPrices.sort((function(t,e){return(t.installmentCount||-1)>(e.installmentCount||-1)?1:-1})),this.installmentInfo=t,[2]}}))}))},this.createCustomer=function(){G.store.customerStore.customer?(G.store.customerStore.customer.addresses.forEach((function(t){return t.checkoutSettings=G.checkoutSettings})),G.checkout.customer=new a(G.store.customerStore.customer)):G.checkout.customer||(G.checkout.customer=new a({}))},this.createShippingAddress=function(){var t;if(G.checkout.shippingAddress)G.selectedShippingAddressId=G.checkout.shippingAddress.id||"-1",G.checkout.shippingAddress.checkoutSettings=G.checkoutSettings;else{var e=null===(t=G.store.customerStore.customer)||void 0===t?void 0:t.addresses;G.onSelectedShippingAddressIdChange((null==e?void 0:e.length)?e[0].id:"-1")}},this.createBillingAddress=function(){"undefined"!=typeof localStorage&&(G.useDifferentAddress=!!localStorage.getItem("sAddr"),G.useDifferentAddress?(G.checkout.billingAddress&&(G.selectedBillingAddressId=G.checkout.billingAddress.id||"-1"),G.checkout.billingAddress=G.checkout.billingAddress||new u):G.checkout.billingAddress=new u(n(G.checkout.shippingAddress)||{}),G.checkout.billingAddress.checkoutSettings=G.checkoutSettings)},this.onShippingMethodChange=function(i){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.isChangingShippingMethod?[2]:(this.isChangingShippingMethod=!0,this.checkout.shippingSettingsId=i.shippingSettingsId,this.checkout.shippingZoneRateId=i.shippingZoneRateId,[4,this.saveCheckout()]);case 1:return e.sent(),[4,p.getCheckoutById(this.checkout.id)];case 2:return(t=e.sent())&&(this.checkout=t),this.isChangingShippingMethod=!1,[2]}}))}))},this.onCouponCodeApply=function(){return t(G,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:if(!this.checkout.couponCode)return[2];e.label=1;case 1:return e.trys.push([1,5,,6]),[4,p.addCouponCodeToCheckout(this.checkout.id,this.checkout.couponCode)];case 2:return e.sent()?[4,p.getCheckoutById(this.checkout.id)]:[3,4];case 3:(t=e.sent())&&(s=this.checkout,this.checkout=new o(i(i({},t),{shippingAddress:s.shippingAddress,billingAddress:s.billingAddress,customer:s.customer}))),e.label=4;case 4:return[3,6];case 5:return e.sent(),[3,6];case 6:return[2]}}))}))},this.onCouponCodeDelete=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,this.saveCheckout()];case 1:return e.sent(),[4,p.getCheckoutById(this.checkout.id)];case 2:return(t=e.sent())&&(this.checkout=t),[3,4];case 3:return e.sent(),[3,4];case 4:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(t){var e;if(G.selectedShippingAddressId=t,"-1"===t)G.checkout.shippingAddress=new u;else{var i=null===(e=G.store.customerStore.customer)||void 0===e?void 0:e.addresses.find((function(e){return e.id===t}));i&&(G.checkout.shippingAddress=new u(i))}G.checkout.shippingAddress&&(G.checkout.shippingAddress.checkoutSettings=G.checkoutSettings)},this.onSelectedBillingAddressIdChange=function(t){var e;if(G.selectedBillingAddressId=t,"-1"===t)G.checkout.billingAddress=new u;else{var i=null===(e=G.store.customerStore.customer)||void 0===e?void 0:e.addresses.find((function(e){return e.id===t}));i&&(G.checkout.billingAddress=new u(i))}G.checkout.billingAddress&&(G.checkout.billingAddress.checkoutSettings=G.checkoutSettings)},this.onTermsAndConditionsCheckedChange=function(t){G.isTermsAndConditionsChecked=t},this.onCardNumberChange=function(t){if(G.cardData&&(!(t.length>G.cardData.cardNumber.length)||N(t))){var e=(G.cardData.cardNumber||"").split(" ").join(""),i=t.split(" ").join("");i.length>16||(e.length<6&&i.length>=6&&!G.installmentInfo?G.retrieveInstallmentInfo({binNumber:i.slice(0,6),paymentGatewayId:G.checkout.selectedPaymentGateway.id,price:G.checkout.totalFinalPrice}):i.length<6&&e.length>i.length&&(G.cardData.installmentCount=1,G.installmentInfo=void 0),G.cardData.cardNumber=R(i,4).join(" "))}},this.onCardHolderNameChange=function(t){G.cardData&&(G.cardData.cardHolderName=t)},this.onExpirationDateChange=function(t){var e;if(G.cardData&&(!(t.length>G.cardData.expirationDate.length)||N(t))){if(0===(null===(e=G.cardData.expirationDate)||void 0===e?void 0:e.length)){var i=t.split("/");if(2===i.length){var s=i[0].trim(),n=i[1].trim();if(4===s.length&&2===n.length){var r=parseInt(s.slice(2)),o=parseInt(n);if(!isNaN(r)&&!isNaN(o))return void(G.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&4===n.length){o=parseInt(s),r=parseInt(n.slice(2));if(!isNaN(r)&&!isNaN(o))return void(G.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var a=t.split(" / ").join("");a.length>4||(G.cardData.expirationDate=R(a,2).join(" / "))}},this.onCvcChange=function(t){G.cardData&&(t.length>G.cardData.cvv.length&&!N(t)||t.length>4||(G.cardData.cvv=t))},this.saveAddress=function(s){return t(G,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return this.shouldSaveAddress?(t=new c(i(i({},"shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress),{title:this.addressTitle||this.t("checkout-page:newAddress"),id:C()})),(r=n(this.store.customerStore.customer)).addresses.push(t),[4,this.store.customerStore.saveCustomer(r)]):[3,2];case 1:e.sent(),"shipping"===s?(this.checkout.shippingAddress.id=t.id,this.selectedShippingAddressId=t.id||"-1"):(this.checkout.billingAddress.id=t.id,this.selectedBillingAddressId=t.id||"-1"),e.label=2;case 2:return[2]}}))}))},this.onGoToCartClick=function(){G.router.push("/cart")},this.onBackToShoppingClick=function(){G.router.push("/")},this.onProceedToShippingClick=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canProceedToShipping)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,e.label=1;case 1:return e.trys.push([1,5,,6]),this.isStepLoading=!0,[4,this.saveAddress("shipping")];case 2:return e.sent(),[4,this.checkStocks()];case 3:return e.sent(),[4,this.saveCheckout()];case 4:return e.sent(),this.changeStep(b.SHIPPING),[3,6];case 5:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:I.UNKNOWN}),this.isStepLoading=!1,[3,6];case 6:return[2]}}))}))},this.onProceedToPaymentClick=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,e.label=1;case 1:return e.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),[4,this.saveCheckout()];case 3:return e.sent(),this.error=void 0,this.changeStep(b.PAYMENT),[3,5];case 4:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:I.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onCompletePaymentClick=function(){return t(G,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canPerformPayment)return this.isErrorsVisible=!0,[2];this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),e.label=1;case 1:return e.trys.push([1,6,,7]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),[4,this.saveAddress("billing")];case 3:return e.sent(),[4,this.saveCheckout()];case 4:return e.sent(),[4,this.createSaleTransaction()];case 5:return e.sent(),[3,7];case 6:return(t=e.sent()).type?this.error=t:this.error={type:I.UNKNOWN},this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.createSaleTransaction=function(){return t(G,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?[4,p.createSaleTransactionWithCheckout(this.checkout.id,this.checkout.selectedPaymentGateway.id,this.checkout.selectedPaymentGateway.paymentMethodType===h.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===l.INTERNAL&&this.cardData?this.cardData.toInput():void 0)]:[2];case 1:return t=e.sent(),i=null==t?void 0:t.transactionStatus,s=i&&[d.SUCCESS,d.AUTHORIZED].includes(i),n=i===d.PENDING,s?[4,this.onCheckoutTransactionSuccess()]:[3,3];case 2:return e.sent(),[3,4];case 3:if(!n||!(null==t?void 0:t.returnSlug))throw{type:I.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+t.returnSlug,e.label=4;case 4:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return t(G,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return localStorage.removeItem("sAddr"),(null===(t=this.checkout.customer)||void 0===t?void 0:t.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(i=this.checkout.customer)||void 0===i?void 0:i.email)||"")]:[3,2];case 1:e.sent(),e.label=2;case 2:return this.changeStep(b.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){G.changeStep(b.INFO)},this.onBackToShippingClick=function(){G.changeStep(b.SHIPPING)},this.setCustomerConsentGranted=function(t){G.checkout.customer&&(G.checkout.customer.notificationsAccepted=t)},this.setUseDifferentAddress=function(t){G.useDifferentAddress=t,G.useDifferentAddress?(localStorage.setItem("sAddr","1"),G.checkout.billingAddress=G.checkout.billingAddress||new u):(localStorage.removeItem("sAddr"),G.checkout.billingAddress=G.checkout.shippingAddress)},this.setShouldSaveAddress=function(t){G.shouldSaveAddress=t},this.setAddressTitle=function(t){G.addressTitle=t},this.setPaymentGateway=function(t){if(G.paymentGateways.length){var e=G.paymentGateways[t];G.checkout.selectedPaymentGateway=e,G.step!==b.SUCCESS&&(e.paymentMethodType===h.CREDIT_CARD&&e.type===l.INTERNAL&&(G.cardData=new v),G.installmentInfo=void 0)}},this.setInstallmentCount=function(t){G.cardData&&(G.cardData.installmentCount=t)},this.changeStep=function(i){return t(G,void 0,void 0,(function(){return e(this,(function(t){return A||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return t(G,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:this.checkout.customer=void 0,this.store.customerStore.logout(),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.saveCheckout()];case 2:case 3:return t.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(t){G.isContactModalVisible=t},this.checkout=P,this.checkoutSettings=j,this.router=x,this.returnPolicy=E,this.privacyPolicy=O,this.termsOfService=T,this.t=D,w&&(this.merchantSettings=w),this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked,this.store.cartStore.cart=this.checkout.cart,this.init(),s(this)}return Object.defineProperty(P.prototype,"cart",{get:function(){return this.checkout.cart},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"selectedPaymentGatewayIndex",{get:function(){var t=this;return this.paymentGateways.findIndex((function(e){var i;return e.id===(null===(i=t.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"selectedInstallmentIndex",{get:function(){var t,e=this;return(null===(t=this.installmentInfo)||void 0===t?void 0:t.installmentPrices.findIndex((function(t){var i;return t.installmentCount===(null===(i=e.cardData)||void 0===i?void 0:i.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"customerAddressOptions",{get:function(){var t,e={label:this.t("checkout-page:newAddress"),value:"-1"},i=(null===(t=this.store.customerStore.customer)||void 0===t?void 0:t.addresses.map((function(t){return{label:t.title+" - "+t.addressText,value:t.id}})))||[];return[e].concat(i)},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"installmentPrice",{get:function(){var t,e,i=this;if(this.installmentInfo&&(null===(t=this.cardData)||void 0===t?void 0:t.installmentCount))return null===(e=this.installmentInfo.installmentPrices.find((function(t){var e;return t.installmentCount===(null===(e=i.cardData)||void 0===e?void 0:e.installmentCount)})))||void 0===e?void 0:e.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"finalPrice",{get:function(){return this.step===b.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"hasStockError",{get:function(){var t;return(null===(t=this.error)||void 0===t?void 0:t.type)===I.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"canProceedToShipping",{get:function(){var t,e;return(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValid)&&this.checkout.hasValidCustomer&&(null===(e=this.error)||void 0===e?void 0:e.type)!==I.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping},enumerable:!1,configurable:!0}),Object.defineProperty(P.prototype,"canPerformPayment",{get:function(){var t,e;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway;return this.canProceedToShipping&&!!(null===(t=this.checkout.billingAddress)||void 0===t?void 0:t.isValid)&&((null==i?void 0:i.paymentMethodType)!==h.CREDIT_CARD||i.type!==l.INTERNAL||(null===(e=this.cardData)||void 0===e?void 0:e.isValid))},enumerable:!1,configurable:!0}),P}();function R(t,e){return t.match(new RegExp(".{1,"+e+"}","g"))||[]}function N(t){return t&&P.test(t.charAt(t.length-1))}!function(t){t.INFO="info",t.SHIPPING="shipping",t.PAYMENT="payment",t.SUCCESS="success"}(b||(b={})),function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.API_ERROR=1]="API_ERROR",t[t.STOCK_ERROR=2]="STOCK_ERROR",t[t.PAYMENT_ERROR=3]="PAYMENT_ERROR",t[t.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",t[t.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR"}(I||(I={}));export{b as CheckoutStep,I as ErrorType,j as default};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t}from'../../ext/tslib/tslib.es6.js';import{reaction as i,makeAutoObservable as n,runInAction as o}from"mobx";import{IkasBlogMetadataTargetType as a}from"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-review/index.js";import{IkasHTMLMetaDataTargetType as r}from"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/installment-info/index.js";import"../../models/data/order/index.js";import"../../models/data/order/line-item/index.js";import"../../api/product-option-file/index.js";import"../../models/data/product/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product-attribute/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product-filter/index.js";import"../../models/data/variant-type/variant-value/index.js";import"../../models/data/order-transaction/index.js";import"../../models/data/product-option-set/index.js";import"../../models/data/raffle/index.js";import"../../models/data/product-campaing/campaign/index.js";import{IkasTheme as s}from"../../models/theme/theme.js";import{IkasThemePageType as d}from"../../models/theme/page/index.js";import{IkasThemePageComponent as p}from"../../models/theme/page/component/index.js";import{IkasThemeComponent as u}from"../../models/theme/component/index.js";import{IkasThemeComponentPropType as c}from"../../models/theme/component/prop/index.js";import"../../models/theme/page/component/prop-value/link.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-detail/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import{IkasThemeSettings as l}from"../../models/theme/settings/index.js";import"../../models/theme/custom-data/index.js";import{IkasPageDataProvider as m}from"../../providers/page-data-get.js";import{IkasPageDataInit as h}from"../../providers/page-data-init.js";import{IkasBlogAPI as g}from"../../api/blog/index.js";import"../../api/brand/index.js";import"../../api/cart/index.js";import"../../api/category/index.js";import"../../api/checkout/index.js";import"../../api/city/index.js";import"../../api/country/index.js";import"../../api/customer/index.js";import"../../api/customer-review/index.js";import"../../api/district/index.js";import{IkasHTMLMetaDataAPI as f}from"../../api/html-meta-data/index.js";import"../../api/merchant/index.js";import{IkasProductSearchAPI as E}from"../../api/product-search/index.js";import{apollo as P}from"../../api/apollo.js";import"../../api/favorite-product/index.js";import"../../api/contact-form/index.js";import"../../api/state/index.js";import"../../api/product-option-set/index.js";import{IkasRaffleAPI as O}from"../../api/raffle/index.js";import"../../api/back-in-stock-reminder/index.js";import"../../api/product-campanign/index.js";import{IkasStorefrontConfig as v}from"../../storefront/index.js";import{IkasStorefront as T}from"../../models/data/storefront/index.js";import C from'../../ext/uuid/dist/esm-browser/v4.js';var _,D=function(){function D(i){var E=this;this.theme=null,this.page=null,this.selectedPageComponentId=null,this.hoveredPageComponentId=null,this.componentRefs={},this.isLoading=!1,this.updateId="",this.locale="en",this.pageParams={},this.apiKey=null,this.pageDataProvider=null,this.startMessaging=function(){window.addEventListener("message",E.onMessage,!1),E.sendMessage(_.FRAME_DID_LOAD,"2.0.20"),E.createLoadingListener()},this.onMessage=function(i){return e(E,void 0,void 0,(function(){var e,n;return t(this,(function(t){switch(t.label){case 0:switch(e=i.data.type,n=i.data.data,e){case _.UPDATE_FRAME_DATA:return[3,1];case _.UPDATE_THEME_JSON:return[3,3];case _.UPDATE_PROP_VALUE:return[3,5];case _.UPDATE_PAGE_PARAMS:return[3,7];case _.UPDATE_PAGE_COMPONENT_ORDER:return[3,9];case _.ADD_COMPONENT:return[3,11];case _.DELETE_COMPONENT:return[3,12];case _.UPDATE_COMPONENT:return[3,13];case _.ADD_PAGE_COMPONENT:return[3,14];case _.DELETE_PAGE_COMPONENT:return[3,16];case _.SET_SELECTED_COMPONENT:return[3,17];case _.SET_HOVERED_COMPONENT:return[3,18];case _.SCROLL_TO_COMPONENT:return[3,19];case _.EDITOR_RELOAD:return[3,20];case _.UPDATE_THEME_SETTINGS:return[3,21]}return[3,22];case 1:return[4,this.handleUpdateFrameData(n)];case 2:case 4:case 6:case 8:case 10:case 15:return t.sent(),[3,23];case 3:return[4,this.handleUpdateThemeJson(n)];case 5:return[4,this.handleUpdatePropValue(n)];case 7:return[4,this.handleUpdatePageParams(n)];case 9:return[4,this.handleUpdatePageComponentOrder(n)];case 11:return this.handleAddNewComponent(n),[3,23];case 12:return this.handleDeleteComponent(n),[3,23];case 13:return this.handleUpdateComponent(n),[3,23];case 14:return[4,this.handleAddNewPageComponent(n)];case 16:return this.handleDeletePageComponent(n),[3,23];case 17:return this.handleSetSelectedComponent(n),[3,23];case 18:return this.handleSetHoveredComponent(n),[3,23];case 19:return this.handleScrollToComponent(n),[3,23];case 20:return this.handleEditorReload(),[3,23];case 21:return this.updateThemeSettings(n),[3,23];case 22:return[3,23];case 23:return[2]}}))}))},this.onClick=function(e){E.sendMessage(_.COMPONENT_CLICK,{componentId:e})},this.onMouseOver=function(e){E.sendMessage(_.COMPONENT_MOUSE_OVER,{componentId:e})},this.onMouseLeave=function(e){E.sendMessage(_.COMPONENT_MOUSE_LEAVE,{componentId:e})},this.onPageChange=function(i){return e(E,void 0,void 0,(function(){var e,n,s,p,u,c,l,m,h,E=this;return t(this,(function(t){switch(t.label){case 0:return e=i.slice(1),n=e.split("?"),e=n[0],s=n[1],this.pageParams={},i.startsWith("/account/orders/")?p=d.ORDER_DETAIL:i.startsWith("/account/orders")?p=d.ORDERS:i.startsWith("/account/addresses")?p=d.ADDRESSES:i.startsWith("/account/favorite-products")?p=d.FAVORITE_PRODUCTS:i.startsWith("/account/forgot-password")?p=d.FORGOT_PASSWORD:i.startsWith("/account/login")?p=d.LOGIN:i.startsWith("/account/raffles")?p=d.RAFFLE_ACCOUNT:i.startsWith("/account/recover-password")?p=d.RECOVER_PASSWORD:i.startsWith("/account/register")?p=d.REGISTER:i.startsWith("/account")?p=d.ACCOUNT:i.startsWith("/blog/")?p=d.BLOG:i.startsWith("/blog")?p=d.BLOG_INDEX:i.startsWith("/pages")?(p=d.CUSTOM,this.pageParams={slug:e.split("/")[1]}):p=i.startsWith("/raffle/")?d.RAFFLE_DETAIL:i.startsWith("/raffle")?d.RAFFLE:i.startsWith("/404")?d.NOT_FOUND:i.startsWith("/cart")?d.CART:i.startsWith("/checkout")?d.CHECKOUT:"/"===i?d.INDEX:i.startsWith("/search")?d.SEARCH:d.PRODUCT,p!==d.PRODUCT?[3,6]:[4,f.listHTMLMetaData(e)];case 1:return(c=t.sent()).length?(l=c[0]).targetType!==r.PRODUCT?[3,3]:[4,this.getVariantIdFromParams(l.targetId,s)]:[3,5];case 2:return u=t.sent(),this.pageParams={productId:l.targetId,variantId:u,slug:e},[3,4];case 3:if(l.targetType===r.CATEGORY)p=d.CATEGORY,this.pageParams={categoryId:l.targetId,slug:e};else{if(l.targetType!==r.BRAND)return[2];p=d.BRAND,this.pageParams={brandId:l.targetId,slug:e}}t.label=4;case 4:return[3,6];case 5:return[2];case 6:return p!==d.BLOG?[3,8]:[4,g.listBlogMetaData(e)];case 7:if(!(c=t.sent()).length)return[2];if((l=c[0]).targetType===a.BLOG)this.pageParams={blogId:l.targetId,slug:e};else{if(l.targetType!==a.BLOG_CATEGORY)return[2];p=d.BLOG_CATEGORY,this.pageParams={blogCategoryId:l.targetId,slug:e}}t.label=8;case 8:return p!==d.RAFFLE_DETAIL?[3,10]:[4,O.listRaffleMetaData(e)];case 9:if(!(c=t.sent()).length)return[2];l=c[0],this.pageParams={raffleId:l.targetId,slug:e},t.label=10;case 10:return this.isLoading=!0,[4,this.getPagePropValues(this.theme,p,this.pageParams)];case 11:return m=t.sent(),o((function(){var e,t;v.store.currentPageType=p,E.pageDataProvider=m,p===d.CUSTOM?E.page=null===(e=E.theme)||void 0===e?void 0:e.pages.find((function(e){return e.type===p&&e.slug===E.pageParams.slug})):E.page=null===(t=E.theme)||void 0===t?void 0:t.pages.find((function(e){return e.type===p})),requestAnimationFrame((function(){document.body.scrollTop=0,document.scrollingElement&&(document.scrollingElement.scrollTop=0)}))})),this.sendMessage(_.EDITOR_PAGE_CHANGE,{pageType:p,pageParams:this.pageParams,pageSpecificData:(null===(h=this.pageDataProvider)||void 0===h?void 0:h.pageSpecificData)||null}),this.isLoading=!1,[2]}}))}))},this.onLoadingChange=function(){E.sendMessage(_.EDITOR_LOADING_CHANGE,{isLoading:E.isLoading})},this.sendMessage=function(e,t){window.parent.postMessage({type:e,data:JSON.parse(JSON.stringify(t))},"*")},this.getPagePropValues=function(i,n,o){return e(E,void 0,void 0,(function(){var e,a,r;return t(this,(function(t){switch(t.label){case 0:return e=new m(i,o,n),(o.blogId||o.blogCategoryId)&&(e.possiblePageTypes=[d.BLOG,d.BLOG_CATEGORY]),o.raffleId&&(e.possiblePageTypes=[d.RAFFLE_DETAIL]),[4,e.getPageData()];case 1:return t.sent(),e.pageSpecificData?(h.setPageSpecificData(JSON.stringify(e.pageSpecificData),n,!0),n===d.PRODUCT&&h.pageSpecificData&&(a=h.pageSpecificData,(r=a.product.variants.find((function(e){return e.id===o.variantId})))&&(a.selectedVariantValues=r.variantValues))):h.pageSpecificData=void 0,e.pageComponentPropValues=h.initPropValues(JSON.stringify(e.pageComponentPropValues),this.router,JSON.stringify(i.settings),!1),[2,e]}}))}))},this.setComponentRef=function(e,t){E.componentRefs[t.id]=e},this.isScrolledIntoView=function(e){var t=e.getBoundingClientRect(),i=t.top,n=t.bottom;return i<window.innerHeight&&n>=0&&n<window.innerHeight&&i>0},this.handleUpdateFrameData=function(i){return e(E,void 0,void 0,(function(){var e,n,o,a,r,d=this;return t(this,(function(t){switch(t.label){case 0:return this.theme=new s(i.theme),this.page=this.theme.pages.find((function(e){return e.id===i.selectedPage.id})),this.pageParams=i.pageParams,this.apiKey=i.apiKey,this.locale=i.locale||"en",this.translations=i.translations||void 0,this.page?((e=i.storefront)&&(n=new T(e),o=n.routings.find((function(e){return e.locale===d.locale})),v.storefrontId=n.id,v.storefrontRoutingId=null==o?void 0:o.id,n.mainStorefrontThemeId&&(v.storefrontThemeId=n.mainStorefrontThemeId),n.salesChannelId&&(v.salesChannelId=n.salesChannelId),(null==o?void 0:o.priceListId)?v.priceListId=o.priceListId:v.priceListId=void 0,v.routings=n.routings,v.stockPreference=this.theme.settings.stockPreference),this.translations&&(v.translations=this.translations),v.isEditor=!0,P.createApolloClient(this.apiKey||void 0),window.editorApiKey=i.apiKey,a=C(),this.updateId=a,this.isLoading=!0,[4,this.getPagePropValues(this.theme,this.page.type,this.pageParams||{})]):[2];case 1:return r=t.sent(),this.updateId===a&&(this.pageDataProvider=r,this.isLoading=!1),[2]}}))}))},this.handleUpdateThemeJson=function(i){return e(E,void 0,void 0,(function(){return t(this,(function(e){return this.theme=new s(i.theme),[2]}))}))},this.handleUpdatePropValue=function(i){return e(E,void 0,void 0,(function(){var e,n,a,r,s,d,p,u,l=this;return t(this,(function(t){switch(t.label){case 0:return e=i.propName,n=i.value,(a=null===(p=null===(d=this.selectedComponent)||void 0===d?void 0:d.props)||void 0===p?void 0:p.find((function(t){return t.name===e})))&&this.selectedPageComponent?(r=null===(u=this.pageDataProvider)||void 0===u?void 0:u.pageComponentPropValues.find((function(e){return e.pageComponent.id===l.selectedPageComponentId})),this.selectedPageComponent.propValues[e]=n,this.pageDataProvider?[4,this.pageDataProvider.getPageComponentPropValue(this.selectedPageComponent,a)]:[2]):[2];case 1:return s=t.sent(),[4,this.pageDataProvider.setLinkSlugs()];case 2:return t.sent(),o((function(){r&&(r.propValues[e]=s,a.type===c.CUSTOM?h.initCustomDataPropValue(a,s,r,l.router,l.theme.settings,!0):a.type===c.COMPONENT?h.initComponentPropValue(a,s,r,l.router,l.theme.settings,!0):a.type===c.COMPONENT_LIST?h.initComponentListPropValue(a,s,r,l.router,l.theme.settings,!0):a.type===c.PRODUCT_DETAIL?h.initProductDetailPropValue(a,s,r,l.router):a.type===c.CATEGORY?h.initCategoryPropValue(a,s,r):a.type===c.BRAND?h.initBrandPropValue(a,s,r):a.type===c.BLOG?h.initBlogPropValue(a,s,r):a.type===c.BLOG_CATEGORY?h.initBlogCategoryPropValue(a,s,r):a.type===c.RAFFLE?h.initRafflePropValue(a,s,r):a.type!==c.LINK&&a.type!==c.LIST_OF_LINK||h.initLinkPropValue(a,s,r))})),[2]}}))}))},this.handleUpdatePageParams=function(i){return e(E,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.pageParams=i.pageParams,this.isLoading=!0,[4,this.getPagePropValues(this.theme,this.page.type,this.pageParams||{})];case 1:return e=t.sent(),this.pageDataProvider=e,this.isLoading=!1,[2]}}))}))},this.handleUpdatePageComponentOrder=function(i){return e(E,void 0,void 0,(function(){return t(this,(function(e){return this.specification?this.specification.components=i.pageComponents.map((function(e){return new p(e)})):this.page.components=i.pageComponents.map((function(e){return new p(e)})),[2]}))}))},this.handleAddNewComponent=function(e){var t,i=new u(e.component);null===(t=E.theme)||void 0===t||t.components.push(i)},this.handleDeleteComponent=function(e){var t,i;(null===(t=E.theme)||void 0===t?void 0:t.components)&&(E.theme.components=E.theme.components.filter((function(t){return t.id!==e.componentId})));var n=E.pageComponents.filter((function(t){return t.componentId!==e.componentId}))||[];E.specification&&E.specification.components&&(E.specification.components=n),!E.specification&&(null===(i=E.page)||void 0===i?void 0:i.components)&&(E.page.components=n)},this.handleUpdateComponent=function(e){var t=E.theme.components.findIndex((function(t){return t.id===e.component.id}));-1!==t&&(E.theme.components[t]=new u(e.component))},this.handleAddNewPageComponent=function(i){return e(E,void 0,void 0,(function(){var e,n,a=this;return t(this,(function(t){switch(t.label){case 0:return e=new p(i.pageComponent),this.pageComponents.some((function(t){return t.id===e.id}))?[2]:[4,this.pageDataProvider.getPageComponentPropValues(e)];case 1:return n=t.sent(),o((function(){n.component.props.filter((function(e){return e.type===c.CUSTOM})).forEach((function(e){h.initCustomDataPropValue(e,n.propValues[e.name],n,a.router,a.theme.settings,!0)})),a.pageDataProvider.pageComponentPropValues.push(n),a.pageComponents.push(e)})),[2]}}))}))},this.handleDeletePageComponent=function(e){E.specification?E.specification.components=E.pageComponents.filter((function(t){return t.id!==e.pageComponentId})):E.page.components=E.pageComponents.filter((function(t){return t.id!==e.pageComponentId}))},this.handleSetSelectedComponent=function(e){E.selectedPageComponentId=e.componentId},this.handleSetHoveredComponent=function(e){E.hoveredPageComponentId=e.componentId},this.handleScrollToComponent=function(e){var t=e.componentId,i=E.componentRefs[t];i&&(E.isScrolledIntoView(i)||window.scrollTo({top:i.offsetTop,behavior:"smooth"}))},this.handleEditorReload=function(){window.location.reload()},this.updateThemeSettings=function(e){var t=e.settings;E.theme&&(E.theme.settings=new l(t))},this.router=i,n(this),this.startMessaging()}return Object.defineProperty(D.prototype,"specification",{get:function(){var e,t,i,n,o,a,r,s=this,p=this.page;return(null==p?void 0:p.type)===d.PRODUCT&&(r=null===(e=p.specifications)||void 0===e?void 0:e.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.productId)}))),(null==p?void 0:p.type)===d.CATEGORY&&(r=null===(t=p.specifications)||void 0===t?void 0:t.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.categoryId)}))),(null==p?void 0:p.type)===d.BRAND&&(r=null===(i=p.specifications)||void 0===i?void 0:i.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.brandId)}))),(null==p?void 0:p.type)===d.BLOG&&(r=null===(n=p.specifications)||void 0===n?void 0:n.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.blogId)}))),(null==p?void 0:p.type)===d.BLOG_CATEGORY&&(r=null===(o=p.specifications)||void 0===o?void 0:o.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.blogCategoryId)}))),(null==p?void 0:p.type)===d.RAFFLE_DETAIL&&(r=null===(a=p.specifications)||void 0===a?void 0:a.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.raffleId)}))),r},enumerable:!1,configurable:!0}),Object.defineProperty(D.prototype,"pageComponents",{get:function(){var e;return this.specification?this.specification.components:(null===(e=this.page)||void 0===e?void 0:e.components)||[]},enumerable:!1,configurable:!0}),Object.defineProperty(D.prototype,"selectedPageComponent",{get:function(){var e=this;return this.pageComponents.find((function(t){return t.id===e.selectedPageComponentId}))},enumerable:!1,configurable:!0}),Object.defineProperty(D.prototype,"selectedComponent",{get:function(){var e,t=this;return null===(e=this.theme)||void 0===e?void 0:e.components.find((function(e){var i;return e.id===(null===(i=t.selectedPageComponent)||void 0===i?void 0:i.componentId)}))},enumerable:!1,configurable:!0}),D.prototype.createLoadingListener=function(){var e=this;i((function(){return e.isLoading}),(function(){e.onLoadingChange()}))},D.prototype.getVariantIdFromParams=function(i,n){return e(this,void 0,void 0,(function(){var e,o,a,r,s,d,p;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=new URLSearchParams("?"+n),[4,E.searchProducts({productIdList:[i],priceListId:v.priceListId,salesChannelId:v.salesChannelId})];case 1:return(null==(o=t.sent())?void 0:o.data.length)?(a=o.data[0],r=a.variantTypes.map((function(e){return e.variantType.slug})),s=[],r.forEach((function(t,i){var n=a.variantTypes[i],o=e.get(t);if(o){var r=n.variantType.values.find((function(e){return e.slug===o}));r&&s.push(r)}})),(d=a.variants.find((function(e){return e.variantValues.every((function(e){return s.some((function(t){return t.id===e.id}))}))})))?[2,d.id]:[3,3]):[2];case 2:return p=t.sent(),console.error(p),[3,3];case 3:return[2]}}))}))},D}();!function(e){e.FRAME_DID_LOAD="FRAME_DID_LOAD",e.UPDATE_FRAME_DATA="UPDATE_FRAME_DATA",e.UPDATE_THEME_JSON="UPDATE_THEME_JSON",e.UPDATE_PROP_VALUE="UPDATE_PROP_VALUE",e.UPDATE_PAGE_PARAMS="UPDATE_PAGE_PARAMS",e.UPDATE_PAGE_COMPONENT_ORDER="UPDATE_PAGE_COMPONENT_ORDER",e.ADD_COMPONENT="ADD_COMPONENT",e.DELETE_COMPONENT="DELETE_COMPONENT",e.UPDATE_COMPONENT="UPDATE_COMPONENT",e.ADD_PAGE_COMPONENT="ADD_PAGE_COMPONENT",e.DELETE_PAGE_COMPONENT="DELETE_PAGE_COMPONENT",e.COMPONENT_MOUSE_OVER="COMPONENT_MOUSE_OVER",e.COMPONENT_MOUSE_LEAVE="COMPONENT_MOUSE_LEAVE",e.COMPONENT_CLICK="COMPONENT_CLICK",e.SET_SELECTED_COMPONENT="SET_SELECTED_COMPONENT",e.SET_HOVERED_COMPONENT="SET_HOVERED_COMPONENT",e.SCROLL_TO_COMPONENT="SCROLL_TO_COMPONENT",e.UPDATE_THEME_SETTINGS="UPDATE_THEME_SETTINGS",e.EDITOR_PAGE_CHANGE="EDITOR_PAGE_CHANGE",e.EDITOR_LOADING_CHANGE="EDITOR_LOADING_CHANGE",e.EDITOR_RELOAD="EDITOR_RELOAD"}(_||(_={}));export{_ as BridgeMessageType,D as default};
1
+ import{__awaiter as e,__generator as t}from'../../ext/tslib/tslib.es6.js';import{reaction as i,makeAutoObservable as n,runInAction as o}from"mobx";import{IkasBlogMetadataTargetType as a}from"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-review/index.js";import{IkasHTMLMetaDataTargetType as r}from"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/installment-info/index.js";import"../../models/data/order/index.js";import"../../models/data/order/line-item/index.js";import"../../api/product-option-file/index.js";import"../../models/data/product/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product-attribute/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product-filter/index.js";import"../../models/data/variant-type/variant-value/index.js";import"../../models/data/order-transaction/index.js";import"../../models/data/product-option-set/index.js";import"../../models/data/raffle/index.js";import"../../models/data/product-campaing/campaign/index.js";import{IkasTheme as s}from"../../models/theme/theme.js";import{IkasThemePageType as d}from"../../models/theme/page/index.js";import{IkasThemePageComponent as p}from"../../models/theme/page/component/index.js";import{IkasThemeComponent as u}from"../../models/theme/component/index.js";import{IkasThemeComponentPropType as c}from"../../models/theme/component/prop/index.js";import"../../models/theme/page/component/prop-value/link.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-detail/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import{IkasThemeSettings as l}from"../../models/theme/settings/index.js";import"../../models/theme/custom-data/index.js";import{IkasPageDataProvider as m}from"../../providers/page-data-get.js";import{IkasPageDataInit as h}from"../../providers/page-data-init.js";import{IkasBlogAPI as g}from"../../api/blog/index.js";import"../../api/brand/index.js";import"../../api/cart/index.js";import"../../api/category/index.js";import"../../api/checkout/index.js";import"../../api/city/index.js";import"../../api/country/index.js";import"../../api/customer/index.js";import"../../api/customer-review/index.js";import"../../api/district/index.js";import{IkasHTMLMetaDataAPI as f}from"../../api/html-meta-data/index.js";import"../../api/merchant/index.js";import{IkasProductSearchAPI as E}from"../../api/product-search/index.js";import{apollo as P}from"../../api/apollo.js";import"../../api/favorite-product/index.js";import"../../api/contact-form/index.js";import"../../api/state/index.js";import"../../api/product-option-set/index.js";import{IkasRaffleAPI as O}from"../../api/raffle/index.js";import"../../api/back-in-stock-reminder/index.js";import"../../api/product-campaign/index.js";import{IkasStorefrontConfig as v}from"../../storefront/index.js";import{IkasStorefront as T}from"../../models/data/storefront/index.js";import C from'../../ext/uuid/dist/esm-browser/v4.js';var _,D=function(){function D(i){var E=this;this.theme=null,this.page=null,this.selectedPageComponentId=null,this.hoveredPageComponentId=null,this.componentRefs={},this.isLoading=!1,this.updateId="",this.locale="en",this.pageParams={},this.apiKey=null,this.pageDataProvider=null,this.startMessaging=function(){window.addEventListener("message",E.onMessage,!1),E.sendMessage(_.FRAME_DID_LOAD,"2.0.20"),E.createLoadingListener()},this.onMessage=function(i){return e(E,void 0,void 0,(function(){var e,n;return t(this,(function(t){switch(t.label){case 0:switch(e=i.data.type,n=i.data.data,e){case _.UPDATE_FRAME_DATA:return[3,1];case _.UPDATE_THEME_JSON:return[3,3];case _.UPDATE_PROP_VALUE:return[3,5];case _.UPDATE_PAGE_PARAMS:return[3,7];case _.UPDATE_PAGE_COMPONENT_ORDER:return[3,9];case _.ADD_COMPONENT:return[3,11];case _.DELETE_COMPONENT:return[3,12];case _.UPDATE_COMPONENT:return[3,13];case _.ADD_PAGE_COMPONENT:return[3,14];case _.DELETE_PAGE_COMPONENT:return[3,16];case _.SET_SELECTED_COMPONENT:return[3,17];case _.SET_HOVERED_COMPONENT:return[3,18];case _.SCROLL_TO_COMPONENT:return[3,19];case _.EDITOR_RELOAD:return[3,20];case _.UPDATE_THEME_SETTINGS:return[3,21]}return[3,22];case 1:return[4,this.handleUpdateFrameData(n)];case 2:case 4:case 6:case 8:case 10:case 15:return t.sent(),[3,23];case 3:return[4,this.handleUpdateThemeJson(n)];case 5:return[4,this.handleUpdatePropValue(n)];case 7:return[4,this.handleUpdatePageParams(n)];case 9:return[4,this.handleUpdatePageComponentOrder(n)];case 11:return this.handleAddNewComponent(n),[3,23];case 12:return this.handleDeleteComponent(n),[3,23];case 13:return this.handleUpdateComponent(n),[3,23];case 14:return[4,this.handleAddNewPageComponent(n)];case 16:return this.handleDeletePageComponent(n),[3,23];case 17:return this.handleSetSelectedComponent(n),[3,23];case 18:return this.handleSetHoveredComponent(n),[3,23];case 19:return this.handleScrollToComponent(n),[3,23];case 20:return this.handleEditorReload(),[3,23];case 21:return this.updateThemeSettings(n),[3,23];case 22:return[3,23];case 23:return[2]}}))}))},this.onClick=function(e){E.sendMessage(_.COMPONENT_CLICK,{componentId:e})},this.onMouseOver=function(e){E.sendMessage(_.COMPONENT_MOUSE_OVER,{componentId:e})},this.onMouseLeave=function(e){E.sendMessage(_.COMPONENT_MOUSE_LEAVE,{componentId:e})},this.onPageChange=function(i){return e(E,void 0,void 0,(function(){var e,n,s,p,u,c,l,m,h,E=this;return t(this,(function(t){switch(t.label){case 0:return e=i.slice(1),n=e.split("?"),e=n[0],s=n[1],this.pageParams={},i.startsWith("/account/orders/")?p=d.ORDER_DETAIL:i.startsWith("/account/orders")?p=d.ORDERS:i.startsWith("/account/addresses")?p=d.ADDRESSES:i.startsWith("/account/favorite-products")?p=d.FAVORITE_PRODUCTS:i.startsWith("/account/forgot-password")?p=d.FORGOT_PASSWORD:i.startsWith("/account/login")?p=d.LOGIN:i.startsWith("/account/raffles")?p=d.RAFFLE_ACCOUNT:i.startsWith("/account/recover-password")?p=d.RECOVER_PASSWORD:i.startsWith("/account/register")?p=d.REGISTER:i.startsWith("/account")?p=d.ACCOUNT:i.startsWith("/blog/")?p=d.BLOG:i.startsWith("/blog")?p=d.BLOG_INDEX:i.startsWith("/pages")?(p=d.CUSTOM,this.pageParams={slug:e.split("/")[1]}):p=i.startsWith("/raffle/")?d.RAFFLE_DETAIL:i.startsWith("/raffle")?d.RAFFLE:i.startsWith("/404")?d.NOT_FOUND:i.startsWith("/cart")?d.CART:i.startsWith("/checkout")?d.CHECKOUT:"/"===i?d.INDEX:i.startsWith("/search")?d.SEARCH:d.PRODUCT,p!==d.PRODUCT?[3,6]:[4,f.listHTMLMetaData(e)];case 1:return(c=t.sent()).length?(l=c[0]).targetType!==r.PRODUCT?[3,3]:[4,this.getVariantIdFromParams(l.targetId,s)]:[3,5];case 2:return u=t.sent(),this.pageParams={productId:l.targetId,variantId:u,slug:e},[3,4];case 3:if(l.targetType===r.CATEGORY)p=d.CATEGORY,this.pageParams={categoryId:l.targetId,slug:e};else{if(l.targetType!==r.BRAND)return[2];p=d.BRAND,this.pageParams={brandId:l.targetId,slug:e}}t.label=4;case 4:return[3,6];case 5:return[2];case 6:return p!==d.BLOG?[3,8]:[4,g.listBlogMetaData(e)];case 7:if(!(c=t.sent()).length)return[2];if((l=c[0]).targetType===a.BLOG)this.pageParams={blogId:l.targetId,slug:e};else{if(l.targetType!==a.BLOG_CATEGORY)return[2];p=d.BLOG_CATEGORY,this.pageParams={blogCategoryId:l.targetId,slug:e}}t.label=8;case 8:return p!==d.RAFFLE_DETAIL?[3,10]:[4,O.listRaffleMetaData(e)];case 9:if(!(c=t.sent()).length)return[2];l=c[0],this.pageParams={raffleId:l.targetId,slug:e},t.label=10;case 10:return this.isLoading=!0,[4,this.getPagePropValues(this.theme,p,this.pageParams)];case 11:return m=t.sent(),o((function(){var e,t;v.store.currentPageType=p,E.pageDataProvider=m,p===d.CUSTOM?E.page=null===(e=E.theme)||void 0===e?void 0:e.pages.find((function(e){return e.type===p&&e.slug===E.pageParams.slug})):E.page=null===(t=E.theme)||void 0===t?void 0:t.pages.find((function(e){return e.type===p})),requestAnimationFrame((function(){document.body.scrollTop=0,document.scrollingElement&&(document.scrollingElement.scrollTop=0)}))})),this.sendMessage(_.EDITOR_PAGE_CHANGE,{pageType:p,pageParams:this.pageParams,pageSpecificData:(null===(h=this.pageDataProvider)||void 0===h?void 0:h.pageSpecificData)||null}),this.isLoading=!1,[2]}}))}))},this.onLoadingChange=function(){E.sendMessage(_.EDITOR_LOADING_CHANGE,{isLoading:E.isLoading})},this.sendMessage=function(e,t){window.parent.postMessage({type:e,data:JSON.parse(JSON.stringify(t))},"*")},this.getPagePropValues=function(i,n,o){return e(E,void 0,void 0,(function(){var e,a,r;return t(this,(function(t){switch(t.label){case 0:return e=new m(i,o,n),(o.blogId||o.blogCategoryId)&&(e.possiblePageTypes=[d.BLOG,d.BLOG_CATEGORY]),o.raffleId&&(e.possiblePageTypes=[d.RAFFLE_DETAIL]),[4,e.getPageData()];case 1:return t.sent(),e.pageSpecificData?(h.setPageSpecificData(JSON.stringify(e.pageSpecificData),n,!0),n===d.PRODUCT&&h.pageSpecificData&&(a=h.pageSpecificData,(r=a.product.variants.find((function(e){return e.id===o.variantId})))&&(a.selectedVariantValues=r.variantValues))):h.pageSpecificData=void 0,e.pageComponentPropValues=h.initPropValues(JSON.stringify(e.pageComponentPropValues),this.router,JSON.stringify(i.settings),!1),[2,e]}}))}))},this.setComponentRef=function(e,t){E.componentRefs[t.id]=e},this.isScrolledIntoView=function(e){var t=e.getBoundingClientRect(),i=t.top,n=t.bottom;return i<window.innerHeight&&n>=0&&n<window.innerHeight&&i>0},this.handleUpdateFrameData=function(i){return e(E,void 0,void 0,(function(){var e,n,o,a,r,d=this;return t(this,(function(t){switch(t.label){case 0:return this.theme=new s(i.theme),this.page=this.theme.pages.find((function(e){return e.id===i.selectedPage.id})),this.pageParams=i.pageParams,this.apiKey=i.apiKey,this.locale=i.locale||"en",this.translations=i.translations||void 0,this.page?((e=i.storefront)&&(n=new T(e),o=n.routings.find((function(e){return e.locale===d.locale})),v.storefrontId=n.id,v.storefrontRoutingId=null==o?void 0:o.id,n.mainStorefrontThemeId&&(v.storefrontThemeId=n.mainStorefrontThemeId),n.salesChannelId&&(v.salesChannelId=n.salesChannelId),(null==o?void 0:o.priceListId)?v.priceListId=o.priceListId:v.priceListId=void 0,v.routings=n.routings,v.stockPreference=this.theme.settings.stockPreference),this.translations&&(v.translations=this.translations),v.isEditor=!0,P.createApolloClient(this.apiKey||void 0),window.editorApiKey=i.apiKey,a=C(),this.updateId=a,this.isLoading=!0,[4,this.getPagePropValues(this.theme,this.page.type,this.pageParams||{})]):[2];case 1:return r=t.sent(),this.updateId===a&&(this.pageDataProvider=r,this.isLoading=!1),[2]}}))}))},this.handleUpdateThemeJson=function(i){return e(E,void 0,void 0,(function(){return t(this,(function(e){return this.theme=new s(i.theme),[2]}))}))},this.handleUpdatePropValue=function(i){return e(E,void 0,void 0,(function(){var e,n,a,r,s,d,p,u,l=this;return t(this,(function(t){switch(t.label){case 0:return e=i.propName,n=i.value,(a=null===(p=null===(d=this.selectedComponent)||void 0===d?void 0:d.props)||void 0===p?void 0:p.find((function(t){return t.name===e})))&&this.selectedPageComponent?(r=null===(u=this.pageDataProvider)||void 0===u?void 0:u.pageComponentPropValues.find((function(e){return e.pageComponent.id===l.selectedPageComponentId})),this.selectedPageComponent.propValues[e]=n,this.pageDataProvider?[4,this.pageDataProvider.getPageComponentPropValue(this.selectedPageComponent,a)]:[2]):[2];case 1:return s=t.sent(),[4,this.pageDataProvider.setLinkSlugs()];case 2:return t.sent(),o((function(){r&&(r.propValues[e]=s,a.type===c.CUSTOM?h.initCustomDataPropValue(a,s,r,l.router,l.theme.settings,!0):a.type===c.COMPONENT?h.initComponentPropValue(a,s,r,l.router,l.theme.settings,!0):a.type===c.COMPONENT_LIST?h.initComponentListPropValue(a,s,r,l.router,l.theme.settings,!0):a.type===c.PRODUCT_DETAIL?h.initProductDetailPropValue(a,s,r,l.router):a.type===c.CATEGORY?h.initCategoryPropValue(a,s,r):a.type===c.BRAND?h.initBrandPropValue(a,s,r):a.type===c.BLOG?h.initBlogPropValue(a,s,r):a.type===c.BLOG_CATEGORY?h.initBlogCategoryPropValue(a,s,r):a.type===c.RAFFLE?h.initRafflePropValue(a,s,r):a.type!==c.LINK&&a.type!==c.LIST_OF_LINK||h.initLinkPropValue(a,s,r))})),[2]}}))}))},this.handleUpdatePageParams=function(i){return e(E,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.pageParams=i.pageParams,this.isLoading=!0,[4,this.getPagePropValues(this.theme,this.page.type,this.pageParams||{})];case 1:return e=t.sent(),this.pageDataProvider=e,this.isLoading=!1,[2]}}))}))},this.handleUpdatePageComponentOrder=function(i){return e(E,void 0,void 0,(function(){return t(this,(function(e){return this.specification?this.specification.components=i.pageComponents.map((function(e){return new p(e)})):this.page.components=i.pageComponents.map((function(e){return new p(e)})),[2]}))}))},this.handleAddNewComponent=function(e){var t,i=new u(e.component);null===(t=E.theme)||void 0===t||t.components.push(i)},this.handleDeleteComponent=function(e){var t,i;(null===(t=E.theme)||void 0===t?void 0:t.components)&&(E.theme.components=E.theme.components.filter((function(t){return t.id!==e.componentId})));var n=E.pageComponents.filter((function(t){return t.componentId!==e.componentId}))||[];E.specification&&E.specification.components&&(E.specification.components=n),!E.specification&&(null===(i=E.page)||void 0===i?void 0:i.components)&&(E.page.components=n)},this.handleUpdateComponent=function(e){var t=E.theme.components.findIndex((function(t){return t.id===e.component.id}));-1!==t&&(E.theme.components[t]=new u(e.component))},this.handleAddNewPageComponent=function(i){return e(E,void 0,void 0,(function(){var e,n,a=this;return t(this,(function(t){switch(t.label){case 0:return e=new p(i.pageComponent),this.pageComponents.some((function(t){return t.id===e.id}))?[2]:[4,this.pageDataProvider.getPageComponentPropValues(e)];case 1:return n=t.sent(),o((function(){n.component.props.filter((function(e){return e.type===c.CUSTOM})).forEach((function(e){h.initCustomDataPropValue(e,n.propValues[e.name],n,a.router,a.theme.settings,!0)})),a.pageDataProvider.pageComponentPropValues.push(n),a.pageComponents.push(e)})),[2]}}))}))},this.handleDeletePageComponent=function(e){E.specification?E.specification.components=E.pageComponents.filter((function(t){return t.id!==e.pageComponentId})):E.page.components=E.pageComponents.filter((function(t){return t.id!==e.pageComponentId}))},this.handleSetSelectedComponent=function(e){E.selectedPageComponentId=e.componentId},this.handleSetHoveredComponent=function(e){E.hoveredPageComponentId=e.componentId},this.handleScrollToComponent=function(e){var t=e.componentId,i=E.componentRefs[t];i&&(E.isScrolledIntoView(i)||window.scrollTo({top:i.offsetTop,behavior:"smooth"}))},this.handleEditorReload=function(){window.location.reload()},this.updateThemeSettings=function(e){var t=e.settings;E.theme&&(E.theme.settings=new l(t))},this.router=i,n(this),this.startMessaging()}return Object.defineProperty(D.prototype,"specification",{get:function(){var e,t,i,n,o,a,r,s=this,p=this.page;return(null==p?void 0:p.type)===d.PRODUCT&&(r=null===(e=p.specifications)||void 0===e?void 0:e.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.productId)}))),(null==p?void 0:p.type)===d.CATEGORY&&(r=null===(t=p.specifications)||void 0===t?void 0:t.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.categoryId)}))),(null==p?void 0:p.type)===d.BRAND&&(r=null===(i=p.specifications)||void 0===i?void 0:i.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.brandId)}))),(null==p?void 0:p.type)===d.BLOG&&(r=null===(n=p.specifications)||void 0===n?void 0:n.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.blogId)}))),(null==p?void 0:p.type)===d.BLOG_CATEGORY&&(r=null===(o=p.specifications)||void 0===o?void 0:o.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.blogCategoryId)}))),(null==p?void 0:p.type)===d.RAFFLE_DETAIL&&(r=null===(a=p.specifications)||void 0===a?void 0:a.find((function(e){var t;return e.id===(null===(t=s.pageParams)||void 0===t?void 0:t.raffleId)}))),r},enumerable:!1,configurable:!0}),Object.defineProperty(D.prototype,"pageComponents",{get:function(){var e;return this.specification?this.specification.components:(null===(e=this.page)||void 0===e?void 0:e.components)||[]},enumerable:!1,configurable:!0}),Object.defineProperty(D.prototype,"selectedPageComponent",{get:function(){var e=this;return this.pageComponents.find((function(t){return t.id===e.selectedPageComponentId}))},enumerable:!1,configurable:!0}),Object.defineProperty(D.prototype,"selectedComponent",{get:function(){var e,t=this;return null===(e=this.theme)||void 0===e?void 0:e.components.find((function(e){var i;return e.id===(null===(i=t.selectedPageComponent)||void 0===i?void 0:i.componentId)}))},enumerable:!1,configurable:!0}),D.prototype.createLoadingListener=function(){var e=this;i((function(){return e.isLoading}),(function(){e.onLoadingChange()}))},D.prototype.getVariantIdFromParams=function(i,n){return e(this,void 0,void 0,(function(){var e,o,a,r,s,d,p;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=new URLSearchParams("?"+n),[4,E.searchProducts({productIdList:[i],priceListId:v.priceListId,salesChannelId:v.salesChannelId})];case 1:return(null==(o=t.sent())?void 0:o.data.length)?(a=o.data[0],r=a.variantTypes.map((function(e){return e.variantType.slug})),s=[],r.forEach((function(t,i){var n=a.variantTypes[i],o=e.get(t);if(o){var r=n.variantType.values.find((function(e){return e.slug===o}));r&&s.push(r)}})),(d=a.variants.find((function(e){return e.variantValues.every((function(e){return s.some((function(t){return t.id===e.id}))}))})))?[2,d.id]:[3,3]):[2];case 2:return p=t.sent(),console.error(p),[3,3];case 3:return[2]}}))}))},D}();!function(e){e.FRAME_DID_LOAD="FRAME_DID_LOAD",e.UPDATE_FRAME_DATA="UPDATE_FRAME_DATA",e.UPDATE_THEME_JSON="UPDATE_THEME_JSON",e.UPDATE_PROP_VALUE="UPDATE_PROP_VALUE",e.UPDATE_PAGE_PARAMS="UPDATE_PAGE_PARAMS",e.UPDATE_PAGE_COMPONENT_ORDER="UPDATE_PAGE_COMPONENT_ORDER",e.ADD_COMPONENT="ADD_COMPONENT",e.DELETE_COMPONENT="DELETE_COMPONENT",e.UPDATE_COMPONENT="UPDATE_COMPONENT",e.ADD_PAGE_COMPONENT="ADD_PAGE_COMPONENT",e.DELETE_PAGE_COMPONENT="DELETE_PAGE_COMPONENT",e.COMPONENT_MOUSE_OVER="COMPONENT_MOUSE_OVER",e.COMPONENT_MOUSE_LEAVE="COMPONENT_MOUSE_LEAVE",e.COMPONENT_CLICK="COMPONENT_CLICK",e.SET_SELECTED_COMPONENT="SET_SELECTED_COMPONENT",e.SET_HOVERED_COMPONENT="SET_HOVERED_COMPONENT",e.SCROLL_TO_COMPONENT="SCROLL_TO_COMPONENT",e.UPDATE_THEME_SETTINGS="UPDATE_THEME_SETTINGS",e.EDITOR_PAGE_CHANGE="EDITOR_PAGE_CHANGE",e.EDITOR_LOADING_CHANGE="EDITOR_LOADING_CHANGE",e.EDITOR_RELOAD="EDITOR_RELOAD"}(_||(_={}));export{_ as BridgeMessageType,D as default};