@ikas/storefront 4.13.7 → 4.13.9
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{__assign as t}from'./../../ext/tslib/tslib.es6.js';import*as e from"react";import{observer as o}from"mobx-react-lite";import i from"next/head.js";import{useRouter as a}from"next/router";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"../../models/data/brand/index.js";import{IkasThemeJsonPageType as r}from"@ikas/storefront-models";import"mobx";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../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/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/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"../../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{IkasIndexPageSeoSetting as n}from"../../models/data/storefront/index-page-seo-setting/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{IkasStorefrontConfig as s}from"@ikas/storefront-config";import"../../analytics/analytics.js";import"../../analytics/head/index.js";import"./index.js";import"next/image.js";import"@ikas/storefront-model-functions";import"../link/index.js";import"../page-editor/loader/style.module.scss.js";import"../google-captcha/index.js";import"../../pages/home.js";import"../../pages/_slug_/index.js";import"../../pages/pages/_slug_.js";import"../../pages/checkout.js";import"../../pages/account/index.js";import"../../pages/account/addresses.js";import"../../pages/account/orders/index.js";import"../../pages/account/orders/_id_.js";import"../../pages/account/login.js";import"../../pages/account/register.js";import"../../pages/account/forgot-password.js";import"../../pages/account/recover-password.js";import"../../pages/cart.js";import"../../pages/editor.js";import"../../pages/account/favorite-products.js";import"../../pages/search.js";import"next/error.js";import"../../pages/blog/index.js";import"../../pages/blog/_slug_.js";import"../../pages/raffle/_slug_.js";import"../../pages/raffle/index.js";import"../../pages/account/raffles.js";import"../../pages/account/activate.js";import{IkasBaseStore as d}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import"lodash/get";var l=o((function(o){var d,l,p,u=o.pageType,g=o.pageTitle,v=o.pageDescription,f=o.canonicals,h=o.disableIndex,j=o.pageSpecificData,x=o.merchantSettings,y=o.addOgpMetas,b=o.productReviewSummary,C=a(),k="undefined"!=typeof window,D="local"===process.env.NEXT_PUBLIC_ENV,T=C.asPath.split("?")[0].replace("/",""),E=(T="/"===T.charAt(T.length-1)?T.slice(0,-1):T).startsWith("pages/"),w=s.getCurrentRouting(),L=(null==w?void 0:w.path)?"/"+w.path:"",P=D?"http://localhost:3333":"https://"+s.getDomain(),R=null===(d=s.getIndexPageSeoSettings())||void 0===d?void 0:d.find((function(t){return t.locale===s.getCurrentLocale()})),_=R?new n(R):null;e.useEffect((function(){document.documentElement.lang=s.getCurrentLocale()}),[u,j]);var S=e.useMemo((function(){if(j&&j.href)return"".concat(P).concat(j.href)}),[j]),O=e.useMemo((function(){var t,e,o=[];if(y){if(o.push({property:"og:type",content:"website"}),o.push({property:"og:site_name",content:"https://"+s.getDomain()}),g&&o.push({property:"og:title",content:g}),v&&o.push({property:"og:description",content:v}),u===r.INDEX){var i=null,a=null;!g&&(null==_?void 0:_.pageTitle)&&(i=_.pageTitle),!v&&(null==_?void 0:_.description)&&(a=_.description);var n=null===(t=s.getMetaTemplates())||void 0===t?void 0:t.find((function(t){return t.locale===s.getCurrentLocale()&&t.pageType===u}));n&&(i=m(j,u,n.titleTemplate||""),a=m(j,u,n.descriptionTemplate||"")),i&&o.push({property:"og:title",content:i}),a&&o.push({property:"og:description",content:a})}if(o.push({property:"og:url",content:S||(k?window.location.href:"")||"https://".concat(s.getDomain())}),j&&u===r.PRODUCT){var d=j.selectedVariant.mainImage;(null==d?void 0:d.image)&&o.push({property:"og:image",content:d.image.src})}else(null==_?void 0:_.icon)?o.push({property:"og:image",content:null===(e=null==_?void 0:_.icon)||void 0===e?void 0:e.src}):(null==x?void 0:x.logo)&&o.push({property:"og:image",content:x.logo.src});if(j&&u===r.CATEGORY){var l=j;l.image&&o.push({property:"og:image",content:l.image.src})}if(j&&u===r.BRAND){var c=j;c.image&&o.push({property:"og:image",content:c.image.src})}}return o}),[g,j,S,v,x,y,x]),I=e.useMemo((function(){var e=[];if(x){var o={"@context":"https://schema.org","@type":"Website",url:"https://"+s.getDomain()},i=function(e){var o,i,a,r,n,d,l=(null==e?void 0:e.logo)?e.logo.src:void 0;return{"@context":"https://schema.org","@type":"Store",name:null==e?void 0:e.merchantName,logo:l,image:l,url:"https://"+s.getDomain(),telephone:null==e?void 0:e.phone,address:t(t({"@type":"PostalAddress",streetAddress:null===(o=e.address)||void 0===o?void 0:o.addressLine1,addressLocality:null===(a=null===(i=e.address)||void 0===i?void 0:i.city)||void 0===a?void 0:a.name},e.address&&e.address.state&&{addressRegion:e.address.state.code}),{postalCode:null===(r=e.address)||void 0===r?void 0:r.postalCode,addressCountry:null===(d=null===(n=e.address)||void 0===n?void 0:n.country)||void 0===d?void 0:d.code})}}(x);e.push(o),e.push(i)}if(j&&u===r.PRODUCT){var a=j,n=function(e,o){var i,a,r,n,d;try{var l=s.getCurrentRouting(),c=null==l?void 0:l.path,m=function(t){return c?"https://".concat(s.getDomain(),"/").concat(c).concat(t):"https://".concat(s.getDomain()).concat(t)},p=e.selectedVariant;return t(t({"@context":"https://schema.org/","@type":"Product",name:e.name,description:null===(i=e.metaData)||void 0===i?void 0:i.description,image:null===(a=p.images)||void 0===a?void 0:a.map((function(t){return t.image?t.image.src:""})),productId:p.id,sku:p.sku,mpn:(null===(r=p.barcodeList)||void 0===r?void 0:r.length)?p.barcodeList[0]:"",brand:{"@type":"Brand",name:null===(n=e.brand)||void 0===n?void 0:n.name}},o&&{aggregateRating:{"@type":"AggregateRating",ratingValue:o.averageStar,reviewCount:o.totalReview}}),{offers:{"@type":"Offer",url:m(e.href),priceCurrency:p.price.currency||"TRY",price:(null!==(d=p.campaignPrice)&&void 0!==d?d:p.price.finalPrice).toFixed(2),priceValidUntil:"",itemCondition:"https://schema.org/NewCondition",availability:p.stock>0?"https://schema.org/InStock":"https://schema.org/OutOfStock"}})}catch(t){}}(a,b||null);if(n&&e.push(n),a.categories.length)(l=c(a.categories[0],a))&&e.push(l)}if(j&&u===r.CATEGORY){var d=function(t){var e,o;try{var i=s.getCurrentRouting(),a=null==i?void 0:i.path,r=function(t){return a?"https://".concat(s.getDomain(),"/").concat(a).concat(t):"https://".concat(s.getDomain()).concat(t)};return{"@context":"http://schema.org","@type":"CollectionPage",url:r(t.href),name:null===(e=t.metaData)||void 0===e?void 0:e.pageTitle,description:null===(o=t.metaData)||void 0===o?void 0:o.description,image:t.image?t.image.src:void 0}}catch(t){}}(j),l=c(j);d&&e.push(d),l&&e.push(l)}if(j&&u===r.BLOG){var m=function(e){var o;try{var i="https://".concat(s.getDomain()).concat(e.href),a=function(t){var e=new Date(t),o=e.getFullYear(),i=(e.getMonth()+1).toString().padStart(2,"0"),a=e.getDate().toString().padStart(2,"0");return"".concat(o,"-").concat(i,"-").concat(a)},r="".concat(e.writer.firstName," ").concat(e.writer.lastName),n=(new DOMParser).parseFromString(e.blogContent.content,"text/html").body.textContent;return t(t({"@context":"https://schema.org","@type":"BlogPosting",headline:e.title,image:null===(o=e.image)||void 0===o?void 0:o.src},e.category&&{genre:e.category.name}),{url:i,datePublished:a(e.createdAt),dateCreated:a(e.createdAt),dateModified:a(e.updatedAt),description:e.shortDescription,articleBody:n,author:{"@type":"Person",name:r}})}catch(t){}}(j);m&&e.push(m)}return e}),[j,x]),A=e.useMemo((function(){var t,e=null===(t=s.getMetaTemplates())||void 0===t?void 0:t.find((function(t){return t.locale===s.getCurrentLocale()&&t.pageType===u}));return e?m(j,u,e.titleTemplate||""):null}),[u,j]),M=e.useMemo((function(){var t,e=null===(t=s.getMetaTemplates())||void 0===t?void 0:t.find((function(t){return t.locale===s.getCurrentLocale()&&t.pageType===u}));return e?m(j,u,e.descriptionTemplate||""):null}),[u,j]),N=e.useMemo((function(){var t,e=null===(t=s.getFavicon())||void 0===t?void 0:t.id;return(null==_?void 0:_.favIcon)&&(e=_.favIcon),e||null}),[]),B=e.useCallback((function(){var t=s.getCustom();return!!t&&!!t.isEPayKolayEnabled}),[]),U=[];s.getRoutings().forEach((function(t){var e;(null===(e=t.countryCodes)||void 0===e?void 0:e.length)?t.countryCodes.forEach((function(e){U.push({routing:t,hrefLang:t.locale+"-"+e})})):U.push({routing:t,hrefLang:t.locale})}));var V=function(t){var e,o,i,a,r,n=j,s=null===(o=null===(e=null==n?void 0:n.metaData)||void 0===e?void 0:e.translations)||void 0===o?void 0:o.find((function(e){return e.locale===t.locale}));if(s&&(null==s?void 0:s.slug))return s.slug;var d=U.find((function(t){return!t.routing.path}));return d&&(null===(r=null===(a=null===(i=null==n?void 0:n.metaData)||void 0===i?void 0:i.translations)||void 0===a?void 0:a.find((function(t){return t.locale===d.routing.locale})))||void 0===r?void 0:r.slug)||""};return e.createElement(i,null,e.createElement("title",null,g||A||(null==_?void 0:_.pageTitle)||""),e.createElement("meta",{name:"description",content:v||M||(null==_?void 0:_.description)||""}),u===r.CHECKOUT&&B()&&e.createElement("script",{type:"text/javascript",src:"https://cdn-epeykolay.mncdn.com/".concat((null===(l=s.getApiUrl())||void 0===l?void 0:l.includes("myikas.com"))?"epay":"epay-uat","/").concat((null===(p=s.getApiUrl())||void 0===p?void 0:p.includes("myikas.com"))?"containerServices":"containerServicesTest",".js")}),U.length>1&&U.filter((function(t){return!E||t.routing.id===(null==w?void 0:w.id)})).map((function(t){return e.createElement("link",{key:t.routing.id+t.hrefLang,rel:"alternate",hrefLang:t.hrefLang,href:"".concat(P+(t.routing.path?"/"+t.routing.path:""),"/").concat(V(t.routing))})})),!!h&&e.createElement("meta",{name:"robots",content:"noindex"}),!!y&&O.map((function(t,o){return e.createElement("meta",{key:"".concat(t.content,"-").concat(o),property:t.property,content:t.content})})),!!f&&f.map((function(t,o){return e.createElement("link",{key:o+"url",rel:"canonical",href:"".concat(P).concat(L).concat(t)})})),N&&e.createElement("link",{rel:"shortcut icon",href:"".concat(process.env.NEXT_PUBLIC_CDN_URL,"images/").concat(N,"/image_180.webp"),type:"image/webp"}),e.createElement("link",{rel:"canonical",href:"".concat(P).concat(L,"/").concat(T)}),!!I.length&&I.map((function(t,o){return e.createElement("script",{key:o,type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(t)}})})))}));function c(t,e){try{var o=d.getInstance(),i=s.getCurrentRouting(),a=null==i?void 0:i.path,n=function(t){return a?"https://".concat(s.getDomain(),"/").concat(a).concat(t):"https://".concat(s.getDomain()).concat(t)},l=t.categoryPathItems.map((function(t,e){return{"@type":"ListItem",position:e+1,name:t.name,item:n(t.href)}}));return l.push({"@type":"ListItem",position:t.categoryPathItems.length+1,name:t.name,item:n(t.href)}),o.currentPageType===r.PRODUCT&&e&&l.push({"@type":"ListItem",position:l.length+1,name:e.name,item:n(e.productHref)}),{"@context":"http://schema.org","@type":"BreadcrumbList",itemListElement:l}}catch(t){}}function m(t,e,o){var i,a,n,s=o;try{switch(e){case r.PRODUCT:var d=t,l=d.name,c=(null===(i=d.brand)||void 0===i?void 0:i.name)||"",m=d.selectedVariant.sku||"",u=(null===(a=d.selectedVariant.barcodeList)||void 0===a?void 0:a.length)?d.selectedVariant.barcodeList[0]:"",g=null!==(n=d.selectedVariant.formattedCampaignPrice)&&void 0!==n?n:d.selectedVariant.formattedFinalPrice;s.includes("{{name}}")&&(s=p(s,"{{name}}",l)),s.includes("{{brand}}")&&(s=p(s,"{{brand}}",c)),s.includes("{{sku}}")&&(s=p(s,"{{sku}}",m)),s.includes("{{barcode}}")&&(s=p(s,"{{barcode}}",u)),s.includes("{{price}}")&&(s=p(s,"{{price}}",g.toString()));break;case r.BRAND:case r.CATEGORY:case r.BLOG_CATEGORY:var v=t.name||"";s.includes("{{name}}")&&(s=p(s,"{{name}}",v));break;case r.BLOG:var f=t.title;s.includes("{{name}}")&&(s=p(s,"{{name}}",f))}}catch(t){}return s.trimEnd()}function p(t,e,o){var i=new RegExp(e,"g");return t.replace(i,o)}export{l as IkasPageHead};
|
|
1
|
+
import{__assign as e}from'./../../ext/tslib/tslib.es6.js';import*as t from"react";import{observer as o}from"mobx-react-lite";import i from"next/head.js";import{useRouter as a}from"next/router";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"../../models/data/brand/index.js";import{IkasThemeJsonPageType as r}from"@ikas/storefront-models";import"mobx";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../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/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/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"../../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{IkasIndexPageSeoSetting as n}from"../../models/data/storefront/index-page-seo-setting/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{IkasStorefrontConfig as s}from"@ikas/storefront-config";import"../../analytics/analytics.js";import"../../analytics/head/index.js";import"./index.js";import"next/image.js";import"@ikas/storefront-model-functions";import"../link/index.js";import"../page-editor/loader/style.module.scss.js";import"../google-captcha/index.js";import"../../pages/home.js";import"../../pages/_slug_/index.js";import"../../pages/pages/_slug_.js";import"../../pages/checkout.js";import"../../pages/account/index.js";import"../../pages/account/addresses.js";import"../../pages/account/orders/index.js";import"../../pages/account/orders/_id_.js";import"../../pages/account/login.js";import"../../pages/account/register.js";import"../../pages/account/forgot-password.js";import"../../pages/account/recover-password.js";import"../../pages/cart.js";import"../../pages/editor.js";import"../../pages/account/favorite-products.js";import"../../pages/search.js";import"next/error.js";import"../../pages/blog/index.js";import"../../pages/blog/_slug_.js";import"../../pages/raffle/_slug_.js";import"../../pages/raffle/index.js";import"../../pages/account/raffles.js";import"../../pages/account/activate.js";import{IkasBaseStore as d}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import"lodash/get";var l=o((function(o){var d,l,p,u=o.pageType,g=o.pageTitle,v=o.pageDescription,f=o.canonicals,h=o.disableIndex,j=o.pageSpecificData,x=o.merchantSettings,y=o.addOgpMetas,b=o.productReviewSummary,C=a(),k="undefined"!=typeof window,w="local"===process.env.NEXT_PUBLIC_ENV,D=C.asPath.split("?")[0].replace("/",""),T=(D="/"===D.charAt(D.length-1)?D.slice(0,-1):D).startsWith("pages/"),E=s.getCurrentRouting(),L=(null==E?void 0:E.path)?"/"+E.path:"",P=w?"http://localhost:3333":"https://"+s.getDomain(),R=null===(d=s.getIndexPageSeoSettings())||void 0===d?void 0:d.find((function(e){return e.locale===s.getCurrentLocale()})),_=R?new n(R):null;t.useEffect((function(){document.documentElement.lang=s.getCurrentLocale()}),[u,j]);var S=t.useMemo((function(){if(j&&j.href)return"".concat(P).concat(j.href)}),[j]),O=t.useMemo((function(){var e,t,o=[];if(y){if(o.push({property:"og:type",content:"website"}),o.push({property:"og:site_name",content:"https://"+s.getDomain()}),g&&o.push({property:"og:title",content:g}),v&&o.push({property:"og:description",content:v}),u===r.INDEX){var i=null,a=null;!g&&(null==_?void 0:_.pageTitle)&&(i=_.pageTitle),!v&&(null==_?void 0:_.description)&&(a=_.description);var n=null===(e=s.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===s.getCurrentLocale()&&e.pageType===u}));n&&(i=m(j,u,n.titleTemplate||""),a=m(j,u,n.descriptionTemplate||"")),i&&o.push({property:"og:title",content:i}),a&&o.push({property:"og:description",content:a})}if(o.push({property:"og:url",content:S||(k?window.location.href:"")||"https://".concat(s.getDomain())}),j&&u===r.PRODUCT){var d=j.selectedVariant.mainImage;(null==d?void 0:d.image)&&o.push({property:"og:image",content:d.image.src.replace(".webp",".jpg")})}else(null==_?void 0:_.icon)?o.push({property:"og:image",content:null===(t=null==_?void 0:_.icon)||void 0===t?void 0:t.src.replace(".webp",".jpg")}):(null==x?void 0:x.logo)&&o.push({property:"og:image",content:x.logo.src.replace(".webp",".jpg")});if(j&&u===r.CATEGORY){var l=j;l.image&&o.push({property:"og:image",content:l.image.src.replace(".webp",".jpg")})}if(j&&u===r.BRAND){var c=j;c.image&&o.push({property:"og:image",content:c.image.src.replace(".webp",".jpg")})}}return o}),[g,j,S,v,x,y,x]),I=t.useMemo((function(){var t=[];if(x){var o={"@context":"https://schema.org","@type":"Website",url:"https://"+s.getDomain()},i=function(t){var o,i,a,r,n,d,l=(null==t?void 0:t.logo)?t.logo.src:void 0;return{"@context":"https://schema.org","@type":"Store",name:null==t?void 0:t.merchantName,logo:l,image:l,url:"https://"+s.getDomain(),telephone:null==t?void 0:t.phone,address:e(e({"@type":"PostalAddress",streetAddress:null===(o=t.address)||void 0===o?void 0:o.addressLine1,addressLocality:null===(a=null===(i=t.address)||void 0===i?void 0:i.city)||void 0===a?void 0:a.name},t.address&&t.address.state&&{addressRegion:t.address.state.code}),{postalCode:null===(r=t.address)||void 0===r?void 0:r.postalCode,addressCountry:null===(d=null===(n=t.address)||void 0===n?void 0:n.country)||void 0===d?void 0:d.code})}}(x);t.push(o),t.push(i)}if(j&&u===r.PRODUCT){var a=j,n=function(t,o){var i,a,r,n,d;try{var l=s.getCurrentRouting(),c=null==l?void 0:l.path,m=function(e){return c?"https://".concat(s.getDomain(),"/").concat(c).concat(e):"https://".concat(s.getDomain()).concat(e)},p=t.selectedVariant;return e(e({"@context":"https://schema.org/","@type":"Product",name:t.name,description:null===(i=t.metaData)||void 0===i?void 0:i.description,image:null===(a=p.images)||void 0===a?void 0:a.map((function(e){return e.image?e.image.src:""})),productId:p.id,sku:p.sku,mpn:(null===(r=p.barcodeList)||void 0===r?void 0:r.length)?p.barcodeList[0]:"",brand:{"@type":"Brand",name:null===(n=t.brand)||void 0===n?void 0:n.name}},o&&{aggregateRating:{"@type":"AggregateRating",ratingValue:o.averageStar,reviewCount:o.totalReview}}),{offers:{"@type":"Offer",url:m(t.href),priceCurrency:p.price.currency||"TRY",price:(null!==(d=p.campaignPrice)&&void 0!==d?d:p.price.finalPrice).toFixed(2),priceValidUntil:"",itemCondition:"https://schema.org/NewCondition",availability:p.stock>0?"https://schema.org/InStock":"https://schema.org/OutOfStock"}})}catch(e){}}(a,b||null);if(n&&t.push(n),a.categories.length)(l=c(a.categories[0],a))&&t.push(l)}if(j&&u===r.CATEGORY){var d=function(e){var t,o;try{var i=s.getCurrentRouting(),a=null==i?void 0:i.path,r=function(e){return a?"https://".concat(s.getDomain(),"/").concat(a).concat(e):"https://".concat(s.getDomain()).concat(e)};return{"@context":"http://schema.org","@type":"CollectionPage",url:r(e.href),name:null===(t=e.metaData)||void 0===t?void 0:t.pageTitle,description:null===(o=e.metaData)||void 0===o?void 0:o.description,image:e.image?e.image.src:void 0}}catch(e){}}(j),l=c(j);d&&t.push(d),l&&t.push(l)}if(j&&u===r.BLOG){var m=function(t){var o;try{var i="https://".concat(s.getDomain()).concat(t.href),a=function(e){var t=new Date(e),o=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0");return"".concat(o,"-").concat(i,"-").concat(a)},r="".concat(t.writer.firstName," ").concat(t.writer.lastName),n=(new DOMParser).parseFromString(t.blogContent.content,"text/html").body.textContent;return e(e({"@context":"https://schema.org","@type":"BlogPosting",headline:t.title,image:null===(o=t.image)||void 0===o?void 0:o.src},t.category&&{genre:t.category.name}),{url:i,datePublished:a(t.createdAt),dateCreated:a(t.createdAt),dateModified:a(t.updatedAt),description:t.shortDescription,articleBody:n,author:{"@type":"Person",name:r}})}catch(e){}}(j);m&&t.push(m)}return t}),[j,x]),A=t.useMemo((function(){var e,t=null===(e=s.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===s.getCurrentLocale()&&e.pageType===u}));return t?m(j,u,t.titleTemplate||""):null}),[u,j]),M=t.useMemo((function(){var e,t=null===(e=s.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===s.getCurrentLocale()&&e.pageType===u}));return t?m(j,u,t.descriptionTemplate||""):null}),[u,j]),N=t.useMemo((function(){var e,t=null===(e=s.getFavicon())||void 0===e?void 0:e.id;return(null==_?void 0:_.favIcon)&&(t=_.favIcon),t||null}),[]),B=t.useCallback((function(){var e=s.getCustom();return!!e&&!!e.isEPayKolayEnabled}),[]),U=[];s.getRoutings().forEach((function(e){var t;(null===(t=e.countryCodes)||void 0===t?void 0:t.length)?e.countryCodes.forEach((function(t){U.push({routing:e,hrefLang:e.locale+"-"+t})})):U.push({routing:e,hrefLang:e.locale})}));var V=function(e){var t,o,i,a,r,n=j,s=null===(o=null===(t=null==n?void 0:n.metaData)||void 0===t?void 0:t.translations)||void 0===o?void 0:o.find((function(t){return t.locale===e.locale}));if(s&&(null==s?void 0:s.slug))return s.slug;var d=U.find((function(e){return!e.routing.path}));return d&&(null===(r=null===(a=null===(i=null==n?void 0:n.metaData)||void 0===i?void 0:i.translations)||void 0===a?void 0:a.find((function(e){return e.locale===d.routing.locale})))||void 0===r?void 0:r.slug)||""};return t.createElement(i,null,t.createElement("title",null,g||A||(null==_?void 0:_.pageTitle)||""),t.createElement("meta",{name:"description",content:v||M||(null==_?void 0:_.description)||""}),u===r.CHECKOUT&&B()&&t.createElement("script",{type:"text/javascript",src:"https://cdn-epeykolay.mncdn.com/".concat((null===(l=s.getApiUrl())||void 0===l?void 0:l.includes("myikas.com"))?"epay":"epay-uat","/").concat((null===(p=s.getApiUrl())||void 0===p?void 0:p.includes("myikas.com"))?"containerServices":"containerServicesTest",".js")}),U.length>1&&U.filter((function(e){return!T||e.routing.id===(null==E?void 0:E.id)})).map((function(e){return t.createElement("link",{key:e.routing.id+e.hrefLang,rel:"alternate",hrefLang:e.hrefLang,href:"".concat(P+(e.routing.path?"/"+e.routing.path:""),"/").concat(V(e.routing))})})),!!h&&t.createElement("meta",{name:"robots",content:"noindex"}),!!y&&O.map((function(e,o){return t.createElement("meta",{key:"".concat(e.content,"-").concat(o),property:e.property,content:e.content})})),!!f&&f.map((function(e,o){return t.createElement("link",{key:o+"url",rel:"canonical",href:"".concat(P).concat(L).concat(e)})})),N&&t.createElement("link",{rel:"shortcut icon",href:"".concat(process.env.NEXT_PUBLIC_CDN_URL,"images/").concat(N,"/image_180.webp"),type:"image/webp"}),t.createElement("link",{rel:"canonical",href:"".concat(P).concat(L,"/").concat(D)}),!!I.length&&I.map((function(e,o){return t.createElement("script",{key:o,type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(e)}})})))}));function c(e,t){try{var o=d.getInstance(),i=s.getCurrentRouting(),a=null==i?void 0:i.path,n=function(e){return a?"https://".concat(s.getDomain(),"/").concat(a).concat(e):"https://".concat(s.getDomain()).concat(e)},l=e.categoryPathItems.map((function(e,t){return{"@type":"ListItem",position:t+1,name:e.name,item:n(e.href)}}));return l.push({"@type":"ListItem",position:e.categoryPathItems.length+1,name:e.name,item:n(e.href)}),o.currentPageType===r.PRODUCT&&t&&l.push({"@type":"ListItem",position:l.length+1,name:t.name,item:n(t.productHref)}),{"@context":"http://schema.org","@type":"BreadcrumbList",itemListElement:l}}catch(e){}}function m(e,t,o){var i,a,n,s=o;try{switch(t){case r.PRODUCT:var d=e,l=d.name,c=(null===(i=d.brand)||void 0===i?void 0:i.name)||"",m=d.selectedVariant.sku||"",u=(null===(a=d.selectedVariant.barcodeList)||void 0===a?void 0:a.length)?d.selectedVariant.barcodeList[0]:"",g=null!==(n=d.selectedVariant.formattedCampaignPrice)&&void 0!==n?n:d.selectedVariant.formattedFinalPrice;s.includes("{{name}}")&&(s=p(s,"{{name}}",l)),s.includes("{{brand}}")&&(s=p(s,"{{brand}}",c)),s.includes("{{sku}}")&&(s=p(s,"{{sku}}",m)),s.includes("{{barcode}}")&&(s=p(s,"{{barcode}}",u)),s.includes("{{price}}")&&(s=p(s,"{{price}}",g.toString()));break;case r.BRAND:case r.CATEGORY:case r.BLOG_CATEGORY:var v=e.name||"";s.includes("{{name}}")&&(s=p(s,"{{name}}",v));break;case r.BLOG:var f=e.title;s.includes("{{name}}")&&(s=p(s,"{{name}}",f))}}catch(e){}return s.trimEnd()}function p(e,t,o){var i=new RegExp(t,"g");return e.replace(i,o)}export{l as IkasPageHead};
|
|
@@ -43,7 +43,7 @@ export declare class IkasCustomerStore {
|
|
|
43
43
|
resendCustomerPhoneVerificationCode: (email: string) => Promise<boolean>;
|
|
44
44
|
saveContactForm: (input: IkasContactForm) => Promise<boolean>;
|
|
45
45
|
checkEmail: (email: string) => Promise<boolean>;
|
|
46
|
-
forgotPassword: (email: string) => Promise<boolean>;
|
|
46
|
+
forgotPassword: (email: string) => Promise<boolean | undefined>;
|
|
47
47
|
recoverPassword: (password: string, passwordAgain: string, token: string) => Promise<boolean>;
|
|
48
48
|
saveCustomer: (customer: IkasCustomer) => Promise<boolean>;
|
|
49
49
|
getOrders: () => Promise<IkasOrder[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as e,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import s from"lodash/xorBy";import o from"lodash/cloneDeep";import n from"./api.js";import{IkasCustomer as a}from"../../models/data/customer/index.js";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"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as c}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../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/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/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"../../models/data/product/index.js";import{IkasRaffleParticipant as u}from"../../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/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 d from"../raffle/index.js";import'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import l from"../product/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{IkasLoginError as p,IkasRegisterError as f,SaveMyCustomerInput as v}from"@ikas/storefront-api";import{populateRaffleParticipantProducts as g}from"@ikas/storefront-providers";var w="undefined"==typeof localStorage,k=function(){function k(s){var a=this;this.customer=null,this.token=null,this.tokenExpiry=null,this.baseStore=null,this._initialized=!1,this._visitorSubscribedEmail=!1,this._lastViewedProducts=[],this._customerConsentGranted=!1,this._refundSettings=null,this._captchaToken=null,this._savedLastViewedProducts=[],this._savedLastViewedProductsResponse=null,this.toAnalyticsCustomer=function(t){return i(i({},t),{consentGranted:a._customerConsentGranted})},this.login=function(i,r){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:i,password:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.customerLogin=function(i,r){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:i,password:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,{isSuccess:!0,errorCodes:[]}]):[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(p).includes(t)?t:p.UNKOWN}))}]}}))}))},this.logout=function(){var t;a.clearLocalData(),null===(t=a.baseStore)||void 0===t||t.cartStore.removeCart(),h.customerLogout()},this.register=function(i,r,s,o,c,u,d){return t(a,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.register({email:s,password:o,firstName:i,lastName:r,isAcceptMarketing:c,attributes:u,captchaToken:this._captchaToken,phone:d})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&(null===(a=t.data)||void 0===a?void 0:a.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.saveLocalLastViewedProducts(),h.completeRegistration(this.toAnalyticsCustomer(this.customer)),[2,{isSuccess:!0,errorCodes:[]}]):[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(f).includes(t)?t:f.UNKOWN}))}]}}))}))},this.activateCustomer=function(){return t(a,void 0,void 0,(function(){var t,i,r;return e(this,(function(e){switch(e.label){case 0:return t=new URLSearchParams(window.location.search),(i=t.get("token"))?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.activateCustomer({token:i,captchaToken:this._captchaToken})];case 2:return r=e.sent(),this.clearCaptchaToken(),[2,r.isSuccess];case 3:return[2,!1]}}))}))},this.resendCustomerActivationMail=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return i?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerActivationMail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess];case 3:return[2,!1]}}))}))},this.validateCustomerPhoneVerificationCode=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return i?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.validateCustomerPhoneVerificationCode({verificationCode:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.resendCustomerPhoneVerificationCode=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return i?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerActivationMail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.saveContactForm=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return h.contactForm(r),[4,this.getCaptcha()];case 1:return e.sent(),[4,n.sendContactFormToMerchant(i(i({},r),{captchaToken:this._captchaToken}))];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.checkEmail=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.checkEmail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&!!(null===(r=t.data)||void 0===r?void 0:r.exists)]}}))}))},this.forgotPassword=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.forgotPassword({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.recoverPassword=function(i,r,s){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.recoverPassword({password:i,passwordAgain:r,token:s,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.saveCustomer=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.saveCustomer({input:new v(i)})];case 1:return(t=e.sent()).isSuccess&&t.data?(this.setCustomer(t.data),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrders({})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrder=function(i){return t(a,void 0,void 0,(function(){var t,r,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrders({orderId:i})];case 1:return(t=e.sent()).isSuccess&&(null===(s=t.data)||void 0===s?void 0:s.length)?(r=t.data[0],[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),r.refundSettings=this._refundSettings,[2,r]}}))}))},this.getOrderByEmail=function(i,r){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrderByEmail({email:i,orderNumber:r})];case 1:return(t=e.sent()).isSuccess&&t.data?(s=t.data,[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),s.refundSettings=this._refundSettings,[2,s]}}))}))},this.getOrderTransactions=function(i){return void 0===i&&(i={}),t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactions({checkoutId:{eq:i.checkoutId},id:{eq:i.checkoutId},orderId:{eq:i.orderId}})];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProductsIds=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProducts=function(){return t(a,void 0,void 0,(function(){var t,i,r,s,o,a;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return(t=e.sent()).isSuccess&&(null===(r=t.data)||void 0===r?void 0:r.length)?[4,l.searchProducts({input:{productIdList:t.data.map((function(t){return t.productId})),priceListId:m.getPriceListId(),salesChannelId:m.getSalesChannelId()}})]:[2,[]];case 2:return i=e.sent(),null===(o=null===(s=i.data)||void 0===s?void 0:s.data)||void 0===o||o.forEach((function(t){t.selectedVariantValues=t.variants[0].variantValues})),[2,(null===(a=null==i?void 0:i.data)||void 0===a?void 0:a.data)||[]]}}))}))},this.addProductToFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!0,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.removeProductFromFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!1,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.isProductFavorite=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!(null===(t=this.customer)||void 0===t?void 0:t.id))throw Error("Unauthorized");return[4,n.isFavoriteProduct({productId:i})];case 1:return[2,e.sent().data||!1]}}))}))},this.createEmailSubscription=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.subscribeToMarketingNotifications({input:{email:i,captchaToken:this._captchaToken}})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(i)),[2,t.isSuccess]}}))}))},this.sendReview=function(r){return t(a,void 0,void 0,(function(){var t,s,o,a;return e(this,(function(e){switch(e.label){case 0:if(t=m.getCustomerReviewSettings(),s=m.getSalesChannelId(),!t)return[2];if(!(o=null===(a=this.customer)||void 0===a?void 0:a.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,n.createCustomerReview({input:i(i({},r),{customerId:t.customerLoginRequired?o:void 0,salesChannelId:s||""})})];case 1:return[2,e.sent().data]}}))}))},this.onCustomerConsentGrant=function(){a.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.waitUntilCaptchaTokenInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a._captchaToken&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,d.listRaffleParticipants()];case 1:return(t=e.sent())&&t.data?[4,g(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,null===(i=t.data)||void 0===i?void 0:i.map((function(t){return new u(t)}))]}}))}))},this.getCustomerAttributes=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,n.listCustomerAttribute()];case 1:return t=e.sent(),this.customer&&(null===(i=this.customer.attributes)||void 0===i||i.forEach((function(e){var i,r,s;e.customerAttribute=(null===(i=t.data)||void 0===i?void 0:i.find((function(t){return t.id===e.customerAttributeId})))||null,e.customerAttributeOptionId&&(e.customerAttributeOption=(null===(s=null===(r=e.customerAttribute)||void 0===r?void 0:r.options)||void 0===s?void 0:s.find((function(t){return t.id===e.customerAttributeOptionId})))||null)}))),[2,t.data||[]]}}))}))},this.getOrderRefundSettings=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:[4,n.listOrderRefundSettings({})];case 1:(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)&&(this._refundSettings=t.data[0]),e.label=2;case 2:return[2]}}))}))},this.setSavedLastViewedProductsResponse=function(t){a._savedLastViewedProducts=o(a._lastViewedProducts),a._savedLastViewedProductsResponse=t},this.setCaptchaToken=function(t){a._captchaToken=t},this.baseStore=s,r(this)}return Object.defineProperty(k.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||w||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"isCaptchaRequired",{get:function(){var t;return(null===(t=m.getCustomerSettings())||void 0===t?void 0:t.requireCaptchaValidation)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"useLastViewedProductResponse",{get:function(){var t;return(null===(t=this._savedLastViewedProducts)||void 0===t?void 0:t.length)&&this._savedLastViewedProductsResponse&&0===s(this._lastViewedProducts,this._savedLastViewedProducts,"productId").length},enumerable:!1,configurable:!0}),k.prototype.socialLogin=function(i){return t(this,void 0,void 0,(function(){var t,r,s;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",r="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(i,"/login/authenticate?redirect=").concat(t),[4,fetch(r,{headers:{"x-api-key":m.getApiKey()||"","x-sfid":m.getStorefrontId()||"","x-sfrid":m.getStorefrontRoutingId()||""}})]);case 1:return[4,e.sent().json()];case 2:return s=e.sent(),window.location.href=s.redirectUrl,[2]}}))}))},k.prototype.socialLoginToken=function(i){var r;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.socialLogin({code:i})];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(r=t.data)||void 0===r?void 0:r.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.customer&&h.customerLogin(),[2,!0]):[2,!1]}}))}))},k.prototype.refundOrder=function(i,r){return t(this,void 0,void 0,(function(){var t,s,o=this;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=[],i.orderLineItems.map((function(e){null!==e.refundQuantity&&(null==t||t.push({orderLineItemId:e.id,quantity:e.refundQuantity?e.refundQuantity:0}))})),[4,n.createOrderRefundRequest({input:{email:r,orderId:i.id,orderLineItems:t}})];case 1:return(s=e.sent()).isSuccess&&s.data?(Object.entries(s.data).forEach((function(t){var e=t[0],i=t[1];o[e]=i})),[2,!0]):[3,3];case 2:return e.sent(),[3,3];case 3:return[2,!1]}}))}))},k.prototype.init=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.loadToken(),this.loadLastViewedProducts(),this.loadCustomerConsent(),[4,this.refreshToken()];case 1:return t.sent(),[4,this.getCustomer()];case 2:return t.sent(),this._initialized=!0,this.customer&&h.customerVisit(),[2]}}))}))},k.prototype.routeChangeInit=function(){this.loadToken(),!this.token&&this.customer&&this.clearLocalData(),this.token&&!this.customer&&this.getCustomer()},k.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return w||!this.token?[2]:[4,n.getCustomer()];case 1:return(t=e.sent()).data&&this.setCustomer(t.data),[2]}}))}))},k.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.token?[4,n.refreshToken({token:this.token})]:[2];case 1:return(t=e.sent()).isSuccess&&t.data?this.setToken(t.data.token,t.data.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},k.prototype.setCustomer=function(t){this.customer=new a(t)},k.prototype.getLastViewedProducts=function(){var i;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.getLastViewedProducts({customerId:this.customer.id})]:[3,2];case 1:return t=e.sent(),this._lastViewedProducts=(null===(i=o(t.data))||void 0===i?void 0:i.reverse())||[],[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},k.prototype.saveLastViewedProducts=function(){w||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},k.prototype.loadLastViewedProducts=function(){w||(this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=o(this._lastViewedProducts).reverse())},k.prototype.getLocalLastViewedProducts=function(){if(w)return[];try{var t=window.localStorage.getItem("lastViewedProducts");if(t)return JSON.parse(t)}catch(t){}return[]},k.prototype.removeLastViewedProducts=function(){w||window.localStorage.removeItem("lastViewedProducts")},k.prototype.onProductView=function(i,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?this._lastViewedProducts.find((function(t){return t.productId===i}))?[2]:[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:[{productId:i,variantId:r}]}})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:i,variantId:r}),[3,3];case 2:this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=this._lastViewedProducts.filter((function(t){return t.productId!==i})),this._lastViewedProducts.push({productId:i,variantId:r}),this._lastViewedProducts=this._lastViewedProducts.slice(-20),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},k.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(w)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),(t=this.getLocalLastViewedProducts()).length?[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:t}})]:[3,3];case 2:e.sent()&&this.removeLastViewedProducts(),e.label=3;case 3:return[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},k.prototype.saveCustomerConsent=function(){w||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},k.prototype.loadCustomerConsent=function(){w||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},k.prototype.removeCustomerConsent=function(){w||window.localStorage.removeItem("customerConsent")},k.prototype.setToken=function(t,e){w||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),m.init({customerToken:t}))},k.prototype.loadToken=function(){if(!w){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e?this.setToken(t,parseInt(e)):this.clearLocalTokenData()}},k.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},k.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,m.init({customerToken:""}),this.clearCaptchaToken()},k.prototype.clearCaptchaToken=function(){this._captchaToken=null},k.prototype.getCaptcha=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.isCaptchaRequired?(window.grecaptcha.execute(),[4,this.waitUntilCaptchaTokenInitialized()]):[3,2];case 1:e.sent(),window.grecaptcha.reset(),e.label=2;case 2:return[3,4];case 3:return t=e.sent(),console.log("Get captcha error",t),[3,4];case 4:return[2]}}))}))},k}();export{k as IkasCustomerStore};
|
|
1
|
+
import{__awaiter as t,__generator as e,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import s from"lodash/xorBy";import o from"lodash/cloneDeep";import n from"./api.js";import{IkasCustomer as a}from"../../models/data/customer/index.js";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"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as c}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../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/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/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"../../models/data/product/index.js";import{IkasRaffleParticipant as u}from"../../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/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 d from"../raffle/index.js";import'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import l from"../product/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{IkasLoginError as p,IkasRegisterError as f,SaveMyCustomerInput as v}from"@ikas/storefront-api";import{populateRaffleParticipantProducts as g}from"@ikas/storefront-providers";var w="undefined"==typeof localStorage,k=function(){function k(s){var a=this;this.customer=null,this.token=null,this.tokenExpiry=null,this.baseStore=null,this._initialized=!1,this._visitorSubscribedEmail=!1,this._lastViewedProducts=[],this._customerConsentGranted=!1,this._refundSettings=null,this._captchaToken=null,this._savedLastViewedProducts=[],this._savedLastViewedProductsResponse=null,this.toAnalyticsCustomer=function(t){return i(i({},t),{consentGranted:a._customerConsentGranted})},this.login=function(i,r){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:i,password:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.customerLogin=function(i,r){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:i,password:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,{isSuccess:!0,errorCodes:[]}]):[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(p).includes(t)?t:p.UNKOWN}))}]}}))}))},this.logout=function(){var t;a.clearLocalData(),null===(t=a.baseStore)||void 0===t||t.cartStore.removeCart(),h.customerLogout()},this.register=function(i,r,s,o,c,u,d){return t(a,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.register({email:s,password:o,firstName:i,lastName:r,isAcceptMarketing:c,attributes:u,captchaToken:this._captchaToken,phone:d})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&(null===(a=t.data)||void 0===a?void 0:a.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.saveLocalLastViewedProducts(),h.completeRegistration(this.toAnalyticsCustomer(this.customer)),[2,{isSuccess:!0,errorCodes:[]}]):[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(f).includes(t)?t:f.UNKOWN}))}]}}))}))},this.activateCustomer=function(){return t(a,void 0,void 0,(function(){var t,i,r;return e(this,(function(e){switch(e.label){case 0:return t=new URLSearchParams(window.location.search),(i=t.get("token"))?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.activateCustomer({token:i,captchaToken:this._captchaToken})];case 2:return r=e.sent(),this.clearCaptchaToken(),[2,r.isSuccess];case 3:return[2,!1]}}))}))},this.resendCustomerActivationMail=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return i?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerActivationMail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess];case 3:return[2,!1]}}))}))},this.validateCustomerPhoneVerificationCode=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return i?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.validateCustomerPhoneVerificationCode({verificationCode:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.resendCustomerPhoneVerificationCode=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return i?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerActivationMail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.saveContactForm=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return h.contactForm(r),[4,this.getCaptcha()];case 1:return e.sent(),[4,n.sendContactFormToMerchant(i(i({},r),{captchaToken:this._captchaToken}))];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.checkEmail=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.checkEmail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&!!(null===(r=t.data)||void 0===r?void 0:r.exists)]}}))}))},this.forgotPassword=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.forgotPassword({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&t.data]}}))}))},this.recoverPassword=function(i,r,s){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.recoverPassword({password:i,passwordAgain:r,token:s,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.saveCustomer=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.saveCustomer({input:new v(i)})];case 1:return(t=e.sent()).isSuccess&&t.data?(this.setCustomer(t.data),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrders({})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrder=function(i){return t(a,void 0,void 0,(function(){var t,r,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrders({orderId:i})];case 1:return(t=e.sent()).isSuccess&&(null===(s=t.data)||void 0===s?void 0:s.length)?(r=t.data[0],[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),r.refundSettings=this._refundSettings,[2,r]}}))}))},this.getOrderByEmail=function(i,r){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrderByEmail({email:i,orderNumber:r})];case 1:return(t=e.sent()).isSuccess&&t.data?(s=t.data,[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),s.refundSettings=this._refundSettings,[2,s]}}))}))},this.getOrderTransactions=function(i){return void 0===i&&(i={}),t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactions({checkoutId:{eq:i.checkoutId},id:{eq:i.checkoutId},orderId:{eq:i.orderId}})];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProductsIds=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProducts=function(){return t(a,void 0,void 0,(function(){var t,i,r,s,o,a;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return(t=e.sent()).isSuccess&&(null===(r=t.data)||void 0===r?void 0:r.length)?[4,l.searchProducts({input:{productIdList:t.data.map((function(t){return t.productId})),priceListId:m.getPriceListId(),salesChannelId:m.getSalesChannelId()}})]:[2,[]];case 2:return i=e.sent(),null===(o=null===(s=i.data)||void 0===s?void 0:s.data)||void 0===o||o.forEach((function(t){t.selectedVariantValues=t.variants[0].variantValues})),[2,(null===(a=null==i?void 0:i.data)||void 0===a?void 0:a.data)||[]]}}))}))},this.addProductToFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!0,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.removeProductFromFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!1,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.isProductFavorite=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!(null===(t=this.customer)||void 0===t?void 0:t.id))throw Error("Unauthorized");return[4,n.isFavoriteProduct({productId:i})];case 1:return[2,e.sent().data||!1]}}))}))},this.createEmailSubscription=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.subscribeToMarketingNotifications({input:{email:i,captchaToken:this._captchaToken}})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(i)),[2,t.isSuccess]}}))}))},this.sendReview=function(r){return t(a,void 0,void 0,(function(){var t,s,o,a;return e(this,(function(e){switch(e.label){case 0:if(t=m.getCustomerReviewSettings(),s=m.getSalesChannelId(),!t)return[2];if(!(o=null===(a=this.customer)||void 0===a?void 0:a.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,n.createCustomerReview({input:i(i({},r),{customerId:t.customerLoginRequired?o:void 0,salesChannelId:s||""})})];case 1:return[2,e.sent().data]}}))}))},this.onCustomerConsentGrant=function(){a.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.waitUntilCaptchaTokenInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a._captchaToken&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,d.listRaffleParticipants()];case 1:return(t=e.sent())&&t.data?[4,g(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,null===(i=t.data)||void 0===i?void 0:i.map((function(t){return new u(t)}))]}}))}))},this.getCustomerAttributes=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,n.listCustomerAttribute()];case 1:return t=e.sent(),this.customer&&(null===(i=this.customer.attributes)||void 0===i||i.forEach((function(e){var i,r,s;e.customerAttribute=(null===(i=t.data)||void 0===i?void 0:i.find((function(t){return t.id===e.customerAttributeId})))||null,e.customerAttributeOptionId&&(e.customerAttributeOption=(null===(s=null===(r=e.customerAttribute)||void 0===r?void 0:r.options)||void 0===s?void 0:s.find((function(t){return t.id===e.customerAttributeOptionId})))||null)}))),[2,t.data||[]]}}))}))},this.getOrderRefundSettings=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:[4,n.listOrderRefundSettings({})];case 1:(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)&&(this._refundSettings=t.data[0]),e.label=2;case 2:return[2]}}))}))},this.setSavedLastViewedProductsResponse=function(t){a._savedLastViewedProducts=o(a._lastViewedProducts),a._savedLastViewedProductsResponse=t},this.setCaptchaToken=function(t){a._captchaToken=t},this.baseStore=s,r(this)}return Object.defineProperty(k.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||w||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"isCaptchaRequired",{get:function(){var t;return(null===(t=m.getCustomerSettings())||void 0===t?void 0:t.requireCaptchaValidation)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"useLastViewedProductResponse",{get:function(){var t;return(null===(t=this._savedLastViewedProducts)||void 0===t?void 0:t.length)&&this._savedLastViewedProductsResponse&&0===s(this._lastViewedProducts,this._savedLastViewedProducts,"productId").length},enumerable:!1,configurable:!0}),k.prototype.socialLogin=function(i){return t(this,void 0,void 0,(function(){var t,r,s;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",r="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(i,"/login/authenticate?redirect=").concat(t),[4,fetch(r,{headers:{"x-api-key":m.getApiKey()||"","x-sfid":m.getStorefrontId()||"","x-sfrid":m.getStorefrontRoutingId()||""}})]);case 1:return[4,e.sent().json()];case 2:return s=e.sent(),window.location.href=s.redirectUrl,[2]}}))}))},k.prototype.socialLoginToken=function(i){var r;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.socialLogin({code:i})];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(r=t.data)||void 0===r?void 0:r.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.customer&&h.customerLogin(),[2,!0]):[2,!1]}}))}))},k.prototype.refundOrder=function(i,r){return t(this,void 0,void 0,(function(){var t,s,o=this;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=[],i.orderLineItems.map((function(e){null!==e.refundQuantity&&(null==t||t.push({orderLineItemId:e.id,quantity:e.refundQuantity?e.refundQuantity:0}))})),[4,n.createOrderRefundRequest({input:{email:r,orderId:i.id,orderLineItems:t}})];case 1:return(s=e.sent()).isSuccess&&s.data?(Object.entries(s.data).forEach((function(t){var e=t[0],i=t[1];o[e]=i})),[2,!0]):[3,3];case 2:return e.sent(),[3,3];case 3:return[2,!1]}}))}))},k.prototype.init=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.loadToken(),this.loadLastViewedProducts(),this.loadCustomerConsent(),[4,this.refreshToken()];case 1:return t.sent(),[4,this.getCustomer()];case 2:return t.sent(),this._initialized=!0,this.customer&&h.customerVisit(),[2]}}))}))},k.prototype.routeChangeInit=function(){this.loadToken(),!this.token&&this.customer&&this.clearLocalData(),this.token&&!this.customer&&this.getCustomer()},k.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return w||!this.token?[2]:[4,n.getCustomer()];case 1:return(t=e.sent()).data&&this.setCustomer(t.data),[2]}}))}))},k.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.token?[4,n.refreshToken({token:this.token})]:[2];case 1:return(t=e.sent()).isSuccess&&t.data?this.setToken(t.data.token,t.data.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},k.prototype.setCustomer=function(t){this.customer=new a(t)},k.prototype.getLastViewedProducts=function(){var i;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.getLastViewedProducts({customerId:this.customer.id})]:[3,2];case 1:return t=e.sent(),this._lastViewedProducts=(null===(i=o(t.data))||void 0===i?void 0:i.reverse())||[],[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},k.prototype.saveLastViewedProducts=function(){w||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},k.prototype.loadLastViewedProducts=function(){w||(this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=o(this._lastViewedProducts).reverse())},k.prototype.getLocalLastViewedProducts=function(){if(w)return[];try{var t=window.localStorage.getItem("lastViewedProducts");if(t)return JSON.parse(t)}catch(t){}return[]},k.prototype.removeLastViewedProducts=function(){w||window.localStorage.removeItem("lastViewedProducts")},k.prototype.onProductView=function(i,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?this._lastViewedProducts.find((function(t){return t.productId===i}))?[2]:[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:[{productId:i,variantId:r}]}})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:i,variantId:r}),[3,3];case 2:this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=this._lastViewedProducts.filter((function(t){return t.productId!==i})),this._lastViewedProducts.push({productId:i,variantId:r}),this._lastViewedProducts=this._lastViewedProducts.slice(-20),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},k.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(w)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),(t=this.getLocalLastViewedProducts()).length?[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:t}})]:[3,3];case 2:e.sent()&&this.removeLastViewedProducts(),e.label=3;case 3:return[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},k.prototype.saveCustomerConsent=function(){w||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},k.prototype.loadCustomerConsent=function(){w||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},k.prototype.removeCustomerConsent=function(){w||window.localStorage.removeItem("customerConsent")},k.prototype.setToken=function(t,e){w||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),m.init({customerToken:t}))},k.prototype.loadToken=function(){if(!w){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e?this.setToken(t,parseInt(e)):this.clearLocalTokenData()}},k.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},k.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,m.init({customerToken:""}),this.clearCaptchaToken()},k.prototype.clearCaptchaToken=function(){this._captchaToken=null},k.prototype.getCaptcha=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.isCaptchaRequired?(window.grecaptcha.execute(),[4,this.waitUntilCaptchaTokenInitialized()]):[3,2];case 1:e.sent(),window.grecaptcha.reset(),e.label=2;case 2:return[3,4];case 3:return t=e.sent(),console.log("Get captcha error",t),[3,4];case 4:return[2]}}))}))},k}();export{k as IkasCustomerStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikas/storefront",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.9",
|
|
4
4
|
"description": "Storefront functionality for ikas storefront themes.",
|
|
5
5
|
"author": "ikas",
|
|
6
6
|
"license": "ISC",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"build": "rm -rf build && rollup -c"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@ikas/storefront-api": "^4.13.
|
|
21
|
-
"@ikas/storefront-config": "^4.13.
|
|
22
|
-
"@ikas/storefront-model-functions": "^4.13.
|
|
23
|
-
"@ikas/storefront-models": "^4.13.
|
|
24
|
-
"@ikas/storefront-providers": "^4.13.
|
|
20
|
+
"@ikas/storefront-api": "^4.13.9",
|
|
21
|
+
"@ikas/storefront-config": "^4.13.9",
|
|
22
|
+
"@ikas/storefront-model-functions": "^4.13.9",
|
|
23
|
+
"@ikas/storefront-models": "^4.13.9",
|
|
24
|
+
"@ikas/storefront-providers": "^4.13.9",
|
|
25
25
|
"@ikas/localized-address": "^1.0.0-beta.3",
|
|
26
26
|
"@adyen/adyen-web": "^5.28.2",
|
|
27
27
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@ikas/localized-address": "^1.0.0-beta.3",
|
|
58
|
-
"@ikas/storefront-api": "^4.13.
|
|
59
|
-
"@ikas/storefront-config": "^4.13.
|
|
60
|
-
"@ikas/storefront-model-functions": "^4.13.
|
|
61
|
-
"@ikas/storefront-models": "^4.13.
|
|
62
|
-
"@ikas/storefront-providers": "^4.13.
|
|
58
|
+
"@ikas/storefront-api": "^4.13.9",
|
|
59
|
+
"@ikas/storefront-config": "^4.13.9",
|
|
60
|
+
"@ikas/storefront-model-functions": "^4.13.9",
|
|
61
|
+
"@ikas/storefront-models": "^4.13.9",
|
|
62
|
+
"@ikas/storefront-providers": "^4.13.9",
|
|
63
63
|
"mobx": "^6.1.3",
|
|
64
64
|
"mobx-react-lite": "^3.1.5",
|
|
65
65
|
"next": "12.2.0",
|