@ikas/storefront 6.1.0-beta.272 → 6.1.0-beta.274

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.
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as r}from'./../ext/tslib/tslib.es6.js';import{makeAutoObservable as o}from"mobx";import"../models/data/blog/category/index.js";import"../models/data/blog/content/index.js";import"../models/data/blog/meta-data/index.js";import"../models/data/blog/tag/index.js";import"../models/data/blog/index.js";import{IkasBrand as s}from"../models/data/brand/index.js";import"@ikas/storefront-models";import"../models/data/campaign-offer/index.js";import"../models/data/cart/campaign-offer/index.js";import{IkasCart as i}from"../models/data/cart/index.js";import"../models/data/category/path-item/index.js";import{IkasCategory as a}from"../models/data/category/index.js";import{IkasCheckout as n}from"../models/data/checkout/index.js";import"../models/data/checkout-settings/index.js";import"../models/data/city/index.js";import"../models/data/country/index.js";import"../models/data/customer/address/region/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/address/ikas-localized-customer-address.js";import"../models/data/customer/attribute/index.js";import"../models/data/customer/review/summary/index.js";import"../models/data/customer/review/index.js";import"../models/data/customer/index.js";import"../models/data/customer-form-data-input/index.js";import"../models/data/district/index.js";import"../models/data/favorite-product/index.js";import"../models/data/filter-category/index.js";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/order/address/region/index.js";import"../models/data/order/address/index.js";import"../models/data/order/line-item/option/value/index.js";import"../models/data/order/line-item/variant/value/index.js";import"../models/data/order/line-item/variant/index.js";import"../models/data/order/line-item/index.js";import"../models/data/order/order-transaction-with-prices/index.js";import"../models/data/order/package/index.js";import"../models/data/order/transaction/index.js";import"../models/data/order/index.js";import"../models/data/payment-gateway/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product/filter/index.js";import"../models/data/product/campaign-offer/index.js";import"../models/data/product/option-set/option/index.js";import"../models/data/product/option-set/index.js";import"../models/data/product/stock-location/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product/variant/index.js";import"../models/data/variant-type/index.js";import{IkasProduct as c}from"../models/data/product/index.js";import"../models/data/raffle/index.js";import"../models/data/shipping-zone/state/city/district/region/index.js";import"../models/data/state/index.js";import"../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../models/data/storefront-popup/storefront-popup-page-filter/index.js";import{IkasStorefrontPopup as d}from"../models/data/storefront-popup/index.js";import"../models/data/theme-json/index.js";import"../models/data/theme-json/component/index.js";import"../models/data/theme-json/custom-data/index.js";import"../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/brand-list/index.js";import"../models/ui/category-list/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/customer-review-summary-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/ikas-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{FacebookPixel as m}from"./facebookPixel.js";import{GoogleTagManager as u}from"./googleTagManager.js";import{IkasEventType as l}from"./events.js";import p from"lodash/cloneDeep";import{tryForEach as b}from"../utils/helper.js";import f from"./ikasV3.js";import{GoogleAnalytics as h}from"./googleAnalytics.js";import{TiktokPixel as g}from"./tiktokPixel.js";import{IkasBaseStore as j}from"../store/base.js";import"../store/customer/index.js";import"../store/cart/index.js";var v=function(){function v(){o(this)}return v.getCustomerInfo=function(){return t(this,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,(t=j.getInstance()).customerStore.waitUntilInitialized()];case 1:return e.sent(),(o=t.customerStore.customer)?[2,r(r({},o.basicInfo),{consentGranted:t.customerStore.customerConsentGranted})]:[2,null]}}))}))},v.pageView=function(r){return t(this,void 0,void 0,(function(){var t,o,s,i;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,4,,5]),[4,f.checkJourneyId()];case 1:return e.sent(),t=window.location.href,[4,v.getCustomerInfo()];case 2:return o=e.sent(),s=Date.now().toString(),u.pageView(t),m.pageView(t,s),[4,f.pageView(r,s)];case 3:return e.sent(),g.pageView(t),b(v.subscribers,(function(e){e.callback({type:l.PAGE_VIEW,data:{url:t,pageType:r,customer:o}})})),[3,5];case 4:return i=e.sent(),console.error(i),[3,5];case 5:return[2]}}))}))},v.productView=function(r){return t(this,void 0,void 0,(function(){var t,o,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Date.now().toString(),m.productView(r,t),u.productView(r),[4,f.productView(r,t)];case 1:return e.sent(),h.productView(r),g.productView(r),v.subscribers.length&&(o=new c(p(r)),b(v.subscribers,(function(t){t.callback({type:l.PRODUCT_VIEW,data:{productDetail:o}})}))),[3,3];case 2:return s=e.sent(),console.error(s),[3,3];case 3:return[2]}}))}))},v.addToCart=function(t,e,r,o,s){try{if(m.addToCart(t,e,r),u.addToCart(t,e,s),f.addToCart(t,e,o,r),h.addToCart(t,e),g.addToCart(t,e),v.subscribers.length){var a=p(t),n=new i(p(o));b(v.subscribers,(function(t){t.callback({type:l.ADD_TO_CART,data:{item:a,quantity:e,cart:n}})}))}}catch(t){console.error(t)}},v.removeFromCart=function(t,e,r){try{if(u.removeFromCart(t,e),h.removeFromCart(t,e),v.subscribers.length){var o=p(t),s=new i(p(r));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_FROM_CART,data:{item:o,quantity:e,cart:s}})}))}}catch(t){console.error(t)}},v.beginCheckout=function(t){try{var e=localStorage.getItem("gtmBeginCheckout");if(e&&t.id===e)return;localStorage.setItem("gtmBeginCheckout",t.id);var r=Date.now().toString();if(m.beginCheckout(t,r),u.beginCheckout(t),f.beginCheckout(t,r),h.beginCheckout(t),g.beginCheckout(t),v.subscribers.length){var o=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.BEGIN_CHECKOUT,data:{checkout:o}})}))}}catch(t){console.error(t)}},v.purchase=function(t,e){try{if(localStorage.removeItem("gtmBeginCheckout"),m.purchase(t,e.id||""),u.purchase(t,t.orderNumber||""),f.orderSuccess(t,e.id||""),h.purchase(t,t.orderNumber||""),g.purchase(t),v.subscribers.length){var r=new n(p(t)),o=p(e);b(v.subscribers,(function(t){t.callback({type:l.COMPLETE_CHECKOUT,data:{checkout:r,transaction:o}})}))}}catch(t){console.error(t)}},v.checkoutStep=function(t,e,r){try{if(u.checkoutStep(t,e,r),f.checkoutStep(t,e),h.checkoutStep(t,e,r),v.subscribers.length){var o=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.CHECKOUT_STEP,data:{checkout:o,step:e}})}))}}catch(t){console.error(t)}},v.disableHTML=function(){try{u.disableHTML()}catch(t){console.error(t)}},v.addToWishlist=function(t,e){try{var r=Date.now().toString();m.addToWishlist(t,r),g.addToWishlist(t),f.addToWishlist(t,r),h.addToWishlist(t),v.subscribers.length&&b(v.subscribers,(function(r){r.callback({type:e?l.REMOVE_FROM_WISHLIST:l.ADD_TO_WISHLIST,data:{productId:t}})}))}catch(t){console.error(t)}},v.search=function(t,e){try{var r=Date.now().toString();m.search(t,r),u.search(t),g.search(t),h.search(t),f.search(t,r,e),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.SEARCH,data:{searchKeyword:t}})}))}catch(t){console.error(t)}},v.completeRegistration=function(t,e){try{var o=Date.now().toString();e||(m.completeRegistration(o),u.completeRegistration(t),g.completeRegistration()),f.customerRegister(o),v.subscribers.length&&b(v.subscribers,(function(o){o.callback({type:l.CUSTOMER_REGISTER,data:r({email:t.email,firstName:t.firstName,lastName:t.lastName,notificationsAccepted:t.subscriptionStatus},e?{attributes:t.attributes}:{})})}))}catch(t){console.error(t)}},v.createEmailSubscripition=function(t){try{v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.EMAIL_SUBSCRIPTION,data:{email:t}})}))}catch(t){console.error(t)}},v.customerLogin=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerLogin(t),[4,f.customerLogin()]):[2];case 2:return e.sent(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_LOGIN,data:{customer:t}})})),[3,4];case 3:return r=e.sent(),console.error(r),[3,4];case 4:return[2]}}))}))},v.customerLogout=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){try{u.customerLogout(),v.subscribers.length&&b(v.subscribers,(function(t){t.callback({type:l.CUSTOMER_LOGOUT,data:{}})}))}catch(t){console.error(t)}return[2]}))}))},v.customerVisit=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerVisit(t),[4,f.customerVisit()]):[2];case 2:return e.sent(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_VISIT,data:{customer:t}})})),[3,4];case 3:return r=e.sent(),console.error(r),[3,4];case 4:return[2]}}))}))},v.viewCart=function(t){try{if(t){var e=Date.now().toString();if(m.viewCart(t,e),f.viewCart(t,e),h.viewCart(t),u.viewCart(t),v.subscribers.length){var r=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_CART,data:{cart:r}})}))}}}catch(t){console.error(t)}},v.viewCategory=function(t,e){try{var r=Date.now().toString();if(m.viewCategory(t,r),u.viewCategory(e,t),f.viewCategory(e,t,r),g.viewCategory(e),v.subscribers.length){var o=new a(p(e));b(v.subscribers,(function(e){e.callback({type:l.VIEW_CATEGORY,data:{categoryPath:t,category:o}})}))}}catch(t){console.error(t)}},v.viewBrand=function(t){try{if(f.viewBrand(t),v.subscribers.length){var e=new s(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_BRAND,data:{brand:e}})}))}}catch(t){console.error(t)}},v.viewStorefrontPopup=function(t){try{if(f.viewPopup(t.id),v.subscribers.length){var e=new d(p(t));b(v.subscribers,(function(t){t.callback({type:l.POPUP_VIEW,data:{popup:e}})}))}}catch(t){console.error(t)}},v.viewSearchResults=function(t,e){try{if(v.subscribers.length){var r=p(e).map((function(t){return new c(t)}));b(v.subscribers,(function(e){e.callback({type:l.VIEW_SEARCH_RESULTS,data:{searchKeyword:t,productDetails:r}})}))}}catch(t){console.error(t)}},v.viewListing=function(t){try{if(v.subscribers.length){var e=p(t).map((function(t){return new c(t)}));b(v.subscribers,(function(t){t.callback({type:l.VIEW_LISTING,data:{productDetails:e}})}))}}catch(t){console.error(t)}},v.contactForm=function(t){try{var e=Date.now().toString();if(m.contactForm(e),g.contactForm(),f.contactForm(e),v.subscribers.length){var r=p(t);b(v.subscribers,(function(t){t.callback({type:l.CONTACT_FORM,data:{form:r}})}))}}catch(t){console.error(t)}},v.addCouponCode=function(t){try{if(t&&v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.ADD_COUPON_CODE,data:{cart:e}})}))}}catch(t){console.error(t)}},v.removeCouponCode=function(t){try{if(t&&v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_COUPON_CODE,data:{cart:e}})}))}}catch(t){console.error(t)}},v.removeLoyaltyPoints=function(t){try{if(t&&v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_LOYALTY_POINTS,data:{cart:e}})}))}}catch(t){console.error(t)}},v.subscribers=[],v}();export{v as Analytics};
1
+ import{__awaiter as t,__generator as e,__assign as r}from'./../ext/tslib/tslib.es6.js';import{makeAutoObservable as o}from"mobx";import"../models/data/blog/category/index.js";import"../models/data/blog/content/index.js";import"../models/data/blog/meta-data/index.js";import"../models/data/blog/tag/index.js";import"../models/data/blog/index.js";import{IkasBrand as s}from"../models/data/brand/index.js";import"@ikas/storefront-models";import"../models/data/campaign-offer/index.js";import"../models/data/cart/campaign-offer/index.js";import{IkasCart as i}from"../models/data/cart/index.js";import"../models/data/category/path-item/index.js";import{IkasCategory as a}from"../models/data/category/index.js";import{IkasCheckout as n}from"../models/data/checkout/index.js";import"../models/data/checkout-settings/index.js";import"../models/data/city/index.js";import"../models/data/country/index.js";import"../models/data/customer/address/region/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/address/ikas-localized-customer-address.js";import"../models/data/customer/attribute/index.js";import"../models/data/customer/review/summary/index.js";import"../models/data/customer/review/index.js";import"../models/data/customer/index.js";import"../models/data/customer-form-data-input/index.js";import"../models/data/district/index.js";import"../models/data/favorite-product/index.js";import"../models/data/filter-category/index.js";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/order/address/region/index.js";import"../models/data/order/address/index.js";import"../models/data/order/line-item/option/value/index.js";import"../models/data/order/line-item/variant/value/index.js";import"../models/data/order/line-item/variant/index.js";import"../models/data/order/line-item/index.js";import"../models/data/order/order-transaction-with-prices/index.js";import"../models/data/order/package/index.js";import"../models/data/order/transaction/index.js";import"../models/data/order/index.js";import"../models/data/payment-gateway/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product/filter/index.js";import"../models/data/product/campaign-offer/index.js";import"../models/data/product/option-set/option/index.js";import"../models/data/product/option-set/index.js";import"../models/data/product/stock-location/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product/variant/index.js";import"../models/data/variant-type/index.js";import{IkasProduct as c}from"../models/data/product/index.js";import"../models/data/raffle/index.js";import"../models/data/shipping-zone/state/city/district/region/index.js";import"../models/data/state/index.js";import"../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../models/data/storefront-popup/storefront-popup-page-filter/index.js";import{IkasStorefrontPopup as d}from"../models/data/storefront-popup/index.js";import"../models/data/theme-json/index.js";import"../models/data/theme-json/component/index.js";import"../models/data/theme-json/custom-data/index.js";import"../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/brand-list/index.js";import"../models/ui/category-list/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/customer-review-summary-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/ikas-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{FacebookPixel as m}from"./facebookPixel.js";import{GoogleTagManager as u}from"./googleTagManager.js";import{IkasEventType as l}from"./events.js";import p from"lodash/cloneDeep";import{tryForEach as b}from"../utils/helper.js";import f from"./ikasV3.js";import{GoogleAnalytics as h}from"./googleAnalytics.js";import{TiktokPixel as g}from"./tiktokPixel.js";import{IkasBaseStore as j}from"../store/base.js";import"../store/customer/index.js";import"../store/cart/index.js";var v=function(){function v(){o(this)}return v.getCustomerInfo=function(){return t(this,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,(t=j.getInstance()).customerStore.waitUntilInitialized()];case 1:return e.sent(),(o=t.customerStore.customer)?[2,r(r({},o.basicInfo),{consentGranted:t.customerStore.customerConsentGranted})]:[2,null]}}))}))},v.pageView=function(r){return t(this,void 0,void 0,(function(){var t,o,s,i;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,4,,5]),[4,f.checkJourneyId()];case 1:return e.sent(),t=window.location.href,[4,v.getCustomerInfo()];case 2:return o=e.sent(),s=Date.now().toString(),u.pageView(t),m.pageView(t,s),[4,f.pageView(r,s)];case 3:return e.sent(),g.pageView(t),b(v.subscribers,(function(e){e.callback({type:l.PAGE_VIEW,data:{url:t,pageType:r,customer:o}})})),[3,5];case 4:return i=e.sent(),console.error(i),[3,5];case 5:return[2]}}))}))},v.productView=function(r){return t(this,void 0,void 0,(function(){var t,o,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Date.now().toString(),m.productView(r,t),u.productView(r),[4,f.productView(r,t)];case 1:return e.sent(),h.productView(r),g.productView(r),v.subscribers.length&&(o=new c(p(r)),b(v.subscribers,(function(t){t.callback({type:l.PRODUCT_VIEW,data:{productDetail:o}})}))),[3,3];case 2:return s=e.sent(),console.error(s),[3,3];case 3:return[2]}}))}))},v.addToCart=function(t,e,r,o,s){try{if(m.addToCart(t,e,r),u.addToCart(t,e,s),f.addToCart(t,e,o,r),h.addToCart(t,e),g.addToCart(t,e),v.subscribers.length){var a=p(t),n=new i(p(o));b(v.subscribers,(function(t){t.callback({type:l.ADD_TO_CART,data:{item:a,quantity:e,cart:n}})}))}}catch(t){console.error(t)}},v.removeFromCart=function(t,e,r){try{if(u.removeFromCart(t,e),h.removeFromCart(t,e),v.subscribers.length){var o=p(t),s=new i(p(r));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_FROM_CART,data:{item:o,quantity:e,cart:s}})}))}}catch(t){console.error(t)}},v.beginCheckout=function(t){try{var e=localStorage.getItem("gtmBeginCheckout");if(e&&t.id===e)return;localStorage.setItem("gtmBeginCheckout",t.id);var r=Date.now().toString();if(m.beginCheckout(t,r),u.beginCheckout(t),f.beginCheckout(t,r),h.beginCheckout(t),g.beginCheckout(t),v.subscribers.length){var o=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.BEGIN_CHECKOUT,data:{checkout:o}})}))}}catch(t){console.error(t)}},v.purchase=function(t,e){try{if(localStorage.removeItem("gtmBeginCheckout"),m.purchase(t,e.id||""),u.purchase(t,t.orderNumber||""),f.orderSuccess(t,e.id||""),h.purchase(t,t.orderNumber||""),g.purchase(t),v.subscribers.length){var r=new n(p(t)),o=p(e);b(v.subscribers,(function(t){t.callback({type:l.COMPLETE_CHECKOUT,data:{checkout:r,transaction:o}})}))}}catch(t){console.error(t)}},v.checkoutStep=function(t,e,r){try{var o=Date.now().toString();if(u.checkoutStep(t,e,r),f.checkoutStep(t,e),h.checkoutStep(t,e,r),m.checkoutStep(t,e,o),v.subscribers.length){var s=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.CHECKOUT_STEP,data:{checkout:s,step:e}})}))}}catch(t){console.error(t)}},v.disableHTML=function(){try{u.disableHTML()}catch(t){console.error(t)}},v.addToWishlist=function(t,e){try{var r=Date.now().toString();m.addToWishlist(t,r),g.addToWishlist(t),f.addToWishlist(t,r),h.addToWishlist(t),v.subscribers.length&&b(v.subscribers,(function(r){r.callback({type:e?l.REMOVE_FROM_WISHLIST:l.ADD_TO_WISHLIST,data:{productId:t}})}))}catch(t){console.error(t)}},v.search=function(t,e){try{var r=Date.now().toString();m.search(t,r),u.search(t),g.search(t),h.search(t),f.search(t,r,e),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.SEARCH,data:{searchKeyword:t}})}))}catch(t){console.error(t)}},v.completeRegistration=function(t,e){try{var o=Date.now().toString();e||(m.completeRegistration(o),u.completeRegistration(t),g.completeRegistration()),f.customerRegister(o),v.subscribers.length&&b(v.subscribers,(function(o){o.callback({type:l.CUSTOMER_REGISTER,data:r({email:t.email,firstName:t.firstName,lastName:t.lastName,notificationsAccepted:t.subscriptionStatus},e?{attributes:t.attributes}:{})})}))}catch(t){console.error(t)}},v.createEmailSubscripition=function(t){try{v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.EMAIL_SUBSCRIPTION,data:{email:t}})}))}catch(t){console.error(t)}},v.customerLogin=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerLogin(t),[4,f.customerLogin()]):[2];case 2:return e.sent(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_LOGIN,data:{customer:t}})})),[3,4];case 3:return r=e.sent(),console.error(r),[3,4];case 4:return[2]}}))}))},v.customerLogout=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){try{u.customerLogout(),v.subscribers.length&&b(v.subscribers,(function(t){t.callback({type:l.CUSTOMER_LOGOUT,data:{}})}))}catch(t){console.error(t)}return[2]}))}))},v.customerVisit=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerVisit(t),[4,f.customerVisit()]):[2];case 2:return e.sent(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_VISIT,data:{customer:t}})})),[3,4];case 3:return r=e.sent(),console.error(r),[3,4];case 4:return[2]}}))}))},v.viewCart=function(t){try{if(t){var e=Date.now().toString();if(m.viewCart(t,e),f.viewCart(t,e),h.viewCart(t),u.viewCart(t),v.subscribers.length){var r=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_CART,data:{cart:r}})}))}}}catch(t){console.error(t)}},v.viewCategory=function(t,e){try{var r=Date.now().toString();if(m.viewCategory(t,r),u.viewCategory(e,t),f.viewCategory(e,t,r),g.viewCategory(e),v.subscribers.length){var o=new a(p(e));b(v.subscribers,(function(e){e.callback({type:l.VIEW_CATEGORY,data:{categoryPath:t,category:o}})}))}}catch(t){console.error(t)}},v.viewBrand=function(t){try{if(f.viewBrand(t),v.subscribers.length){var e=new s(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_BRAND,data:{brand:e}})}))}}catch(t){console.error(t)}},v.viewStorefrontPopup=function(t){try{if(f.viewPopup(t.id),v.subscribers.length){var e=new d(p(t));b(v.subscribers,(function(t){t.callback({type:l.POPUP_VIEW,data:{popup:e}})}))}}catch(t){console.error(t)}},v.viewSearchResults=function(t,e){try{if(v.subscribers.length){var r=p(e).map((function(t){return new c(t)}));b(v.subscribers,(function(e){e.callback({type:l.VIEW_SEARCH_RESULTS,data:{searchKeyword:t,productDetails:r}})}))}}catch(t){console.error(t)}},v.viewListing=function(t){try{if(v.subscribers.length){var e=p(t).map((function(t){return new c(t)}));b(v.subscribers,(function(t){t.callback({type:l.VIEW_LISTING,data:{productDetails:e}})}))}}catch(t){console.error(t)}},v.contactForm=function(t){try{var e=Date.now().toString();if(m.contactForm(e),g.contactForm(),f.contactForm(e),v.subscribers.length){var r=p(t);b(v.subscribers,(function(t){t.callback({type:l.CONTACT_FORM,data:{form:r}})}))}}catch(t){console.error(t)}},v.addCouponCode=function(t){try{if(t&&v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.ADD_COUPON_CODE,data:{cart:e}})}))}}catch(t){console.error(t)}},v.removeCouponCode=function(t){try{if(t&&v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_COUPON_CODE,data:{cart:e}})}))}}catch(t){console.error(t)}},v.removeLoyaltyPoints=function(t){try{if(t&&v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_LOYALTY_POINTS,data:{cart:e}})}))}}catch(t){console.error(t)}},v.subscribers=[],v}();export{v as Analytics};
@@ -1,5 +1,6 @@
1
1
  import { IkasCheckout, IkasProduct, IkasOrderLineItem } from "../models";
2
2
  import { IkasCart } from "../models/data/cart";
3
+ import { CheckoutStep } from "../components/checkout/model";
3
4
  export declare class FacebookPixel {
4
5
  constructor();
5
6
  private static get fbpId();
@@ -8,6 +9,7 @@ export declare class FacebookPixel {
8
9
  static addToCart(item: IkasOrderLineItem, quantity: number, eventId: string): void;
9
10
  static beginCheckout(checkout: IkasCheckout, eventId: string): void;
10
11
  static purchase(checkout: IkasCheckout, eventId: string): void;
12
+ static checkoutStep(checkout: IkasCheckout, step: CheckoutStep, eventId: string): void;
11
13
  static addToWishlist(id: string, eventId: string): void;
12
14
  static search(searchKeyword: string, eventId: string): void;
13
15
  static completeRegistration(eventId: string): void;
@@ -1 +1 @@
1
- import{makeAutoObservable as t}from"mobx";import{IkasStorefrontConfig as n}from"@ikas/storefront-config";var e="undefined"==typeof window,r=function(){function r(){t(this)}return Object.defineProperty(r,"fbpId",{get:function(){return n.getFbpId()},enumerable:!1,configurable:!0}),r.pageView=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","PageView",{},{eventID:n}))}catch(t){console.error(t)}},r.productView=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","ViewContent",(r=t,{content_name:r.name,content_category:r.categories.length>0?r.categories[0].path.map((function(t){return t.name})).join(" > "):"",content_ids:[r.selectedVariant.id],content_type:"product",value:r.selectedVariant.price.finalPrice,currency:""===r.selectedVariant.price.currency?"TRY":r.selectedVariant.price.currency}),{eventID:n}))}catch(t){console.error(t)}var r},r.addToCart=function(t,n,r){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","AddToCart",function(t,n){var e,r,o=[];(null===(e=t.variant.categories)||void 0===e?void 0:e.length)&&(null===(r=t.variant.categories[0].categoryPath)||void 0===r||r.map((function(t){return o.push(t.name)}))),t.variant.categories&&t.variant.categories.length>0&&o.push(t.variant.categories[0].name);var i=o.length>0?o.join(" > "):"";return{content_name:t.variant.name,content_category:i,content_ids:[t.variant.id],content_type:"product",value:t.finalPrice,currency:t.currencyCode}}(t),{eventID:r}))}catch(t){console.error(t)}},r.beginCheckout=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","InitiateCheckout",o(t),{eventID:n}))}catch(t){console.error(t)}},r.purchase=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","Purchase",o(t),{eventID:n}))}catch(t){console.error(t)}},r.addToWishlist=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","AddToWishlist",{content_ids:[t]},{eventID:n}))}catch(t){console.error(t)}},r.search=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","Search",{search_string:t},{eventID:n}))}catch(t){console.error(t)}},r.completeRegistration=function(t){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","CompleteRegistration",{status:!0,value:0,currency:"TRY"},{eventID:t}))}catch(t){console.error(t)}},r.viewCart=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","ViewCart",function(t){var n=[],e=[];return t.items.map((function(t){n.push(t.variant.id||""),e.push({id:t.variant.id,quantity:t.quantity})})),{contents:e,content_type:"product",content_ids:n,currency:t.items[0].currencyCode,value:t.totalPrice,num_items:t.items.length}}(t),{eventID:n}))}catch(t){console.error(t)}},r.viewCategory=function(t,n){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","ViewCategory",{content_name:t},{eventID:n}))}catch(t){console.error(t)}},r.contactForm=function(t){try{return void(!e&&this.fbpId&&window.fbq&&window.fbq("track","ContactForm",{},{eventID:t}))}catch(t){console.error(t)}},r}();function o(t){var n=[],e=[];return t.items.map((function(t){n.push(t.variant.id||""),e.push({id:t.variant.id,quantity:t.quantity})})),{contents:e,content_category:"",content_type:"product",content_ids:n,currency:t.items[0].currencyCode,value:t.totalFinalPrice,num_items:t.items.length}}export{r as FacebookPixel};
1
+ import{makeAutoObservable as t}from"mobx";import{IkasStorefrontConfig as e}from"@ikas/storefront-config";import{CheckoutStep as n}from"../components/checkout/model.js";var r="undefined"==typeof window,o=function(){function o(){t(this)}return Object.defineProperty(o,"fbpId",{get:function(){return e.getFbpId()},enumerable:!1,configurable:!0}),o.pageView=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","PageView",{},{eventID:e}))}catch(t){console.error(t)}},o.productView=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","ViewContent",(n=t,{content_name:n.name,content_category:n.categories.length>0?n.categories[0].path.map((function(t){return t.name})).join(" > "):"",content_ids:[n.selectedVariant.id],content_type:"product",value:n.selectedVariant.price.finalPrice,currency:""===n.selectedVariant.price.currency?"TRY":n.selectedVariant.price.currency}),{eventID:e}))}catch(t){console.error(t)}var n},o.addToCart=function(t,e,n){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","AddToCart",c(t,e),{eventID:n}))}catch(t){console.error(t)}},o.beginCheckout=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","InitiateCheckout",i(t),{eventID:e}))}catch(t){console.error(t)}},o.purchase=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","Purchase",i(t),{eventID:e}))}catch(t){console.error(t)}},o.checkoutStep=function(t,e,o){var i,a,d;if(e===n.SHIPPING&&1!==(null===(i=t.availableShippingMethods)||void 0===i?void 0:i.length)||1===(null===(a=t.availableShippingMethods)||void 0===a?void 0:a.length)&&e===n.PAYMENT)try{!r&&this.fbpId&&window.fbq&&window.fbq("track","AddPaymentInfo",{currency:t.currencyCode,value:t.totalFinalPrice,shipping_tier:"Ground",coupon:t.couponCode,items:t.items.map((function(t){return c(t,t.quantity)}))},{eventID:o})}catch(t){console.error(t)}if(e===n.PAYMENT)try{!r&&this.fbpId&&window.fbq&&window.fbq("track","AddPaymentInfo",{currency:t.currencyCode,value:t.totalFinalPrice,coupon:t.couponCode,payment_type:null===(d=t.selectedPaymentGateway)||void 0===d?void 0:d.paymentMethodType,items:t.items.map((function(t){return c(t,t.quantity)}))},{eventID:o})}catch(t){console.error(t)}},o.addToWishlist=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","AddToWishlist",{content_ids:[t]},{eventID:e}))}catch(t){console.error(t)}},o.search=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","Search",{search_string:t},{eventID:e}))}catch(t){console.error(t)}},o.completeRegistration=function(t){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","CompleteRegistration",{status:!0,value:0,currency:"TRY"},{eventID:t}))}catch(t){console.error(t)}},o.viewCart=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","ViewCart",function(t){var e=[],n=[];return t.items.map((function(t){e.push(t.variant.id||""),n.push({id:t.variant.id,quantity:t.quantity})})),{contents:n,content_type:"product",content_ids:e,currency:t.items[0].currencyCode,value:t.totalPrice,num_items:t.items.length}}(t),{eventID:e}))}catch(t){console.error(t)}},o.viewCategory=function(t,e){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","ViewCategory",{content_name:t},{eventID:e}))}catch(t){console.error(t)}},o.contactForm=function(t){try{return void(!r&&this.fbpId&&window.fbq&&window.fbq("track","ContactForm",{},{eventID:t}))}catch(t){console.error(t)}},o}();function i(t){var e=[],n=[];return t.items.map((function(t){e.push(t.variant.id||""),n.push({id:t.variant.id,quantity:t.quantity})})),{contents:n,content_category:"",content_type:"product",content_ids:e,currency:t.items[0].currencyCode,value:t.totalFinalPrice,num_items:t.items.length}}function c(t,e){var n,r,o=[];(null===(n=t.variant.categories)||void 0===n?void 0:n.length)&&(null===(r=t.variant.categories[0].categoryPath)||void 0===r||r.map((function(t){return o.push(t.name)}))),t.variant.categories&&t.variant.categories.length>0&&o.push(t.variant.categories[0].name);var i=o.length>0?o.join(" > "):"";return{content_name:t.variant.name,content_category:i,content_ids:[t.variant.id],content_type:"product",value:t.finalPrice,currency:t.currencyCode}}export{o as FacebookPixel};
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.js';import*as e from"react";import{StorefrontWidgetSettingsStatusEnum as r,getStorefrontWidgetSettings as i,listEarningMethods as o,listLoyaltyProgramTiers as a,listSpendingMethodsByCartId as s,getLoyaltyCustomerInfo as u,listLoyaltyProgramPointHistory as c,useLoyaltyPoints as d,removeLoyaltyPointsFromCart as l}from"@ikas/storefront-api";import{IkasStorefrontConfig as f}from"@ikas/storefront-config";import{IkasBaseStore as v}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import g from"../../../store/product/index.js";import h from"../../../store/category/index.js";import m from"../../../store/brand/index.js";import{resolveStoreUrl as y}from"./common.js";import{formatCurrency as p}from"../../../utils/currency.js";import"lodash/get";function w(e){var r,y=this,w=v.getInstance(),S=function(){var t;return null===(t=w.cartStore.cart)||void 0===t?void 0:t.id},b=function(t){var n,e=null!==(n=null==t?void 0:t.themeSettingsJson)&&void 0!==n?n:t;if(!e)throw new Error("Loyalty widget settings not found");if("string"==typeof e)try{return JSON.parse(e)}catch(t){throw new Error("Loyalty widget settings format is invalid")}return e};return{getLoyaltyWidget:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return e?[2,b(e)]:[4,i()];case 1:if((t=n.sent()).isSuccess&&t.data)return[2,b(t.data)];throw new Error("Loyalty widget settings not found")}}))}))},subscribeToMarketingNotifications:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,v.getInstance().customerStore.createEmailSubscription((null===(t=v.getInstance().customerStore.customer)||void 0===t?void 0:t.email)||"")];case 1:return[2,n.sent()]}}))}))},listEarningMethods:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,o()];case 1:return[2,t.sent().data||[]]}}))}))},listLoyaltyProgramTier:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,a()];case 1:return[2,t.sent().data||[]]}}))}))},listSpendingMethodsByCartId:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,s({cartId:e||S()})];case 1:return[2,t.sent().data||[]]}}))}))},getLoyaltyCustomerInfo:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,u({cartId:S()||null})];case 1:return[2,t.sent().data||null]}}))}))},listLoyaltyProgramPointHistory:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t={},(r=null==e?void 0:e.type)&&(t.type=Array.isArray(r)?{in:r}:{eq:r}),[4,c(t)];case 1:return[2,n.sent().data||[]]}}))}))},useLoyaltyPoints:function(e){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,d({input:e})];case 1:return(t=n.sent()).isSuccess?(r=e.loyaltySpendingMethodId,[4,w.cartStore.getCart()]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,!!t.isSuccess]}}))}))},removeLoyaltyPointsFromCart:function(){return t(y,void 0,void 0,(function(){var t,e,i,o,a;return n(this,(function(n){switch(n.label){case 0:return t=S(),e=r||(null===(a=null===(o=null===(i=w.cartStore.cart)||void 0===i?void 0:i.loyaltyLines)||void 0===o?void 0:o[0])||void 0===a?void 0:a.loyaltySpendingMethodId),t&&e?[4,l({cartId:t,loyaltySpendingMethodId:e})]:[2];case 1:return n.sent().isSuccess?[4,w.cartStore.getCart()]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},getProducts:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?[4,g.searchProducts({input:{productIdList:e,page:1,perPage:e.length,priceListId:f.getPriceListId(),salesChannelId:f.getSalesChannelId()}},[])]:[2,[]];case 1:return t=n.sent(),[2,((null===(r=t.data)||void 0===r?void 0:r.data)||[]).map((function(t){var n,e,r,i,o,a;return{id:t.id,name:t.name,mainImageSrc:(null===(o=null===(i=null===(r=null===(e=null===(n=t.variants)||void 0===n?void 0:n[0])||void 0===e?void 0:e.images)||void 0===r?void 0:r.find((function(t){return t.isMain})))||void 0===i?void 0:i.image)||void 0===o?void 0:o.thumbnailSrc)||null,variants:(null===(a=t.variants)||void 0===a?void 0:a.map((function(t){var n,e,r,i;return{id:t.id,mainImageSrc:(null===(r=null===(e=null===(n=t.images)||void 0===n?void 0:n.find((function(t){return t.isMain})))||void 0===e?void 0:e.image)||void 0===r?void 0:r.thumbnailSrc)||null,variantText:(null===(i=t.variantValues)||void 0===i?void 0:i.map((function(t){return t.name})).join(" / "))||null}})))||[]}}))]}}))}))},getCategories:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,h.listCategory(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getBrands:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,m.listProductBrand(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getTags:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){return[2,[]]}))}))},formatCurrency:function(t){return p(t,f.getDefaultCurrencyCode()||"TRY",f.getDefaultCurrencySymbol()||"TRY")}}}var S=function(){e.useEffect((function(){if("undefined"!=typeof window&&"undefined"!=typeof document){var e=!1,o=function(t){if("function"==typeof window.startIkasLoyaltyWidget)try{window.startIkasLoyaltyWidget(t)}catch(t){console.error("[@ikas/storefront] Failed to start loyalty widget",t)}},a=function(t){var n=window.location.href.includes("http://localhost:3333/")?"http://localhost:3000/storefront-widget-script-injector.iife.js":"/sf/assets/popup/storefront-widget-script-injector.iife.js";if(n){var r=document.querySelector('script[data-ikas-loyalty-widget="true"]');if(r)"true"===r.dataset.loaded?o(t):r.addEventListener("load",(function(){return o(t)}),{once:!0});else{var i=document.createElement("script");i.src=n,i.defer=!0,i.setAttribute("data-ikas-loyalty-widget","true"),i.addEventListener("load",(function(){i.dataset.loaded="true",e||o(t)}),{once:!0}),i.addEventListener("error",(function(t){console.error("[@ikas/storefront] Failed to load loyalty widget script",n,t)}),{once:!0}),document.body.appendChild(i)}}};return t(void 0,void 0,void 0,(function(){var e,o,s,u,c,d;return n(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),(e=f.getLoyaltyPrograms()).length?(o=f.getStorefrontRoutingId(),s=[],e.forEach((function(t){var n;null===(n=t.salesChannels)||void 0===n||n.forEach((function(t){var n;null===(n=t.routingIds)||void 0===n||n.forEach((function(t){s.push(t)}))}))})),e.length>0&&o&&!s.some((function(t){return t===o}))?[2]:[4,i()]):[2];case 1:return(null==(u=l.sent())?void 0:u.isSuccess)&&u.data&&u.data.status===r.ACTIVE?[4,(g=u.data,t(void 0,void 0,void 0,(function(){var t,e,r,i;return n(this,(function(n){switch(n.label){case 0:return t={cdnURL:f.getCdnUrl()||"",merchantId:(null===(r=f.getMerchantSettings())||void 0===r?void 0:r.merchantId)||"",currency:f.getDefaultCurrencySymbol()||"TRY",callbacks:w(g),position:"fixed",storeURL:y()},[4,new Promise((function(t){var n=setInterval((function(){var e=f.getSessionId();e&&(clearInterval(n),t(e))}),100)}))];case 1:return n.sent(),(e=null===(i=v.getInstance().cartStore.cart)||void 0===i?void 0:i.id)&&(t.cartId=e),g&&(t.widgetSettings=g),[2,t]}}))})))]:[2];case 2:return c=l.sent(),window.ikasLoyaltyWidgetConfig=c,a(c),[3,4];case 3:return d=l.sent(),console.error("[@ikas/storefront] Failed to initialize loyalty widget",d),[3,4];case 4:return[2]}var g}))})),function(){e=!0}}}),[])};export{S as useLoyaltyWidget};
1
+ import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.js';import*as e from"react";import{StorefrontWidgetSettingsStatusEnum as r,getStorefrontWidgetSettings as i,listEarningMethods as o,listLoyaltyProgramTiers as a,listSpendingMethodsByCartId as s,getLoyaltyCustomerInfo as u,listLoyaltyProgramPointHistory as c,useLoyaltyPoints as d,removeLoyaltyPointsFromCart as l}from"@ikas/storefront-api";import{IkasStorefrontConfig as f}from"@ikas/storefront-config";import{IkasBaseStore as v}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import g from"../../../store/product/index.js";import m from"../../../store/category/index.js";import h from"../../../store/brand/index.js";import{resolveStoreUrl as y}from"./common.js";import{formatCurrency as p}from"../../../utils/currency.js";import"lodash/get";function w(e){var r,y=this,w=v.getInstance(),S=function(){var t;return null===(t=w.cartStore.cart)||void 0===t?void 0:t.id},b=function(t){var n,e=null!==(n=null==t?void 0:t.themeSettingsJson)&&void 0!==n?n:t;if(!e)throw new Error("Loyalty widget settings not found");if("string"==typeof e)try{return JSON.parse(e)}catch(t){throw new Error("Loyalty widget settings format is invalid")}return e};return{getLoyaltyWidget:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return e?[2,b(e)]:[4,i()];case 1:if((t=n.sent()).isSuccess&&t.data)return[2,b(t.data)];throw new Error("Loyalty widget settings not found")}}))}))},subscribeToMarketingNotifications:function(){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,v.getInstance().customerStore.createEmailSubscription((null===(t=v.getInstance().customerStore.customer)||void 0===t?void 0:t.email)||"")];case 1:return[2,n.sent()]}}))}))},listEarningMethods:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,o()];case 1:return[2,t.sent().data||[]]}}))}))},listLoyaltyProgramTier:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,a()];case 1:return[2,t.sent().data||[]]}}))}))},listSpendingMethodsByCartId:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,s({cartId:e||S()})];case 1:return[2,t.sent().data||[]]}}))}))},getLoyaltyCustomerInfo:function(){return t(y,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,u({cartId:S()||null})];case 1:return[2,t.sent().data||null]}}))}))},listLoyaltyProgramPointHistory:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t={},(r=null==e?void 0:e.type)&&(t.type=Array.isArray(r)?{in:r}:{eq:r}),[4,c(t)];case 1:return[2,n.sent().data||[]]}}))}))},useLoyaltyPoints:function(e){return t(y,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,d({input:e})];case 1:return(t=n.sent()).isSuccess?(r=e.loyaltySpendingMethodId,[4,w.cartStore.getCart()]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,!!t.isSuccess]}}))}))},removeLoyaltyPointsFromCart:function(){return t(y,void 0,void 0,(function(){var t,e,i,o,a;return n(this,(function(n){switch(n.label){case 0:return t=S(),e=r||(null===(a=null===(o=null===(i=w.cartStore.cart)||void 0===i?void 0:i.loyaltyLines)||void 0===o?void 0:o[0])||void 0===a?void 0:a.loyaltySpendingMethodId),t&&e?[4,l({cartId:t,loyaltySpendingMethodId:e})]:[2];case 1:return n.sent().isSuccess?[4,w.cartStore.getCart()]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},getProducts:function(e){return t(y,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?[4,g.searchProducts({input:{productIdList:e,page:1,perPage:e.length,priceListId:f.getPriceListId(),salesChannelId:f.getSalesChannelId()}},[])]:[2,[]];case 1:return t=n.sent(),[2,((null===(r=t.data)||void 0===r?void 0:r.data)||[]).map((function(t){var n,e,r,i,o,a,s;return{id:t.id,name:t.name,mainImageSrc:(null===(o=null===(i=null===(r=null===(e=null===(n=t.variants)||void 0===n?void 0:n[0])||void 0===e?void 0:e.images)||void 0===r?void 0:r.find((function(t){return t.isMain})))||void 0===i?void 0:i.image)||void 0===o?void 0:o.thumbnailSrc)||null,variants:(null===(a=t.variants)||void 0===a?void 0:a.map((function(t){var n,e,r,i;return{id:t.id,mainImageSrc:(null===(r=null===(e=null===(n=t.images)||void 0===n?void 0:n.find((function(t){return t.isMain})))||void 0===e?void 0:e.image)||void 0===r?void 0:r.thumbnailSrc)||null,variantText:(null===(i=t.variantValues)||void 0===i?void 0:i.map((function(t){return t.name})).join(" / "))||null}})))||[],url:null===(s=t.metaData)||void 0===s?void 0:s.slug}}))]}}))}))},getCategories:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,m.listCategory(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getBrands:function(e){return t(y,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.length)?(t={id:{in:e},pagination:{limit:e.length,page:1}},[4,h.listProductBrand(t)]):[2,[]];case 1:return r=n.sent(),[2,(null===(i=r.data)||void 0===i?void 0:i.data)||[]]}}))}))},getTags:function(e){return t(y,void 0,void 0,(function(){return n(this,(function(t){return[2,[]]}))}))},formatCurrency:function(t){return p(t,f.getDefaultCurrencyCode()||"TRY",f.getDefaultCurrencySymbol()||"TRY")}}}var S=function(){e.useEffect((function(){if("undefined"!=typeof window&&"undefined"!=typeof document){var e=!1,o=function(t){if("function"==typeof window.startIkasLoyaltyWidget)try{window.startIkasLoyaltyWidget(t)}catch(t){console.error("[@ikas/storefront] Failed to start loyalty widget",t)}},a=function(t){var n=window.location.href.includes("http://localhost:3333/")?"http://localhost:3000/storefront-widget-script-injector.iife.js":"/sf/assets/popup/storefront-widget-script-injector.iife.js";if(n){var r=document.querySelector('script[data-ikas-loyalty-widget="true"]');if(r)"true"===r.dataset.loaded?o(t):r.addEventListener("load",(function(){return o(t)}),{once:!0});else{var i=document.createElement("script");i.src=n,i.defer=!0,i.setAttribute("data-ikas-loyalty-widget","true"),i.addEventListener("load",(function(){i.dataset.loaded="true",e||o(t)}),{once:!0}),i.addEventListener("error",(function(t){console.error("[@ikas/storefront] Failed to load loyalty widget script",n,t)}),{once:!0}),document.body.appendChild(i)}}};return t(void 0,void 0,void 0,(function(){var e,o,s,u,c,d;return n(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),(e=f.getLoyaltyPrograms()).length?(o=f.getStorefrontRoutingId(),s=[],e.forEach((function(t){var n;null===(n=t.salesChannels)||void 0===n||n.forEach((function(t){var n;null===(n=t.routingIds)||void 0===n||n.forEach((function(t){s.push(t)}))}))})),e.length>0&&o&&!s.some((function(t){return t===o}))?[2]:[4,i()]):[2];case 1:return(null==(u=l.sent())?void 0:u.isSuccess)&&u.data&&u.data.status===r.ACTIVE?[4,(g=u.data,t(void 0,void 0,void 0,(function(){var t,e,r,i;return n(this,(function(n){switch(n.label){case 0:return t={cdnURL:f.getCdnUrl()||"",merchantId:(null===(r=f.getMerchantSettings())||void 0===r?void 0:r.merchantId)||"",currency:f.getDefaultCurrencySymbol()||"TRY",callbacks:w(g),position:"fixed",storeURL:y()},[4,new Promise((function(t){var n=setInterval((function(){var e=f.getSessionId();e&&(clearInterval(n),t(e))}),100)}))];case 1:return n.sent(),(e=null===(i=v.getInstance().cartStore.cart)||void 0===i?void 0:i.id)&&(t.cartId=e),g&&(t.widgetSettings=g),[2,t]}}))})))]:[2];case 2:return c=l.sent(),window.ikasLoyaltyWidgetConfig=c,a(c),[3,4];case 3:return d=l.sent(),console.error("[@ikas/storefront] Failed to initialize loyalty widget",d),[3,4];case 4:return[2]}var g}))})),function(){e=!0}}}),[])};export{S as useLoyaltyWidget};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "6.1.0-beta.272",
3
+ "version": "6.1.0-beta.274",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -17,17 +17,17 @@
17
17
  "build": "rm -rf build && rollup -c"
18
18
  },
19
19
  "dependencies": {
20
- "@ikas/loyalty-widget-renderer": "1.0.0-alpha.83",
20
+ "@ikas/loyalty-widget-renderer": "1.0.0-alpha.84",
21
21
  "@ikas/popup-renderer": "1.0.227",
22
22
  "@ikas/popup-script-injector": "1.0.0-alpha.21",
23
23
  "swiper": "11.0.6"
24
24
  },
25
25
  "devDependencies": {
26
- "@ikas/storefront-api": "^6.1.0-beta.272",
27
- "@ikas/storefront-config": "^6.1.0-beta.272",
28
- "@ikas/storefront-model-functions": "^6.1.0-beta.272",
29
- "@ikas/storefront-models": "^6.1.0-beta.272",
30
- "@ikas/storefront-providers": "^6.1.0-beta.272",
26
+ "@ikas/storefront-api": "^6.1.0-beta.274",
27
+ "@ikas/storefront-config": "^6.1.0-beta.274",
28
+ "@ikas/storefront-model-functions": "^6.1.0-beta.274",
29
+ "@ikas/storefront-models": "^6.1.0-beta.274",
30
+ "@ikas/storefront-providers": "^6.1.0-beta.274",
31
31
  "@ikas/localized-address": "1.0.0-beta.6",
32
32
  "@adyen/adyen-web": "^5.57.0",
33
33
  "@rollup/plugin-commonjs": "^22.0.0",
@@ -62,11 +62,11 @@
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@ikas/localized-address": "1.0.0-beta.6",
65
- "@ikas/storefront-api": "^6.1.0-beta.272",
66
- "@ikas/storefront-config": "^6.1.0-beta.272",
67
- "@ikas/storefront-model-functions": "^6.1.0-beta.272",
68
- "@ikas/storefront-models": "^6.1.0-beta.272",
69
- "@ikas/storefront-providers": "^6.1.0-beta.272",
65
+ "@ikas/storefront-api": "^6.1.0-beta.274",
66
+ "@ikas/storefront-config": "^6.1.0-beta.274",
67
+ "@ikas/storefront-model-functions": "^6.1.0-beta.274",
68
+ "@ikas/storefront-models": "^6.1.0-beta.274",
69
+ "@ikas/storefront-providers": "^6.1.0-beta.274",
70
70
  "mobx": "^6.1.3",
71
71
  "mobx-react-lite": "^3.1.5",
72
72
  "next": "12.2.0",